| | |
| | | beforeSetValue(); |
| | | } |
| | | |
| | | protected override void afterInsert() { |
| | | changeDesperateRetrieveDate(); |
| | | } |
| | | |
| | | protected override void afterUpdate() { |
| | | changeDesperateRetrieveDate(); |
| | | } |
| | | |
| | | private void beforeSetValue() { |
| | | for (AssetMaintainDetail__c nObj : newList) { |
| | | if(Trigger.isInsert || Trigger.isUpdate){ |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void changeDesperateRetrieveDate(){ |
| | | Set<Id> ids = new Set<Id>(); |
| | | List<AssetMaintainDetail__c> amdList = new List<AssetMaintainDetail__c>(); |
| | | for (AssetMaintainDetail__c amd : newList) { |
| | | AssetMaintainDetail__c oldAMD = null; |
| | | if (Trigger.isUpdate) { |
| | | oldAMD = oldMap.get(amd.Id); |
| | | } |
| | | if ((oldAMD == null || (oldAMD != null && oldAMD.MaintainType__c != amd.MaintainType__c)) |
| | | && (amd.MaintainType__c == '断念找回(断念取消)' || amd.MaintainType__c == '断念找回(重新登录)')) { |
| | | ids.add(amd.AssetMaintainHeader__c); |
| | | amdList.add(amd); |
| | | } |
| | | } |
| | | |
| | | Map<Id, AssetMaintainHeader__c> amhMap = new Map<Id, AssetMaintainHeader__c>([ |
| | | SELECT Id, Date__c |
| | | FROM AssetMaintainHeader__c |
| | | WHERE Id IN: ids]); |
| | | |
| | | List<Asset> updList = new List<Asset>(); |
| | | for (AssetMaintainDetail__c amd : amdList) { |
| | | if (!amhMap.isEmpty() && amhMap.containsKey(amd.AssetMaintainHeader__c)) { |
| | | Asset ass = new Asset(); |
| | | ass.Id = amd.Asset__c; |
| | | ass.DesperateRetrieveDate__c = amhMap.get(amd.AssetMaintainHeader__c).Date__c; |
| | | updList.add(ass); |
| | | } |
| | | } |
| | | |
| | | if (!updList.isEmpty()) { |
| | | update updList; |
| | | } |
| | | |
| | | } |
| | | } |