高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
public with sharing class WeeklyReportCmp {
    @AuraEnabled public List<Agency_Report__c> reports{get;set;}
    @AuraEnabled public Map<String,List<Map<String,String>>> allselectlist{get;set;}
    @AuraEnabled public Map<String,String> fieldsMap{get;set;}
    @AuraEnabled public Map<String,List<Map<String,String>>> docmap{get;set;}
    @AuraEnabled public List<Map<String,String>> doctorList{get;set;}
    
    public WeeklyReportCmp() {
    }
 
    @RemoteAction
    @AuraEnabled
    public static List<Map<String,String>> getProductList(String dc, String opdsis){
        List<ProductTypes__c> ptList;
        if (opdsis != '') {
            ptList = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dc and OPD_SIS_Type__c =:opdsis];
        } else {
            ptList = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dc];
        }
        List<Map<String,String>> pts = new List<Map<String,String>>();
        Map<String,String> blank = new Map<String,String>();
        blank.put('label', '');
        blank.put('value', '');
        pts.add(blank);
        for (ProductTypes__c pt : ptList) {
            Map<String,String> ptMap = new Map<String,String>();
            ptMap.put('label', pt.Name);
            ptMap.put('value', pt.Id);
            pts.add(ptMap);
        }
        return pts;
    }
    
    public void setalldata()
    {
        /*** create allselectlist ***/
        this.allselectlist = new Map<String,List<Map<String,String>>>();
 
        Map<String,List<Map<String,String>>> alldata = new Map<String,List<Map<String,String>>>();
 
        // プルダウン初期値の空白
        List<Map<String,String>> tmp = new List<Map<String,String>>();
        Map<String,String> space = new Map<String,String>();
        space.put('label', '');
        space.put('value', '');
        space.put('selected', 'true');
        tmp.add(space);
        
        // 代理店担当者 AgencyPerson__c
        List<Contact> agency_person_data = LightningUtil.selectAgencyPerson();
        for(Contact var : agency_person_data) {
            Map<String,String> om = new Map<String,String>();
            om.put('label', var.Name);
            om.put('value', var.Id);
            om.put('selected', 'false');
            tmp.add(om);
        }
        this.allselectlist.put('AgencyPerson__c', tmp);
        
        /*
        List<AgencyPerson__c> agency_person_data = [Select Id,Name,CurrencyIsoCode From AgencyPerson__c];
        List<Map<String,String>> tmp = new List<Map<String,String>>();
        Map<String,String> space = new Map<String,String>();
        space.put('label', '');
        space.put('value', '');
        space.put('selected', 'true');
        tmp.add(space);
        for(AgencyPerson__c var : agency_person_data){
            Map<String,String> om = new Map<String,String>();
            om.put('label', var.Name);
            om.put('value', var.Id);
            om.put('selected', 'false');
            tmp.add(om);
        }
        this.allselectlist.put('AgencyPerson__c', tmp);
        */
        
        // 科室分类 Department_Cateogy__c 
        this.allselectlist.put('Department_Cateogy__c', WeeklyReportCmp.getPicklistValues('Agency_Report__c','Department_Cateogy__c'));
 
        // 活动区分 Purpose_Type__c
        this.allselectlist.put('Purpose_Type__c', WeeklyReportCmp.getPicklistValues('Agency_Report__c','Purpose_Type__c'));
 
        // 结果 Result__c
        this.allselectlist.put('Result__c', WeeklyReportCmp.getPicklistValues('Agency_Report__c','Result__c'));
 
        //阶段 StageName__c
        this.allselectlist.put('StageName__c', WeeklyReportCmp.getPicklistValues('Agency_Opportunity__c','StageName__c'));
 
        // 职位
//        this.allselectlist.put('visitor_title__c', WeeklyReportCmp.getPicklistValues('Agency_Report__c','visitor_title__c'));
 
        // 製品区分
        //List<ProductTypes__c> ProductTypes = [select id,Name from ProductTypes__c];
        //List<Map<String,String>> tmp2 = new List<Map<String,String>>();
        //tmp2.add(space);
        //for(ProductTypes__c var : ProductTypes){
        //    Map<String,String> om = new Map<String,String>();
        //    om.put('label', var.Name);
        //    om.put('value', var.Id);
        //    om.put('selected', 'false');
        //    tmp2.add(om);
        //}
        //this.allselectlist.put('Product_Category__c', tmp2);
        
        // 見出し設定
        this.fieldsMap = new Map<String,String>();
        this.fieldsMap = this.getfiledsmap();
        
        //System.debug('fieldsMap is ' + fieldsMap);
        //System.debug('allselectlist is ' + this.allselectlist);
    }
    
    
    public static List<Map<String,String>> getPicklistValues(String objstr, String fld){
        List<Map<String,String>> options = new List<Map<String,String>>();
        Map<String,String> space = new Map<String,String>();
        space.put('label', '');
        space.put('value', '');
        space.put('selected', 'true');
        options.add(space);
 
        Schema.sObjectType objType = Schema.getGlobalDescribe().get(objstr);
        Schema.DescribeSObjectResult objDescribe = objType.getDescribe();
        map<String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap();
        list<Schema.PicklistEntry> values = fieldMap.get(fld).getDescribe().getPickListValues();
        system.debug(objstr + '=' + values);
        for (Schema.PicklistEntry a : values)
        {
            if (!a.isActive()) continue;
            Map<String,String> ses = new Map<String,String>();
            ses.put('label', a.getLabel());
            ses.put('value', a.getValue());
            ses.put('selected', 'false');
            options.add(ses);
        }
        return options;
    }
    
    
    public  Map<String,String> getfiledsmap()
    {
        Map<String,Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
        Map<String,List<String>>   typemap = new Map<String,List<String>>  ();
        
        Map<String,Schema.SObjectField> fieldMap = schemaMap.get('Agency_Opportunity__c').getDescribe().fields.getMap();
        Map<String,String> mappingmap = new Map<String,String>();
        for(Schema.SObjectField sfield : fieldMap.Values())
        {
            Schema.describefieldresult dfield = sfield.getDescribe();
            String lab = '';
            lab = dfield.getLabel();
            system.debug(lab);
            mappingmap.put(dfield.name,lab);
        }
        fieldMap = schemaMap.get('Agency_Report__c').getDescribe().fields.getMap();
        for(Schema.SObjectField sfield : fieldMap.Values())
        {
            Schema.describefieldresult dfield = sfield.getDescribe();
            String lab = '';
            lab = dfield.getLabel();
            system.debug(lab);
            mappingmap.put(dfield.name,lab);
        }
        return mappingmap;
    }
    
    @RemoteAction
    @AuraEnabled
    public static WeeklyReportCmp getalldata(){
        WeeklyReportCmp li = new WeeklyReportCmp();
        li.setalldata();
        return li;
    }
 
    @RemoteAction
    @AuraEnabled
    public static ProductTypes__c getProduct(String id){
        return [select Department_Cateogy__c, OPD_Flg__c, Id, SIS_Flg__c from ProductTypes__c where Id =:id];
    }
    
    @RemoteAction
    @AuraEnabled
    public static String createReportHeader(String name, String s_date, String s_agency, String head_key){
        Agency_Report_Header__c agency_report_header = makeReportHeader(name, s_date, s_agency, head_key);
 
        agency_report_header = LightningUtil.upsertAgencyReportHeader(agency_report_header);
        return agency_report_header.Id;
    }
    public static Agency_Report_Header__c makeReportHeader(String name, String s_date, String s_agency, String head_key){
        Date week = Date.valueOf(s_date);
        Agency_Report_Header__c agency_report_header = new Agency_Report_Header__c();
        agency_report_header.Name = name + ' (' + s_date + ')';
        agency_report_header.HeaderInputKey__c = head_key;
        agency_report_header.Week__c = week;
        agency_report_header.Agency_Person2__c = s_agency;
 
        // READ OlympusCalendar__c
        system.debug(week);
        OlympusCalendar__c olympus_calendar = [select Id,Date__c from OlympusCalendar__c where Date__c=:week];
        system.debug(olympus_calendar);
        String olympus_calendar_id = olympus_calendar.Id;
        if (olympus_calendar_id != '') { agency_report_header.OlympusDate__c = olympus_calendar_id; }
 
        system.debug(agency_report_header);
        return agency_report_header;
    }
    
    @RemoteAction
    @AuraEnabled
    public static List<Agency_Hospital_Link__c> getHospitalList(String hospital_name) {
        hospital_name = '%' + hospital_name.trim() + '%'; 
        return [select Hospital_Name_readonly__c, Id, Hospital__c from Agency_Hospital_Link__c where Hospital_Name_readonly__c like :hospital_name and Agency_Campaign_Obj__c = true];
    }
    
    @RemoteAction
    @AuraEnabled
    public static List<Map<String,String>> getDoctorList(String hospital_id){
        List<Map<String,String>> ret = new List<Map<String,String>>();
        Map<String,String> space = new Map<String,String>();
        space.put('label', '');
        space.put('value', '');
        space.put('selected', 'true');
        ret.add(space);
        
        // 戦略科室IDを取得して、それをもとに顧客をSELECT
        Agency_Hospital_Link__c ahl = [select Hospital__c from Agency_Hospital_Link__c where id = :hospital_id];
 
        List<Agency_Contact__c> doctor_list = [select id,Name,Doctor_Division1__c,Type__c,Agency_Hospital__c 
            FROM Agency_Contact__c WHERE Hospital_ID18__c=:ahl.Hospital__c order by Name];
 
        
        for (Agency_Contact__c row : doctor_list)
        {
            Map<String,String> tmp = new Map<String,String>();
            tmp.put('label', row.Name);
            tmp.put('value', row.Id);
            tmp.put('selected', 'false');
            tmp.put('Doctor_Division1__c', row.Doctor_Division1__c);
            ret.add(tmp);
        }
        
        
        /*
        String record_type_id = LightningUtil.getRecordTypeId(department);
 
        List<Contact> doctor_list = LightningUtil.selectContactList(hospital_id, record_type_id);
        
        for (Contact row : doctor_list)
        {
            Map<String,String> tmp = new Map<String,String>();
            tmp.put('label', row.Name);
            tmp.put('value', row.Id);
            tmp.put('selected', 'false');
            tmp.put('Doctor_Division1__c', row.Doctor_Division1__c);
            ret.add(tmp);
        }
        */
 
        return ret;
    }
 
    /*
    @RemoteAction
    @AuraEnabled
    public static List<Map<String,String>> getOpportunityList(String record_type, String hospital_link_id){
        List<Map<String,String>> ret = new List<Map<String,String>>();
        Map<String,String> space = new Map<String,String>();
        space.put('label', '');
        space.put('value', '');
        space.put('selected', 'true');
        ret.add(space);
        
        List<Agency_Opportunity__c> opportunity_list = [select id,Name from Agency_Opportunity__c where RecordType__c=:record_type AND Account__c=:hospital_link_id];
        
        for (Agency_Opportunity__c row : opportunity_list)
        {
            Map<String,String> tmp = new Map<String,String>();
            tmp.put('label', row.Name);
            tmp.put('value', row.Id);
            tmp.put('selected', 'false');
            ret.add(tmp);
        }
 
        return ret;
    }
    */
 
    @RemoteAction
    @AuraEnabled
    public static String saveAgencyReport(String Department_Cateogy, String Purpose_Type, String Agency_Report_Header,
            String Agency_Hospital, String Person_In_Charge2, String doctor, String Submit_date,
            String Product_Category1, String Product_Category2, String Product_Category3,
            String Result, String Opportunity, String StageName, String oppAmount, String oppOCMPrice, String Close_Forecasted_Date, String Report_Date)
    {
        Agency_Report__c agency_report = makeAgencyReport(Department_Cateogy, Purpose_Type, Agency_Report_Header,
            Agency_Hospital, Person_In_Charge2, doctor, Submit_date,
            Product_Category1, Product_Category2, Product_Category3,
            Result, Opportunity, StageName, oppAmount, oppOCMPrice, Close_Forecasted_Date, Report_Date);
 
        agency_report = LightningUtil.insertAgencyReport(agency_report);
        return agency_report.Id;
    }
    public static Agency_Report__c makeAgencyReport(String Department_Cateogy, String Purpose_Type, String Agency_Report_Header,
            String Agency_Hospital, String Person_In_Charge2, String doctor, String Submit_date,
            String Product_Category1, String Product_Category2, String Product_Category3,
            String Result, String Opportunity, String StageName, String oppAmount, String oppOCMPrice, String Close_Forecasted_Date, String Report_Date)
    {
        Agency_Report__c agency_report = new Agency_Report__c();
        Date week = Date.valueOf(Submit_date);
        agency_report.Submit_date__c = week;
        Date reportDate = Date.valueOf(Report_Date);
        agency_report.Report_Date__c = reportDate;
 
        // MaxActivityDate__c 更新
        if (Person_In_Charge2 != '') {
            agency_report.Person_In_Charge2__c = Person_In_Charge2;
            //Contact contact = LightningUtil.selectContact(Person_In_Charge2)[0];
            //LightningUtil.updateAccMaxActivityDate(contact.AccountId, reportDate);
        } else {
            agency_report.Person_In_Charge2__c = null;
        }
 
        if (Agency_Hospital != '')  {
            LightningUtil.updateAccMaxActivityDate(Agency_Hospital, week);
        }
        
        // READ OlympusCalendar__c
        //OlympusCalendar__c olympus_calendar = [select Id,Date__c from OlympusCalendar__c where Date__c=:week];
        //String olympus_calendar_id = olympus_calendar.Id;
        
        // WRITE Agency Report__c
        if (doctor != '') { agency_report.doctor2__c = doctor; } else { agency_report.doctor2__c = null; }
        if (Department_Cateogy != '') { agency_report.Department_Cateogy__c = Department_Cateogy; }
        if (Purpose_Type != '') { agency_report.Purpose_Type__c = Purpose_Type; }
        if (Agency_Report_Header != '') { agency_report.Agency_Report_Header__c = Agency_Report_Header; }
        if (Agency_Hospital != '') { agency_report.Agency_Hospital__c = Agency_Hospital; }
        //if (olympus_calendar_id != '') { agency_report.Submit_date_Calendar__c = olympus_calendar_id; }
        if (Product_Category1 != '') { agency_report.Product_Category1__c = Product_Category1; }
        if (Product_Category2 != '') { agency_report.Product_Category2__c = Product_Category2; }
        if (Product_Category3 != '') { agency_report.Product_Category3__c = Product_Category3; }
        if (Result != '') { agency_report.Result__c = Result; }
        if (Opportunity != '') { 
            agency_report.Opportunity__c = Opportunity; 
            if (StageName != '' || oppAmount != '' || Close_Forecasted_Date != '' || oppOCMPrice != '') {
                Agency_Opportunity__c aopp = [select Id, StageName__c, Amount__c, Close_Forecasted_Date__c from Agency_Opportunity__c where Id = :Opportunity];
                if (StageName != '') {
                    aopp.StageName__c = StageName;
                }
                if (String.isNotBlank(oppAmount)) {
                    Decimal amt = Decimal.valueOf(oppAmount);
                    aopp.Amount__c = amt;
                }
                if (String.isNotBlank(oppOCMPrice)) {
                    Decimal amt = Decimal.valueOf(oppOCMPrice);
                    aopp.OCMSale_Price__c = amt;
                }
                if (Close_Forecasted_Date != '') {
                    Date closeForecastedDate = Date.valueOf(Close_Forecasted_Date);
                    aopp.Close_Forecasted_Date__c = closeForecastedDate;
                }
                update aopp;
            }
        }
        
        system.debug(agency_report);
        return agency_report;
    }
 
    @RemoteAction
    @AuraEnabled
    public static String editAgencyReport(String Agency_Report_Id, String Department_Cateogy, String Purpose_Type, String Agency_Report_Header,
                                        String Agency_Hospital, String Person_In_Charge2, String doctor, String Submit_date,
                                        String Product_Category1, String Product_Category2, String Product_Category3, 
                                        String Result, String Opportunity, String StageName, String oppAmount, String oppOCMPrice, String Close_Forecasted_Date, String Report_Date)
    {
        if (String.isBlank(Agency_Report_Id)) {
            return null;
        }
        Agency_Report__c agency_report = [select Id, Name, Department_Cateogy__c, Purpose_Type__c, Agency_Hospital__c,
                                          Person_In_Charge2__c, doctor2__c, Submit_date__c, Product_Category__c, Result__c, visitor_title__c, Opportunity__c
                                          from Agency_Report__c where id=:Agency_Report_Id];
        Date week = Date.valueOf(Submit_date);
        agency_report.Submit_date__c = week;
        Date reportDate = Date.valueOf(Report_Date);
        agency_report.Report_Date__c = reportDate;
 
        // MaxActivityDate__c 更新
        if (Person_In_Charge2 != '') {
            agency_report.Person_In_Charge2__c = Person_In_Charge2;
            //Contact contact = LightningUtil.selectContact(Person_In_Charge2)[0];
            //LightningUtil.updateAccMaxActivityDate(contact.AccountId, reportDate);
        } else {
            agency_report.Person_In_Charge2__c = null;
        }
 
        if (Agency_Hospital != '')  {
            LightningUtil.updateAccMaxActivityDate(Agency_Hospital, week);
        }
 
        // WRITE Agency Report__c
        if (doctor != '') { agency_report.doctor2__c = doctor; } else { agency_report.doctor2__c = null; }
        if (Department_Cateogy != '') { agency_report.Department_Cateogy__c = Department_Cateogy; } else { agency_report.Department_Cateogy__c = null; }
        if (Purpose_Type != '') { agency_report.Purpose_Type__c = Purpose_Type; } else { agency_report.Purpose_Type__c = null; }
        if (Agency_Hospital != '') { agency_report.Agency_Hospital__c = Agency_Hospital; } else { agency_report.Agency_Hospital__c = null; }
        if (Product_Category1 != '') { agency_report.Product_Category1__c = Product_Category1; } else { agency_report.Product_Category1__c = null; }
        if (Product_Category2 != '') { agency_report.Product_Category2__c = Product_Category2; } else { agency_report.Product_Category2__c = null; }
        if (Product_Category3 != '') { agency_report.Product_Category3__c = Product_Category3; } else { agency_report.Product_Category3__c = null; }
        //if (Product_Category != '') { agency_report.Product_Category__c = Product_Category; } else { agency_report.Product_Category__c = null; }
        if (Result != '') { agency_report.Result__c = Result; } else { agency_report.Result__c = null; }
        //if (Opportunity != '') { agency_report.Opportunity__c = Opportunity; } else { agency_report.Opportunity__c = null; }
        if (Opportunity != '') { 
            agency_report.Opportunity__c = Opportunity; 
            if (StageName != '' || oppAmount != '' || Close_Forecasted_Date != '' || oppOCMPrice != '') {
                Agency_Opportunity__c aopp = [select Id, StageName__c, Amount__c, Close_Forecasted_Date__c from Agency_Opportunity__c where Id = :Opportunity];
                if (StageName != '') {
                    aopp.StageName__c = StageName;
                }
                if (String.isNotBlank(oppAmount)) {
                    Decimal amt = Decimal.valueOf(oppAmount);
                    aopp.Amount__c = amt;
                }
                if (String.isNotBlank(oppOCMPrice)) {
                    Decimal amt = Decimal.valueOf(oppOCMPrice);
                    aopp.OCMSale_Price__c = amt;
                }
                if (Close_Forecasted_Date != '') {
                    Date closeForecastedDate = Date.valueOf(Close_Forecasted_Date);
                    aopp.Close_Forecasted_Date__c = closeForecastedDate;
                }
                update aopp;
            }
        } else { agency_report.Opportunity__c = null; }
        system.debug(agency_report);
        
        agency_report = LightningUtil.updateAgencyReport(agency_report);
        
        return agency_report.Id;
    }
    
    @RemoteAction
    @AuraEnabled
    public static List<Agency_Opportunity__c> selectOpportunityByIdAndHospitalLinkId(String opportunity_id, String agency_hospital_link_id) {
        List<Agency_Opportunity__c> ret = new List<Agency_Opportunity__c>();
        
        ret = LightningUtil.selectOpportunityByIdAndHospitalLinkId(opportunity_id, agency_hospital_link_id);
        
        return ret;
    }
    
    @RemoteAction
    @AuraEnabled
    public static WeeklyReportCmp getReports(String date_str, String person_str) {
        WeeklyReportCmp li = new WeeklyReportCmp();
        li.get_reports(date_str, person_str);
        return li;
    }
    
    public void get_reports(String date_str, String person_str) {        
        // 週報データを取得
        Date week = Date.valueOf(date_str);
        this.reports = LightningUtil.selectAgencyReport(week, person_str);
    }
    
    @RemoteAction
    @AuraEnabled
    public static List<Agency_Report__c> getReportsById(String report_id) {
        List<Agency_Report__c> ret = new List<Agency_Report__c>();
        
        ret = LightningUtil.selectAgencyReportById(report_id);
        
        return ret;
    }
    
    // 批量添加周报by vivek start
    @RemoteAction
    @AuraEnabled
    public static List<Agency_Report__c> getReportsByDate(String date1, String date2) {
        Date date1_date = Date.valueOf(date1);
        Date date2_date = Date.valueOf(date2);
        WeeklyReportCmp li = new WeeklyReportCmp();
        // li.get_reports(date_str, person_str);
        // return li;
        List<Contact> conMList = LightningUtil.selectAgencyPerson();
        // LightningUtil.selectAgencyPerson();
 
        System.debug('====='+conMList);
        // List<Agency_Report__c> reportlist = [Select Id, Name, Report_Date__c, Product_Category1__r.Name, Product_Category2__r.Name, Product_Category3__r.Name, Product_Category1__c, Product_Category2__c, Product_Category3__c, Department_Cateogy__c, Purpose_Type__c, Agency_Report_Header__c, Agency_Hospital__r.Name, Agency_Hospital__r.Hospital__c, OppName__c,
        //                     Person_In_Charge2__c, Person_In_Charge2__r.Name, doctor2__c, doctor2__r.Name, Submit_date__c,
        //                     Product_Category__c, Product_Category__r.Name, Result__c, visitor_title__c, Opportunity__c, Opportunity__r.Name
        //                     From Agency_Report__c
        //                     where Person_In_Charge2__c in :conMList and Report_Date__c >= :date1_date and Report_Date__c <= :date2_date ];
        // return reportlist;
        return LightningUtil.selectMAgencyReport(date1_date, date2_date, conMList);
    }
 
    public List<contact> selectMAgencyPerson() {
        String login_user_id = UserInfo.getUserId();
        // return [select id, Name, Agency_User__c from contact where Agency_User__c = true and Isactive__c = '有效' and AccountId in (select AccountId from User where id=:login_user_id)];
        // return [select id, Name, Agency_User__c from contact where Agency_User__c = true  and AccountId in (select AccountId from User where id=:login_user_id)];
        return [select id, Name, Agency_User__c from contact];
    }
 
    @AuraEnabled
    public static String processData(String fileData,String sobjectName,List<String> fields) {
 
       System.debug('fileData:::'+filedata);
       System.debug('sobjectName:::'+sobjectName);
       System.debug('fields:::'+fields);
       String errorMag = '';
       
       // 创建周报
       try{
          
            if(fileData!=null){ 
                String[] fileLines = new String[]{};
                fileLines = fileData.split('\n');
                // 担当名称的list
                List<String> nameList = new List<String>();
                // 报告日的list
                List<Date> dateList = new List<Date>();
                // List<String> s_dateList = new List<String>();
                // 导入的数据
                List<List<String>> inputList = new List<List<String>>();
                // 经销商医院名称list
                List<String> ahlNameList = new List<String>();
                // 科室Set
                Set<String> departmentSet = new Set<String>();
                // 经销商询价名称list
                // List<String> ahlOppNameList = new List<String>();
                //for content
                system.debug('fileLines.size()==============>'+fileLines.size());
                for (Integer i=1,j=fileLines.size();i<j;i++){
                    system.debug('for2022161329');
                    List<String> inputvalues = new List<String>();
                    inputvalues = fileLines[i].split(',');
                    if(inputvalues != null){
                        system.debug('if2022161333');
                        if(inputvalues[0] == '' || inputvalues[0] == null){
                            // return 'error1 第'+i+'行数据担当不能为空';
                            errorMag += 'error1 第'+i+'行数据担当不能为空';
                            errorMag += '=';
                        }
                        if(inputvalues[1] == '' || inputvalues[1] == null){
                            // return 'error1 第'+i+'行数据活动日不能为空';
                            errorMag += 'error1 第'+i+'行数据活动日不能为空';
                            errorMag += '=';
                        }
                        //SWAG-C7AASP 【委托】DAMS系统周报补录时间调整  2022-1-10 pk start
                        List<String> R = new List<String>();
                        R = inputvalues[1].split('/');
                        system.debug('R202216'+R);
                        Date rDate = Date.newInstance(Integer.Valueof(R[0]),Integer.Valueof(R[1]),Integer.Valueof(R[2]));
                        system.debug('rDate202216'+rDate);
                        Date start = Date.today().addMonths(-1);
                        Date startDay = start.toStartOfWeek();
                        Date firstDayOfweek = System.today().toStartOfWeek();
                        Date endDay = firstDayOfweek.addDays(6);
                        if(rDate > endDay || rDate < startDay){
                            system.debug('rDate >= ssDate');
                            // return 'error1 第'+i+'行数据活动日不能为空';
                            errorMag += 'error1 第'+i+'行数据,导入周报仅可补报最近一月周报';
                            errorMag += '=';
                        }
                        //SWAG-C7AASP 【委托】DAMS系统周报补录时间调整  2022-1-10 pk end
                        if(inputvalues[2] == '' || inputvalues[2] == null){
                            // return 'error1 第'+i+'行数据医院不能为空';
                            errorMag += 'error1 第'+i+'行数据医院不能为空';
                            errorMag += '=';
                        }
                        if(inputvalues[3] == '' || inputvalues[3] == null){
                            // return 'error1 第'+i+'行数据科室不能为空';
                            errorMag += 'error1 第'+i+'行数据科室不能为空';
                            errorMag += '=';
                        }
                        String departmentstr = GetDepartment_Cateogy(inputvalues[3]);
                        if(departmentstr == 'no' && inputvalues[3] != '' && inputvalues[3] != null){
                            // return 'error3 第'+i+'行数据科室选项列表的值'+inputvalues[3]+'不存在';
                            errorMag += 'error3 第'+i+'行数据科室选项列表的值'+inputvalues[3]+'不存在';
                            errorMag += '=';
                        }
                        if(inputvalues[4] == '' || inputvalues[4] == null){
                            // return 'error1 第'+i+'行数据拜访人不能为空';
                            errorMag += 'error1 第'+i+'行数据拜访人不能为空';
                            errorMag += '=';
                        }
                        if(inputvalues[5] == '' || inputvalues[5] == null){
                            // return 'error1 第'+i+'行数据产品区分1不能为空';
                            errorMag += 'error1 第'+i+'行数据产品区分1不能为空';
                            errorMag += '=';
                        }
                        if((inputvalues[6] != '' && inputvalues[6] != null)&& inputvalues[5] == inputvalues[6]){
                            // return 'error1 第'+i+'行数据产品区分1和产品区分2的值不能重复';
                            errorMag += 'error1 第'+i+'行数据产品区分1和产品区分2的值不能重复';
                            errorMag += '=';
                        }
                        if((inputvalues[7] != '' && inputvalues[7] != null)&& inputvalues[5] == inputvalues[7]){
                           
 
                            // return 'error1 第'+i+'行数据产品区分1和产品区分3的值不能重复';
                            errorMag += 'error1 第'+i+'行数据产品区分1和产品区分3的值不能重复';
                            errorMag += '=';
                        }
                        if((inputvalues[6] != '' && inputvalues[6] != null) && (inputvalues[7] != '' && inputvalues[7] != null) && inputvalues[6] == inputvalues[7]){
                            // return 'error1 第'+i+'行数据产品区分2和产品区分3的值不能重复';
                            errorMag += 'error1 第'+i+'行数据产品区分2和产品区分3的值不能重复';
                            errorMag += '=';
                        }
                        if(inputvalues[8] == '' || inputvalues[8] == null){
                            // return 'error1 第'+i+'行数据活动区分不能为空';
                            errorMag += 'error1 第'+i+'行数据活动区分不能为空';
                            errorMag += '=';
                        }
                        boolean purposeType = GetPurposeType(inputvalues[8]);
                        if(!purposeType && inputvalues[8] != '' && inputvalues[8] != null){
                            // return 'error3 第'+i+'行数据活动区分选项列表的值'+inputvalues[8]+'不存在';
                            errorMag += 'error3 第'+i+'行数据活动区分选项列表的值'+inputvalues[8]+'不存在';
                            errorMag += '=';
                        }
                        // if(inputvalues[9] == '\r' || inputvalues[9] == null){
                        //     return 'error1 结果不能为空';
                        // }
                        if(inputvalues[8] == '询价挖掘-OPD' || inputvalues[8] == '询价挖掘-SIS' || inputvalues[8] == '询价推进-OPD' || inputvalues[8] == '询价推进-SIS'){
                            System.debug(']]]]]1'+inputvalues[9]+'=====');
                            if(inputvalues[9] == '\r'){
 
                                // return 'error5 第'+i+'行数据当活动区分为'+inputvalues[8]+'结果不能为空';
                                errorMag += 'error5 第'+i+'行数据当活动区分为'+inputvalues[8]+'结果不能为空';
                                errorMag += '=';
                            }
                        }
                        if(inputvalues[9] != '\r' && getResultlist(inputvalues[9])){
                            // return 'error3 第'+i+'行数据结果选项列表的值'+inputvalues[9]+'不存在';
                            errorMag += 'error3 第'+i+'行数据结果选项列表的值'+inputvalues[9]+'不存在';
                            errorMag += '=';
                        }
                        system.debug('inputvalues[0]=================>'+inputvalues[0]);
                        system.debug('inputvalues[1]=================>'+inputvalues[1]);
                        system.debug('inputvalues[2]=================>'+inputvalues[2]);
                        system.debug('inputvalues[3]=================>'+inputvalues[3]);
                        system.debug('inputvalues[4]=================>'+inputvalues[4]);
                        system.debug('inputvalues[5]=================>'+inputvalues[5]);
                        system.debug('inputvalues[6]=================>'+inputvalues[6]);
                        system.debug('inputvalues[7]=================>'+inputvalues[7]);
                        system.debug('inputvalues[8]=================>'+inputvalues[8]);
                        system.debug('inputvalues[9]=================>'+inputvalues[9]);
                        
 
                        nameList.add(inputvalues[0]);
                        dateList.add(Date.valueOf(inputvalues[1].replace('/','-')));
                        ahlNameList.add(inputvalues[2]);
                        departmentSet.add('%'+GetDepartment_Cateogy(inputvalues[3])+'%'+'-'+GetEPurposeType(inputvalues[8]));
                        inputList.add(inputvalues);
                    }
                }
                system.debug('snduksbdnjsvbdskjv');
                // 担当名称匹配的map
                Map<String,String> nameIdMap = new Map<String,String>();
                Map<String,String> nameConMap = new Map<String,String>();
                // 经销商医院名称匹配的map
                Map<String,Agency_Hospital_Link__c> ahlMap = new Map<String,Agency_Hospital_Link__c>();
                // 产品区分的map
                Map<String,String> protypeMap = new Map<String,String>();
                // 经销商医院的ocsm医院id的list
                List<String> ahlOcsmIdList = new List<String>();
                // 经销商医院id的List
                List<String> ahlIdList = new List<String>();
                // 获取每周第一天的map
                Map<Date,Date> dateMap = new Map<Date,Date>();
                // 根据日期获取olympus日历id的map
                Map<Date,String> dateIdMap = new Map<Date,String>();
                // 根据经销商医院的ocsm医院获取的所有.客户人员的信息的名称和id的map
                Map<String,String> doctor2Map = new Map<String,String>();
                // 经销商询价的map
                Map<String,Agency_Opportunity__c> aoMap = new Map<String,Agency_Opportunity__c>();
                // 科室和产品区分关系map
                Map<String,List<Map<String,String>>> impProMap = new  Map<String,List<Map<String,String>>>();
                impProMap = getImplProductList(departmentSet);
                System.debug('---===---===---==='+impProMap);
                // return nameList[0];
                // List<Contact> conList = [select id,name from Contact where name = :nameList];
                // List<Contact> conList = [select id,name from Contact];
                List<Contact> conList = LightningUtil.selectAgencyPerson();
                System.debug('---===---===---====='+conList);
                List<OlympusCalendar__c> olympusDateList = [select Id,Date__c,FirstDayOfWeek__c,DayOfTheWeek__c from OlympusCalendar__c where Date__c= :dateList ];
                // test用
                // String testuse = '';
                // testuse += '====='+ahlNameList;
                List<Agency_Hospital_Link__c> ahlList = [select id,name,Hospital__c,MaxActivityDate__c from Agency_Hospital_Link__c where name = :ahlNameList and Agency_Campaign_Obj__c = true];
                // List<Agency_Hospital_Link__c> ahlList = [select id,name,Hospital__c,MaxActivityDate__c from Agency_Hospital_Link__c ];
                // List<ProductTypes__c> proTypeList = [select id,name from ProductTypes__c];
                for(OlympusCalendar__c olym : olympusDateList){
                    if(olym.DayOfTheWeek__c == 'Sun'){
                        dateMap.put(olym.Date__c, olym.Date__c.addDays(1));
                    }
                    else{
                        dateMap.put(olym.Date__c, olym.FirstDayOfWeek__c);
                    }
                }
                System.debug('x'+dateMap);
                List<OlympusCalendar__c> olympusIdList = [select Id,Date__c,FirstDayOfWeek__c from OlympusCalendar__c where Date__c= :dateMap.values()];
                for(OlympusCalendar__c olym : olympusIdList){
                    dateIdMap.put(olym.FirstDayOfWeek__c, olym.id);
                }
                System.debug('dateIdMap===='+dateIdMap);
                for(Contact con :conList){
                    nameIdMap.put(con.Name.replace(' ',''), con.Id);
                    nameConMap.put(con.Id, con.Name);
                }
                // testuse += '======'+ahlList;
                // return testuse;
                for(Agency_Hospital_Link__c ahl : ahlList){
                    ahlMap.put(ahl.Name, ahl);
                    ahlOcsmIdList.add(ahl.Hospital__c);
                    ahlIdList.add(ahl.Id);
                }
                // for(ProductTypes__c protype : proTypeList){
                //     protypeMap.put(protype.Name, protype.Id);
                // }
                List<Agency_Contact__c> doctor2list = [select id,Name,Doctor_Division1__c,Type__c,Agency_Hospital__c FROM Agency_Contact__c WHERE Hospital_ID18__c= :ahlOcsmIdList order by Name];
                for(Agency_Contact__c ac : doctor2list){
                    doctor2Map.put(ac.Name.replace(' ',''), ac.Id);
                }
 
                
                // List<Agency_Opportunity__c> aoList = [select id,name,StageName__c,Amount__c,OCMSale_Price__c,Close_Forecasted_Date__c,Agency_Hospital__c from Agency_Opportunity__c where Agency_Hospital__c = :ahlIdList and name = :ahlOppNameList];
                // for(Agency_Opportunity__c ao : aoList){
                //     aoMap.put(ao.Name, ao);
                // }
                System.debug('nameIdMap===='+nameIdMap);
                // 创建周报
                List<Agency_Report_Header__c> agency_report_headerlist = new List<Agency_Report_Header__c>();
                Map<String,Agency_Report_Header__c> agency_report_headerMap = new Map<String,Agency_Report_Header__c>();
                for(List<String> lineList :inputList){
                    Date week = Date.today();
                    String s_agency = null;
                    String s_agencyname = null;
                    System.debug('dateMap===='+dateMap);
                    // System.debug('lineList[0]====不等于空'+lineList[1]);
                    if(dateMap.get(Date.valueOf(lineList[1].replace('/','-'))) != null){
                        System.debug('dateMap====不等于空');
                        week = dateMap.get(Date.valueOf(lineList[1].replace('/','-')));
                        System.debug('===='+week);
                    }
                    System.debug('lineList[0].replace()'+lineList[0].replace(' ',''));
                    if(nameIdMap.get(lineList[0].replace(' ','')) != null){
                        System.debug('nameIdMap====不等于空');
                        s_agency = nameIdMap.get(lineList[0].replace(' ',''));
                        s_agencyname = nameConMap.get(nameIdMap.get(lineList[0].replace(' ','')));
                        System.debug('===='+s_agency);
                    }
                    // if(s_agency == null || s_agencyname == null){
                    //     // return 'error0 担当 '+lineList[0]+'填写不正确';
                    //     errorMag += 'error0 担当 '+lineList[0]+'不存在';
                    //     errorMag += '=';
                    // }
                    Agency_Report_Header__c agency_report_header = new Agency_Report_Header__c();
                    // agency_report_header.Name = lineList[0] + ' (' + week.format() + ')';
                    agency_report_header.Name = s_agencyname + ' (' + week.format().replace('/','-') + ')';
                    agency_report_header.HeaderInputKey__c = createHeader(week,s_agency);
                    agency_report_header.Week__c = week;
                    agency_report_header.Agency_Person2__c = s_agency;
                    if(dateIdMap.containsKey(week)){
                        agency_report_header.OlympusDate__c = dateIdMap.get(week);
                    }
                    if(s_agencyname != null && s_agencyname != '' && s_agencyname != 'null'){
                        agency_report_headerMap.put(agency_report_header.HeaderInputKey__c, agency_report_header);
                    }
                    
                }
                agency_report_headerlist = agency_report_headerMap.values();
                System.debug('==========='+agency_report_headerlist+'');
                // upsert agency_report_headerlist Agency_Report_Header__c.HeaderInputKey__c;
                if(agency_report_headerlist.size() > 0){
                    LightningUtil.upsertMAgencyReportHeader(agency_report_headerlist);
                }
                
                List<Agency_Report__c> arList = new List<Agency_Report__c>();
                Integer hang = 1;
                for(List<String> lineList :inputList){
                    // 创建周报明细
                    Date week = null;
                    String s_agency = null;
                    System.debug('dateMap===='+dateMap);
                    System.debug('lineList[0]====不等于空'+lineList[1]);
                    if(dateMap.get(Date.valueOf(lineList[1].replace('/','-'))) != null){
                        System.debug('dateMap====不等于空');
                        week = dateMap.get(Date.valueOf(lineList[1].replace('/','-')));
                        System.debug('===='+week);
                    }
                    if(nameIdMap.get(lineList[0].replace(' ','')) != null){
                        System.debug('nameIdMap====不等于空');
                        s_agency = nameIdMap.get(lineList[0].replace(' ',''));
                        System.debug('===='+s_agency);
                    }
 
                    Agency_Report__c agencyReport = new Agency_Report__c();
                    if(week == null && lineList[1] != '' && lineList[1] != null){
                        // return 'error2 第'+hang+'行数据报告日'+lineList[1]+'填写有误';
                        errorMag += 'error2 第'+hang+'行数据报告日'+lineList[1]+'填写有误';
                        errorMag += '=';
                    }
                    agencyReport.Submit_date__c = week;   // 提出周
                    if((s_agency == null || s_agency == '')&& lineList[0] != '' && lineList[0] != null){
                        // return 'error2 第'+hang+'行数据担当'+lineList[0]+'不存在';
                        errorMag += 'error2 第'+hang+'行数据担当'+lineList[0]+'不存在';
                        errorMag += '=';
                    }
                    agencyReport.Person_In_Charge2__c = s_agency;  // 担当
                    if(lineList[1] != null && lineList[1] != ''){
                        agencyReport.Report_Date__c = Date.valueOf(lineList[1].replace('/','-')); // 活动日
                    }
                    if(ahlMap.containsKey(lineList[2])){
                        agencyReport.Agency_Hospital__c = ahlMap.get(lineList[2]).Id; //经销商医院
                        // 更新经销商医院的最新周
                        ahlMap.get(lineList[2]).MaxActivityDate__c = week;
                    }else{
                        if(lineList[2] != '' && lineList[2] != null){
 
                            // return 'error2 第'+hang+'行数据经销商医院'+lineList[2]+'不存在';
                            errorMag += 'error2 第'+hang+'行数据经销商医院'+lineList[2]+'不存在';
                            errorMag += '=';
                        }
                        
                    }
                    
                    String departmentE = GetDepartment_Cateogy(lineList[3]);
                    if(departmentE != 'no'){
                        agencyReport.Department_Cateogy__c = departmentE;  // 科室
                    }else{
                        // return 'error2 第'+hang+'行数据科室'+lineList[3]+'不存在';
                        // errorMag += 'error2 第'+hang+'行数据科室'+lineList[3]+'不存在';
                        // errorMag += '=';
                    }
 
                    if(doctor2Map.containsKey(lineList[4].replace(' ',''))){
                        agencyReport.doctor2__c = doctor2Map.get(lineList[4].replace(' ','')); // 拜访人
                    }else{
                        if(lineList[4] != '' && lineList[4] != null){
                            // return 'error2 第'+hang+'行数据拜访人'+lineList[4]+'不存在';
                            errorMag += 'error2 第'+hang+'行数据拜访人'+lineList[4]+'不存在';
                            errorMag += '=';
                        }
                        
                    }
 
                    if(GetPurposeType(lineList[8])){
                        agencyReport.Purpose_Type__c = lineList[8]; // 活动区分
                    }else{
                        // return 'error3 第'+hang+'行数据活动区分选项列表值'+lineList[8]+'不存在';
                        // errorMag += 'error3 第'+hang+'行数据活动区分选项列表值'+lineList[8]+'不存在';
                        // errorMag += '=';
                    }
                    // 科室产品区分关系判断
                    // 如果能找到,就是正确的
                    String departandprokey = '%'+GetDepartment_Cateogy(lineList[3])+'%'+'-'+GetEPurposeType(lineList[8]);
                    System.debug('---===---===---==='+departandprokey);
                    if(impProMap.containsKey(departandprokey)){
                        System.debug('---===---===---==='+ifTrueProduct(impProMap.get(departandprokey),lineList[5]));
                        if(ifTrueProduct(impProMap.get(departandprokey),lineList[5]) != ''){
                            System.debug(']]]不等于空进入');
                            agencyReport.Product_Category1__c = ifTrueProduct(impProMap.get(departandprokey),lineList[5]);
                        }else{
                            System.debug(']]]等于空进入');
                            // return 'error4 第'+hang+'行数据产品区分1的赋值不正确'+lineList[5];
                            errorMag += 'error4 第'+hang+'行数据产品区分1的赋值不正确'+lineList[5];
                            errorMag += '=';
                        }
                        if(lineList[6] != '' && lineList[6] != null){
                            if(ifTrueProduct(impProMap.get(departandprokey),lineList[6]) != ''){
                                agencyReport.Product_Category2__c = ifTrueProduct(impProMap.get(departandprokey),lineList[6]);
                            }else{
                                // return 'error4 第'+hang+'行数据产品区分2的赋值不正确'+lineList[6];
                                errorMag += 'error4 第'+hang+'行数据产品区分2的赋值不正确'+lineList[6];
                                errorMag += '=';
                            }
                        }
                        if(lineList[7] != '' && lineList[7] != null){
                            if(ifTrueProduct(impProMap.get(departandprokey),lineList[7]) != ''){
                                agencyReport.Product_Category3__c = ifTrueProduct(impProMap.get(departandprokey),lineList[7]);
                            }else{
                                // return 'error4 第'+hang+'行数据产品区分3的赋值不正确'+lineList[7];
                                errorMag += 'error4 第'+hang+'行数据产品区分3的赋值不正确'+lineList[7];
                                errorMag += '=';
                            }
                        }
                    }
                    
                    
                    // 通过map 科室,产品区分名 判断取值是否符合要求
                    // if(protypeMap.containsKey(lineList[5])){
                    //     agencyReport.Product_Category1__c = protypeMap.get(lineList[5]);// 产品区分1
                    // }
                    // if(protypeMap.containsKey(lineList[6])){
                    //     agencyReport.Product_Category2__c = protypeMap.get(lineList[6]);// 产品区分2
                    // }
                    // if(protypeMap.containsKey(lineList[7])){
                    //     agencyReport.Product_Category3__c = protypeMap.get(lineList[7]);// 产品区分3
                    // }
                    agencyReport.Result__c = lineList[9];
                    String headerStr = createHeader(week,s_agency);
                    if(agency_report_headerMap.containsKey(headerStr)){
                        agencyReport.Agency_Report_Header__c = agency_report_headerMap.get(headerStr).Id; // 周报一览
                    }
                    // if(aoMap.containsKey(lineList[6])){
                    //     agencyReport.Opportunity__c = aoMap.get(lineList[6]).Id; // 经销商询价
                    //     // 经销商询价更新字段
                    //     aoMap.get(lineList[6]).StageName__c = lineList[5]; // 询价阶段
                    //     aoMap.get(lineList[6]).Amount__c = Decimal.valueOf(lineList[6]); // 医院采购预算(含税,元)
                    //     aoMap.get(lineList[6]).OCMSale_Price__c = Decimal.valueOf(lineList[7]); // 订货金额(含税,元)
                    //     aoMap.get(lineList[6]).Close_Forecasted_Date__c = Date.valueOf(lineList[8].replace('/','-')); // 预测于OLY签约日
                    // }
                    hang++;
                    arList.add(agencyReport);
                }
 
                if(errorMag != ''){
                    return errorMag;
                }
 
                // 更新经销商意愿的最新周
                if(ahlMap.values().size() > 0 ){
                    update ahlMap.values();
                }
                // 更新经销商询价
                // if(aoMap.values().size() > 0 ){
                //     update aoMap.values();
                // }
                // 新增周报明细
                if(arList.size() > 0 ){
                    // insert arList;
                    LightningUtil.insertMAgencyReport(arList);
                }
                
 
            }
            return 'success';  
        }catch(Exception e){
             System.debug('exception'+e);
             return 'exception'+e;   
        }
        return 'success';
    }
 
    // 创建唯一键
    public static String createHeader(Date s_date,String nameid){
        String str = s_date.format();
        String str1 = str.replace('/', '');
        return nameid+':'+str1;
    }
 
    // 科室对应翻译
    public static String GetDepartment_Cateogy(String department){
        String departmentE = 'no';
        if(department == '呼吸科'){
            departmentE = 'BF';
        }
        if(department == '耳鼻喉科'){
            departmentE = 'ENT';
        }
        if(department == 'ET耗材'){
            departmentE = 'ET';
        }
        if(department == '消化科'){
            departmentE = 'GI';
        }
        if(department == '普外科'){
            departmentE = 'GS';
        }
        if(department == '妇科'){
            departmentE = 'GYN';
        }
        if(department == '其他'){
            departmentE = 'OTH';
        }
        if(department == '泌尿科'){
            departmentE = 'URO';
        }
        return departmentE;
    }
 
    // 判断活动分区是否存在
    public static boolean GetPurposeType(String purposeType){
        Schema.DescribeFieldResult fieldResult = Agency_Report__c.Purpose_Type__c.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry pickListVal : ple){
            if(pickListVal.getValue() == purposeType){
                return true;
            }
        }
        return false;
    }
    public static boolean getResultlist(String resultlist){
        system.debug('resultlist===============>'+resultlist);
        Schema.DescribeFieldResult fieldResult = Agency_Report__c.Result__c.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry pickListVal : ple){
            System.debug('weixiao'+resultlist.trim()+'111111'+pickListVal.getValue()+'222222');
            string temp = string.ValueOf(pickListVal.getValue());
            if(temp.equals(resultlist.trim())){
            // if(pickListVal.getValue().equals(resultlist)){
                System.debug('weixiaoweixiao'+resultlist+''+pickListVal.getValue());
                return false;
            }
        }
        return true;
    }
    public static String GetEPurposeType(String purposeType){
        // String purpose_Type='';
        if(purposeType.substring(purposeType.length()-3) == 'OPD'){
            purposeType = 'OPD';
        }else if(purposeType.substring(purposeType.length()-3) == 'SIS'){
            purposeType = 'SIS';
        }else{
            purposeType = '';
        }
        return purposeType;
    }
 
    // 判断产品区分是否满足要求
    public static String ifTrueProduct(List<Map<String,String>> prolist,String str){
        system.debug('=ifTrueProduct==============ifTrueProduct========='+str);
        system.debug('=prolist==============prolist========='+prolist);
 
        for(Map<String,String> strmap :prolist){
            System.debug('---===---===---==='+str+'==='+strmap.get('label'));
            if(strmap.get('label')==str){
                return strmap.get('value');
            }
        }
        return '';
    }
    // 获取导入数据的科室和产品区分的匹配
    public static Map<String,List<Map<String,String>>> getImplProductList(Set<String> ptdc){
         Map<String,List<Map<String,String>>> impProMap = new  Map<String,List<Map<String,String>>>();
         List<String> dc = new List<String>(ptdc);
        if(dc.size() > 0){
            List<ProductTypes__c> ptList1 = new List<ProductTypes__c>();
            List<String> dcList = dc[0].split('-');
            if (dcList.size() > 1) {
                ptList1 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList1 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList1){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[0], impProList);
            
        }
        if(dc.size() > 1){
            List<ProductTypes__c> ptList2 = new List<ProductTypes__c>();
            List<String> dcList = dc[1].split('-');
            if (dcList.size() > 1) {
                ptList2 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList2 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList2){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[1], impProList);
        }
        if(dc.size() > 2){
            List<ProductTypes__c> ptList3 = new List<ProductTypes__c>();
            List<String> dcList = dc[2].split('-');
            if (dcList.size() > 1) {
                ptList3 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList3 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList3){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[2], impProList); 
        }
        if(dc.size() > 3){
            List<ProductTypes__c> ptList4 = new List<ProductTypes__c>();
            List<String> dcList = dc[3].split('-');
            if (dcList.size() > 1) {
                ptList4 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList4 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList4){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[3], impProList);
        }
        if(dc.size() > 4){
            List<ProductTypes__c> ptList5 = new List<ProductTypes__c>();
            List<String> dcList = dc[4].split('-');
            if (dcList.size() > 1) {
                ptList5 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList5 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList5){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[4], impProList); 
        }
        if(dc.size() > 5){
            List<ProductTypes__c> ptList6 = new List<ProductTypes__c>();
            List<String> dcList = dc[5].split('-');
            if (dcList.size() > 1) {
                ptList6 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList6 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList6){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[5], impProList);
        }
        if(dc.size() > 6){
            List<ProductTypes__c> ptList7 = new List<ProductTypes__c>();
            List<String> dcList = dc[6].split('-');
            if (dcList.size() > 1) {
                ptList7 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList7 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList7){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[6], impProList); 
        }
        if(dc.size() > 7){
            List<ProductTypes__c> ptList8 = new List<ProductTypes__c>();
            List<String> dcList = dc[7].split('-');
            if (dcList.size() > 1) {
                ptList8 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList8 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList8){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[7], impProList);
        }
 
        if(dc.size() > 8){
            List<ProductTypes__c> ptList9 = new List<ProductTypes__c>();
            List<String> dcList = dc[8].split('-');
            if (dcList.size() > 1) {
                ptList9 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList9 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList9){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[8], impProList);
        }
        if(dc.size() > 9){
            List<ProductTypes__c> ptList10 = new List<ProductTypes__c>();
            List<String> dcList = dc[9].split('-');
            if (dcList.size() > 1) {
                ptList10 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList10 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList10){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[9], impProList);
        }
        if(dc.size() > 10){
            List<ProductTypes__c> ptList11 = new List<ProductTypes__c>();
            List<String> dcList = dc[10].split('-');
            if (dcList.size() > 1) {
                ptList11 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList11 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList11){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[10], impProList);
        }
        if(dc.size() > 11){
            List<ProductTypes__c> ptList12 = new List<ProductTypes__c>();
            List<String> dcList = dc[11].split('-');
            if (dcList.size() > 1) {
                ptList12 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList12 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList12){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[11], impProList);
        }
        if(dc.size() > 12){
            List<ProductTypes__c> ptList13 = new List<ProductTypes__c>();
            List<String> dcList = dc[12].split('-');
            if (dcList.size() > 1) {
                ptList13 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList13 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList13){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[12], impProList);
        }
        if(dc.size() > 13){
            List<ProductTypes__c> ptList14 = new List<ProductTypes__c>();
            List<String> dcList = dc[13].split('-');
            if (dcList.size() > 1) {
                ptList14 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList14 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList14){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[13], impProList);
        }
        if(dc.size() > 14){
            List<ProductTypes__c> ptList15 = new List<ProductTypes__c>();
            List<String> dcList = dc[14].split('-');
            if (dcList.size() > 1) {
                ptList15 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList15 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList15){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[14], impProList);
        }
        if(dc.size() > 15){
            List<ProductTypes__c> ptList16 = new List<ProductTypes__c>();
            List<String> dcList = dc[15].split('-');
            if (dcList.size() > 1) {
                ptList16 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList16 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList16){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[15], impProList);
        }
        if(dc.size() > 16){
            List<ProductTypes__c> ptList17 = new List<ProductTypes__c>();
            List<String> dcList = dc[16].split('-');
            if (dcList.size() > 1) {
                ptList17 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList17 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList17){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[16], impProList);
        }
        if(dc.size() > 17){
            List<ProductTypes__c> ptList18 = new List<ProductTypes__c>();
            List<String> dcList = dc[17].split('-');
            if (dcList.size() > 1) {
                ptList18 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList18 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList18){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[17], impProList);
        }
        if(dc.size() > 18){
            List<ProductTypes__c> ptList19 = new List<ProductTypes__c>();
            List<String> dcList = dc[18].split('-');
            if (dcList.size() > 1) {
                ptList19 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList19 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList19){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[18], impProList);
        }
        if(dc.size() > 19){
            List<ProductTypes__c> ptList20 = new List<ProductTypes__c>();
            List<String> dcList = dc[19].split('-');
            if (dcList.size() > 1) {
                ptList20 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList20 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList20){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[19], impProList);
        }
        if(dc.size() > 20){
            List<ProductTypes__c> ptList21 = new List<ProductTypes__c>();
            List<String> dcList = dc[20].split('-');
            if (dcList.size() > 1) {
                ptList21 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList21 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList21){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[20], impProList);
        }
        if(dc.size() > 21){
            List<ProductTypes__c> ptList22 = new List<ProductTypes__c>();
            List<String> dcList = dc[21].split('-');
            if (dcList.size() > 1) {
                ptList22 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList22 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList22){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[21], impProList);
        }
        if(dc.size() > 22){
            List<ProductTypes__c> ptList23 = new List<ProductTypes__c>();
            List<String> dcList = dc[22].split('-');
            if (dcList.size() > 1) {
                ptList23 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList23 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList23){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[22], impProList);
        }
        if(dc.size() > 23){
            List<ProductTypes__c> ptList24 = new List<ProductTypes__c>();
            List<String> dcList = dc[23].split('-');
            if (dcList.size() > 1) {
                ptList24 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0] and OPD_SIS_Type__c =:dcList[1]];
            } else {
                ptList24 = [select Id, Name, Department_Cateogy__c, OPD_Flg__c, SIS_Flg__c from ProductTypes__c where DeleteFlg__c = false and Department_Cateogy_Text__c like :dcList[0]];
            }
            List<Map<String,String>> impProList = new List<Map<String,String>>();
            for(ProductTypes__c pt : ptList24){
                Map<String,String> productMap = new Map<String,String>();
                productMap.put('label', pt.Name);
                productMap.put('value', pt.Id);
                impProList.add(productMap);
            }
            impProMap.put(dc[23], impProList);
        }
 
        return impProMap;
        
    }
    // 批量添加周报by vivek end 
}