public without sharing class AfterUpdateReportHandler extends Oly_TriggerHandler{ private Map newMap; private Map oldMap; private List newList; private List oldList; public AfterUpdateReportHandler() { this.newMap = (Map) Trigger.newMap; this.oldMap = (Map) Trigger.oldMap; this.newList = (List) Trigger.new; this.oldList = (List) Trigger.old; Integer i = 0; } protected override void afterInsert() { InsertReport(); //add by rentx 2021-03-31 start SplitOptionList(); //add by rentx 2021-03-31 end } protected override void afterUpdate() { ChangeReport(); UpdateReport(); //add by rentx 2021-03-31 start SplitOptionList(); //add by rentx 2021-03-31 end } private void InsertReport() { List raList = new List(); List oPDPlans = new List(); for (Report__c newReprot : newList) { if (newReprot.Loaner_request_no1__c != null) { Rental_Apply__c ra = new Rental_Apply__c( Id = newReprot.Loaner_request_no1__c, OPD__c = newReprot.Id ); raList.add(ra); } } // SWAG-BA65JL 2019/03/22 XHL Start for (Report__c newReprot : newList) { if (String.isNotBlank(newReprot.Report_OPDPlan__c)) { OPDPlan__c opdplan = new OPDPlan__c( Id = newReprot.Report_OPDPlan__c, OPDPlan_Report__c = newReprot.Id ); oPDPlans.add(opdplan); } } if (raList.size() > 0) { update raList; } if (oPDPlans.size() > 0) { update oPDPlans; } // SWAG-BA65JL 2019/03/22 XHL End } private void ChangeReport() { List raList = new List(); for (Report__c newReprot : newList) { Report__c oldReprot = oldMap.get(newReprot.Id); if (newReprot.Loaner_request_no1__c != null && oldReprot.Loaner_request_no1__c != newReprot.Loaner_request_no1__c) { Rental_Apply__c ra = new Rental_Apply__c( Id = newReprot.Loaner_request_no1__c, OPD__c = newReprot.Id ); raList.add(ra); } } if (raList.size() > 0) { update raList; } } // SWAG-BA65JL 2019/03/22 XHL Start private void UpdateReport(){ List oPDPlanList = new List(); // CHAN-BC6BW9 LHJ 20190520 Start List taskList = new List(); // CHAN-BC6BW9 LHJ 20190520 End for (Report__c newReprot : newList) { OPDPlan__c opdplan = new OPDPlan__c(); if (oldMap.get(newReprot.Id).get('Status__c') != newReprot.Status__c && newReprot.Status__c == '申請中' && String.isNotBlank( newReprot.Report_OPDPlan__c)) { opdplan.Id = newReprot.Report_OPDPlan__c; opdplan.Status__c = '完毕'; oPDPlanList.add(opdplan); } else if (oldMap.get(newReprot.Id).get('Report_OPDPlan__c') != newReprot.Report_OPDPlan__c && String.isNotBlank( newReprot.Report_OPDPlan__c)) { opdplan.Id = newReprot.Report_OPDPlan__c; opdplan.OPDPlan_Report__c = newReprot.Id; oPDPlanList.add(opdplan); } //else if (oldMap.get(newReprot.Id).get('Report_OPDPlan__c') != newReprot.Report_OPDPlan__c && String.isBlank( newReprot.Report_OPDPlan__c)) { // opdplan.Id = oldMap.get(newReprot.Id).Report_OPDPlan__c; // opdplan.OPDPlan_Report__c = null; // oPDPlanList.add(opdplan); //} // CHAN-BC6BW9 LHJ 20190520 Start if (oldMap.get(newReprot.Id).get('Status__c') != newReprot.Status__c && oldMap.get(newReprot.Id).get('Status__c') == '草案中' ) { taskList.add(newReprot.ID); } // CHAN-BC6BW9 LHJ 20190520 End } // CHAN-BC6BW9 LHJ 20190520 Start if (taskList != null && taskList.size() > 0) { List lstTask = [select id, status from task where whatid in :taskList and status != '完了']; if (lstTask != null && lstTask.size() > 0) { List updTask = new List(); for(Task tsk : lstTask) { tsk.status = '完了'; updTask.add(tsk); } if (updTask.size() > 0) { update updTask; } } } // CHAN-BC6BW9 LHJ 20190520 End if (oPDPlanList.size() > 0) { update oPDPlanList; } } // SWAG-BA65JL 2019/03/22 XHL End //add by rentx 2021-03-31 start private void SplitOptionList(){ //创建参数 key:Sobject对象 value:发生改变的选项列表字段集合 (哪个选项列表发生变化就把哪个当做参数,目前只有'产品优点(可多选) ','产品缺点(可多选)','此次OPD总结(可多选) ') Map> data = new Map>(); for (Report__c rep : newList) { List columsList = new List(); Report__c oldrep = null; if (Trigger.isUpdate) { oldrep = oldMap.get(rep.Id); } if (oldrep == null || oldrep.Product_Evaluation_Advantage1__c != rep.Product_Evaluation_Advantage1__c) { columsList.add('Product_Evaluation_Advantage1__c'); } if (oldrep == null || oldrep.Product_Evaluation_Faults1__c != rep.Product_Evaluation_Faults1__c) { columsList.add('Product_Evaluation_Faults1__c'); } if (oldrep == null || oldrep.This_OPD_Summarize__c != rep.This_OPD_Summarize__c) { columsList.add('This_OPD_Summarize__c'); } data.put(rep, columsList); } //更新历史数据 add by rentx 2021-04-07 start /*Map> data = new Map>(); List columsList = new List(); columsList.add('Product_Evaluation_Advantage1__c'); columsList.add('Product_Evaluation_Faults1__c'); columsList.add('This_OPD_Summarize__c'); for (Report__c rep : newList) { data.put(rep, columsList); }*/ //更新历史数据 by rentx 2021-04-07 end SplitOptionListUtil util = new SplitOptionListUtil(); util.makeObject(data); } //add by rentx 2021-03-31 end }