/** * @Author lijinhuan * @DateTime 2022-12-14T17:01:14+0800 * 测试类:FrameNumUploadControllerTest */ public without sharing class FrameNumManageHandler extends Oly_TriggerHandler { private Map newMap; private Map oldMap; private List newList; private List oldList; public FrameNumManageHandler() { this.newMap = (Map) Trigger.newMap; this.oldMap = (Map) Trigger.oldMap; this.newList = (List) Trigger.new; this.oldList = (List) Trigger.old; } protected override void afterInsert() { // 进口单证 增加发货日设置 start updateAsset(); // 进口单证 增加发货日设置 end } protected override void afterUpdate() { updateAsset(); } protected override void beforeInsert() { } protected override void beforeUpdate() { IsChange(); } private Void updateAsset(){ Map FrameNumManageMap = new Map(); for (FrameNumManage__c nObj : newList) { FrameNumManage__c oObj = oldMap != null ? oldMap.get(nObj.Id) : null; if( String.isNotBlank(nObj.Asset__c) && ( oObj == null || nObj.Asset__c != oObj.Asset__c || nObj.ApplyList_Select__c != oObj.ApplyList_Select__c || nObj.InspectionCard_Select__c != oObj.InspectionCard_Select__c || nObj.ApplyList__c != oObj.ApplyList__c || nObj.InspectionCard__c != oObj.InspectionCard__c || nObj.ScanDate__c != oObj.ScanDate__c || nObj.ScanDate_select__c != oObj.ScanDate_select__c || nObj.DeliveryDate__c != oObj.DeliveryDate__c || nObj.DeliveryDate_select__c != oObj.DeliveryDate_select__c ) ){ FrameNumManageMap.put(nObj.Asset__c,nObj); } } if(FrameNumManageMap.size() > 0 ){ List AssetList = [select id,ApplyList__c,InspectionCard__c from Asset where id in :FrameNumManageMap.keySet()]; List upAssetList = new List(); for(Asset ass:AssetList){ if( (ass.ApplyList__c == null || (ass.ApplyList__c != null && ass.ApplyList__c != FrameNumManageMap.get(ass.Id).ApplyList_NoHave__c)) || (ass.InspectionCard__c == null || (ass.InspectionCard__c != null && ass.InspectionCard__c != FrameNumManageMap.get(ass.Id).InspectionCard_NoHave__c)) ){ Asset tempAsset = new Asset(); tempAsset.Id = ass.Id; if(ass.ApplyList__c == null || (ass.ApplyList__c != null && ass.ApplyList__c != FrameNumManageMap.get(ass.Id).ApplyList_NoHave__c)){ tempAsset.ApplyList__c = FrameNumManageMap.get(ass.Id).ApplyList_NoHave__c; } if(ass.InspectionCard__c == null || (ass.InspectionCard__c != null && ass.InspectionCard__c != FrameNumManageMap.get(ass.Id).InspectionCard_NoHave__c)){ tempAsset.InspectionCard__c = FrameNumManageMap.get(ass.Id).InspectionCard_NoHave__c; } upAssetList.add(tempAsset); } } if(upAssetList.size() > 0){ StaticParameter.EscapeVMCTrigger = true; update upAssetList; StaticParameter.EscapeVMCTrigger = false; } } } private Void IsChange(){ for (FrameNumManage__c nObj : newList) { FrameNumManage__c oObj = oldMap.get(nObj.Id); if((nObj.ApplyList__c != oObj.ApplyList__c) ||(nObj.InspectionCard__c != oObj.InspectionCard__c) ){ nObj.IsChange__c = true; } } } }