李彤
2022-11-16 3d8a1f5c0952d3d62b8c24432f8525871c32e591
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
//BEFORE -- 设置GI/SP 助理和5个战略科室所有人的共享
//NOW ----- 设置GI/SP助理 和5个医院下所有战略科室所有人的共享
// { 1. 根据OCSM管理省 给GI和SP助理  信息负责人(助理),行政窗口 ,备品窗口 赋值 信息负责人助理设置GI助理
//3.给关联医院的所有启用战略科室下的所有启用所有人设置销售共享 ,给招投标项目的行政窗口和备品窗口设置共享 ,给招投标项目的GI/SP助理设置共享}
 
//设置GI/SP/销售助理的值 和共享
public without sharing class TenderInformationHandler extends Oly_TriggerHandler {
    private Map<Id, Tender_information__c> newMap;
    private Map<Id, Tender_information__c> oldMap;
    private List<Tender_information__c> newList;
    private List<Tender_information__c> oldList;
 
 
    public TenderInformationHandler() {
        this.newMap = (Map<Id, Tender_information__c>) Trigger.newMap;
        this.oldMap = (Map<Id, Tender_information__c>) Trigger.oldMap;
        this.newList = (List<Tender_information__c>) Trigger.new;
        this.oldList = (List<Tender_information__c>) Trigger.old;
    }
 
    //根据新建的OCSM管理省字段,根据OCSM管理省对象GI,SP助理, 行政窗口 ,备品窗口  给这个招投标项目的GI,SP助理,行政窗口,备品窗口 ,信息负责人(助理)赋值;
    protected override void beforeInsert() {
        AssignValueToAssistant();
        // add 【委托】P-招标项目-手动创建的招标项目增加必填字段 2021/11/03 fxk Star
        for (Tender_information__c ten : newList) {
            if (ten.RecordTypeId == '0121m000000bKzA' || ten.RecordTypeId == '01210000000VLZ8') {
                ten.OwnerId = '00510000000gmxH';
                if(ten.Hospital__c != null
                    || ten.Hospital1__c != null
                    || ten.Hospital2__c != null
                    || ten.Hospital3__c != null
                    || ten.Hospital4__c != null){
                    ten.IsRelateProject__c = '是';
                    ten.relativeTime__c = Datetime.now();
                }
                updateTenOwner();
            }
        }
        // add 【委托】P-招标项目-手动创建的招标项目增加必填字段 2021/11/03 fxk End
    }
 
    protected override void beforeUpdate() {
        //反逻辑删除 fxk
        changeRelateOppDate();
        updateTenDel();
        AssignValueToAssistant();
        if (!StaticParameter.EscapeOtherUpdateTenOwner) {
            updateTenOwner();
        }
        // 20221011 ljh  SWAG-CK28WT start
        updateTenOwnerJC();
        // 20221011 ljh  SWAG-CK28WT end
        //20220804 you 询价任务
        updateOppotunityBeforeUpdate();
        
    }
 
    protected override void afterInsert() {
        // 根据上面赋值的GI、SP助理,行政窗口,备品窗口,更新共享,共享原因不一样
        addShare();
        //sednMessage(); 20220729 you 招标项目 取消发送邮件通知
        // updateTenOwner();
    }
    protected override void afterUpdate() {
        addShare();        
        //sednMessage(); 20220729 you 招标项目 取消发送邮件通知
        updateWin();
 
        // 中标任务 废标流标时清空中标日
        clearConfirmationofAward();
 
        //2022-3-29 yjk SWAG-CCL6R7
        //updateOpportunity();//2022-5-18 yjk XLIU-CEJ38N 注释掉 
    }
 
    //修改项目阶段,由 结果变为其他,,相关任务取消
    public void updateOppotunityBeforeUpdate() {
        Set<String> Tenids = new Set<String>();//招标项目id,查询link
        Set<String> oppTens = new Set<String>();//招标项目id,查询link
        List<String> oppIds = new List<String>();//询价
        // 获得要更新的询价
        for (Tender_information__c record: newList) {
           if ( ( ('3-5:中标通知'.equals((oldMap.get(record.Id).subInfoType__c)) || '3-6:合同公告'.equals((oldMap.get(record.Id).subInfoType__c)) ) && ('3-1:废标公告'.equals(record.subInfoType__c)  || '3-2:流标公告'.equals(record.subInfoType__c) )) || (!'3:结果'.equals(record.InfoType__c) && '3:结果'.equals((oldMap.get(record.Id).InfoType__c)))) {
                Tenids.add(record.id);
            }
        }
        Map<String,String> InfoTypeMap = new Map<String,String>(); //判断是否是因为中标修改得
        if(null!=Tenids && Tenids.size()>0){
            
            List<Tender_Opportunity_Link__c> TenOppLinkList = [select id, Tender_information__c,Tender_information__r.InfoType__c, Opportunity__c from Tender_Opportunity_Link__c where Tender_information__c in :Tenids];
            if(null!=TenOppLinkList && TenOppLinkList.size()>0){
                for(Tender_Opportunity_Link__c topl :TenOppLinkList){
                    String oppid =String.valueOf(topl.Opportunity__c);
                    String tenid =String.valueOf(topl.Tender_information__c);
                    oppTens.add(oppid.subString(0,15)+tenid.subString(0,15));
                    if (!oppIds.contains(topl.Opportunity__c)) {
                        oppIds.add(topl.Opportunity__c);
                    }
                    if(!'3:结果'.equals(topl.Tender_information__r.InfoType__c)){
                       InfoTypeMap.put(topl.Opportunity__c,topl.Tender_information__c); 
                    }   
                }
            }
        }
        if (null!=oppTens && oppTens.size()>0) {
          List<Opportunity> opportunities = [select id, Bidding_Project_Name_Bid__c, TenderBeginDate_Text__c,Opp_Order__c from Opportunity where id in :oppIds];
           List<task__c> taskList = [select id,taskStatus__c,Tender_information_Task__c,OpportunityId__c from task__c where (RecordType.Name ='失单报告任务' and OpportunityId__c in:oppIds) or (RecordType.Name ='中标结果确认' and Opp_Tender__c in :oppTens)];
            for(task__c tsk : taskList){
                tsk.taskStatus__c = '04 取消';
                tsk.cancelDate__c = date.today();
                if(null!=InfoTypeMap && InfoTypeMap.containsKey(tsk.OpportunityId__c)){
                   tsk.cancelReasonSelect__c = '修改项目阶段';
                }else{
                   tsk.cancelReasonSelect__c = '流标/废标'; 
                }
            }
             update taskList;
            if(taskList.size() > 0){
                for (task__c tlink : taskList) {
                    for (Opportunity opp : opportunities) {
                        if (opp.Id == tlink.OpportunityId__c) {
                           //20220718 you 询价任务 start
                            opp.ConfirmationofAward__c = null;
                            opp.Task_createTime__c = null;
                            opp.ConfirmationofAward_createTime__c =null;
                            opp.LostTask_comfirmTime__c =null;
                            opp.Is_ConfirmationofAward__c =null;
                            opp.LostTask_createTime__c =null;
                            opp.Closing_Bid_Date__c = null;
                            //20220718 you 询价任务 end
                       }  
                    }
                }
            } 
            update opportunities;   
        }
    }    
    //20220718 you 询价任务 end
    // 20221027 updateOpportunity() 全文搜索过 没有调用的,方法引用已经注释,覆盖率不够方法体也注释(SWAG-CKL5UC),
    //2022-3-29 yjk SWAG-CCL6R7
    /*private void updateOpportunity(){
        for(Tender_information__c newOne : newList){
            Tender_information__c oldOne = oldMap.get(newOne.id);
            if(oldOne.ResultDate__c == null && newOne.ResultDate__c != null){
                List<Opportunity> oppList = [select id,Closing_Bid_Date__c  from Opportunity where Bidding_Project_Name_Bid__c = :newOne.id];
                if(oppList.size() > 0){
                    for(Opportunity opp : oppList){
                        opp.Closing_Bid_Date__c = newOne.ResultDate__c;
                    }
                    update oppList;
                }
            }
        }
    }*/
    //20220729 you 
    //public void sednMessage() {
    //    //规则条件
    //    //ISCHANGED(InfoType__c) && Text(InfoType__c) = '3:结果' && (Text(IsBid__c) = '是' || ( Text(IsBid__c) = '否' && OpportunityNum__c != null && OpportunityNum__c > 0) )
    //    // 1)没有关联询价,确认相关性,那么就发给GI和SP助理;
    //    // 2)关联询价后,询价的所有人、项目所有人,GI和SP助理,收邮件;
    //    //关联询价 发给询价所有人 招标项目所有人
    //    //没有关联询价并且做了相关性确认 发给招标项目所有人
 
    //    //1.判断是否符合大条件 拿到招标id
    //    Set<Id> zbIds = new Set<Id>();
    //    //拿到招标id , 招标所有人 GI/SP助理 的邮件地址
    //    Map<Id, Set<String>> zbOppMap = new Map<Id, Set<String>>();
    //    List<Tender_information__c> tlist = new List<Tender_information__c>();
 
    //    for (Tender_information__c ten : newList) {
    //        // if (ten.InfoType__c == '3:结果' &&
    //        //     (ten.IsBid__c == '是' || (ten.IsBid__c == '否' && ten.OpportunityNum__c != null && ten.OpportunityNum__c > 0))
    //        //     && (Trigger.isInsert || (Trigger.isUpdate && oldMap.get(ten.Id).InfoType__c != '3:结果'))) {
    //        //     zbIds.add(ten.Id);
    //        // }
    //        // 判断条件修改
    //        if (ten.InfoType__c == '3:结果' && (Trigger.isInsert || (Trigger.isUpdate && oldMap.get(ten.Id).InfoType__c != '3:结果'))) {
    //            // 如果招标所有人为系统管理员(OlympusSystem)时需要跳过
    //            if (ten.Ownerid != '00510000000gmxH') {
    //                zbIds.add(ten.Id);
    //            }
    //        }
    //    }
    //    if (zbIds.size() > 0) {
    //        tlist = [select Id, GI_assistant__r.Email, SP_assistant__r.Email, Hospital__r.Name, BudgetAmount__c, Name, department__r.Name, OpenBidingTime__c, Owner.Alias, Owner.Email from Tender_information__c where id in :zbIds];
    //        for (Tender_information__c ten : tlist) {
    //            if (!zbOppMap.containsKey(ten.Id)) {
    //                zbOppMap.put(ten.Id, new Set<String>());
    //            }
    //            zbOppMap.get(ten.Id).add(ten.Owner.Email);
 
    //        }
    //        //取得询价
    //        // 招标-询价关联修改 20210817 start
    //        // List<Opportunity> oppList = new List<Opportunity>();
    //        // oppList = [select id,Owner.Email,Bidding_Project_Name_Bid__c,Bidding_Project_Name_Bid__r.owner.Email from Opportunity where Bidding_Project_Name_Bid__c in :zbIds];
    //        // if (oppList.size() > 0) {
    //        //     for (Opportunity opp : oppList) {
    //        //         // 能走到这说明 询价的所有人、项目所有人 也得发邮件
    //        //         if (!zbOppMap.containsKey(opp.Bidding_Project_Name_Bid__c)) {
    //        //             zbOppMap.put(opp.Bidding_Project_Name_Bid__c, new Set<String>());
    //        //         }
    //        //         zbOppMap.get(opp.Bidding_Project_Name_Bid__c).add(opp.Owner.Email);
    //        //         // zbOppMap.get(opp.Bidding_Project_Name_Bid__c).add(opp.Bidding_Project_Name_Bid__r.owner.Email);
    //        //     }
    //        // }
    //        List<Tender_Opportunity_Link__c> link_list = [select id, Tender_information__c, Opportunity__r.Owner.Email from Tender_Opportunity_Link__c where Tender_information__c in :zbIds];
    //        if (link_list != null && link_list.size() > 0) {
    //            for (Tender_Opportunity_Link__c link : link_list) {
    //                // 能走到这说明 询价的所有人、项目所有人 也得发邮件
    //                if (!zbOppMap.containsKey(link.Tender_information__c)) {
    //                    zbOppMap.put(link.Tender_information__c, new Set<String>());
    //                }
    //                zbOppMap.get(link.Tender_information__c).add(link.Opportunity__r.Owner.Email);
    //            }
    //        }
    //        // 招标-询价关联修改 20210817 end
    //    }
 
    //    if (zbOppMap.size() > 0) {
    //        if (tlist.size() > 0) {
    //            List<Messaging.SingleEmailMessage> sendMails = new List<Messaging.SingleEmailMessage>();
 
    //            for (Tender_information__c ten : tlist) {
    //                if (zbOppMap.containsKey(ten.Id)) {
    //                    String body = '';
    //                    String title = '';
    //                    String BudgetAmount = ten.BudgetAmount__c == null ? '' : ten.BudgetAmount__c + '';
    //                    String HospitalName = ten.Hospital__c == null ? '' : ten.Hospital__r.Name;
    //                    String departmentName = ten.department__c == null ? '' : ten.department__r.Name;
    //                    String OpenBidingTime = ten.OpenBidingTime__c == null ? '' : ten.OpenBidingTime__c.format();
 
    //                    title = '中标结果:' + ten.Hospital__r.Name + ' 预算金额' + BudgetAmount + '已有中标结果请确认';
 
    //                    body += '项目名:' + ten.Name + '<br/>';
    //                    body += '预算金额:' + BudgetAmount + '<br/>';
    //                    body += '医院:' + HospitalName + '<br/>';
    //                    // body += '战略科室:'+departmentName + '<br/>';
    //                    body += '中标日:' + OpenBidingTime + '<br/>';
    //                    body += '主担当:' + ten.Owner.Alias + '<br/>';
    //                    body += '招投标链接: <br/>';
    //                    body += '<a href="' + URL.getSalesforceBaseUrl().toExternalForm() + '/' + ten.Id  + '">' + URL.getSalesforceBaseUrl().toExternalForm() + '/' + ten.Id + '</a><br/>';
    //                    // body += '收件人: '+zbOppMap.get(ten.Id);
 
    //                    List<String> toMailList = new List<String>();
    //                    // List<String> toccList = new List<String>();
    //                    // emas.add(UserInfo.getUserEmail());
    //                    //收信人
    //                    toMailList.addAll(zbOppMap.get(ten.Id));
    //                    // if (toMailList.contains(null)) {
    //                    // toMailList.remove(null);
    //                    // }
    //                    // toMailList.add('rentongxiao@prec-tech.com');
    //                    //抄送人
    //                    // toccList.add('gzw@prec-tech.com');
    //                    // toccList.add('rentongxiao@prec-tech.com');
    //                    Messaging.SingleEmailMessage messageNEW = new Messaging.SingleEmailMessage();
    //                    messageNEW.subject = title;
    //                    //messageNEW.plainTextBody = body;
    //                    messageNEW.htmlBody = body;
    //                    messageNEW.setCharset('UTF-8');
    //                    messageNEW.toAddresses = toMailList;
    //                    // messageNEW.ccAddresses = toccList;
    //                    sendMails.add(messageNEW);
    //                }
    //            }
 
    //            if (sendMails.size() > 0) {
    //                for (Messaging.SingleEmailMessage mc : sendMails) {
    //                    List<Messaging.SingleEmailMessage> tempsendMails = new List<Messaging.SingleEmailMessage>();
    //                    tempsendMails.add(mc);  
    //                    Messaging.SendEmailResult[] results = null;                      
    //                    if (!NFMUtil.isSandbox()) {
    //                        results = messaging.sendEmail(tempsendMails);
    //                    }
    //                    if (results != null && results.size() > 0) {
    //                        for (Integer i = 0; i < results.size(); i++) {
    //                            if (results[i].success == false) {
    //                                System.debug('邮件:::' + mc.getSubject() + '发送失败');
    //                            } else {
    //                                System.debug('邮件:::' + mc.getSubject() + '发送成功');
    //                            }
    //                        }
    //                    }
    //                }
    //            }
    //        }
    //    }
    //}
 
 
 
    public void addShare() {
        //1.获得医院
        Set<Id> hpIdsets = new Set<Id>();
        for (Tender_information__c info : newList) {
            if (info.Hospital__c != null) {
                hpIdsets.add(info.Hospital__c);
            }
            if (info.Hospital1__c != null) {
                hpIdsets.add(info.Hospital1__c);
            }
            if (info.Hospital2__c != null) {
                hpIdsets.add(info.Hospital2__c);
            }
            if (info.Hospital3__c != null) {
                hpIdsets.add(info.Hospital3__c);
            }
            if (info.Hospital4__c != null) {
                hpIdsets.add(info.Hospital4__c);
            }
 
        }
 
        if (hpIdsets.contains(null)) {
            hpIdsets.remove(null);
        }
 
        List<Account> accList = new List<Account>();
        if (hpIdsets.size() > 0) {
            //获取医院下所有启用战略科室的启用所有人
            //取得战略科室:
            // accList = [select id,OwnerId,ParentId,OwnerIsActive__c from Account where Parent.RecordType_DeveloperName__c = 'HP'
            //                                          AND OwnerIsActive__c = true
            //                                          AND ParentId  in :hpIdsets];
            //获取医院上的主担当
            accList = [select id, GI_Main__c, GI_Main__r.IsActive, BF_owner__c, BF_owner__r.IsActive,
                       ET_owner__c, ET_owner__r.IsActive, SP_Main__c, SP_Main__r.IsActive, URO_owner_ID__c, URO_owner_ID__r.IsActive,
                       GYN_owner__c, GYN_owner__r.IsActive, ENT_owner_ID__c, ENT_owner_ID__r.IsActive, Energy_LeaderStr__c
                       from Account where  Id in :hpIdsets ];
            // updateTenOwner(newList, accList);
        }
 
        //获取共享原因
        String rowCauseGI = Schema.Tender_information__Share.RowCause.GI_assistant__c;
        String rowCauseSP = Schema.Tender_information__Share.RowCause.SP_assistant__c;
        String rowCauseSale = Schema.Tender_information__Share.RowCause.SalesOwner__c;
        String rowCauseAdministrative = Schema.Tender_information__Share.RowCause.Administrative_assistant__c;
        String rowCauseBeipin = Schema.Tender_information__Share.RowCause.Beipin_assistant__c;
        String rowCauseTender = Schema.Tender_information__Share.RowCause.TenderAssistant__c;
        //营业窗口的共享原因
        String rowCauseYingye = Schema.Tender_information__Share.RowCause.YingyeWindow__c;
 
        List<String> rowCauseList = new List<String>();
        rowCauseList.add(rowCauseGI);
        rowCauseList.add(rowCauseSP);
        rowCauseList.add(rowCauseSale);
        rowCauseList.add(rowCauseAdministrative);
        rowCauseList.add(rowCauseBeipin);
        rowCauseList.add(rowCauseTender);
        rowCauseList.add(rowCauseYingye);
 
 
        //以 医院id 和战略科室所有人id集合为map
        // Map<Id,Set<Id>> hpDepartmentMap = new Map<Id,Set<Id>>();
        // if (accList.size() > 0) {
        //     for (Account department : accList) {
        //         if (!hpDepartmentMap.containsKey(department.ParentId)) {
        //             hpDepartmentMap.put(department.ParentId, new Set<Id>());
        //         }
        //         hpDepartmentMap.get(department.ParentId).add(department.OwnerId);
        //     }
        // }
        //能量担当需要单独查一下
        List<String> ddNameListtrim = new List<String>();
        List<String> ddNameList = new List<String>();
        for (Account hp : accList) {
            if (hp.Energy_LeaderStr__c != null && hp.Energy_LeaderStr__c != '') {
                // update fxk 2021/10/26 star
                String str = hp.Energy_LeaderStr__c.replaceAll(' ', '');
                String name = str.subString(0, 1) + ' ' + str.subString(1, str.length());
                ddNameListtrim.add(name);
                ddNameList.add(str);
                // update fxk 2021/10/26 end
            }
        }
        //查询用户 获取id
        List<User> ulist = new List<User>();
        ulist = [select id, Alias, IsActive, Name from user where IsActive = true and (Alias in :ddNameList or Alias in :ddNameListtrim)];
        Map<String, Id> uidmap = new Map<String, Id>();
        if (ulist != null && ulist.size() > 0) {
            for (User u : ulist) {
                uidmap.put(u.Name, u.Id);
            }
        }
        // upd 用户勾选了战略科室的话,这条招标信息只有关联医院对应的战略科室主担当可以看到,否则医院所有科室主担当都能看到 2021、9、22 fxk Star
        // Map<Id, Set<Id>> hpDepartmentMap = new Map<Id, Set<Id>>();
        Map<Id, Map<String, Id>> hpDepartmentMap = new Map<Id, Map<String, Id>>();
        if (accList.size() > 0) {
            for (Account hp : accList) {
                //消化科主担当
                // Set<Id> ddIds = new Set<Id>();
                Map<String, Id> ddmap = new Map<String, Id>();
                if (hp.GI_Main__c != null && hp.GI_Main__r.IsActive ) {
                    // System.debug('-------2------' + tenDepartMap.get(info.Id));
                    // ddIds.add(hp.GI_Main__c);
                    ddmap.put('01210000000QemLAAS', hp.GI_Main__c);
                }
                // 呼吸科主担当
                if (hp.BF_owner__c != null && hp.BF_owner__r.IsActive ) {
                    // System.debug('-------3------' + hp.BF_owner__c);
                    // ddIds.add(hp.BF_owner__c);
                    ddmap.put('01210000000QezZAAS', hp.BF_owner__c);
                }
                // ET科主担当
                // if (hp.ET_owner__c != null && hp.ET_owner__r.IsActive) {
                //     // System.debug('-------3------' + hp.ET_owner__r);
                //     // ddIds.add(hp.ET_owner__c);
                //     ddmap.put(hp.Department_Class__r.RecordTypeId, hp.GI_Main__c);
                // }
                // 普外科主担当
                if (hp.SP_Main__c != null && hp.SP_Main__r.IsActive) {
                    // System.debug('-------3------' + hp.SP_Main__r);
                    // ddIds.add(hp.SP_Main__c);
                    ddmap.put('01210000000QezeAAC', hp.SP_Main__c);
                }
                // 泌尿科主担当
                if (hp.URO_owner_ID__c != null && hp.URO_owner_ID__r.IsActive) {
                    // System.debug('-------3------' + hp.URO_owner_ID__r);
                    // ddIds.add(hp.URO_owner_ID__c);
                    ddmap.put('01210000000QezjAAC', hp.URO_owner_ID__c);
                }
                // 妇科主担当
                if (hp.GYN_owner__c != null && hp.GYN_owner__r.IsActive) {
                    // System.debug('-------3------' + hp.GYN_owner__r);
                    // ddIds.add(hp.GYN_owner__c);
                    ddmap.put('01210000000QezoAAC', hp.GYN_owner__c);
                }
                // 耳鼻喉科主担当
                if (hp.ENT_owner_ID__c != null && hp.ENT_owner_ID__r.IsActive) {
                    // System.debug('-------3------' + hp.ENT_owner_ID__r);
                    // ddIds.add(hp.ENT_owner_ID__c);
                    ddmap.put('01210000000QeztAAC', hp.ENT_owner_ID__c);
                }
                //能量担当
 
                if (hp.Energy_LeaderStr__c != null) {
 
                    String str = hp.Energy_LeaderStr__c.replaceAll(' ', '');
                    String name = str.subString(0, 1) + ' ' + str.subString(1, str.length());
                    // update fxk 2021/10/26 star
                    if (uidmap.containsKey(hp.Energy_LeaderStr__c)) {
                        // ddIds.add(uidmap.get(hp.Energy_LeaderStr__c));
                        // ddIds.add(uidmap.get(name));
                        ddmap.put('nengliang', uidmap.get(hp.Energy_LeaderStr__c));
 
                    }else if(uidmap.containsKey(name)){
                        ddmap.put('nengliang', uidmap.get(name));
                    }
                    // update fxk 2021/10/26 end
                }
                // ddIds.remove(null);
                ddmap.remove(null);
                if (ddmap.size() > 0) {
                    // hpDepartmentMap.put(hp.Id, ddIds);
                    hpDepartmentMap.put(hp.Id, ddmap);
                }
            }
        }
        // upd 用户勾选了战略科室的话,这条招标信息只有关联医院对应的战略科室主担当可以看到,否则医院所有科室主担当都能看到 2021、9、22 fxk End
 
 
        //待共享的数据
        //取值顺序是:所有人,之后是gi助理,接下来是sp助理,接下来是战略科室所有人 所以倒着来
        List<Tender_information__Share> tenShareList = new List<Tender_information__Share>();
        for (Tender_information__c tenc : newList) {
            // 20221013 ljh SWAG-CK28WT start
            // 集采项目 后续共享不需要,只把原来的共享删除
            if(tenc.CentralizedProject__c){
                continue;
            }
            // 20221013 ljh SWAG-CK28WT start
            //一个map为 针对一条招投标计划的共享
            Map<Id, Tender_information__Share> sharemap = new Map<Id, Tender_information__Share>();
            //1.先设置 医院担当的共享
            //获取5个医院
            Map<Id, String> hmap = new Map<Id, String>();
            hmap.put(tenc.Hospital__c, tenc.Hospital__c);
            hmap.put(tenc.Hospital1__c, tenc.Hospital1__c);
            hmap.put(tenc.Hospital2__c, tenc.Hospital2__c);
            hmap.put(tenc.Hospital3__c, tenc.Hospital3__c);
            hmap.put(tenc.Hospital4__c, tenc.Hospital4__c);
            hmap.remove(null);
            if (hpDepartmentMap.size() > 0) {
                for (Id hpId : hpDepartmentMap.keySet()) {
                    if (hmap.containsKey(hpId)) {
                        // upd 用户勾选了战略科室的话,这条招标信息只有关联医院对应的战略科室主担当可以看到,否则医院所有科室主担当都能看到 2021、9、22 fxk Star
                        Map<String, String> tempMap = new Map<String, String>();
                        if (tenc.department_selection__c != null) {
                            System.debug('=========1=======' + tenc.department_selection__c);
                            List<String> tenDepartList = tenc.department_selection__c.split(';');
                            for (String departs : tenDepartList) {
                                tempMap.put(departs, '');
                            }
                            // tempMap.put('nengliang', '');
                        } else {
                            System.debug('=========2=======' + tenc.department_selection__c);
                            tempMap.put('01210000000QemLAAS', '');
                            tempMap.put('01210000000QezZAAS', '');
                            tempMap.put('01210000000QezeAAC', '');
                            tempMap.put('01210000000QezjAAC', '');
                            tempMap.put('01210000000QezoAAC', '');
                            tempMap.put('01210000000QeztAAC', '');
                            tempMap.put('nengliang', '');
                        }
                        Map<String, Id> departToMainmap = hpDepartmentMap.get(hpId);
                        for (String depart : tempMap.keySet()) {
                            if (departToMainmap.containsKey(depart)) {
                                if (tenc.OwnerId != departToMainmap.get(depart)) {
                                    Tender_information__Share aos = new Tender_information__Share(
                                        RowCause = rowCauseSale,
                                        ParentId = tenc.Id,
                                        UserOrGroupId = departToMainmap.get(depart),
                                        AccessLevel = 'Edit');
                                    sharemap.put(departToMainmap.get(depart), aos);
                                }
                            }
                        }
                        // for (Id uId : hpDepartmentMap.get(hpId)) {
                        //     if (tenc.OwnerId != uId) {
                        //         Tender_information__Share aos = new Tender_information__Share(
                        //             RowCause = rowCauseSale,
                        //             ParentId = tenc.Id,
                        //             UserOrGroupId = uId,
                        //             AccessLevel = 'Edit');
                        //         sharemap.put(uId, aos);
 
                        //     }
                        // }
                        // upd 用户勾选了战略科室的话,这条招标信息只有关联医院对应的战略科室主担当可以看到,否则医院所有科室主担当都能看到 2021、9、22 fxk End
 
                    }
                }
            }
            //行政窗口
            if (tenc.OwnerId != tenc.Window2__c  && tenc.Window2__c != null) {
                Tender_information__Share aos = new Tender_information__Share(
                    RowCause = rowCauseAdministrative,
                    ParentId = tenc.Id,
                    UserOrGroupId = tenc.Window2__c,
                    AccessLevel = 'Edit');
                sharemap.put(tenc.Window2__c, aos);
            }
            //备品窗口
            // if (tenc.OwnerId != tenc.beiPinwindow__c  && tenc.beiPinwindow__c != null){
            //     Tender_information__Share aos = new Tender_information__Share(
            //         RowCause = rowCauseBeipin,
            //         ParentId = tenc.Id,
            //         UserOrGroupId = tenc.beiPinwindow__c,
            //         AccessLevel = 'Edit');
            //     sharemap.put(tenc.beiPinwindow__c, aos);
            // }
            //招标项目助理2
            if (tenc.OwnerId != tenc.TenderAssistant2__c && tenc.TenderAssistant2__c != null) {
                Tender_information__Share aos = new Tender_information__Share(
                    RowCause = rowCauseTender,
                    ParentId = tenc.Id,
                    UserOrGroupId = tenc.TenderAssistant2__c,
                    AccessLevel = 'Edit');
                sharemap.put(tenc.TenderAssistant2__c, aos);
            }
            //招标项目助理1
            if (tenc.OwnerId != tenc.TenderAssistant1__c && tenc.TenderAssistant1__c != null) {
                Tender_information__Share aos = new Tender_information__Share(
                    RowCause = rowCauseTender,
                    ParentId = tenc.Id,
                    UserOrGroupId = tenc.TenderAssistant1__c,
                    AccessLevel = 'Edit');
                sharemap.put(tenc.TenderAssistant1__c, aos);
            }
            //营业窗口
            if (tenc.OwnerId != tenc.YingyeWindow__c && tenc.YingyeWindow__c != null) {
                Tender_information__Share aos = new Tender_information__Share(
                    RowCause = rowCauseYingye,
                    ParentId = tenc.Id,
                    UserOrGroupId = tenc.YingyeWindow__c,
                    AccessLevel = 'Edit');
                sharemap.put(tenc.YingyeWindow__c, aos);
            }
 
            //2.SP助理
            if (tenc.OwnerId != tenc.SP_assistant__c && tenc.SP_assistant__c != null) {
                Tender_information__Share aos = new Tender_information__Share(
                    RowCause = rowCauseSP,
                    ParentId = tenc.Id,
                    UserOrGroupId = tenc.SP_assistant__c,
                    AccessLevel = 'Edit');
                sharemap.put(tenc.SP_assistant__c, aos);
            }
            //3.GI助理
            if (tenc.OwnerId != tenc.GI_assistant__c  && tenc.GI_assistant__c != null) {
                Tender_information__Share aos = new Tender_information__Share(
                    RowCause = rowCauseGI,
                    ParentId = tenc.Id,
                    UserOrGroupId = tenc.GI_assistant__c,
                    AccessLevel = 'Edit');
                sharemap.put(tenc.GI_assistant__c, aos);
            }
            tenShareList.addAll(sharemap.values());
 
        }
        
        //现在用的是全删全加的方法,没有再判断是否发生改变了
        //删除
        List<Tender_information__Share> beforeShareList =
            [select id from Tender_information__Share
             where ParentId in :newMap.keySet()
             and RowCause in :rowCauseList];
        //先删
        if (beforeShareList != null && beforeShareList.size() > 0) {
            delete beforeShareList;
        }
        //再加
        if (tenShareList.size() > 0) {
            insert tenShareList;
        }
    }
 
    /**
     * 2022-04-03 增加判断 当用户无效时也跳过设置
     */
    public void AssignValueToAssistant() {
        //根据ocsm管理省的助理设置当前招投标项目的gi/sp助理
        Map<String, OCM_Management_Province__c> mpMap = new Map<String, OCM_Management_Province__c>();
 
        for (OCM_Management_Province__c mp : [SELECT id, Name, GI_assistant__c, SP_assistant__c, SP_assistant__r.IsActive, GI_assistant__r.IsActive, Window2__c, Window2__r.IsActive, Admin_assistant3__c, Admin_assistant3__r.IsActive, TenderAssistant1__c, TenderAssistant1__r.IsActive, TenderAssistant2__c, TenderAssistant2__r.IsActive, Window1__c, Window1__r.IsActive FROM OCM_Management_Province__c]) {
            mpMap.put(mp.Name, mp);
        }
        //设置GI/SP助理  行政助理、备品窗口
        //直接设置 信息负责人(助理) 为GI助理
        for (Tender_information__c info : newList) {
            //用户自己选 所有人需要和用户选的人保持一致;
            // if (info.OwnerId != info.departmentOwner__c && info.departmentOwner__c != null) {
            //     info.OwnerId = info.departmentOwner__c;
            // }
            //不能判断ocsm管理省是否发生改变了 会有历史数据
            if (info.OCSMProvince__c != null) {
                OCM_Management_Province__c ocm = mpMap.get(info.OCSMProvince__c);
                if (ocm != null) {
                    //设置OCSM管理省查找字段的值 20210728 start  为了更新历史数据 直接赋值即可
                    // if (Trigger.isInsert || (Trigger.isUpdate && oldMap.get(info.Id).OCSMProvince__c != info.OCSMProvince__c)) {
                    info.OCSMProvinceS__c = ocm.Id;
                    // }
                    //设置OCSM管理省查找字段的值 20210728 end
                    // GI助理为空时__r.IsActive返回false 20210813
                    if (ocm.GI_assistant__r.IsActive ) {
                        if (info.GI_assistant__c != ocm.GI_assistant__c) {
                            info.GI_assistant__c = ocm.GI_assistant__c;
                        }
                        if (info.InfoOwner__c != ocm.GI_assistant__c) {
                            if(info.CentralizedProject__c == false){ // 20221012 ljh SWAG-CK28WT 添加的if
                                info.InfoOwner__c = ocm.GI_assistant__c;
                            }
                        }
                    }
                    // 增加GI助理为空时的处理,清空招标项目的GI助理和信息负责人(助理) 20210813
                    else if (ocm.GI_assistant__c == null || !ocm.GI_assistant__r.IsActive) {
                        info.GI_assistant__c = null;
                        if(info.CentralizedProject__c == false){ // 20221012 ljh SWAG-CK28WT 添加的if
                            info.InfoOwner__c = null;
                        }
                    }
                    if (ocm.SP_assistant__r.IsActive && info.SP_assistant__c != ocm.SP_assistant__c) {
                        info.SP_assistant__c = ocm.SP_assistant__c;
                    }
                    // 增加SP助理为空时的处理,清空招标项目的SP助理 20210813
                    else if (ocm.SP_assistant__c == null || !ocm.GI_assistant__r.IsActive) {
                        info.SP_assistant__c = null;
                    }
                    if (ocm.Window2__r.IsActive && info.Window2__c != ocm.Window2__c) {
                        info.Window2__c = ocm.Window2__c;
                    }
                    // 清空行政窗口 20210813
                    else if (ocm.Window2__c == null || !ocm.Window2__r.IsActive) {
                        info.Window2__c = null;
                    }
                    //
                    // if (ocm.Admin_assistant3__r.IsActive && info.beiPinwindow__c != ocm.Admin_assistant3__c) {
                    //     info.beiPinwindow__c = ocm.Admin_assistant3__c;
                    // }
                    //设置招标助理1和招标助理2的值
                    if (ocm.TenderAssistant1__r.IsActive && info.TenderAssistant1__c != ocm.TenderAssistant1__c) {
                        info.TenderAssistant1__c = ocm.TenderAssistant1__c;
                    }
                    // 清空招标助理1 20210813
                    else if (ocm.TenderAssistant1__c == null || !ocm.TenderAssistant1__r.IsActive) {
                        info.TenderAssistant1__c = null;
                    }
                    if (ocm.TenderAssistant2__r.IsActive && info.TenderAssistant2__c != ocm.TenderAssistant2__c) {
                        info.TenderAssistant2__c = ocm.TenderAssistant2__c;
                    }
                    // 清空招标助理2 20210813
                    else if (ocm.TenderAssistant2__c == null || !ocm.TenderAssistant2__r.IsActive) {
                        info.TenderAssistant2__c = null;
                    }
 
                    //设置营业窗口  add by rentx 20210721
                    if (ocm.Window1__r.IsActive && info.YingyeWindow__c != ocm.Window1__c) {
                        info.YingyeWindow__c = ocm.Window1__c;
                    }
                    // 清空营业窗口 20210813
                    else if (ocm.Window1__c == null || !ocm.Window1__r.IsActive) {
                        info.YingyeWindow__c = null;
                    }
                }
                // add 战略科室分类为普外科、泌尿科、妇科、耳鼻喉科时,信息负责人(助理)修改为 SP助理 2021、11、11 fxk star
                if(info.department_selection__c != null){
                    List<String> tenDepartList = info.department_selection__c.split(';');
                    if(tenDepartList.contains('01210000000QezeAAC')
                        || tenDepartList.contains('01210000000QezjAAC')
                        || tenDepartList.contains('01210000000QezoAAC')
                        || tenDepartList.contains('01210000000QeztAAC')){
                        System.debug('=====-----'+info.department_selection__c);
                        if(info.CentralizedProject__c == false){ // 20221012 ljh SWAG-CK28WT 添加的if
                            info.InfoOwner__c = info.SP_assistant__c;
                        }
                        
                    }
                }
                // add 战略科室分类为普外科、泌尿科、妇科、耳鼻喉科时,信息负责人(助理)修改为 SP助理 2021、11、11 fxk end
                // 20221012 ljh SWAG-CK28WT start
                if(info.CentralizedProject__c){
                    // 清除这些人赋值 (就没有权限了)
                    info.GI_assistant__c = null;
                    info.SP_assistant__c = null;
                    info.Window2__c = null;
                    info.TenderAssistant1__c = null;
                    info.TenderAssistant2__c = null;
                    info.YingyeWindow__c = null;
                }
                // 20221012 ljh SWAG-CK28WT end
            }
            // 20221027 ljh SWAG-CKL5UC add start
            // 项目中当结果记录日有值公告记录日为空时,给公告记录日赋值逻辑=结果记录日-15天
            if(info.ResultDate__c != null && info.publicDate__c == null){
                info.publicDate__c = info.ResultDate__c.addDays(-15);
            }
            // 20221027 ljh SWAG-CKL5UC add start
        }
        
    }
// fxk 2021/8/3 反逻辑删除 Star
    private void updateTenDel() {
        List<Tender_information__c> updateTenList = new List<Tender_information__c>();
        for (Tender_information__c TenoldInfo : newList) {
            if (TenoldInfo.Logical_delete__c == false && (TenoldInfo.Logical_delete__c != oldMap.get(TenoldInfo.Id).Logical_delete__c)) {
                TenoldInfo.Retain_Tender__c = null;
            }
            if (TenoldInfo.Retain_Tender__c == null && (TenoldInfo.Retain_Tender__c != oldMap.get(TenoldInfo.Id).Retain_Tender__c)) {
                TenoldInfo.Logical_delete__c = false;
            }
        }
    }
 
    private void changeRelateOppDate(){
        System.debug(LoggingLevel.INFO, '*** 进入方法: ');
        List<String> oldUserOrGroups = new List<String>();
        Map<Id,Tender_information__c> tOldMap = (Map<Id,Tender_information__c>) Trigger.oldMap;
        Map<Id,Tender_information__c> tNewMap = (Map<Id,Tender_information__c>) Trigger.newMap;
        List<Date> cd = new List<Date>();
        System.debug(LoggingLevel.INFO, '*** cd: ' + cd);
        System.debug(LoggingLevel.INFO, '*** tOldMap: ' + tOldMap);
        for(Tender_information__c t:(List<Tender_information__c>) Trigger.new){
            System.debug(LoggingLevel.INFO, '*** 进入for循环: ');
            System.debug(LoggingLevel.INFO, '*** t: ' + t);
            if(Trigger.isUpdate){
                if (String.isNotBlank(t.IsRelateProject__c) && t.IsRelateProject__c == '是' && t.relativeTime__c == null && System.Label.ProfileId_2S6.equals(UserInfo.getProfileId())) {
                    t.relativeTime__c = Datetime.now();
                }
                System.debug(LoggingLevel.INFO, '*** tOldMap: ' + tOldMap.get(t.Id).relativeDate__c);
                System.debug(LoggingLevel.INFO, '*** t.relativeDate__c: ' + t.relativeDate__c);
                // if(tOldMap.get(t.Id).relativeDate__c != null && t.relativeDate__c != tOldMap.get(t.Id).relativeDate__c){
                //lt 20221114 DB202211270805 【紧急】招标项目是否按时关联计算错误 start
                // if(t.relativeDate__c != null && t.relativeDate__c != tOldMap.get(t.Id).relativeDate__c){
                if(((t.OBSAP_relativeTime__c != null || t.relativeTime_F__c != null) && t.Tender_Olympus__c == null) || (t.relativeDate__c != null && t.relativeDate__c != tOldMap.get(t.Id).relativeDate__c)){
                //lt 20221114 DB202211270805 【紧急】招标项目是否按时关联计算错误 end
                    System.debug(LoggingLevel.INFO, '*** 进入if语句: ');
                    String datastr = String.valueOf(t.relativeDate__c);
                    cd.add( Date.valueOf(datastr.substring(0,10)) );
                    System.debug(LoggingLevel.INFO, '*** cd: ' + cd);
                }
            }
        }
        Map<Date,String> lm = new Map<Date,String>();
        if(cd.size() > 0){
            for(OlympusCalendar__c oc:[SELECT Id,Date__c FROM OlympusCalendar__c WHERE Date__c IN:cd]){
                lm.put(oc.Date__c,oc.Id); 
                System.debug(LoggingLevel.INFO, '*** map赋值: ');    
            }
    
            for(Tender_information__c l:(List<Tender_information__c>) Trigger.new){
                //lt 20221114 DB202211270805 【紧急】招标项目是否按时关联计算错误 start
                // if (l.relativeDate__c == null) {
                //     continue;
                // }
                if (l.relativeDate__c == null && l.OBSAP_relativeTime__c == null) {
                    continue;
                }
                Datetime relativetime = l.OBSAP_relativeTime__c != null ? l.OBSAP_relativeTime__c : l.relativeTime__c;
                // String datastr = String.valueOf(l.relativeDate__c);
                String datastr = String.valueOf(relativetime);
                //lt 20221114 DB202211270805 【紧急】招标项目是否按时关联计算错误 end
                String dt = lm.get(Date.valueOf(datastr.substring(0,10)));
                System.debug(LoggingLevel.INFO, '*** dt: '+ dt);
                l.Tender_Olympus__c = dt;
                System.debug(LoggingLevel.INFO, '*** l.Tender_Olympus__c: '+ l.Tender_Olympus__c);
            }
        }
        
    }
// fxk 2021/8/3 反逻辑删除 end
// 20210824 中标时修改关联询价的招标项目名和中标时间
    private void updateWin() {
        List<String> tenderIds = new List<String>();
        List<String> lostWinIds = new List<String>();
        // 20221028 ljh SWAG-CKL5UC start
        Map<Id,Tender_information__c>  tendMap = New Map<Id,Tender_information__c>(); 
        Map<Id,Opportunity> updateOpp = New Map<Id,Opportunity>();
        // 20221028 ljh SWAG-CKL5UC end
        for (Tender_information__c ten : newList) {
            /** 20220614 SWAG-CFD4SU you 更改,询价优先显示项目阶段最新的招标项目信息
            if ('3:结果'.equals(ten.InfoType__c) && !'3:结果'.equals((oldMap.get(ten.Id).InfoType__c))) {
                tenderIds.add(ten.Id);
            } else if (!'3:结果'.equals(ten.InfoType__c) && '3:结果'.equals((oldMap.get(ten.Id).InfoType__c))) {
                lostWinIds.add(ten.Id);
            }
            **/
            //上线处理老数据
            if((String.isNotBlank(ten.InfoType__c) && ten.InfoType__c != oldMap.get(ten.Id).InfoType__c) || (String.isNotBlank(ten.subInfoType__c) && ten.subInfoType__c != oldMap.get(ten.Id).subInfoType__c)  || System.Label.TenderToOpp == '1'){
               tenderIds.add(ten.Id);
            }
            // 20221028 ljh SWAG-CKL5UC add start
            // 关联询价的 询价页面创建日晚于招标项目公告记录日,漏单数为1
            // 关联询价的 && 更新有值 
            if(ten.OpportunityNum__c > 0 && Trigger.isUpdate && oldMap.get(ten.Id).publicDate__c == null && ten.publicDate__c != null){
                tendMap.put(ten.Id, ten);
            }
            // 20221028 ljh SWAG-CKL5UC add end
            
        }
        if (tenderIds.size() > 0) {
            //20220616 SWAG-CFD4SU you 增加order by
            //查询招标项目下所有中间表
            List<Tender_Opportunity_Link__c> links =
                [SELECT id,
                 Tender_information__c,
                 Tender_information__r.OpenBidingTime__c,
                 Tender_information__r.WinnerAmount__c,
                 Tender_information__r.ZhongBiaoUnit1__c,
                 Tender_information__r.Tender_Order__c,
                 Opportunity__c
                 FROM Tender_Opportunity_Link__c
                 WHERE Tender_information__c IN :tenderIds];// AND Opportunity__r.Bidding_Project_Name_Bid__c NOT IN :tenderIds
            if (links != null && links.size() > 0) {
                List<String> oppIds = new List<String>();
                for (Tender_Opportunity_Link__c link : links) {
                    oppIds.add(link.Opportunity__c);
                }
                if (oppIds.size() > 0) {
                    //查询询价下所有中间表
                    List<Tender_Opportunity_Link__c> links1 =
                    [SELECT id,
                     Tender_information__c,
                     Tender_information__r.OpenBidingTime__c,
                     Tender_information__r.WinnerAmount__c,
                     Tender_information__r.ZhongBiaoUnit1__c,
                     Tender_information__r.Tender_Order__c,
                     Tender_information__r.InfoType__c,
                     Tender_information__r.subInfoType__c,
                     Opportunity__c
                     FROM Tender_Opportunity_Link__c
                     WHERE Opportunity__c IN :oppIds order by Opportunity__c,Tender_information__r.Tender_Order__c desc, Tender_information__r.relativeTime_F__c desc];
                    List<Opportunity> opps = [select id, Bidding_Project_Name_Bid__c, Bidding_Project_Name_Bid__r.InfoType__c, Closing_Bid_Date_Bid__c,Opp_Order__c from Opportunity where Id in :oppIds];// and Bidding_Project_Name_Bid__r.InfoType__c != '3:结果'
                    if (opps != null && opps.size() > 0) {
                        for (Opportunity opp : opps) {
                            if(links1 !=null && links1.size() > 0){
                               for (Tender_Opportunity_Link__c link : links1) {
                                if (link.Opportunity__c == opp.Id) {
                                    //20220616 SWAG-CFD4SU you start 改造,询价实时显示项目阶段最新的招标项目信息
                                    if(opp.Opp_Order__c <= link.Tender_information__r.Tender_Order__c){
                                       opp.Bidding_Project_Name_Bid__c = link.Tender_information__c;
                                       break;
                                    }
                                    //20220616 SWAG-CFD4SU you end 改造,询价实时显示项目阶段最新的招标项目信息
                                }
                              } 
                            }
                            //20220830 you SWAG-CHL67J start
                            Integer returncount =0;
                             for (Tender_Opportunity_Link__c link : links1) {
                                if (link.Opportunity__c == opp.Id) {
                                    if(String.isNotBlank(link.Tender_information__r.InfoType__c) && link.Tender_information__r.InfoType__c!='1:预告' && String.isNotBlank(link.Tender_information__r.subInfoType__c) && link.Tender_information__r.subInfoType__c!='3-1:废标公告' && link.Tender_information__r.subInfoType__c!='3-2:流标公告'){
                                        system.debug('test2进来了');
                                          returncount += 1;
                                      }
                                }
                            }
                            opp.Tender_Number__c =returncount;
                            //20220830 you SWAG-CHL67J end   
                        }
                        // 需要跳过询价trigger 防止出现重复更新的情况
                        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
                        update opps;
                        StaticParameter.EscapeOpportunityBefUpdTrigger = false;
                    }
                }
            }
        }
        /**20220616 SWAG-CFD4SU you
        if (lostWinIds.size() > 0) {
            List<Tender_Opportunity_Link__c> links_2 =
                [SELECT id,
                 Tender_information__c,
                 Opportunity__c
                 FROM Tender_Opportunity_Link__c
                 WHERE Tender_information__c NOT IN :lostWinIds
                 AND Tender_information__r.InfoType__c = '3:结果' 
                 AND Opportunity__r.Bidding_Project_Name_Bid__c IN :lostWinIds];
            if (links_2 != null && links_2.size() > 0) {
                List<String> oppIds = new List<String>();
                for (Tender_Opportunity_Link__c link : links_2) {
                    oppIds.add(link.Opportunity__c);
                }
                if (oppIds.size() > 0) {
                    List<Opportunity> opps_2 = [select id, Bidding_Project_Name_Bid__c, Bidding_Project_Name_Bid__r.InfoType__c, Closing_Bid_Date_Bid__c from Opportunity where Id in :oppIds and Bidding_Project_Name_Bid__r.InfoType__c != '3:结果'];
                    if (opps_2 != null && opps_2.size() > 0) {
                        for (Opportunity opp : opps_2) {
                            for (Tender_Opportunity_Link__c link : links_2) {
                                if (link.Opportunity__c == opp.Id) {
                                    opp.Bidding_Project_Name_Bid__c = link.Tender_information__c;
                                    break;
                                }
                            }
                        }
                        // 需要跳过询价trigger 防止出现重复更新的情况
                        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
                        update opps_2;
                        StaticParameter.EscapeOpportunityBefUpdTrigger = false;
                    }
                }
            }
        }
        **/
        // 20221028 ljh SWAG-CKL5UC add start
        if(tendMap.size() > 0){
            List<Tender_Opportunity_Link__c> links = [select id, Opportunity__c, Tender_information__c, Opportunity__r.Created_Day__c ,Opportunity__r.LeakageNumber__c,Opportunity__r.LeadSource  from Tender_Opportunity_Link__c where Tender_information__c in :tendMap.keySet()];
            for(Tender_Opportunity_Link__c lk:links){
                if(lk.Opportunity__r.Created_Day__c  > tendMap.get(lk.Tender_information__c).publicDate__c && lk.Opportunity__r.LeadSource == '招标网'){
                    Opportunity opp = new Opportunity();
                    opp.Id = lk.Opportunity__c;
                    opp.LeakageNumber__c = 1;
                    updateOpp.put(opp.Id,opp);
                }
            }
        }
        if(updateOpp.size() > 0){
            update updateOpp.values();
        }
        // 20221028 ljh SWAG-CKL5UC add end
    }
 
    public void updateTenOwner() {
        System.debug('12345678');
        //1.获得医院
        Set<Id> hpIdsets = new Set<Id>();
        // Map < 招投标Id,Map<关联医院 >> 对应招投标下的关联医院
        Map<Id, Map<Id, Id>> hpIdsetsMap = new Map<Id, Map<Id, Id>>();
        // 得到招投标的所有人
        Map<Id, Id> tenderinformationOwnerMap = new Map<Id, Id>();
        // 得到招投标的关联战略科室
        Map<Id, List<String>> department_selectionMap = new Map<Id, List<String>>();
        for (Tender_information__c info : newList) {
            Map<Id, Id> ressMap = new  Map<Id, Id>();
            // 多加一步判断 如果new的OwnerId和old的不同 就不再做判断了 start
            // add 【委托】P-招标项目-手动创建的招标项目增加必填字段 2021/11/03 fxk Star
            Tender_information__c oldTen = new Tender_information__c();
            if (oldMap!=null && oldMap.containskey(info.Id)) {
                oldTen = oldMap.get(info.Id);
            }
            // add 【委托】P-招标项目-手动创建的招标项目增加必填字段 2021/11/03 fxk End
            if (oldTen.OwnerId != null && !oldTen.OwnerId.equals(info.OwnerId)) {
                continue;
            }
            // 多加一步判断 如果new的OwnerId和old的不同 就不再做判断了 end
            tenderinformationOwnerMap.put(info.Id, info.OwnerId);
            System.debug('-------9=======' + info.Hospital__c);
            if (info.Hospital__c != null) {
                hpIdsets.add(info.Hospital__c);
                System.debug('-------7=======' + hpIdsets);
                ressMap.put(info.Hospital__c, info.Hospital__c);
                System.debug('-------8=======' + ressMap);
            }
            // if (info.Hospital1__c != null) {
            //     hpIdsets.add(info.Hospital1__c);
            //     ressMap.put(info.Hospital1__c, info.Hospital1__c);
            // }
            // if (info.Hospital2__c != null) {
            //     hpIdsets.add(info.Hospital2__c);
            //     ressMap.put(info.Hospital2__c, info.Hospital2__c);
            // }
            // if (info.Hospital3__c != null) {
            //     hpIdsets.add(info.Hospital3__c);
            //     ressMap.put(info.Hospital3__c, info.Hospital3__c);
            // }
            // if (info.Hospital4__c != null) {
            //     hpIdsets.add(info.Hospital4__c);
            //     ressMap.put(info.Hospital4__c, info.Hospital4__c);
            // }
            hpIdsetsMap.put(info.Id, ressMap);
            if (info.department_selection__c != null) {
                List<String> tenDepartList = info.department_selection__c.split(';');
                department_selectionMap.put(info.Id, tenDepartList);
            }
        }
 
        if (hpIdsets.contains(null)) {
            hpIdsets.remove(null);
        }
 
        List<Account> accList = new List<Account>();
        System.debug('-------4=======' + hpIdsets);
        if (hpIdsets.size() > 0) {
            System.debug('-------5=======');
            //获取医院下所有启用战略科室的启用所有人
            //取得战略科室:
            // accList = [select id,OwnerId,ParentId,OwnerIsActive__c from Account where Parent.RecordType_DeveloperName__c = 'HP'
            //                                          AND OwnerIsActive__c = true
            //                                          AND ParentId  in :hpIdsets];
            //获取医院上的主担当
            accList = [select id, GI_Main__c, GI_Main__r.IsActive, BF_owner__c, BF_owner__r.IsActive,
                       ET_owner__c, ET_owner__r.IsActive, SP_Main__c, SP_Main__r.IsActive, URO_owner_ID__c, URO_owner_ID__r.IsActive,
                       GYN_owner__c, GYN_owner__r.IsActive, ENT_owner_ID__c, ENT_owner_ID__r.IsActive, Energy_LeaderStr__c
                       from Account where  Id in :hpIdsets ];
        }
 
 
 
 
        // List<Tender_information__c> TenInfoList = new List<Tender_information__c>();
        // Map<Id,Map<String,Id>> ddd = new Map<Id,Map<String,Id>>();
        // for (Id  tenderId : hpIdsetsMap.keySet()) {
        //     // Tender_information__c ten = new Tender_information__c();
        //     // ten.Id = tenderId;
        //     Id tenderownerId = tenderinformationOwnerMap.get(tenderId);
        //     Map<Id, Id> ressMap = hpIdsetsMap.get(tenderId);
        //     for (Account hp : accList) {
        //         Map<String, Id> hptempMap = new Map<String, Id>();
 
        //         Map<String, Id> hptempMap1 = new Map<String, Id>();
        //         if (ressMap.containsKey(hp.Id) && ddd.containsKey(tenderId)) {
        //             hptempMap1 = ddd.get()
        //         }
        //         if (hp.GI_Main__c != null && hp.GI_Main__r.IsActive ) {
        //             hptempMap.put('01210000000QemLAAS', hp.GI_Main__c);
        //             // ttt = tenderownerId == hp.GI_Main__c;
        //             hptempMap1.put(hp.GI_Main__c,hp.GI_Main__c);
        //         }
        //         // 呼吸科主担当
        //         if (hp.BF_owner__c != null && hp.BF_owner__r.IsActive ) {
        //             hptempMap.put('01210000000QezZAAS', hp.BF_owner__c);
        //         }
 
        //         // 普外科主担当
        //         if (hp.SP_Main__c != null && hp.SP_Main__r.IsActive) {
        //             hptempMap.put('01210000000QezeAAC', hp.SP_Main__c);
        //         }
        //         // 泌尿科主担当
        //         if (hp.URO_owner_ID__c != null && hp.URO_owner_ID__r.IsActive) {
        //             hptempMap.put('01210000000QezjAAC', hp.URO_owner_ID__c);
        //         }
        //         // 妇科主担当
        //         if (hp.GYN_owner__c != null && hp.GYN_owner__r.IsActive) {
        //             hptempMap.put('01210000000QezoAAC', hp.GYN_owner__c);
        //         }
        //         // 耳鼻喉科主担当
        //         if (hp.ENT_owner_ID__c != null && hp.ENT_owner_ID__r.IsActive) {
        //             hptempMap.put('01210000000QeztAAC', hp.ENT_owner_ID__c);
        //         }
 
        //         // if (ressMap.containsKey(hp.Id) && !hptempMap1.containsKey(tenderownerId)) {
        //         //     ddd.put(tenderId, hptempMap);
        //         // }
        //     }
 
 
        // }
        // 用于更新招投标
        List<Tender_information__c> TenInfoList = new List<Tender_information__c>();
 
        Map<Id, Map<String, Id>> hpTypeToMainMap = new Map<Id, Map<String, Id>>();
        // 存招投标对应的医院主担当
        Map<Id, Map<String, Id>> hpMainMap = new Map<Id, Map<String, Id>>();
        for (Id  tenderId : hpIdsetsMap.keySet()) {
            // 招投标 所有人
            Id tenderownerId = tenderinformationOwnerMap.get(tenderId);
            // 存医院
            Map<Id, Id> ressMap = hpIdsetsMap.get(tenderId);
            System.debug('-------3=======' + accList);
            Map<String, Id> hpTypeToMaintempMap = new Map<String, Id>();
            if (accList.size() > 0) {
                for (Account hp : accList) {
                    // 医院主担当 记录类型Id 对应 医院主担当
                    hpTypeToMaintempMap = new Map<String, Id>();
                    // 存放 医院主担当
                    Map<String, Id> hpMaintempMap = new Map<String, Id>();
                    // 关联医院
                    if (ressMap.containsKey(hp.Id) && hpMainMap.containsKey(tenderId)) {
                        hpMaintempMap = hpMainMap.get(tenderId);
                    }
                    if (hp.GI_Main__c != null && hp.GI_Main__r.IsActive ) {
                        hpTypeToMaintempMap.put('01210000000QemLAAS', hp.GI_Main__c);
                        hpMaintempMap.put(hp.GI_Main__c, hp.GI_Main__c);
                    }
                    // 呼吸科主担当
                    if (hp.BF_owner__c != null && hp.BF_owner__r.IsActive ) {
                        hpTypeToMaintempMap.put('01210000000QezZAAS', hp.BF_owner__c);
                        hpMaintempMap.put(hp.BF_owner__c, hp.BF_owner__c);
                    }
                    // 普外科主担当
                    if (hp.SP_Main__c != null && hp.SP_Main__r.IsActive) {
                        hpTypeToMaintempMap.put('01210000000QezeAAC', hp.SP_Main__c);
                        hpMaintempMap.put(hp.SP_Main__c, hp.SP_Main__c);
                    }
                    // 泌尿科主担当
                    if (hp.URO_owner_ID__c != null && hp.URO_owner_ID__r.IsActive) {
                        hpTypeToMaintempMap.put('01210000000QezjAAC', hp.URO_owner_ID__c);
                        hpMaintempMap.put(hp.URO_owner_ID__c, hp.URO_owner_ID__c);
                    }
                    // 妇科主担当
                    if (hp.GYN_owner__c != null && hp.GYN_owner__r.IsActive) {
                        hpTypeToMaintempMap.put('01210000000QezoAAC', hp.GYN_owner__c);
                        hpMaintempMap.put(hp.GYN_owner__c, hp.GYN_owner__c);
                    }
                    // 耳鼻喉科主担当
                    if (hp.ENT_owner_ID__c != null && hp.ENT_owner_ID__r.IsActive) {
                        hpTypeToMaintempMap.put('01210000000QeztAAC', hp.ENT_owner_ID__c);
                        hpMaintempMap.put(hp.ENT_owner_ID__c, hp.ENT_owner_ID__c);
                    }
                    // 存招投标下所有关联医院 的所有主担当
                    if (ressMap.containsKey(hp.Id) ) {
                        hpMainMap.put(tenderId, hpMaintempMap);
                    }
                }
            }
            // 所有关联医院的主担当不包含 招投标所有人
            System.debug('-------2=======' + hpMainMap);
            if (hpMainMap.get(tenderId) != null) {
                // 增加判断战略科室
                if (department_selectionMap.get(tenderId) != null) {
                    boolean changeOwner = true;
                    Map<String, Id> tenHpMainMap = hpMainMap.get(tenderId);
                    for (String type : department_selectionMap.get(tenderId)) {
                        if (tenHpMainMap.get(type) != null && tenHpMainMap.get(type).equals(tenderownerId)) {
                            changeOwner = false;
                            break;
                        }
                    }
                    if (changeOwner) {
                        hpTypeToMainMap.put(tenderId, hpTypeToMaintempMap);
                    }
                } else {
                    hpTypeToMaintempMap.put('00510000000gmxH', '00510000000gmxH');
                    hpTypeToMainMap.put(tenderId, hpTypeToMaintempMap);
                }
            } else {
                hpTypeToMaintempMap.put('00510000000gmxH', '00510000000gmxH');
                hpTypeToMainMap.put(tenderId, hpTypeToMaintempMap);
            }
 
        }
        System.debug('-------1=======' + hpTypeToMainMap);
        Map<Id, Id> UpdateTenMap = new Map<Id, Id>();
        if (hpTypeToMainMap.size() > 0) {
            // 查招投标-询价关联表
            List<Tender_Opportunity_Link__c> TenOppLinkList = [select Id, Opportunity__c, Tender_information__c, Opportunity__r.OwnerId, Opportunity__r.Owner.IsActive, Name
                    from Tender_Opportunity_Link__c where Tender_information__c in :hpTypeToMainMap.keySet() and  Opportunity__r.Owner.IsActive = true
                                    order by Tender_information__c, Name asc];
            Map<Id, Id> oppMainMap = new Map<Id, Id>();
            for (Tender_Opportunity_Link__c oppLinks : TenOppLinkList) {
                if (!oppMainMap.containsKey(oppLinks.Tender_information__c)) {
                    oppMainMap.put(oppLinks.Tender_information__c, oppLinks.Opportunity__r.OwnerId );
                }
            }
            for (Id  tenderId : hpTypeToMainMap.keySet()) {
                for (Tender_information__c info : newList) {
                    // add 【委托】P-招标项目-手动创建的招标项目增加必填字段 2021/11/03 fxk Star
                    Tender_information__c oldTen = new Tender_information__c();
                    if (oldMap!=null && oldMap.containskey(info.Id)) {
                        oldTen = oldMap.get(info.Id);
                    }
                    // add 【委托】P-招标项目-手动创建的招标项目增加必填字段 2021/11/03 fxk End
                    // 招投标没关联询价
                    if (!oppMainMap.containsKey(tenderId)) {
                        System.debug('----------5---------' + oppMainMap);
                        // 招投标 关联战略科室(字段) 有值
                        if (department_selectionMap.containsKey(tenderId)) {
                            System.debug('----------4---------' + department_selectionMap);
                            // 战略科室的 记录类型
                            String typeId = department_selectionMap.get(tenderId) == null ? '' : department_selectionMap.get(tenderId)[0];
                            System.debug('----------6---------' + typeId);
                            Map<String, Id> hpTypeToMaintempMap = hpTypeToMainMap.get(tenderId);
                            System.debug('----------7---------' + hpTypeToMaintempMap);
                            if (hpTypeToMaintempMap.containsKey(typeId)) {
                                UpdateTenMap.put(tenderId, hpTypeToMaintempMap.get(typeId));
                                System.debug('----------8---------' + UpdateTenMap);
                            } else {
                                UpdateTenMap.put(tenderId, '00510000000gmxH');
                                System.debug('----------9---------' + UpdateTenMap);
                            }
                        } else {
                            // 20220421 SWAG-CC58ME ljh add 是否相关:是;关联医院:!null; 关联战略科室 null; start
                            // 是否应标:有值 :所有人:启用 不需要更新
                            // UpdateTenMap.put(tenderId, '00510000000gmxH');
                            // System.debug('----------10---------' + UpdateTenMap);
                            if(!(String.isNotBlank(info.IsBid__c) && info.OwnerIsActive__c)){
                                UpdateTenMap.put(tenderId, '00510000000gmxH');
                                System.debug('----------10---------' + UpdateTenMap);
                            }
                            // 20220421 SWAG-CC58ME ljh add 是否相关:是;关联医院:!null; 关联战略科室 null; end
                        }
                     } else {
                        /*
                        20220422 SWAG-CC58ME ljh update   
                        针对如下场景做的修改:
                        相关性确认:之后所有人取了医院+第一个战略科室的主担当A,然后关联询价,询价所有人是B,
                        所有人取了B。然后B离职了,运行Batch,变成A,在把B启用,不变会来B
                        */
                        // 20220422 ljh update start
                        System.debug('zheli:'+oppMainMap.get(tenderId));
                        Boolean a = oldTen.OwnerId.equals(info.OwnerId);
                        Boolean b = !hpMainMap.get(tenderId).containskey(info.ownerId);
                        System.debug('zheli:'+a+b);
                        // if ((oldTen.OwnerId != null && oldTen.OwnerId.equals(info.OwnerId)) 
                        //      && !hpMainMap.get(tenderId).containskey(info.ownerId)) {
                        // 20220422 ljh update end
                        UpdateTenMap.put(tenderId, oppMainMap.get(tenderId));
                        System.debug('----------11---------' + UpdateTenMap);
                    }
                }
            }
        }
        // StaticParameter.EscapeOtherUpdateTenOwner = false;
        if (UpdateTenMap.size() > 0) {
            for (Tender_information__c info : newList) {
                if (UpdateTenMap.containsKey(info.Id)) {
                    info.OwnerId = UpdateTenMap.get(info.Id);
                }
            }
        }
        // StaticParameter.EscapeOtherUpdateTenOwner = true;
    }
    /*
    集采项目导致所有人更新
    **/
    // 20221011 ljh  SWAG-CK28WT
    public void updateTenOwnerJC() {
        // 
        String OCSM_province = '市场企划本部';
        Id OwnerIdStr;
        List<OCM_Management_Province__c> ompList = [select Id,TenderAssistant1__c,TenderAssistant1__r.IsActive,TenderAssistant2__c from OCM_Management_Province__c where name =:OCSM_province];
        if(ompList.size() > 0 && ompList[0].TenderAssistant1__r.IsActive){
            OwnerIdStr = ompList[0].TenderAssistant1__c;
        }
        System.debug('zheli00:'+OwnerIdStr);
        for (Tender_information__c nObj : newList) {
            Tender_information__c oObj = oldMap.get(nObj.Id);
            if (nObj.CentralizedProject__c != oObj.CentralizedProject__c) {
                if(nObj.CentralizedProject__c && OwnerIdStr != null){
                    /**
                    本部自动变成市场企划本部,项目助理和所有人都是市场企划本部的人,
                    取OCSM管理省页面维护的市场企划本部,招标项目助理1,
                    */
                    nObj.OwnerId = OwnerIdStr;
                    nObj.InfoOwner__c = OwnerIdStr;
                }else if(!nObj.CentralizedProject__c){
                    /**
                    取消勾选后返回营业部门的省和本部,
                    所有人根据关联医院和战略科室取担当的名字。
                    */
                    updateTenOwner();
                } 
            }
            // 如果触发 更新所有人 没有询价则 还是市场企划本部
            if (!StaticParameter.EscapeOtherUpdateTenOwner) {
                if(nObj.CentralizedProject__c && OwnerIdStr != null && (nObj.OpportunityNum__c == 0 || nObj.OpportunityNum__c == null)){
                    nObj.OwnerId = OwnerIdStr;
                    nObj.InfoOwner__c = OwnerIdStr;
                }
            }
        }
    }
    // 中标任务 废标流标时清空中标日
    public void clearConfirmationofAward() {
        List<String> tenders = new List<String>();
        String labelTypes = System.Label.ClearConfirmationofAwardTypes;
        List<String> subTypes = labelTypes.split(',');
        for (Tender_information__c tender : this.newList) {
            Tender_information__c old_tender = this.oldMap.get(tender.Id);
            if (subTypes.contains(tender.subInfoType__c) && !tender.subInfoType__c.equals(old_tender.subInfoType__c)) {
                tenders.add(tender.Id);
            }
        }
        if (tenders.size() > 0) {
            List<Tender_Opportunity_Link__c> links = [select Id, Opportunity__c from Tender_Opportunity_Link__c where Tender_information__c in :tenders];
            if (links != null && links.size() > 0) {
                List<String> oppids = new List<String>();
                for (Tender_Opportunity_Link__c link : links) {
                    oppids.add(link.Opportunity__c);
                }
                // 状态=询价且没有做合同申请的
                List<Opportunity> opps = [select Id, Closing_Bid_Date__c 
                                        from Opportunity 
                                        where StageName = '引合' 
                                        and IF_Submit__c = false
                                        and Id in :oppids];
                if (opps != null && opps.size() > 0) {
                    for (Opportunity opp : opps) {
                        opp.Closing_Bid_Date__c = null;
                    }
                    StaticParameter.EscapeOpportunityBefUpdTrigger = true;
                    update opps;
                    StaticParameter.EscapeOpportunityBefUpdTrigger = false;
                }
            }
        }
    }
}