public without sharing class OpportunityBiddingHandler extends Oly_TriggerHandler { private Map newMap; private Map oldMap; private List newList; private List oldList; public OpportunityBiddingHandler() { this.newMap = (Map) Trigger.newMap; this.oldMap = (Map) Trigger.oldMap; this.newList = (List) Trigger.new; this.oldList = (List) Trigger.old; } // protected override void beforeUpdate() { // (); // } // @override //根据ocsm管理省的Gi助理为询价不应标申请中的主负责人(助理)赋值 protected override void beforeInsert() { AssignValueToAssistant(); } protected override void beforeUpdate() { AssignValueToAssistant(); } protected override void afterUpdate() { addOpp(); //add by rentx 20210726 start addShare(); //add by rentx 20210726 end } protected override void afterInsert() { //add by rentx 20210726 start addShare(); //add by rentx 20210726 end } //当审批流程走完时 更新 询价相关字段 private void addOpp() { // List TenInfoList = [select Id, IsReactionOpp__c from Tender_information__c]; List OppIdList = new List(); Map updateOppMap = new Map(); List updateTenList = new List(); // 遍历询价 for (Enquiry_No_Bidding_Apply__c Enbas : newList) { // 如果新的状态!=更新之前的状态,现在的状态=批准 (将给询价中的是否应标赋值为否) if ((Enbas.NotBidApprovalStatus__c != oldMap.get(Enbas.Id).NotBidApprovalStatus__c) && Enbas.NotBidApprovalStatus__c == '批准') { String oppId = Enbas.Opportunity__c; if (String.isNotBlank(oppId)) { Opportunity opp = new Opportunity(); opp.Id = oppId; // System.debug('----1----' + opp.Bidding_Project_Name_Bid__c); opp.Whether_Bidding__c = '否'; updateOppMap.put(oppId, opp); } } } if (updateOppMap.values().size() > 0) { update updateOppMap.values(); List oppInfoList = [select Id, Bidding_Project_Name_Bid__c from Opportunity where Id in :updateOppMap.keySet() and Bidding_Project_Name_Bid__c != null]; for (Opportunity opp : oppInfoList) { Tender_information__c TenInfo = new Tender_information__c(); TenInfo.Id = opp.Bidding_Project_Name_Bid__c; TenInfo.IsReactionOpp__c = true; updateTenList.add(TenInfo); } } if (updateTenList.size() > 0) { System.debug('----3----' + updateTenList.size()); update updateTenList; } } //根据ocsm管理省的Gi助理为询价不应标申请中的主负责人(助理)赋值 private void AssignValueToAssistant() { // 通过OCSM管理省,关联招投标 与 管理省 Map mpMap = new Map(); // 关联询价与询价不应标申请 Map oppMap = new Map(); // 查 询价不应标申请数据 List OCMinfoList = [SELECT id, Name, GI_assistant__c, GI_assistant__r.IsActive FROM OCM_Management_Province__c]; for (OCM_Management_Province__c mp : OCMinfoList) { mpMap.put(mp.Name, mp); } //直接设置 信息负责人(助理) 为GI助理 for (Enquiry_No_Bidding_Apply__c Enbainfos : newList) { oppMap.put(Enbainfos.Opportunity__c, Enbainfos); } // 关联 招投标 与 询价 Map EnquiryMap = new Map(); // 通过 与 询价 关联的 询价不应标申请 查对应的询价(多此一举,易理解) List oppinfoList = [SELECT id, OCM_man_province__c, Bidding_Project_Name_Bid__c, Bidding_Project_Name_Bid__r.OCSMProvince__c FROM Opportunity Where Id In: oppMap.keySet()]; for (Opportunity Oppinfos : oppinfoList) { EnquiryMap.put(oppMap.get(Oppinfos.Id), Oppinfos.OCM_man_province__c ); } List EnquiryList = new List(); for (Enquiry_No_Bidding_Apply__c Enbainfo : newList) { if (EnquiryMap.get(Enbainfo) != null && oppMap.keySet() != null) { // Enbainfo.leading_Cadre_Assistant__c = mpMap.get(EnquiryMap.get(Enbainfo)).GI_assistant__c; EnquiryList.add(Enbainfo); } } // if (EnquiryList.size() > 0) { // upsert EnquiryList; // } } //add by rentx 20210726 start public void addShare(){ //获取共享原因 String rowCauseXinxi = Schema.Enquiry_No_Bidding_Apply__Share.RowCause.Xinxi__c; List rowCauseList = new List(); rowCauseList.add(rowCauseXinxi); //设置共享 Map sharemap = new Map(); List enqShareList = new List(); for (Enquiry_No_Bidding_Apply__c enq : newList) { //判断 如果信息负责人不是owner 则设置共享 if (enq.leading_Cadre_Assistant__c != enq.OwnerId && enq.leading_Cadre_Assistant__c != null) { Enquiry_No_Bidding_Apply__Share aos = new Enquiry_No_Bidding_Apply__Share( RowCause = rowCauseXinxi, ParentId = enq.Id, UserOrGroupId = enq.leading_Cadre_Assistant__c, AccessLevel = 'Edit'); sharemap.put(enq.leading_Cadre_Assistant__c, aos); } } //先删再加 List beforeShareList = [select id from Enquiry_No_Bidding_Apply__Share where ParentId in :newMap.keySet() and RowCause in :rowCauseList]; if (beforeShareList != null && beforeShareList.size() > 0) { delete beforeShareList; } if (sharemap != null && sharemap.size() > 0) { insert sharemap.values(); } } //add by rentx 20210726 end }