//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 newMap; private Map oldMap; private List newList; private List oldList; public TenderInformationHandler() { this.newMap = (Map) Trigger.newMap; this.oldMap = (Map) Trigger.oldMap; this.newList = (List) Trigger.new; this.oldList = (List) 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 Tenids = new Set();//招标项目id,查询link Set oppTens = new Set();//招标项目id,查询link List oppIds = new List();//询价 // 获得要更新的询价 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 InfoTypeMap = new Map(); //判断是否是因为中标修改得 if(null!=Tenids && Tenids.size()>0){ List 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 opportunities = [select id, Bidding_Project_Name_Bid__c, Opp_Order__c from Opportunity where id in :oppIds]; List 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 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 zbIds = new Set(); // //拿到招标id , 招标所有人 GI/SP助理 的邮件地址 // Map> zbOppMap = new Map>(); // List tlist = new List(); // 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()); // } // zbOppMap.get(ten.Id).add(ten.Owner.Email); // } // //取得询价 // // 招标-询价关联修改 20210817 start // // List oppList = new List(); // // 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()); // // } // // 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 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()); // } // zbOppMap.get(link.Tender_information__c).add(link.Opportunity__r.Owner.Email); // } // } // // 招标-询价关联修改 20210817 end // } // if (zbOppMap.size() > 0) { // if (tlist.size() > 0) { // List sendMails = new List(); // 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 + '
'; // body += '预算金额:' + BudgetAmount + '
'; // body += '医院:' + HospitalName + '
'; // // body += '战略科室:'+departmentName + '
'; // body += '中标日:' + OpenBidingTime + '
'; // body += '主担当:' + ten.Owner.Alias + '
'; // body += '招投标链接:
'; // body += '' + URL.getSalesforceBaseUrl().toExternalForm() + '/' + ten.Id + '
'; // // body += '收件人: '+zbOppMap.get(ten.Id); // List toMailList = new List(); // // List toccList = new List(); // // 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 tempsendMails = new List(); // 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 hpIdsets = new Set(); 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 accList = new List(); 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 rowCauseList = new List(); 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> hpDepartmentMap = new Map>(); // if (accList.size() > 0) { // for (Account department : accList) { // if (!hpDepartmentMap.containsKey(department.ParentId)) { // hpDepartmentMap.put(department.ParentId, new Set()); // } // hpDepartmentMap.get(department.ParentId).add(department.OwnerId); // } // } //能量担当需要单独查一下 List ddNameListtrim = new List(); List ddNameList = new List(); 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 ulist = new List(); ulist = [select id, Alias, IsActive, Name from user where IsActive = true and (Alias in :ddNameList or Alias in :ddNameListtrim)]; Map uidmap = new Map(); if (ulist != null && ulist.size() > 0) { for (User u : ulist) { uidmap.put(u.Name, u.Id); } } // upd 用户勾选了战略科室的话,这条招标信息只有关联医院对应的战略科室主担当可以看到,否则医院所有科室主担当都能看到 2021、9、22 fxk Star // Map> hpDepartmentMap = new Map>(); Map> hpDepartmentMap = new Map>(); if (accList.size() > 0) { for (Account hp : accList) { //消化科主担当 // Set ddIds = new Set(); Map ddmap = new Map(); 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 tenShareList = new List(); for (Tender_information__c tenc : newList) { // 20221013 ljh SWAG-CK28WT start // 集采项目 后续共享不需要,只把原来的共享删除 if(tenc.CentralizedProject__c){ continue; } // 20221013 ljh SWAG-CK28WT start //一个map为 针对一条招投标计划的共享 Map sharemap = new Map(); //1.先设置 医院担当的共享 //获取5个医院 Map hmap = new Map(); 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 tempMap = new Map(); if (tenc.department_selection__c != null) { System.debug('=========1=======' + tenc.department_selection__c); List 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 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 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 mpMap = new Map(); 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 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 updateTenList = new List(); 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 oldUserOrGroups = new List(); Map tOldMap = (Map) Trigger.oldMap; Map tNewMap = (Map) Trigger.newMap; List cd = new List(); System.debug(LoggingLevel.INFO, '*** cd: ' + cd); System.debug(LoggingLevel.INFO, '*** tOldMap: ' + tOldMap); for(Tender_information__c t:(List) 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 lm = new Map(); 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) 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 tenderIds = new List(); List lostWinIds = new List(); // 20221028 ljh SWAG-CKL5UC start Map tendMap = New Map(); Map updateOpp = New Map(); // 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 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 oppIds = new List(); for (Tender_Opportunity_Link__c link : links) { oppIds.add(link.Opportunity__c); } if (oppIds.size() > 0) { //查询询价下所有中间表 List 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 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 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 oppIds = new List(); for (Tender_Opportunity_Link__c link : links_2) { oppIds.add(link.Opportunity__c); } if (oppIds.size() > 0) { List 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 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 hpIdsets = new Set(); // Map < 招投标Id,Map<关联医院 >> 对应招投标下的关联医院 Map> hpIdsetsMap = new Map>(); // 得到招投标的所有人 Map tenderinformationOwnerMap = new Map(); // 得到招投标的关联战略科室 Map> department_selectionMap = new Map>(); for (Tender_information__c info : newList) { Map ressMap = new Map(); // 多加一步判断 如果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 tenDepartList = info.department_selection__c.split(';'); department_selectionMap.put(info.Id, tenDepartList); } } if (hpIdsets.contains(null)) { hpIdsets.remove(null); } List accList = new List(); 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 TenInfoList = new List(); // Map> ddd = new Map>(); // for (Id tenderId : hpIdsetsMap.keySet()) { // // Tender_information__c ten = new Tender_information__c(); // // ten.Id = tenderId; // Id tenderownerId = tenderinformationOwnerMap.get(tenderId); // Map ressMap = hpIdsetsMap.get(tenderId); // for (Account hp : accList) { // Map hptempMap = new Map(); // Map hptempMap1 = new Map(); // 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 TenInfoList = new List(); Map> hpTypeToMainMap = new Map>(); // 存招投标对应的医院主担当 Map> hpMainMap = new Map>(); for (Id tenderId : hpIdsetsMap.keySet()) { // 招投标 所有人 Id tenderownerId = tenderinformationOwnerMap.get(tenderId); // 存医院 Map ressMap = hpIdsetsMap.get(tenderId); System.debug('-------3=======' + accList); Map hpTypeToMaintempMap = new Map(); if (accList.size() > 0) { for (Account hp : accList) { // 医院主担当 记录类型Id 对应 医院主担当 hpTypeToMaintempMap = new Map(); // 存放 医院主担当 Map hpMaintempMap = new Map(); // 关联医院 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 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 UpdateTenMap = new Map(); if (hpTypeToMainMap.size() > 0) { // 查招投标-询价关联表 List 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 oppMainMap = new Map(); 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 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 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 tenders = new List(); String labelTypes = System.Label.ClearConfirmationofAwardTypes; List 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 links = [select Id, Opportunity__c from Tender_Opportunity_Link__c where Tender_information__c in :tenders]; if (links != null && links.size() > 0) { List oppids = new List(); for (Tender_Opportunity_Link__c link : links) { oppids.add(link.Opportunity__c); } // 状态=询价且没有做合同申请的 List 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; } } } } }