From d8dc84a3d56df839895f1c417a4d9cbee763d262 Mon Sep 17 00:00:00 2001
From: 高章伟 <gaozhangwei@prec-tech.com>
Date: 星期五, 03 三月 2023 14:50:59 +0800
Subject: [PATCH] gzw 测试环境代码更新

---
 force-app/main/default/classes/AssetMaintainDetailHandler.cls |   44 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/force-app/main/default/classes/AssetMaintainDetailHandler.cls b/force-app/main/default/classes/AssetMaintainDetailHandler.cls
index 14b7040..61ce4c8 100644
--- a/force-app/main/default/classes/AssetMaintainDetailHandler.cls
+++ b/force-app/main/default/classes/AssetMaintainDetailHandler.cls
@@ -28,6 +28,14 @@
         beforeSetValue();
     }
 
+    protected override void afterInsert() {
+        changeDesperateRetrieveDate();
+    }
+
+    protected override void afterUpdate() {
+        changeDesperateRetrieveDate();
+    }
+
     private void beforeSetValue() {
         for (AssetMaintainDetail__c nObj : newList) {
             if(Trigger.isInsert || Trigger.isUpdate){
@@ -35,4 +43,40 @@
             }
         }
     }
+
+    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;
+        }
+
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.1