From af7b716a60d889acea95560abba0e46eee008b8f Mon Sep 17 00:00:00 2001
From: buli <137736985@qq.com>
Date: 星期三, 05 七月 2023 13:54:50 +0800
Subject: [PATCH] backup0705

---
 force-app/main/default/classes/RentalApplyEquipmentSetDetailHandler.cls | 7513 +++++++++++++++++++++--------------------------------------
 1 files changed, 2,663 insertions(+), 4,850 deletions(-)

diff --git a/force-app/main/default/classes/RentalApplyEquipmentSetDetailHandler.cls b/force-app/main/default/classes/RentalApplyEquipmentSetDetailHandler.cls
index 0c730b4..1187abe 100644
--- a/force-app/main/default/classes/RentalApplyEquipmentSetDetailHandler.cls
+++ b/force-app/main/default/classes/RentalApplyEquipmentSetDetailHandler.cls
@@ -1,4643 +1,2358 @@
 public without sharing class RentalApplyEquipmentSetDetailHandler extends Oly_TriggerHandler {
-    private Map<Id, Rental_Apply_Equipment_Set_Detail__c> newMap;
-    private Map<Id, Rental_Apply_Equipment_Set_Detail__c> oldMap;
-    private List<Rental_Apply_Equipment_Set_Detail__c> newList;
-    private List<Rental_Apply_Equipment_Set_Detail__c> oldList;
-    private static final Map<String,Schema.RecordTypeInfo>  DEVELOPERNAMEMAP  = Schema.SObjectType.Rental_Apply__c.getRecordTypeInfosByDeveloperName();//璁板綍绫诲瀷 20201119 ljh add
-    //Rental_Apply_Equipment_Set_Detail__c 鏇存柊銇欍倠鏅傘伀Asset銈傛洿鏂般仚銈嬪彲鑳芥�с亴銇傘倞銇俱仚銇仹锛屻亾銇撱仹staticMap銈掍綔鎴愩仐siAsset銈掔祼闆嗐仐銇俱仚
-    private static Map<Id, Asset> assMap                = new Map<Id, Asset>(); // new Only
-    // 涓婃灦鐨勬椂鍊欎繚鏈夎澶囩殑鍊熷嚭鍒嗛厤鏁颁細-1,浣嗘槸涓讳綋鐨勮瘽鏈夊彲鑳戒細鏆傚畾鍒嗛厤銆傝繖鏃跺�欏氨浼氭湁鏇存柊浜嗕袱鏉℃槑缁�,浣嗘槸鏇存柊鐨勪繚鏈夎澶囨槸鍚屼竴鏉$殑鎯呭喌(鏆傚畾鍒嗛厤鎺ヨЕ鍒嗛厤鏁伴噺闇�瑕�+1)
-    // 鍥犱负鏆傚畾鍒嗛厤鐨勬椂鍊欏�熷嚭鍒嗛厤涔﹂渶瑕佸啀鍘熸潵鐨勪笂鏋�-1鍚庣殑鍩虹涓�+1鎵�浠ヤ笂鏋舵椂鍊欎繚鏈夎澶囩殑鎺ヨЕ鍒嗛厤鏁伴渶瑕佷繚瀛樺啀娆′娇鐢ㄣ��
-    // 濡傛灉涓嶆槸Static涓婃灦鍚庡氨浼氭竻绌篴ssUpdMap,杩欐椂鍊欏氨浼氫娇鐢╝ssMap閲岀殑淇濇湁璁惧鏉ュ仛鏁伴噺鍔犲噺,铏界劧鍐嶆绱竴娆′繚鏈夎澶囧苟淇濆瓨鍒癮ssMap鐨勮瘽鏁版嵁浼氬緢骞插噣
-    // 浣嗗洜涓篠OQL101鐨勯棶棰樺彂鐢熺殑鍑犵巼浼氬ぇ澶у鍔�,鎵�浠ssUpdMap杩樻槸浣跨敤闈欐�佸彉閲�
-    private static Map<Id, Asset> assUpdMap             = new Map<Id, Asset>(); // new 銇� old
-    private static Set<Id> executeed_refreshQueueNumber = new Set<Id>();        // 宸茬粡澶勭悊杩囨帓闃熼『 Rental_Apply_Equipment_Set_Detail__c.Id
+  private Map<Id, Rental_Apply_Equipment_Set_Detail__c> newMap;
+  private Map<Id, Rental_Apply_Equipment_Set_Detail__c> oldMap;
+  private List<Rental_Apply_Equipment_Set_Detail__c> newList;
+  private List<Rental_Apply_Equipment_Set_Detail__c> oldList;
+  private static final Map<String, Schema.RecordTypeInfo> DEVELOPERNAMEMAP = Schema.SObjectType.Rental_Apply__c.getRecordTypeInfosByDeveloperName(); //璁板綍绫诲瀷 20201119 ljh add
+  //Rental_Apply_Equipment_Set_Detail__c 鏇存柊銇欍倠鏅傘伀Asset銈傛洿鏂般仚銈嬪彲鑳芥�с亴銇傘倞銇俱仚銇仹锛屻亾銇撱仹staticMap銈掍綔鎴愩仐siAsset銈掔祼闆嗐仐銇俱仚
+  private static Map<Id, Asset> assMap = new Map<Id, Asset>(); // new Only
+  // 涓婃灦鐨勬椂鍊欎繚鏈夎澶囩殑鍊熷嚭鍒嗛厤鏁颁細-1,浣嗘槸涓讳綋鐨勮瘽鏈夊彲鑳戒細鏆傚畾鍒嗛厤銆傝繖鏃跺�欏氨浼氭湁鏇存柊浜嗕袱鏉℃槑缁�,浣嗘槸鏇存柊鐨勪繚鏈夎澶囨槸鍚屼竴鏉$殑鎯呭喌(鏆傚畾鍒嗛厤鎺ヨЕ鍒嗛厤鏁伴噺闇�瑕�+1)
+  // 鍥犱负鏆傚畾鍒嗛厤鐨勬椂鍊欏�熷嚭鍒嗛厤涔﹂渶瑕佸啀鍘熸潵鐨勪笂鏋�-1鍚庣殑鍩虹涓�+1鎵�浠ヤ笂鏋舵椂鍊欎繚鏈夎澶囩殑鎺ヨЕ鍒嗛厤鏁伴渶瑕佷繚瀛樺啀娆′娇鐢ㄣ��
+  // 濡傛灉涓嶆槸Static涓婃灦鍚庡氨浼氭竻绌篴ssUpdMap,杩欐椂鍊欏氨浼氫娇鐢╝ssMap閲岀殑淇濇湁璁惧鏉ュ仛鏁伴噺鍔犲噺,铏界劧鍐嶆绱竴娆′繚鏈夎澶囧苟淇濆瓨鍒癮ssMap鐨勮瘽鏁版嵁浼氬緢骞插噣
+  // 浣嗗洜涓篠OQL101鐨勯棶棰樺彂鐢熺殑鍑犵巼浼氬ぇ澶у鍔�,鎵�浠ssUpdMap杩樻槸浣跨敤闈欐�佸彉閲�
+  private static Map<Id, Asset> assUpdMap = new Map<Id, Asset>(); // new 銇� old
+  private static Set<Id> executeed_refreshQueueNumber = new Set<Id>(); // 宸茬粡澶勭悊杩囨帓闃熼『 Rental_Apply_Equipment_Set_Detail__c.Id
 
-    private static Set<Id> shipment_requestedRaIdSet = new Set<Id>();
-    private static Set<Id> shipment_requestedRaIdStaticSet = new Set<Id>();
+  private static Set<Id> shipment_requestedRaIdSet = new Set<Id>();
+  private static Set<Id> shipment_requestedRaIdStaticSet = new Set<Id>();
 
-    public RentalApplyEquipmentSetDetailHandler() {
-        Integer i = 0;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        i ++;
-        if (Trigger.isUpdate || Trigger.isUndelete || Trigger.isDelete) {
-            this.newMap = new Map<Id, Rental_Apply_Equipment_Set_Detail__c>();
-            this.newList = new List<Rental_Apply_Equipment_Set_Detail__c>();
-            this.oldMap = (Map<Id, Rental_Apply_Equipment_Set_Detail__c>) Trigger.oldMap;
-            this.oldList = (List<Rental_Apply_Equipment_Set_Detail__c>) Trigger.old;
-            // 澶у墠鎻� Fixture_Set__c 銇с仚銇屼笅瑷樸伄灞炴�с亴瑷畾銇曘倢銇︺亜銇俱仚
-            // 鍙傜収闁總銇惈銇俱倢銈嬪弬鐓с儸銈炽兗銉夈伅鍓婇櫎銇с亶銇俱仜銈撱��
-            if (Trigger.isUpdate || Trigger.isUndelete) {
-                for (SObject nSObj : Trigger.new) {
-                    Rental_Apply_Equipment_Set_Detail__c nObj = (Rental_Apply_Equipment_Set_Detail__c) nSObj;
-                    Rental_Apply_Equipment_Set_Detail__c oObj = null;
-                    if (Trigger.isUpdate) {
-                        oObj = oldMap.get(nObj.Id);
-                    }
-                    if (Trigger.isUndelete && String.isBlank(nObj.Fixture_Set_Id__c)) {
-                        // 鏃с儑銉笺偪銆乥eipin2 銇� trigger 瀹熻銇椼仾銇�
-                        continue;
-                    }
-                    else if (Trigger.isUpdate && String.isBlank(nObj.Fixture_Set_Id__c)
-                            && String.isNotBlank(oObj.Fixture_Set_Id__c)) {
-                        nObj.addError('涓嶈兘娓呯┖鍊熷嚭澶囧搧閰嶅 Fixture_Set__c');
-                    }
-                    else if (Trigger.isUpdate && String.isNotBlank(nObj.DeliverySlip__c)
-                            && String.isNotBlank(oObj.DeliverySlip__c) && oObj.DeliverySlip__c != nObj.DeliverySlip__c) {
-                        nObj.addError('涓嶈兘淇敼鍊熷嚭澶囧搧閰嶅鏄庣粏鐨勮繍杈撳崟');
-                    }
-                    else if (Trigger.isUpdate && String.isNotBlank(nObj.Return_DeliverySlip__c )
-                            && String.isNotBlank(oObj.Return_DeliverySlip__c ) && oObj.Return_DeliverySlip__c  != nObj.Return_DeliverySlip__c ) {
-                        nObj.addError('涓嶈兘淇敼鍊熷嚭澶囧搧閰嶅鏄庣粏鐨勫洖瀵勮繍杈撳崟');
-                    }
-                    else {
-                        this.newList.add(nObj);
-                        this.newMap.put(nObj.Id, nObj);
-                    }
-                }
-            }
+  public RentalApplyEquipmentSetDetailHandler() {
+    if (Trigger.isUpdate || Trigger.isUndelete || Trigger.isDelete) {
+      this.newMap = new Map<Id, Rental_Apply_Equipment_Set_Detail__c>();
+      this.newList = new List<Rental_Apply_Equipment_Set_Detail__c>();
+      this.oldMap = (Map<Id, Rental_Apply_Equipment_Set_Detail__c>) Trigger.oldMap;
+      this.oldList = (List<Rental_Apply_Equipment_Set_Detail__c>) Trigger.old;
+      // 澶у墠鎻� Fixture_Set__c 銇с仚銇屼笅瑷樸伄灞炴�с亴瑷畾銇曘倢銇︺亜銇俱仚
+      // 鍙傜収闁總銇惈銇俱倢銈嬪弬鐓с儸銈炽兗銉夈伅鍓婇櫎銇с亶銇俱仜銈撱��
+      if (Trigger.isUpdate || Trigger.isUndelete) {
+        for (SObject nSObj : Trigger.new) {
+          Rental_Apply_Equipment_Set_Detail__c nObj = (Rental_Apply_Equipment_Set_Detail__c) nSObj;
+          Rental_Apply_Equipment_Set_Detail__c oObj = null;
+          if (Trigger.isUpdate) {
+            oObj = oldMap.get(nObj.Id);
+          }
+          if (Trigger.isUndelete && String.isBlank(nObj.Fixture_Set_Id__c)) {
+            // 鏃с儑銉笺偪銆乥eipin2 銇� trigger 瀹熻銇椼仾銇�
+            continue;
+          } else if (
+            Trigger.isUpdate &&
+            String.isBlank(nObj.Fixture_Set_Id__c) &&
+            String.isNotBlank(oObj.Fixture_Set_Id__c)
+          ) {
+            nObj.addError('涓嶈兘娓呯┖鍊熷嚭澶囧搧閰嶅 Fixture_Set__c');
+          } else if (
+            Trigger.isUpdate &&
+            String.isNotBlank(nObj.DeliverySlip__c) &&
+            String.isNotBlank(oObj.DeliverySlip__c) &&
+            oObj.DeliverySlip__c != nObj.DeliverySlip__c
+          ) {
+            //nObj.addError('涓嶈兘淇敼鍊熷嚭澶囧搧閰嶅鏄庣粏鐨勮繍杈撳崟');
+          } else if (
+            Trigger.isUpdate &&
+            String.isNotBlank(nObj.Return_DeliverySlip__c) &&
+            String.isNotBlank(oObj.Return_DeliverySlip__c) &&
+            oObj.Return_DeliverySlip__c != nObj.Return_DeliverySlip__c
+          ) {
+            nObj.addError('涓嶈兘淇敼鍊熷嚭澶囧搧閰嶅鏄庣粏鐨勫洖瀵勮繍杈撳崟');
+          } else {
+            this.newList.add(nObj);
+            this.newMap.put(nObj.Id, nObj);
+          }
         }
-        else {
-            // insert
-            this.newMap = (Map<Id, Rental_Apply_Equipment_Set_Detail__c>) Trigger.newMap;
-            this.oldMap = (Map<Id, Rental_Apply_Equipment_Set_Detail__c>) Trigger.oldMap;
-            this.newList = (List<Rental_Apply_Equipment_Set_Detail__c>) Trigger.new;
-            this.oldList = (List<Rental_Apply_Equipment_Set_Detail__c>) Trigger.old;
-        }
+      }
+    } else {
+      // insert
+      this.newMap = (Map<Id, Rental_Apply_Equipment_Set_Detail__c>) Trigger.newMap;
+      this.oldMap = (Map<Id, Rental_Apply_Equipment_Set_Detail__c>) Trigger.oldMap;
+      this.newList = (List<Rental_Apply_Equipment_Set_Detail__c>) Trigger.new;
+      this.oldList = (List<Rental_Apply_Equipment_Set_Detail__c>) Trigger.old;
     }
-    public static Boolean disabled = false;
-    protected override void beforeInsert() {
-        if(!disabled){
-            beforeSetValue();
-        }
+  }
+  public static Boolean disabled = false;
+  // 澶囧搧浼樺寲杩藉姞 20230518 lc Start
+  public static Boolean skipUpdateAgain = false;
+  // 澶囧搧浼樺寲杩藉姞 20230518 lc End
+  protected override void beforeInsert() {
+    if (!disabled) {
+      beforeSetValue();
     }
-    protected override void beforeUpdate() {
-        if(!disabled){
-            beforeSetValue();
+  }
+  protected override void beforeUpdate() {
+    if (!disabled && !FixtureUtil.isRepairRenewal) {
+      beforeSetValue();
 
-            // 璁惧�兼帓闃熺殑UniqueKey
-            setUniqueKeyQueue();
-        }
+      // 璁惧�兼帓闃熺殑UniqueKey
+      setUniqueKeyQueue();
     }
-    protected override void afterInsert() {
-        if(!disabled){
-            formulaToTextCheck();
-            //鍏ュ姏瑕忓墖 鏂板缓鏁版嵁涓嶈兘鍒嗛厤銇屻亗銈娿伨銇欍伄銇э紝銇撱亾銇с伅Last銇∣ut_of_wh__c銇ō瀹氬繀瑕併亗銈娿伨銇涖倱
+  }
+  protected override void afterInsert() {
+    if (!disabled && !FixtureUtil.isRepairRenewal) {
+      formulaToTextCheck();
+      //鍏ュ姏瑕忓墖 鏂板缓鏁版嵁涓嶈兘鍒嗛厤銇屻亗銈娿伨銇欍伄銇э紝銇撱亾銇с伅Last銇∣ut_of_wh__c銇ō瀹氬繀瑕併亗銈娿伨銇涖倱
 
-            Set<Id> raesdAssignSet = new Set<Id>();
-            for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
-                if (nObj.Select_Time__c != null) {
-                    if (String.isNotBlank(nObj.Rental_Apply__c)) {
-                        raesdAssignSet.add(nObj.Rental_Apply__c);
-                    }
-                }
-            }
-            if (raesdAssignSet.size() > 0) {
-                // 璁剧疆鍒嗛厤浜�
-                setAssginPerson(raesdAssignSet);
-            }
-            // 鍔炰簨澶勬柊寤哄凡鍒嗛厤鏄庣粏鏃舵墽琛�
-            afterInsertAgencyAssignedDetail();
-            if(!assUpdMap.isEmpty()) {
-                update assUpdMap.values();
-            }
+      Set<Id> raesdAssignSet = new Set<Id>();
+      for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
+        if (nObj.Select_Time__c != null) {
+          if (String.isNotBlank(nObj.Rental_Apply__c)) {
+            raesdAssignSet.add(nObj.Rental_Apply__c);
+          }
         }
+      }
+      if (raesdAssignSet.size() > 0) {
+        // 璁剧疆鍒嗛厤浜�
+        setAssginPerson(raesdAssignSet);
+      }
+      // 鍔炰簨澶勬柊寤哄凡鍒嗛厤鏄庣粏鏃舵墽琛�
+      afterInsertAgencyAssignedDetail();
+      if (!assUpdMap.isEmpty()) {
+        update assUpdMap.values();
+      }
     }
-    protected override void afterDelete() {
-        // OLY_OCM-1189 杩藉姞鍒犻櫎Check
-        deleteCheck();
-        deleteReFirst();
-        //鎺掗槦椤烘湁鍙樺寲鐨勬椂鍊欓噸鏂拌缃帓闃熼『
-        // reQueueNumber();
-        //added by denny
-        reQueueAndSequence();
-        // 鍔炰簨澶勫垹闄ゅ凡鍒嗛厤鏄庣粏鏃舵墽琛�
-        afterDeleteAgencyAssignedDetail();
-        if(!assUpdMap.isEmpty()) {
-            update assUpdMap.values();
-        }
+  }
+  protected override void afterDelete() {
+    // OLY_OCM-1189 杩藉姞鍒犻櫎Check
+    deleteCheck();
+    deleteReFirst();
+    //鎺掗槦椤烘湁鍙樺寲鐨勬椂鍊欓噸鏂拌缃帓闃熼『
+    // reQueueNumber();
+    //added by denny
+    reQueueAndSequence();
+    // 鍔炰簨澶勫垹闄ゅ凡鍒嗛厤鏄庣粏鏃舵墽琛�
+    afterDeleteAgencyAssignedDetail();
+    if (!assUpdMap.isEmpty()) {
+      update assUpdMap.values();
     }
-    protected override void afterUpdate() {
-        if(!disabled){
-            Set<Id> assIds = new Set<Id>();
-            for (Rental_Apply_Equipment_Set_Detail__c raesd : newList) {
-                if (String.isNotBlank(raesd.Asset__c)) {
-                    assIds.add(raesd.Asset__c);
-                }
-            }
-            if (Trigger.isUpdate && !assIds.isEmpty()) {
-                assMap = new Map<Id, Asset>([
-                        Select Id, Quantity, Status, Manage_type__c,
-                               Out_of_wh__c, Rental_Count__c, Abandoned_Inventory__c, Abandoned_RealThing__c,
-                               Confirm_Lost_Count__c, CountForRepair__c
-                        From Asset
-                        Where Id =: assIds
-                          and Asset_loaner_category__c != '鑰楁潗'
-                          and RecordTypeId = '01210000000kOPR'
-                          FOR UPDATE]);
-            }
-            // 澶囧搧鏁伴噺鐨勫姞鍑�
-            changeAsset();
-            System.debug(LoggingLevel.INFO, '*00** assUpdMap: ' + JSON.serialize(assUpdMap));
-            // 鎺掗槦鍐嶅垎閰� 鍊熷嚭鍒嗛厤鏁伴噺鐨勫噺 绛�, clear Last_Reserve_RAES_Detail__c, 瑷畾First_RAESD__c
-            clearLastReserveRAESD();
-            System.debug(LoggingLevel.INFO, '*11** assUpdMap: ' + JSON.serialize(assUpdMap));
-            //Asset鍙樻洿鐨勬椂鍊� 鏇存柊Asset鐨� Last_Reserve_RAES_Detail__c
-            changeAssetLast();
-            System.debug(LoggingLevel.INFO, '*22** assUpdMap: ' + JSON.serialize(assUpdMap));
-            // Asset.Out_of_wh__c+ -
-            changeAssetCount();
-            System.debug(LoggingLevel.INFO, '*33* assUpdMap: ' + JSON.serialize(assUpdMap));
-            // change Consumable_Guaranteen_end__c OLY_OCM-601
-            changeAssetConsumable_Guaranteen_end();
-            System.debug(LoggingLevel.INFO, '*44** assUpdMap: ' + JSON.serialize(assUpdMap));
-            // 鍚屻仒block 銇� 鎺掗槦銉偝銉笺儔 Queue_Number__c 銈抮efresh
-            // refreshQueueNumberByBlock();
-            if (!assUpdMap.isEmpty()) {
-                System.debug(LoggingLevel.INFO, '*----** assUpdMap: ' + JSON.serialize(assUpdMap));
-                update assUpdMap.values();
-            }
-            // 4-XX 鐨� 涓�瀵逛竴瀵瑰簲
-            oneToOne4XX();
-            // 銈儯銉炽偦銉偝銉斻兗, 涓�瑙堝崟浣嶅彇娑堝悗鐨勬嫹璐濆湪涓�瑙堢殑Handler閲岄潰鍋�
-            cancelCopy();
-            // before 銇с伅鏁板紡闋呯洰銇宯ull銇牬鍚堛亴銇傘倞銇俱仚
-            formulaToTextCheck();
-            // 涓嬩竴娆″�熺敤棰勮鍑哄簱鏃堕棿  鍥炴敹鍚�-妫�娴嬬粨鏋淥K  2021117 ljh 
-            NextShippmentDate();
-            NextShippmentDate_out();
-            // 鍏佽鎻掗槦閭欢  20211125 ljh
-            setToRa_Email_Text();
-            //鎺掗槦椤烘湁鍙樺寲鐨勬椂鍊欓噸鏂拌缃帓闃熼『
-            // reQueueNumber();
-            //鎺掗槦鏂伴�昏緫
-            //added by denny
-            reQueueAndSequence();
-            //鐢宠鑰呮敹鍥濶G鍚庢槑缁嗗洖瀵勬椂鐨勯偖浠跺洖瀵勫崟鍐呭璁剧疆
-            receivedConfirmNGSetReturnDeliverySlipText();
-            Set<Id> raesdSet = new Set<Id>();
-            Set<Id> raesdAssignSet = new Set<Id>();
-            for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
-                Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
-                if (String.isBlank(oObj.Return_DeliverySlip__c) && String.isNotBlank(nObj.Return_DeliverySlip__c)) {
-                    raesdSet.add(nObj.Id);
-                }
-                if (nObj.Select_Time__c != null && oObj.Select_Time__c == null) {
-                    raesdAssignSet.add(nObj.Rental_Apply__c);
-                }
-            }
-            System.debug(raesdSet);
-            if (raesdSet.size() > 0) {
-                // 璁剧疆鍥炲瘎閫氱煡鍐呭
-                RentalApplyEquipmentSetDetailHandler.setRequestAsset_return_Text(raesdSet);
-            }
-
-            if (raesdAssignSet.size() > 0) {
-                // 璁剧疆鍒嗛厤浜�
-                setAssginPerson(raesdAssignSet);
-            }
-
-            // 璁剧疆鑰楁潗鐨勫鍝佹帴瑙︾敵璇峰嚭搴撴寚绀洪偖浠跺彂閫佹椂闂�
-            setConsumSend_Rental_Apply_EmailTime();
-
-            //2021-12-20  mzy  澶囧搧浠诲姟  start
-            // FinishRentalTask(); // 20220121 鎺掗槦涓婄嚎
-            //2021-12-20  mzy  澶囧搧浠诲姟  end
+  }
+  protected override void afterUpdate() {
+    if (!disabled && !FixtureUtil.isRepairRenewal) {
+      Set<Id> assIds = new Set<Id>();
+      for (Rental_Apply_Equipment_Set_Detail__c raesd : newList) {
+        if (String.isNotBlank(raesd.Asset__c)) {
+          assIds.add(raesd.Asset__c);
         }
+      }
+      if (Trigger.isUpdate && !assIds.isEmpty()) {
+        assMap = new Map<Id, Asset>(
+          [
+            SELECT
+              Id,
+              Quantity,
+              Status,
+              Manage_type__c,
+              Out_of_wh__c,
+              Rental_Count__c,
+              Abandoned_Inventory__c,
+              Abandoned_RealThing__c,
+              Confirm_Lost_Count__c,
+              CountForRepair__c
+            FROM Asset
+            WHERE
+              Id = :assIds
+              AND Asset_loaner_category__c != '鑰楁潗'
+              AND RecordTypeId = '01210000000kOPR'
+            FOR UPDATE
+          ]
+        );
+      }
+      // 澶囧搧鏁伴噺鐨勫姞鍑�
+      changeAsset();
+      System.debug(
+        LoggingLevel.INFO,
+        '*00** assUpdMap: ' + JSON.serialize(assUpdMap)
+      );
+      // 鎺掗槦鍐嶅垎閰� 鍊熷嚭鍒嗛厤鏁伴噺鐨勫噺 绛�, clear Last_Reserve_RAES_Detail__c, 瑷畾First_RAESD__c
+      clearLastReserveRAESD();
+      System.debug(
+        LoggingLevel.INFO,
+        '*11** assUpdMap: ' + JSON.serialize(assUpdMap)
+      );
+      //Asset鍙樻洿鐨勬椂鍊� 鏇存柊Asset鐨� Last_Reserve_RAES_Detail__c
+      changeAssetLast();
+      System.debug(
+        LoggingLevel.INFO,
+        '*22** assUpdMap: ' + JSON.serialize(assUpdMap)
+      );
+      // Asset.Out_of_wh__c+ -
+      changeAssetCount();
+      System.debug(
+        LoggingLevel.INFO,
+        '*33* assUpdMap: ' + JSON.serialize(assUpdMap)
+      );
+      // change Consumable_Guaranteen_end__c OLY_OCM-601
+      changeAssetConsumable_Guaranteen_end();
+      System.debug(
+        LoggingLevel.INFO,
+        '*44** assUpdMap: ' + JSON.serialize(assUpdMap)
+      );
+      // 鍚屻仒block 銇� 鎺掗槦銉偝銉笺儔 Queue_Number__c 銈抮efresh
+      // refreshQueueNumberByBlock();
+      if (!assUpdMap.isEmpty()) {
+        System.debug(
+          LoggingLevel.INFO,
+          '*----** assUpdMap: ' + JSON.serialize(assUpdMap)
+        );
+        update assUpdMap.values();
+      }
+      // 4-XX 鐨� 涓�瀵逛竴瀵瑰簲
+      oneToOne4XX();
+      // 銈儯銉炽偦銉偝銉斻兗, 涓�瑙堝崟浣嶅彇娑堝悗鐨勬嫹璐濆湪涓�瑙堢殑Handler閲岄潰鍋�
+      cancelCopy();
+      // before 銇с伅鏁板紡闋呯洰銇宯ull銇牬鍚堛亴銇傘倞銇俱仚
+      formulaToTextCheck();
+      // 涓嬩竴娆″�熺敤棰勮鍑哄簱鏃堕棿  鍥炴敹鍚�-妫�娴嬬粨鏋淥K  2021117 ljh
+      NextShippmentDate();
+      NextShippmentDate_out();
+      // 鍏佽鎻掗槦閭欢  20211125 ljh
+      setToRa_Email_Text();
+      //鎺掗槦椤烘湁鍙樺寲鐨勬椂鍊欓噸鏂拌缃帓闃熼『
+      // reQueueNumber();
+      //鎺掗槦鏂伴�昏緫
+      //added by denny
+      reQueueAndSequence();
+      //鐢宠鑰呮敹鍥濶G鍚庢槑缁嗗洖瀵勬椂鐨勯偖浠跺洖瀵勫崟鍐呭璁剧疆
+      receivedConfirmNGSetReturnDeliverySlipText();
+      Set<Id> raesdSet = new Set<Id>();
+      Set<Id> raesdAssignSet = new Set<Id>();
+      for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
+        Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
+        if (
+          String.isBlank(oObj.Return_DeliverySlip__c) &&
+          String.isNotBlank(nObj.Return_DeliverySlip__c)
+        ) {
+          raesdSet.add(nObj.Id);
+        }
+        if (nObj.Select_Time__c != null && oObj.Select_Time__c == null) {
+          raesdAssignSet.add(nObj.Rental_Apply__c);
+        }
+      }
+      System.debug(raesdSet);
+      if (raesdSet.size() > 0) {
+        // 璁剧疆鍥炲瘎閫氱煡鍐呭
+        RentalApplyEquipmentSetDetailHandler.setRequestAsset_return_Text(
+          raesdSet
+        );
+      }
+
+      if (raesdAssignSet.size() > 0) {
+        // 璁剧疆鍒嗛厤浜�
+        setAssginPerson(raesdAssignSet);
+      }
+
+      // 璁剧疆鑰楁潗鐨勫鍝佹帴瑙︾敵璇峰嚭搴撴寚绀洪偖浠跺彂閫佹椂闂�
+      setConsumSend_Rental_Apply_EmailTime();
+
+      //2021-12-20  mzy  澶囧搧浠诲姟  start
+      // FinishRentalTask(); // 20220121 鎺掗槦涓婄嚎
+      //2021-12-20  mzy  澶囧搧浠诲姟  end
     }
-    private Map<Id, Asset> createAssetMap() {
-        Set<Id> assIds = new Set<Id>();
-        String ra_RecordTypeId = DEVELOPERNAMEMAP.get('AgencyRequest').getRecordTypeId();
-        List<Rental_Apply_Equipment_Set_Detail__c> objList = new List<Rental_Apply_Equipment_Set_Detail__c>();
-        if(Trigger.isInsert) {
-            objList = newList;
-        }
-        else {
-            objList = oldList;
-        }
-        for (Rental_Apply_Equipment_Set_Detail__c obj : objList) {
-            if(ra_RecordTypeId != null
-                && obj.RA_RecordTypeId__c.substring(0,15) == ra_RecordTypeId.substring(0,15)
-                && obj.Asset__c != null && obj.Select_Time__c != null
-                && (Trigger.isDelete || Trigger.isInsert)) {
-                assIds.add(obj.Asset__c);
-            }
-        }
-        Map<Id, Asset> m = new Map<Id, Asset>();
-        if (!assIds.isEmpty()) {
-            m = new Map<Id, Asset>([
-                    Select Id, Quantity, Status, Manage_type__c,
-                           Out_of_wh__c, Rental_Count__c, Abandoned_Inventory__c, Abandoned_RealThing__c,
-                           Confirm_Lost_Count__c
-                    From Asset
-                    Where Id =: assIds
-                      and Asset_loaner_category__c != '鑰楁潗'
-                      and RecordTypeId = '01210000000kOPR'
-                      FOR UPDATE]);
-        }
-        return m;
+  }
+  private Map<Id, Asset> createAssetMap() {
+    Set<Id> assIds = new Set<Id>();
+    String ra_RecordTypeId = DEVELOPERNAMEMAP.get('AgencyRequest')
+      .getRecordTypeId();
+    List<Rental_Apply_Equipment_Set_Detail__c> objList = new List<Rental_Apply_Equipment_Set_Detail__c>();
+    if (Trigger.isInsert) {
+      objList = newList;
+    } else {
+      objList = oldList;
     }
-    private void afterInsertAgencyAssignedDetail() {
-        // 鍔炰簨澶勬柊寤哄凡鍒嗛厤鏄庣粏鏃舵墽琛�
-        assMap = createAssetMap();
-        if(!assMap.isEmpty()) {
-            for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
-                if(assMap.containsKey(nObj.Asset__c)) {
-                    Asset ass = assMap.get(nObj.Asset__c);
-                    if(ass.Manage_type__c == '涓綋绠$悊'){
-                        ass.Last_Reserve_RAES_Detail__c = nObj.Id;
-                    }
-                    if(ass.Out_of_wh__c == null) {
-                        ass.Out_of_wh__c = 1;
-                    }
-                    else {
-                        ass.Out_of_wh__c += 1;
-                    }
-                    assUpdMap.put(ass.Id, ass);
-                }
-            }
-        }
+    for (Rental_Apply_Equipment_Set_Detail__c obj : objList) {
+      if (
+        ra_RecordTypeId != null &&
+        obj.RA_RecordTypeId__c.substring(0, 15) ==
+        ra_RecordTypeId.substring(0, 15) &&
+        obj.Asset__c != null &&
+        obj.Select_Time__c != null &&
+        (Trigger.isDelete || Trigger.isInsert)
+      ) {
+        assIds.add(obj.Asset__c);
+      }
     }
-    private void afterDeleteAgencyAssignedDetail() {
-        // 鍔炰簨澶勫垹闄ゅ凡鍒嗛厤鏄庣粏鏃舵墽琛�
-        assMap = createAssetMap();
-        if(!assMap.isEmpty()) {
-            for (Rental_Apply_Equipment_Set_Detail__c oObj : oldList) {
-                if(assMap.containsKey(oObj.Asset__c)) {
-                    Asset ass = assMap.get(oObj.Asset__c);
-                    if(ass.Manage_type__c == '涓綋绠$悊') {
-                        ass.Last_Reserve_RAES_Detail__c = null;
-                    }
-                    if(ass.Out_of_wh__c != null) {
-                        ass.Out_of_wh__c -= 1;
-                    }
-                    assUpdMap.put(ass.Id, ass);
-                }
-            }
-        }
+    Map<Id, Asset> m = new Map<Id, Asset>();
+    if (!assIds.isEmpty()) {
+      m = new Map<Id, Asset>(
+        [
+          SELECT
+            Id,
+            Quantity,
+            Status,
+            Manage_type__c,
+            Out_of_wh__c,
+            Rental_Count__c,
+            Abandoned_Inventory__c,
+            Abandoned_RealThing__c,
+            Confirm_Lost_Count__c
+          FROM Asset
+          WHERE
+            Id = :assIds
+            AND Asset_loaner_category__c != '鑰楁潗'
+            AND RecordTypeId = '01210000000kOPR'
+          FOR UPDATE
+        ]
+      );
     }
-
-    private void deleteCheck() {
-        String ra_RecordTypeId = DEVELOPERNAMEMAP.get('AgencyRequest').getRecordTypeId();
-        for (Rental_Apply_Equipment_Set_Detail__c oObj : oldList) {
-            if (
-                (oObj.RA_RecordTypeId__c.substring(0,15) != ra_RecordTypeId.substring(0,15)
-                    &&(oObj.Rental_Apply_Request_approval_time_F__c != null
-                        && oObj.ApplyPersonAppended_F__c == false)
-                        || (oObj.ApplyPersonAppended_F__c == true && oObj.Add_Request_approval_time__c != null)
-                )
-                || (oObj.RA_RecordTypeId__c.substring(0,15) == ra_RecordTypeId.substring(0,15)
-                    && (oObj.Rental_Apply_Request_approval_time_F__c != null
-                        && (oObj.Rental_Apply_CreatedDate_F__c > oObj.CreatedDate
-                            || oObj.StockDown__c == true)
-                        && !oObj.canDelete__c  //20210523 ljh add 1829
-                    )
-                )
-            ) {
-                oObj.addError('宸茬粡鎵瑰噯鐨勫鍝佸�熷嚭鏄庣粏涓嶈兘鍋氱墿鐞嗗垹闄ゃ��');
-            }
+    return m;
+  }
+  private void afterInsertAgencyAssignedDetail() {
+    // 鍔炰簨澶勬柊寤哄凡鍒嗛厤鏄庣粏鏃舵墽琛�
+    assMap = createAssetMap();
+    if (!assMap.isEmpty()) {
+      for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
+        if (assMap.containsKey(nObj.Asset__c)) {
+          Asset ass = assMap.get(nObj.Asset__c);
+          if (ass.Manage_type__c == '涓綋绠$悊') {
+            ass.Last_Reserve_RAES_Detail__c = nObj.Id;
+          }
+          if (ass.Out_of_wh__c == null) {
+            ass.Out_of_wh__c = 1;
+          } else {
+            ass.Out_of_wh__c += 1;
+          }
+          assUpdMap.put(ass.Id, ass);
         }
+      }
     }
-
-    private void setConsumSend_Rental_Apply_EmailTime() {
-        if (shipment_requestedRaIdSet.isEmpty() == false) {
-            List<Consum_Apply__c> caList = [SELECT Id
-                        , Loaner_centre_mail_address__c
-                     FROM Consum_Apply__c
-                    WHERE Rental_Apply__c = :shipment_requestedRaIdSet];
-            if (caList.size() > 0) {
-                Datetime dt = Datetime.now();
-                for (Consum_Apply__c ca : caList) {
-                    ca.Send_Rental_Apply_EmailTime__c = dt;
-                }
-                update caList;
-            }
-            shipment_requestedRaIdSet = new Set<Id>();
+  }
+  private void afterDeleteAgencyAssignedDetail() {
+    // 鍔炰簨澶勫垹闄ゅ凡鍒嗛厤鏄庣粏鏃舵墽琛�
+    assMap = createAssetMap();
+    if (!assMap.isEmpty()) {
+      for (Rental_Apply_Equipment_Set_Detail__c oObj : oldList) {
+        if (assMap.containsKey(oObj.Asset__c)) {
+          Asset ass = assMap.get(oObj.Asset__c);
+          if (ass.Manage_type__c == '涓綋绠$悊') {
+            ass.Last_Reserve_RAES_Detail__c = null;
+          }
+          if (ass.Out_of_wh__c != null) {
+            ass.Out_of_wh__c -= 1;
+          }
+          assUpdMap.put(ass.Id, ass);
         }
+      }
     }
+  }
 
-    private void beforeSetValue() {
-        Set<Id> raesdSet = new Set<Id>();
-        for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
-            raesdSet.add(nObj.Rental_Apply_Equipment_Set__c);
-        }
-        Map<Id, Rental_Apply_Equipment_Set__c> raesdMap = new Map<Id, Rental_Apply_Equipment_Set__c>([Select Id, Fixture_Set__r.Name ,
-                IndexFromUniqueKey__c
-                From Rental_Apply_Equipment_Set__c
-                Where Id =: raesdSet]);
-        String agencyRecordTypeId = DEVELOPERNAMEMAP.get('AgencyRequest').getRecordTypeId();
-
-        for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
-            //鍥犱负鏄疘nsert鏃跺�欒鍊�  鎯呭喌1锛岀敵璇锋柊寤轰細璁惧��  鎯呭喌2锛孨G鎷疯礉鍑烘潵鐨勬椂鍊欎細璁惧��
-            //鍥犱负UniqueKey__c鍒ゆ柇浜咲ataMigration_Flag__c鎵�浠ヨ繖閲屼篃闇�瑕佸垽鏂�  妫�绱㈢殑鏃跺�欏洜涓鸿鍋嘔nsert鎵�浠ヤ笉闇�瑕佽缃�
-            // TODO bp3 DetailHandler閲�, 瀵笷SD璁惧�肩殑鍦版柟 闇�瑕佸湪Rental_Apply__c鐨凥andler閲�, 鍙樻垚鎵瑰噯鏅�, 涔熻璁惧�笺��
-            if (Trigger.isInsert && nObj.DataMigration_Flag__c == false) {
-                nObj.Is_Body__c = nObj.Is_Body_F__c;
-                if (String.isNotBlank(nObj.Fixture_Set_Detail__c)) {
-                    nObj.FSD_Id__c = nObj.Fixture_Set_Detail__c;
-                }
-                // 272銉併偙銉冦儓
-                // Create_State__c涓虹┖骞朵笖鐢宠涔︾殑鏍囧噯鎵瑰噯鏃堕棿涓嶄负绌虹殑鏃跺�欒缃负1
-                // 1 --- 杩藉姞闄勫睘鍝�
-                // 0 --- Cancel鎷疯礉
-                // null --- 鏅�氭柊瑙�
-                if (nObj.Create_State__c == null
-                        && nObj.Rental_Apply_Request_approval_time_F__c != null
-                        && nObj.Substitute_Select_Again__c == false // OLY_OCM-404 鍒嗛厤浠f浛鍝�
-                        // 鍔炰簨澶勫垎閰嶆椂杩藉姞鐨勬槑缁嗕笉绠楄拷鍔犻檮灞炲搧
-                        && nObj.RA_RecordTypeId__c.substring(0,15) != agencyRecordTypeId.substring(0,15)) {
-                    nObj.Create_State__c = 1;
-                }
-                nObj.FSD_Is_Optional__c = nObj.FSD_Is_Optional_F__c;
-                // 鍔炰簨澶勫湪鍒嗛厤涓己鍒惰涓簍rue鏃讹紝涓嶄粠FSD鎷疯礉
-                if(nObj.RA_RecordTypeId__c.substring(0,15) != agencyRecordTypeId.substring(0,15) || !nObj.FSD_Is_OneToOne__c) {
-                    nObj.FSD_Is_OneToOne__c = nObj.FSD_Is_OneToOne_F__c;
-                }
-                nObj.FSD_Name_CHN__c    = nObj.Fixture_Name_F__c;
-                nObj.FSD_OneToOneAccessory_Cnt__c = nObj.FSD_OneToOneAccessory_Cnt_F__c;
-                nObj.FSD_Fixture_Model_No__c = nObj.Fixture_Model_No_F__c;
-                if (nObj.DataMigration_Flag__c == false && (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))) {
-                    nObj.Fixture_Model_No_text__c = nObj.Fixture_Model_No_F__c;
-                }
-                nObj.CreatedBy_ProfileId__c = UserInfo.getProfileId();
-//              nObj.ApplyPersonAppended__c = nObj.ApplyPersonAppended_F__c;
-            }
-            if (nObj.DeliverySlip__c != null
-                    && nObj.DataMigration_Flag__c == false && (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))) {
-                if (nObj.Shippment_loaner_time__c == null) {
-                    nObj.Shippment_loaner_time__c = nObj.Shippment_loaner_time2__c;
-                }
-            }
-            nObj.DeliverySlip_Text__c = nObj.DeliverySlip__c;
-            nObj.Return_DeliverySlip_Text__c = nObj.Return_DeliverySlip__c;
-            nObj.Received_Confirm_Text__c = nObj.Received_Confirm_F__c;
-            Rental_Apply_Equipment_Set_Detail__c oObj = null;
-            if (Trigger.isUpdate) {
-                oObj = oldMap.get(nObj.Id);
-                //鍑哄簱鍓嶆鏌G銇牬鍚堛偔銉c兂銈汇儷銇椼伨銇�
-                if(oObj.Inspection_result__c != 'NG' && nObj.Inspection_result__c == 'NG') {
-                    nObj.Cancel_Select__c = true;
-                    nObj.Loaner_cancel_reason__c = '鍏朵粬';// 20210830 ljh SFDC-C448KZ add
-                    nObj.Cancel_Reason__c = '閲嶆柊鍒嗛厤';
-                    nObj.Loaner_cancel_Remarks__c = '鍑哄簱鍓嶆鏌G';
-                }
-                // OLY_OCM-435瀵惧繙 start
-                String userid = UserInfo.getUserId();
-                DateTime now = System.now();
-                if (oObj.Inspection_result__c != nObj.Inspection_result__c && String.isNotBlank(nObj.Inspection_result__c)) {
-                    nObj.Pre_inspection_time__c = now;
-                    //20210428 ljh 1719 update start
-                    //nObj.Inspection_staff__c = userid;
-                    nObj.Inspection_staff__c  =  nObj.RA_RecordTypeId__c == Schema.SObjectType.Rental_Apply__c.getRecordTypeInfosByDeveloperName().get('AgencyRequest').getRecordTypeId() ?null:userid;
-                    //20210428 ljh 1719 update start
-                }
-
-                if (oObj.Check_lost_Item_Final__c != nObj.Check_lost_Item_Final__c && String.isNotBlank(nObj.Check_lost_Item_Final__c)) {
-                    nObj.Lost_item_check_time_Final__c = now;
-                    nObj.Lost_item_check_staff_Final__c = userid;
-                }
-
-                if (oObj.Check_lost_Item__c != nObj.Check_lost_Item__c && String.isNotBlank(nObj.Check_lost_Item__c)) {
-                    nObj.Lost_item_check_time__c = now;
-                    nObj.Lost_item_check_staff__c = userid;
-                }
-
-                if (oObj.CDS_complete__c != nObj.CDS_complete__c && nObj.CDS_complete__c) {
-                    nObj.CDS_complete_time__c = now;
-                    nObj.CDS_staff__c = userid;
-                }
-
-                if (oObj.Inspection_result_after_Final__c != nObj.Inspection_result_after_Final__c && String.isNotBlank(nObj.Inspection_result_after_Final__c)) {
-                    nObj.After_Inspection_time_Final__c = now;
-                    nObj.Inspection_staff_After_Final__c = userid;
-                }
-
-                if (oObj.Inspection_result_after__c != nObj.Inspection_result_after__c && String.isNotBlank(nObj.Inspection_result_after__c)) {
-                    // 妫�娴嬬粨鏋滄洿鏂颁簡浣嗘椂闂存病鏈夋墜鍔ㄦ洿鏂帮紝鍒欐洿鏂版椂闂�
-                    // 濡傛灉鎵嬪姩鏇存柊浜嗘椂闂达紝灏变笉鐢ㄥ啀鏇存柊
-                    if(oObj.After_Inspection_time__c == nObj.After_Inspection_time__c) {
-                        nObj.After_Inspection_time__c = now;
-                    }
-                    //20210716 ljh 1719 update start
-                    //nObj.Inspection_staff_After__c = userid;
-                    nObj.Inspection_staff_After__c  =  nObj.RA_RecordTypeId__c == Schema.SObjectType.Rental_Apply__c.getRecordTypeInfosByDeveloperName().get('AgencyRequest').getRecordTypeId() ?null:userid;
-                    //20210716 ljh 1719 update start
-                }
-                // OLY_OCM-435瀵惧繙 end
-                if(nObj.Detail_Finish__c) {
-                    nObj.RAESD_Status_Text__c = nObj.Id;
-                }
-                else{
-                    nObj.RAESD_Status_Text__c = nObj.RAESD_Status__c;
-                }
-            }
-            Rental_Apply_Equipment_Set__c raes = raesdMap.get(nObj.Rental_Apply_Equipment_Set__c);
-            //鐢婚潰鏄剧ず鐢╟lone鍑烘潵鐨勬暟鎹笉闇�瑕佽缃甆ame
-            //IndexFromUniqueKey__c.format()浼氭姤閿� 瑕佸垽涓嶆槸Null
-            if (nObj.DataMigration_Flag__c == false
-                    && raes != null
-                    && String.isNotBlank(raes.Fixture_Set__r.Name)
-                    && raes.IndexFromUniqueKey__c != null
-                    && nObj.IndexFromUniqueKey__c != null
-                    && (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))) {
-                String split_ApplyNum = nObj.RequestNoJoinStr2__c;
-                if (nObj.Rental_Apply_r_Name__c.contains('_')) {
-                    // XXXX-YYYY_1 (ZZZZ_1)
-                    List<String> split_ApplyNumList = nObj.Rental_Apply_r_Name__c.split('_');
-                    String raName = split_ApplyNumList[split_ApplyNumList.size() - 2];      // XXXX-YYYY (ZZZZ)
-                    split_ApplyNum = split_ApplyNumList[split_ApplyNumList.size() - 1];     // 1
-                    split_ApplyNumList = raName.split('-');     // [XXXX, YYYY]  ([ZZZZ])
-                    if (split_ApplyNumList.size() > 1) {
-                        // YYYY_1
-                        split_ApplyNum = split_ApplyNumList[split_ApplyNumList.size() - 1] + '_' + split_ApplyNum;
-                    } else {
-                        // ZZZZ_1
-                        split_ApplyNum = nObj.Rental_Apply_r_Name__c;
-                    }
-                }
-                nObj.Name = split_ApplyNum + ':' + raes.Fixture_Set__r.Name + ':'
-                        + raes.IndexFromUniqueKey__c.format().leftpad(3, '0');
-
-                // 濡傛灉鏄垎閰嶄唬鏇垮搧鍚嶅瓧鍔�:Sub
-                if (nObj.Substitute_Select_Again__c) {
-                    nObj.Name += ':Sub';
-                }
-
-                //涓�瑙堟椂鐢宠鑰呮敹璐G鐨勮瘽鍚嶅瓧娣诲姞NG
-                if (nObj.Received_Confirm_F__c == 'NG') {
-                    nObj.Name += ':NG';
-                }
-                nObj.Name += ':' + nObj.IndexFromUniqueKey_Text__c + ':'
-                        + nObj.IndexFromUniqueKey__c.format().leftpad(3, '0');
-                //鍙栨秷鐨勬椂鍊欏悕瀛楀姞Canceled
-                if (nObj.Cancel_Select__c) {
-                    nObj.Name += ':Canceled';
-                }
-            }
-            nObj.Loaner_accsessary__c = nObj.Loaner_accsessary_F__c;
-            nObj.Loaner_centre_mail_address__c = nObj.Loaner_centre_mail_address_F__c;
-            // 20220117 ljh add start
-            // 鏇存柊鎺掗槦棰勮 鍏紡鎷锋枃鏈�
-            if(Trigger.isUpdate && String.isBlank(nObj.Asset__c) == false && oObj.Asset__c != nObj.Asset__c){
-                nObj.UQueueShippmentDateText__c = nObj.UQueueShippmentDate__c;
-            }
-            // 20220117 ljh add end
-            // 鍒嗛厤鏃�, 璁惧��
-            if (String.isBlank(nObj.Asset__c) == false && nObj.Select_Time__c != null
-                    && (Trigger.isInsert
-                            || (oObj.Asset__c != nObj.Asset__c || oObj.Select_Time__c != nObj.Select_Time__c)
-                    )
-            ) {
-                // 涓�瀵逛竴淇濈涓讳綋锛堝�熷嚭鏃讹級
-                // nObj.Main_OneToOne_FlagInt__c = nObj.Main_OneToOne_FlagInt__c;
-                if (nObj.DataMigration_Flag__c == false && (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))) {
-                    // 澶囧搧閰嶅鏄庣粏鍨嬪彿(鍊熷嚭鏃�)
-                    if (String.isBlank(nObj.Fixture_Model_No_F__c)) {
-                        nObj.addError('鍒嗛厤鐨凙sset:'+ nObj.Asset__c + ', 娌℃湁璁惧畾 澶囧搧閰嶅鏄庣粏鍨嬪彿');
-                    } else {
-                        nObj.Fixture_Model_No_text__c = nObj.Fixture_Model_No_F__c;
-                    }
-                }
-                // 鏈鸿韩缂栧彿锛堝�熷嚭鏃讹級
-                nObj.SerialNumber_text__c = nObj.SerialNumber__c;
-                // 鎵�鍦ㄥ湴鍖�(鐪�) 鍊熷嚭鏃� #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
-                nObj.SalesProvince_before__c = nObj.SalesProvince__c;
-                // 鎵�鍦ㄥ湴鍖�(鏈儴) 鍊熷嚭鏃� #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
-                nObj.Salesdepartment_before__c = nObj.Salesdepartment__c;
-                // 浜у搧鍒嗙被(GI/SP)(鍊熷嚭鏃�) #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
-                nObj.Product_category_text__c = nObj.Product_category_F__c;
-                // 澶囧搧鍒嗙被(鍊熷嚭鏃�) #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
-                nObj.Equipment_Type_text__c = nObj.Equipment_Type_F__c;
-                // 澶囧搧鎴愭湰(鍊熷嚭鏃�)
-                nObj.Asset_cost_del_before__c = nObj.Asset_cost_del__c;
-                // 澶囧搧瀛樻斁鍦�(鍊熷嚭鏃�)
-                nObj.Internal_asset_location_before__c = nObj.Internal_asset_location__c;
-                //澶囧搧鍚嶇О(鍊熷嚭鏃�)
-                nObj.Fixture_Name_text__c = nObj.Fixture_Name_F__c;
-                // OLY_OCM-243 杩藉姞瀛楁瀵瑰簲 澶囧搧绠$悊缂栫爜(鍊熷嚭鏃�)
-                nObj.EquipmentSet_Managment_Code_text__c = nObj.EquipmentSet_Managment_Code__c;
-                // OLY_OCM-452 杩藉姞瀛楁瀵瑰簲 鍒�澶�(鍊熷嚭鏃�)
-                if (String.isNotBlank(nObj.Fixture_Set_Detail__c)) {
-                    nObj.Is_Special_Product_Text__c = nObj.Is_Special_Product__c;
-                }
-            }
-            // 鎺掗槦鏃�, 瑕佹敞鎰� 璁惧�� 绉诲姩鍒版帓闃焍tn閲�
-            else if (Trigger.isUpdate && String.isBlank(nObj.Asset__c) && oObj.Cancel_Select__c == false
-                    // && oObj.Fixture_Model_No_text__c != nObj.Fixture_Model_No_text__c
-                    && (oObj.Queue_Number__c == 0 || oObj.Queue_Number__c == null) && nObj.Queue_Number__c > 0
-            ) {
-                // 鎺掗槦鏃堕噸鏂拌祴鍊糉ixture_Model_No_text__c 涓轰簡鎺掔殑涓嶆槸鏃odel_No
-                nObj.FSD_Fixture_Model_No__c = nObj.Fixture_Model_No_F__c;
-                // 澶囧搧閰嶅鏄庣粏鍨嬪彿(鍊熷嚭鏃�)
-                // nObj.Fixture_Model_No_text__c = nObj.Fixture_Model_No_F__c;
-                // 鎵�鍦ㄥ湴鍖�(鐪�) 鍊熷嚭鏃�
-                //nObj.SalesProvince_before__c = nObj.SalesProvince__c;
-                // // 鎵�鍦ㄥ湴鍖�(鏈儴) 鍊熷嚭鏃�
-                // nObj.Salesdepartment_before__c = nObj.Salesdepartment__c;
-                // // 浜у搧鍒嗙被(GI/SP)(鍊熷嚭鏃�)
-                // nObj.Product_category_text__c = nObj.Product_category_F__c;
-                // // 澶囧搧鍒嗙被(鍊熷嚭鏃�)
-                // nObj.Equipment_Type_text__c = nObj.Equipment_Type__c;
-                // // 澶囧搧瀛樻斁鍦�(鍊熷嚭鏃�)
-                // nObj.Internal_asset_location_before__c = nObj.Internal_asset_location__c;
-            }
-            // 鍏朵粬鏃跺��(鐢宠鏃�), null璁惧�� 鍜�
-            // 涓�瀵逛竴宸插垎閰嶇殑闄勫睘鍝�,涓讳綋閲嶆柊鎺掗槦鏃�,涓�瀵逛竴闄勫睘鍝侀渶瑕侀噸鏂版寜鐓х敵璇风殑閫昏緫閲嶆柊璧嬪��
-            else if ((Trigger.isInsert && nObj.Cancel_Select__c == false)
-                    || (Trigger.isUpdate && String.isBlank(nObj.Asset__c) && oObj.Cancel_Select__c == false)) {
-                // 澶囧搧閰嶅鏄庣粏鍨嬪彿(鍊熷嚭鏃�)
-                if (String.isBlank(nObj.Fixture_Model_No_text__c)
-                        && nObj.DataMigration_Flag__c == false && (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))) {
-                    nObj.Fixture_Model_No_text__c = nObj.Fixture_Model_No_F__c;
-                }
-                // 鎵�鍦ㄥ湴鍖�(鐪�) 鍊熷嚭鏃� #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
-                if (String.isBlank(nObj.SalesProvince_before__c)) {
-                    nObj.SalesProvince_before__c = nObj.SalesProvince__c;
-                }
-                // 鎵�鍦ㄥ湴鍖�(鏈儴) 鍊熷嚭鏃� #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
-                if (String.isBlank(nObj.Salesdepartment_before__c)) {
-                    nObj.Salesdepartment_before__c = nObj.Salesdepartment__c;
-                }
-                // 浜у搧鍒嗙被(GI/SP)(鍊熷嚭鏃�) #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
-                if (String.isBlank(nObj.Product_category_text__c)) {
-                    nObj.Product_category_text__c = nObj.Product_category_F__c;
-                }
-                // 澶囧搧鍒嗙被(鍊熷嚭鏃�) #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
-                if (String.isBlank(nObj.Equipment_Type_text__c)) {
-                    nObj.Equipment_Type_text__c = nObj.Equipment_Type__c;
-                }
-                // 澶囧搧瀛樻斁鍦�
-                if (String.isBlank(nObj.Internal_asset_location_before__c)) {
-                    nObj.Internal_asset_location_before__c = nObj.Internal_asset_location__c;
-                }
-                // 澶囧搧鍚嶇О(鍊熷嚭鏃�)
-                if (String.isBlank(nObj.Fixture_Name_text__c)) {
-                    nObj.Fixture_Name_text__c = nObj.Fixture_Name_F__c;
-                }
-                // OLY_OCM-243 杩藉姞瀛楁瀵瑰簲 澶囧搧绠$悊缂栫爜(鍊熷嚭鏃�)
-                if (String.isBlank(nObj.EquipmentSet_Managment_Code_text__c)) {
-                    nObj.EquipmentSet_Managment_Code_text__c = nObj.EquipmentSet_Managment_Code__c;
-                }
-                // OLY_OCM-452 杩藉姞瀛楁瀵瑰簲 鍒�澶�(鍊熷嚭鏃�)
-                if (String.isBlank(nObj.Is_Special_Product_Text__c)) {
-                    nObj.Is_Special_Product_Text__c = nObj.Is_Special_Product__c;
-                }
-            } else {
-                // 鍙栨秷鐨勬儏鍐靛湪涓嬮潰鏈夎鍊�
-            }
-            if (nObj.DataMigration_Flag__c == false && nObj.Cancel_Select__c == false
-                    && (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))) {
-                if (String.isBlank(nObj.Fixture_Model_No_text__c)) {
-                    nObj.addError(nObj.Id + ':澶囧搧閰嶅鏄庣粏鍨嬪彿涓嶈兘涓虹┖, 澶囧搧閰嶅鏄庣粏=' + nObj.Fixture_Set_Detail__c);
-                }
-
-                // #OLY_OCM-654 鏁伴噺绠$悊鐨勮瘽,鎵�鍦ㄥ湴鍖�(鏈儴)&浜у搧鍒嗙被&澶囧搧鍒嗙被鐨勫垽鏂笉闇�瑕� Start
-                if ('鏁伴噺绠$悊' == nObj.Manage_type_F__c ) {  // || false == nObj.Loaner_accsessary__c TODO: 闇�纭
-                    if (String.isBlank(nObj.Internal_asset_location_before__c)) {
-                        nObj.addError('澶囧搧瀛樻斁鍦颁笉鑳戒负绌�');
-                    }
-                }
-                else {
-                // #OLY_OCM-654 鏁伴噺绠$悊鐨勮瘽,鎵�鍦ㄥ湴鍖�(鏈儴)&浜у搧鍒嗙被&澶囧搧鍒嗙被鐨勫垽鏂笉闇�瑕� end
-                    if (String.isBlank(nObj.Salesdepartment_before__c)) {
-                        nObj.addError('鎵�鍦ㄥ湴鍖�(鏈儴)涓嶈兘涓虹┖');
-                    }
-                    if (String.isBlank(nObj.Internal_asset_location_before__c)) {
-                        nObj.addError('澶囧搧瀛樻斁鍦颁笉鑳戒负绌�');
-                    }
-                    if (String.isBlank(nObj.Product_category_text__c) && nObj.Is_Body__c) {
-                        nObj.addError('浜у搧鍒嗙被(GI/SP)涓嶈兘涓虹┖');
-                    }
-                    if (String.isBlank(nObj.Equipment_Type_text__c) && nObj.Is_Body__c && nObj.Demo_purpose1__c != '鍏朵粬') {
-                        nObj.addError('澶囧搧鍒嗙被涓嶈兘涓虹┖');
-                    }
-                    // if (String.isBlank(nObj.SalesProvince_before__c) && nObj.Is_Body__c) {
-                    //     nObj.addError('鎵�鍦ㄥ湴鍖�(鐪�)涓嶈兘涓虹┖');
-                    // }
-                }
-            }
-            if (nObj.DataMigration_Flag__c == false
-                    && String.isNotBlank(nObj.FSD_Id__c)
-                    && (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))) {
-                //鍑哄簱鎸囩ず鏇存柊鏄庣粏鐨刱ey
-                nObj.UniqueKey__c = nObj.RequestNoJoinStr2__c + ':'+ nObj.Rental_Apply_Equipment_Set__c
-                        + ':' + nObj.FSD_Id__c + ':' + nObj.IndexFromUniqueKey__c;
-                if (nObj.Cancel_Select__c) {
-                    nObj.UniqueKey__c += nObj.Id;
-                    // 涓嬫灦鍚庣殑鍙栨秷鍔�;
-                    if (nObj.StockDown__c) {
-                        nObj.UniqueKey__c += ';' + nObj.Id;
-                    }
-                    // nObj.Queue_Number__c = null;
-                    if (nObj.StockDown__c && nObj.Inspection_result__c != 'NG'
-                            && String.isBlank(nObj.DeliverySlip__c)) {
-                        nObj.OnStock_By_Cancel__c = true;
-//                      nObj.Inspection_result_after_Flag_Text__c = 'true';
-                    }
-                }
-            }
-            System.debug(nObj.IndexFromUniqueKey__c + 'key is' + nObj.UniqueKey__c);
-            // 鍙栨秷鍒嗛厤
-            //Action 18 銇倛銇c仸銈儯銉炽偦銉伄鍫村悎
-            //鍊熷嚭澶囧搧Set涓�瑙堟槑缁�.淇濇湁璁惧(Link)
-            //鍊熷嚭澶囧搧Set涓�瑙堟槑缁�.鍒嗛厤鏃堕棿
-            //鍊熷嚭澶囧搧Set涓�瑙堟槑缁�.宸插仛鍑哄簱鎸囩ず
-            //鍊熷嚭澶囧搧Set涓�瑙堟槑缁�.鍑哄簱鎸囩ず鏃堕棿
-            if (Trigger.isInsert || oObj.Cancel_Select__c != nObj.Cancel_Select__c) {
-                if (nObj.Cancel_Select__c) {
-                    nObj.Cancel_Date__c = System.today();
-                    nObj.Cancel_Time__c = MainFixtureSelectController.getCurrentTime();
-                    nObj.Cancel_Mem__c = UserInfo.getUserId();
-                    if(nObj.AgencyTempCancel__c) {
-                        if(nObj.AgencyTempCancelTime__c != null) {
-                            Datetime dt = nObj.AgencyTempCancelTime__c;
-                            nObj.Cancel_Time__c = Time.newInstance(dt.hour(), dt.minute(), dt.second(), dt.millisecond());
-                            nObj.Cancel_Date__c = Date.newinstance(dt.year(), dt.month(), dt.day());
-                        }
-                    }
-                    nObj.AgencyTempCancel__c = false; // 鐪熷彇娑堟椂鎶婁复鏃跺彇娑堟爣璁版竻鎺�
-                    nObj.AgencyTempCancelTime__c = null;
-                    if (nObj.StockDown__c == false) {
-                        nObj.Asset__c = null;
-                        nObj.Select_Time__c = null;
-                        nObj.Shipment_request_time2__c = null;
-                        nObj.Shipment_request__c = false;
-                        // 鏍规嵁OLY_OCM-243璁拌浇,鍙栨秷涔熼渶瑕佹竻闄ゆ帴鍊熷嚭鏃剁浉鍏崇殑瀛楁
-                        if (nObj.DataMigration_Flag__c == false && (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))) {
-                            // 澶囧搧閰嶅鏄庣粏鍨嬪彿(鍊熷嚭鏃�)
-                            nObj.Fixture_Model_No_text__c = nObj.FSD_Fixture_Model_No__c;
-                        }
-                        // 鏈鸿韩缂栧彿锛堝�熷嚭鏃讹級
-                        nObj.SerialNumber_text__c = null;
-                        // 鎵�鍦ㄥ湴鍖�(鐪�) 鍊熷嚭鏃� #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
-                        nObj.SalesProvince_before__c = null;
-                        // 鎵�鍦ㄥ湴鍖�(鏈儴) 鍊熷嚭鏃� #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
-                        nObj.Salesdepartment_before__c = null;
-                        // 浜у搧鍒嗙被(GI/SP)(鍊熷嚭鏃�) #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
-                        nObj.Product_category_text__c = null;
-                        // 澶囧搧鍒嗙被(鍊熷嚭鏃�) #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
-                        nObj.Equipment_Type_text__c = null;
-                        // 澶囧搧鎴愭湰(鍊熷嚭鏃�)
-                        nObj.Asset_cost_del_before__c = null;
-                        // 澶囧搧瀛樻斁鍦�(鍊熷嚭鏃�)
-                        nObj.Internal_asset_location_before__c = null;
-                        //澶囧搧鍚嶇О(鍊熷嚭鏃�)
-                        nObj.Fixture_Name_text__c = nObj.FSD_Name_CHN__c;
-                        // 澶囧搧绠$悊缂栫爜(鍊熷嚭鏃�)
-                        nObj.EquipmentSet_Managment_Code_text__c = null;
-                    }
-                    //20201118 ljh add
-                    else{
-                        String ra_RecordTypeId = DEVELOPERNAMEMAP.get('AgencyRequest').getRecordTypeId();
-                        //System.debug('ra_RecordTypeId:'+ra_RecordTypeId);
-                        if(ra_RecordTypeId !=null && nObj.RA_RecordTypeId__c.substring(0,15) == ra_RecordTypeId.substring(0,15)){
-                            //nObj.Inspection_result__c = 'OK';
-                            nObj.Inspection_result_NG__c = null;
-                            nObj.Arrival_in_wh__c = true;
-                            nObj.Arrival_wh_time__c = System.now();
-                            nObj.Return_wh_chenk_staff__c = Userinfo.getUserId();
-                            nObj.Arrival_wh_Result_Agency__c = 'OK';
-                        }
-                    }
-                    //20201118 ljh add
-                } else {
-                    nObj.Cancel_Date__c = null;
-                    nObj.Cancel_Time__c = null;
-                    nObj.Cancel_Mem__c = null;
-                    //nObj.Cancel_Reason__c = null;
-                }
-            }
-            // 褰掕繕鍚嶤DS
-            if (Trigger.isInsert || oObj.CDS_complete__c != nObj.CDS_complete__c) {
-                if (nObj.CDS_complete__c) {
-                    nObj.CDS_complete_time__c = System.now();
-                    nObj.CDS_staff__c = UserInfo.getUserId();
-                } else {
-                    nObj.CDS_complete_time__c = null;
-                    nObj.CDS_staff__c = null;
-                }
-            }
-            System.debug(nObj.Return_Status_F__c);
-            // 蹇呫仛鏈�寰屻仹缃亸
-            //鍔广亱銇亜銇牬鍚堛亴銇傘倞銇俱仚銇仹After銇с倓銈娿伨銇�
-            // nObj.Repair_Status_Text__c = nObj.Repair_Status_F__c;
-            // nObj.Return_Status_Text__c = nObj.Return_Status_F__c;
-            // nObj.Shipment_Status_Text__c = nObj.Shipment_Status_F__c;
-            nObj.Canceled_Id__c = nObj.Canceled__c;
-            if (Trigger.isUpdate
-                && ((oObj.Inspection_result_after_Final__c != 'NG'
-                        && nObj.Inspection_result_after_Final__c == 'NG'
-                        && nObj.Inspection_result_after_NG_Final__c == '缁翠慨')
-                    || (oObj.Inspection_result_after__c != 'NG'
-                        && nObj.Inspection_result_after__c == 'NG'
-                        && nObj.Inspection_result_after_NG__c == '缁翠慨')
-                )
-            ) {
-                nObj.Repair__c = null;
-            }
-
-            // OLY_OCM-531 Start 鎼伐浣滄祦瑙勫垯
-            if (nObj.Check_lost_Item_F__c == '娆犲搧'
-                    && nObj.Loaner_Giveup_Time__c == null
-                    && nObj.Lost_item_giveup__c == true) {
-                nObj.Loaner_Giveup_Time__c = Datetime.now();
-            }
-
-            if (nObj.RAESD_Status__c == '鎺掗槦涓�'
-                    && nObj.Queue_Day_Text__c == null) {
-                nObj.Queue_Day_Text__c = nObj.Queue_Day__c;
-                nObj.Queue_Time_Text__c = nObj.Queue_Time__c;
-            }
-
-            // OLY_OCM-531 End
-            if (Trigger.isUpdate
-                    &&oObj.Confirm_Lost_Date__c != null
-                    && oObj.Check_lost_Item_F__c != nObj.Check_lost_Item_F__c
-                    && oObj.Check_lost_Item_F__c == '娆犲搧') {
-                nObj.Confirm_Lost_Date__c = null;
-            }
-
-            if (Trigger.isUpdate
-                    && oObj.Shipment_request_time2__c != nObj.Shipment_request_time2__c
-                    && nObj.Shipment_request_time2__c != null
-                    && nObj.Is_Body__c
-                    && shipment_requestedRaIdStaticSet.contains(nObj.Rental_Apply__c) == false
-                ) {
-                    shipment_requestedRaIdStaticSet.add(nObj.Rental_Apply__c);
-                    shipment_requestedRaIdSet.add(nObj.Rental_Apply__c);
-                }
-
-        }
+  private void deleteCheck() {
+    String ra_RecordTypeId = DEVELOPERNAMEMAP.get('AgencyRequest')
+      .getRecordTypeId();
+    for (Rental_Apply_Equipment_Set_Detail__c oObj : oldList) {
+      if (
+        (oObj.RA_RecordTypeId__c.substring(0, 15) !=
+        ra_RecordTypeId.substring(0, 15) &&
+        (oObj.Rental_Apply_Request_approval_time_F__c != null &&
+        oObj.ApplyPersonAppended_F__c == false) ||
+        (oObj.ApplyPersonAppended_F__c == true &&
+        oObj.Add_Request_approval_time__c != null)) ||
+        (oObj.RA_RecordTypeId__c.substring(0, 15) ==
+        ra_RecordTypeId.substring(0, 15) &&
+        (oObj.Rental_Apply_Request_approval_time_F__c != null &&
+        (oObj.Rental_Apply_CreatedDate_F__c > oObj.CreatedDate ||
+        oObj.StockDown__c == true) &&
+        !oObj.canDelete__c)) //20210523 ljh add 1829
+      ) {
+        oObj.addError('宸茬粡鎵瑰噯鐨勫鍝佸�熷嚭鏄庣粏涓嶈兘鍋氱墿鐞嗗垹闄ゃ��');
+      }
     }
-    /*
-    * Asset 銇甉uantity鏇存柊
-    * changeAssetCount()鏂规硶銇ut_of_wh__c銆丷ental_Count__c 鍑�1
-    */
-    private void changeAsset() {
-        if (Trigger.isUpdate && Trigger.isAfter) {
-            if (assMap.isEmpty()) {
-                return;
-            }
-            for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
-                if (!assMap.containsKey(nObj.Asset__c)) {
-                    continue;
-                }
-                Rental_Apply_Equipment_Set_Detail__c oObj = null;
-                if (Trigger.isUpdate) {
-                    oObj = oldMap.get(nObj.Id);
-                }
-                Asset ass = assMap.get(nObj.Asset__c);
-                // Abandoned_Inventory__c  null -> 0
-                if (ass.Abandoned_Inventory__c == null) {
-                    ass.Abandoned_Inventory__c = 0;
-                }
-                // Abandoned_RealThing__c  null -> 0
-                if (ass.Abandoned_RealThing__c == null) {
-                    ass.Abandoned_RealThing__c = 0;
-                }
-                if (ass.CountForRepair__c == null) {
-                    ass.CountForRepair__c = 0;
-                }
+  }
 
-                if (ass.Confirm_Lost_Count__c == null) {
-                    ass.Confirm_Lost_Count__c = 0;
-                }
-                if (String.isBlank(oObj.Check_lost_Item_F__c) && nObj.Check_lost_Item_F__c == 'OK') {
-                    //鏈叆鍔涖亱銈夋瑺鍝併伀澶夋洿鏅備綍銈傘仐銇俱仜銈�
-                } else if (String.isBlank(oObj.Check_lost_Item_F__c) && nObj.Check_lost_Item_F__c == '娆犲搧'
-                        && nObj.Lost_item_giveup__c == false) {
-                    //鏈叆鍔涖亱銈夋瑺鍝併伀澶夋洿鏅備綍銈傘仐銇俱仜銈�
-                } else if (String.isBlank(oObj.Check_lost_Item_F__c) && nObj.Check_lost_Item_F__c == '娆犲搧'
-                    && nObj.Lost_item_giveup__c == true) {
-                    //鏈叆鍔涖亱銈夋瑺鍝佹斁妫勩伀澶夋洿鏅� 鏀惧純娆犲搧鍥炴敹锛堜涪澶憋級銇仺銇� 寰呭簾寮冩暟(涓㈠け/鐩樹簭)鍔�1
-                    ass.Abandoned_Inventory__c += 1;
-                    if (oObj.Confirm_Lost_Date__c != null) {
-                        ass.Confirm_Lost_Count__c -= 1;
-                    }
-                    assUpdMap.put(ass.Id, ass);
-                } else if (String.isBlank(oObj.Check_lost_Item_F__c) && nObj.Check_lost_Item_F__c == '娑堣��') {
-                    //鏈叆鍔涖亱銈夋秷鑰椼伀澶夋洿鏅俀uantity銈�-1
-                    ass.Quantity -= 1;
-                    ass.ChangeQuantityReason__c = '娑堣��';
-                    assUpdMap.put(ass.Id, ass);
-                } else if (oObj.Check_lost_Item_F__c == 'OK' && String.isBlank(nObj.Check_lost_Item_F__c)) {
-                    //OK銇嬨倝绌虹櫧銇鏇存檪浣曘倐銇椼伨銇涖倱
-                } else if (oObj.Check_lost_Item_F__c == 'OK' && nObj.Check_lost_Item_F__c == '娆犲搧'
-                        && nObj.Lost_item_giveup__c == false) {
-                    //OK銇嬨倝娆犲搧銇鏇存檪浣曘倐銇椼伨銇涖倱
-                } else if (oObj.Check_lost_Item_F__c == 'OK' && nObj.Check_lost_Item_F__c == '娆犲搧'
-                        && nObj.Lost_item_giveup__c == true) {
-                    //OK銇嬨倝娆犲搧鏀炬銇鏇存檪 鏀惧純娆犲搧鍥炴敹锛堜涪澶憋級銇仺銇� 寰呭簾寮冩暟(涓㈠け/鐩樹簭)鍔�1
-                    ass.Abandoned_Inventory__c += 1;
-                    if (oObj.Confirm_Lost_Date__c != null) {
-                        ass.Confirm_Lost_Count__c -= 1;
-                    }
-                    assUpdMap.put(ass.Id, ass);
-                } else if (oObj.Check_lost_Item_F__c == 'OK' && nObj.Check_lost_Item_F__c == '娑堣��') {
-                    //OK銇嬨倝娑堣�椼伀澶夋洿鏅俀uantity銈�-1
-                    ass.Quantity -= 1;
-                    ass.ChangeQuantityReason__c = '娑堣��';
-                    assUpdMap.put(ass.Id, ass);
-                } else if (oObj.Check_lost_Item_F__c == '娆犲搧' && String.isBlank(nObj.Check_lost_Item_F__c)
-                        && oObj.Lost_item_giveup__c == false) {
-                    if (oObj.Confirm_Lost_Date__c != null) {
-                        ass.Confirm_Lost_Count__c -= 1;
-                    }
-                    assUpdMap.put(ass.Id, ass);
-                } else if (oObj.Check_lost_Item_F__c == '娆犲搧' && nObj.Check_lost_Item_F__c == 'OK'
-                        && oObj.Lost_item_giveup__c == false) {
-                    if (oObj.Confirm_Lost_Date__c != null) {
-                        ass.Confirm_Lost_Count__c -= 1;
-                    }
-                    assUpdMap.put(ass.Id, ass);
-                } else if (oObj.Check_lost_Item_F__c == '娆犲搧' && nObj.Check_lost_Item_F__c == '娆犲搧'
-                        && oObj.Lost_item_giveup__c == false && nObj.Lost_item_giveup__c == true) {
-                    //娆犲搧銇嬨倝娆犲搧鏀炬銇鏇存檪 鏀惧純娆犲搧鍥炴敹锛堜涪澶憋級銇仺銇� 寰呭簾寮冩暟(涓㈠け/鐩樹簭)鍔�1
-                    ass.Abandoned_Inventory__c += 1;
-                    if (oObj.Confirm_Lost_Date__c != null) {
-                        ass.Confirm_Lost_Count__c -= 1;
-                    }
-                    assUpdMap.put(ass.Id, ass);
-                } else if (oObj.Check_lost_Item_F__c == '娆犲搧' && nObj.Check_lost_Item_F__c == '娑堣��'
-                        && oObj.Lost_item_giveup__c == false) {
-                    //娆犲搧銇嬨倝娑堣�椼伀澶夋洿鏅俀uantity銈�-1
-                    ass.Quantity -= 1;
-                    ass.ChangeQuantityReason__c = '娑堣��';
-                    if (oObj.Confirm_Lost_Date__c != null) {
-                        ass.Confirm_Lost_Count__c -= 1;
-                    }
-                    assUpdMap.put(ass.Id, ass);
-                } else if (oObj.Check_lost_Item_F__c == '娆犲搧' && String.isBlank(nObj.Check_lost_Item_F__c) && oObj.Lost_item_giveup__c == true) {
-                    //娆犲搧鏀炬銇嬨倝绌虹櫧銇鏇存檪 寰呭簾寮冩暟(涓㈠け/鐩樹簭)鍑�1
-                    ass.Abandoned_Inventory__c -= 1;
-                    ass.Out_of_wh__c += 1;
-                    ass.Rental_Count__c += 1;
-                    ass.ChangeQuantityReason__c = '娆犲搧' + '->' + '';
-                    assUpdMap.put(ass.Id, ass);
-                } else if (oObj.Check_lost_Item_F__c == '娆犲搧' && nObj.Check_lost_Item_F__c == 'OK' && oObj.Lost_item_giveup__c == true) {
-                    //娆犲搧鏀炬銇嬨倝OK銇鏇存檪 寰呭簾寮冩暟(涓㈠け/鐩樹簭)鍑�1
-                    ass.Abandoned_Inventory__c -= 1;
-                    ass.Out_of_wh__c += 1;
-                    ass.Rental_Count__c += 1;
-                    ass.ChangeQuantityReason__c = '娆犲搧' + '->' + 'OK';
-                    assUpdMap.put(ass.Id, ass);
-                } else if (oObj.Check_lost_Item_F__c == '娆犲搧' && nObj.Check_lost_Item_F__c == '娆犲搧'
-                        && oObj.Lost_item_giveup__c == true && nObj.Lost_item_giveup__c == false) {
-                    //娆犲搧鏀炬銇嬨倝娆犲搧銇鏇存檪 寰呭簾寮冩暟(涓㈠け/鐩樹簭)鍑�1
-                    ass.Abandoned_Inventory__c -= 1;
-                    ass.Out_of_wh__c += 1;
-                    ass.Rental_Count__c += 1;
-                    ass.ChangeQuantityReason__c = '娆犲搧鏀惧純 -> ' + '娆犲搧';
-                    assUpdMap.put(ass.Id, ass);
-                } else if (oObj.Check_lost_Item_F__c == '娆犲搧' && nObj.Check_lost_Item_F__c == '娑堣��' && oObj.Lost_item_giveup__c == true) {
-                    //娆犲搧鏀炬銇嬨倝娑堣�椼伀澶夋洿鏅� 寰呭簾寮冩暟(涓㈠け/鐩樹簭)鍑�1 Quantity銈�-1
-                    ass.Abandoned_Inventory__c -= 1;
-                    ass.Quantity -= 1;
-                } else if (oObj.Check_lost_Item_F__c == '娑堣��' && String.isBlank(nObj.Check_lost_Item_F__c)) {
-                    //娑堣�椼亱銈夌┖鐧姐伀澶夋洿鏅俀uantity銈�+1
-                    ass.Quantity += 1;
-                    ass.Out_of_wh__c += 1;
-                    ass.Rental_Count__c += 1;
-                    ass.ChangeQuantityReason__c = '娑堣�� -> ' + '';
-                    assUpdMap.put(ass.Id, ass);
-                } else if (oObj.Check_lost_Item_F__c == '娑堣��' && nObj.Check_lost_Item_F__c == 'OK') {
-                    //娑堣�椼亱銈夌┖鐧姐伀澶夋洿鏅俀uantity銈�+1
-                    ass.Quantity += 1;
-                    ass.Out_of_wh__c += 1;
-                    ass.Rental_Count__c += 1;
-                    ass.ChangeQuantityReason__c = '娑堣�� -> ' + 'OK';
-                    assUpdMap.put(ass.Id, ass);
-                } else if (oObj.Check_lost_Item_F__c == '娑堣��' && nObj.Check_lost_Item_F__c == '娆犲搧'
-                        && nObj.Lost_item_giveup__c == false) {
-                    //娑堣�椼亱銈夋瑺鍝併伀澶夋洿鏅俀uantity銈�+1
-                    ass.Quantity += 1;
-                    ass.Out_of_wh__c += 1;
-                    ass.Rental_Count__c += 1;
-                    ass.ChangeQuantityReason__c = '娑堣�� -> 娆犲搧';
-                    assUpdMap.put(ass.Id, ass);
-                } else if (oObj.Check_lost_Item_F__c == '娑堣��' && nObj.Check_lost_Item_F__c == '娆犲搧'
-                        &&  nObj.Lost_item_giveup__c == true) {
-                    //娑堣�椼亱銈夋瑺鍝佹斁妫勩伀澶夋洿鏅� 寰呭簾寮冩暟(涓㈠け/鐩樹簭)+1 Quantity銈�+1
-                    ass.Abandoned_Inventory__c += 1;
-                    ass.Quantity += 1;
-                }
-                // 缁翠慨
-                if (oObj.Arrival_in_wh__c == false && nObj.Arrival_in_wh__c == true
-                        && nObj.Arrival_wh_Result_Agency__c == '寰呬慨鐞�') {
-                    ass.CountForRepair__c += 1;
-                    assUpdMap.put(ass.Id, ass);
-                }
-                //搴熷純
-                if (oObj.Arrival_in_wh__c == false && nObj.Arrival_in_wh__c == true
-                        && (nObj.Inspection_result_after_NG_F__c == '搴熷純'
-                            //鍑哄簱鍓嶆娴嬪簾寮冪殑鏃跺�欎篃闇�瑕佸垽鏂�
-                            || nObj.Inspection_result_NG__c == '搴熷純')) {
-                    ass.Abandoned_RealThing__c += 1;
-                    ass.ChangeQuantityReason__c = FixtureUtil.raesdStatusMap.get(FixtureUtil.HistoryStatus.Dai_Fei_Qi.ordinal());
-                    assUpdMap.put(ass.Id, ass);
-                } else if (oObj.Arrival_in_wh__c == true && nObj.Arrival_in_wh__c == false
-                        && (oObj.Inspection_result_after_NG_F__c == '搴熷純'
-                            //鍑哄簱鍓嶆娴嬪簾寮冪殑鏃跺�欎篃闇�瑕佸垽鏂�
-                            || oObj.Inspection_result_NG__c == '搴熷純')) {
-                    ass.Abandoned_RealThing__c -= 1;
-                    ass.Out_of_wh__c += 1;
-                    ass.Rental_Count__c += 1;
-                    // ass.Freeze_sign__c = true; // OLY_OCM-689 鍒犻櫎鍐荤粨瀛楁鐨勬洿鏂�
-                    String rea = nObj.Inspection_result_after_NG_F__c == '搴熷純' ? '寰呯Щ鑷虫姤搴熷尯' : nObj.Inspection_result_after_NG_F__c;
-                    ass.ChangeQuantityReason__c = FixtureUtil.raesdStatusMap.get(FixtureUtil.HistoryStatus.Dai_Fei_Qi.ordinal()) + ' ->' + rea;
-                    assUpdMap.put(ass.Id, ass);
-                }
-                //寰呭簾寮�
-                if (nObj.RAESD_Status__c == FixtureUtil.raesdStatusMap.get(FixtureUtil.HistoryStatus.Dai_Fei_Qi.ordinal())
-                        && oObj.RAESD_Status__c != nObj.RAESD_Status__c
-                        && ass.Manage_type__c == '涓綋绠$悊') {
-                    ass.Status = FixtureUtil.assetStatusMap.get(FixtureUtil.AssetStatus.Dai_Fei_Qi.ordinal());
-                    // ass.Freeze_sign__c = true;
-                    assUpdMap.put(ass.Id, ass);
-                }
-                // 鍔炰簨澶勫洖搴撶粨鏋滀慨鏀�
-                if(oObj.Arrival_in_wh__c && nObj.Arrival_in_wh__c
-                    && oObj.Arrival_wh_Result_Agency__c != nObj.Arrival_wh_Result_Agency__c ) {
-                    switch on oObj.Arrival_wh_Result_Agency__c {
-                        when '绉昏嚦鎶ュ簾鍖�' {
-                            ass.Abandoned_RealThing__c -=1;
-                        }
-                        when '寰呬慨鐞�' {
-                            ass.CountForRepair__c -=1;
-                        }
-                    }
-                    switch on nObj.Arrival_wh_Result_Agency__c {
-                        when '绉昏嚦鎶ュ簾鍖�' {
-                            ass.Abandoned_RealThing__c +=1;
-                        }
-                        when '寰呬慨鐞�' {
-                            ass.CountForRepair__c +=1;
-                        }
-                    }
-                    assUpdMap.put(ass.Id, ass);
-                }
-                // //宸叉秷鑰�
-                // else if (nObj.Check_lost_Item_Final__c == '娑堣��'
-                //         && oObj.Check_lost_Item_Final__c != nObj.Check_lost_Item_Final__c
-                //         && ass.Manage_type__c == '涓綋绠$悊') {
-                //     ass.Status = FixtureUtil.assetFixtureStatusMap.get(FixtureUtil.AssetFixtureStatus.Yi_Xiao_Hao.ordinal());
-                //     assUpdMap.put(ass.Id, ass);
-                // }
-                //涓㈠け
-                // else if (nObj.Lost_item_giveup__c == true
-                //         && oObj.Lost_item_giveup__c != nObj.Lost_item_giveup__c
-                //         && ass.Manage_type__c == '涓綋绠$悊') {
-                    // ass.Status = FixtureUtil.assetFixtureStatusMap.get(FixtureUtil.AssetFixtureStatus.Diu_Shi.ordinal());
-                    // assUpdMap.put(ass.Id, ass);
-                // }
-                // else if (ass.Manage_type__c == '鏁伴噺绠$悊' && assMap.containsKey(ass.Id)) {
-                //     if (ass.Quantity != null && ass.Quantity > 0) {
-                //         if (ass.Status != FixtureUtil.assetFixtureStatusMap.get(FixtureUtil.AssetFixtureStatus.Ke_Yi_Fen_Pei.ordinal())) {
-                //             ass.Status = FixtureUtil.assetFixtureStatusMap.get(FixtureUtil.AssetFixtureStatus.Ke_Yi_Fen_Pei.ordinal());
-                //             assUpdMap.put(ass.Id, ass);
-                //         }
-                //     }
-                //     else {
-                //         if (ass.Status != FixtureUtil.assetFixtureStatusMap.get(FixtureUtil.AssetFixtureStatus.Mei_You_Ku_Cun.ordinal())) {
-                //             ass.Status = FixtureUtil.assetFixtureStatusMap.get(FixtureUtil.AssetFixtureStatus.Mei_You_Ku_Cun.ordinal());
-                //             assUpdMap.put(ass.Id, ass);
-                //         }
-                //     }
-                // }
-            }
+  private void setConsumSend_Rental_Apply_EmailTime() {
+    if (shipment_requestedRaIdSet.isEmpty() == false) {
+      List<Consum_Apply__c> caList = [
+        SELECT Id, Loaner_centre_mail_address__c
+        FROM Consum_Apply__c
+        WHERE Rental_Apply__c = :shipment_requestedRaIdSet
+      ];
+      if (caList.size() > 0) {
+        Datetime dt = Datetime.now();
+        for (Consum_Apply__c ca : caList) {
+          ca.Send_Rental_Apply_EmailTime__c = dt;
         }
+        update caList;
+      }
+      shipment_requestedRaIdSet = new Set<Id>();
     }
-    /*
-     * 鍥炲簱纭 OFF -> ON:
-     * 鍙栨秷鍒嗛厤 OFF -> ON:
-     * 鏀惧純娆犲搧 OFF -> ON
-     * 宸叉秷鑰�
-     *
-     *  娓呯┖Asset 鏈�鏂板鍝佺敵璇峰�熷嚭鏄庣粏 Last_Reserve_RAES_Detail__c
-     *  (nObj.Asset__c 澶夋洿銇椼仾銇勩仧銈併�乧hangeAssetLast()銇с偗銉偄銇с亶銇亜銇熴倎銆併亾銇撱仹銈儶銈�)
-     *
-     * 銈儵銈广伄 assUpdMap 銈掓洿鏂般仚銈嬨仩銇�
-     */
-    private void clearLastReserveRAESD() {
-        for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
-            Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
-            // 涓讳綋鍜岄檮灞炲搧
-            if (finishOrChangeAsset(Trigger.isDelete, oObj, nObj)) {
-                Asset ass = assMap.get(nObj.Asset__c);
-                if (assUpdMap.containsKey(nObj.Asset__c)) {
-                    ass = assUpdMap.get(nObj.Asset__c);
-                }
-                // 杩欓噷 浼氬嚭鐜� assUpdMap 鏈� 浣嗘槸 assMap 娌℃湁鐨勬儏鍐�
-                if (ass == null
-                        //鍒嗛厤澶囧搧鏈夊彉鍖� (涓嬫灦鍓�)
-                        && (oObj.Asset__c != null && oObj.Asset__c != nObj.Asset__c
-                                && nObj.StockDown__c == false)) {
-                    ass = new Asset(Id = oObj.Asset__c);
-                }
-                if (ass == null) {
-                    continue;
-                }
-                // 鏆傛椂鏀惧湪杩欓噷
-                if (oObj.Manage_type_F__c == '涓綋绠$悊') {
-                    ass.Last_Reserve_RAES_Detail__c = null;
-                    assUpdMap.put(ass.Id, ass);
-                }
-            }
-        }
-    }
-    //nObj.Asset__c銇屻亗銈嬪牬鍚堛�佸鏇淬仐銇熷牬鍚�
-    private void changeAssetLast() {
-        for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
-            Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
-            Asset nass = assMap.get(nObj.Asset__c);
-            if (assUpdMap.containsKey(nObj.Asset__c)) {
-                nass = assUpdMap.get(nObj.Asset__c);
-            } else if (String.isNotBlank(nObj.Asset__c)) {
-                nass = new Asset(Id = nObj.Asset__c);
-            }
-            Asset oass = assMap.get(oObj.Asset__c);
-            if (assUpdMap.containsKey(oObj.Asset__c)) {
-                oass = assUpdMap.get(oObj.Asset__c);
-            } else if (String.isNotBlank(oObj.Asset__c)) {
-                oass = new Asset(Id = oObj.Asset__c);
-            }
-            //nObj.Asset__c銇屻亗銈嬪牬鍚堛�佸鏇淬仐銇熷牬鍚�
-            if (nObj.Asset__c != null && oObj.Asset__c != nObj.Asset__c
-                    && (oObj.Manage_type_F__c == '涓綋绠$悊' || nObj.Manage_type_F__c == '涓綋绠$悊')) {
-                if (nObj.Manage_type_F__c == '涓綋绠$悊') {
-                    nass.Last_Reserve_RAES_Detail__c = nObj.Id;
-                    assUpdMap.put(nass.Id, nass);
-                }
-                if (oObj.Manage_type_F__c == '涓綋绠$悊') {
-                    oass.Last_Reserve_RAES_Detail__c = null;
-                    assUpdMap.put(oass.Id, oass);
-                }
-            }
-        }
-    }
-    // 鍙栨秷鍒嗛厤 鐨勬椂鍊�, 闇�瑕佸湪 beforeSetValue() 閲屾妸 Asset__c 娓呴櫎
-    //鏄庣窗绲備簡銇ˋsset澶夋洿銇檪Out_of_wh__c銈掓洿鏂�
-    //afterupdate銇伩瀹熻
-    private void changeAssetCount() {
-        for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
-            Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
-            Asset nass = assMap.get(nObj.Asset__c);
-            if (assUpdMap.containsKey(nObj.Asset__c)) {
-                nass = assUpdMap.get(nObj.Asset__c);
-            } else if (String.isNotBlank(nObj.Asset__c)) {
-                nass = new Asset(Id = nObj.Asset__c);
-            }
-            Asset oass = assMap.get(oObj.Asset__c);
-            if (assUpdMap.containsKey(oObj.Asset__c)) {
-                oass = assUpdMap.get(oObj.Asset__c);
-            } else if (String.isNotBlank(oObj.Asset__c)) {
-                oass = new Asset(Id = oObj.Asset__c);
-            }
-            //Map銇獳sset銈掓柊瑕弍ush鏅傚�ゃ倰瑷畾
-            if (oass != null && (oass.Out_of_wh__c == null || oass.Rental_Count__c == null || oass.Confirm_Lost_Count__c == null)) {
-                oass.Out_of_wh__c = oObj.Out_of_wh__c;
-                oass.Rental_Count__c = oObj.Rental_Count__c;
-                oass.Confirm_Lost_Count__c = oObj.Confirm_Lost_Count__c;
-            }
-            if (nass != null && (nass.Out_of_wh__c == null || nass.Rental_Count__c == null || nass.Confirm_Lost_Count__c == null)) {
-                nass.Out_of_wh__c = nObj.Out_of_wh__c;
-                nass.Rental_Count__c = nObj.Rental_Count__c;
-                nass.Confirm_Lost_Count__c = nObj.Confirm_Lost_Count__c;
-            }
-            // 鏈�绲傜姸鎱嬪強銇ˋsset澶夋洿銇牬鍚�
-            if (finishOrChangeAsset(Trigger.isDelete, oObj, nObj)) {
-                System.debug('oass is ' + oass);
-                if (oass != null) {
-                    if (oass.Out_of_wh__c != null && oass.Out_of_wh__c > 0) {
-                        oass.Out_of_wh__c = oass.Out_of_wh__c - 1;
-                        // assUpdMap.put(oass.Id, oass);
-                        System.debug('oass.Out_of_wh__c -1' + oass.Out_of_wh__c + ' Id = ' + nObj.Id);
-                    }
-                    if (nObj.DeliverySlip__c != null) {
-                        if (oass.Rental_Count__c != null && oass.Rental_Count__c > 0) {
-                            oass.Rental_Count__c = oass.Rental_Count__c - 1;
-                        }
-                    }
-                        assUpdMap.put(oass.Id, oass);
-                }
-            } else if (oass != null && oObj.DeliverySlip__c != null && nObj.DeliverySlip__c == null) {
-                //鍙戣揣杩愯緭鍗� 鍒犻櫎鐨勬椂鍊欏凡鍊熷嚭鏁� -1 鍙戣揣Asset__c鍘熷垯涓嶄細鍙樻墍浠ュ氨鐩存帴鐢ㄤ笂闈㈢殑oass
-                // if (nObj.DeliverySlip__c != null) {
-                if (oass.Rental_Count__c != null && oass.Rental_Count__c > 0) {
-                    oass.Rental_Count__c = oass.Rental_Count__c - 1;
-                    assUpdMap.put(oass.Id, oass);
-                }
-                // }
-            }
-            if (oObj.Confirm_Lost_Date__c == null
-                    && nObj.Confirm_Lost_Date__c != null) {
-                nass.Confirm_Lost_Count__c = nass.Confirm_Lost_Count__c + 1;
-                assUpdMap.put(nass.Id, nass);
-            }
-            else if (nObj.Confirm_Lost_Date__c == null
-                    && oObj.Confirm_Lost_Date__c != null
-                    && nass.Confirm_Lost_Count__c > 0) {
-                nass.Confirm_Lost_Count__c = nass.Confirm_Lost_Count__c - 1;
-                assUpdMap.put(nass.Id, nass);
-            }
-            //鍙戣揣杩愯緭鍗曡缃殑鏃跺�欏凡瑙i櫎鏁�+1
-            if (oObj.DeliverySlip__c == null && nObj.DeliverySlip__c != null) {
-                nass.Rental_Count__c = nass.Rental_Count__c + 1;
-                assUpdMap.put(nass.Id, nass);
-            }
-            //nObj.Asset__c銇屻亗銈嬪牬鍚堛�佸鏇淬仐銇熷牬鍚�
-            System.debug(LoggingLevel.INFO, '*** nObj.Asset__c: ' + nObj.Asset__c);
-            if (nObj.Asset__c != null && oObj.Asset__c != nObj.Asset__c) {
-                nass.Out_of_wh__c = nass.Out_of_wh__c + 1;
-                System.debug('nass.Out_of_wh__c +1' + nass.Out_of_wh__c  + ' Id = ' + nObj.Id);
-                assUpdMap.put(nass.Id, nass);
-            }
-        }
-    }
-    // 鍚屻仒block 銇� 鎺掗槦銉偝銉笺儔 Queue_Number__c 銈抮efresh
-    // private void refreshQueueNumberByBlock() {
-    //     for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
-    //         Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
-    //         // 鍚屻仒block 銇� 鎺掗槦澶夋洿銇屻亗銈嬪牬鍚�
-    //         if (oObj.Cancel_Select__c == false
-    //                 && String.isBlank(oObj.Fixture_Model_No_text__c) == false
-    //                 && String.isBlank(oObj.Salesdepartment_before__c) == false
-    //                 && String.isBlank(oObj.Product_category_text__c) == false
-    //                 && String.isBlank(oObj.Equipment_Type_text__c) == false
-    //                 && oObj.Queue_Number__c > 0
-    //                 // 澶夊寲銈掔⒑瑾�
-    //                 && (oObj.Cancel_Select__c != nObj.Cancel_Select__c
-    //                     || oObj.Fixture_Model_No_text__c != nObj.Fixture_Model_No_text__c
-    //                     || oObj.Salesdepartment_before__c != nObj.Salesdepartment_before__c
-    //                     || oObj.Product_category_text__c != nObj.Product_category_text__c
-    //                     || oObj.Equipment_Type_text__c != nObj.Equipment_Type_text__c
-    //                     || (nObj.Queue_Number__c == 0 || nObj.Queue_Number__c == null))
-    //         ) {
-    //             if (executeed_refreshQueueNumber.contains(nObj.Id) && executeed_refreshQueueNumber.contains(oObj.Id)) {
-    //                 continue;
-    //             }
-    //             else if (executeed_refreshQueueNumber.contains(nObj.Id) == false) {
-    //                 executeed_refreshQueueNumber.add(nObj.Id);
-    //             } else {   //  executeed_refreshQueueNumber.contains(oObj.Id) == false
-    //                 executeed_refreshQueueNumber.add(oObj.Id);
-    //             }
-    //             // TODO 鎯冲畾 鐢婚潰銇嬨倝銇�1 record 銇椼亱銇亜
-    //             List<Rental_Apply_Equipment_Set_Detail__c> updateList = new List<Rental_Apply_Equipment_Set_Detail__c>();
-    //             List<Rental_Apply_Equipment_Set_Detail__c> refreshTargetList = [
-    //                     Select Id, Queue_Number__c
-    //                       from Rental_Apply_Equipment_Set_Detail__c
-    //                      where Cancel_Select__c = false
-    //                        and Fixture_Model_No_text__c = :oObj.Fixture_Model_No_text__c
-    //                        and Salesdepartment_before__c = :oObj.Salesdepartment_before__c
-    //                        and Product_category_text__c = :oObj.Product_category_text__c
-    //                        and Equipment_Type_text__c = :oObj.Equipment_Type_text__c
-    //                        and Queue_Number__c > 0
-    //                      Order by Queue_Number__c];
-    //             for (Integer i = 0; i < refreshTargetList.size(); i++) {
-    //                 Rental_Apply_Equipment_Set_Detail__c refreshTarget = refreshTargetList[i];
-    //                 if (refreshTarget.Queue_Number__c != (i + 1)) {
-    //                     refreshTarget.Queue_Number__c = i + 1;
-    //                     executeed_refreshQueueNumber.add(refreshTarget.Id);
-    //                     updateList.add(refreshTarget);
-    //                 }
-    //             }
-    //             if (!updateList.isEmpty()) { update updateList; }
-    //         }
-    //     }
-    // }
+  }
 
-    // 4-XX 涓嬫灦鍚�, 鍑哄簱鍓嶆娴嬬殑Action涓�瀵逛竴鍒嗛厤鐨勮瘽, 鍜屼富浣撲竴璧� Cancel
-    private void oneToOne4XX() {
-
-        //涓讳綋CnacelSet
-        Set<Id> raesdBodyCnacelSet = new Set<Id>();
-        Set<Id> raesdBodyNGSet = new Set<Id>();
-        //鏆傛椂鍙�冭檻涓讳綋NG鎴栬�呭彇娑堢殑鏃跺��
-        Map<Id, String> raesdCancel_Remarks = new Map<Id, String>();
-        //妫�娴婲G鎴栬�呮湰鏉ュ氨Cancel鐨勪笉闇�瑕佸啀鏇存柊
-        Set<Id> raesdIdSet = new Set<Id>();
-        String ra_RecordTypeId = DEVELOPERNAMEMAP.get('AgencyRequest').getRecordTypeId();
-
-        for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
-            // 鍔炰簨澶勯檮灞炲搧涓嶉渶瑕侀殢涓讳綋鍙栨秷
-            if(nObj.RA_RecordTypeId__c.substring(0,15) == ra_RecordTypeId.substring(0,15)) {
-                continue;
-            }
-            Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
-            //Set娌℃湁cancel鐨勮瘽閮介渶瑕佹嫹璐�
-            //涓讳綋鍑哄簱鍓嶆娴婲G 缁翠慨
-            if (nObj.Is_Body__c == true
-                    && nObj.Inspection_result__c == 'NG'
-                    && oObj.Inspection_result__c != nObj.Inspection_result__c
-                    && nObj.Inspection_result_NG__c == '缁翠慨') {
-                //闇�瑕侀噸鏂板垎閰嶄竴瀵逛竴闄勫睘鍝佺殑涓�瑙�
-                raesdBodyNGSet.add(nObj.Rental_Apply_Equipment_Set__c);
-                raesdCancel_Remarks.put(nObj.Rental_Apply_Equipment_Set__c, nObj.Loaner_cancel_Remarks__c);
-                raesdIdSet.add(nObj.Id);
-            }
-            //涓讳綋鍑哄簱鍓嶆娴婲G 搴熷純
-            else if (nObj.Is_Body__c == true
-                    && nObj.Inspection_result__c == 'NG'
-                    && oObj.Inspection_result__c != nObj.Inspection_result__c
-                    && nObj.Inspection_result_NG__c == '搴熷純') {
-                //闇�瑕侀噸鏂板垎閰嶄竴瀵逛竴闄勫睘鍝佺殑涓�瑙�
-                raesdBodyNGSet.add(nObj.Rental_Apply_Equipment_Set__c);
-                raesdCancel_Remarks.put(nObj.Rental_Apply_Equipment_Set__c, nObj.Loaner_cancel_Remarks__c);
-                raesdIdSet.add(nObj.Id);
-            }
-            //闄勫睘鍝佸嚭搴撳墠妫�娴婲G 缁翠慨 骞朵笖鏄竴瀵逛竴鍒嗛厤
-            else if (nObj.Is_Body__c == false
-                    && nObj.Inspection_result__c == 'NG'
-                    && oObj.Inspection_result__c != nObj.Inspection_result__c
-                    && nObj.Inspection_result_NG__c == '缁翠慨'
-                    && nObj.OneToOne_Flag__c == true) {
-                raesdIdSet.add(nObj.Id);
-            }
-            //闄勫睘鍝佸嚭搴撳墠妫�娴婲G 搴熷純 骞朵笖鏄竴瀵逛竴鍒嗛厤
-            else if (nObj.Is_Body__c == false
-                    && nObj.Inspection_result__c == 'NG'
-                    && oObj.Inspection_result__c != nObj.Inspection_result__c
-                    && nObj.Inspection_result_NG__c == '搴熷純'
-                    && nObj.OneToOne_Flag__c == true) {
-                raesdIdSet.add(nObj.Id);
-            }
-            //OLY_OCM-152 涓嬫灦鍚庝富浣撳彇娑堢殑璇濅竴瀵逛竴闄勫睘鍝佷篃瑕佷竴璧峰彇娑�
-            else if (String.isBlank(nObj.DeliverySlip__c)
-                    && nObj.Is_Body__c == true
-                    && nObj.StockDown__c == true
-                    && oObj.Cancel_Select__c == false
-                    && nObj.Cancel_Select__c == true) {
-                raesdIdSet.add(nObj.Id);
-                raesdBodyCnacelSet.add(nObj.Rental_Apply_Equipment_Set__c);
-                raesdCancel_Remarks.put(nObj.Rental_Apply_Equipment_Set__c, nObj.Loaner_cancel_Remarks__c);
-            }
-        }
-        if (raesdBodyNGSet.isEmpty() && raesdBodyCnacelSet.isEmpty()) {
-            return;
-        }
-        List<Rental_Apply_Equipment_Set_Detail__c> raesds = [
-                Select Id, UniqueKey__c, Rental_Apply_Equipment_Set__c,
-                        Rental_Apply__c, Fixture_Set_Detail__c, Cancel_Reason__c
-                From Rental_Apply_Equipment_Set_Detail__c
-                //涓讳綋鍑哄簱鍓嶆娴婲G涓�瑙堢殑鎵�鏈変竴瀵逛竴鍒嗛厤鐨勬槑缁�
-                Where (Rental_Apply_Equipment_Set__c = :raesdBodyNGSet
-                    //涓嬫灦鍚庝富浣撳彇娑堜竴瀵逛竴闄勫睘鍝佷篃瑕佷竴璧峰彇娑�
-                       OR Rental_Apply_Equipment_Set__c = :raesdBodyCnacelSet)
-                    AND OneToOne_Flag__c = true
-                    //鍜屼富浣撲竴璧锋娴婲G鐨勪笉鍐嶆洿鏂�
-                    AND Id !=: raesdIdSet];
-        List<Rental_Apply_Equipment_Set_Detail__c> raesdList = new List<Rental_Apply_Equipment_Set_Detail__c>();
-        for (Rental_Apply_Equipment_Set_Detail__c raesd : raesds) {
-            raesd.OnStock_By_Cancel__c = true;
-            raesd.Cancel_Select__c = true;
-            // OLY_OCM-163#comment-20120592 閫氳繃鍙栨秷鏃ュ垽鏂� -銆� 鏇存柊鐨勬椂鍊檅efore璁剧疆
-            //raesd.Cancel_Date__c = Date.today();
-            raesd.Cancel_Reason__c = '閲嶆柊鍒嗛厤';
-            raesd.Loaner_cancel_reason__c = '鍏朵粬';// 20210830 ljh SFDC-C448KZ add            
-            //涓讳綋鍑哄簱鍓嶆鏌G鐨勮瘽鍙栨秷澶囨敞鍥炶嚜鍔ㄨ缃负鍑哄簱鍓嶆鏌G
-            raesd.Loaner_cancel_Remarks__c = raesdCancel_Remarks.get(raesd.Rental_Apply_Equipment_Set__c);
-            // }
-            raesdList.add(raesd);
-        }
-        System.debug('raesdList size' + raesdList.size());
-        if (!raesdList.isEmpty()) {
-            update raesdList;
-        }
+  private void beforeSetValue() {
+    Set<Id> raesdSet = new Set<Id>();
+    for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
+      raesdSet.add(nObj.Rental_Apply_Equipment_Set__c);
     }
+    Map<Id, Rental_Apply_Equipment_Set__c> raesdMap = new Map<Id, Rental_Apply_Equipment_Set__c>(
+      [
+        SELECT Id, Fixture_Set__r.Name, IndexFromUniqueKey__c
+        FROM Rental_Apply_Equipment_Set__c
+        WHERE Id = :raesdSet
+      ]
+    );
+    String agencyRecordTypeId = DEVELOPERNAMEMAP.get('AgencyRequest')
+      .getRecordTypeId();
 
-    //涓�瑙堝崟浣嶅彇娑堝悗鐨勬嫹璐濆湪涓�瑙堢殑Handler閲岄潰鍋�
-    // 鍥犱负cancel鏄富浣撶殑璇滷irst搴斿紑濮嬫嫹璐濆嚭鏉ョ殑涓讳綋鎵�浠irst鐨勬洿鏂伴�昏緫绉诲姩鍒癱ancelcopy
-    private void cancelCopy() {
-        List<Rental_Apply_Equipment_Set_Detail__c> raesdList = new List<Rental_Apply_Equipment_Set_Detail__c>();
-        List<Rental_Apply_Equipment_Set_Detail__c> raesdListup = new List<Rental_Apply_Equipment_Set_Detail__c>();
-        Map<Id, Rental_Apply_Equipment_Set__c> raesMap = new Map<Id, Rental_Apply_Equipment_Set__c>();
-        String ra_RecordTypeId = DEVELOPERNAMEMAP.get('AgencyRequest').getRecordTypeId();
-        for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
-            Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
-            //Set娌℃湁cancel鐨勮瘽閮介渶瑕佹嫹璐�
-            //Cancel_Select__c 銇痜alse銇嬨倝true銇鏇淬仾銇仹銇伄銇rigger浜屽洖銇仐銇︺倐瀹熻銇欍倠銇伅锛戝洖銇犮亼
-            if (nObj.Set_Cancel_Select__c == false
-                    && (oObj.Cancel_Select__c == false && nObj.Cancel_Select__c == true)
-                    && nObj.StockDown__c == true && nObj.Cancel_Reason__c == '閲嶆柊鍒嗛厤'
-                    // 鍔炰簨澶勫彇娑堟椂涓嶈鎷疯礉鏄庣粏锛屽湪controller閲屾墜鍔ㄩ��
-                    && nObj.RA_RecordTypeId__c.substring(0,15) != ra_RecordTypeId.substring(0,15)) {
-                Rental_Apply_Equipment_Set_Detail__c craesd = new Rental_Apply_Equipment_Set_Detail__c();
-                craesd.Rental_Apply_Equipment_Set__c = nObj.Rental_Apply_Equipment_Set__c;
-                craesd.Rental_Apply__c               = nObj.Rental_Apply__c;
-                craesd.Fixture_Set_Detail__c         = nObj.Fixture_Set_Detail__c;
-                craesd.Fixture_Model_No_text__c      = nObj.FSD_Fixture_Model_No__c;
-                craesd.Fixture_Name_text__c          = nObj.FSD_Name_CHN__c;
-                craesd.IndexFromUniqueKey_Text__c    = nObj.IndexFromUniqueKey_Text__c;
-                craesd.Canceled__c                   = nObj.Id;
-                craesd.FSD_Id__c                     = nObj.FSD_Id__c;
-                craesd.FSD_Is_Optional__c            = nObj.FSD_Is_Optional_F__c;
-                craesd.FSD_Is_OneToOne__c            = nObj.FSD_Is_OneToOne_F__c;
-                craesd.FSD_Name_CHN__c               = nObj.FSD_Name_CHN__c;
-                craesd.FSD_OneToOneAccessory_Cnt__c  = nObj.FSD_OneToOneAccessory_Cnt_F__c;
-                craesd.FSD_Fixture_Model_No__c       = nObj.FSD_Fixture_Model_No__c;
-                // 20211125 ljh add 鎺掗槦鎻掗槦 start
-                if(nObj.Is_Body__c){
-                    craesd.Allow_Adjust_Queue_Flag__c    = true;
-                    craesd.jumpReason__c = '鍙戣揣鍓嶆娴婲G閲嶆柊鍒嗛厤';
-                }
-                // 20211125 ljh add 鎺掗槦鎻掗槦 end
-                if (nObj.DataMigration_Flag__c == false && (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))) {
-                    craesd.Rental_Num__c  = nObj.Rental_Num__c;
-                    craesd.IndexFromUniqueKey__c = nObj.IndexFromUniqueKey__c;
-                }
-                //cancel閲嶆柊鍒嗛厤鐨勪笉绠楄拷鍔犻檮灞炲搧 272銉併偙銉冦儓
-                craesd.Create_State__c = 0;
-                raesdList.add(craesd);
-            }
-            // 濡傛灉鏄富浣� cancel鐨勮瘽First搴旇鏄嫹璐濆嚭鏉ョ殑涓讳綋
-            if ((oObj.Cancel_Select__c == false && nObj.Cancel_Select__c == true)
-                    && nObj.Is_First_RAESD_F__c == true && nObj.Set_Cancel_Select__c == false
-                    && nObj.DataMigration_Flag__c == false && (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))) {
-                Rental_Apply_Equipment_Set__c raes = new Rental_Apply_Equipment_Set__c(
-                        Id = nObj.Rental_Apply_Equipment_Set__c,
-                        First_RAESD__c = null);
-                raesMap.put(nObj.Rental_Apply_Equipment_Set__c, raes);
-            }
-        }
-        //娌′笅鏋剁殑瀛楁娓呯┖鍦╞efore閲岄潰鍋�
-        if (!raesdList.isEmpty()) {
-            insert raesdList;
-        }
-        if (!raesMap.isEmpty()) {
-            List<Rental_Apply_Equipment_Set_Detail__c> raess = [Select Id, Rental_Apply_Equipment_Set__c
-                From Rental_Apply_Equipment_Set_Detail__c
-                Where Rental_Apply_Equipment_Set__c = :raesMap.keySet()
-                  and Cancel_Select__c = False
-                order by Rental_Apply_Equipment_Set__c, Fixture_Set_Detail__r.SortInt__c ASC nulls last];
-            System.debug(raess);
-            Id raesId = null;
-            // 涓�浠剁洰銈扚irst_RAESD__c銇ō瀹�
-            for (Rental_Apply_Equipment_Set_Detail__c raes : raess) {
-                if (raesId != raes.Rental_Apply_Equipment_Set__c) {
-                    raesMap.get(raes.Rental_Apply_Equipment_Set__c).First_RAESD__c = raes.Id;
-                    raesId = raes.Rental_Apply_Equipment_Set__c;
-                }
+    // 澶囧搧鎬ц兘浼樺寲鏀逛慨 20230312 by lc Start
+    String userid = UserInfo.getUserId();
+    // 澶囧搧鎬ц兘浼樺寲鏀逛慨 20230312 by lc End
 
-            }
+    for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
+      //鍥犱负鏄疘nsert鏃跺�欒鍊�  鎯呭喌1锛岀敵璇锋柊寤轰細璁惧��  鎯呭喌2锛孨G鎷疯礉鍑烘潵鐨勬椂鍊欎細璁惧��
+      //鍥犱负UniqueKey__c鍒ゆ柇浜咲ataMigration_Flag__c鎵�浠ヨ繖閲屼篃闇�瑕佸垽鏂�  妫�绱㈢殑鏃跺�欏洜涓鸿鍋嘔nsert鎵�浠ヤ笉闇�瑕佽缃�
+      // TODO bp3 DetailHandler閲�, 瀵笷SD璁惧�肩殑鍦版柟 闇�瑕佸湪Rental_Apply__c鐨凥andler閲�, 鍙樻垚鎵瑰噯鏅�, 涔熻璁惧�笺��
+      if (Trigger.isInsert && nObj.DataMigration_Flag__c == false) {
+        nObj.Is_Body__c = nObj.Is_Body_F__c;
+        if (String.isNotBlank(nObj.Fixture_Set_Detail__c)) {
+          nObj.FSD_Id__c = nObj.Fixture_Set_Detail__c;
         }
-        //涓�瑙團irst鏇存柊
-        if (!raesMap.isEmpty()) {
-            update raesMap.values();
+        // 272銉併偙銉冦儓
+        // Create_State__c涓虹┖骞朵笖鐢宠涔︾殑鏍囧噯鎵瑰噯鏃堕棿涓嶄负绌虹殑鏃跺�欒缃负1
+        // 1 --- 杩藉姞闄勫睘鍝�
+        // 0 --- Cancel鎷疯礉
+        // null --- 鏅�氭柊瑙�
+        if (
+          nObj.Create_State__c == null &&
+          !FixtureUtil.isRepairRenewal &&
+          nObj.Rental_Apply_Request_approval_time_F__c != null &&
+          nObj.Substitute_Select_Again__c == false && // OLY_OCM-404 鍒嗛厤浠f浛鍝�
+          // 鍔炰簨澶勫垎閰嶆椂杩藉姞鐨勬槑缁嗕笉绠楄拷鍔犻檮灞炲搧
+          nObj.RA_RecordTypeId__c.substring(0, 15) !=
+          agencyRecordTypeId.substring(0, 15)
+        ) {
+          nObj.Create_State__c = 1;
         }
-    }
+        nObj.FSD_Is_Optional__c = nObj.FSD_Is_Optional_F__c;
+        // 鍔炰簨澶勫湪鍒嗛厤涓己鍒惰涓簍rue鏃讹紝涓嶄粠FSD鎷疯礉
+        if (
+          nObj.RA_RecordTypeId__c.substring(0, 15) !=
+          agencyRecordTypeId.substring(0, 15) || !nObj.FSD_Is_OneToOne__c
+        ) {
+          nObj.FSD_Is_OneToOne__c = nObj.FSD_Is_OneToOne_F__c;
+        }
+        nObj.FSD_Name_CHN__c = nObj.Fixture_Name_F__c;
+        nObj.FSD_OneToOneAccessory_Cnt__c = nObj.FSD_OneToOneAccessory_Cnt_F__c;
+        nObj.FSD_Fixture_Model_No__c = nObj.Fixture_Model_No_F__c;
+        if (
+          nObj.DataMigration_Flag__c == false &&
+          (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))
+        ) {
+          nObj.Fixture_Model_No_text__c = nObj.Fixture_Model_No_F__c;
+        }
+        nObj.CreatedBy_ProfileId__c = UserInfo.getProfileId();
+        //              nObj.ApplyPersonAppended__c = nObj.ApplyPersonAppended_F__c;
+      }
+      if (
+        nObj.DeliverySlip__c != null &&
+        nObj.DataMigration_Flag__c == false &&
+        (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))
+      ) {
+        if (nObj.Shippment_loaner_time__c == null) {
+          nObj.Shippment_loaner_time__c = nObj.Shippment_loaner_time2__c;
+        }
+      }
+      nObj.DeliverySlip_Text__c = nObj.DeliverySlip__c;
+      nObj.Return_DeliverySlip_Text__c = nObj.Return_DeliverySlip__c;
+      nObj.Received_Confirm_Text__c = nObj.Received_Confirm_F__c;
+      //澶囧搧鍙戣揣鎶ラ敊瀵瑰簲 20230413 by lc Start
+      nObj.Detail_Not_Finish_Text__c = !nObj.Detail_Finish__c;
+      //澶囧搧鍙戣揣鎶ラ敊瀵瑰簲 20230413 by lc End
+      Rental_Apply_Equipment_Set_Detail__c oObj = null;
+      if (Trigger.isUpdate) {
+        oObj = oldMap.get(nObj.Id);
+        //鍑哄簱鍓嶆鏌G銇牬鍚堛偔銉c兂銈汇儷銇椼伨銇�
+        if (
+          oObj.Inspection_result__c != 'NG' &&
+          nObj.Inspection_result__c == 'NG'
+        ) {
+          nObj.Cancel_Select__c = true;
+          nObj.Loaner_cancel_reason__c = '鍏朵粬'; // 20210830 ljh SFDC-C448KZ add
+          nObj.Cancel_Reason__c = '閲嶆柊鍒嗛厤';
+          nObj.Loaner_cancel_Remarks__c = '鍑哄簱鍓嶆鏌G';
+        }
+        // OLY_OCM-435瀵惧繙 start
+        // 澶囧搧鎬ц兘浼樺寲鏀逛慨 20230312 by lc Start
+        //String userid = UserInfo.getUserId();
+        // 澶囧搧鎬ц兘浼樺寲鏀逛慨 20230312 by lc End
+        DateTime now = System.now();
+        if (
+          oObj.Inspection_result__c != nObj.Inspection_result__c &&
+          String.isNotBlank(nObj.Inspection_result__c)
+        ) {
+          nObj.Pre_inspection_time__c = now;
+          //20210428 ljh 1719 update start
+          //nObj.Inspection_staff__c = userid;
+          nObj.Inspection_staff__c = nObj.RA_RecordTypeId__c ==
+            Schema.SObjectType.Rental_Apply__c.getRecordTypeInfosByDeveloperName()
+              .get('AgencyRequest')
+              .getRecordTypeId()
+            ? null
+            : userid;
+          //20210428 ljh 1719 update start
+        }
 
-    // afterdelete銇伩
-    private void deleteReFirst() {
-        Map<Id, Rental_Apply_Equipment_Set__c> raesMap = new Map<Id, Rental_Apply_Equipment_Set__c>();
-        for (Rental_Apply_Equipment_Set_Detail__c oObj : oldList) {
-            if (oObj.Is_First_RAESD_F__c == true) {
-                    Rental_Apply_Equipment_Set__c raes = new Rental_Apply_Equipment_Set__c(
-                            Id = oObj.Rental_Apply_Equipment_Set__c,
-                            First_RAESD__c = null);
-                    raesMap.put(oObj.Rental_Apply_Equipment_Set__c, raes);
-                }
+        if (
+          oObj.Check_lost_Item_Final__c != nObj.Check_lost_Item_Final__c &&
+          String.isNotBlank(nObj.Check_lost_Item_Final__c)
+        ) {
+          nObj.Lost_item_check_time_Final__c = now;
+          nObj.Lost_item_check_staff_Final__c = userid;
         }
-        //淇敼涓�瑙堢殑FirstMap
-        if (raesMap.isEmpty()) {
-            return;
+
+        if (
+          oObj.Check_lost_Item__c != nObj.Check_lost_Item__c &&
+          String.isNotBlank(nObj.Check_lost_Item__c)
+        ) {
+          nObj.Lost_item_check_time__c = now;
+          nObj.Lost_item_check_staff__c = userid;
         }
-        if (!raesMap.isEmpty()) {
-            List<Rental_Apply_Equipment_Set_Detail__c> raess = [Select Id, Rental_Apply_Equipment_Set__c
-                From Rental_Apply_Equipment_Set_Detail__c
-                Where Rental_Apply_Equipment_Set__c = :raesMap.keySet()
-                  and Cancel_Select__c = False
-                  //涓�瑕с倐鍓婇櫎銇椼仧銈夋洿鏂般仐銇俱仜銈�
-                  and IsDeleted = false
-                // RAESD_SortInt_F__c -> IndexFromUniqueKey_Text__c(澶囧搧閰嶅鏄庣粏.SortInt__c)
-                // 1搴旇鏄富浣�
-                order by Rental_Apply_Equipment_Set__c, IndexFromUniqueKey_Text__c ASC nulls last];
-            Id raesId = null;
-            // 涓�浠剁洰銈扚irst_RAESD__c銇ō瀹�
-            for (Rental_Apply_Equipment_Set_Detail__c raes : raess) {
-                if (raesId != raes.Rental_Apply_Equipment_Set__c) {
-                    raesMap.get(raes.Rental_Apply_Equipment_Set__c).First_RAESD__c = raes.Id;
-                    raesId = raes.Rental_Apply_Equipment_Set__c;
-                }
-            }
+
+        if (
+          oObj.CDS_complete__c != nObj.CDS_complete__c && nObj.CDS_complete__c
+        ) {
+          nObj.CDS_complete_time__c = now;
+          nObj.CDS_staff__c = userid;
         }
-        //涓�瑙團irst鏇存柊
-        if (!raesMap.isEmpty()) {
-            update raesMap.values();
+
+        if (
+          oObj.Inspection_result_after_Final__c !=
+          nObj.Inspection_result_after_Final__c &&
+          String.isNotBlank(nObj.Inspection_result_after_Final__c)
+        ) {
+          nObj.After_Inspection_time_Final__c = now;
+          nObj.Inspection_staff_After_Final__c = userid;
         }
-    }
-    // 鏈�绲傜姸鎱嬪強銇矨sset澶夋洿
-    private Boolean finishOrChangeAsset(Boolean isDelete, Rental_Apply_Equipment_Set_Detail__c oObj, Rental_Apply_Equipment_Set_Detail__c nObj) {
-        Boolean rtn = false;
-        if (isDelete) {
-            // oObj 銈掔⒑瑾嶃仚銈嬨�乷ld銇� 銈傘仺銈傘仺 finish銇倐銇�乫alse銈掕繑銇欍��
-            rtn = !(
-                //鍥炲簱纭
-                   (oObj.Arrival_in_wh__c)
-                //鍙栨秷鍒嗛厤, (涓嬫灦鍚�, 鍘熷垯闇�瑕佷笂鏋�, 鎵�浠ヤ笉鑳藉崟绾殑鏂紑)
-                || (oObj.Cancel_Select__c == true && oObj.StockDown__c == false)
-                //涓嬫灦鍓�, 鍒嗛厤澶囧搧鏈夊彉鍖� (鍙樻垚鍒殑閰嶅, or 鍙� null)
-                || (oObj.Asset__c == null && oObj.StockDown__c == false)
-                //鍙栨秷鍒嗛厤, (涓嬫灦鍚�, 鍘熷垯闇�瑕佷笂鏋�, 鎵�浠ヤ笉鑳藉崟绾殑鏂紑)
-                || (oObj.Cancel_Select__c == true && nObj.StockDown__c == false)
-                //鏀惧純娆犲搧
-                || (oObj.Lost_item_giveup__c == true)
-                //宸叉秷鑰�
-                || (oObj.Check_lost_Item_F__c == '娑堣��')
-            );
+
+        if (
+          oObj.Inspection_result_after__c != nObj.Inspection_result_after__c &&
+          String.isNotBlank(nObj.Inspection_result_after__c)
+        ) {
+          // 妫�娴嬬粨鏋滄洿鏂颁簡浣嗘椂闂存病鏈夋墜鍔ㄦ洿鏂帮紝鍒欐洿鏂版椂闂�
+          // 濡傛灉鎵嬪姩鏇存柊浜嗘椂闂达紝灏变笉鐢ㄥ啀鏇存柊
+          if (oObj.After_Inspection_time__c == nObj.After_Inspection_time__c) {
+            nObj.After_Inspection_time__c = now;
+          }
+          //20210716 ljh 1719 update start
+          //nObj.Inspection_staff_After__c = userid;
+          nObj.Inspection_staff_After__c = nObj.RA_RecordTypeId__c ==
+            Schema.SObjectType.Rental_Apply__c.getRecordTypeInfosByDeveloperName()
+              .get('AgencyRequest')
+              .getRecordTypeId()
+            ? null
+            : userid;
+          //20210716 ljh 1719 update start
+        }
+        // OLY_OCM-435瀵惧繙 end
+        if (nObj.Detail_Finish__c) {
+          nObj.RAESD_Status_Text__c = nObj.Id;
         } else {
-            rtn = (
-                //鍥炲簱纭
-                   (!oObj.Arrival_in_wh__c && nObj.Arrival_in_wh__c)
-                //鍙栨秷鍒嗛厤, (涓嬫灦鍚�, 鍘熷垯闇�瑕佷笂鏋�, 鎵�浠ヤ笉鑳藉崟绾殑鏂紑)
-                || (oObj.Cancel_Select__c == false && nObj.Cancel_Select__c == true
-                    && nObj.StockDown__c == false)
-                //涓嬫灦鍓�, 鍒嗛厤澶囧搧鏈夊彉鍖� (鍙樻垚鍒殑閰嶅, or 鍙� null)
-                || (oObj.Asset__c != null && oObj.Asset__c != nObj.Asset__c
-                    && nObj.StockDown__c == false)
-                //鍙栨秷鍒嗛厤, (涓嬫灦鍚�, 鍘熷垯闇�瑕佷笂鏋�, 鎵�浠ヤ笉鑳藉崟绾殑鏂紑)
-                || (oObj.Cancel_Select__c == false && nObj.Cancel_Select__c == true
-                    && nObj.StockDown__c == false)
-                //鏀惧純娆犲搧
-                || (oObj.Lost_item_giveup__c == false && nObj.Lost_item_giveup__c == true
-                    && oObj.Check_lost_Item_F__c != '娑堣��')
-                //宸叉秷鑰�
-                || (oObj.Check_lost_Item_F__c != '娑堣��' && nObj.Check_lost_Item_F__c == '娑堣��'
-                    && oObj.Lost_item_giveup__c == false)
+          nObj.RAESD_Status_Text__c = nObj.RAESD_Status__c;
+        }
+      }
+      Rental_Apply_Equipment_Set__c raes = raesdMap.get(
+        nObj.Rental_Apply_Equipment_Set__c
+      );
+      //鐢婚潰鏄剧ず鐢╟lone鍑烘潵鐨勬暟鎹笉闇�瑕佽缃甆ame
+      //IndexFromUniqueKey__c.format()浼氭姤閿� 瑕佸垽涓嶆槸Null
+      if (
+        nObj.DataMigration_Flag__c == false &&
+        raes != null &&
+        String.isNotBlank(raes.Fixture_Set__r.Name) &&
+        raes.IndexFromUniqueKey__c != null &&
+        nObj.IndexFromUniqueKey__c != null &&
+        (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))
+      ) {
+        String split_ApplyNum = nObj.RequestNoJoinStr2__c;
+        if (nObj.Rental_Apply_r_Name__c.contains('_')) {
+          // XXXX-YYYY_1 (ZZZZ_1)
+          List<String> split_ApplyNumList = nObj.Rental_Apply_r_Name__c.split(
+            '_'
+          );
+          String raName = split_ApplyNumList[split_ApplyNumList.size() - 2]; // XXXX-YYYY (ZZZZ)
+          split_ApplyNum = split_ApplyNumList[split_ApplyNumList.size() - 1]; // 1
+          split_ApplyNumList = raName.split('-'); // [XXXX, YYYY]  ([ZZZZ])
+          if (split_ApplyNumList.size() > 1) {
+            // YYYY_1
+            split_ApplyNum =
+              split_ApplyNumList[split_ApplyNumList.size() - 1] +
+              '_' +
+              split_ApplyNum;
+          } else {
+            // ZZZZ_1
+            split_ApplyNum = nObj.Rental_Apply_r_Name__c;
+          }
+        }
+        nObj.Name =
+          split_ApplyNum +
+          ':' +
+          raes.Fixture_Set__r.Name +
+          ':' +
+          raes.IndexFromUniqueKey__c.format().leftpad(3, '0');
+
+        // 濡傛灉鏄垎閰嶄唬鏇垮搧鍚嶅瓧鍔�:Sub
+        if (nObj.Substitute_Select_Again__c) {
+          nObj.Name += ':Sub';
+        }
+
+        //涓�瑙堟椂鐢宠鑰呮敹璐G鐨勮瘽鍚嶅瓧娣诲姞NG
+        if (nObj.Received_Confirm_F__c == 'NG') {
+          nObj.Name += ':NG';
+        }
+        nObj.Name +=
+          ':' +
+          nObj.IndexFromUniqueKey_Text__c +
+          ':' +
+          nObj.IndexFromUniqueKey__c.format().leftpad(3, '0');
+        //鍙栨秷鐨勬椂鍊欏悕瀛楀姞Canceled
+        if (nObj.Cancel_Select__c) {
+          nObj.Name += ':Canceled';
+        }
+      }
+      nObj.Loaner_accsessary__c = nObj.Loaner_accsessary_F__c;
+      nObj.Loaner_centre_mail_address__c = nObj.Loaner_centre_mail_address_F__c;
+      // 20220117 ljh add start
+      // 鏇存柊鎺掗槦棰勮 鍏紡鎷锋枃鏈�
+      if (
+        Trigger.isUpdate &&
+        String.isBlank(nObj.Asset__c) == false &&
+        oObj.Asset__c != nObj.Asset__c
+      ) {
+        nObj.UQueueShippmentDateText__c = nObj.UQueueShippmentDate__c;
+      }
+      // 20220117 ljh add end
+      // 鍒嗛厤鏃�, 璁惧��
+      if (
+        String.isBlank(nObj.Asset__c) == false &&
+        nObj.Select_Time__c != null &&
+        (Trigger.isInsert ||
+        (oObj.Asset__c != nObj.Asset__c ||
+        oObj.Select_Time__c != nObj.Select_Time__c))
+      ) {
+        // 涓�瀵逛竴淇濈涓讳綋锛堝�熷嚭鏃讹級
+        // nObj.Main_OneToOne_FlagInt__c = nObj.Main_OneToOne_FlagInt__c;
+        if (
+          nObj.DataMigration_Flag__c == false &&
+          (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))
+        ) {
+          // 澶囧搧閰嶅鏄庣粏鍨嬪彿(鍊熷嚭鏃�)
+          if (String.isBlank(nObj.Fixture_Model_No_F__c)) {
+            nObj.addError(
+              '鍒嗛厤鐨凙sset:' + nObj.Asset__c + ', 娌℃湁璁惧畾 澶囧搧閰嶅鏄庣粏鍨嬪彿'
             );
+          } else {
+            nObj.Fixture_Model_No_text__c = nObj.Fixture_Model_No_F__c;
+          }
         }
-        return rtn;
-    }
-    //before 鏁板紡銇�ゃ亴null銇仾銈嬪彲鑳芥�с亴銇傘倞銇俱仚銇仹銇撱亾銇с倐涓�鍥炪儊銈с儍銈仐銇俱仚
-    private void formulaToTextCheck() {
-        List<Rental_Apply_Equipment_Set_Detail__c> raesds = new List<Rental_Apply_Equipment_Set_Detail__c>();
-        for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
-            //鏄庣粏鐘舵�佹病鏈変慨鐞嗗畬姣曟墍浠ヤ慨鐞嗗畬姣曠殑鏃跺�欎笉鎷疯礉鐘舵�佸埌Text瀛楁
-            if ((nObj.Repair_Status_Text__c != nObj.Repair_Status_F__c
-                        && nObj.Repair_Status_F__c != '淇悊瀹屾瘯')
-                    || nObj.Return_Status_Text__c != nObj.Return_Status_F__c
-                    || nObj.Shipment_Status_Text__c != nObj.Shipment_Status_F__c
-                    || (nObj.ApplyPersonAppended__c != nObj.ApplyPersonAppended_F__c && Trigger.isInsert)
-                    ) {
-                Rental_Apply_Equipment_Set_Detail__c raesd = new Rental_Apply_Equipment_Set_Detail__c(Id = nObj.Id);
-                //鏄庣粏鐘舵�佹病鏈変慨鐞嗗畬姣曟墍浠ヤ慨鐞嗗畬姣曠殑鏃跺�欎笉鎷疯礉鐘舵�佸埌Text瀛楁
-                if (nObj.Repair_Status_F__c != '淇悊瀹屾瘯') {
-                    raesd.Repair_Status_Text__c = nObj.Repair_Status_F__c;
-                }
-                raesd.Return_Status_Text__c = nObj.Return_Status_F__c;
-                raesd.Shipment_Status_Text__c = nObj.Shipment_Status_F__c;
-                if (Trigger.isInsert) {
-                    raesd.ApplyPersonAppended__c = nObj.ApplyPersonAppended_F__c;
-                }
-                raesds.add(raesd);
+        // 鏈鸿韩缂栧彿锛堝�熷嚭鏃讹級
+        nObj.SerialNumber_text__c = nObj.SerialNumber__c;
+        // 鎵�鍦ㄥ湴鍖�(鐪�) 鍊熷嚭鏃� #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
+        nObj.SalesProvince_before__c = nObj.SalesProvince__c;
+        // 鎵�鍦ㄥ湴鍖�(鏈儴) 鍊熷嚭鏃� #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
+        nObj.Salesdepartment_before__c = nObj.Salesdepartment__c;
+        // 浜у搧鍒嗙被(GI/SP)(鍊熷嚭鏃�) #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
+        nObj.Product_category_text__c = nObj.Product_category_F__c;
+        // 澶囧搧鍒嗙被(鍊熷嚭鏃�) #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
+        nObj.Equipment_Type_text__c = nObj.Equipment_Type_F__c;
+        // 澶囧搧鎴愭湰(鍊熷嚭鏃�)
+        nObj.Asset_cost_del_before__c = nObj.Asset_cost_del__c;
+        // 澶囧搧瀛樻斁鍦�(鍊熷嚭鏃�)
+        nObj.Internal_asset_location_before__c = nObj.Internal_asset_location__c;
+        //澶囧搧鍚嶇О(鍊熷嚭鏃�)
+        nObj.Fixture_Name_text__c = nObj.Fixture_Name_F__c;
+        // OLY_OCM-243 杩藉姞瀛楁瀵瑰簲 澶囧搧绠$悊缂栫爜(鍊熷嚭鏃�)
+        nObj.EquipmentSet_Managment_Code_text__c = nObj.EquipmentSet_Managment_Code__c;
+        // OLY_OCM-452 杩藉姞瀛楁瀵瑰簲 鍒�澶�(鍊熷嚭鏃�)
+        if (String.isNotBlank(nObj.Fixture_Set_Detail__c)) {
+          nObj.Is_Special_Product_Text__c = nObj.Is_Special_Product__c;
+        }
+      }
+      // 鎺掗槦鏃�, 瑕佹敞鎰� 璁惧�� 绉诲姩鍒版帓闃焍tn閲�
+      else if (
+        Trigger.isUpdate &&
+        String.isBlank(nObj.Asset__c) &&
+        oObj.Cancel_Select__c == false &&
+        // && oObj.Fixture_Model_No_text__c != nObj.Fixture_Model_No_text__c
+        (oObj.Queue_Number__c == 0 ||
+        oObj.Queue_Number__c == null) &&
+        nObj.Queue_Number__c > 0
+      ) {
+        // 鎺掗槦鏃堕噸鏂拌祴鍊糉ixture_Model_No_text__c 涓轰簡鎺掔殑涓嶆槸鏃odel_No
+        nObj.FSD_Fixture_Model_No__c = nObj.Fixture_Model_No_F__c;
+        // 澶囧搧閰嶅鏄庣粏鍨嬪彿(鍊熷嚭鏃�)
+        // nObj.Fixture_Model_No_text__c = nObj.Fixture_Model_No_F__c;
+        // 鎵�鍦ㄥ湴鍖�(鐪�) 鍊熷嚭鏃�
+        //nObj.SalesProvince_before__c = nObj.SalesProvince__c;
+        // // 鎵�鍦ㄥ湴鍖�(鏈儴) 鍊熷嚭鏃�
+        // nObj.Salesdepartment_before__c = nObj.Salesdepartment__c;
+        // // 浜у搧鍒嗙被(GI/SP)(鍊熷嚭鏃�)
+        // nObj.Product_category_text__c = nObj.Product_category_F__c;
+        // // 澶囧搧鍒嗙被(鍊熷嚭鏃�)
+        // nObj.Equipment_Type_text__c = nObj.Equipment_Type__c;
+        // // 澶囧搧瀛樻斁鍦�(鍊熷嚭鏃�)
+        // nObj.Internal_asset_location_before__c = nObj.Internal_asset_location__c;
+      }
+      // 鍏朵粬鏃跺��(鐢宠鏃�), null璁惧�� 鍜�
+      // 涓�瀵逛竴宸插垎閰嶇殑闄勫睘鍝�,涓讳綋閲嶆柊鎺掗槦鏃�,涓�瀵逛竴闄勫睘鍝侀渶瑕侀噸鏂版寜鐓х敵璇风殑閫昏緫閲嶆柊璧嬪��
+      else if (
+        (Trigger.isInsert && nObj.Cancel_Select__c == false) ||
+        (Trigger.isUpdate &&
+        String.isBlank(nObj.Asset__c) &&
+        oObj.Cancel_Select__c == false)
+      ) {
+        // 澶囧搧閰嶅鏄庣粏鍨嬪彿(鍊熷嚭鏃�)
+        if (
+          String.isBlank(nObj.Fixture_Model_No_text__c) &&
+          nObj.DataMigration_Flag__c == false &&
+          (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))
+        ) {
+          nObj.Fixture_Model_No_text__c = nObj.Fixture_Model_No_F__c;
+        }
+        // 鎵�鍦ㄥ湴鍖�(鐪�) 鍊熷嚭鏃� #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
+        if (String.isBlank(nObj.SalesProvince_before__c)) {
+          nObj.SalesProvince_before__c = nObj.SalesProvince__c;
+        }
+        // 鎵�鍦ㄥ湴鍖�(鏈儴) 鍊熷嚭鏃� #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
+        if (String.isBlank(nObj.Salesdepartment_before__c)) {
+          nObj.Salesdepartment_before__c = nObj.Salesdepartment__c;
+        }
+        // 浜у搧鍒嗙被(GI/SP)(鍊熷嚭鏃�) #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
+        if (String.isBlank(nObj.Product_category_text__c)) {
+          nObj.Product_category_text__c = nObj.Product_category_F__c;
+        }
+        // 澶囧搧鍒嗙被(鍊熷嚭鏃�) #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
+        if (String.isBlank(nObj.Equipment_Type_text__c)) {
+          nObj.Equipment_Type_text__c = nObj.Equipment_Type__c;
+        }
+        // 澶囧搧瀛樻斁鍦�
+        if (String.isBlank(nObj.Internal_asset_location_before__c)) {
+          nObj.Internal_asset_location_before__c = nObj.Internal_asset_location__c;
+        }
+        // 澶囧搧鍚嶇О(鍊熷嚭鏃�)
+        if (String.isBlank(nObj.Fixture_Name_text__c)) {
+          nObj.Fixture_Name_text__c = nObj.Fixture_Name_F__c;
+        }
+        // OLY_OCM-243 杩藉姞瀛楁瀵瑰簲 澶囧搧绠$悊缂栫爜(鍊熷嚭鏃�)
+        if (String.isBlank(nObj.EquipmentSet_Managment_Code_text__c)) {
+          nObj.EquipmentSet_Managment_Code_text__c = nObj.EquipmentSet_Managment_Code__c;
+        }
+        // OLY_OCM-452 杩藉姞瀛楁瀵瑰簲 鍒�澶�(鍊熷嚭鏃�)
+        if (String.isBlank(nObj.Is_Special_Product_Text__c)) {
+          nObj.Is_Special_Product_Text__c = nObj.Is_Special_Product__c;
+        }
+      } else {
+        // 鍙栨秷鐨勬儏鍐靛湪涓嬮潰鏈夎鍊�
+      }
+      if (
+        nObj.DataMigration_Flag__c == false &&
+        nObj.Cancel_Select__c == false &&
+        (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))
+      ) {
+        if (String.isBlank(nObj.Fixture_Model_No_text__c)) {
+          nObj.addError(
+            nObj.Id +
+              ':澶囧搧閰嶅鏄庣粏鍨嬪彿涓嶈兘涓虹┖, 澶囧搧閰嶅鏄庣粏=' +
+              nObj.Fixture_Set_Detail__c
+          );
+        }
+
+        // #OLY_OCM-654 鏁伴噺绠$悊鐨勮瘽,鎵�鍦ㄥ湴鍖�(鏈儴)&浜у搧鍒嗙被&澶囧搧鍒嗙被鐨勫垽鏂笉闇�瑕� Start
+        if ('鏁伴噺绠$悊' == nObj.Manage_type_F__c) {
+          // || false == nObj.Loaner_accsessary__c TODO: 闇�纭
+          if (String.isBlank(nObj.Internal_asset_location_before__c)) {
+            nObj.addError('澶囧搧瀛樻斁鍦颁笉鑳戒负绌�');
+          }
+        } else {
+          // #OLY_OCM-654 鏁伴噺绠$悊鐨勮瘽,鎵�鍦ㄥ湴鍖�(鏈儴)&浜у搧鍒嗙被&澶囧搧鍒嗙被鐨勫垽鏂笉闇�瑕� end
+          if (String.isBlank(nObj.Salesdepartment_before__c)) {
+            nObj.addError('鎵�鍦ㄥ湴鍖�(鏈儴)涓嶈兘涓虹┖');
+          }
+          if (String.isBlank(nObj.Internal_asset_location_before__c)) {
+            nObj.addError('澶囧搧瀛樻斁鍦颁笉鑳戒负绌�');
+          }
+          if (
+            String.isBlank(nObj.Product_category_text__c) && nObj.Is_Body__c
+          ) {
+            nObj.addError('浜у搧鍒嗙被(GI/SP)涓嶈兘涓虹┖');
+          }
+          if (
+            String.isBlank(nObj.Equipment_Type_text__c) &&
+            nObj.Is_Body__c &&
+            nObj.Demo_purpose1__c != '鍏朵粬'
+          ) {
+            nObj.addError('澶囧搧鍒嗙被涓嶈兘涓虹┖');
+          }
+          // if (String.isBlank(nObj.SalesProvince_before__c) && nObj.Is_Body__c) {
+          //     nObj.addError('鎵�鍦ㄥ湴鍖�(鐪�)涓嶈兘涓虹┖');
+          // }
+        }
+      }
+      if (
+        nObj.DataMigration_Flag__c == false &&
+        String.isNotBlank(nObj.FSD_Id__c) &&
+        (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))
+      ) {
+        //鍑哄簱鎸囩ず鏇存柊鏄庣粏鐨刱ey
+        nObj.UniqueKey__c =
+          nObj.RequestNoJoinStr2__c +
+          ':' +
+          nObj.Rental_Apply_Equipment_Set__c +
+          ':' +
+          nObj.FSD_Id__c +
+          ':' +
+          nObj.IndexFromUniqueKey__c;
+        if (nObj.Cancel_Select__c) {
+          nObj.UniqueKey__c += nObj.Id;
+          // 涓嬫灦鍚庣殑鍙栨秷鍔�;
+          if (nObj.StockDown__c) {
+            nObj.UniqueKey__c += ';' + nObj.Id;
+          }
+          // nObj.Queue_Number__c = null;
+          if (
+            nObj.StockDown__c &&
+            nObj.Inspection_result__c != 'NG' &&
+            String.isBlank(nObj.DeliverySlip__c)
+          ) {
+            nObj.OnStock_By_Cancel__c = true;
+            //                      nObj.Inspection_result_after_Flag_Text__c = 'true';
+          }
+        }
+      }
+      System.debug(nObj.IndexFromUniqueKey__c + 'key is' + nObj.UniqueKey__c);
+      // 鍙栨秷鍒嗛厤
+      //Action 18 銇倛銇c仸銈儯銉炽偦銉伄鍫村悎
+      //鍊熷嚭澶囧搧Set涓�瑙堟槑缁�.淇濇湁璁惧(Link)
+      //鍊熷嚭澶囧搧Set涓�瑙堟槑缁�.鍒嗛厤鏃堕棿
+      //鍊熷嚭澶囧搧Set涓�瑙堟槑缁�.宸插仛鍑哄簱鎸囩ず
+      //鍊熷嚭澶囧搧Set涓�瑙堟槑缁�.鍑哄簱鎸囩ず鏃堕棿
+      if (Trigger.isInsert || oObj.Cancel_Select__c != nObj.Cancel_Select__c) {
+        if (nObj.Cancel_Select__c) {
+          nObj.Cancel_Date__c = System.today();
+          nObj.Cancel_Time__c = MainFixtureSelectController.getCurrentTime();
+          nObj.Cancel_Mem__c = UserInfo.getUserId();
+          if (nObj.AgencyTempCancel__c) {
+            if (nObj.AgencyTempCancelTime__c != null) {
+              Datetime dt = nObj.AgencyTempCancelTime__c;
+              nObj.Cancel_Time__c = Time.newInstance(
+                dt.hour(),
+                dt.minute(),
+                dt.second(),
+                dt.millisecond()
+              );
+              nObj.Cancel_Date__c = Date.newinstance(
+                dt.year(),
+                dt.month(),
+                dt.day()
+              );
             }
+          }
+          nObj.AgencyTempCancel__c = false; // 鐪熷彇娑堟椂鎶婁复鏃跺彇娑堟爣璁版竻鎺�
+          nObj.AgencyTempCancelTime__c = null;
+          if (nObj.StockDown__c == false) {
+            nObj.Asset__c = null;
+            nObj.Select_Time__c = null;
+            nObj.Shipment_request_time2__c = null;
+            nObj.Shipment_request__c = false;
+            // 鏍规嵁OLY_OCM-243璁拌浇,鍙栨秷涔熼渶瑕佹竻闄ゆ帴鍊熷嚭鏃剁浉鍏崇殑瀛楁
+            if (
+              nObj.DataMigration_Flag__c == false &&
+              (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))
+            ) {
+              // 澶囧搧閰嶅鏄庣粏鍨嬪彿(鍊熷嚭鏃�)
+              nObj.Fixture_Model_No_text__c = nObj.FSD_Fixture_Model_No__c;
+            }
+            // 鏈鸿韩缂栧彿锛堝�熷嚭鏃讹級
+            nObj.SerialNumber_text__c = null;
+            // 鎵�鍦ㄥ湴鍖�(鐪�) 鍊熷嚭鏃� #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
+            nObj.SalesProvince_before__c = null;
+            // 鎵�鍦ㄥ湴鍖�(鏈儴) 鍊熷嚭鏃� #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
+            nObj.Salesdepartment_before__c = null;
+            // 浜у搧鍒嗙被(GI/SP)(鍊熷嚭鏃�) #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
+            nObj.Product_category_text__c = null;
+            // 澶囧搧鍒嗙被(鍊熷嚭鏃�) #OLY_OCM-654:鍥犱负鏄祴鍊兼墍浠ヤ笉淇敼
+            nObj.Equipment_Type_text__c = null;
+            // 澶囧搧鎴愭湰(鍊熷嚭鏃�)
+            nObj.Asset_cost_del_before__c = null;
+            // 澶囧搧瀛樻斁鍦�(鍊熷嚭鏃�)
+            nObj.Internal_asset_location_before__c = null;
+            //澶囧搧鍚嶇О(鍊熷嚭鏃�)
+            nObj.Fixture_Name_text__c = nObj.FSD_Name_CHN__c;
+            // 澶囧搧绠$悊缂栫爜(鍊熷嚭鏃�)
+            nObj.EquipmentSet_Managment_Code_text__c = null;
+          }
+          //20201118 ljh add
+          else {
+            String ra_RecordTypeId = DEVELOPERNAMEMAP.get('AgencyRequest')
+              .getRecordTypeId();
+            //System.debug('ra_RecordTypeId:'+ra_RecordTypeId);
+            if (
+              ra_RecordTypeId != null &&
+              nObj.RA_RecordTypeId__c.substring(0, 15) ==
+              ra_RecordTypeId.substring(0, 15)
+            ) {
+              //nObj.Inspection_result__c = 'OK';
+              nObj.Inspection_result_NG__c = null;
+              nObj.Arrival_in_wh__c = true;
+              nObj.Arrival_wh_time__c = System.now();
+              nObj.Return_wh_chenk_staff__c = Userinfo.getUserId();
+              nObj.Arrival_wh_Result_Agency__c = 'OK';
+            }
+          }
+          //20201118 ljh add
+        } else {
+          nObj.Cancel_Date__c = null;
+          nObj.Cancel_Time__c = null;
+          nObj.Cancel_Mem__c = null;
+          //nObj.Cancel_Reason__c = null;
         }
-        if (!raesds.isEmpty()) {
-            update raesds;
+      }
+      // 褰掕繕鍚嶤DS
+      if (Trigger.isInsert || oObj.CDS_complete__c != nObj.CDS_complete__c) {
+        if (nObj.CDS_complete__c) {
+          nObj.CDS_complete_time__c = System.now();
+          nObj.CDS_staff__c = UserInfo.getUserId();
+        } else {
+          nObj.CDS_complete_time__c = null;
+          nObj.CDS_staff__c = null;
         }
+      }
+      System.debug(nObj.Return_Status_F__c);
+      // 蹇呫仛鏈�寰屻仹缃亸
+      //鍔广亱銇亜銇牬鍚堛亴銇傘倞銇俱仚銇仹After銇с倓銈娿伨銇�
+      // nObj.Repair_Status_Text__c = nObj.Repair_Status_F__c;
+      // nObj.Return_Status_Text__c = nObj.Return_Status_F__c;
+      // nObj.Shipment_Status_Text__c = nObj.Shipment_Status_F__c;
+      nObj.Canceled_Id__c = nObj.Canceled__c;
+      if (
+        Trigger.isUpdate &&
+        ((oObj.Inspection_result_after_Final__c != 'NG' &&
+        nObj.Inspection_result_after_Final__c == 'NG' &&
+        nObj.Inspection_result_after_NG_Final__c == '缁翠慨') ||
+        (oObj.Inspection_result_after__c != 'NG' &&
+        nObj.Inspection_result_after__c == 'NG' &&
+        nObj.Inspection_result_after_NG__c == '缁翠慨'))
+      ) {
+        nObj.Repair__c = null;
+      }
+
+      // OLY_OCM-531 Start 鎼伐浣滄祦瑙勫垯
+      if (
+        nObj.Check_lost_Item_F__c == '娆犲搧' &&
+        nObj.Loaner_Giveup_Time__c == null &&
+        nObj.Lost_item_giveup__c == true
+      ) {
+        nObj.Loaner_Giveup_Time__c = Datetime.now();
+      }
+
+      if (nObj.RAESD_Status__c == '鎺掗槦涓�' && nObj.Queue_Day_Text__c == null) {
+        nObj.Queue_Day_Text__c = nObj.Queue_Day__c;
+        nObj.Queue_Time_Text__c = nObj.Queue_Time__c;
+      }
+
+      // OLY_OCM-531 End
+      if (
+        Trigger.isUpdate &&
+        oObj.Confirm_Lost_Date__c != null &&
+        oObj.Check_lost_Item_F__c != nObj.Check_lost_Item_F__c &&
+        oObj.Check_lost_Item_F__c == '娆犲搧'
+      ) {
+        nObj.Confirm_Lost_Date__c = null;
+      }
+
+      if (
+        Trigger.isUpdate &&
+        oObj.Shipment_request_time2__c != nObj.Shipment_request_time2__c &&
+        nObj.Shipment_request_time2__c != null &&
+        nObj.Is_Body__c &&
+        shipment_requestedRaIdStaticSet.contains(nObj.Rental_Apply__c) == false
+      ) {
+        shipment_requestedRaIdStaticSet.add(nObj.Rental_Apply__c);
+        shipment_requestedRaIdSet.add(nObj.Rental_Apply__c);
+      }
     }
-    // 20211116 ljh 涓嬩竴娆″�熺敤棰勮鍑哄簱鏃堕棿  鐨勮祴鍊� 鍥炴敹鍚�-妫�娴嬬粨鏋淥K閫昏緫 start
-    /*
+  }
+  /*
+   * Asset 銇甉uantity鏇存柊
+   * changeAssetCount()鏂规硶銇ut_of_wh__c銆丷ental_Count__c 鍑�1
+   */
+  private void changeAsset() {
+    if (Trigger.isUpdate && Trigger.isAfter) {
+      if (assMap.isEmpty()) {
+        return;
+      }
+      for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
+        if (!assMap.containsKey(nObj.Asset__c)) {
+          continue;
+        }
+        Rental_Apply_Equipment_Set_Detail__c oObj = null;
+        if (Trigger.isUpdate) {
+          oObj = oldMap.get(nObj.Id);
+        }
+        Asset ass = assMap.get(nObj.Asset__c);
+        // Abandoned_Inventory__c  null -> 0
+        if (ass.Abandoned_Inventory__c == null) {
+          ass.Abandoned_Inventory__c = 0;
+        }
+        // Abandoned_RealThing__c  null -> 0
+        if (ass.Abandoned_RealThing__c == null) {
+          ass.Abandoned_RealThing__c = 0;
+        }
+        if (ass.CountForRepair__c == null) {
+          ass.CountForRepair__c = 0;
+        }
+
+        if (ass.Confirm_Lost_Count__c == null) {
+          ass.Confirm_Lost_Count__c = 0;
+        }
+        if (
+          String.isBlank(oObj.Check_lost_Item_F__c) &&
+          nObj.Check_lost_Item_F__c == 'OK'
+        ) {
+          //鏈叆鍔涖亱銈夋瑺鍝併伀澶夋洿鏅備綍銈傘仐銇俱仜銈�
+        } else if (
+          String.isBlank(oObj.Check_lost_Item_F__c) &&
+          nObj.Check_lost_Item_F__c == '娆犲搧' &&
+          nObj.Lost_item_giveup__c == false
+        ) {
+          //鏈叆鍔涖亱銈夋瑺鍝併伀澶夋洿鏅備綍銈傘仐銇俱仜銈�
+        } else if (
+          String.isBlank(oObj.Check_lost_Item_F__c) &&
+          nObj.Check_lost_Item_F__c == '娆犲搧' &&
+          nObj.Lost_item_giveup__c == true
+        ) {
+          //鏈叆鍔涖亱銈夋瑺鍝佹斁妫勩伀澶夋洿鏅� 鏀惧純娆犲搧鍥炴敹锛堜涪澶憋級銇仺銇� 寰呭簾寮冩暟(涓㈠け/鐩樹簭)鍔�1
+          ass.Abandoned_Inventory__c += 1;
+          if (oObj.Confirm_Lost_Date__c != null) {
+            ass.Confirm_Lost_Count__c -= 1;
+          }
+          assUpdMap.put(ass.Id, ass);
+        } else if (
+          String.isBlank(oObj.Check_lost_Item_F__c) &&
+          nObj.Check_lost_Item_F__c == '娑堣��'
+        ) {
+          //鏈叆鍔涖亱銈夋秷鑰椼伀澶夋洿鏅俀uantity銈�-1
+          ass.Quantity -= 1;
+          ass.ChangeQuantityReason__c = '娑堣��';
+          assUpdMap.put(ass.Id, ass);
+        } else if (
+          oObj.Check_lost_Item_F__c == 'OK' &&
+          String.isBlank(nObj.Check_lost_Item_F__c)
+        ) {
+          //OK銇嬨倝绌虹櫧銇鏇存檪浣曘倐銇椼伨銇涖倱
+        } else if (
+          oObj.Check_lost_Item_F__c == 'OK' &&
+          nObj.Check_lost_Item_F__c == '娆犲搧' &&
+          nObj.Lost_item_giveup__c == false
+        ) {
+          //OK銇嬨倝娆犲搧銇鏇存檪浣曘倐銇椼伨銇涖倱
+        } else if (
+          oObj.Check_lost_Item_F__c == 'OK' &&
+          nObj.Check_lost_Item_F__c == '娆犲搧' &&
+          nObj.Lost_item_giveup__c == true
+        ) {
+          //OK銇嬨倝娆犲搧鏀炬銇鏇存檪 鏀惧純娆犲搧鍥炴敹锛堜涪澶憋級銇仺銇� 寰呭簾寮冩暟(涓㈠け/鐩樹簭)鍔�1
+          ass.Abandoned_Inventory__c += 1;
+          if (oObj.Confirm_Lost_Date__c != null) {
+            ass.Confirm_Lost_Count__c -= 1;
+          }
+          assUpdMap.put(ass.Id, ass);
+        } else if (
+          oObj.Check_lost_Item_F__c == 'OK' &&
+          nObj.Check_lost_Item_F__c == '娑堣��'
+        ) {
+          //OK銇嬨倝娑堣�椼伀澶夋洿鏅俀uantity銈�-1
+          ass.Quantity -= 1;
+          ass.ChangeQuantityReason__c = '娑堣��';
+          assUpdMap.put(ass.Id, ass);
+        } else if (
+          oObj.Check_lost_Item_F__c == '娆犲搧' &&
+          String.isBlank(nObj.Check_lost_Item_F__c) &&
+          oObj.Lost_item_giveup__c == false
+        ) {
+          if (oObj.Confirm_Lost_Date__c != null) {
+            ass.Confirm_Lost_Count__c -= 1;
+          }
+          assUpdMap.put(ass.Id, ass);
+        } else if (
+          oObj.Check_lost_Item_F__c == '娆犲搧' &&
+          nObj.Check_lost_Item_F__c == 'OK' &&
+          oObj.Lost_item_giveup__c == false
+        ) {
+          if (oObj.Confirm_Lost_Date__c != null) {
+            ass.Confirm_Lost_Count__c -= 1;
+          }
+          assUpdMap.put(ass.Id, ass);
+        } else if (
+          oObj.Check_lost_Item_F__c == '娆犲搧' &&
+          nObj.Check_lost_Item_F__c == '娆犲搧' &&
+          oObj.Lost_item_giveup__c == false &&
+          nObj.Lost_item_giveup__c == true
+        ) {
+          //娆犲搧銇嬨倝娆犲搧鏀炬銇鏇存檪 鏀惧純娆犲搧鍥炴敹锛堜涪澶憋級銇仺銇� 寰呭簾寮冩暟(涓㈠け/鐩樹簭)鍔�1
+          ass.Abandoned_Inventory__c += 1;
+          if (oObj.Confirm_Lost_Date__c != null) {
+            ass.Confirm_Lost_Count__c -= 1;
+          }
+          assUpdMap.put(ass.Id, ass);
+        } else if (
+          oObj.Check_lost_Item_F__c == '娆犲搧' &&
+          nObj.Check_lost_Item_F__c == '娑堣��' &&
+          oObj.Lost_item_giveup__c == false
+        ) {
+          //娆犲搧銇嬨倝娑堣�椼伀澶夋洿鏅俀uantity銈�-1
+          ass.Quantity -= 1;
+          ass.ChangeQuantityReason__c = '娑堣��';
+          if (oObj.Confirm_Lost_Date__c != null) {
+            ass.Confirm_Lost_Count__c -= 1;
+          }
+          assUpdMap.put(ass.Id, ass);
+        } else if (
+          oObj.Check_lost_Item_F__c == '娆犲搧' &&
+          String.isBlank(nObj.Check_lost_Item_F__c) &&
+          oObj.Lost_item_giveup__c == true
+        ) {
+          //娆犲搧鏀炬銇嬨倝绌虹櫧銇鏇存檪 寰呭簾寮冩暟(涓㈠け/鐩樹簭)鍑�1
+          ass.Abandoned_Inventory__c -= 1;
+          ass.Out_of_wh__c += 1;
+          ass.Rental_Count__c += 1;
+          ass.ChangeQuantityReason__c = '娆犲搧' + '->' + '';
+          assUpdMap.put(ass.Id, ass);
+        } else if (
+          oObj.Check_lost_Item_F__c == '娆犲搧' &&
+          nObj.Check_lost_Item_F__c == 'OK' &&
+          oObj.Lost_item_giveup__c == true
+        ) {
+          //娆犲搧鏀炬銇嬨倝OK銇鏇存檪 寰呭簾寮冩暟(涓㈠け/鐩樹簭)鍑�1
+          ass.Abandoned_Inventory__c -= 1;
+          ass.Out_of_wh__c += 1;
+          ass.Rental_Count__c += 1;
+          ass.ChangeQuantityReason__c = '娆犲搧' + '->' + 'OK';
+          assUpdMap.put(ass.Id, ass);
+        } else if (
+          oObj.Check_lost_Item_F__c == '娆犲搧' &&
+          nObj.Check_lost_Item_F__c == '娆犲搧' &&
+          oObj.Lost_item_giveup__c == true &&
+          nObj.Lost_item_giveup__c == false
+        ) {
+          //娆犲搧鏀炬銇嬨倝娆犲搧銇鏇存檪 寰呭簾寮冩暟(涓㈠け/鐩樹簭)鍑�1
+          ass.Abandoned_Inventory__c -= 1;
+          ass.Out_of_wh__c += 1;
+          ass.Rental_Count__c += 1;
+          ass.ChangeQuantityReason__c = '娆犲搧鏀惧純 -> ' + '娆犲搧';
+          assUpdMap.put(ass.Id, ass);
+        } else if (
+          oObj.Check_lost_Item_F__c == '娆犲搧' &&
+          nObj.Check_lost_Item_F__c == '娑堣��' &&
+          oObj.Lost_item_giveup__c == true
+        ) {
+          //娆犲搧鏀炬銇嬨倝娑堣�椼伀澶夋洿鏅� 寰呭簾寮冩暟(涓㈠け/鐩樹簭)鍑�1 Quantity銈�-1
+          ass.Abandoned_Inventory__c -= 1;
+          ass.Quantity -= 1;
+        } else if (
+          oObj.Check_lost_Item_F__c == '娑堣��' &&
+          String.isBlank(nObj.Check_lost_Item_F__c)
+        ) {
+          //娑堣�椼亱銈夌┖鐧姐伀澶夋洿鏅俀uantity銈�+1
+          ass.Quantity += 1;
+          ass.Out_of_wh__c += 1;
+          ass.Rental_Count__c += 1;
+          ass.ChangeQuantityReason__c = '娑堣�� -> ' + '';
+          assUpdMap.put(ass.Id, ass);
+        } else if (
+          oObj.Check_lost_Item_F__c == '娑堣��' &&
+          nObj.Check_lost_Item_F__c == 'OK'
+        ) {
+          //娑堣�椼亱銈夌┖鐧姐伀澶夋洿鏅俀uantity銈�+1
+          ass.Quantity += 1;
+          ass.Out_of_wh__c += 1;
+          ass.Rental_Count__c += 1;
+          ass.ChangeQuantityReason__c = '娑堣�� -> ' + 'OK';
+          assUpdMap.put(ass.Id, ass);
+        } else if (
+          oObj.Check_lost_Item_F__c == '娑堣��' &&
+          nObj.Check_lost_Item_F__c == '娆犲搧' &&
+          nObj.Lost_item_giveup__c == false
+        ) {
+          //娑堣�椼亱銈夋瑺鍝併伀澶夋洿鏅俀uantity銈�+1
+          ass.Quantity += 1;
+          ass.Out_of_wh__c += 1;
+          ass.Rental_Count__c += 1;
+          ass.ChangeQuantityReason__c = '娑堣�� -> 娆犲搧';
+          assUpdMap.put(ass.Id, ass);
+        } else if (
+          oObj.Check_lost_Item_F__c == '娑堣��' &&
+          nObj.Check_lost_Item_F__c == '娆犲搧' &&
+          nObj.Lost_item_giveup__c == true
+        ) {
+          //娑堣�椼亱銈夋瑺鍝佹斁妫勩伀澶夋洿鏅� 寰呭簾寮冩暟(涓㈠け/鐩樹簭)+1 Quantity銈�+1
+          ass.Abandoned_Inventory__c += 1;
+          ass.Quantity += 1;
+        }
+        // 缁翠慨
+        if (
+          oObj.Arrival_in_wh__c == false &&
+          nObj.Arrival_in_wh__c == true &&
+          nObj.Arrival_wh_Result_Agency__c == '寰呬慨鐞�'
+        ) {
+          ass.CountForRepair__c += 1;
+          assUpdMap.put(ass.Id, ass);
+        }
+        //搴熷純
+        if (
+          oObj.Arrival_in_wh__c == false &&
+          nObj.Arrival_in_wh__c == true &&
+          (nObj.Inspection_result_after_NG_F__c == '搴熷純' ||
+          //鍑哄簱鍓嶆娴嬪簾寮冪殑鏃跺�欎篃闇�瑕佸垽鏂�
+          nObj.Inspection_result_NG__c == '搴熷純')
+        ) {
+          ass.Abandoned_RealThing__c += 1;
+          ass.ChangeQuantityReason__c = FixtureUtil.raesdStatusMap.get(
+            FixtureUtil.HistoryStatus.Dai_Fei_Qi.ordinal()
+          );
+          assUpdMap.put(ass.Id, ass);
+        } else if (
+          oObj.Arrival_in_wh__c == true &&
+          nObj.Arrival_in_wh__c == false &&
+          (oObj.Inspection_result_after_NG_F__c == '搴熷純' ||
+          //鍑哄簱鍓嶆娴嬪簾寮冪殑鏃跺�欎篃闇�瑕佸垽鏂�
+          oObj.Inspection_result_NG__c == '搴熷純')
+        ) {
+          ass.Abandoned_RealThing__c -= 1;
+          ass.Out_of_wh__c += 1;
+          ass.Rental_Count__c += 1;
+          // ass.Freeze_sign__c = true; // OLY_OCM-689 鍒犻櫎鍐荤粨瀛楁鐨勬洿鏂�
+          String rea = nObj.Inspection_result_after_NG_F__c == '搴熷純'
+            ? '寰呯Щ鑷虫姤搴熷尯'
+            : nObj.Inspection_result_after_NG_F__c;
+          ass.ChangeQuantityReason__c =
+            FixtureUtil.raesdStatusMap.get(
+              FixtureUtil.HistoryStatus.Dai_Fei_Qi.ordinal()
+            ) +
+            ' ->' +
+            rea;
+          assUpdMap.put(ass.Id, ass);
+        }
+        //寰呭簾寮�
+        if (
+          nObj.RAESD_Status__c ==
+          FixtureUtil.raesdStatusMap.get(
+            FixtureUtil.HistoryStatus.Dai_Fei_Qi.ordinal()
+          ) &&
+          oObj.RAESD_Status__c != nObj.RAESD_Status__c &&
+          ass.Manage_type__c == '涓綋绠$悊'
+        ) {
+          ass.Status = FixtureUtil.assetStatusMap.get(
+            FixtureUtil.AssetStatus.Dai_Fei_Qi.ordinal()
+          );
+          // ass.Freeze_sign__c = true;
+          assUpdMap.put(ass.Id, ass);
+        }
+        // 鍔炰簨澶勫洖搴撶粨鏋滀慨鏀�
+        if (
+          oObj.Arrival_in_wh__c &&
+          nObj.Arrival_in_wh__c &&
+          oObj.Arrival_wh_Result_Agency__c != nObj.Arrival_wh_Result_Agency__c
+        ) {
+          switch on oObj.Arrival_wh_Result_Agency__c {
+            when '绉昏嚦鎶ュ簾鍖�' {
+              ass.Abandoned_RealThing__c -= 1;
+            }
+            when '寰呬慨鐞�' {
+              ass.CountForRepair__c -= 1;
+            }
+          }
+          switch on nObj.Arrival_wh_Result_Agency__c {
+            when '绉昏嚦鎶ュ簾鍖�' {
+              ass.Abandoned_RealThing__c += 1;
+            }
+            when '寰呬慨鐞�' {
+              ass.CountForRepair__c += 1;
+            }
+          }
+          assUpdMap.put(ass.Id, ass);
+        }
+        // //宸叉秷鑰�
+        // else if (nObj.Check_lost_Item_Final__c == '娑堣��'
+        //         && oObj.Check_lost_Item_Final__c != nObj.Check_lost_Item_Final__c
+        //         && ass.Manage_type__c == '涓綋绠$悊') {
+        //     ass.Status = FixtureUtil.assetFixtureStatusMap.get(FixtureUtil.AssetFixtureStatus.Yi_Xiao_Hao.ordinal());
+        //     assUpdMap.put(ass.Id, ass);
+        // }
+        //涓㈠け
+        // else if (nObj.Lost_item_giveup__c == true
+        //         && oObj.Lost_item_giveup__c != nObj.Lost_item_giveup__c
+        //         && ass.Manage_type__c == '涓綋绠$悊') {
+        // ass.Status = FixtureUtil.assetFixtureStatusMap.get(FixtureUtil.AssetFixtureStatus.Diu_Shi.ordinal());
+        // assUpdMap.put(ass.Id, ass);
+        // }
+        // else if (ass.Manage_type__c == '鏁伴噺绠$悊' && assMap.containsKey(ass.Id)) {
+        //     if (ass.Quantity != null && ass.Quantity > 0) {
+        //         if (ass.Status != FixtureUtil.assetFixtureStatusMap.get(FixtureUtil.AssetFixtureStatus.Ke_Yi_Fen_Pei.ordinal())) {
+        //             ass.Status = FixtureUtil.assetFixtureStatusMap.get(FixtureUtil.AssetFixtureStatus.Ke_Yi_Fen_Pei.ordinal());
+        //             assUpdMap.put(ass.Id, ass);
+        //         }
+        //     }
+        //     else {
+        //         if (ass.Status != FixtureUtil.assetFixtureStatusMap.get(FixtureUtil.AssetFixtureStatus.Mei_You_Ku_Cun.ordinal())) {
+        //             ass.Status = FixtureUtil.assetFixtureStatusMap.get(FixtureUtil.AssetFixtureStatus.Mei_You_Ku_Cun.ordinal());
+        //             assUpdMap.put(ass.Id, ass);
+        //         }
+        //     }
+        // }
+      }
+    }
+  }
+  /*
+   * 鍥炲簱纭 OFF -> ON:
+   * 鍙栨秷鍒嗛厤 OFF -> ON:
+   * 鏀惧純娆犲搧 OFF -> ON
+   * 宸叉秷鑰�
+   *
+   *  娓呯┖Asset 鏈�鏂板鍝佺敵璇峰�熷嚭鏄庣粏 Last_Reserve_RAES_Detail__c
+   *  (nObj.Asset__c 澶夋洿銇椼仾銇勩仧銈併�乧hangeAssetLast()銇с偗銉偄銇с亶銇亜銇熴倎銆併亾銇撱仹銈儶銈�)
+   *
+   * 銈儵銈广伄 assUpdMap 銈掓洿鏂般仚銈嬨仩銇�
+   */
+  private void clearLastReserveRAESD() {
+    for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
+      Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
+      // 涓讳綋鍜岄檮灞炲搧
+      if (finishOrChangeAsset(Trigger.isDelete, oObj, nObj)) {
+        Asset ass = assMap.get(nObj.Asset__c);
+        if (assUpdMap.containsKey(nObj.Asset__c)) {
+          ass = assUpdMap.get(nObj.Asset__c);
+        }
+        // 杩欓噷 浼氬嚭鐜� assUpdMap 鏈� 浣嗘槸 assMap 娌℃湁鐨勬儏鍐�
+        if (
+          ass == null &&
+          //鍒嗛厤澶囧搧鏈夊彉鍖� (涓嬫灦鍓�)
+          (oObj.Asset__c != null &&
+          oObj.Asset__c != nObj.Asset__c &&
+          nObj.StockDown__c == false)
+        ) {
+          ass = new Asset(Id = oObj.Asset__c);
+        }
+        if (ass == null) {
+          continue;
+        }
+        // 鏆傛椂鏀惧湪杩欓噷
+        if (oObj.Manage_type_F__c == '涓綋绠$悊') {
+          ass.Last_Reserve_RAES_Detail__c = null;
+          assUpdMap.put(ass.Id, ass);
+        }
+      }
+    }
+  }
+  //nObj.Asset__c銇屻亗銈嬪牬鍚堛�佸鏇淬仐銇熷牬鍚�
+  private void changeAssetLast() {
+    for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
+      Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
+      Asset nass = assMap.get(nObj.Asset__c);
+      if (assUpdMap.containsKey(nObj.Asset__c)) {
+        nass = assUpdMap.get(nObj.Asset__c);
+      } else if (String.isNotBlank(nObj.Asset__c)) {
+        nass = new Asset(Id = nObj.Asset__c);
+      }
+      Asset oass = assMap.get(oObj.Asset__c);
+      if (assUpdMap.containsKey(oObj.Asset__c)) {
+        oass = assUpdMap.get(oObj.Asset__c);
+      } else if (String.isNotBlank(oObj.Asset__c)) {
+        oass = new Asset(Id = oObj.Asset__c);
+      }
+      //nObj.Asset__c銇屻亗銈嬪牬鍚堛�佸鏇淬仐銇熷牬鍚�
+      if (
+        nObj.Asset__c != null &&
+        oObj.Asset__c != nObj.Asset__c &&
+        (oObj.Manage_type_F__c == '涓綋绠$悊' ||
+        nObj.Manage_type_F__c == '涓綋绠$悊')
+      ) {
+        if (nObj.Manage_type_F__c == '涓綋绠$悊') {
+          nass.Last_Reserve_RAES_Detail__c = nObj.Id;
+          assUpdMap.put(nass.Id, nass);
+        }
+        if (oObj.Manage_type_F__c == '涓綋绠$悊') {
+          oass.Last_Reserve_RAES_Detail__c = null;
+          assUpdMap.put(oass.Id, oass);
+        }
+      }
+    }
+  }
+  // 鍙栨秷鍒嗛厤 鐨勬椂鍊�, 闇�瑕佸湪 beforeSetValue() 閲屾妸 Asset__c 娓呴櫎
+  //鏄庣窗绲備簡銇ˋsset澶夋洿銇檪Out_of_wh__c銈掓洿鏂�
+  //afterupdate銇伩瀹熻
+  private void changeAssetCount() {
+    for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
+      Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
+      Asset nass = assMap.get(nObj.Asset__c);
+      if (assUpdMap.containsKey(nObj.Asset__c)) {
+        nass = assUpdMap.get(nObj.Asset__c);
+      } else if (String.isNotBlank(nObj.Asset__c)) {
+        nass = new Asset(Id = nObj.Asset__c);
+      }
+      Asset oass = assMap.get(oObj.Asset__c);
+      if (assUpdMap.containsKey(oObj.Asset__c)) {
+        oass = assUpdMap.get(oObj.Asset__c);
+      } else if (String.isNotBlank(oObj.Asset__c)) {
+        oass = new Asset(Id = oObj.Asset__c);
+      }
+      //Map銇獳sset銈掓柊瑕弍ush鏅傚�ゃ倰瑷畾
+      if (
+        oass != null &&
+        (oass.Out_of_wh__c == null ||
+        oass.Rental_Count__c == null ||
+        oass.Confirm_Lost_Count__c == null)
+      ) {
+        oass.Out_of_wh__c = oObj.Out_of_wh__c;
+        oass.Rental_Count__c = oObj.Rental_Count__c;
+        oass.Confirm_Lost_Count__c = oObj.Confirm_Lost_Count__c;
+      }
+      if (
+        nass != null &&
+        (nass.Out_of_wh__c == null ||
+        nass.Rental_Count__c == null ||
+        nass.Confirm_Lost_Count__c == null)
+      ) {
+        nass.Out_of_wh__c = nObj.Out_of_wh__c;
+        nass.Rental_Count__c = nObj.Rental_Count__c;
+        nass.Confirm_Lost_Count__c = nObj.Confirm_Lost_Count__c;
+      }
+      // 鏈�绲傜姸鎱嬪強銇ˋsset澶夋洿銇牬鍚�
+      if (finishOrChangeAsset(Trigger.isDelete, oObj, nObj)) {
+        System.debug('oass is ' + oass);
+        if (oass != null) {
+          if (oass.Out_of_wh__c != null && oass.Out_of_wh__c > 0) {
+            oass.Out_of_wh__c = oass.Out_of_wh__c - 1;
+            // assUpdMap.put(oass.Id, oass);
+            System.debug(
+              'oass.Out_of_wh__c -1' + oass.Out_of_wh__c + ' Id = ' + nObj.Id
+            );
+          }
+          if (nObj.DeliverySlip__c != null) {
+            if (oass.Rental_Count__c != null && oass.Rental_Count__c > 0) {
+              oass.Rental_Count__c = oass.Rental_Count__c - 1;
+            }
+          }
+          assUpdMap.put(oass.Id, oass);
+        }
+      } else if (
+        oass != null &&
+        oObj.DeliverySlip__c != null &&
+        nObj.DeliverySlip__c == null
+      ) {
+        //鍙戣揣杩愯緭鍗� 鍒犻櫎鐨勬椂鍊欏凡鍊熷嚭鏁� -1 鍙戣揣Asset__c鍘熷垯涓嶄細鍙樻墍浠ュ氨鐩存帴鐢ㄤ笂闈㈢殑oass
+        // if (nObj.DeliverySlip__c != null) {
+        if (oass.Rental_Count__c != null && oass.Rental_Count__c > 0) {
+          oass.Rental_Count__c = oass.Rental_Count__c - 1;
+          assUpdMap.put(oass.Id, oass);
+        }
+        // }
+      }
+      if (
+        oObj.Confirm_Lost_Date__c == null &&
+        nObj.Confirm_Lost_Date__c != null
+      ) {
+        nass.Confirm_Lost_Count__c = nass.Confirm_Lost_Count__c + 1;
+        assUpdMap.put(nass.Id, nass);
+      } else if (
+        nObj.Confirm_Lost_Date__c == null &&
+        oObj.Confirm_Lost_Date__c != null &&
+        nass.Confirm_Lost_Count__c > 0
+      ) {
+        nass.Confirm_Lost_Count__c = nass.Confirm_Lost_Count__c - 1;
+        assUpdMap.put(nass.Id, nass);
+      }
+      //鍙戣揣杩愯緭鍗曡缃殑鏃跺�欏凡瑙i櫎鏁�+1
+      if (oObj.DeliverySlip__c == null && nObj.DeliverySlip__c != null) {
+        nass.Rental_Count__c = nass.Rental_Count__c + 1;
+        assUpdMap.put(nass.Id, nass);
+      }
+      //nObj.Asset__c銇屻亗銈嬪牬鍚堛�佸鏇淬仐銇熷牬鍚�
+      System.debug(LoggingLevel.INFO, '*** nObj.Asset__c: ' + nObj.Asset__c);
+      if (nObj.Asset__c != null && oObj.Asset__c != nObj.Asset__c) {
+        nass.Out_of_wh__c = nass.Out_of_wh__c + 1;
+        System.debug(
+          'nass.Out_of_wh__c +1' + nass.Out_of_wh__c + ' Id = ' + nObj.Id
+        );
+        assUpdMap.put(nass.Id, nass);
+      }
+    }
+  }
+  // 鍚屻仒block 銇� 鎺掗槦銉偝銉笺儔 Queue_Number__c 銈抮efresh
+  // private void refreshQueueNumberByBlock() {
+  //     for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
+  //         Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
+  //         // 鍚屻仒block 銇� 鎺掗槦澶夋洿銇屻亗銈嬪牬鍚�
+  //         if (oObj.Cancel_Select__c == false
+  //                 && String.isBlank(oObj.Fixture_Model_No_text__c) == false
+  //                 && String.isBlank(oObj.Salesdepartment_before__c) == false
+  //                 && String.isBlank(oObj.Product_category_text__c) == false
+  //                 && String.isBlank(oObj.Equipment_Type_text__c) == false
+  //                 && oObj.Queue_Number__c > 0
+  //                 // 澶夊寲銈掔⒑瑾�
+  //                 && (oObj.Cancel_Select__c != nObj.Cancel_Select__c
+  //                     || oObj.Fixture_Model_No_text__c != nObj.Fixture_Model_No_text__c
+  //                     || oObj.Salesdepartment_before__c != nObj.Salesdepartment_before__c
+  //                     || oObj.Product_category_text__c != nObj.Product_category_text__c
+  //                     || oObj.Equipment_Type_text__c != nObj.Equipment_Type_text__c
+  //                     || (nObj.Queue_Number__c == 0 || nObj.Queue_Number__c == null))
+  //         ) {
+  //             if (executeed_refreshQueueNumber.contains(nObj.Id) && executeed_refreshQueueNumber.contains(oObj.Id)) {
+  //                 continue;
+  //             }
+  //             else if (executeed_refreshQueueNumber.contains(nObj.Id) == false) {
+  //                 executeed_refreshQueueNumber.add(nObj.Id);
+  //             } else {   //  executeed_refreshQueueNumber.contains(oObj.Id) == false
+  //                 executeed_refreshQueueNumber.add(oObj.Id);
+  //             }
+  //             // TODO 鎯冲畾 鐢婚潰銇嬨倝銇�1 record 銇椼亱銇亜
+  //             List<Rental_Apply_Equipment_Set_Detail__c> updateList = new List<Rental_Apply_Equipment_Set_Detail__c>();
+  //             List<Rental_Apply_Equipment_Set_Detail__c> refreshTargetList = [
+  //                     Select Id, Queue_Number__c
+  //                       from Rental_Apply_Equipment_Set_Detail__c
+  //                      where Cancel_Select__c = false
+  //                        and Fixture_Model_No_text__c = :oObj.Fixture_Model_No_text__c
+  //                        and Salesdepartment_before__c = :oObj.Salesdepartment_before__c
+  //                        and Product_category_text__c = :oObj.Product_category_text__c
+  //                        and Equipment_Type_text__c = :oObj.Equipment_Type_text__c
+  //                        and Queue_Number__c > 0
+  //                      Order by Queue_Number__c];
+  //             for (Integer i = 0; i < refreshTargetList.size(); i++) {
+  //                 Rental_Apply_Equipment_Set_Detail__c refreshTarget = refreshTargetList[i];
+  //                 if (refreshTarget.Queue_Number__c != (i + 1)) {
+  //                     refreshTarget.Queue_Number__c = i + 1;
+  //                     executeed_refreshQueueNumber.add(refreshTarget.Id);
+  //                     updateList.add(refreshTarget);
+  //                 }
+  //             }
+  //             if (!updateList.isEmpty()) { update updateList; }
+  //         }
+  //     }
+  // }
+
+  // 4-XX 涓嬫灦鍚�, 鍑哄簱鍓嶆娴嬬殑Action涓�瀵逛竴鍒嗛厤鐨勮瘽, 鍜屼富浣撲竴璧� Cancel
+  private void oneToOne4XX() {
+    //涓讳綋CnacelSet
+    Set<Id> raesdBodyCnacelSet = new Set<Id>();
+    Set<Id> raesdBodyNGSet = new Set<Id>();
+    //鏆傛椂鍙�冭檻涓讳綋NG鎴栬�呭彇娑堢殑鏃跺��
+    Map<Id, String> raesdCancel_Remarks = new Map<Id, String>();
+    //妫�娴婲G鎴栬�呮湰鏉ュ氨Cancel鐨勪笉闇�瑕佸啀鏇存柊
+    Set<Id> raesdIdSet = new Set<Id>();
+    String ra_RecordTypeId = DEVELOPERNAMEMAP.get('AgencyRequest')
+      .getRecordTypeId();
+
+    for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
+      // 鍔炰簨澶勯檮灞炲搧涓嶉渶瑕侀殢涓讳綋鍙栨秷
+      if (
+        nObj.RA_RecordTypeId__c.substring(0, 15) ==
+        ra_RecordTypeId.substring(0, 15)
+      ) {
+        continue;
+      }
+      Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
+      //Set娌℃湁cancel鐨勮瘽閮介渶瑕佹嫹璐�
+      //涓讳綋鍑哄簱鍓嶆娴婲G 缁翠慨
+      if (
+        nObj.Is_Body__c == true &&
+        nObj.Inspection_result__c == 'NG' &&
+        oObj.Inspection_result__c != nObj.Inspection_result__c &&
+        nObj.Inspection_result_NG__c == '缁翠慨'
+      ) {
+        //闇�瑕侀噸鏂板垎閰嶄竴瀵逛竴闄勫睘鍝佺殑涓�瑙�
+        raesdBodyNGSet.add(nObj.Rental_Apply_Equipment_Set__c);
+        raesdCancel_Remarks.put(
+          nObj.Rental_Apply_Equipment_Set__c,
+          nObj.Loaner_cancel_Remarks__c
+        );
+        raesdIdSet.add(nObj.Id);
+      }
+      //涓讳綋鍑哄簱鍓嶆娴婲G 搴熷純
+      else if (
+        nObj.Is_Body__c == true &&
+        nObj.Inspection_result__c == 'NG' &&
+        oObj.Inspection_result__c != nObj.Inspection_result__c &&
+        nObj.Inspection_result_NG__c == '搴熷純'
+      ) {
+        //闇�瑕侀噸鏂板垎閰嶄竴瀵逛竴闄勫睘鍝佺殑涓�瑙�
+        raesdBodyNGSet.add(nObj.Rental_Apply_Equipment_Set__c);
+        raesdCancel_Remarks.put(
+          nObj.Rental_Apply_Equipment_Set__c,
+          nObj.Loaner_cancel_Remarks__c
+        );
+        raesdIdSet.add(nObj.Id);
+      }
+      //闄勫睘鍝佸嚭搴撳墠妫�娴婲G 缁翠慨 骞朵笖鏄竴瀵逛竴鍒嗛厤
+      else if (
+        nObj.Is_Body__c == false &&
+        nObj.Inspection_result__c == 'NG' &&
+        oObj.Inspection_result__c != nObj.Inspection_result__c &&
+        nObj.Inspection_result_NG__c == '缁翠慨' &&
+        nObj.OneToOne_Flag__c == true
+      ) {
+        raesdIdSet.add(nObj.Id);
+      }
+      //闄勫睘鍝佸嚭搴撳墠妫�娴婲G 搴熷純 骞朵笖鏄竴瀵逛竴鍒嗛厤
+      else if (
+        nObj.Is_Body__c == false &&
+        nObj.Inspection_result__c == 'NG' &&
+        oObj.Inspection_result__c != nObj.Inspection_result__c &&
+        nObj.Inspection_result_NG__c == '搴熷純' &&
+        nObj.OneToOne_Flag__c == true
+      ) {
+        raesdIdSet.add(nObj.Id);
+      }
+      //OLY_OCM-152 涓嬫灦鍚庝富浣撳彇娑堢殑璇濅竴瀵逛竴闄勫睘鍝佷篃瑕佷竴璧峰彇娑�
+      else if (
+        String.isBlank(nObj.DeliverySlip__c) &&
+        nObj.Is_Body__c == true &&
+        nObj.StockDown__c == true &&
+        oObj.Cancel_Select__c == false &&
+        nObj.Cancel_Select__c == true
+      ) {
+        raesdIdSet.add(nObj.Id);
+        raesdBodyCnacelSet.add(nObj.Rental_Apply_Equipment_Set__c);
+        raesdCancel_Remarks.put(
+          nObj.Rental_Apply_Equipment_Set__c,
+          nObj.Loaner_cancel_Remarks__c
+        );
+      }
+    }
+    if (raesdBodyNGSet.isEmpty() && raesdBodyCnacelSet.isEmpty()) {
+      return;
+    }
+    List<Rental_Apply_Equipment_Set_Detail__c> raesds = [
+      SELECT
+        Id,
+        UniqueKey__c,
+        Rental_Apply_Equipment_Set__c,
+        Rental_Apply__c,
+        Fixture_Set_Detail__c,
+        Cancel_Reason__c
+      FROM Rental_Apply_Equipment_Set_Detail__c
+      //涓讳綋鍑哄簱鍓嶆娴婲G涓�瑙堢殑鎵�鏈変竴瀵逛竴鍒嗛厤鐨勬槑缁�
+      WHERE
+        (Rental_Apply_Equipment_Set__c = :raesdBodyNGSet
+        //涓嬫灦鍚庝富浣撳彇娑堜竴瀵逛竴闄勫睘鍝佷篃瑕佷竴璧峰彇娑�
+        OR Rental_Apply_Equipment_Set__c = :raesdBodyCnacelSet)
+        AND OneToOne_Flag__c = TRUE
+        //鍜屼富浣撲竴璧锋娴婲G鐨勪笉鍐嶆洿鏂�
+        AND Id != :raesdIdSet
+    ];
+    List<Rental_Apply_Equipment_Set_Detail__c> raesdList = new List<Rental_Apply_Equipment_Set_Detail__c>();
+    for (Rental_Apply_Equipment_Set_Detail__c raesd : raesds) {
+      raesd.OnStock_By_Cancel__c = true;
+      raesd.Cancel_Select__c = true;
+      // OLY_OCM-163#comment-20120592 閫氳繃鍙栨秷鏃ュ垽鏂� -銆� 鏇存柊鐨勬椂鍊檅efore璁剧疆
+      //raesd.Cancel_Date__c = Date.today();
+      raesd.Cancel_Reason__c = '閲嶆柊鍒嗛厤';
+      raesd.Loaner_cancel_reason__c = '鍏朵粬'; // 20210830 ljh SFDC-C448KZ add
+      //涓讳綋鍑哄簱鍓嶆鏌G鐨勮瘽鍙栨秷澶囨敞鍥炶嚜鍔ㄨ缃负鍑哄簱鍓嶆鏌G
+      raesd.Loaner_cancel_Remarks__c = raesdCancel_Remarks.get(
+        raesd.Rental_Apply_Equipment_Set__c
+      );
+      // }
+      raesdList.add(raesd);
+    }
+    System.debug('raesdList size' + raesdList.size());
+    if (!raesdList.isEmpty()) {
+      update raesdList;
+    }
+  }
+
+  //涓�瑙堝崟浣嶅彇娑堝悗鐨勬嫹璐濆湪涓�瑙堢殑Handler閲岄潰鍋�
+  // 鍥犱负cancel鏄富浣撶殑璇滷irst搴斿紑濮嬫嫹璐濆嚭鏉ョ殑涓讳綋鎵�浠irst鐨勬洿鏂伴�昏緫绉诲姩鍒癱ancelcopy
+  private void cancelCopy() {
+    List<Rental_Apply_Equipment_Set_Detail__c> raesdList = new List<Rental_Apply_Equipment_Set_Detail__c>();
+    List<Rental_Apply_Equipment_Set_Detail__c> raesdListup = new List<Rental_Apply_Equipment_Set_Detail__c>();
+    Map<Id, Rental_Apply_Equipment_Set__c> raesMap = new Map<Id, Rental_Apply_Equipment_Set__c>();
+    String ra_RecordTypeId = DEVELOPERNAMEMAP.get('AgencyRequest')
+      .getRecordTypeId();
+    for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
+      Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
+      //Set娌℃湁cancel鐨勮瘽閮介渶瑕佹嫹璐�
+      //Cancel_Select__c 銇痜alse銇嬨倝true銇鏇淬仾銇仹銇伄銇rigger浜屽洖銇仐銇︺倐瀹熻銇欍倠銇伅锛戝洖銇犮亼
+      if (
+        nObj.Set_Cancel_Select__c == false &&
+        (oObj.Cancel_Select__c == false &&
+        nObj.Cancel_Select__c == true) &&
+        nObj.StockDown__c == true &&
+        nObj.Cancel_Reason__c == '閲嶆柊鍒嗛厤' &&
+        // 鍔炰簨澶勫彇娑堟椂涓嶈鎷疯礉鏄庣粏锛屽湪controller閲屾墜鍔ㄩ��
+        nObj.RA_RecordTypeId__c.substring(0, 15) !=
+        ra_RecordTypeId.substring(0, 15)
+      ) {
+        Rental_Apply_Equipment_Set_Detail__c craesd = new Rental_Apply_Equipment_Set_Detail__c();
+        craesd.Rental_Apply_Equipment_Set__c = nObj.Rental_Apply_Equipment_Set__c;
+        craesd.Rental_Apply__c = nObj.Rental_Apply__c;
+        craesd.Fixture_Set_Detail__c = nObj.Fixture_Set_Detail__c;
+        craesd.Fixture_Model_No_text__c = nObj.FSD_Fixture_Model_No__c;
+        craesd.Fixture_Name_text__c = nObj.FSD_Name_CHN__c;
+        craesd.IndexFromUniqueKey_Text__c = nObj.IndexFromUniqueKey_Text__c;
+        craesd.Canceled__c = nObj.Id;
+        craesd.FSD_Id__c = nObj.FSD_Id__c;
+        craesd.FSD_Is_Optional__c = nObj.FSD_Is_Optional_F__c;
+        craesd.FSD_Is_OneToOne__c = nObj.FSD_Is_OneToOne_F__c;
+        craesd.FSD_Name_CHN__c = nObj.FSD_Name_CHN__c;
+        craesd.FSD_OneToOneAccessory_Cnt__c = nObj.FSD_OneToOneAccessory_Cnt_F__c;
+        craesd.FSD_Fixture_Model_No__c = nObj.FSD_Fixture_Model_No__c;
+        // 20211125 ljh add 鎺掗槦鎻掗槦 start
+        if (nObj.Is_Body__c) {
+          craesd.Allow_Adjust_Queue_Flag__c = true;
+          craesd.jumpReason__c = '鍙戣揣鍓嶆娴婲G閲嶆柊鍒嗛厤';
+        }
+        // 20211125 ljh add 鎺掗槦鎻掗槦 end
+        if (
+          nObj.DataMigration_Flag__c == false &&
+          (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))
+        ) {
+          craesd.Rental_Num__c = nObj.Rental_Num__c;
+          craesd.IndexFromUniqueKey__c = nObj.IndexFromUniqueKey__c;
+        }
+        //cancel閲嶆柊鍒嗛厤鐨勪笉绠楄拷鍔犻檮灞炲搧 272銉併偙銉冦儓
+        craesd.Create_State__c = 0;
+        raesdList.add(craesd);
+      }
+      // 濡傛灉鏄富浣� cancel鐨勮瘽First搴旇鏄嫹璐濆嚭鏉ョ殑涓讳綋
+      if (
+        (oObj.Cancel_Select__c == false &&
+        nObj.Cancel_Select__c == true) &&
+        nObj.Is_First_RAESD_F__c == true &&
+        nObj.Set_Cancel_Select__c == false &&
+        nObj.DataMigration_Flag__c == false &&
+        (!Trigger.isUpdate || String.isNotBlank(nObj.Fixture_Set_Id__c))
+      ) {
+        Rental_Apply_Equipment_Set__c raes = new Rental_Apply_Equipment_Set__c(
+          Id = nObj.Rental_Apply_Equipment_Set__c,
+          First_RAESD__c = null
+        );
+        raesMap.put(nObj.Rental_Apply_Equipment_Set__c, raes);
+      }
+    }
+    //娌′笅鏋剁殑瀛楁娓呯┖鍦╞efore閲岄潰鍋�
+    if (!raesdList.isEmpty()) {
+      insert raesdList;
+    }
+    if (!raesMap.isEmpty()) {
+      List<Rental_Apply_Equipment_Set_Detail__c> raess = [
+        SELECT Id, Rental_Apply_Equipment_Set__c
+        FROM Rental_Apply_Equipment_Set_Detail__c
+        WHERE
+          Rental_Apply_Equipment_Set__c = :raesMap.keySet()
+          AND Cancel_Select__c = FALSE
+        ORDER BY
+          Rental_Apply_Equipment_Set__c,
+          Fixture_Set_Detail__r.SortInt__c ASC NULLS LAST
+      ];
+      System.debug(raess);
+      Id raesId = null;
+      // 涓�浠剁洰銈扚irst_RAESD__c銇ō瀹�
+      for (Rental_Apply_Equipment_Set_Detail__c raes : raess) {
+        if (raesId != raes.Rental_Apply_Equipment_Set__c) {
+          raesMap.get(raes.Rental_Apply_Equipment_Set__c)
+            .First_RAESD__c = raes.Id;
+          raesId = raes.Rental_Apply_Equipment_Set__c;
+        }
+      }
+    }
+    //涓�瑙團irst鏇存柊
+    if (!raesMap.isEmpty()) {
+      update raesMap.values();
+    }
+  }
+
+  // afterdelete銇伩
+  private void deleteReFirst() {
+    Map<Id, Rental_Apply_Equipment_Set__c> raesMap = new Map<Id, Rental_Apply_Equipment_Set__c>();
+    for (Rental_Apply_Equipment_Set_Detail__c oObj : oldList) {
+      if (oObj.Is_First_RAESD_F__c == true) {
+        Rental_Apply_Equipment_Set__c raes = new Rental_Apply_Equipment_Set__c(
+          Id = oObj.Rental_Apply_Equipment_Set__c,
+          First_RAESD__c = null
+        );
+        raesMap.put(oObj.Rental_Apply_Equipment_Set__c, raes);
+      }
+    }
+    //淇敼涓�瑙堢殑FirstMap
+    if (raesMap.isEmpty()) {
+      return;
+    }
+    if (!raesMap.isEmpty()) {
+      List<Rental_Apply_Equipment_Set_Detail__c> raess = [
+        SELECT Id, Rental_Apply_Equipment_Set__c
+        FROM Rental_Apply_Equipment_Set_Detail__c
+        WHERE
+          Rental_Apply_Equipment_Set__c = :raesMap.keySet()
+          AND Cancel_Select__c = FALSE
+          //涓�瑕с倐鍓婇櫎銇椼仧銈夋洿鏂般仐銇俱仜銈�
+          AND IsDeleted = FALSE
+        // RAESD_SortInt_F__c -> IndexFromUniqueKey_Text__c(澶囧搧閰嶅鏄庣粏.SortInt__c)
+        // 1搴旇鏄富浣�
+        ORDER BY
+          Rental_Apply_Equipment_Set__c,
+          IndexFromUniqueKey_Text__c ASC NULLS LAST
+      ];
+      Id raesId = null;
+      // 涓�浠剁洰銈扚irst_RAESD__c銇ō瀹�
+      for (Rental_Apply_Equipment_Set_Detail__c raes : raess) {
+        if (raesId != raes.Rental_Apply_Equipment_Set__c) {
+          raesMap.get(raes.Rental_Apply_Equipment_Set__c)
+            .First_RAESD__c = raes.Id;
+          raesId = raes.Rental_Apply_Equipment_Set__c;
+        }
+      }
+    }
+    //涓�瑙團irst鏇存柊
+    if (!raesMap.isEmpty()) {
+      update raesMap.values();
+    }
+  }
+  // 鏈�绲傜姸鎱嬪強銇矨sset澶夋洿
+  private Boolean finishOrChangeAsset(
+    Boolean isDelete,
+    Rental_Apply_Equipment_Set_Detail__c oObj,
+    Rental_Apply_Equipment_Set_Detail__c nObj
+  ) {
+    Boolean rtn = false;
+    if (isDelete) {
+      // oObj 銈掔⒑瑾嶃仚銈嬨�乷ld銇� 銈傘仺銈傘仺 finish銇倐銇�乫alse銈掕繑銇欍��
+      rtn = !//鍥炲簱纭
+      ((oObj.Arrival_in_wh__c) ||
+      //鍙栨秷鍒嗛厤, (涓嬫灦鍚�, 鍘熷垯闇�瑕佷笂鏋�, 鎵�浠ヤ笉鑳藉崟绾殑鏂紑)
+      (oObj.Cancel_Select__c == true &&
+      oObj.StockDown__c == false) ||
+      //涓嬫灦鍓�, 鍒嗛厤澶囧搧鏈夊彉鍖� (鍙樻垚鍒殑閰嶅, or 鍙� null)
+      (oObj.Asset__c == null &&
+      oObj.StockDown__c == false) ||
+      //鍙栨秷鍒嗛厤, (涓嬫灦鍚�, 鍘熷垯闇�瑕佷笂鏋�, 鎵�浠ヤ笉鑳藉崟绾殑鏂紑)
+      (oObj.Cancel_Select__c == true &&
+      nObj.StockDown__c == false) ||
+      //鏀惧純娆犲搧
+      (oObj.Lost_item_giveup__c == true) ||
+      //宸叉秷鑰�
+      (oObj.Check_lost_Item_F__c == '娑堣��'));
+    } else {
+      rtn =
+        //鍥炲簱纭
+        ((!oObj.Arrival_in_wh__c && nObj.Arrival_in_wh__c) ||
+        //鍙栨秷鍒嗛厤, (涓嬫灦鍚�, 鍘熷垯闇�瑕佷笂鏋�, 鎵�浠ヤ笉鑳藉崟绾殑鏂紑)
+        (oObj.Cancel_Select__c == false &&
+        nObj.Cancel_Select__c == true &&
+        nObj.StockDown__c == false) ||
+        //涓嬫灦鍓�, 鍒嗛厤澶囧搧鏈夊彉鍖� (鍙樻垚鍒殑閰嶅, or 鍙� null)
+        (oObj.Asset__c != null &&
+        oObj.Asset__c != nObj.Asset__c &&
+        nObj.StockDown__c == false) ||
+        //鍙栨秷鍒嗛厤, (涓嬫灦鍚�, 鍘熷垯闇�瑕佷笂鏋�, 鎵�浠ヤ笉鑳藉崟绾殑鏂紑)
+        (oObj.Cancel_Select__c == false &&
+        nObj.Cancel_Select__c == true &&
+        nObj.StockDown__c == false) ||
+        //鏀惧純娆犲搧
+        (oObj.Lost_item_giveup__c == false &&
+        nObj.Lost_item_giveup__c == true &&
+        oObj.Check_lost_Item_F__c != '娑堣��') ||
+        //宸叉秷鑰�
+        (oObj.Check_lost_Item_F__c != '娑堣��' &&
+        nObj.Check_lost_Item_F__c == '娑堣��' &&
+        oObj.Lost_item_giveup__c == false));
+    }
+    return rtn;
+  }
+  //before 鏁板紡銇�ゃ亴null銇仾銈嬪彲鑳芥�с亴銇傘倞銇俱仚銇仹銇撱亾銇с倐涓�鍥炪儊銈с儍銈仐銇俱仚
+  private void formulaToTextCheck() {
+    List<Rental_Apply_Equipment_Set_Detail__c> raesds = new List<Rental_Apply_Equipment_Set_Detail__c>();
+    for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
+      //鏄庣粏鐘舵�佹病鏈変慨鐞嗗畬姣曟墍浠ヤ慨鐞嗗畬姣曠殑鏃跺�欎笉鎷疯礉鐘舵�佸埌Text瀛楁
+      if (
+        (nObj.Repair_Status_Text__c != nObj.Repair_Status_F__c &&
+        nObj.Repair_Status_F__c != '淇悊瀹屾瘯') ||
+        nObj.Return_Status_Text__c != nObj.Return_Status_F__c ||
+        nObj.Shipment_Status_Text__c != nObj.Shipment_Status_F__c ||
+        (nObj.ApplyPersonAppended__c != nObj.ApplyPersonAppended_F__c &&
+        Trigger.isInsert)
+      ) {
+        Rental_Apply_Equipment_Set_Detail__c raesd = new Rental_Apply_Equipment_Set_Detail__c(
+          Id = nObj.Id
+        );
+        //鏄庣粏鐘舵�佹病鏈変慨鐞嗗畬姣曟墍浠ヤ慨鐞嗗畬姣曠殑鏃跺�欎笉鎷疯礉鐘舵�佸埌Text瀛楁
+        if (nObj.Repair_Status_F__c != '淇悊瀹屾瘯') {
+          raesd.Repair_Status_Text__c = nObj.Repair_Status_F__c;
+        }
+        raesd.Return_Status_Text__c = nObj.Return_Status_F__c;
+        raesd.Shipment_Status_Text__c = nObj.Shipment_Status_F__c;
+        if (Trigger.isInsert) {
+          raesd.ApplyPersonAppended__c = nObj.ApplyPersonAppended_F__c;
+        }
+        raesds.add(raesd);
+      }
+    }
+    if (!raesds.isEmpty()) {
+      // 澶囧搧浼樺寲杩藉姞 20230518 lc Start
+      if (skipUpdateAgain) {
+        Oly_TriggerHandler.bypass('RentalApplyEquipmentSetDetailHandler');
+        update raesds;
+        Oly_TriggerHandler.clearBypass('RentalApplyEquipmentSetDetailHandler');
+      } else {
+        update raesds;
+      }
+      // 澶囧搧浼樺寲杩藉姞 20230518 lc End
+    }
+  }
+  // 20211116 ljh 涓嬩竴娆″�熺敤棰勮鍑哄簱鏃堕棿  鐨勮祴鍊� 鍥炴敹鍚�-妫�娴嬬粨鏋淥K閫昏緫 start
+  /*
     鏍规嵁褰撳墠鐘舵�侊紝if 鍥炴敹鍚�-妫�娴嬬粨鏋� Inspection_result_after_F_New__c 鏈夊�� && new =OK old != OK {
         妫�娴婳K鏃堕棿+3涓伐浣滄棩(濂ユ灄宸存柉鏃ュ巻)
     }
     */
-    private void NextShippmentDate() {
-        Date minDate = Date.newInstance(4000, 12, 31);
-        Date maxDate = Date.newInstance(1700, 1, 1);
-        Map<Date, List<Rental_Apply_Equipment_Set_Detail__c>> dLMap = new Map<Date, List<Rental_Apply_Equipment_Set_Detail__c>>();
-        List<Rental_Apply_Equipment_Set_Detail__c> upRdList = new List<Rental_Apply_Equipment_Set_Detail__c>();
-        for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
-            if(nObj.RA_RecordTypeId__c != '01210000000NPGK'){
-                Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
-                if(nObj.Inspection_result_after_F_New__c != null && nObj.Inspection_result_after_F_New__c == 'OK' && oObj.Inspection_result_after_F_New__c != nObj.Inspection_result_after_F_New__c){
-                    // 妫�娴婳K鏃堕棿+3涓伐浣滄棩(濂ユ灄宸存柉鏃ュ巻)
-                    Date date1 = nObj.After_Inspection_time_F_New__c.date();
-                    if (minDate > date1) {
-                        minDate = date1;
-                    }
-                    if (maxDate < date1) {
-                        maxDate = date1;
-                    }
-                    if(!dLMap.containsKey(date1)){
-                        dLMap.put(date1,new List<Rental_Apply_Equipment_Set_Detail__c>());
-                    }
-                    dLMap.get(date1).add(nObj);
-                } 
-                // 妫�娴婲G鍜屾瑺鍝佺殑锛氫笉鏄剧ず鏃堕棿
-                if((
-                    // (
-                    nObj.RAESD_Status__c == '娆犲搧涓�' || nObj.RAESD_Status__c == '寰呬慨鐞�' || nObj.RAESD_Status__c == '寰呯Щ鑷虫姤搴熷尯')
-                    // || (nObj.Arrival_in_wh__c && oObj.Arrival_in_wh__c != nObj.Arrival_in_wh__c))
-                 && nObj.NextShippmentDate__c != null){
-                    Rental_Apply_Equipment_Set_Detail__c raesd = new Rental_Apply_Equipment_Set_Detail__c();
-                    raesd.Id = nObj.Id;
-                    raesd.NextShippmentDate__c = null;
-                    upRdList.add(raesd);
-                }  
-            }
+  private void NextShippmentDate() {
+    Date minDate = Date.newInstance(4000, 12, 31);
+    Date maxDate = Date.newInstance(1700, 1, 1);
+    Map<Date, List<Rental_Apply_Equipment_Set_Detail__c>> dLMap = new Map<Date, List<Rental_Apply_Equipment_Set_Detail__c>>();
+    List<Rental_Apply_Equipment_Set_Detail__c> upRdList = new List<Rental_Apply_Equipment_Set_Detail__c>();
+    for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
+      if (nObj.RA_RecordTypeId__c != '01210000000NPGK') {
+        Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
+        if (
+          nObj.Inspection_result_after_F_New__c != null &&
+          nObj.Inspection_result_after_F_New__c == 'OK' &&
+          oObj.Inspection_result_after_F_New__c !=
+          nObj.Inspection_result_after_F_New__c
+        ) {
+          // 妫�娴婳K鏃堕棿+3涓伐浣滄棩(濂ユ灄宸存柉鏃ュ巻)
+          Date date1 = nObj.After_Inspection_time_F_New__c.date();
+          if (minDate > date1) {
+            minDate = date1;
+          }
+          if (maxDate < date1) {
+            maxDate = date1;
+          }
+          if (!dLMap.containsKey(date1)) {
+            dLMap.put(date1, new List<Rental_Apply_Equipment_Set_Detail__c>());
+          }
+          dLMap.get(date1).add(nObj);
         }
-        if(dLMap.size() > 0){
-            List<OlympusCalendar__c> ocList = [SELECT Id
-                        , Date__c
-                     FROM OlympusCalendar__c
-                    WHERE Date__c >= :minDate
-                      AND Date__c <= :maxDate.addDays(30)
-                      AND IsWorkDay__c = 1
-                    ORDER BY Date__c ASC];
-            Map<Date, Date> dateadd3Map = new Map<Date, Date>();
-            Integer ocListSize = ocList.size();
-            if (ocListSize > 3) {
-                for (Integer i = 0; i < ocListSize - 3; i ++) {
-                    dateadd3Map.put(ocList[i].Date__c, ocList[i + 3].Date__c);
-                }
-                for(Date d:dLMap.keySet()){
-                    // 鍥犱负 妫�娴嬫槸宸ヤ綔鏃� 涓�鑸笉浼氬嚭鐜� else 鎯呭喌
-                    if (dateadd3Map.containsKey(d)) {
-                        for(Rental_Apply_Equipment_Set_Detail__c rd:dLMap.get(d)){
-                            Rental_Apply_Equipment_Set_Detail__c raesd = new Rental_Apply_Equipment_Set_Detail__c();
-                            raesd.Id = rd.id;
-                            raesd.NextShippmentDate__c = dateadd3Map.get(d);
-                            upRdList.add(raesd);
-                        }
-                    }
-                    // 寰堝皯鍙戠敓
-                    else{
-                        for (Integer i = 0; i < ocListSize - 3; i ++) {
-                            if(d < ocList[i].Date__c){
-                                for(Rental_Apply_Equipment_Set_Detail__c rd:dLMap.get(d)){
-                                    Rental_Apply_Equipment_Set_Detail__c raesd = new Rental_Apply_Equipment_Set_Detail__c();
-                                    raesd.Id = rd.id;
-                                    raesd.NextShippmentDate__c = ocList[i + 2].Date__c;
-                                    upRdList.add(raesd);
-                                }
-                                break;
-                            }
-                        }
-                    }
-                }
-                
-            }
+        // 妫�娴婲G鍜屾瑺鍝佺殑锛氫笉鏄剧ず鏃堕棿
+        if (
+          (// (
+          nObj.RAESD_Status__c == '娆犲搧涓�' ||
+          nObj.RAESD_Status__c == '寰呬慨鐞�' ||
+          nObj.RAESD_Status__c == '寰呯Щ鑷虫姤搴熷尯') &&
+          // || (nObj.Arrival_in_wh__c && oObj.Arrival_in_wh__c != nObj.Arrival_in_wh__c))
+          nObj.NextShippmentDate__c != null
+        ) {
+          Rental_Apply_Equipment_Set_Detail__c raesd = new Rental_Apply_Equipment_Set_Detail__c();
+          raesd.Id = nObj.Id;
+          raesd.NextShippmentDate__c = null;
+          upRdList.add(raesd);
         }
-        if(upRdList.size() > 0){
-            update upRdList;
-        }
+      }
     }
-    /*
+    if (dLMap.size() > 0) {
+      List<OlympusCalendar__c> ocList = [
+        SELECT Id, Date__c
+        FROM OlympusCalendar__c
+        WHERE
+          Date__c >= :minDate
+          AND Date__c <= :maxDate.addDays(30)
+          AND IsWorkDay__c = 1
+        ORDER BY Date__c ASC
+      ];
+      Map<Date, Date> dateadd3Map = new Map<Date, Date>();
+      Integer ocListSize = ocList.size();
+      if (ocListSize > 3) {
+        for (Integer i = 0; i < ocListSize - 3; i++) {
+          dateadd3Map.put(ocList[i].Date__c, ocList[i + 3].Date__c);
+        }
+        for (Date d : dLMap.keySet()) {
+          // 鍥犱负 妫�娴嬫槸宸ヤ綔鏃� 涓�鑸笉浼氬嚭鐜� else 鎯呭喌
+          if (dateadd3Map.containsKey(d)) {
+            for (Rental_Apply_Equipment_Set_Detail__c rd : dLMap.get(d)) {
+              Rental_Apply_Equipment_Set_Detail__c raesd = new Rental_Apply_Equipment_Set_Detail__c();
+              raesd.Id = rd.id;
+              raesd.NextShippmentDate__c = dateadd3Map.get(d);
+              upRdList.add(raesd);
+            }
+          }
+          // 寰堝皯鍙戠敓
+          else {
+            for (Integer i = 0; i < ocListSize - 3; i++) {
+              if (d < ocList[i].Date__c) {
+                for (Rental_Apply_Equipment_Set_Detail__c rd : dLMap.get(d)) {
+                  Rental_Apply_Equipment_Set_Detail__c raesd = new Rental_Apply_Equipment_Set_Detail__c();
+                  raesd.Id = rd.id;
+                  raesd.NextShippmentDate__c = ocList[i + 2].Date__c;
+                  upRdList.add(raesd);
+                }
+                break;
+              }
+            }
+          }
+        }
+      }
+    }
+    if (upRdList.size() > 0) {
+      update upRdList;
+    }
+  }
+  /*
     鏍规嵁褰撳墠鐘舵�侊紝if 鍥炴敹鍚�-妫�娴嬬粨鏋� DeliverySlip__c 鏈夊�� && new != old {
         鍑哄簱鏈�鏂伴瀹氬綊杩樻棩RAES_Final_reply_day__c+8涓伐浣滄棩(濂ユ灄宸存柉鏃ュ巻)
     }
     */
-    private void NextShippmentDate_out() {
-        Date minDate = Date.newInstance(4000, 12, 31);
-        Date maxDate = Date.newInstance(1700, 1, 1);
-        Map<Date, List<Rental_Apply_Equipment_Set_Detail__c>> dLMap = new Map<Date, List<Rental_Apply_Equipment_Set_Detail__c>>();
-        List<Rental_Apply_Equipment_Set_Detail__c> upRdList = new List<Rental_Apply_Equipment_Set_Detail__c>();
-        for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
-            if(nObj.RA_RecordTypeId__c != '01210000000NPGK'){
-                Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
-                if(nObj.DeliverySlip__c != null  && oObj.DeliverySlip__c != nObj.DeliverySlip__c){
-                    // 妫�娴婳K鏃堕棿+3涓伐浣滄棩(濂ユ灄宸存柉鏃ュ巻)
-                    Date date1 = nObj.RAES_Final_reply_day__c;
-                    if (minDate > date1) {
-                        minDate = date1;
-                    }
-                    if (maxDate < date1) {
-                        maxDate = date1;
-                    }
-                    if(!dLMap.containsKey(date1)){
-                        dLMap.put(date1,new List<Rental_Apply_Equipment_Set_Detail__c>());
-                    }
-                    dLMap.get(date1).add(nObj);
-                } 
-            }
+  private void NextShippmentDate_out() {
+    Date minDate = Date.newInstance(4000, 12, 31);
+    Date maxDate = Date.newInstance(1700, 1, 1);
+    Map<Date, List<Rental_Apply_Equipment_Set_Detail__c>> dLMap = new Map<Date, List<Rental_Apply_Equipment_Set_Detail__c>>();
+    List<Rental_Apply_Equipment_Set_Detail__c> upRdList = new List<Rental_Apply_Equipment_Set_Detail__c>();
+    for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
+      if (nObj.RA_RecordTypeId__c != '01210000000NPGK') {
+        Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
+        if (
+          nObj.DeliverySlip__c != null &&
+          oObj.DeliverySlip__c != nObj.DeliverySlip__c
+        ) {
+          // 妫�娴婳K鏃堕棿+3涓伐浣滄棩(濂ユ灄宸存柉鏃ュ巻)
+          Date date1 = nObj.RAES_Final_reply_day__c;
+          if (minDate > date1) {
+            minDate = date1;
+          }
+          if (maxDate < date1) {
+            maxDate = date1;
+          }
+          if (!dLMap.containsKey(date1)) {
+            dLMap.put(date1, new List<Rental_Apply_Equipment_Set_Detail__c>());
+          }
+          dLMap.get(date1).add(nObj);
         }
-        if(dLMap.size() > 0){
-            List<OlympusCalendar__c> ocList = [SELECT Id
-                        , Date__c
-                     FROM OlympusCalendar__c
-                    WHERE Date__c >= :minDate
-                      AND Date__c <= :maxDate.addDays(30)
-                      AND IsWorkDay__c = 1
-                    ORDER BY Date__c ASC];
-            Map<Date, Date> dateadd3Map = new Map<Date, Date>();
-            Integer ocListSize = ocList.size();
-            if (ocListSize > 8) {
-                for (Integer i = 0; i < ocListSize - 8; i ++) {
-                    dateadd3Map.put(ocList[i].Date__c, ocList[i + 8].Date__c);
-                }
-                for(Date d:dLMap.keySet()){
-                    if (dateadd3Map.containsKey(d)) {
-                        for(Rental_Apply_Equipment_Set_Detail__c rd:dLMap.get(d)){
-                            Rental_Apply_Equipment_Set_Detail__c raesd = new Rental_Apply_Equipment_Set_Detail__c();
-                            raesd.Id = rd.id;
-                            raesd.NextShippmentDate__c = dateadd3Map.get(d);
-                            upRdList.add(raesd);
-                        }
-                    }
-                    else{
-                        for (Integer i = 0; i < ocListSize - 8; i ++) {
-                            if(d < ocList[i].Date__c){
-                                for(Rental_Apply_Equipment_Set_Detail__c rd:dLMap.get(d)){
-                                    Rental_Apply_Equipment_Set_Detail__c raesd = new Rental_Apply_Equipment_Set_Detail__c();
-                                    raesd.Id = rd.id;
-                                    raesd.NextShippmentDate__c = ocList[i + 7].Date__c;
-                                    upRdList.add(raesd);
-                                }
-                                break;
-                            }
-                        }
-                    }
-                }
-                if(upRdList.size() > 0){
-                    update upRdList;
-                }
-            }
-        }
+      }
     }
-    // 20211116 ljh 涓嬩竴娆″�熺敤棰勮鍑哄簱鏃堕棿  鐨勮祴鍊� 鍥炴敹鍚�-妫�娴嬬粨鏋淥K閫昏緫 end
-    //added by denny
-    public void reQueueAndSequence(){
-        Map<Id, Rental_Apply_Equipment_Set_Detail__c> newdetailMap = (Map<Id, Rental_Apply_Equipment_Set_Detail__c>) Trigger.newMap;
-        List<Rental_Apply_Equipment_Set_Detail__c> updateList = new List<Rental_Apply_Equipment_Set_Detail__c>();
-        List<String> detailIds = new List<String>();
-        List<String> externalKeyList = new List<String>();
-        Map<String,Decimal> minNumberMap = new Map<String,Decimal>();
-        for(Rental_Apply_Equipment_Set_Detail__c olddetail : (List<Rental_Apply_Equipment_Set_Detail__c>)trigger.old){
-            Rental_Apply_Equipment_Set_Detail__c detail ;
-            if(Trigger.isUpdate){
-                detail = newdetailMap.get(olddetail.Id);
-            }
-            if((Trigger.isUpdate && (
-                (oldDetail.Queue_Number__c > 0  && detail.Queue_Number__c == 0)// 鏆傚畾鍒嗛厤
-                // 20220127 ljh update start
-                // || (!oldDetail.Cancel_Select__c && detail.Cancel_Select__c && olddetail.Queue_Number__c >= 0)  //鍙栨秷(鎺掗槦涓紝鏆傚畾鍒嗛厤)
-                || (!oldDetail.Cancel_Select__c && detail.Cancel_Select__c && olddetail.Queue_Number__c > 0)  //鍙栨秷(鎺掗槦涓紝鏆傚畾鍒嗛厤)
-                // 20220127 ljh update end
-                || (oldDetail.Queue_Number__c > 0  && detail.Queue_Number__c == null )//鍒嗗崟
-                || (oldDetail.Queue_Number__c > 0 && olddetail.ExternalKey__c != detail.ExternalKey__c)))//閲嶆帓 
-                || (Trigger.isDelete && olddetail.Queue_Number__c > 0 )){
-
-                updateList.add(olddetail);
-                detailIds.add(olddetail.Id);
-                externalKeyList.add(olddetail.ExternalKey__c);
-                if(!minNumberMap.containsKey(olddetail.Externalkey__c)){
-                    minNumberMap.put(olddetail.Externalkey__c,olddetail.Queue_Number__c);
-                }else{
-                    if(minNumberMap.get(olddetail.Externalkey__c) > olddetail.Queue_Number__c){
-                        minNumberMap.put(olddetail.Externalkey__c,olddetail.Queue_Number__c);
-                    }
-                }
-            }
+    if (dLMap.size() > 0) {
+      List<OlympusCalendar__c> ocList = [
+        SELECT Id, Date__c
+        FROM OlympusCalendar__c
+        WHERE
+          Date__c >= :minDate
+          AND Date__c <= :maxDate.addDays(30)
+          AND IsWorkDay__c = 1
+        ORDER BY Date__c ASC
+      ];
+      Map<Date, Date> dateadd3Map = new Map<Date, Date>();
+      Integer ocListSize = ocList.size();
+      if (ocListSize > 8) {
+        for (Integer i = 0; i < ocListSize - 8; i++) {
+          dateadd3Map.put(ocList[i].Date__c, ocList[i + 8].Date__c);
         }
-
-        if (!detailIds.isEmpty()) {
-            List<String> sequencekeylist = new List<String>();
-            List<String> changeSequenceIds = new List<String>();
-            Map<String,Decimal> changesequenceMap = new Map<String,Decimal>();
-            List<Rental_Apply_Sequence__c> assignSequence = [SELECT Id,Series_No__c,Invalid_Flag__c,Externalkey__c 
-                                                            FROM Rental_Apply_Sequence__c 
-                                                            WHERE Apply_Set_Detail__c IN: detailIds
-                                                            AND Invalid_Flag__c = false
-                                                            AND Series_No__c > 0];
-            for(Rental_Apply_Sequence__c se:assignSequence){
-                // sequencekeylist.add(se.Externalkey__c);
-                changeSequenceIds.add(se.Id);
-                // if(!changesequenceMap.containsKey(se.Externalkey__c)){
-                //     changesequenceMap.put(se.Externalkey__c,se.Series_No__c);
-                // }else{
-                //     if(changesequenceMap.get(se.Externalkey__c) > se.Series_No__c){
-                //         changesequenceMap.put(se.Externalkey__c,se.Series_No__c);
-                //     }
-                // }
-                se.Invalid_Flag__c = true;
-                se.Series_No__c = 0;
-            } 
-            List<Rental_Apply_Equipment_Set_Detail__c> changeDetailList = new List<Rental_Apply_Equipment_Set_Detail__c>();
-            List<Rental_Apply_Equipment_Set_Detail__c> raesdList = [SELECT Id, Rental_Apply_Equipment_Set__c, Asset__c,Rental_Apply_Equipment_Set__r.Fixture_Set__r.Product_Type__c,
-                                                                       FSD_Fixture_Model_No__c, Fixture_Model_No_text__c,Rental_Apply__r.demo_purpose2__c,Queue_Day__c,ExternalKey__c,
-                                                                       Is_Body__c, FSD_Is_OneToOne__c, Select_Time__c,Rental_Apply__r.EquipmentGuaranteeFlg__c,Allow_Adjust_Queue_Flag__c,
-                                                                       Cancel_Select__c, Fixture_Model_No_F__c, Queue_Number__c, Internal_asset_location__c,Fixture_Model_No__c,Rental_Apply__c,
-                                                                       Internal_asset_location_before__c,Salesdepartment__c, Product_category_F__c, Product_category_text__c,Equipment_Type_text__c,
-                                                                       Salesdepartment_before__c,Rental_Apply__r.Request_shipping_day__c,QuenType__c,IsAdjust__c,Rental_Apply__r.Request_approval_time__c,
-                                                                       Equipment_Type__c, Rental_Apply__r.Internal_asset_location_F__c,Cancel_Reason__c,Loaner_cancel_reason__c,
-                                                                       Loaner_cancel_Remarks__c ,Rental_Apply_Equipment_Set__r.Name
-                                                                FROM Rental_Apply_Equipment_Set_Detail__c
-                                                                WHERE Queue_Number__c > 0
-                                                                  AND Cancel_Select__c = false
-                                                                  AND ExternalKey__c IN:externalKeyList
-                                                                  AND Id NOT IN :detailIds
-                                                                ORDER BY Queue_Number__c ASC ];
-            Map<String,List<Rental_Apply_Equipment_Set_Detail__c>> detailsMap = new Map<String,List<Rental_Apply_Equipment_Set_Detail__c>>();
-            for(Rental_Apply_Equipment_Set_Detail__c setdetail:raesdList){
-                if(!detailsMap.containsKey(setdetail.Externalkey__c)){
-                    detailsMap.put(setdetail.Externalkey__c,new List<Rental_Apply_Equipment_Set_Detail__c>());
+        for (Date d : dLMap.keySet()) {
+          if (dateadd3Map.containsKey(d)) {
+            for (Rental_Apply_Equipment_Set_Detail__c rd : dLMap.get(d)) {
+              Rental_Apply_Equipment_Set_Detail__c raesd = new Rental_Apply_Equipment_Set_Detail__c();
+              raesd.Id = rd.id;
+              raesd.NextShippmentDate__c = dateadd3Map.get(d);
+              upRdList.add(raesd);
+            }
+          } else {
+            for (Integer i = 0; i < ocListSize - 8; i++) {
+              if (d < ocList[i].Date__c) {
+                for (Rental_Apply_Equipment_Set_Detail__c rd : dLMap.get(d)) {
+                  Rental_Apply_Equipment_Set_Detail__c raesd = new Rental_Apply_Equipment_Set_Detail__c();
+                  raesd.Id = rd.id;
+                  raesd.NextShippmentDate__c = ocList[i + 7].Date__c;
+                  upRdList.add(raesd);
                 }
-                detailsMap.get(setdetail.Externalkey__c).add(setdetail);
-
-                
+                break;
+              }
             }
-            for(String key:detailsMap.keySet()){
-                Decimal queueNo = minNumberMap.get(key);
-                System.debug(LoggingLevel.INFO, '*** queueNo: ' + queueNo);
-                Decimal i = 0;
-                for(Rental_Apply_Equipment_Set_Detail__c detail : detailsMap.get(key)){
-                    System.debug(LoggingLevel.INFO, '*** detail.Queue_Number__c: ' + detail.Queue_Number__c);
-                    if(detail.Queue_Number__c > queueNo){
-                        RentalFixtureSetAssignController.KeyObj dobj = RentalFixtureSetAssignController.getSequenceInfo(detail);
-                        sequencekeylist.addAll(dobj.sequencekeylist);
-                        detail.Queue_Number__c  = queueNo + i;
-                        i ++;
-                        System.debug(LoggingLevel.INFO, '**111* detail.Queue_Number__c: ' + detail.Queue_Number__c);
-                        changeDetailList.add(detail);
-                    }
-                }
-            }
-            List<String> nodusequencekeylist = new List<String>(new Set<String>(sequencekeylist));
-            List<Rental_Apply_Sequence__c> sequenceList = [SELECT Id,ExternalKey__c,Demo_Purpose2__c,
-                                                        Apply_Set_Detail__c,Apply_Set_Detail_ExternalKey__c,
-                                                        Series_No__c,Salesdepartment__c,Product_category__c,
-                                                        Rental_Apply__c,Internal_asset_location__c,
-                                                        Apply_Set_Detail__r.Queue_Number__c,Series_Unequal_Queue_Flag__c,
-                                                        Fixture_Model_No__c,Equipment_Type__c
-                                                        FROM Rental_Apply_Sequence__c
-                                                        WHERE ExternalKey__c IN: nodusequencekeylist
-                                                        AND Id NOT IN:changeSequenceIds
-                                                        AND Series_No__c > 0
-                                                        AND Invalid_Flag__c = false
-                                                        FOR UPDATE
-                                                        ];
-            System.debug(LoggingLevel.INFO, '*** sequenceList: ' + sequenceList);
-            Map<String,List<Rental_Apply_Sequence__c>> sequenceMap = new Map<String,List<Rental_Apply_Sequence__c>>();
-            List<FixtureUtil.SequenceWrapper> Wrappers = new List<FixtureUtil.SequenceWrapper>();
-            for(Rental_Apply_Sequence__c se: sequenceList){
-                Wrappers.add(new FixtureUtil.SequenceWrapper(se));
-            }
-            Wrappers.sort();
-            sequenceList = new List<Rental_Apply_Sequence__c>();
-            for(FixtureUtil.SequenceWrapper wrapper:wrappers){
-                sequenceList.add(wrapper.sequence);
-            }
-            for(Rental_Apply_Sequence__c se: sequenceList){
-                if(!sequenceMap.containsKey(se.Externalkey__c)){
-                    sequenceMap.put(se.Externalkey__c,new List<Rental_Apply_Sequence__c>());
-                }
-                sequenceMap.get(se.Externalkey__c).add(se);
-            }
-            List<Rental_Apply_Sequence__c> changeSequenceList = new List<Rental_Apply_Sequence__c>();
-            for(String key:sequenceMap.keyset()){
-                Decimal i = 1;
-                for(Rental_Apply_Sequence__c se: sequenceMap.get(key)){
-                    if(se.Series_No__c != i){
-                        se.Series_No__c =  i;
-                        changeSequenceList.add(se);
-                    }
-                    i ++ ;
-                }
-            }
-            update assignSequence;
-            update changeSequenceList;
-            update changeDetailList;
+          }
         }
+        if (upRdList.size() > 0) {
+          // 澶囧搧浼樺寲杩藉姞 20230518 lc Start
+          if (skipUpdateAgain) {
+            Oly_TriggerHandler.bypass('RentalApplyEquipmentSetDetailHandler');
+            update upRdList;
+            Oly_TriggerHandler.clearBypass(
+              'RentalApplyEquipmentSetDetailHandler'
+            );
+          } else {
+            update upRdList;
+          }
+          // 澶囧搧浼樺寲杩藉姞 20230518 lc End
+        }
+      }
+    }
+  }
+  // 20211116 ljh 涓嬩竴娆″�熺敤棰勮鍑哄簱鏃堕棿  鐨勮祴鍊� 鍥炴敹鍚�-妫�娴嬬粨鏋淥K閫昏緫 end
+  //added by denny
+  public void reQueueAndSequence() {
+    Map<Id, Rental_Apply_Equipment_Set_Detail__c> newdetailMap = (Map<Id, Rental_Apply_Equipment_Set_Detail__c>) Trigger.newMap;
+    List<Rental_Apply_Equipment_Set_Detail__c> updateList = new List<Rental_Apply_Equipment_Set_Detail__c>();
+    List<String> detailIds = new List<String>();
+    List<String> externalKeyList = new List<String>();
+    Map<String, Decimal> minNumberMap = new Map<String, Decimal>();
+    for (
+      Rental_Apply_Equipment_Set_Detail__c olddetail : (List<Rental_Apply_Equipment_Set_Detail__c>) Trigger.old
+    ) {
+      Rental_Apply_Equipment_Set_Detail__c detail;
+      if (Trigger.isUpdate) {
+        detail = newdetailMap.get(olddetail.Id);
+      }
+      if (
+        (Trigger.isUpdate &&
+        ((oldDetail.Queue_Number__c > 0 &&
+        detail.Queue_Number__c == 0) || // 鏆傚畾鍒嗛厤
+        // 20220127 ljh update start
+        // || (!oldDetail.Cancel_Select__c && detail.Cancel_Select__c && olddetail.Queue_Number__c >= 0)  //鍙栨秷(鎺掗槦涓紝鏆傚畾鍒嗛厤)
+        (!oldDetail.Cancel_Select__c &&
+        detail.Cancel_Select__c &&
+        olddetail.Queue_Number__c > 0) || //鍙栨秷(鎺掗槦涓紝鏆傚畾鍒嗛厤)
+        // 20220127 ljh update end
+        (oldDetail.Queue_Number__c > 0 &&
+        detail.Queue_Number__c == null) || //鍒嗗崟
+        (oldDetail.Queue_Number__c > 0 &&
+        olddetail.ExternalKey__c != detail.ExternalKey__c))) || //閲嶆帓
+        (Trigger.isDelete && olddetail.Queue_Number__c > 0)
+      ) {
+        updateList.add(olddetail);
+        detailIds.add(olddetail.Id);
+        externalKeyList.add(olddetail.ExternalKey__c);
+        if (!minNumberMap.containsKey(olddetail.Externalkey__c)) {
+          minNumberMap.put(olddetail.Externalkey__c, olddetail.Queue_Number__c);
+        } else {
+          if (
+            minNumberMap.get(olddetail.Externalkey__c) >
+            olddetail.Queue_Number__c
+          ) {
+            minNumberMap.put(
+              olddetail.Externalkey__c,
+              olddetail.Queue_Number__c
+            );
+          }
+        }
+      }
     }
 
-    private void setUniqueKeyQueue(){
-        Map<Id, Rental_Apply_Equipment_Set_Detail__c> olddetailMap = (Map<Id, Rental_Apply_Equipment_Set_Detail__c>) Trigger.oldMap;
-
-        System.debug('寮�濮嬪鐞�------------------------------------');
-        System.debug('(List<Rental_Apply_Equipment_Set_Detail__c>) Trigger.new---------------' + (List<Rental_Apply_Equipment_Set_Detail__c>) Trigger.new);
-        for(Rental_Apply_Equipment_Set_Detail__c newdetail :  (List<Rental_Apply_Equipment_Set_Detail__c>) Trigger.new){
-            System.debug(newdetail.Id + ' 鐢宠鍗曞彿锛�' + newdetail.Rental_Apply__r.name);
-            Rental_Apply_Equipment_Set_Detail__c olddetail = olddetailMap.get(newdetail.Id);
-            System.debug('鏃ф帓闃烴o锛�' + olddetail.Queue_Number__c);
-            System.debug('鏂版帓闃烴o锛�' + newdetail.Queue_Number__c);
-            
-            if((olddetail.Queue_Number__c > 0  && newdetail.Queue_Number__c == 0)// 鏆傚畾鍒嗛厤
-                || (!olddetail.Cancel_Select__c && newdetail.Cancel_Select__c && olddetail.Queue_Number__c > 0)  //鍙栨秷(鎺掗槦涓紝鏆傚畾鍒嗛厤)
-                || (olddetail.Queue_Number__c > 0  && newdetail.Queue_Number__c == null )//鍒嗗崟
-                ){
-                // 娓呯┖鎺掗槦鐨刄niqueKey
-                newdetail.UniqueKey_Queue__c = null;
-                System.debug('鏂版帓闃烾niqueKey_Queue__c锛�' + newdetail.UniqueKey_Queue__c);
-            }
-
-            // 閲嶆帓鎴栬�呮帓闃烴o鍙樺寲鏃舵洿鏂�
-            if (!newdetail.Cancel_Select__c && newdetail.Queue_Number__c > 0 && newdetail.ExternalKey__c != null
-                && (newdetail.Queue_Number__c != olddetail.Queue_Number__c
-                    || newdetail.ExternalKey__c != olddetail.ExternalKey__c)) {
-                // 鎺掗槦鐨刄niqueKey璁惧��
-                newdetail.UniqueKey_Queue__c = newdetail.ExternalKey__c + ':' + newdetail.Queue_Number__c;
-            System.debug('鏂版帓闃烾niqueKey_Queue__c锛�' + newdetail.UniqueKey_Queue__c);
-            }
+    if (!detailIds.isEmpty()) {
+      List<String> sequencekeylist = new List<String>();
+      List<String> changeSequenceIds = new List<String>();
+      Map<String, Decimal> changesequenceMap = new Map<String, Decimal>();
+      List<Rental_Apply_Sequence__c> assignSequence = [
+        SELECT Id, Series_No__c, Invalid_Flag__c, Externalkey__c
+        FROM Rental_Apply_Sequence__c
+        WHERE
+          Apply_Set_Detail__c IN :detailIds
+          AND Invalid_Flag__c = FALSE
+          AND Series_No__c > 0
+      ];
+      for (Rental_Apply_Sequence__c se : assignSequence) {
+        // sequencekeylist.add(se.Externalkey__c);
+        changeSequenceIds.add(se.Id);
+        // if(!changesequenceMap.containsKey(se.Externalkey__c)){
+        //     changesequenceMap.put(se.Externalkey__c,se.Series_No__c);
+        // }else{
+        //     if(changesequenceMap.get(se.Externalkey__c) > se.Series_No__c){
+        //         changesequenceMap.put(se.Externalkey__c,se.Series_No__c);
+        //     }
+        // }
+        se.Invalid_Flag__c = true;
+        se.Series_No__c = 0;
+      }
+      List<Rental_Apply_Equipment_Set_Detail__c> changeDetailList = new List<Rental_Apply_Equipment_Set_Detail__c>();
+      List<Rental_Apply_Equipment_Set_Detail__c> raesdList = [
+        SELECT
+          Id,
+          Rental_Apply_Equipment_Set__c,
+          Asset__c,
+          Rental_Apply_Equipment_Set__r.Fixture_Set__r.Product_Type__c,
+          FSD_Fixture_Model_No__c,
+          Fixture_Model_No_text__c,
+          Rental_Apply__r.demo_purpose2__c,
+          Queue_Day__c,
+          ExternalKey__c,
+          Is_Body__c,
+          FSD_Is_OneToOne__c,
+          Select_Time__c,
+          Rental_Apply__r.EquipmentGuaranteeFlg__c,
+          Allow_Adjust_Queue_Flag__c,
+          Cancel_Select__c,
+          Fixture_Model_No_F__c,
+          Queue_Number__c,
+          Internal_asset_location__c,
+          Fixture_Model_No__c,
+          Rental_Apply__c,
+          Internal_asset_location_before__c,
+          Salesdepartment__c,
+          Product_category_F__c,
+          Product_category_text__c,
+          Equipment_Type_text__c,
+          Salesdepartment_before__c,
+          Rental_Apply__r.Request_shipping_day__c,
+          QuenType__c,
+          IsAdjust__c,
+          Rental_Apply__r.Request_approval_time__c,
+          Equipment_Type__c,
+          Rental_Apply__r.Internal_asset_location_F__c,
+          Cancel_Reason__c,
+          Loaner_cancel_reason__c,
+          Loaner_cancel_Remarks__c,
+          Rental_Apply_Equipment_Set__r.Name
+        FROM Rental_Apply_Equipment_Set_Detail__c
+        WHERE
+          Queue_Number__c > 0
+          AND Cancel_Select__c = FALSE
+          AND ExternalKey__c IN :externalKeyList
+          AND Id NOT IN :detailIds
+        ORDER BY Queue_Number__c ASC
+      ];
+      Map<String, List<Rental_Apply_Equipment_Set_Detail__c>> detailsMap = new Map<String, List<Rental_Apply_Equipment_Set_Detail__c>>();
+      for (Rental_Apply_Equipment_Set_Detail__c setdetail : raesdList) {
+        if (!detailsMap.containsKey(setdetail.Externalkey__c)) {
+          detailsMap.put(
+            setdetail.Externalkey__c,
+            new List<Rental_Apply_Equipment_Set_Detail__c>()
+          );
         }
-        System.debug('缁撴潫澶勭悊------------------------------------');
+        detailsMap.get(setdetail.Externalkey__c).add(setdetail);
+      }
+      for (String key : detailsMap.keySet()) {
+        Decimal queueNo = minNumberMap.get(key);
+        System.debug(LoggingLevel.INFO, '*** queueNo: ' + queueNo);
+        Decimal i = 0;
+        for (
+          Rental_Apply_Equipment_Set_Detail__c detail : detailsMap.get(key)
+        ) {
+          System.debug(
+            LoggingLevel.INFO,
+            '*** detail.Queue_Number__c: ' + detail.Queue_Number__c
+          );
+          if (detail.Queue_Number__c > queueNo) {
+            RentalFixtureSetAssignController.KeyObj dobj = RentalFixtureSetAssignController.getSequenceInfo(
+              detail
+            );
+            sequencekeylist.addAll(dobj.sequencekeylist);
+            detail.Queue_Number__c = queueNo + i;
+            i++;
+            System.debug(
+              LoggingLevel.INFO,
+              '**111* detail.Queue_Number__c: ' + detail.Queue_Number__c
+            );
+            changeDetailList.add(detail);
+          }
+        }
+      }
+      List<String> nodusequencekeylist = new List<String>(
+        new Set<String>(sequencekeylist)
+      );
+      List<Rental_Apply_Sequence__c> sequenceList = [
+        SELECT
+          Id,
+          ExternalKey__c,
+          Demo_Purpose2__c,
+          Apply_Set_Detail__c,
+          Apply_Set_Detail_ExternalKey__c,
+          Series_No__c,
+          Salesdepartment__c,
+          Product_category__c,
+          Rental_Apply__c,
+          Internal_asset_location__c,
+          Apply_Set_Detail__r.Queue_Number__c,
+          Series_Unequal_Queue_Flag__c,
+          Fixture_Model_No__c,
+          Equipment_Type__c
+        FROM Rental_Apply_Sequence__c
+        WHERE
+          ExternalKey__c IN :nodusequencekeylist
+          AND Id NOT IN :changeSequenceIds
+          AND Series_No__c > 0
+          AND Invalid_Flag__c = FALSE
+        FOR UPDATE
+      ];
+      System.debug(LoggingLevel.INFO, '*** sequenceList: ' + sequenceList);
+      Map<String, List<Rental_Apply_Sequence__c>> sequenceMap = new Map<String, List<Rental_Apply_Sequence__c>>();
+      List<FixtureUtil.SequenceWrapper> Wrappers = new List<FixtureUtil.SequenceWrapper>();
+      for (Rental_Apply_Sequence__c se : sequenceList) {
+        Wrappers.add(new FixtureUtil.SequenceWrapper(se));
+      }
+      Wrappers.sort();
+      sequenceList = new List<Rental_Apply_Sequence__c>();
+      for (FixtureUtil.SequenceWrapper wrapper : wrappers) {
+        sequenceList.add(wrapper.sequence);
+      }
+      for (Rental_Apply_Sequence__c se : sequenceList) {
+        if (!sequenceMap.containsKey(se.Externalkey__c)) {
+          sequenceMap.put(
+            se.Externalkey__c,
+            new List<Rental_Apply_Sequence__c>()
+          );
+        }
+        sequenceMap.get(se.Externalkey__c).add(se);
+      }
+      List<Rental_Apply_Sequence__c> changeSequenceList = new List<Rental_Apply_Sequence__c>();
+      for (String key : sequenceMap.keyset()) {
+        Decimal i = 1;
+        for (Rental_Apply_Sequence__c se : sequenceMap.get(key)) {
+          if (se.Series_No__c != i) {
+            se.Series_No__c = i;
+            changeSequenceList.add(se);
+          }
+          i++;
+        }
+      }
+      update assignSequence;
+      update changeSequenceList;
+      update changeDetailList;
     }
+  }
 
-    /*
+  private void setUniqueKeyQueue() {
+    Map<Id, Rental_Apply_Equipment_Set_Detail__c> olddetailMap = (Map<Id, Rental_Apply_Equipment_Set_Detail__c>) Trigger.oldMap;
+
+    System.debug('寮�濮嬪鐞�------------------------------------');
+    System.debug(
+      '(List<Rental_Apply_Equipment_Set_Detail__c>) Trigger.new---------------' +
+      (List<Rental_Apply_Equipment_Set_Detail__c>) Trigger.new
+    );
+    for (
+      Rental_Apply_Equipment_Set_Detail__c newdetail : (List<Rental_Apply_Equipment_Set_Detail__c>) Trigger.new
+    ) {
+      System.debug(
+        newdetail.Id + ' 鐢宠鍗曞彿锛�' + newdetail.Rental_Apply__r.name
+      );
+      Rental_Apply_Equipment_Set_Detail__c olddetail = olddetailMap.get(
+        newdetail.Id
+      );
+      System.debug('鏃ф帓闃烴o锛�' + olddetail.Queue_Number__c);
+      System.debug('鏂版帓闃烴o锛�' + newdetail.Queue_Number__c);
+
+      if (
+        (olddetail.Queue_Number__c > 0 &&
+        newdetail.Queue_Number__c == 0) || // 鏆傚畾鍒嗛厤
+        (!olddetail.Cancel_Select__c &&
+        newdetail.Cancel_Select__c &&
+        olddetail.Queue_Number__c > 0) || //鍙栨秷(鎺掗槦涓紝鏆傚畾鍒嗛厤)
+        (olddetail.Queue_Number__c > 0 &&
+        newdetail.Queue_Number__c == null) //鍒嗗崟
+      ) {
+        // 娓呯┖鎺掗槦鐨刄niqueKey
+        newdetail.UniqueKey_Queue__c = null;
+        System.debug(
+          '鏂版帓闃烾niqueKey_Queue__c锛�' + newdetail.UniqueKey_Queue__c
+        );
+      }
+
+      // 閲嶆帓鎴栬�呮帓闃烴o鍙樺寲鏃舵洿鏂�
+      if (
+        !newdetail.Cancel_Select__c &&
+        newdetail.Queue_Number__c > 0 &&
+        newdetail.ExternalKey__c != null &&
+        (newdetail.Queue_Number__c != olddetail.Queue_Number__c ||
+        newdetail.ExternalKey__c != olddetail.ExternalKey__c)
+      ) {
+        // 鎺掗槦鐨刄niqueKey璁惧��
+        newdetail.UniqueKey_Queue__c =
+          newdetail.ExternalKey__c +
+          ':' +
+          newdetail.Queue_Number__c;
+        System.debug(
+          '鏂版帓闃烾niqueKey_Queue__c锛�' + newdetail.UniqueKey_Queue__c
+        );
+      }
+    }
+    System.debug('缁撴潫澶勭悊------------------------------------');
+  }
+
+  /*
     private void reQueueNumber() {
         Map<String, List<Rental_Apply_Equipment_Set_Detail__c>> queueRaesdMap = new Map<String, List<Rental_Apply_Equipment_Set_Detail__c>>();
         String wher = '';
@@ -4750,286 +2465,384 @@
             update raesdList;
         }
     }*/
-    //鐢宠鑰呮敹鍥濶G鍚庢槑缁嗗洖瀵勬椂鐨勯偖浠跺洖瀵勫崟鍐呭璁剧疆
-    //鍙湪Afterupdate閲岄潰璋冪敤
-    private void receivedConfirmNGSetReturnDeliverySlipText() {
-        //涓�瑙圛d鍜屽搴旂殑鍥炲瘎鍙戣揣鍗旾D
-        Map<Id, Id> raesRDSMap = new Map<Id, Id>();
-        Map<Id, String> raesDateMap = new Map<Id, String>();
-        for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
-            Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
-            //鐢宠鑰呮敹璐G鐨勬槑缁�
-            if (nObj.Received_Confirm_F__c == 'NG') {
-                //鍥炲瘎杩愯緭鍗曡祴鍊�
-                if (String.isBlank(oObj.Return_DeliverySlip__c) && String.isNotBlank(nObj.Return_DeliverySlip__c)) {
-                    //鍥犱负鏄互涓轰竴瑙堜负鍗曚綅锛屾墍浠ュ彧鏈変竴鏉″洖瀵勫崟
-                    //鐢宠鑰呮敹璐G鐨勬槑缁嗘媶鎴愪袱涓洖瀵勫崟鍥炲瘎鐨勬儏鍐垫殏鏃朵笉鑰冭檻锛堝簲璇ユ病鏈夎繖绉嶆儏鍐碉級
-                    if (!raesRDSMap.containsKey(nObj.Rental_Apply_Equipment_Set__c)) {
-                        raesRDSMap.put(nObj.Rental_Apply_Equipment_Set__c, nObj.Return_DeliverySlip__c);
-                        raesDateMap.put(nObj.Rental_Apply_Equipment_Set__c, nObj.Asset_return_time__c.format());
-                    }
-                }
-            }
+  //鐢宠鑰呮敹鍥濶G鍚庢槑缁嗗洖瀵勬椂鐨勯偖浠跺洖瀵勫崟鍐呭璁剧疆
+  //鍙湪Afterupdate閲岄潰璋冪敤
+  private void receivedConfirmNGSetReturnDeliverySlipText() {
+    //涓�瑙圛d鍜屽搴旂殑鍥炲瘎鍙戣揣鍗旾D
+    Map<Id, Id> raesRDSMap = new Map<Id, Id>();
+    Map<Id, String> raesDateMap = new Map<Id, String>();
+    for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
+      Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
+      //鐢宠鑰呮敹璐G鐨勬槑缁�
+      if (nObj.Received_Confirm_F__c == 'NG') {
+        //鍥炲瘎杩愯緭鍗曡祴鍊�
+        if (
+          String.isBlank(oObj.Return_DeliverySlip__c) &&
+          String.isNotBlank(nObj.Return_DeliverySlip__c)
+        ) {
+          //鍥犱负鏄互涓轰竴瑙堜负鍗曚綅锛屾墍浠ュ彧鏈変竴鏉″洖瀵勫崟
+          //鐢宠鑰呮敹璐G鐨勬槑缁嗘媶鎴愪袱涓洖瀵勫崟鍥炲瘎鐨勬儏鍐垫殏鏃朵笉鑰冭檻锛堝簲璇ユ病鏈夎繖绉嶆儏鍐碉級
+          if (!raesRDSMap.containsKey(nObj.Rental_Apply_Equipment_Set__c)) {
+            raesRDSMap.put(
+              nObj.Rental_Apply_Equipment_Set__c,
+              nObj.Return_DeliverySlip__c
+            );
+            raesDateMap.put(
+              nObj.Rental_Apply_Equipment_Set__c,
+              nObj.Asset_return_time__c.format()
+            );
+          }
         }
-        if (raesRDSMap.isEmpty()) {
-            return;
-        }
-        //NG_Return_DeliverySlip__c涓虹┖鐨勪竴瑙堟墠鍋氶偖浠跺彂閫�
-        Map<Id, Rental_Apply_Equipment_Set__c> raessMap = new Map<Id, Rental_Apply_Equipment_Set__c>([Select Id From Rental_Apply_Equipment_Set__c
-                WHERE Id =: raesRDSMap.keySet()
-                AND NG_Return_DeliverySlip__c = null]);
-        Map<Id, FixtureDeliverySlip__c> fdss = new Map<Id, FixtureDeliverySlip__c>([Select Id, Name, Combine_Pack__c, Wh_Staff__c, DeliveryCompany__c, Shippment_loaner_time__c,
-                Distributor_method__c, DeliveryCompany_SlipNo__c, DeliveryType__c
-                From FixtureDeliverySlip__c
-                Where Id =: raesRDSMap.values()]);
-        System.debug('fdss is ' + fdss);
-        List<Rental_Apply_Equipment_Set__c> raess = new List<Rental_Apply_Equipment_Set__c>();
-        for (Id key: raesRDSMap.keySet()) {
-            //褰揘G_Return_DeliverySlip__c涓嶄负绌烘椂涓嶅彂閭欢
-            if (!raessMap.containsKey(key)) {
-                continue;
-            }
-            FixtureDeliverySlip__c fds = fdss.get(raesRDSMap.get(key));
-            String message = '鍙戣揣-鍙戣揣杩愯緭鍗曞彿锛�'
-                            + fds.Name + '<BR>'
-                            + '鍙戣揣-鐗╂祦鍏徃锛�'
-                            + fds.DeliveryCompany__c + '<BR>'
-                            + '鍙戣揣-杩愯緭鏂瑰紡锛�'
-                            + fds.Distributor_method__c + '<BR>'
-                            + '鐗╂祦鎻愯揣鏃堕棿锛�'
-                            + raesDateMap.get(key) + '<BR>';
-            raess.add(new Rental_Apply_Equipment_Set__c(Id = key,
-                    NG_Return_DeliverySlip_Information__c = message,
-                    NG_Return_DeliverySlip__c = fds.Id));
-        }
-        if (!raess.isEmpty()) {
-            update raess;
-        }
+      }
     }
-
-    //璁剧疆鐢宠涔︾殑鍥炲瘎閫氱煡鏂囨湰
-    @future
-    private static void setRequestAsset_return_Text(Set<Id> raesdIdSet) {
-        List<Rental_Apply_Equipment_Set_Detail__c> raesdList = [SELECT Id,
-                                                                       Rental_Apply__c,
-                                                                       Return_DeliverySlip__c,
-                                                                       Rental_Apply_Equipment_Set__c,
-                                                                       Fixture_Model_No_text__c,
-                                                                       Lost_Item_return__c,
-                                                                       NoItemReturn__c,
-                                                                       Rental_Apply__r.Name,
-                                                                       Rental_Apply__r.Id,
-                                                                       Return_DeliverySlip__r.Id,
-                                                                       Return_DeliverySlip__r.Name,
-                                                                       Return_DeliverySlip__r.DeliveryCompany__c,
-                                                                       Return_DeliverySlip__r.Distributor_method__c,
-                                                                       Return_DeliverySlip__r.Shippment_loaner_time__c
-                                                                  FROM Rental_Apply_Equipment_Set_Detail__c
-                                                                 WHERE Id = :raesdIdSet
-                                                                   // 鍥炲瘎閫氱煡鍙彂閫佹湁閾炬帴鍥炲瘎鍗曠殑鏄庣粏淇℃伅
-                                                                   AND Return_DeliverySlip__c != null
-                                                                 ORDER BY Rental_Apply__c, Rental_Apply_Equipment_Set__c, Name];
-        // 鏀堕泦鍥炲瘎鏄庣粏 {raesId -> raesdList}
-        Map<Id, List<Rental_Apply_Equipment_Set_Detail__c>> raesdListMap = new Map<Id, List<Rental_Apply_Equipment_Set_Detail__c>>();
-        Map<Id, FixtureDeliverySlip__c> return_DeliverySlipMap = new Map<Id, FixtureDeliverySlip__c>();
-        for (Rental_Apply_Equipment_Set_Detail__c raesd : raesdList) {
-            if (!raesdListMap.containsKey(raesd.Rental_Apply_Equipment_Set__c)) {
-                raesdListMap.put(raesd.Rental_Apply_Equipment_Set__c, new List<Rental_Apply_Equipment_Set_Detail__c>());
-            }
-
-            raesdListMap.get(raesd.Rental_Apply_Equipment_Set__c).add(raesd);
-            /* --------- 璁剧疆杩愯緭鍗昅ap Start --------- */
-            if (return_DeliverySlipMap.containsKey(raesd.Rental_Apply__c) == false) {
-                FixtureDeliverySlip__c fds = raesd.Return_DeliverySlip__r;
-                // 鏃犲疄鐗╁洖瀵勭殑鍥炲瘎鍗曚笉鏄剧ず鐗╂祦鍗曚俊鎭�
-                if (fds.Name == raesd.Rental_Apply__r.Name + '_Dummy') {
-                    continue;
-                }
-                return_DeliverySlipMap.put(raesd.Rental_Apply__c, fds);
-            }
-            /* --------- 璁剧疆杩愯緭鍗昅ap End --------- */
-        }
-        if (raesdListMap.isEmpty()) {
-            return;
-        }
-        // 妫�绱㈠洖瀵勭殑涓�瑙� {raId -> raesList}
-        Map<Id, List<Rental_Apply_Equipment_Set__c>> raesListMap = new Map<Id, List<Rental_Apply_Equipment_Set__c>>();
-        List<Rental_Apply_Equipment_Set__c> raesList = [SELECT Id,
-                                                               Loaner_code_F__c,
-                                                               Rental_Apply__c,
-                                                               Asset_return_Status__c,
-                                                               Received_Confirm__c
-                                                          FROM Rental_Apply_Equipment_Set__c
-                                                         WHERE Id =: raesdListMap.keySet()];
-        for (Rental_Apply_Equipment_Set__c raes : raesList) {
-            if (!raesListMap.containsKey(raes.Rental_Apply__c)) {
-                raesListMap.put(raes.Rental_Apply__c, new List<Rental_Apply_Equipment_Set__c>());
-            }
-            raes.recalculateFormulas();
-            System.debug(raes.Wei_Return__c);
-            raesListMap.get(raes.Rental_Apply__c).add(raes);
-        }
-        List<Rental_Apply__c> raList = new List<Rental_Apply__c>();
-        List<Rental_Apply__c> raList2 = new List<Rental_Apply__c>();
-        String message = '';
-        Integer i = 0;
-        // 鐢宠涔﹀崟浣嶉兘鏄瑺鍝佸洖瀵勭殑鏄庣粏
-        Boolean allLostItemReturnFlag = true;
-        // 鏌ョ湅鎵�鏈夌殑鐢宠涔�
-        for (Id raId : raesListMap.keySet()) {
-            allLostItemReturnFlag = true;
-            i = 0;
-            // 鏌ョ湅鐢宠涔︿笅闈㈢殑鎵�鏈変竴瑙�
-            for (Rental_Apply_Equipment_Set__c raes : raesListMap.get(raId)) {
-                i++;
-                message += '閰嶅' + i + '锛�' + raes.Loaner_code_F__c;
-                String message2 = '<BR>';
-                Boolean haveLost_Item_return = false;
-                 // 鏌ョ湅涓�瑙堜笅鐨勬墍鏈夋槑缁�
-                for (Rental_Apply_Equipment_Set_Detail__c nObj : raesdListMap.get(raes.Id)) {
-                    message2 += '&nbsp;&nbsp;&nbsp;&nbsp;' + nObj.Fixture_Model_No_text__c;
-                    if (nObj.Lost_Item_return__c) {
-                        message2 += ' (娆犲搧褰掕繕)';
-                        haveLost_Item_return = true;
-                    }
-                    else {
-                        // 濡傛灉鏈変竴鏉′笉鏄瑺鍝佸洖瀵勯偅涔堝氨涓嶆樉绀烘瑺鍝佸洖瀵�
-                        allLostItemReturnFlag = false;
-                    }
-                    if (nObj.NoItemReturn__c == true) {
-                        message2 += ' (鏃犲疄鐗╁綊杩�)';
-                    }
-                    // if (nObj.Received_Confirm_F__c == 'NG') {
-                    //     message += '(NG褰掕繕)';
-                    // }
-                    message2 += '<BR>';
-                }
-                if (haveLost_Item_return == false && raes.Received_Confirm__c == 'NG') {
-                     message += ' (NG褰掕繕)';
-                }
-                message += message2;
-            }
-
-            message += '<BR>';
-            FixtureDeliverySlip__c fds = new FixtureDeliverySlip__c();
-            if (return_DeliverySlipMap.containsKey(raId)) {
-                 fds = return_DeliverySlipMap.get(raId);
-            }
-            message += '鍥炲瘎-鍙戣揣杩愯緭鍗曞彿锛�' + (String.isBlank(fds.Name)? '' : fds.Name) + '<BR>';
-            message += '鍥炲瘎-鐗╂祦鍏徃锛�' + (String.isBlank(fds.DeliveryCompany__c)? '' : fds.DeliveryCompany__c) + '<BR>';
-            message += '鍥炲瘎-杩愯緭鏂瑰紡锛�' + (String.isBlank(fds.Distributor_method__c)? '' : fds.Distributor_method__c) + '<BR>';
-            String sdate = fds.Shippment_loaner_time__c == null ? '' : fds.Shippment_loaner_time__c.format();
-            message += '鐗╂祦鎻愯揣鏃堕棿锛�' + sdate + '<BR>';
-            if (String.isNotBlank(message)) {
-                raList.add(new Rental_Apply__c(Id = raId,
-                                               Asset_return_Text__c = message,
-                                               Lost_item_Return_Flag__c = allLostItemReturnFlag));
-                raList2.add(new Rental_Apply__c(Id = raId,
-                                               Asset_return_Text__c = null));
-                message = '';
-            }
-        }
-        if (raList.size() > 0) {
-            FixtureUtil.withoutUpdate(raList2);
-            FixtureUtil.withoutUpdate(raList);
-        }
+    if (raesRDSMap.isEmpty()) {
+      return;
     }
-
-    private void setAssginPerson(Set<Id> raId) {
-        List<Rental_Apply__c> raList = [select Id, Assign_Person__c from Rental_Apply__c where Id in :raId];
-        List<Rental_Apply__c> updateList = new List<Rental_Apply__c>();
-        for (Rental_Apply__c ra : raList) {
-            if (ra.Assign_Person__c == null) {
-                ra.Assign_Person__c = UserInfo.getUserId();
-                updateList.add(ra);
-            }
-        }
-        if (updateList.size() > 0) update updateList;
+    //NG_Return_DeliverySlip__c涓虹┖鐨勪竴瑙堟墠鍋氶偖浠跺彂閫�
+    Map<Id, Rental_Apply_Equipment_Set__c> raessMap = new Map<Id, Rental_Apply_Equipment_Set__c>(
+      [
+        SELECT Id
+        FROM Rental_Apply_Equipment_Set__c
+        WHERE Id = :raesRDSMap.keySet() AND NG_Return_DeliverySlip__c = NULL
+      ]
+    );
+    Map<Id, FixtureDeliverySlip__c> fdss = new Map<Id, FixtureDeliverySlip__c>(
+      [
+        SELECT
+          Id,
+          Name,
+          Combine_Pack__c,
+          Wh_Staff__c,
+          DeliveryCompany__c,
+          Shippment_loaner_time__c,
+          Distributor_method__c,
+          DeliveryCompany_SlipNo__c,
+          DeliveryType__c
+        FROM FixtureDeliverySlip__c
+        WHERE Id = :raesRDSMap.values()
+      ]
+    );
+    System.debug('fdss is ' + fdss);
+    List<Rental_Apply_Equipment_Set__c> raess = new List<Rental_Apply_Equipment_Set__c>();
+    for (Id key : raesRDSMap.keySet()) {
+      //褰揘G_Return_DeliverySlip__c涓嶄负绌烘椂涓嶅彂閭欢
+      if (!raessMap.containsKey(key)) {
+        continue;
+      }
+      FixtureDeliverySlip__c fds = fdss.get(raesRDSMap.get(key));
+      String message =
+        '鍙戣揣-鍙戣揣杩愯緭鍗曞彿锛�' +
+        fds.Name +
+        '<BR>' +
+        '鍙戣揣-鐗╂祦鍏徃锛�' +
+        fds.DeliveryCompany__c +
+        '<BR>' +
+        '鍙戣揣-杩愯緭鏂瑰紡锛�' +
+        fds.Distributor_method__c +
+        '<BR>' +
+        '鐗╂祦鎻愯揣鏃堕棿锛�' +
+        raesDateMap.get(key) +
+        '<BR>';
+      raess.add(
+        new Rental_Apply_Equipment_Set__c(
+          Id = key,
+          NG_Return_DeliverySlip_Information__c = message,
+          NG_Return_DeliverySlip__c = fds.Id
+        )
+      );
     }
-
-    private void changeAssetConsumable_Guaranteen_end() {
-        for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
-            Rental_Apply_Equipment_Set_Detail__c oObj;
-            if (trigger.isUpdate) {
-                oObj = oldMap.get(nObj.Id);
-            }
-
-            if (oObj.Shippment_loaner_time__c == null
-                    && nObj.Shippment_loaner_time__c != null
-                    && nObj.NeedSet_Consumable_Guaranteen_end_F__c == true) {
-                            Asset nass = assMap.get(nObj.Asset__c);
-                if (assUpdMap.containsKey(nObj.Asset__c)) {
-                    nass = assUpdMap.get(nObj.Asset__c);
-                } else if (String.isNotBlank(nObj.Asset__c)) {
-                    nass = new Asset(Id = nObj.Asset__c);
-                }
-                Datetime dt = nObj.Shippment_loaner_time__c.addYears(1);
-                nass.Consumable_Guaranteen_end__c = Date.newinstance(dT.year(), dT.month(), dT.day());
-                nass.HaveSet_Consumable_Guaranteen_end__c = true;
-            }
-        }
+    if (!raess.isEmpty()) {
+      update raess;
     }
-    // 鍏佽鎻掗槦閭欢  20211125 ljh
-    private void setToRa_Email_Text() {
-        Set<Id> raesdIdJumpSet = new Set<Id>();//鎻掗槦鐨勬槑缁�
-        for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
-            Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
-            // 鐢宠鎻掗槦 && 鎻掗槦鍘熷洜鍙戠敓鍙樺寲鐨�
-            if((nObj.Allow_Adjust_Queue_Flag__c && oObj.Allow_Adjust_Queue_Flag__c != nObj.Allow_Adjust_Queue_Flag__c)
-               ||(!String.isBlank(nObj.jumpReason__c) && oObj.jumpReason__c != nObj.jumpReason__c)
-               ){
-               raesdIdJumpSet.add(nObj.Id);
-            }
-        }
-        System.debug('zheli:'+raesdIdJumpSet);
-        List<Rental_Apply__c> raList = new List<Rental_Apply__c>();
-        List<Rental_Apply__c> raList2 = new List<Rental_Apply__c>();
-        if(raesdIdJumpSet.size() > 0){
-            Map<ID,List<Rental_Apply_Equipment_Set_Detail__c>> radMap = new Map<ID,List<Rental_Apply_Equipment_Set_Detail__c>>();
-            List<Rental_Apply_Equipment_Set_Detail__c> radList =[ SELECT Id, Name,RAESD_Status__c,Rental_Apply__c,Fixture_Model_No__c,Rental_Apply_Equipment_Set__c,Rental_Apply_Equipment_Set__r.Name,
-                     Allow_Adjust_Queue_Flag__c,jumpReason__c 
-                    FROM Rental_Apply_Equipment_Set_Detail__c
-                    WHERE Id = :raesdIdJumpSet
-                    AND Allow_Adjust_Queue_Flag__c = TRUE 
-                    ORDER BY Rental_Apply__c
-            ];
-            for (Rental_Apply_Equipment_Set_Detail__c  rad:radList) {
-                List<Rental_Apply_Equipment_Set_Detail__c> tempL = new List<Rental_Apply_Equipment_Set_Detail__c>();
-                if(radMap.containsKey(rad.Rental_Apply__c)) {   
-                    tempL = radMap.get(rad.Rental_Apply__c);
-                }
-                tempL.add(rad);
-                radMap.put(rad.Rental_Apply__c,tempL);
-            }
-            for (Id raId: radMap.keySet()) {
-                Rental_Apply__c tempRa = new Rental_Apply__c();
-                Rental_Apply__c tempRa2  = new Rental_Apply__c();
-                tempRa.Id = raId;
-                tempRa2.Id = raId;
-                String htmlStr = '';
-                htmlStr += '<table border="1">';
-                htmlStr += '<tr> <th>涓�瑙圢o.</th><th>鍨嬪彿</th><th>鍊熷嚭澶囧搧涓�瑙堟槑缁嗙姸鎬�</th><th>鎻掗槦鍘熷洜</th></tr>';
-                for (Rental_Apply_Equipment_Set_Detail__c rad : radMap.get(raId)) {
-                    htmlStr += '<tr><td>'+rad.Rental_Apply_Equipment_Set__r.Name+'</td><td>'+rad.Fixture_Model_No__c+'</td><td>'+rad.RAESD_Status__c+'</td><td>'+rad.jumpReason__c+'</td></tr>';
-                }
-                htmlStr += '</table>';
-                tempRa.Email_Jump_List__c = htmlStr;
-                tempRa2.Email_Jump_List__c = null;
-                tempRa.Email_Jump__c = TRUE;
-                tempRa2.Email_Jump__c = FALSE;
-                raList.add(tempRa);
-                raList2.add(tempRa2);
-            }
-        }
-        if (raList.size() > 0) {
-            FixtureUtil.withoutUpdate(raList2);
-            FixtureUtil.withoutUpdate(raList);
-        }
-    }
+  }
 
-    // 20220121 鎺掗槦涓婄嚎
-    //澶囧搧浠诲姟瀹屾垚鍒ゆ柇   mzy  2021-12-14
-    /*private void FinishRentalTask() {
+  //璁剧疆鐢宠涔︾殑鍥炲瘎閫氱煡鏂囨湰
+  @future
+  private static void setRequestAsset_return_Text(Set<Id> raesdIdSet) {
+    List<Rental_Apply_Equipment_Set_Detail__c> raesdList = [
+      SELECT
+        Id,
+        Rental_Apply__c,
+        Return_DeliverySlip__c,
+        Rental_Apply_Equipment_Set__c,
+        Fixture_Model_No_text__c,
+        Lost_Item_return__c,
+        NoItemReturn__c,
+        Rental_Apply__r.Name,
+        Rental_Apply__r.Id,
+        Return_DeliverySlip__r.Id,
+        Return_DeliverySlip__r.Name,
+        Return_DeliverySlip__r.DeliveryCompany__c,
+        Return_DeliverySlip__r.Distributor_method__c,
+        Return_DeliverySlip__r.Shippment_loaner_time__c
+      FROM Rental_Apply_Equipment_Set_Detail__c
+      WHERE
+        Id = :raesdIdSet
+        // 鍥炲瘎閫氱煡鍙彂閫佹湁閾炬帴鍥炲瘎鍗曠殑鏄庣粏淇℃伅
+        AND Return_DeliverySlip__c != NULL
+      ORDER BY Rental_Apply__c, Rental_Apply_Equipment_Set__c, Name
+    ];
+    // 鏀堕泦鍥炲瘎鏄庣粏 {raesId -> raesdList}
+    Map<Id, List<Rental_Apply_Equipment_Set_Detail__c>> raesdListMap = new Map<Id, List<Rental_Apply_Equipment_Set_Detail__c>>();
+    Map<Id, FixtureDeliverySlip__c> return_DeliverySlipMap = new Map<Id, FixtureDeliverySlip__c>();
+    for (Rental_Apply_Equipment_Set_Detail__c raesd : raesdList) {
+      if (!raesdListMap.containsKey(raesd.Rental_Apply_Equipment_Set__c)) {
+        raesdListMap.put(
+          raesd.Rental_Apply_Equipment_Set__c,
+          new List<Rental_Apply_Equipment_Set_Detail__c>()
+        );
+      }
+
+      raesdListMap.get(raesd.Rental_Apply_Equipment_Set__c).add(raesd);
+      /* --------- 璁剧疆杩愯緭鍗昅ap Start --------- */
+      if (return_DeliverySlipMap.containsKey(raesd.Rental_Apply__c) == false) {
+        FixtureDeliverySlip__c fds = raesd.Return_DeliverySlip__r;
+        // 鏃犲疄鐗╁洖瀵勭殑鍥炲瘎鍗曚笉鏄剧ず鐗╂祦鍗曚俊鎭�
+        if (fds.Name == raesd.Rental_Apply__r.Name + '_Dummy') {
+          continue;
+        }
+        return_DeliverySlipMap.put(raesd.Rental_Apply__c, fds);
+      }
+      /* --------- 璁剧疆杩愯緭鍗昅ap End --------- */
+    }
+    if (raesdListMap.isEmpty()) {
+      return;
+    }
+    // 妫�绱㈠洖瀵勭殑涓�瑙� {raId -> raesList}
+    Map<Id, List<Rental_Apply_Equipment_Set__c>> raesListMap = new Map<Id, List<Rental_Apply_Equipment_Set__c>>();
+    List<Rental_Apply_Equipment_Set__c> raesList = [
+      SELECT
+        Id,
+        Loaner_code_F__c,
+        Rental_Apply__c,
+        Asset_return_Status__c,
+        Received_Confirm__c
+      FROM Rental_Apply_Equipment_Set__c
+      WHERE Id = :raesdListMap.keySet()
+    ];
+    for (Rental_Apply_Equipment_Set__c raes : raesList) {
+      if (!raesListMap.containsKey(raes.Rental_Apply__c)) {
+        raesListMap.put(
+          raes.Rental_Apply__c,
+          new List<Rental_Apply_Equipment_Set__c>()
+        );
+      }
+      raes.recalculateFormulas();
+      System.debug(raes.Wei_Return__c);
+      raesListMap.get(raes.Rental_Apply__c).add(raes);
+    }
+    List<Rental_Apply__c> raList = new List<Rental_Apply__c>();
+    List<Rental_Apply__c> raList2 = new List<Rental_Apply__c>();
+    String message = '';
+    Integer i = 0;
+    // 鐢宠涔﹀崟浣嶉兘鏄瑺鍝佸洖瀵勭殑鏄庣粏
+    Boolean allLostItemReturnFlag = true;
+    // 鏌ョ湅鎵�鏈夌殑鐢宠涔�
+    for (Id raId : raesListMap.keySet()) {
+      allLostItemReturnFlag = true;
+      i = 0;
+      // 鏌ョ湅鐢宠涔︿笅闈㈢殑鎵�鏈変竴瑙�
+      for (Rental_Apply_Equipment_Set__c raes : raesListMap.get(raId)) {
+        i++;
+        message += '閰嶅' + i + '锛�' + raes.Loaner_code_F__c;
+        String message2 = '<BR>';
+        Boolean haveLost_Item_return = false;
+        // 鏌ョ湅涓�瑙堜笅鐨勬墍鏈夋槑缁�
+        for (
+          Rental_Apply_Equipment_Set_Detail__c nObj : raesdListMap.get(raes.Id)
+        ) {
+          message2 +=
+            '&nbsp;&nbsp;&nbsp;&nbsp;' + nObj.Fixture_Model_No_text__c;
+          if (nObj.Lost_Item_return__c) {
+            message2 += ' (娆犲搧褰掕繕)';
+            haveLost_Item_return = true;
+          } else {
+            // 濡傛灉鏈変竴鏉′笉鏄瑺鍝佸洖瀵勯偅涔堝氨涓嶆樉绀烘瑺鍝佸洖瀵�
+            allLostItemReturnFlag = false;
+          }
+          if (nObj.NoItemReturn__c == true) {
+            message2 += ' (鏃犲疄鐗╁綊杩�)';
+          }
+          // if (nObj.Received_Confirm_F__c == 'NG') {
+          //     message += '(NG褰掕繕)';
+          // }
+          message2 += '<BR>';
+        }
+        if (haveLost_Item_return == false && raes.Received_Confirm__c == 'NG') {
+          message += ' (NG褰掕繕)';
+        }
+        message += message2;
+      }
+
+      message += '<BR>';
+      FixtureDeliverySlip__c fds = new FixtureDeliverySlip__c();
+      if (return_DeliverySlipMap.containsKey(raId)) {
+        fds = return_DeliverySlipMap.get(raId);
+      }
+      message +=
+        '鍥炲瘎-鍙戣揣杩愯緭鍗曞彿锛�' +
+        (String.isBlank(fds.Name) ? '' : fds.Name) +
+        '<BR>';
+      message +=
+        '鍥炲瘎-鐗╂祦鍏徃锛�' +
+        (String.isBlank(fds.DeliveryCompany__c) ? '' : fds.DeliveryCompany__c) +
+        '<BR>';
+      message +=
+        '鍥炲瘎-杩愯緭鏂瑰紡锛�' +
+        (String.isBlank(fds.Distributor_method__c)
+          ? ''
+          : fds.Distributor_method__c) +
+        '<BR>';
+      String sdate = fds.Shippment_loaner_time__c == null
+        ? ''
+        : fds.Shippment_loaner_time__c.format();
+      message += '鐗╂祦鎻愯揣鏃堕棿锛�' + sdate + '<BR>';
+      if (String.isNotBlank(message)) {
+        raList.add(
+          new Rental_Apply__c(
+            Id = raId,
+            Asset_return_Text__c = message,
+            Lost_item_Return_Flag__c = allLostItemReturnFlag
+          )
+        );
+        raList2.add(
+          new Rental_Apply__c(Id = raId, Asset_return_Text__c = null)
+        );
+        message = '';
+      }
+    }
+    if (raList.size() > 0) {
+      FixtureUtil.withoutUpdate(raList2);
+      FixtureUtil.withoutUpdate(raList);
+    }
+  }
+
+  private void setAssginPerson(Set<Id> raId) {
+    List<Rental_Apply__c> raList = [
+      SELECT Id, Assign_Person__c
+      FROM Rental_Apply__c
+      WHERE Id IN :raId
+    ];
+    List<Rental_Apply__c> updateList = new List<Rental_Apply__c>();
+    for (Rental_Apply__c ra : raList) {
+      if (ra.Assign_Person__c == null) {
+        ra.Assign_Person__c = UserInfo.getUserId();
+        updateList.add(ra);
+      }
+    }
+    if (updateList.size() > 0)
+      update updateList;
+  }
+
+  private void changeAssetConsumable_Guaranteen_end() {
+    for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
+      Rental_Apply_Equipment_Set_Detail__c oObj;
+      if (Trigger.isUpdate) {
+        oObj = oldMap.get(nObj.Id);
+      }
+
+      if (
+        oObj.Shippment_loaner_time__c == null &&
+        nObj.Shippment_loaner_time__c != null &&
+        nObj.NeedSet_Consumable_Guaranteen_end_F__c == true
+      ) {
+        Asset nass = assMap.get(nObj.Asset__c);
+        if (assUpdMap.containsKey(nObj.Asset__c)) {
+          nass = assUpdMap.get(nObj.Asset__c);
+        } else if (String.isNotBlank(nObj.Asset__c)) {
+          nass = new Asset(Id = nObj.Asset__c);
+        }
+        Datetime dt = nObj.Shippment_loaner_time__c.addYears(1);
+        nass.Consumable_Guaranteen_end__c = Date.newinstance(
+          dT.year(),
+          dT.month(),
+          dT.day()
+        );
+        nass.HaveSet_Consumable_Guaranteen_end__c = true;
+      }
+    }
+  }
+  // 鍏佽鎻掗槦閭欢  20211125 ljh
+  private void setToRa_Email_Text() {
+    Set<Id> raesdIdJumpSet = new Set<Id>(); //鎻掗槦鐨勬槑缁�
+    for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
+      Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
+      // 鐢宠鎻掗槦 && 鎻掗槦鍘熷洜鍙戠敓鍙樺寲鐨�
+      if (
+        (nObj.Allow_Adjust_Queue_Flag__c &&
+        oObj.Allow_Adjust_Queue_Flag__c != nObj.Allow_Adjust_Queue_Flag__c) ||
+        (!String.isBlank(nObj.jumpReason__c) &&
+        oObj.jumpReason__c != nObj.jumpReason__c)
+      ) {
+        raesdIdJumpSet.add(nObj.Id);
+      }
+    }
+    System.debug('zheli:' + raesdIdJumpSet);
+    List<Rental_Apply__c> raList = new List<Rental_Apply__c>();
+    List<Rental_Apply__c> raList2 = new List<Rental_Apply__c>();
+    if (raesdIdJumpSet.size() > 0) {
+      Map<ID, List<Rental_Apply_Equipment_Set_Detail__c>> radMap = new Map<ID, List<Rental_Apply_Equipment_Set_Detail__c>>();
+      List<Rental_Apply_Equipment_Set_Detail__c> radList = [
+        SELECT
+          Id,
+          Name,
+          RAESD_Status__c,
+          Rental_Apply__c,
+          Fixture_Model_No__c,
+          Rental_Apply_Equipment_Set__c,
+          Rental_Apply_Equipment_Set__r.Name,
+          Allow_Adjust_Queue_Flag__c,
+          jumpReason__c
+        FROM Rental_Apply_Equipment_Set_Detail__c
+        WHERE Id = :raesdIdJumpSet AND Allow_Adjust_Queue_Flag__c = TRUE
+        ORDER BY Rental_Apply__c
+      ];
+      for (Rental_Apply_Equipment_Set_Detail__c rad : radList) {
+        List<Rental_Apply_Equipment_Set_Detail__c> tempL = new List<Rental_Apply_Equipment_Set_Detail__c>();
+        if (radMap.containsKey(rad.Rental_Apply__c)) {
+          tempL = radMap.get(rad.Rental_Apply__c);
+        }
+        tempL.add(rad);
+        radMap.put(rad.Rental_Apply__c, tempL);
+      }
+      for (Id raId : radMap.keySet()) {
+        Rental_Apply__c tempRa = new Rental_Apply__c();
+        Rental_Apply__c tempRa2 = new Rental_Apply__c();
+        tempRa.Id = raId;
+        tempRa2.Id = raId;
+        String htmlStr = '';
+        htmlStr += '<table border="1">';
+        htmlStr += '<tr> <th>涓�瑙圢o.</th><th>鍨嬪彿</th><th>鍊熷嚭澶囧搧涓�瑙堟槑缁嗙姸鎬�</th><th>鎻掗槦鍘熷洜</th></tr>';
+        for (Rental_Apply_Equipment_Set_Detail__c rad : radMap.get(raId)) {
+          htmlStr +=
+            '<tr><td>' +
+            rad.Rental_Apply_Equipment_Set__r.Name +
+            '</td><td>' +
+            rad.Fixture_Model_No__c +
+            '</td><td>' +
+            rad.RAESD_Status__c +
+            '</td><td>' +
+            rad.jumpReason__c +
+            '</td></tr>';
+        }
+        htmlStr += '</table>';
+        tempRa.Email_Jump_List__c = htmlStr;
+        tempRa2.Email_Jump_List__c = null;
+        tempRa.Email_Jump__c = true;
+        tempRa2.Email_Jump__c = false;
+        raList.add(tempRa);
+        raList2.add(tempRa2);
+      }
+    }
+    if (raList.size() > 0) {
+      FixtureUtil.withoutUpdate(raList2);
+      FixtureUtil.withoutUpdate(raList);
+    }
+  }
+
+  // 20220121 鎺掗槦涓婄嚎
+  //澶囧搧浠诲姟瀹屾垚鍒ゆ柇   mzy  2021-12-14
+  /*private void FinishRentalTask() {
         Set<String> RentalList = new Set<String>();
         for (Rental_Apply_Equipment_Set_Detail__c nObj : newList) {
             Rental_Apply_Equipment_Set_Detail__c oObj = oldMap.get(nObj.Id);
@@ -5193,5 +3006,5 @@
 
         }
     }*/
-    // 20220121 鎺掗槦涓婄嚎
-}
\ No newline at end of file
+  // 20220121 鎺掗槦涓婄嚎
+}

--
Gitblit v1.9.1