From 27f90ff7016a0532a8d97af80367c95905701707 Mon Sep 17 00:00:00 2001
From: unknown <sunxia@prec-tech.com>
Date: 星期三, 12 四月 2023 11:28:37 +0800
Subject: [PATCH] 出库指示

---
 force-app/main/default/classes/RentalApplyWebService.cls                             | 2068 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 force-app/main/default/lwc/lexLoanerArrangedEmail/lexLoanerArrangedEmail.js          |  102 ++
 force-app/main/default/classes/RentalApplyWebService.cls-meta.xml                    |    5 
 force-app/main/default/classes/loanerArrangedEmailController.cls                     |   95 ++
 force-app/main/default/lwc/lexLoanerArrangedEmail/lexLoanerArrangedEmail.js-meta.xml |   11 
 force-app/main/default/lwc/lexLoanerArrangedEmail/lexLoanerArrangedEmail.css         |   10 
 force-app/main/default/lwc/lexLoanerArrangedEmail/lexLoanerArrangedEmail.html        |    5 
 force-app/main/default/classes/loanerArrangedEmailController.cls-meta.xml            |    5 
 8 files changed, 2,301 insertions(+), 0 deletions(-)

diff --git a/force-app/main/default/classes/RentalApplyWebService.cls b/force-app/main/default/classes/RentalApplyWebService.cls
new file mode 100644
index 0000000..a5ffa9e
--- /dev/null
+++ b/force-app/main/default/classes/RentalApplyWebService.cls
@@ -0,0 +1,2068 @@
+global class RentalApplyWebService {
+    // TODO please use public okStatus
+    public final static Integer okStatus = 99;
+    public final static String okStatus2 = '寮曞綋娓�';
+
+//bp2
+//    /**
+//     * check meisai
+//     * @param rentalApplyId            澶囧搧鍊熷嚭鐢宠ID
+//     * @param rentalApplys             澶囧搧鍊熷嚭鐢宠
+//     * @param rentalApplyEquipmentSets 澶囧搧鐢宠鍊熷嚭鍘嗗彶(澶囧搧鍊熷嚭鐢宠 鍜� 澶囧搧Set 鐨凩ink琛�)
+//     * @param equipmentSetIdList       Equipment_Set__c.id
+//     * @param idmap                    Equipment_Set__c.Id => Rental_Apply_Equipment_Set__c.Id
+//     * @return 鎴愬姛: 1銆乷r 閿欒鍐呭
+//     */
+//    private static String privateCheck(String rentalApplyId,
+//            Map<String, List<List<Rental_Apply__c>>> mRentalApplys,
+//            Map<String, List<List<Rental_Apply_Equipment_Set__c>>> mRentalApplyEquipmentSets,
+//            Map<String, List<List<Id>>> mEquipmentSetIdList,
+//            Map<String, List<Map<Id, Id>>> mIdmap
+//    ) {
+//        List<Rental_Apply__c> rentalApplys = mRentalApplys.get('rentalApplys')[0];
+//        List<Rental_Apply_Equipment_Set__c> rentalApplyEquipmentSets = mRentalApplyEquipmentSets.get('rentalApplyEquipmentSets')[0];
+//        List<Id> equipmentSetIdList = mEquipmentSetIdList.get('equipmentSetIdList')[0];
+//        Map<Id, Id> idmap = mIdmap.get('idmap')[0];
+
+//        //杩斿洖缁撴灉,1:鎴愬姛銆�
+//        String checkRS = '1';
+        
+//        //澶囧搧鍊熷嚭鐢宠
+//        rentalApplys = [select Rental_Apply_Equipment_Set_Cnt__c from Rental_Apply__c where Id = :rentalApplyId];
+//        if (rentalApplys.size() == 0) {
+//            checkRS = '娌℃湁澶囧搧鍊熷嚭鐢宠锛岃纭銆�';
+//            return checkRS;
+//        }
+//        Rental_Apply__c rentalApply = rentalApplys[0];
+//        if (rentalApply.Rental_Apply_Equipment_Set_Cnt__c <= 0) {
+//            //杩斿洖缁撴灉,2:message-娌℃湁澶囧搧Set锛岃纭銆�
+//            checkRS = '娌℃湁鍊熷嚭澶囧搧set涓�瑙堬紝璇风‘璁ゃ��';
+//            return checkRS;
+//        }
+        
+//        //澶囧搧鐢宠鍊熷嚭鍘嗗彶
+//        equipmentSetIdList = new List<Id>();
+//        rentalApplyEquipmentSets = [
+//                select Equipment_Set__c,Equipment_Set__r.Active_judgement__c
+//                  from Rental_Apply_Equipment_Set__c
+//                 where Rental_Apply__c = :rentalApplyId and Cancel_Select__c = false];
+//        for (Rental_Apply_Equipment_Set__c rentalApplyEquipmentSet : rentalApplyEquipmentSets) {
+//            equipmentSetIdList.add(rentalApplyEquipmentSet.Equipment_Set__c);
+//        }
+
+//        // Equipment_Set_Detail__c锛岀┖鏇存柊 (TODO 浠婂緦batch銇仾銈嬶紒锛�)
+//        List<Equipment_Set_Detail__c> updDetailList = [
+//                select id
+//                  from Equipment_Set_Detail__c
+//                 where Equipment_Set__c in :equipmentSetIdList];
+//        update updDetailList;
+
+//        //澶囧搧鐢宠鍊熷嚭鍘嗗彶銆佸啀鍙栧緱
+//        List<Rental_Apply_Equipment_Set__c> raesList = new List<Rental_Apply_Equipment_Set__c>();
+//        equipmentSetIdList = new List<Id>();
+        
+//        rentalApplyEquipmentSets = [
+//                select Id,Name,Equipment_Set__c,ES_Stock_Status__c,Loaner_name_text__c,Loaner_code_text__c,SerialNumber_text__c,
+//                        Salesdepartment_text__c,Salesprovince_text__c,Equipment_Type_text__c,Equipment_Set_Borrowed__c,Product_Class_Bor__c,
+//                        Equipment_Set__r.Name,Equipment_Set__r.ES_Status__c,Equipment_Set__r.Active_judgement2__c,
+//                        Equipment_Set__r.Last_Reserve_Rental_Apply_Equipment_Set__c,Rental_Start_Date__c,
+//                        Equipment_Set__r.Already_Stock_Out__c, Equipment_Set__r.Loaner_name__c,
+//                        Equipment_Set__r.Loaner_code__c,Equipment_Set__r.Salesdepartment__c,
+//                        Equipment_Set__r.SalesProvince__c,Equipment_Set__r.Equipment_Type__c,Equipment_Set__r.SerialNumber__c,
+//                        Equipment_Set__r.Contents_number__c,Equipment_Set__r.Product_category__c
+//                  from Rental_Apply_Equipment_Set__c
+//                 where Rental_Apply__c = :rentalApplyId and Cancel_Select__c = false];
+//        idmap = new Map<Id,Id>();    // Equipment_Set__c.Id => Rental_Apply_Equipment_Set__c.Id
+        
+//        for (Rental_Apply_Equipment_Set__c rentalApplyEquipmentSet : rentalApplyEquipmentSets) {
+//            if (rentalApplyEquipmentSet.Equipment_Set__r.Last_Reserve_Rental_Apply_Equipment_Set__c != rentalApplyEquipmentSet.Id) {
+//                raesList.add(rentalApplyEquipmentSet);
+//                equipmentSetIdList.add(rentalApplyEquipmentSet.Equipment_Set__c);
+//            }
+//        }
+        
+//        for (Rental_Apply_Equipment_Set__c rentalApplyEquipmentSet : raesList) {
+//            /*
+//            if (rentalApplyEquipmentSet.Rental_Start_Date__c <= Date.today()) {
+//                checkRS = '鍊熷嚭寮�濮嬫棩蹇呴』澶т簬浠婃棩銆傚�熷嚭澶囧搧set涓�瑙堬細' + rentalApplyEquipmentSet.Name;
+//                return checkRS;
+//            }
+//            */
+//            /*
+//            if (rentalApplyEquipmentSet.Equipment_Set__r.Active_judgement2__c != okStatus) {
+//                //杩斿洖缁撴灉,1:message-璇风‘璁ゅ鍝丼et鐘舵�併��
+//                checkRS = '澶囧搧set ' + rentalApplyEquipmentSet.Equipment_Set__r.Name + ' 鐨�' + Schema.SObjectType.Equipment_Set__c.fields.Asset_Set_status2__c.label + '涓嶆槸 99.绛夊緟棰勭害 锛岀幇鍦ㄦ槸 ' + rentalApplyEquipmentSet.Equipment_Set__r.Asset_Set_status2__c + ' 璇风‘璁�';
+//                return checkRS;
+//            }
+//            */
+//            //
+////bp2            if (rentalApplyEquipmentSet.Equipment_Set__r.Contents_number__c == 0) {
+////bp2                checkRS = '澶囧搧set ' + rentalApplyEquipmentSet.Equipment_Set__r.Name + ' 娌℃湁閫夋嫨鍊熷嚭鐨勬槑缁嗭紝璇风‘璁�';
+////bp2                return checkRS;
+////bp2            }
+////bp2            if (rentalApplyEquipmentSet.Equipment_Set__r.ES_Status__c != okStatus2) {
+////bp2                checkRS = '澶囧搧set ' + rentalApplyEquipmentSet.Equipment_Set__r.Name + ' 鐨�' + Schema.SObjectType.Equipment_Set__c.fields.ES_Status__c.label + '涓嶆槸 ' + okStatus2 + '锛岀幇鍦ㄦ槸 ' + rentalApplyEquipmentSet.Equipment_Set__r.ES_Status__c + ' 璇风‘璁�';
+////bp2                return checkRS;
+////bp2            }
+////bp2            if (rentalApplyEquipmentSet.Equipment_Set__r.Already_Stock_Out__c == true) {
+////bp2                checkRS = '澶囧搧set ' + rentalApplyEquipmentSet.Equipment_Set__r.Name + ' 娌℃湁涓婃灦锛岃纭';
+////bp2                return checkRS;
+////bp2            }
+////bp2            if (rentalApplyEquipmentSet.ES_Stock_Status__c == '涓嶈兘鍑哄簱') {
+////bp2                checkRS = '澶囧搧set ' + rentalApplyEquipmentSet.Equipment_Set__r.Name + ' 鍦ㄩ绾︽湡闂村涓嶈兘鍑哄簱锛岃纭';
+////bp2                return checkRS;
+////bp2            }
+//            idmap.put(rentalApplyEquipmentSet.Equipment_Set__c, rentalApplyEquipmentSet.Id);
+//        }
+//        mRentalApplys.get('rentalApplys')[0] = rentalApplys;
+//        mRentalApplyEquipmentSets.get('rentalApplyEquipmentSets')[0] = raesList;
+//        mEquipmentSetIdList.get('equipmentSetIdList')[0] = equipmentSetIdList;
+//        mIdmap.get('idmap')[0] = idmap;
+//        return checkRS;
+//    }
+
+//bp2
+//    /**
+//     *@param  : String 澶囧搧鍊熷嚭鐢宠ID
+//     *@return : String (鎴愬姛: 1銆乷r 閿欒鍐呭)
+//     */
+//    WebService static String reserveCheck(String rentalApplyId) {
+//        //澶囧搧鍊熷嚭鐢宠
+//        List<Rental_Apply__c> rentalApplys = new List<Rental_Apply__c>();
+//        //澶囧搧鐢宠鍊熷嚭鍘嗗彶
+//        List<Rental_Apply_Equipment_Set__c> rentalApplyEquipmentSets = new List<Rental_Apply_Equipment_Set__c>();
+//        List<Id> equipmentSetIdList = new List<Id>();
+//        Map<Id, Id> idmap = new Map<Id,Id>();    // Equipment_Set__c.Id => Rental_Apply_Equipment_Set__c.Id
+
+//        Map<String, List<List<Rental_Apply__c>>> mRentalApplys =
+//                new Map<String, List<List<Rental_Apply__c>>>{'rentalApplys' => new List<List<Rental_Apply__c>>{rentalApplys}};
+//        Map<String, List<List<Rental_Apply_Equipment_Set__c>>> mRentalApplyEquipmentSets =
+//                new Map<String, List<List<Rental_Apply_Equipment_Set__c>>>{'rentalApplyEquipmentSets' => new List<List<Rental_Apply_Equipment_Set__c>>{rentalApplyEquipmentSets}};
+//        Map<String, List<List<Id>>> mEquipmentSetIdList =
+//                new Map<String, List<List<Id>>>{'equipmentSetIdList' => new List<List<Id>>{equipmentSetIdList}};
+//        Map<String, List<Map<Id, Id>>> mIdmap =
+//                new Map<String, List<Map<Id, Id>>>{'idmap' => new List<Map<Id, Id>>{idmap}};
+
+//        String rt1 = RentalApplyWebService.approvalCheck(rentalApplyId);
+//        if (rt1 != '1') {
+//            return rt1;
+//        }
+//        //杩斿洖缁撴灉,1:鎴愬姛銆�
+////        return RentalApplyWebService.privateCheck(rentalApplyId, mRentalApplys, mRentalApplyEquipmentSets, mEquipmentSetIdList, mIdmap);
+//        String rt2 = RentalApplyWebService.privateCheck(rentalApplyId, mRentalApplys, mRentalApplyEquipmentSets, mEquipmentSetIdList, mIdmap);
+//        if (rt2 != '1') {
+//            return rt2;
+//        }
+//        return '1';
+//    }
+
+//bp2
+//    /**
+//     *@param  : String 澶囧搧鍊熷嚭鐢宠ID
+//     *@return : String (鎴愬姛: 1銆乷r 閿欒鍐呭)
+//     */
+//    WebService static String reserve(String rentalApplyId) {
+//        //澶囧搧鍊熷嚭鐢宠
+//        List<Rental_Apply__c> rentalApplys = new List<Rental_Apply__c>();
+//        //澶囧搧鐢宠鍊熷嚭鍘嗗彶
+//        List<Rental_Apply_Equipment_Set__c> rentalApplyEquipmentSets = new List<Rental_Apply_Equipment_Set__c>();
+//        List<Id> equipmentSetIdList = new List<Id>();
+//        Map<Id, Id> idmap = new Map<Id,Id>();    // Equipment_Set__c.Id => Rental_Apply_Equipment_Set__c.Id
+
+//        Map<String, List<List<Rental_Apply__c>>> mRentalApplys =
+//                new Map<String, List<List<Rental_Apply__c>>>{'rentalApplys' => new List<List<Rental_Apply__c>>{rentalApplys}};
+//        Map<String, List<List<Rental_Apply_Equipment_Set__c>>> mRentalApplyEquipmentSets =
+//                new Map<String, List<List<Rental_Apply_Equipment_Set__c>>>{'rentalApplyEquipmentSets' => new List<List<Rental_Apply_Equipment_Set__c>>{rentalApplyEquipmentSets}};
+//        Map<String, List<List<Id>>> mEquipmentSetIdList =
+//                new Map<String, List<List<Id>>>{'equipmentSetIdList' => new List<List<Id>>{equipmentSetIdList}};
+//        Map<String, List<Map<Id, Id>>> mIdmap =
+//                new Map<String, List<Map<Id, Id>>>{'idmap' => new List<Map<Id, Id>>{idmap}};
+
+//        //杩斿洖缁撴灉,1:鎴愬姛銆�
+//        String checkRS = RentalApplyWebService.privateCheck(rentalApplyId, mRentalApplys, mRentalApplyEquipmentSets, mEquipmentSetIdList, mIdmap);
+//        if (checkRS != '1') return checkRS;
+//        rentalApplys = mRentalApplys.get('rentalApplys')[0];
+//        rentalApplyEquipmentSets = mRentalApplyEquipmentSets.get('rentalApplyEquipmentSets')[0];
+//        equipmentSetIdList = mEquipmentSetIdList.get('equipmentSetIdList')[0];
+//        idmap = mIdmap.get('idmap')[0];
+
+//        Rental_Apply__c rentalApply = rentalApplys[0];
+
+//        //澶囧搧Set
+//        List<Equipment_Set__c> equipmentSetUpdateList = new List<Equipment_Set__c>();
+//        //澶囧搧Set鏄庣粏
+//        List<Equipment_Set_Detail__c> equipmentSetDetailList = new List<Equipment_Set_Detail__c>();
+//        List<Equipment_Set_Detail__c> equipmentSetDetailList2 = new List<Equipment_Set_Detail__c>();
+//        //澶囧搧鐢宠鍊熷嚭鏄庣粏鍘嗗彶
+//        List<Rental_Apply_Equipment_Set_Detail__c> rentalApplyEquipmentSetDetailList = new List<Rental_Apply_Equipment_Set_Detail__c>();
+//        for (Rental_Apply_Equipment_Set__c rentalApplyEquipmentSet : rentalApplyEquipmentSets) {
+//            // 宸插仛鍑哄簱鎸囩ずflag鈬掑墠鍥炪伄鐢宠珛銇伨銇犵祩銈忋仯銇︺仾銇勨噿鍑哄簱銇椼仾銇�
+//            if (rentalApplyEquipmentSet.Equipment_Set__r.Already_Stock_Out__c == false) {
+//                //鏇存柊澶囧搧Set
+//                Equipment_Set__c equipmentSet = new Equipment_Set__c(
+//                    Id = rentalApplyEquipmentSet.Equipment_Set__c,
+//                    Last_Reserve_Rental_Apply_Equipment_Set__c = rentalApplyEquipmentSet.Id,
+//                    Pre_Reserve_Rental_Apply_Equipment_Set__c = rentalApplyEquipmentSet.Equipment_Set__r.Last_Reserve_Rental_Apply_Equipment_Set__c,
+//                    StockDown__c = false,
+//                    StockDown_time__c = null,
+//                    Shipment_request_time__c = System.now(),            //鍑哄簱鎸囩ず鏃堕棿
+//                    Shippment_loaner_time__c = null,            //澶囧搧涓績鍑哄簱鏃堕棿
+//                    Forecast_arrival_day__c = null,             //棰勮鍒拌揣鏃�
+//                    //Loaner_received_day__c = null,              //鐜板満绛炬敹鏃�
+//                    Return_wh_chenk_staff__c = null,
+//                    Request_asset_extend_time__c = null,        //寤舵湡鐢宠鏃堕棿
+//                    asset_extend_approval_time__c = null,       //寤舵湡鐢宠鎵瑰噯鏃堕棿
+//                    //Asset_return_day__c = null,                 //鐗╂祦鎻愯揣鏃�
+//                    Received_loaner_time__c = null,             //澶囧搧涓績鍥炴敹鏃堕棿
+//                    delivery_company__c = null,
+//                    Fedex_number__c = null,
+//                    Distributor_method__c = null,
+//                    Return_to_wh_staff__c = null,
+//                    Return_delivery_company__c = null,
+//                    Return_Fedex_number__c = null,
+//                    Return_Distributor_method__c = null,
+//                    Received_confirmation_staff__c = null,
+//                    Customer_install_explanation_sign__c = null, //鏄惁鍥炴敹CDS纭鍗�
+//                    Send_to_return_email__c = false, //鍙戦�佸洖鏀剁粨鏋滃弽棣堥偖浠�
+//                    Return_comment_anoucment__c = null, //鍙戦�佸洖鏀剁粨鏋滃弽棣堝唴瀹�(NG鐞嗙敱鍜屾瑺鍝佹儏鍐�)
+////bp2                    CDS_complete__c = false,
+//                    Arrival_in_wh__c = false,
+//                    Arrival_wh_time2__c = null,
+//                    Already_Stock_Out__c = true,
+
+//                    Repair_Sum_Update__c = 0
+//                );
+//                //鏇存柊澶囧搧Set
+//                equipmentSetUpdateList.add(equipmentSet);
+//            }
+//        }
+
+//        //鍊熷嚭璁惧鏈鸿韩鍙风爜
+//        Map<String, String> assetSerialNumberMap = new Map<String, String>();
+//        //澶囧搧Set鏄庣粏
+//        Equipment_Set_Detail__c[] equipmentSetDetails = [select Equipment_Set__c,Asset__c,Asset__r.SerialNumber,
+//                                            Check_lost_Item__c,Pre_disinfection__c,Water_leacage_check__c,
+//                                            Inspection_result_after__c,Arrival_in_wh__c,
+//                                            Lost_item_check_staff__c,CDS_staff__c,Inspection_staff_After__c,
+//                                            Return_wh_chenk_staff__c,Pre_inspection_time__c,Lost_item_check_time__c,
+//                                            After_Inspection_time__c,Arrival_wh_time__c,
+//                                            Inspection_result__c,Inspection_staff__c,Last_Reserve_RAES_Detail__c,
+//                                            Equipment_Set__r.Already_Stock_Out__c
+////bp2            , CDS_complete__c, CDS_complete_time__c
+//                                            from Equipment_Set_Detail__c
+//                                            where Equipment_Set__c in :equipmentSetIdList and Select_rental__c = true];
+        
+//        for (Equipment_Set_Detail__c equipmentSetDetail : equipmentSetDetails) {
+//            // 宸插仛鍑哄簱鎸囩ずflag鈬掑墠鍥炪伄鐢宠珛銇伨銇犵祩銈忋仯銇︺仾銇勨噿鍑哄簱銇椼仾銇�
+//            if (equipmentSetDetail.Equipment_Set__r.Already_Stock_Out__c == false) {
+//                //鎻掑叆澶囧搧鐢宠鍊熷嚭鏄庣粏鍘嗗彶
+//                Rental_Apply_Equipment_Set_Detail__c rentalApplyEquipmentSetDetail = new Rental_Apply_Equipment_Set_Detail__c();
+//                rentalApplyEquipmentSetDetail.Rental_Apply__c = rentalApply.Id;//澶囧搧鍊熷嚭鐢宠
+//                rentalApplyEquipmentSetDetail.Rental_Apply_Equipment_Set__c = idmap.get(equipmentSetDetail.Equipment_Set__c);//澶囧搧Set鍊熷嚭鍘嗗彶
+//                rentalApplyEquipmentSetDetail.Equipment_Set__c = equipmentSetDetail.Equipment_Set__c;//澶囧搧Set
+//                rentalApplyEquipmentSetDetail.Asset__c = equipmentSetDetail.Asset__c;//淇濇湁璁惧
+//                //鎻掑叆澶囧搧鐢宠鍊熷嚭鏄庣粏鍘嗗彶
+//                rentalApplyEquipmentSetDetailList.add(rentalApplyEquipmentSetDetail);
+                
+//                //鏇存柊澶囧搧Set鏄庣粏
+//                equipmentSetDetail.Check_lost_Item__c = null;//娆犲搧纭缁撴灉
+//                equipmentSetDetail.Lost_item_giveup__c = false;
+//                equipmentSetDetail.Pre_disinfection__c = null;//娓呮礂鍓�
+//                equipmentSetDetail.Water_leacage_check__c = null;//娴嬫紡妫�鏌ョ粨鏋�
+//                equipmentSetDetail.Inspection_result_after__c = null;//鍥炴敹鍚�-妫�娴嬬粨鏋�
+//                equipmentSetDetail.Arrival_in_wh__c = false;//鍥炲簱纭
+//                equipmentSetDetail.Lost_item_check_staff__c = null;//娆犲搧纭鑰�
+//                equipmentSetDetail.CDS_staff__c = null;//娑堟瘨浜哄憳
+//                equipmentSetDetail.Inspection_staff_After__c = null;//鍥炴敹鍚�-妫�娴嬩汉鍛�
+//                equipmentSetDetail.Return_wh_chenk_staff__c = null;//鍥炲簱纭鑰�
+//                equipmentSetDetail.Inspection_result__c = null;//鍙戣揣鍓�-妫�娴嬬粨鏋�
+//                equipmentSetDetail.Inspection_staff__c = null;//鍙戣揣鍓�-妫�娴嬩汉鍛�
+                
+//                equipmentSetDetail.Pre_inspection_time__c = null;//澶囧搧Set鐢�,鍙戣揣鍓�-妫�娴嬪悎鏍兼椂闂�
+//                equipmentSetDetail.Lost_item_check_time__c = null;//澶囧搧Set鐢�,娆犲搧纭鏃堕棿
+////bp2                equipmentSetDetail.CDS_complete_time__c = null;//澶囧搧Set鐢�,CDS瀹屾瘯鏃堕棿
+//                equipmentSetDetail.After_Inspection_time__c = null;//澶囧搧Set鐢�,鍥炴敹鍚�-妫�娴嬪畬姣曟椂闂�
+//                equipmentSetDetail.Arrival_wh_time__c = null;//澶囧搧Set鐢�,鍥炲簱纭瀹屾瘯鏃堕棿
+
+//                equipmentSetDetail.Inspection_result_after_ng__c = null;//鍥炴敹鍚�-妫�娴婲G鍖哄垎
+//                equipmentSetDetail.Inspection_result_ng__c = null;//鍙戣揣鍓�-妫�娴婲G鍖哄垎
+////bp2                equipmentSetDetail.CDS_complete__c = false;//CDS瀹屾瘯
+
+//                //鏇存柊澶囧搧Set鏄庣粏
+//                equipmentSetDetailList.add(equipmentSetDetail);
+//                //鍊熷嚭璁惧鏈鸿韩鍙风爜
+//                if (String.isNotBlank(equipmentSetDetail.Asset__r.SerialNumber)) {
+//                    if (assetSerialNumberMap.containsKey(equipmentSetDetail.Equipment_Set__c) == false) {
+//                        assetSerialNumberMap.put(equipmentSetDetail.Equipment_Set__c, ',' + equipmentSetDetail.Asset__r.SerialNumber + ',');
+//                    } else {
+//                        String tmp = assetSerialNumberMap.get(equipmentSetDetail.Equipment_Set__c);
+//                        tmp += equipmentSetDetail.Asset__r.SerialNumber + ',';
+//                        assetSerialNumberMap.put(equipmentSetDetail.Equipment_Set__c, tmp);
+//                    }
+//                }
+//            }
+//        }
+
+//        // TODO liang 锛戙仱sql銇伨銇ㄣ倎銇︺亸銇犮仌銇�
+//        Equipment_Set_Detail__c[] equipmentSetDetails2 = [select Id, Last_Reserve_RAES_Detail__c
+////bp2                ,CDS_complete__c
+//                                            from Equipment_Set_Detail__c
+//                                            where Equipment_Set__c in :equipmentSetIdList and Select_rental__c = false];
+//        for (Equipment_Set_Detail__c equipmentSetDetail : equipmentSetDetails2) {
+//            equipmentSetDetail.Pre_Reserve_RAES_Detail__c = equipmentSetDetail.Last_Reserve_RAES_Detail__c;
+//            equipmentSetDetail.Last_Reserve_RAES_Detail__c = null;
+////bp2            equipmentSetDetail.CDS_complete__c = false;//CDS瀹屾瘯
+//            equipmentSetDetailList2.add(equipmentSetDetail);
+//        }
+        
+//        //鏇存柊鍊熷嚭璁惧鏈鸿韩鍙风爜
+//        List<Rental_Apply_Equipment_Set__c> rentalApplyEquipmentSetUpdateList = new List<Rental_Apply_Equipment_Set__c>();
+//        for (Rental_Apply_Equipment_Set__c rentalApplyEquipmentSet : rentalApplyEquipmentSets) {
+//            if (assetSerialNumberMap.containsKey(rentalApplyEquipmentSet.Equipment_Set__c)) {
+//                rentalApplyEquipmentSet.Rental_Asset_SerialNumber__c = assetSerialNumberMap.get(rentalApplyEquipmentSet.Equipment_Set__c);
+//              // xiongyl-start
+//            }           
+//             rentalApplyEquipmentSet.Loaner_name_text__c =rentalApplyEquipmentSet.Equipment_Set__r.Loaner_name__c; //澶囧搧鍚嶇О
+//             rentalApplyEquipmentSet.Loaner_code_text__c = rentalApplyEquipmentSet.Equipment_Set__r.Loaner_code__c; //鍌欏搧鍨嬬暘
+//             rentalApplyEquipmentSet.Salesdepartment_text__c = rentalApplyEquipmentSet.Equipment_Set__r.Salesdepartment__c; // 鎵�鍦ㄥ湴鍖�(鏈儴)                
+//             rentalApplyEquipmentSet.Salesprovince_text__c = rentalApplyEquipmentSet.Equipment_Set__r.SalesProvince__c; //鎵�鍦ㄥ湴鍖�(鐪�)
+//             rentalApplyEquipmentSet.Equipment_Type_text__c = rentalApplyEquipmentSet.Equipment_Set__r.Equipment_Type__c; //鍒嗙被 
+//             rentalApplyEquipmentSet.Equipment_Set_Borrowed__c = rentalApplyEquipmentSet.Equipment_Set__r.Name;//澶囧搧set
+//             rentalApplyEquipmentSet.Product_Class_Bor__c = rentalApplyEquipmentSet.Equipment_Set__r.Product_category__c;
+//             rentalApplyEquipmentSet.SerialNumber_text__c = rentalApplyEquipmentSet.Equipment_Set__r.SerialNumber__c;
+//             rentalApplyEquipmentSetUpdateList.add(rentalApplyEquipmentSet);
+//             // xiongyl-end
+//        }
+
+//        Savepoint sp = Database.setSavepoint();
+//        try {
+//            if (equipmentSetUpdateList.size() > 0) {
+//                update equipmentSetUpdateList;
+//            }
+//            if (rentalApplyEquipmentSetDetailList.size() > 0) {
+//                insert rentalApplyEquipmentSetDetailList;
+//            }
+//            if (equipmentSetDetailList.size() > 0) {
+//                for (Integer i=0; i<equipmentSetDetailList.size(); i++) {
+//                    equipmentSetDetailList[i].Pre_Reserve_RAES_Detail__c = equipmentSetDetailList[i].Last_Reserve_RAES_Detail__c;
+//                    equipmentSetDetailList[i].Last_Reserve_RAES_Detail__c = rentalApplyEquipmentSetDetailList[i].Id;
+//                }
+//                update equipmentSetDetailList;
+//            }
+//            if (equipmentSetDetailList2.size() > 0) {
+//                update equipmentSetDetailList2;
+//            }
+//            if (rentalApplyEquipmentSetUpdateList.size() > 0) {
+//                update rentalApplyEquipmentSetUpdateList;
+//            }
+//            eSetRefreshStatus(equipmentSetIdList);
+//        } catch (System.Exception e) {
+//            Database.rollback(sp);
+//            return e.getMessage();
+//        }
+//        //杩斿洖缁撴灉
+//        return checkRS;
+//    }
+    
+    // 澶囧搧鍊熷嚭鏃堕棿check
+    @AuraEnabled
+    WebService static String approvalCheck(String rentalApplyId) {
+        // check缁撴灉
+        String returnStr = '';
+        
+        //1388 yc 20211021 璺ㄥ尯鍩熷垎閰嶄笉鑳藉嚭搴�  start
+        String rasdid = '';
+        system.debug(rentalApplyId+'==');
+        if(String.isNotBlank(rentalApplyId) && rentalApplyId.indexOf(';') >= 0){//璇存槑鏄粠涓�瑙堜笂瑙﹀彂鐨�
+           rasdid = rentalApplyId.subString(rentalApplyId.indexOf(';') + 1);
+           rentalApplyId = rentalApplyId.subString(0, rentalApplyId.indexOf(';'));
+        }
+        //1388 yc 20211021 璺ㄥ尯鍩熷垎閰嶄笉鑳藉嚭搴�  end
+        //澶囧搧鍊熷嚭鐢宠
+        Rental_Apply__c[] rentalApply = [select Id,repair__r.Repair_Final_Inspection_Date__c,Bollow_Date__c,repair__r.Return_Without_Repair_Date__c,
+                                        CreatedDate,Rental_Apply_Equipment_Set_Cnt__c,Prepare_Day__c,Cross_Region_Assign__c,
+                                        demo_purpose2__c,Follow_UP_Opp__r.Shipping_Finished_Day_Func__c,next_action__c,QIS_number__r.ReplaceDeliveryDate__c
+                                        from Rental_Apply__c 
+                                        where Id = :rentalApplyId];
+        if (rentalApply.size() == 0) {
+            returnStr = '娌℃湁澶囧搧鍊熷嚭鐢宠锛岃纭銆�';
+            return returnStr;
+        }
+        Rental_Apply__c ra = rentalApply[0];
+        if (ra.Rental_Apply_Equipment_Set_Cnt__c <= 0) {
+            returnStr = '娌℃湁鍊熷嚭澶囧搧set涓�瑙堬紝璇风‘璁ゃ��';
+            return returnStr;
+        }
+        //1822 yc 20211111 start
+        if(ra.demo_purpose2__c=='宸茶喘寰呰揣' && ra.Follow_UP_Opp__r.Shipping_Finished_Day_Func__c!= null){
+            returnStr = '宸茶喘寰呰揣鐩殑锛屾柊鍝佸凡鏈夊彂璐ф棩锛屼笉鍙嚭搴撴寚绀�';
+            return returnStr;
+        }
+        if(ra.demo_purpose2__c=='绱㈣禂QIS' && ra.next_action__c=='鏃犲伩鏇存崲' && ra.QIS_number__r.ReplaceDeliveryDate__c!= null){
+            returnStr = '绱㈣禂QIS鐩殑锛孮IS宸叉湁鏂板搧鍙戣揣鏃ワ紝涓嶅彲鍑哄簱鎸囩ず';
+            return returnStr;
+       }
+        //1822 yc 20211111 end
+
+//*************************Insert 20160826 SWAG-AD59Z6 瓒欏境鑺� Start*************************//
+        if(Ra.repair__r.Repair_Final_Inspection_Date__c != null) {
+            return '淇悊鏈�缁堟娴嬫棩涓嶄负绌猴紝涓嶈兘鍋氬嚭搴撴寚绀�';
+        }
+        if(Ra.repair__c!=null&&Ra.repair__r.Return_Without_Repair_Date__c != null) {
+            return '鏈慨鐞嗗綊杩樻棩涓嶄负绌猴紝涓嶈兘鍋氬嚭搴撴寚绀�';
+        }
+//*************************Insert 20160826 SWAG-AD59Z6 瓒欏境鑺� End***************************//
+
+        //1388 yc 20211021 璺ㄥ尯鍩熷垎閰嶄笉鑳藉嚭搴� start
+        if(String.isNotBlank(ra.Cross_Region_Assign__c)){
+            String soql = 'select Id, Name,Rental_Apply__c,Internal_asset_location_before__c';
+                   soql +=' from Rental_Apply_Equipment_Set_Detail__c';
+                   soql +=' where Rental_Apply__c = \'' + ra.Id +'\'';
+                   soql +=' and Internal_asset_location_before__c !=null and Internal_asset_location_before__c != \'' + ra.Cross_Region_Assign__c+ '\'';
+            
+            if(String.isNotBlank(rasdid)){
+                   soql +=' and Rental_Apply_Equipment_Set__c = :rasdid';            
+              }
+            List<Rental_Apply_Equipment_Set_Detail__c> raesd = Database.query(soql);
+            if(raesd.size()>0){
+                returnStr = '鍒嗛厤鐨勫鍝佷笉鏄偍鎵�灞炲鍝佷腑蹇冪殑澶囧搧锛屼笉鑳藉仛鍑哄簱鎸囩ず'; 
+                return returnStr;
+            }
+            
+        }
+        //1388 yc 20211021 璺ㄥ尯鍩熷垎閰嶄笉鑳藉嚭搴� end
+        // 20220211 ljh add 澶囧搧FY23璇鹃01 start
+        // AggregateResult[] resultsRas = [SELECT Rental_Start_Date__c,count(Id) cnt
+        //                              FROM Rental_Apply_Equipment_Set__c
+        //                              WHERE Rental_Apply__c = :rentalApplyId 
+        //                              AND Cancel_Select__c = false
+        //                              group by Rental_Start_Date__c];
+        // If(resultsRas.size() > 1){
+        //  returnStr = '鎵�鏈変竴瑙堝鍝侀璁″嚭璐ф棩搴斾竴鑷达紝涓嶄竴鑷翠笉鑳藉仛鍑哄簱鎸囩ず'; 
+        //     return returnStr;
+        // }
+        // 20220211 ljh add 澶囧搧FY23璇鹃01 end
+
+//bp2        // 澶囧搧鍊熷嚭鍘嗗彶鍙栧緱
+//        List<String> equipmentSetList = new List<String>();
+//        Rental_Apply_Equipment_Set__c[] raes = [
+//            select Id, Name, Equipment_Set__c, Equipment_Set__r.Name, Rental_Start_Date__c, Rental_End_Date__c, Rental_Apply__c 
+//              from Rental_Apply_Equipment_Set__c 
+//             where Rental_Apply__c = :rentalApplyId and Cancel_Select__c = false];
+//        // 鏃ュ巻鑼冨洿锛屾渶灏忕殑鍊熷嚭寮�濮嬫棩鍒版渶澶х殑鍊熷嚭缁堜簡鏃�
+//        Date startDate = Date.today();
+//        Date endDate = Date.today();
+//        for (Rental_Apply_Equipment_Set__c r : raes) {
+//            equipmentSetList.add(r.Equipment_Set__c);
+//            if (r.Rental_Start_Date__c != null && r.Rental_Start_Date__c < startDate) {
+//                startDate = r.Rental_Start_Date__c;
+//            }
+//            if (r.Rental_End_Date__c != null && r.Rental_End_Date__c > endDate) {
+//                endDate = r.Rental_End_Date__c;
+//            }
+//        }
+//        Integer prepareDay = ra.Prepare_Day__c == null ? Integer.valueOf(System.Label.EquipmentRentalPrepare) : ra.Prepare_Day__c.intValue();
+//        Date minDate = getWD_addday(startDate, -1 * prepareDay);
+//        Date maxDate = getWD_addday(endDate, prepareDay);
+//        // 鍏朵粬澶囧搧鍊熷嚭鐢宠鍘嗗彶
+//        Rental_Apply_Equipment_Set__c[] others = [
+//                    select Id, Name, Rental_Start_Date__c, Rental_End_Date__c, Equipment_Set__c, Rental_Apply__r.Status__c ,Rental_Apply__r.Prepare_Day__c 
+//                      from Rental_Apply_Equipment_Set__c
+//                     where Rental_Apply__c != :rentalApplyId
+//                       and Equipment_Set__c in :equipmentSetList
+//                       and Request_Status__c != '鍙栨秷'
+//                       and Request_Status__c != '鍒犻櫎'
+//                       and Cancel_Select__c = false
+//                       and ((Rental_Start_Date__c >= :minDate and Rental_Start_Date__c <= :maxDate)
+//                            or (Rental_End_Date__c >= :minDate and Rental_End_Date__c <= :maxDate)
+//                            or (Rental_Start_Date__c <= :startDate and Rental_End_Date__c >= :endDate))];
+        
+//        Map<String, List<Rental_Apply_Equipment_Set__c>> othersMap = new Map<String,List<Rental_Apply_Equipment_Set__c>>();
+//        for (Rental_Apply_Equipment_Set__c other : others) {
+//            if (othersMap.containsKey(other.Equipment_Set__c)) {
+//                othersMap.get(other.Equipment_Set__c).add(other);
+//            } else {
+//                List<Rental_Apply_Equipment_Set__c> l = new List<Rental_Apply_Equipment_Set__c>();
+//                l.add(other);
+//                othersMap.put(other.Equipment_Set__c, l);
+//            }
+//        }
+        
+//        for (Rental_Apply_Equipment_Set__c r : raes) {
+            
+//            List<Rental_Apply_Equipment_Set__c> other = othersMap.get(r.Equipment_Set__c);
+            
+//            Map<Date, Map<String, String>> dateMap= new Map<Date, Map<String, String>>();
+//            if (other != null) {
+//                Date sdate = startDate;
+//                Date edate = endDate;
+//                for (Rental_Apply_Equipment_Set__c o : other) {
+//                    if (o.Rental_Start_Date__c != null && (sdate == null || o.Rental_Start_Date__c < sdate)) {
+//                        sdate = o.Rental_Start_Date__c;
+//                    }
+//                    if (o.Rental_End_Date__c != null && (edate == null || o.Rental_End_Date__c > edate)) {
+//                        edate = o.Rental_End_Date__c;
+//                    }
+//                }
+//                if (sdate != null && edate != null) {
+//                    RentalApplyWebService raws = new RentalApplyWebService();
+//                    dateMap = raws.getDateMap(sdate, edate, prepareDay);
+//                }
+//            }
+            
+//            if (r.Rental_Start_Date__c == null && r.Rental_End_Date__c == null) {
+//                // 娓呯┖璇ュ�熷嚭鍘嗗彶鐨勫嚭搴撳拰鍥炴敹鏃堕棿
+//            } else if (other == null || other.size() == 0) {
+//                // 涓庡叾浠栧�熷嚭鍘嗗彶娌℃湁鍐茬獊
+//            } else {
+//                Date fromDate = r.Rental_Start_Date__c;
+//                Date toDate = r.Rental_End_Date__c;
+//                for (Rental_Apply_Equipment_Set__c o : other) {
+//                    if (o.Rental_Apply__r.Status__c != '鑽夋涓�' && o.Rental_Apply__r.Status__c != '鐢宠涓�' && o.Rental_Apply__r.Status__c != null) {
+//                        Date startD = o.Rental_Start_Date__c;
+//                        Date endD = o.Rental_End_Date__c;
+//                        Integer prepare = prepareDay; //>= o.Rental_Apply__r.Prepare_Day__c || o.Rental_Apply__r.Prepare_Day__c == null ? prepareDay : o.Rental_Apply__r.Prepare_Day__c.intValue();
+//                        if ((dateMap.containsKey(fromDate) && Date.valueOf(dateMap.get(fromDate).get('Next')) > startD && dateMap.containsKey(endD) && fromDate < Date.valueOf(dateMap.get(endD).get('Next'))) ||
+//                            (dateMap.containsKey(toDate) && Date.valueOf(dateMap.get(toDate).get('Next')) > startD && dateMap.containsKey(endD) && toDate < Date.valueOf(dateMap.get(endD).get('Next'))) ||
+//                            (dateMap.containsKey(fromDate) && Date.valueOf(dateMap.get(fromDate).get('Next')) <= startD && dateMap.containsKey(endD) && toDate >= Date.valueOf(dateMap.get(endD).get('Next')))) {
+//                            returnStr = '澶囧搧' + r.Equipment_Set__r.Name + '鐨勫�熷嚭鏃ヤ笌澶囧搧鍊熷嚭鍘嗗彶' + o.Name + '鏈夊啿绐侊紝璇风‘璁ゃ��';
+//                            return returnStr;
+//                        }
+//                    }
+//                }
+//            }
+//        }
+        return '1';
+    }
+
+    // 寤舵湡瀹℃壒Check
+    WebService static String extension_approval_processCheck(String rentalApplyId) {
+        try {
+            List<Rental_Apply__c> raList = [SELECT Id,Name
+                       , Demo_purpose1__c
+                       , Demo_purpose2__c
+                       , Loaner_received_ng_num__c
+                       , ExtensionApprovalTime_Initial__c
+                       , ExtensionApplicationTime_Final__c
+                       , ExtensionApprovalTime_Final__c
+                       , NewRepair__c
+                       , NewRepair__r.Agreed_Date__c
+                       , NewRepair__r.Status__c
+                       , NewRepair__r.ReRepairObject_F__c
+                       , NewRepair__r.Repair_Shipped_Date__c
+                       , AgreementBorrowingExtensionDate__c
+                       , next_action__c
+                       , RC_Ordered_Date__c
+                       , Bollow_Date_Add_10_WD__c
+                       , Root_Rental_Apply__c
+                       , Assign_Person__c
+                       , Return_dadeline_final__c
+                       , RA_Status__c
+                       , ExtensionApplicationTime_Initial__c
+                       , RecordType.DeveloperName
+                       , RecordType.id
+                       , ExtensionStatus__c
+                    FROM Rental_Apply__c
+                    WHERE Id = :rentalApplyId];
+            if (raList.size() == 0) {
+                return '娌℃湁澶囧搧鍊熷嚭鐢宠锛岃纭銆�';
+            }
+            //add       wangweipeng            2021/11/26                   start
+            /*List<Rental_Apply_Equipment_Set__c> raesList = RentalApplyTriggerHandler.getCan_Extend_RequestList(raList[0],'1');
+            return '1';*/
+            String ErrorMessageStr = unifyGetRentalApply(raList[0]);
+            //add       wangweipeng            2021/11/26                   end
+            return ErrorMessageStr;
+        }
+        catch(Exception e) {
+            return e.getMessage();
+        }
+        
+    }
+
+    //add       wangweipeng            2021/11/26                   start
+    /**
+     * @param  rentalApplyId 澶囧搧id
+     * @return               澶囧搧閰嶅鏁版嵁
+     *
+     * 寤舵湡鏁翠綋閫昏緫锛�
+     *     1锛氳瘯鐢ㄧ洰鐨�2涓嶄负锛氭湁璇环鍜屾棤璇环锛屽仛鐗规畩澶勭悊
+     *     2锛氬叾浠栨儏鍐碉細閫昏緫涓嶅彉
+     *   涓婇潰绗竴涓潯浠舵弧瓒筹細
+     *       1锛氫粠鍘熷崟鐐瑰嚮寤舵湡鐢宠鎸夐挳锛屾病鏈夊垎鍓插崟
+     *       2锛氫粠鍘熷崟鐐瑰嚮寤舵湡鐢宠鎸夐挳锛屾湁鍒嗗壊鍗�
+     *       3锛氫粠鍗曠偣鍑诲欢鏈熺敵璇锋寜閽�
+     *
+     *      绗竴绉嶆儏鍐碉細鎸夌収鍘熸潵鐨勯�昏緫璧帮紝涓嶉渶瑕佸仛鐗规畩澶勭悊
+     *      绗簩绉嶆儏鍐碉細
+     *          锛�1锛夛細璁板綍绫诲瀷涓猴細澶囧搧涓績锛屽垽鏂垎閰嶄汉鏄惁涓虹┖锛屽姙浜嬪鍒嗛厤浜轰笉鍙兘涓虹┖
+     *          锛�2锛夛細鑾峰彇鍘熷崟鍜屽師鍗曚笅鎵�鏈夌殑鍒嗗崟锛屽洜涓烘壒閲忓欢鏈熶笉鍏夋煡鐪嬭嚜宸辩敵璇峰崟鎯呭喌锛屽鏋滄槸涓诲崟杩涙潵鐨勶紝杩橀渶瑕佹煡鐪嬪綋鍓嶅崟瀛愶紝鍜屼粬涓嬮潰鐨勬墍鏈変粠鍗�
+     *          锛�2锛夛細璧颁竴涓柟娉曪紝杩欐槸涓�涓欢鏈熼�氱敤鐨勬柟娉曪紝鐢ㄤ簬鍒ゆ柇姝ゆ寤舵湡鐨勭敵璇峰崟鏄惁鏈夊彲浠ュ欢鏈熺殑涓�瑙堬紝浼氬湪涓嬮潰鍏蜂綋浠嬬粛
+     *          锛�3锛夛細璧颁笂闈㈤�氱敤鐨勬柟娉曪紝娌℃湁鑾峰彇鍒板彲浠ュ欢鏈熺殑涓�瑙堬紝閭d箞鍋氭彁绀猴紝涓嶈兘寤舵湡
+     *          锛�4锛夛細璺宠浆椤甸潰涓猴細姝ゆ涓烘壒閲忓欢鏈熻嚜瀹氫箟寮�鍙戠殑椤甸潰
+     *      绗笁绉嶆儏鍐碉細
+     *          锛�1锛夛細濡傛灉鏄粠鍗曞欢鏈燂紝閭d箞闇�瑕佹煡鐪嬫鍗曪紝姝ゅ崟鐨勫師鍗曪紝姝ゅ崟鍘熷崟涓嬫墍鏈夌殑浠庡崟鏄惁婊¤冻寤舵湡鏉′欢
+     *          锛�2锛夛細浠ヤ笂鐨勫崟瀛愬繀椤绘弧瓒筹細宸插嚭搴撶殑--宸插洖鏀讹紙涓嶅惈锛変箣闂寸姸鎬侊紝涓旀渶鏂伴瀹氬綊杩樻棩鈮� 浠婂ぉ銆�
+     *          锛�3锛夛細璧颁竴涓柟娉曪紝杩欐槸涓�涓欢鏈熼�氱敤鐨勬柟娉曪紝鐢ㄤ簬鍒ゆ柇姝ゆ寤舵湡鐨勭敵璇峰崟鏄惁鏈夊彲浠ュ欢鏈熺殑涓�瑙堬紝浼氬湪涓嬮潰鍏蜂綋浠嬬粛
+     *          锛�4锛夛細鐢变簬閫氱敤鐨勬柟娉曚細杩斿洖鎵�鏈夌敵璇峰崟鍙欢鏈熺殑涓�瑙堬紝鎵�浠ラ渶瑕佸垽鏂鍗曟槸鍚︽湁鍙互寤舵湡鐨勪竴瑙�
+     *          锛�5锛夛細鐢变簬閫氱敤鐨勬柟娉曚細璺宠繃 ok骞朵笖鍥炲瘎鏃堕棿涓嶄负绌虹殑涓�瑙堬紝鎵�浠ユ鏃跺垽鏂繖涓潯浠讹紝婊¤冻灏变笉鑳藉欢鏈�
+     *          锛�6锛夛細璺宠浆椤甸潰涓哄師鏉ュ欢鏈熷紑鍙戠殑鑷畾涔夐〉闈�
+     *
+     *     閫氱敤鏄惁鍙互寤舵湡鐨勬柟娉曪細锛堣瘯鐢紙鏈夎浠凤級銆佽瘯鐢紙鏃犺浠凤級锛�
+     *         锛�1锛夛細姝ゆ柟娉曞弬鏁颁负list锛屽鏋滆秴杩�1鏉℃暟鎹紝榛樿涓鸿蛋鎵归噺寤舵湡鐨勬潯浠�
+     *         锛�2锛夛細鐢宠鍗曪細濡傛灉size澶т簬1锛岃烦杩囦竴浜涢獙璇侊細鏈畬鎴愬埌璐х‘璁や笉楠岃瘉鍜屽欢鏈熸壒鍑嗘椂闂�(鏈�鍒�)涓嶈兘寤舵湡
+     *         锛�3锛夛細涓�瑙堬細濡傛灉size澶т簬1锛宱k骞朵笖鍥炲瘎鏃堕棿涓嶄负绌虹殑涓�瑙堜笉楠岃瘉
+     *          
+     */
+    public static String unifyGetRentalApply(Rental_Apply__c rentalApply){
+        Rental_Apply__c rac = rentalApply;
+        //濡傛灉鐢宠鍗曠殑 浣跨敤鐩�2涓� 鏈夎浠锋垨鏃犺浠风殑,閭d箞闇�瑕佺壒娈婂鐞嗕竴涓�
+        if(rac.Demo_purpose1__c == '浜у搧璇曠敤' && (rac.demo_purpose2__c == '璇曠敤锛堟棤璇环锛�' || rac.demo_purpose2__c == '璇曠敤锛堟湁璇环锛�')){
+            if(rac.ExtensionStatus__c == '宸叉壒鍑�'){
+                return '浜у搧璇曠敤鐨勭敵璇蜂笉鑳芥彁浜ょ浜屾寤舵湡鐢宠銆�';
+            }else{
+                return muchRentalApply(rac);
+            }
+        }else{
+            //鍔炰簨澶勭洰鍓嶅彧鑳藉欢鏈熸湁璇环鎴栨棤璇环
+            if(rac.RecordType.DeveloperName == 'AgencyRequest'){
+                return '鍔炰簨澶勭敵璇峰崟锛岄潪璇曠敤锛堟棤璇环锛夈�� 璇曠敤锛堟湁璇环锛変笉鍙欢鏈熴��';
+            }else{
+                List<Rental_Apply_Equipment_Set__c> raesList = RentalApplyTriggerHandler.getCan_Extend_RequestList(new List<Rental_Apply__c>{rac});
+                return '1';
+            }
+        }
+    }
+
+    /**
+     * 
+     * @param  rac [寤舵湡鍏ュ彛]
+     * @return     [description]
+     *      
+     * 閫昏緫瑙i噴锛�
+     *     鍘熷崟锛堟病鏈変粠鍗曪級锛氳蛋鍘熸潵鐨勯�昏緫
+     *     浠庡崟锛氬垽鏂浠庡崟鐨勫師鍗曘�佸師鍗曚笅鎵�鏈夌殑浠庡崟鏄惁婊¤冻绗竴鏉★紝骞朵笖褰撳墠浠庡崟蹇呴』鏈変竴鏉℃弧瓒崇浜屾潯鎵嶈兘寤舵湡
+     *     鍘熷崟锛堟湁浠庡崟锛夛細鍒ゆ柇姝ょ敵璇峰崟鍜屽師鍗曚笅鎵�鏈夌殑浠庡崟鏄惁婊¤冻绗竴鏉★紝骞朵笖杩欎簺鐢宠鍗曟渶灏戞湁涓�涓敵璇峰崟婊¤冻绗簩涓潯浠讹紝鎵嶈兘寤舵湡
+     */
+    public static String muchRentalApply(Rental_Apply__c rac){
+        //鑾峰彇鎵�鏈夌殑鐢宠鍗�
+        List<Rental_Apply__c> rentalApplyData =  getAllRentalApply(rac);
+        if(rentalApplyData != null && rentalApplyData.size() > 0){
+            //濡傛灉鍙煡鍒颁竴鏉℃暟鎹紝閭d箞璇佹槑浠栨槸鍘熷崟锛屽苟涓旀病鏈夊垎鍓插崟锛岄偅涔堝氨璧板師鏉ュ欢鏈熺殑閫昏緫
+            if(rentalApplyData.size() == 1){
+                List<Rental_Apply_Equipment_Set__c> raesList = RentalApplyTriggerHandler.getCan_Extend_RequestList(rentalApplyData);
+                return '1';
+            }else{
+                //濡傛灉涓哄鏉★紝璇佹槑浠栨湁浠庡崟鎴栧綋鍓嶈寤舵湡鐨勫崟瀛愭槸浠庡崟锛岄偅涔堝氨闇�瑕佸仛鐗规畩澶勭悊
+                List<Rental_Apply__c> racList = new List<Rental_Apply__c>();
+                //鍒ゆ柇浠栨槸鍘熷崟杩樻槸浠庡崟
+                System.debug('--345----------'+rac.Root_Rental_Apply__c);
+                if(String.isNotBlank(rac.Root_Rental_Apply__c)){
+                    //鍙欢鏈熺殑鐢宠鍗曞簲婊¤冻锛氬凡鍑哄簱鐨�--宸插洖鏀讹紙涓嶅惈锛変箣闂寸姸鎬侊紝涓旀渶鏂伴瀹氬綊杩樻棩鈮� 浠婂ぉ銆�
+                    //褰撳墠鏃ユ湡
+                    Date today = Date.today();
+                    //棰勫畾褰掕繕鏃ヤ笉鑳戒负绌�
+                    if(rac.Return_dadeline_final__c != null){
+                        //鏈�鏂伴瀹氬綊杩樻棩鈮� 浠婂ぉ銆�
+                        if(rac.Return_dadeline_final__c >= today){
+                            //鍙欢鏈熺殑鐢宠鍗曞簲婊¤冻锛氬凡鍑哄簱鐨�--宸插洖鏀讹紙涓嶅惈锛変箣闂寸姸鎬�
+                            if(rac.RA_Status__c == '鐢宠鑰呭凡鏀惰揣' || rac.RA_Status__c == '鍖婚櫌宸茶鏈虹‘璁�' || rac.RA_Status__c == '宸插嚭搴�')
+                            {
+                                //鑳借蛋鍒拌繖閲岋紝璇佹槑寤舵湡鍏ュ彛鐨勭敵璇峰崟涓嶆槸宸茬粡寤惰繃鐨勶紝鎵�鏈夌幇鍦ㄥ垽鏂叾浠栫殑鐢宠鍗曟槸鍚﹀凡缁忓欢鏈燂紝濡傛灉寤惰繃锛岄偅涔堜笉闇�瑕侀獙璇�
+                                //if(rac.ExtensionApplicationTime_Initial__c == null){
+                                    racList = rentalApplyData;
+                                //}
+                            }else{
+                                if(rac.RA_Status__c != '鍙栨秷' && rac.RA_Status__c != '鍒犻櫎'){
+                                    return '鐢宠鍗曪細'+rac.Name+'鐨勭姸鎬佷负銆�'+rac.RA_Status__c+'銆� 涓嶅彲浠ヨ繘琛屽欢鏈熴��';
+                                }
+                            }
+                        }else{
+                            return '鐢宠鍗曪細'+rac.Name+'鐨勬渶鏂伴瀹氬綊杩樻棩灏忎簬褰撳墠鏃堕棿锛屼笉鍙互杩涜寤舵湡銆�';   
+                        }
+                    }else{
+                        return '鐢宠鍗曪細'+rac.Name+' 鐨勯瀹氬綊杩樻棩涓嶈兘涓虹┖銆�';
+                    }
+                }else{
+                    //澶囧搧涓績
+                    if(rac.RecordType.DeveloperName == 'StandardRequest'){
+                        //a. 鍘熷崟涓婂垎閰嶄汉=绌猴紝鐐瑰嚮鍘熷崟涓婄殑銆愬欢鏈熺敵璇枫�戞寜閽椂锛屾彁绀恒�愬師鍗曟湭鍒嗛厤鎴栧凡鍙栨秷锛岃鍦ㄥ垎鍗曚笂鎿嶄綔寤舵湡銆�
+                        //娉細鍘熷崟鏈垎閰嶅凡鍙栨秷鎴栨湭鍒嗛厤鏃讹紝鍘熷崟鍒嗛厤浜轰负绌�
+                        if(String.isBlank(rac.Assign_Person__c)){
+                            return '鍘熷崟鏈垎閰嶆垨宸插彇娑堬紝璇峰湪鍒嗗崟涓婃搷浣滃欢鏈熴��';
+                        }
+                    }
+                    //濡傛灉鏄師鍗曪紝鐩存帴鍒ゆ柇鏄惁婊¤冻绗竴鍜岀浜屾潯锛岀涓夋潯涓嶉渶瑕佺幇鍦ㄥ垽鏂�
+                    racList = rentalApplyData;
+                }
+                if(racList != null && racList.size() > 0){
+                    System.debug('-----------543---'+racList);
+                    //姝ゆ柟娉曚富瑕侀獙璇佺涓�鍜岀浜屼釜鏉′欢
+                    List<Rental_Apply_Equipment_Set__c> raesList = RentalApplyTriggerHandler.getCan_Extend_RequestList(racList);
+                    if(raesList.size() == 0){
+                       return '鏃犱换浣曠敵璇峰崟婊¤冻銆�';
+                    }else{
+                        //濡傛灉浠庡崟涓哄欢鏈熷叆鍙o紝浼氬垽鏂粬鐨勫師鍗曞拰姝ゅ師鍗曚笅鎵�鏈変粠鍗曟弧瓒冲欢鏈熸潯浠�
+                        //濡傛灉婊¤冻鏉′欢锛岄偅涔堝垽鏂綋鍓嶄粠鍗曟槸鍚︽弧瓒冲欢鏈熸潯浠讹紝濡傛灉鏄叾浠栫敵璇峰崟婊¤冻锛岄偅涔堜笉鑳藉欢鏈燂紝
+                        //濡傛灉姝ょ敵璇峰崟鏈変竴涓厤濂楁弧瓒筹紝閭d箞鍙互寤舵湡锛岃蛋鍗曠嫭寤舵湡閫昏緫锛堝師鏉ュ欢鏈熼�昏緫锛�
+                        if(String.isNotBlank(rac.Root_Rental_Apply__c)){
+                            Integer indexI = 0;
+                            String racIds = rac.Id;
+                            racIds = racIds.substring(0,15);
+                            //寰幆鍒ゆ柇姝ゅ崟鏄惁鏈夊彲浠ュ欢鏈熺殑閰嶅鍚楋紵
+                            for(Rental_Apply_Equipment_Set__c raesc : raesList){
+                                String raescId = raesc.Rental_Apply__c;
+                                raescId = raescId.substring(0,15);
+                                if(racIds.equals(raescId)){
+                                    indexI++;
+                                }
+                            }
+                            if(indexI > 0) {
+                                //濡傛灉浠庡崟涓哄欢鏈熷叆鍙o紝浠栦細璧伴�氱敤鐨勬壒閲忓欢鏈熼獙璇侊紝鎵�浠ラ渶瑕侀獙璇佷互涓嬬殑鏉′欢锛屽鏋滄弧瓒冲氨涓嶇劧寤舵湡
+                                //鍒ゆ柇鏄鐢宠鍗曟槸鍚﹀瓨鍦� ok骞朵笖鍥炲瘎鏃堕棿涓嶄负绌虹殑涓�瑙�
+                                List<Rental_Apply_Equipment_Set__c> raescc = getAllRentalApplyEs(rac);
+                                if(raescc != null && raescc.size() > 0){
+                                    for(Rental_Apply_Equipment_Set__c rr : raescc){
+                                        if ((rr.Received_Confirm__c == 'OK' || rr.Received_Confirm__c == '榛樿绛炬敹-OK') && rr.Asset_return_time__c != null) {
+                                            return '姝ゅ崟涓嶆弧瓒冲欢鏈熸潯浠躲��';
+                                        }
+                                    }
+                                    return '1';
+                                }
+                            }else{
+                                return '姝ゅ崟涓嶆弧瓒冲欢鏈熸潯浠躲��';
+                            }
+                        }else{
+                            return '2';
+                        }
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 鏍规嵁浼犺繃鏉ョ殑澶囧搧id鑾峰彇鎵�鏈夌殑浠庡崟鍜屽師鍗�
+     * @param  rea 寤舵湡鐨勫叆鍙g敵璇峰崟
+     * @return               杩斿洖鎵�鏈夌殑鍘熷崟鍜屼粠鍗�
+     * 鍙傛暟鏈夊彲鑳芥槸鍘熷崟id鎴栦粠鍗昳d
+     */
+    public static List<Rental_Apply__c> getAllRentalApply(Rental_Apply__c rea){
+        List<Rental_Apply__c> allRentalApply = [SELECT id,
+                                                        Name,
+                                                        RA_Status__c,
+                                                        Request_return_day__c,
+                                                        demo_purpose1__c,demo_purpose2__c,
+                                                        ExtensionApprovalTime_Final__c,
+                                                        RC_Ordered_Date__c,
+                                                        Bollow_Date_Add_10_WD__c,
+                                                        Loaner_received_ng_num__c,
+                                                        ExtensionApprovalTime_Initial__c,
+                                                        next_action__c,
+                                                        NewRepair__c,
+                                                        NewRepair__r.Agreed_Date__c,
+                                                        NewRepair__r.Status__c,
+                                                        NewRepair__r.ReRepairObject_F__c,
+                                                        NewRepair__r.Repair_Shipped_Date__c,
+                                                        AgreementBorrowingExtensionDate__c,
+                                                        Return_dadeline_final__c,
+                                                        ExtensionApplicationTime_Initial__c,
+                                                        Root_Rental_Apply__c,
+                                                        ExtensionStatus__c
+                                                    FROM Rental_Apply__c 
+                                                    WHERE id = :rea.Id 
+                                                        OR id = :rea.Root_Rental_Apply__c 
+                                                        OR (Root_Rental_Apply__c = :rea.Id AND Root_Rental_Apply__c != NULL)
+                                                        OR (Root_Rental_Apply__c = :rea.Root_Rental_Apply__c AND Root_Rental_Apply__c != NULL) 
+                                                        limit 1000];
+        return allRentalApply;
+    }
+
+    /**
+     * [getAllRentalApplyEs 鑾峰彇涓�瑙圿
+     * @param  rea [description]
+     * @return     [description]
+     *
+     * 鍙湁浠庡崟涓哄欢鏈熷叆鍙g殑鏃跺�欙紝鎵嶄細鍘绘煡璇竴瑙�
+     */
+    public static List<Rental_Apply_Equipment_Set__c> getAllRentalApplyEs(Rental_Apply__c rea){
+        List<Rental_Apply_Equipment_Set__c> raes = [SELECT Id,name
+                                                                , Rental_Apply__c
+                                                                , Rental_Apply__r.Repair__r.Agreed_Date__c
+                                                                , Rental_Apply__r.Repair__r.Repair_Estimated_date_formula__c
+                                                                , Rental_Apply__r.NewRepair__c
+                                                                , Rental_Apply__r.NewRepair__r.Agreed_Date__c
+                                                                , Rental_Apply__r.NewRepair__r.Status__c
+                                                                , Rental_Apply__r.NewRepair__r.ReRepairObject_F__c
+                                                                , Rental_Apply__r.NewRepair__r.Repair_Shipped_Date__c
+                                                                , Rental_Apply__r.QISRepair__r.Repair_Shipped_Date__c
+                                                                , Rental_Apply__r.RC_return_to_office__c
+                                                                , Rental_Apply__r.AgreementBorrowingExtensionDate__c
+                                                                , Rental_Apply__r.ExtensionApprovalTime_Initial__c
+                                                                , Rental_Apply__r.ExtensionApplicationTime_Final__c
+                                                                , Rental_Apply__r.RcUnexpectExpiryDelay__c
+                                                                , Final_reply_day__c
+                                                                , Asset_return_time__c
+                                                                , Bollow_Date__c
+                                                                , demo_purpose2__c
+                                                                , demo_purpose1__c
+                                                                , Request_demo_time__c
+                                                                , Loaner_received_time__c
+                                                                , Received_Confirm__c
+                                                                , Loaner_received_day2__c
+                                                                , RcUnexpectExpiryDelay__c
+                                                             FROM Rental_Apply_Equipment_Set__c
+                                                            WHERE Rental_Apply__c = :rea.Id 
+                                                              AND Cancel_Reason__c = null // 鍙栨秷閲嶆柊鍒嗛厤鐨勮瘽闇�瑕佸仛涓篘G閲嶆柊鍒嗛厤鐨勬儏鍐垫墍浠ヤ笉鑳界敤Cancel_Select__c
+                                                             ];
+        return raes;
+    }
+
+    //add       wangweipeng            2021/11/26                   start
+    
+//bp2
+//    // 澶囧搧鍊熷嚭鏃堕棿check
+//    WebService static String approvalCheck2(String raesId) {
+//        // check缁撴灉
+//        String returnStr = '';
+        
+//        // 澶囧搧鍊熷嚭鍘嗗彶鍙栧緱
+//        List<String> equipmentSetList = new List<String>();
+//        Rental_Apply_Equipment_Set__c[] raes = [
+//            select Id, Name, Equipment_Set__c, Equipment_Set__r.Name, Rental_Start_Date__c, Rental_End_Date__c, Rental_Apply__c, Rental_Apply__r.Prepare_Day__c 
+//              from Rental_Apply_Equipment_Set__c 
+//             where Id = :raesId and Cancel_Select__c = false];
+        
+//        Rental_Apply_Equipment_Set__c r = raes[0];
+//        // 鏃ュ巻鑼冨洿锛屾渶灏忕殑鍊熷嚭寮�濮嬫棩鍒版渶澶х殑鍊熷嚭缁堜簡鏃�
+//        Date startDate = r.Rental_Start_Date__c;
+//        Date endDate = r.Rental_End_Date__c;
+//        Integer prepareDay = r.Rental_Apply__r.Prepare_Day__c == null ? Integer.valueOf(System.Label.EquipmentRentalPrepare) : r.Rental_Apply__r.Prepare_Day__c.intValue();
+//        Date minDate = getWD_addday(startDate, -1 * prepareDay);
+//        Date maxDate = getWD_addday(endDate, prepareDay);
+//        // 鍏朵粬澶囧搧鍊熷嚭鐢宠鍘嗗彶
+//        Rental_Apply_Equipment_Set__c[] others = [
+//                    select Id, Name, Rental_Start_Date__c, Rental_End_Date__c, Equipment_Set__c, Rental_Apply__r.Status__c ,Rental_Apply__r.Prepare_Day__c 
+//                      from Rental_Apply_Equipment_Set__c
+//                     where Id != :raesId
+//                       and Equipment_Set__c = :r.Equipment_Set__c
+//                       and Request_Status__c != '鍙栨秷'
+//                       and Request_Status__c != '鍒犻櫎'
+//                       and Cancel_Select__c = false
+//                       and ((Rental_Start_Date__c >= :minDate and Rental_Start_Date__c <= :maxDate)
+//                            or (Rental_End_Date__c >= :minDate and Rental_End_Date__c <= :maxDate)
+//                            or (Rental_Start_Date__c <= :startDate and Rental_End_Date__c >= :endDate))];
+        
+//        Map<String, List<Rental_Apply_Equipment_Set__c>> othersMap = new Map<String,List<Rental_Apply_Equipment_Set__c>>();
+//        for (Rental_Apply_Equipment_Set__c other : others) {
+//            if (othersMap.containsKey(other.Equipment_Set__c)) {
+//                othersMap.get(other.Equipment_Set__c).add(other);
+//            } else {
+//                List<Rental_Apply_Equipment_Set__c> l = new List<Rental_Apply_Equipment_Set__c>();
+//                l.add(other);
+//                othersMap.put(other.Equipment_Set__c, l);
+//            }
+//        }
+        
+//        List<Rental_Apply_Equipment_Set__c> other = othersMap.get(r.Equipment_Set__c);
+        
+//        Map<Date, Map<String, String>> dateMap= new Map<Date, Map<String, String>>();
+//        if (other != null) {
+//            Date sdate = startDate;
+//            Date edate = endDate;
+//            for (Rental_Apply_Equipment_Set__c o : other) {
+//                if (o.Rental_Start_Date__c != null && (sdate == null || o.Rental_Start_Date__c < sdate)) {
+//                    sdate = o.Rental_Start_Date__c;
+//                }
+//                if (o.Rental_End_Date__c != null && (edate == null || o.Rental_End_Date__c > edate)) {
+//                    edate = o.Rental_End_Date__c;
+//                }
+//            }
+//            if (sdate != null && edate != null) {
+//                RentalApplyWebService raws = new RentalApplyWebService();
+//                dateMap = raws.getDateMap(sdate, edate, prepareDay);
+//            }
+//        }
+        
+//        if (r.Rental_Start_Date__c == null && r.Rental_End_Date__c == null) {
+//            // 娓呯┖璇ュ�熷嚭鍘嗗彶鐨勫嚭搴撳拰鍥炴敹鏃堕棿
+//        } else if (other == null || other.size() == 0) {
+//            // 涓庡叾浠栧�熷嚭鍘嗗彶娌℃湁鍐茬獊
+//        } else {
+//            Date fromDate = r.Rental_Start_Date__c;
+//            Date toDate = r.Rental_End_Date__c;
+//            for (Rental_Apply_Equipment_Set__c o : other) {
+//                if (o.Rental_Apply__r.Status__c != '鑽夋涓�' && o.Rental_Apply__r.Status__c != '鐢宠涓�' && o.Rental_Apply__r.Status__c != null) {
+//                    Date startD = o.Rental_Start_Date__c;
+//                    Date endD = o.Rental_End_Date__c;
+//                    Integer prepare = prepareDay; //>= o.Rental_Apply__r.Prepare_Day__c || o.Rental_Apply__r.Prepare_Day__c == null ? prepareDay : o.Rental_Apply__r.Prepare_Day__c.intValue();
+//                    Date minD = startD.addDays(-1 * prepare);
+//                    Date maxD = endD.addDays(prepare);
+//                    if ((dateMap.containsKey(fromDate) && Date.valueOf(dateMap.get(fromDate).get('Next')) > startD && dateMap.containsKey(endD) && fromDate < Date.valueOf(dateMap.get(endD).get('Next'))) ||
+//                        (dateMap.containsKey(toDate) && Date.valueOf(dateMap.get(toDate).get('Next')) > startD && dateMap.containsKey(endD) && toDate < Date.valueOf(dateMap.get(endD).get('Next'))) ||
+//                        (dateMap.containsKey(fromDate) && Date.valueOf(dateMap.get(fromDate).get('Next')) <= startD && dateMap.containsKey(endD) && toDate >= Date.valueOf(dateMap.get(endD).get('Next')))) {
+//                        returnStr = '澶囧搧' + r.Equipment_Set__r.Name + '鐨勫�熷嚭鏃ヤ笌澶囧搧鍊熷嚭鍘嗗彶' + o.Name + '鏈夊啿绐侊紝璇风‘璁ゃ��';
+//                        return returnStr;
+//                    }
+//                }
+//            }
+//        }
+        
+//        return '1';
+//    }
+
+//bp2
+//    WebService static String reserve2(String raesId) {
+//        String checkRS = '1';
+//        Rental_Apply_Equipment_Set__c raes = [
+//                select Id,Name,Rental_Apply__c,Rental_Start_Date__c,ES_Stock_Status__c,
+//                       Equipment_Set__c,
+//                       Equipment_Set__r.Name,
+//                       Equipment_Set__r.Active_judgement2__c,
+//                       Equipment_Set__r.Last_Reserve_Rental_Apply_Equipment_Set__c,
+//                       Equipment_Set__r.Pre_Reserve_Rental_Apply_Equipment_Set__c
+//                  from Rental_Apply_Equipment_Set__c where Id = :raesId and Cancel_Select__c = false
+//        ];
+//        if (raes.Equipment_Set__r.Last_Reserve_Rental_Apply_Equipment_Set__c == raes.Id) {
+//            checkRS = '璇ュ�熷嚭澶囧搧set涓�瑙堝凡缁忓仛杩囧嚭搴撴寚绀�:' + raes.Name;
+//            return checkRS;
+//        }
+//        if (raes.ES_Stock_Status__c == '涓嶈兘鍑哄簱') {
+//             checkRS = '澶囧搧set ' + raes.Equipment_Set__r.Name + ' 鍦ㄩ绾︽湡闂村涓嶈兘鍑哄簱锛岃纭';
+//             return checkRS;
+//        }
+//        checkRS = RentalApplyWebService.approvalCheck2(raesId);
+//        if (checkRS != '1') {
+//            return checkRS;
+//        }
+//        /*
+//        if (raes.Rental_Start_Date__c <= Date.today()) {
+//            checkRS = '鍊熷嚭寮�濮嬫棩蹇呴』澶т簬浠婃棩銆傚�熷嚭澶囧搧set涓�瑙堬細' + raes.Name;
+//            return checkRS;
+//        }
+//        if (raes.Equipment_Set__r.Active_judgement2__c != okStatus) {
+//            checkRS = '澶囧搧set ' + raes.Equipment_Set__r.Name + ' 鐨�' + Schema.SObjectType.Equipment_Set__c.fields.Asset_Set_status2__c.label + '涓嶆槸 99.绛夊緟棰勭害 锛岀幇鍦ㄦ槸 ' + raes.Equipment_Set__r.Asset_Set_status2__c + ' 璇风‘璁�';
+//            return checkRS;
+//        }
+//        */
+//        //澶囧搧Set鏄庣粏
+//        List<Equipment_Set_Detail__c> equipmentSetDetailList = new List<Equipment_Set_Detail__c>();
+//        List<Equipment_Set_Detail__c> equipmentSetDetailList2 = new List<Equipment_Set_Detail__c>();
+//        //澶囧搧鐢宠鍊熷嚭鏄庣粏鍘嗗彶
+//        List<Rental_Apply_Equipment_Set_Detail__c> rentalApplyEquipmentSetDetailList = new List<Rental_Apply_Equipment_Set_Detail__c>();
+//        //鏇存柊澶囧搧Set
+//        Equipment_Set__c equipmentSet = new Equipment_Set__c(
+//            Id = raes.Equipment_Set__c,
+//            Last_Reserve_Rental_Apply_Equipment_Set__c = raes.Id,
+//            Pre_Reserve_Rental_Apply_Equipment_Set__c = raes.Equipment_Set__r.Last_Reserve_Rental_Apply_Equipment_Set__c == null ? raes.Equipment_Set__r.Pre_Reserve_Rental_Apply_Equipment_Set__c : raes.Equipment_Set__r.Last_Reserve_Rental_Apply_Equipment_Set__c,
+//            StockDown__c = false,
+//            StockDown_time__c = null,
+//            Shipment_request_time__c = System.now(),            //鍑哄簱鎸囩ず鏃堕棿
+//            Shippment_loaner_time__c = null,            //澶囧搧涓績鍑哄簱鏃堕棿
+//            Forecast_arrival_day__c = null,             //棰勮鍒拌揣鏃�
+//            //Loaner_received_day__c = null,              //鐜板満绛炬敹鏃�
+//            Request_asset_extend_time__c = null,        //寤舵湡鐢宠鏃堕棿
+//            asset_extend_approval_time__c = null,       //寤舵湡鐢宠鎵瑰噯鏃堕棿
+//            //Asset_return_day__c = null,                 //鐗╂祦鎻愯揣鏃�
+//            Received_loaner_time__c = null,             //澶囧搧涓績鍥炴敹鏃堕棿
+//            delivery_company__c = null,
+//            Fedex_number__c = null,
+//            Distributor_method__c = null,
+//            Return_to_wh_staff__c = null,
+//            Return_delivery_company__c = null,
+//            Return_Fedex_number__c = null,
+//            Return_Distributor_method__c = null,
+//            Received_confirmation_staff__c = null,
+//            Customer_install_explanation_sign__c = null, //鏄惁鍥炴敹CDS纭鍗�
+//            Send_to_return_email__c = false, //鍙戦�佸洖鏀剁粨鏋滃弽棣堥偖浠�
+//            Return_comment_anoucment__c = null, //鍙戦�佸洖鏀剁粨鏋滃弽棣堝唴瀹�(NG鐞嗙敱鍜屾瑺鍝佹儏鍐�)
+////bp2            CDS_complete__c = false,
+//            Arrival_in_wh__c = false,
+//            Arrival_wh_time2__c = null,
+
+//            Repair_Sum_Update__c = 0
+//        );
+        
+//        //鍊熷嚭璁惧鏈鸿韩鍙风爜
+//        String assetSerialNumber = '';
+//        Boolean assetFirst = false;
+//        //澶囧搧Set鏄庣粏
+//        Equipment_Set_Detail__c[] equipmentSetDetails = [select Equipment_Set__c,Asset__c,Asset__r.SerialNumber,
+//                                            Check_lost_Item__c,Pre_disinfection__c,Water_leacage_check__c,
+//                                            Inspection_result_after__c,Arrival_in_wh__c,
+//                                            Lost_item_check_staff__c,CDS_staff__c,Inspection_staff_After__c,
+//                                            Return_wh_chenk_staff__c,Pre_inspection_time__c,Lost_item_check_time__c,
+//                                            After_Inspection_time__c,Arrival_wh_time__c,
+//                                            Inspection_result__c,Inspection_staff__c,Last_Reserve_RAES_Detail__c
+////bp2        CDS_complete_time__c,
+//                                            from Equipment_Set_Detail__c
+//                                            where Equipment_Set__c = :equipmentSet.Id and Select_rental__c = true];
+        
+//        for (Equipment_Set_Detail__c equipmentSetDetail : equipmentSetDetails) {
+//            //鎻掑叆澶囧搧鐢宠鍊熷嚭鏄庣粏鍘嗗彶
+//            Rental_Apply_Equipment_Set_Detail__c rentalApplyEquipmentSetDetail = new Rental_Apply_Equipment_Set_Detail__c();
+//            rentalApplyEquipmentSetDetail.Rental_Apply__c = raes.Rental_Apply__c;//澶囧搧鍊熷嚭鐢宠
+//            rentalApplyEquipmentSetDetail.Rental_Apply_Equipment_Set__c = raes.Id;//澶囧搧Set鍊熷嚭鍘嗗彶
+//            rentalApplyEquipmentSetDetail.Equipment_Set__c = equipmentSetDetail.Equipment_Set__c;//澶囧搧Set
+//            rentalApplyEquipmentSetDetail.Asset__c = equipmentSetDetail.Asset__c;//淇濇湁璁惧
+//            //鎻掑叆澶囧搧鐢宠鍊熷嚭鏄庣粏鍘嗗彶
+//            rentalApplyEquipmentSetDetailList.add(rentalApplyEquipmentSetDetail);
+            
+//            //鏇存柊澶囧搧Set鏄庣粏
+//            equipmentSetDetail.Check_lost_Item__c = null;//娆犲搧纭缁撴灉
+//            equipmentSetDetail.Pre_disinfection__c = null;//娓呮礂鍓�
+//            equipmentSetDetail.Water_leacage_check__c = null;//娴嬫紡妫�鏌ョ粨鏋�
+//            equipmentSetDetail.Inspection_result_after__c = null;//鍥炴敹鍚�-妫�娴嬬粨鏋�
+//            equipmentSetDetail.Arrival_in_wh__c = false;//鍥炲簱纭
+//            equipmentSetDetail.Lost_item_check_staff__c = null;//娆犲搧纭鑰�
+//            equipmentSetDetail.CDS_staff__c = null;//娑堟瘨浜哄憳
+//            equipmentSetDetail.Inspection_staff_After__c = null;//鍥炴敹鍚�-妫�娴嬩汉鍛�
+//            equipmentSetDetail.Return_wh_chenk_staff__c = null;//鍥炲簱纭鑰�
+//            equipmentSetDetail.Inspection_result__c = null;//鍙戣揣鍓�-妫�娴嬬粨鏋�
+//            equipmentSetDetail.Inspection_staff__c = null;//鍙戣揣鍓�-妫�娴嬩汉鍛�
+            
+//            equipmentSetDetail.Pre_inspection_time__c = null;//澶囧搧Set鐢�,鍙戣揣鍓�-妫�娴嬪悎鏍兼椂闂�
+//            equipmentSetDetail.Lost_item_check_time__c = null;//澶囧搧Set鐢�,娆犲搧纭鏃堕棿
+////bp2            equipmentSetDetail.CDS_complete_time__c = null;//澶囧搧Set鐢�,CDS瀹屾瘯鏃堕棿
+//            equipmentSetDetail.After_Inspection_time__c = null;//澶囧搧Set鐢�,鍥炴敹鍚�-妫�娴嬪畬姣曟椂闂�
+//            equipmentSetDetail.Arrival_wh_time__c = null;//澶囧搧Set鐢�,鍥炲簱纭瀹屾瘯鏃堕棿
+//            //鏇存柊澶囧搧Set鏄庣粏
+//            equipmentSetDetailList.add(equipmentSetDetail);
+//            //鍊熷嚭璁惧鏈鸿韩鍙风爜
+//            if (String.isNotBlank(equipmentSetDetail.Asset__r.SerialNumber)) {
+//                if (assetFirst == false) {
+//                    assetSerialNumber += ',' + equipmentSetDetail.Asset__r.SerialNumber + ',';
+//                    assetFirst = true;
+//                } else {
+//                    assetSerialNumber += equipmentSetDetail.Asset__r.SerialNumber + ',';
+//                }
+//            }
+//        }
+        
+//        Equipment_Set_Detail__c[] equipmentSetDetails2 = [select Id, Last_Reserve_RAES_Detail__c
+//                                            from Equipment_Set_Detail__c
+//                                            where Equipment_Set__c = :equipmentSet.Id and Select_rental__c = false];
+//        for (Equipment_Set_Detail__c equipmentSetDetail : equipmentSetDetails2) {
+//            equipmentSetDetail.Pre_Reserve_RAES_Detail__c = equipmentSetDetail.Last_Reserve_RAES_Detail__c;
+//            equipmentSetDetail.Last_Reserve_RAES_Detail__c = null;
+//            equipmentSetDetailList2.add(equipmentSetDetail);
+//        }
+        
+//        //鏇存柊鍊熷嚭璁惧鏈鸿韩鍙风爜
+//        raes.Rental_Asset_SerialNumber__c = assetSerialNumber;
+        
+//        Savepoint sp = Database.setSavepoint();
+//        try {
+//            if (equipmentSet != null) {
+//                update equipmentSet;
+//            }
+//            if (rentalApplyEquipmentSetDetailList.size() > 0) {
+//                insert rentalApplyEquipmentSetDetailList;
+//            }
+//            if (equipmentSetDetailList.size() > 0) {
+//                for (Integer i=0; i<equipmentSetDetailList.size(); i++) {
+//                    equipmentSetDetailList[i].Pre_Reserve_RAES_Detail__c = equipmentSetDetailList[i].Last_Reserve_RAES_Detail__c;
+//                    equipmentSetDetailList[i].Last_Reserve_RAES_Detail__c = rentalApplyEquipmentSetDetailList[i].Id;
+//                }
+//                update equipmentSetDetailList;
+//            }
+//            if (equipmentSetDetailList2.size() > 0) {
+//                update equipmentSetDetailList2;
+//            }
+//            if (String.isNotBlank(assetSerialNumber)) {
+//                update raes;
+//            }
+//            eSetRefreshStatus(equipmentSet.Id);
+//        } catch (System.Exception e) {
+//            Database.rollback(sp);
+//            return e.getMessage();
+//        }
+//        //杩斿洖缁撴灉
+//        return checkRS;
+//    }
+
+    // 鍊熷嚭澶囧搧閰嶅涓�瑙堢姸鎬佸嵆鏃舵洿鏂�
+    WebService static String eSetRefreshStatus(String raeSetId) {
+        return eSetRefreshStatus(new List<String> {raeSetId});
+    }
+    public static String eSetRefreshStatus(List<String> raeSetIds) {
+        List<Rental_Apply_Equipment_Set__c> updateList1 = new List<Rental_Apply_Equipment_Set__c>();
+
+        if (!raeSetIds.isEmpty()) {
+            for (Rental_Apply_Equipment_Set__c raes: [
+                    select Id,Repair_Status1__c,Repair_Status_Text__c,Final_reply_day__c,Final_reply_day_text__c,
+                            Received_Confirm_NG_Not_Return__c,Received_Confirm_NG_Not_Return_Text__c,
+                            Received_Confirm_Status_Text__c, Received_Confirm_Status_F__c
+                              , NG_Final_reply_day_Text__c
+                              , NG_Final_reply_day_F__c
+                              , Yizhouweixiu_Final_reply_day_Text__c
+                              , Yizhouweixiu_Final_reply_day_F__c
+                              , Extend_Final_reply_day_Text__c
+                              , Extend_Final_reply_day_F__c
+                              , QIS_Final_reply_day_Text__c
+                              , QIS_Final_reply_day_F__c
+                              , Repair_cancel_Final_reply_day_Text__c
+                              , Repair_cancel_Final_reply_day_F__c
+                              , Return_to_office_Final_reply_day_Text__c
+                              , Return_to_office_Final_reply_day_F__c
+                              , Repair_delete_Final_reply_day_Text__c
+                              , Repair_delete_Final_reply_day_F__c
+                              , Yigoudaihuo_Final_reply_day_Text__c
+                              , Yigoudaihuo_Final_reply_day_F__c
+                              , Guzhangpaicha_Final_reply_day_Text__c
+                              , Guzhangpaicha_Final_reply_day_F__c
+                              , Repair_Agreed_Quotation_Text__c
+                              , Repair_Agreed_Quotation_F__c
+                              , Return_to_office_Final_reply_day_U_RC__c
+                              , Return_to_office_Final_reply_day_U_RC_F__c
+                              , Extend_Date__c
+                              , Extend_Date_F__c
+                              , Received_NG_ReAssign_Text__c
+                              , Received_NG_ReAssign__c
+                        //銆怓Y23澶у強宸ㄥぇ璇鹃銆戦暱鍋囧鍝佸�熺敤寤舵湡寮�鍙� 2022/12/27 start xxf
+                              , Final_reply_day_Holiday_backup__c
+                              , NG_Final_reply_day_F_Holiday_backup__c
+                              , NG_Final_reply_day_Text_Holiday_backup__c
+                              , Yizhouweixiu_Final_reply_day_F_Holiday__c
+                              , Yizhouweixiu_Final_reply_day_TextHoliday__c
+                              , Extend_Final_reply_day_F_Holiday_backup__c
+                              , Extend_Final_reply_day_Text_Holiday_back__c
+                              , QIS_Final_reply_day_F_Holiday_backup__c
+                              , QIS_Final_reply_day_Text_Holiday_backup__c
+                              , Repair_cancel_Final_reply_day_F_Holiday__c
+                              , Repair_cancel_Final_reply_day_Text_Holid__c
+                              , Return_to_office_Final_reply_day_F_Ho__c
+                              , Return_to_office_Final_reply_day_Text_Ho__c
+                              , Repair_delete_Final_reply_day_F_Holiday__c
+                              , Repair_delete_Final_reply_day_Text_Ho__c
+                              , Yigoudaihuo_Final_reply_day_F_Holiday__c
+                              , Yigoudaihuo_Final_reply_day_Text_Holiday__c
+                              , FGuzhangpaicha_Final_reply_day_F_Holiday__c
+                              , Guzhangpaicha_Final_reply_day_Text_Holid__c
+                              , Return_to_office_Final_reply_day_U_RC_Ho__c
+                              , Return_to_office_Final_reply_day_U_RC_FH__c
+                        //銆怓Y23澶у強宸ㄥぇ璇鹃銆戦暱鍋囧鍝佸�熺敤寤舵湡寮�鍙� 2022/12/27 end xxf
+                      from Rental_Apply_Equipment_Set__c
+                     where Id IN :raeSetIds
+            ]) {
+                Rental_Apply_Equipment_Set__c upd = UpdateRentalApplyEquipmentSetBatch.setRAES(raes);
+                if (upd != null) {
+                    updateList1.add(upd);
+                }
+            }
+        }
+//bp2
+//        List<Equipment_Set_Detail__c> esdList = [
+//                select Id,Asset_condition__c,Asset_condition_Text__c,
+//                       Serial_Lot__c,Serial_Lot_text__c,
+//                       Asset__r.Loaner_accsessary__c, Loaner_accsessary_text__c,
+//                       Active_judgement__c,Active_judgement_select__c,Active_judgement_text__c,
+//                       Last_Reserve_RAES_Detail_RAES_F__c,Last_Reserve_RAES_Detail_RAES_Id__c,
+//                       Equipment_Set_Last_Reserve_RAES_F__c,Equipment_Set_Last_Reserve_RAES_Id__c
+//                  from Equipment_Set_Detail__c 
+//                 where Equipment_Set__c IN :eSetIds];
+//        List<Equipment_Set_Detail__c> updateList2 = UpdateRentalApplyEquipmentSetBatch.setESD(esdList);
+
+        Savepoint sp = Database.setSavepoint();
+        try {
+            if (!updateList1.isEmpty()) update updateList1;
+//bp2            if (updateList2.size() > 0) update updateList2;
+            return '1';
+        } catch (System.Exception e) {
+            Database.rollback(sp);
+            return e.getMessage();
+        }
+        return '1';
+    }
+
+//bp2    //鏁板嚭涓�鍏辨湁澶氬皯涓鍝丼et锛屽嚭搴撴寚绀猴紝鍏ㄩ儴鍙戣揣浼氱敤鍒�
+//    Webservice static Integer CntEquipmentSet(String Raid){
+//        List<Rental_Apply_Equipment_Set__c> Raesc = [Select Equipment_Set__c from Rental_Apply_Equipment_Set__c where Rental_Apply__c=:Raid and Cancel_Select__c = false];
+//        return Raesc.size();
+//    }
+    // 鍒嗛厤楠岃瘉
+    Webservice static String AssignBtn(String Rid){
+
+        List<String> statusList = System.Label.StatusProcessState.split(',');
+
+        List<Rental_Apply__c> raList = [select demo_purpose2__c,next_action__c,QIS_number__r.ReplaceDeliveryDate__c,Follow_UP_Opp__r.Shipping_Finished_Day_Func__c,repair__r.Repair_Final_Inspection_Date__c,repair__r.Return_Without_Repair_Date__c,Campaign__c,Campaign__r.Status,Repair__r.Repair_Shipped_Date__c,Campaign__r.IF_Approved__c,Campaign__r.Meeting_Approved_No__c,Campaign__r.Approved_Status__c   from Rental_Apply__c where id = :Rid];
+        // 20210803 ljh  SFDC-C5HDC7 add 鏌ヨ娣诲姞 Campaign__c,Campaign__r.Status,Repair__r.Repair_Shipped_Date__c 
+        if(raList.size()>0){
+            Rental_Apply__c Ra = raList[0];
+            // 20210803 ljh  SFDC-C5HDC7 update  鍒ゆ柇澧炲姞 Ra.repair__c != null && start
+            // if(Ra.repair__r.Repair_Final_Inspection_Date__c!=null){
+            //     return '淇悊鏈�缁堟娴嬫棩涓嶄负绌猴紝涓嶈兘鍒嗛厤';
+            // }else if(Ra.repair__r.Return_Without_Repair_Date__c !=null){
+            //     return '鏈慨鐞嗗綊杩樻棩涓嶄负绌猴紝涓嶈兘鍒嗛厤';
+            if(Ra.Campaign__c != null && Ra.Campaign__r.Status == '鍙栨秷'){
+                return '瀛︿細鍙栨秷锛屼笉鍙垎閰�';
+            }else if(Ra.repair__c != null && (Ra.repair__r.Repair_Final_Inspection_Date__c!=null || Ra.Repair__r.Repair_Shipped_Date__c != null)){
+                return '淇悊鏈夋渶缁堟娴嬫棩鎴栦慨鐞嗗搧杩旈�佹棩锛屼笉鍙垎閰�';
+            }else if(Ra.repair__c != null && Ra.repair__r.Return_Without_Repair_Date__c !=null){
+                return '鏈慨鐞嗗綊杩樻棩涓嶄负绌猴紝涓嶈兘鍒嗛厤';
+            // 20210803 ljh  SFDC-C5HDC7 add end   
+            }//1822 yc 20211021 start
+            else if(Ra.demo_purpose2__c=='宸茶喘寰呰揣' && Ra.Follow_UP_Opp__r.Shipping_Finished_Day_Func__c!= null){
+                return '宸茶喘寰呰揣鐩殑锛屾柊鍝佸凡鏈夊彂璐ф棩锛屼笉鍙垎閰�';
+           }else if(Ra.demo_purpose2__c=='绱㈣禂QIS' && Ra.next_action__c=='鏃犲伩鏇存崲' && Ra.QIS_number__r.ReplaceDeliveryDate__c!= null){
+                return '绱㈣禂QIS鐩殑锛孮IS宸叉湁鏂板搧鍙戣揣鏃ワ紝涓嶅彲鍒嗛厤';
+           }//1822 yc 20211108 end
+           else if(Ra.Campaign__r.IF_Approved__c && Ra.Campaign__r.Meeting_Approved_No__c == null){
+                return '宸茬敵璇峰喅瑁佷絾鍐宠缂栫爜涓虹┖';
+           }//20220301 sx obpm淇敼
+           else if(Ra.Campaign__r.IF_Approved__c && Ra.Campaign__r.Meeting_Approved_No__c != null && statusList.contains(Ra.Campaign__r.Approved_Status__c)){
+                return '宸茬敵璇峰喅瑁佷絾鍐宠鐘舵�佷笉绗﹀悎鏉′欢';
+           }//20220315 sx obpm澶囧搧鍐宠鐘舵�佺浉鍏充慨鏀�
+           else{
+                return 'Fin';
+            } 
+        }else{
+            return '璇ュ�熷嚭鐢宠涓嶅瓨鍦�';
+        }
+    }
+
+//bp2
+//    // 琛ュ厖闄勫睘鍝�
+//    WebService static String fillOtherDetail(String eSetId) {
+//        // 涓嶆墦鍕剧殑涓嶈琛ュ厖锛屾墍浠ョ湅 Active_judgement_select__c
+//        List<Equipment_Set_Detail__c> sesd = [select Id from Equipment_Set_Detail__c where Equipment_Set__c = :eSetId and Asset__r.Loaner_accsessary__c = false and Active_judgement_select__c != :okStatus];
+//        if (sesd.size() > 0) {
+//            // 瑕佺瓑涓绘満鍥炴潵浜嗘墠鑳借ˉ
+//            return '璇风‘璁ゅ鍝佷腑涓绘満鐘舵��';
+//        }
+        
+//        List<Equipment_Set_Detail__c> oesd = [select Id, Last_Reserve_RAES_Detail__c from Equipment_Set_Detail__c where Equipment_Set__c = :eSetId and Asset__r.Loaner_accsessary__c = true and Equipment_Set__r.ES_Status__c not in ('寮曞綋鍙�','寮曞綋娓�') and Select_rental__c = true];
+//        // 鍥犱负鏈夊弬鐓у鍝乻et鐨勫瓧娈碉紝鎵�浠ヤ负浜嗚揪鍒扮姸鎬佸彉鎴�99鐨勭洰鐨勶紝鍦ㄨ繖閲屽仛浜嗗叆搴撶殑鎿嶄綔锛岃�屼笉鏄叏娓呯┖銆�
+//        for (Equipment_Set_Detail__c esd : oesd) {
+//            if (esd.Last_Reserve_RAES_Detail__c != null) {
+//                esd.Pre_Reserve_RAES_Detail__c = esd.Last_Reserve_RAES_Detail__c;
+//                esd.Last_Reserve_RAES_Detail__c = null;
+//            }
+
+//            esd.Inspection_result_ng__c = null;
+//            esd.Pre_inspection_time__c = null;
+//            esd.Inspection_staff__c = null;
+//            esd.Inspection_result__c = 'OK';
+
+//            esd.Check_lost_Item__c = 'OK';
+//            esd.Lost_item_check_time__c = null;
+//            esd.Lost_item_check_staff__c = null;
+//            esd.Lost_item_giveup__c = false;
+
+//            esd.Inspection_result_after_ng__c = null;
+//            esd.After_Inspection_time__c = null;
+//            esd.Inspection_staff_After__c = null;
+//            esd.Inspection_result_after__c = 'OK';
+
+//            esd.Arrival_in_wh__c = true;
+//            esd.Arrival_wh_time__c = null;
+//            esd.Return_wh_chenk_staff__c = null;
+
+//            esd.Pre_disinfection__c = null;
+//            esd.Water_leacage_check__c = null;
+////bp2            esd.CDS_staff__c = null;
+////bp2            esd.CDS_complete_time__c = null;
+//        }
+
+//        Savepoint sp = Database.setSavepoint();
+//        try {
+//            update oesd;
+//            return '1';
+//        } catch (System.Exception e) {
+//            Database.rollback(sp);
+//            return e.getMessage();
+//        }
+//        return '1';
+//    }
+
+    Webservice static String postponeCheck(String endDate, Integer d) {
+        Date before5day = getWD_addday(date.parse(endDate), d);
+        if (Date.today() > before5day) {
+            return System.Label.EquipmentRentalPostponeOverDeadline;
+        }
+        return 'OK';
+    }
+    
+    // TODO please use public
+    public static Date getWD_now(Date d) {
+        List<OlympusCalendar__c> workday = [
+                select Id, Date__c, IsWorkDay__c 
+                  from OlympusCalendar__c 
+                 where Date__c >= :d 
+                   and IsWorkDay__c = 1
+                 order by Date__c
+                 limit 1];
+        Date selectDate = workday[0].Date__c;
+        return selectDate;
+    }
+
+    // TODO please use public
+    public static Date getWD_addday(Date d, Integer i) {
+        if (d == Date.valueOf('4000-12-31')) {
+            return d;
+        }
+        if (i >= 0) {
+            List<OlympusCalendar__c> workday = [
+                    select Id, Date__c, IsWorkDay__c 
+                      from OlympusCalendar__c 
+                     where Date__c >= :d 
+                       and IsWorkDay__c = 1
+                     order by Date__c
+                     limit :(i+1)];
+            Date selectDate = workday[i].Date__c;
+            return selectDate;
+        } else {
+            i = Math.abs(i);
+            List<OlympusCalendar__c> workday = [
+                    select Id, Date__c, IsWorkDay__c 
+                      from OlympusCalendar__c 
+                     where Date__c <= :d 
+                       and IsWorkDay__c = 1
+                     order by Date__c desc
+                     limit :(i+1)];
+            Date selectDate = workday[i].Date__c;
+            return selectDate;
+        }
+    }
+    
+    // pd:0浠h〃褰撳ぉ,1浠h〃绗簩澶�
+    public Map<Date, Map<String, String>> getDateMap(Date sd, Date ed, Integer pd) {
+        Map<Date, Map<String, String>> returnMap = new Map<Date, Map<String, String>>();
+        List<OlympusCalendar__c> workdayList = [
+                select Id, Date__c, IsWorkDay__c 
+                  from OlympusCalendar__c 
+                 where Date__c >= :sd
+                   and Date__c <= :ed.addDays(15 + pd)                  // +15 鐨勭洰鐨勬槸銆佷负浜嗗彇寰梕d 銇� 涓嬩竴涓伐浣滄棩
+                 order by Date__c];
+        for (Integer i = 0; i < workdayList.size(); i++) {
+            OlympusCalendar__c wd = workdayList[i];
+            if (wd.Date__c > ed) break;
+            Integer nextWordDays = 0;
+            Map<String, String> valueMap = new Map<String, String>();
+            valueMap.put('WorkDay', String.valueOf(wd.IsWorkDay__c));
+            Integer maxJ = 15 + i + pd;
+            if (maxJ > workdayList.size()) maxJ = workdayList.size();
+            for (Integer j = i; j < maxJ; j++) {
+                OlympusCalendar__c oc = workdayList[j];
+                if (oc.IsWorkDay__c == 1) {
+                    nextWordDays++;
+                    if (nextWordDays == pd + 1) {
+                        valueMap.put('Next', String.valueOf(oc.Date__c));
+                        break;
+                    }
+                }
+            }
+            
+            returnMap.put(wd.Date__c, valueMap);
+        }
+        return returnMap;
+    }
+
+//bp2
+//// TODO katsu select in for, why?銆乬etBetweenWD 銈掋仾銇忋仚鏂瑰悜銆丆ount銇犮亼銇倝銆乬etOlympusWorkDayCount 銇儭銈姐儍銉夈亴銇傘倞銇俱仚銆�
+//    //宸ヤ綔鏃�
+//    WebService static String getBetweenWD(String sd, String ed) {
+//        String betweenWD = '0';
+//        if (sd != '' && ed != '') {
+//            Date sdate = Date.valueof(sd.replace('/','-'));
+//            Date edate = Date.valueof(ed.replace('/','-'));
+//            List<OlympusCalendar__c> workdayList = [
+//                    select Id, Date__c, IsWorkDay__c 
+//                      from OlympusCalendar__c 
+//                    where Date__c >= :sdate
+//                       and Date__c <= :edate
+//                       and IsWorkDay__c = 1
+//                     order by Date__c];
+//            betweenWD = String.valueOf(workdayList.size());
+//        }
+//        return betweenWD;
+//    }
+//bp2 OLY_OCM-113
+    ////鑷劧鏃�
+    //Webservice static String getBetweenNaturalDay(String sd, String ed){
+    //    String betweenND = '0';
+    //    if(sd != '' && ed != ''){
+    //        Date sdate = Date.valueof(sd.replace('/','-'));
+    //        Date edate = Date.valueof(ed.replace('/','-'));
+    //        Integer days = sdate.daysBetween(edate);
+
+    //        betweenND = String.valueOf(days);
+    //    }
+    //    return betweenND;
+    //}
+    //WebService static String sendAll(String raid) {
+    //    return '1';
+    //}
+
+////bp2 OLY_OCM-81
+//*************************Create 20160825 SWAG-AD59Z6 瓒欏境鑺� Start*************************//
+//    //鍏ㄩ儴鍙戣揣
+//    WebService static String DeliverAll(String raid){
+//        List<Rental_Apply__c> raList = [select id,repair__r.Repair_Final_Inspection_Date__c,Bollow_Date__c,repair__r.Return_Without_Repair_Date__c, delivery_company__c, Return_to_wh_staff__c, Distributor_method__c, Tracking_Number__c,
+//                                               Shippment_loaner_time__c,Status__c,All_Delivery_Flag_c__c
+//                                          from Rental_Apply__c
+//                                         where id = :raid];
+//        Rental_Apply__c Ra = new Rental_Apply__c();
+//        System.debug(raList);
+//        if(raList.size()>0){
+//            Ra = raList[0];
+//            if(Ra.delivery_company__c == null||
+//                Ra.Return_to_wh_staff__c == null ||
+//                 Ra.Distributor_method__c == null ||
+//                  Ra.Tracking_Number__c == null){
+//                return '璇疯ˉ鍏ㄥ彂璐х墿娴佷俊鎭�';
+//            }else if(Ra.Status__c !='鍑哄簱鎸囩ず瀹屼簡'){
+//                return '璇峰厛鍋氬嚭搴撴寚绀哄悗锛屽啀杩涜鍑哄簱';
+//            }
+//            //else if(Ra.repair__c.Repair_Final_Inspection_Date__c<Ra.Bollow_Date__c){
+//            //  return '淇悊鏈�缁堟娴嬫棩鏃╀簬鍙戣揣鏃ワ紝涓嶈兘鍙戣揣';
+//            //}
+//            else if(Ra.repair__c!=null&&Ra.repair__r.Repair_Final_Inspection_Date__c!=null){
+//                return '淇悊鏈�缁堟娴嬫棩涓嶄负绌猴紝涓嶈兘鍙戣揣';
+//            }else if(Ra.repair__c!=null&&Ra.repair__r.Return_Without_Repair_Date__c!=null){
+//                return '鏈慨鐞嗗綊杩樻棩涓嶄负绌猴紝涓嶈兘鍙戣揣';
+//            }else{
+//                List<Rental_Apply_Equipment_Set__c> DeliveryGoodDetail = new List<Rental_Apply_Equipment_Set__c>();
+//                DeliveryGoodDetail = [select id,name,Equipment_Set__c from Rental_Apply_Equipment_Set__c where Shippment_loaner_time__c =null and Rental_Apply__c =:raid and  Cancel_Select__c = false];
+//                if(DeliveryGoodDetail.size()>0){
+//                    List<Rental_Apply_Equipment_Set__c> ExistSet  = new List<Rental_Apply_Equipment_Set__c>();
+//                    ExistSet = [select id,name,Equipment_Set__c from Rental_Apply_Equipment_Set__c where Rental_Apply__c =:raid and Cancel_Select__c = false];
+//                    List<String> sqlLine = new List<String>();
+//                    for(Rental_Apply_Equipment_Set__c RAESC : DeliveryGoodDetail){
+//                        sqlLine.add(RAESC.Equipment_Set__c);
+//                    }
+//                    List<Equipment_Set__c> ResultSet = new List<Equipment_Set__c>();
+//                    ResultSet = [select id,Pre_inspection_time__c,Shippment_loaner_time__c from Equipment_Set__c where id in:sqlLine];
+//                    System.debug(ResultSet);
+//                    Integer Ncnt =0;
+//                    for(Equipment_Set__c ESC : ResultSet){
+//                        if(ESC.Shippment_loaner_time__c!=null){
+//                            Ncnt=Ncnt+1;
+//                        }
+//                    }
+//                    Savepoint sp = Database.setSavepoint();
+//                    List<Equipment_Set__c> UpsertEsc = new List<Equipment_Set__c>();
+//                    if(Ncnt==0){
+//                        for(Equipment_Set__c ESC : ResultSet){
+//                            Equipment_Set__c EscEle =  new Equipment_Set__c();
+//                            EscEle.id=ESC.id;
+//                            EscEle.delivery_company__c  = Ra.delivery_company__c;
+//                            EscEle.Return_to_wh_staff__c  = Ra.Return_to_wh_staff__c;
+//                            EscEle.Distributor_method__c  = Ra.Distributor_method__c;
+//                            EscEle.Fedex_number__c  = Ra.Tracking_Number__c;
+//                            EscEle.StockDown__c  = true;
+//                            UpsertEsc.add(EscEle);
+//                        }
+//                        if(UpsertEsc.size()>0){
+//                            Ra.All_Delivery_Flag_c__c = true;
+//                            try{
+//                                update Ra;    
+//                                update UpsertEsc;
+//                                return 'Fin';
+//                            }catch (System.Exception e){
+//                                Database.rollback(sp);
+//                                return e.getMessage();
+//                            }
+//                        }else{
+//                            return '鎵�閫夊鍝丼et锛屽凡鍏ㄩ儴鍑哄簱锛屾棤娉曞啀娆″嚭搴�';
+//                        }               
+//                    }else{
+//                        return '澶囧搧宸插嚭搴�';
+//                    }
+//                }else{
+//                    return '鏈�熷嚭鐢宠鏃犻渶瑕佸嚭搴撶殑澶囧搧';
+//                }
+//            }
+//        }else{
+//            return '鏃犳晥鐨勫鍝佸�熷嚭鐢宠';
+//        }
+//    }
+
+////bp2 OLY_OCM-81
+////*************************Create 20160825 SWAG-AD59Z6 瓒欏境鑺� End***************************//
+//    WebService static String receiveAll(String raid) {
+//        List<Rental_Apply__c> raList = [select id, Return_Track_Company__c, Return_Distrubutor_Method__c, Return_Trake_Staff__c, Return_Track_Number__c,
+//                                               Shippment_loaner_time__c
+//                                          from Rental_Apply__c
+//                                         where id = :raid];
+//        if (raList.size() == 0) {
+//            return '鏃犳晥鐨勫鍝佸�熷嚭鐢宠';
+//        }
+//        Rental_Apply__c ra = raList[0];
+//        if (ra.Return_Track_Company__c == null ||
+//            ra.Return_Distrubutor_Method__c == null ||
+//            ra.Return_Trake_Staff__c == null ||
+//            ra.Return_Track_Number__c == '' || ra.Return_Track_Number__c == null) {
+//            return '璇疯ˉ鍏ㄥ洖搴撶墿娴佷俊鎭�';
+//        }
+//        if (ra.Shippment_loaner_time__c == null) {
+//            return '澶囧搧杩樻病鍑哄簱';
+//        }
+//        List<Rental_Apply_Equipment_Set__c> raesList = [select id, Equipment_Set__c from Rental_Apply_Equipment_Set__c where Shippment_loaner_time__c != null and Rental_Apply__c = :raid and Cancel_Select__c = false];
+//        if (raesList.size() == 0) {
+//            return '澶囧搧杩樻病鍑哄簱';
+//        }
+//        Map<id,id> RaesEsIdMap = new Map<Id,id>();
+//        List<String> esidList = new List<String>();
+//        for (Rental_Apply_Equipment_Set__c raes : raesList) {
+//            esidList.add(raes.Equipment_Set__c);
+//            RaesEsIdMap.put(raes.Equipment_Set__c, raes.Id);
+//        }
+//        List<Equipment_Set__c> esList = [select id,Return_Fedex_number__c,Last_Reserve_Rental_Apply_Equipment_Set__c from Equipment_Set__c where id in :esidList];
+//        List<Equipment_Set__c> updList = new List<Equipment_Set__c>();
+//        for (Equipment_Set__c es : esList) {
+//            if ((es.Return_Fedex_number__c == null || es.Return_Fedex_number__c == '') && es.Last_Reserve_Rental_Apply_Equipment_Set__c == RaesEsIdMap.get(es.Id)) {
+//                Equipment_Set__c tmp = new Equipment_Set__c(
+//                    id = es.id,
+//                    Return_delivery_company__c = ra.Return_Track_Company__c,
+//                    Received_confirmation_staff__c = ra.Return_Trake_Staff__c,
+//                    Return_Distributor_method__c = ra.Return_Distrubutor_Method__c,
+//                    Return_Fedex_number__c = ra.Return_Track_Number__c
+//                );
+//                updList.add(tmp);
+//            }
+//        }
+//        if (updList.size() == 0) {
+//            return '澶囧搧宸茬粡鍏ㄩ儴鍥炲簱';
+//        } else {
+//            try {
+//                update updList;
+//            } catch (Exception ex) {
+//                return ex.getMessage();
+//            }
+//        }
+//        return '1';
+//    }
+
+    WebService static String RentalApplyCancel(String raid, Boolean autoCancel) {
+        List<Rental_Apply__c> raList = [select id, Shipment_request_Cnt__c, Status__c, RA_Status__c, Shippment_loaner_cnt__c, Loaner_cancel_request__c, Arrival_wh_cnt__c,
+                Cancel_Reason__c
+                from Rental_Apply__c
+                where id = :raid];
+        List<Rental_Apply_Equipment_Set__c> raesList = [select id, StockDown_time__c
+//bp2        , Equipment_Set__c
+                                                          from Rental_Apply_Equipment_Set__c
+                                                         where Rental_Apply__c = :raid
+                                                           and Cancel_Select__c = false];
+
+        List<Rental_Apply_Equipment_Set__c> updList = new List<Rental_Apply_Equipment_Set__c>();
+        // List<Rental_Apply_Equipment_Set_Detail__c> delList = new List<Rental_Apply_Equipment_Set_Detail__c>();
+        Set<Id> esIdSet = new Set<Id>();
+
+        if (raList.size() <= 0) {
+            return '澶囧搧鐢宠涔︿笉瀛樺湪銆�';
+        }
+        Rental_Apply__c ra = raList[0];
+        if (ra.Status__c == '鍙栨秷') {
+            return '澶囧搧鐢宠涔﹀凡缁忓彇娑堛��';
+        }
+        if (ra.Status__c == '鍒犻櫎') {
+            return '澶囧搧鐢宠涔﹀凡缁忓垹闄ゃ��';
+        }
+        if (ra.RA_Status__c == FixtureUtil.raStatusMap.get(FixtureUtil.RaStatus.Yi_Chu_Ku.ordinal()) || ra.Arrival_wh_cnt__c > 0) {
+            return '澶囧搧宸茬粡鍑哄簱锛屼笉鑳藉彇娑堛��';
+        }
+        
+        User loginUser = [Select Id, Name, ProfileId From User where Id = :Userinfo.getUserId()];
+        if(loginUser.ProfileId != System.Label.ProfileId_SystemAdmin && loginUser.ProfileId != System.Label.ProfileId_EquipmentCenter && !System.Label.ProfileId_EquCenCheckAndDepot.contains(loginUser.ProfileId)  && !System.Label.ProfileId_EquCenAdmin.contains(loginUser.ProfileId) && loginUser.ProfileId != System.Label.ProfileId_IThelp && ra.Shipment_request_Cnt__c > 0
+        ){
+            return '涓嶈兘鍙栨秷鐢宠锛岃鑱旂郴澶囧搧涓績绐楀彛鍙栨秷銆�';
+        }
+
+
+        if (autoCancel == false && String.isBlank(ra.Cancel_Reason__c)) {
+            return '蹇呴』杈撳叆鍙栨秷鐞嗙敱銆�';
+        }
+        ra.Status__c = '鍙栨秷';
+        if (autoCancel) {
+            ra.Cancel_Reason__c = '琚姩鍙栨秷';
+        }
+        // Map<Id, Asset> assetMap = new Map<Id, Asset>();
+        // for (Rental_Apply_Equipment_Set__c raes : raesList) {
+        //     // if (raes.StockDown_time__c != null) {
+        //         raes.Cancel_Select__c = true;
+        //         raes.Cancel_Reason__c = ra.Loaner_cancel_request__c;
+        //         if (autoCancel) {
+        //             raes.Cancel_Reason__c = '琚姩鍙栨秷';
+        //         }
+        //         updList.add(raes);
+//bp2                esIdSet.add(raes.Equipment_Set__c);
+            // } else {
+                // delList.add(raes);
+//bp2                esIdSet.add(raes.Equipment_Set__c);
+            // }
+            // Asset ass = new Asset(Id = raes.Asset__c, Last_Reserve_RAES_Detail__c = null);
+            // assetMap.put(raes.Asset__c, ass);
+        // }
+
+        Savepoint sp = Database.setSavepoint();
+        try {
+            Set<Id> assetIdSet = new Set<Id>();
+            for (Rental_Apply_Equipment_Set_Detail__c raesd : [SELECT Id, Asset__c
+                                                                 FROM Rental_Apply_Equipment_Set_Detail__c
+                                                                WHERE Rental_Apply__c = :raid
+                                                                  FOR UPDATE]
+            ) {
+                if (String.isNotBlank(raesd.Asset__c)) {
+                    assetIdSet.add(raesd.Asset__c);
+                }
+            }
+            if (assetIdSet.size() > 0) {
+                List<Asset> assetList = [SELECT Id FROM Asset WHERE Id = :assetIdSet FOR UPDATE];
+            }
+            update ra;
+            //if (updList.size() > 0) update updList;
+            // if (!assetMap.isEmpty()) update assetMap.values();
+//bp2            ControllerUtil.setEquipmentSetProvisionFlg(esIdSet);
+        } catch (Exception ex) {
+            return ex.getMessage();
+            Database.rollback(sp);
+        }
+
+        return '1';
+    }
+
+    // 涓�瑕у崢浣�
+    @AuraEnabled
+    WebService static String setRaesShipment_request(String raesid) {
+      return setShipment_requests(null, raesid);
+    }
+
+    // 鐢宠珛鏇稿崢浣�
+    @AuraEnabled
+    WebService static String setShipment_request(String raid) {
+      return setShipment_requests(raid, null);
+    }
+
+    //鍑哄簱鎸囩ず鎸夐挳js涓�娆℃渶澶氭洿鏂�200鏉★紝鎵�浠ユ敼鍦╓ebService鍋氬嚭搴撴寚绀�
+    @AuraEnabled
+    WebService static String setShipment_requests(String raid, String raesid) {
+      Savepoint sp = Database.setSavepoint();
+
+      try {
+        //涓�瑙堟儏鍐典笅妫�绱竴瑙堝搴旂殑鐢宠涔d锛宻oql瀛愭煡璇笉鑳藉拰涓绘煡璇㈡槸鍚屼竴涓〃锛屽崟鐙绱竴娆�
+        if (String.isBlank(raid)) {
+            List<Rental_Apply_Equipment_Set__c> raList = [select Id, Rental_Apply__c from Rental_Apply_Equipment_Set__c where id = :raesid];
+            if (raList.size() > 0) {
+                raid = raList[0].Rental_Apply__c;
+            } else {
+                //搴旇涓嶄細鍒拌繖閲�
+                return '娌℃湁鍙互鍑哄簱鎸囩ず鐨勪竴瑙�';
+            }
+        }
+        String soql = 'SELECT Id'
+                + ' FROM Rental_Apply_Equipment_Set__c '
+                + ' WHERE Shippment_loaner_time2__c <> null '
+                + ' AND Rental_Apply__c = :raid '
+                + ' ORDER BY Id' ;
+        List<Rental_Apply_Equipment_Set__c> shippedRaesList = Database.query(soql);
+        String raesStrShipped = '';
+        for (Rental_Apply_Equipment_Set__c raes : shippedRaesList) {
+            raesStrShipped += raes.Id;
+        }
+
+        //Srring soql = "SELECT Id FROM Rental_Apply_Equipment_Set_Detail__c WHERE Rental_Apply__c = '{!Rental_Apply__c.Id}' AND Cancel_Select__c = false AND Rental_Num__c > 0 AND Rental_Apply_Equipment_Set__r.Wei_Assigned_Cnt__c = 0 AND Rental_Apply_Equipment_Set__r.Yi_Assigned_Cnt__c > 0 AND Shipment_request__c  = false";
+        soql = 'SELECT Id, Rental_Apply__c, Rental_Apply_Equipment_Set__c'
+                + ' FROM Rental_Apply_Equipment_Set_Detail__c '
+                + ' WHERE ' + (String.isNotBlank(raesid) ? 'Rental_Apply_Equipment_Set__c = :raesid ' : 'Rental_Apply__c = :raid ')
+                + ' AND Cancel_Select__c = false '
+                + ' AND Rental_Num__c > 0 '
+                + ' AND Rental_Apply_Equipment_Set__r.Wei_Assigned_Cnt__c = 0 '
+                + ' AND Rental_Apply_Equipment_Set__r.Yi_Assigned_Cnt__c > 0 '
+                + ' AND Shipment_request__c  = false'
+                + ' ORDER BY Rental_Apply_Equipment_Set__c, Id';
+        List<Rental_Apply_Equipment_Set_Detail__c> raesds = Database.query(soql);
+
+        Map<Id, List<String>> rental_Asset_SerialNumberMap = new Map<Id, List<String>>();
+
+        if (raesds.size() < 1) {
+            return '娌℃湁鍙互鍑哄簱鎸囩ず鐨勪竴瑙�';
+        } else {
+            Set<Id> raesSet = new Set<Id>();
+            String raesStrRequest = '';
+            for (Rental_Apply_Equipment_Set_Detail__c raesd : raesds) {
+                if (false == raesSet.contains(raesd.Rental_Apply_Equipment_Set__c)) {
+                    raesSet.add(raesd.Rental_Apply_Equipment_Set__c);
+                    raesStrRequest += raesd.Rental_Apply_Equipment_Set__c;
+                }
+                raesd.Shipment_request_time2__c = Datetime.now();
+                raesd.Shipment_request__c = true;
+            }
+            // 鍑哄簱鍚�, 鍐嶆鍋氬嚭搴撴寚绀虹殑涓�瑙�, 涓�瀹氳涓嚭杩囧簱鐨勪竴瑙堜竴鏍�
+            if (false == String.isBlank(raesStrShipped) && raesStrRequest != raesStrShipped) {
+                return '涓嶈兘鍋氬嚭搴撴寚绀猴紝闇�瑕佸垎鍗曞悗鍐嶆搷浣�';
+            }
+        }
+
+        // add lc 20220927 SFDC-CJ48VE 澶囧搧棰勮鍑哄簱鏃ラ�昏緫璋冩暣 start
+        List<Rental_Apply_Equipment_Set__c> RAESRecords = [
+                SELECT Id,Rental_Start_Date__c 
+                FROM Rental_Apply_Equipment_Set__c 
+                WHERE Rental_Apply__c = :raid
+                AND Cancel_Select__c = False];
+
+        for (Integer i = 0; i < RAESRecords.size(); i++) {
+            // 澶囧搧棰勮鍑哄簱鏃ヤ笉涓�鑷达紝涓嶅彲鍑哄簱鎸囩ず
+            if (RAESRecords[i].Rental_Start_Date__c != RAESRecords[0].Rental_Start_Date__c) {
+                return '澶囧搧棰勮鍑鸿揣鏃ヤ笉涓�鑷达紝涓嶅彲鍑哄簱鎸囩ず';
+            }
+        }
+        // add lc 20220927 SFDC-CJ48VE 澶囧搧棰勮鍑哄簱鏃ラ�昏緫璋冩暣 end
+
+        Rental_Apply__c ra = new Rental_Apply__c(Id = raesds[0].Rental_Apply__c, Status__c = '宸插嚭搴撴寚绀�');
+        update ra;
+        Database.SaveResult[] results = Database.update(raesds);
+        Database.SaveResult dmlResult = results[0];
+        if (dmlResult.isSuccess()) {
+            //鏄庣粏鏇存柊鎴愬姛鍚庢墠鏇存柊涓�瑙堢殑Rental_Asset_SerialNumber__c
+            soql = 'SELECT Id, SerialNumber_text__c, Rental_Apply_Equipment_Set__c '
+                    +'FROM Rental_Apply_Equipment_Set_Detail__c '
+                    +'WHERE Rental_Apply__c = \'' + raesds[0].Rental_Apply__c + '\''
+                    +'AND Shipment_request_time2__c != null '
+                    +'AND Shipment_request__c = true '
+                    +'AND SerialNumber_text__c != null '
+                    +'ORDER BY Rental_Apply_Equipment_Set__c ';
+
+
+            List<Rental_Apply_Equipment_Set_Detail__c> raesdSerialNumbers = Database.query(soql);
+
+            for (Rental_Apply_Equipment_Set_Detail__c raesd : raesdSerialNumbers) {
+
+                if (!rental_Asset_SerialNumberMap.containsKey(raesd.Rental_Apply_Equipment_Set__c)) {
+                    // Asset__r.SerialNumber + ','
+                    rental_Asset_SerialNumberMap.put(raesd.Rental_Apply_Equipment_Set__c, new List<String>());
+                }
+                rental_Asset_SerialNumberMap.get(raesd.Rental_Apply_Equipment_Set__c).add(raesd.SerialNumber_text__c);
+            }
+
+            List<Rental_Apply_Equipment_Set__c> raess = new List<Rental_Apply_Equipment_Set__c>();
+            for (Id key : rental_Asset_SerialNumberMap.keySet()) {
+                raess.add(new Rental_Apply_Equipment_Set__c(Id = key,
+                        Rental_Asset_SerialNumber__c = ',' + String.join(rental_Asset_SerialNumberMap.get(key), ',') + ','));
+            }
+            if (!raess.isEmpty()) {
+                update raess;
+            }
+
+            return '鐘舵�佹洿鏂板埌宸插嚭搴撴寚绀�';
+        } else {
+            Database.rollback(sp);
+            Database.Error emsg = dmlResult.getErrors()[0];
+            return 'failed to update:' + emsg.getFields() +  ' ' + emsg.getMessage();
+        }
+      } catch (Exception ex) {
+        Database.rollback(sp);
+        return ex.getMessage();
+      }
+    }
+
+    /**
+     * 娉ㄦ畫鐢宠澶囧搧鐨勭鎺�
+     */
+     WebService static String RentalApplyCheckForSAoneEle(String SaID) {
+        Statu_Achievements__c Sac = [select id,
+            SalesChannel__c,
+            Opportunity__r.Sales_Root__c,
+            Status_1__c,
+            Status_2_Formula__c,
+            Opp_Number__c,
+            ContractNO__c,
+            FirstApproveDate__c,
+            CreatedDate,
+            X30_Deposit_Day__c,
+            Deposit_In_Full_Day__c,
+            DeliveryDate__c,
+            Backorder_complete_day__c,
+            DeliveryStatus__c
+        from Statu_Achievements__c where id = :SaID];
+        if(Sac.Opportunity__r.Sales_Root__c == '璨╁2搴�'){
+            if(Sac.Opp_Number__c.contains('GI')||Sac.Opp_Number__c.contains('BF')||Sac.Opp_Number__c.contains('ET') ){
+                //modify by lyh 20220606 start 宸茶喘寰呰揣閫昏緫璋冩暣 
+                //瀹㈡埛GIR璁㈠崟锛屾敞娈嬬姸鎬�2鏄��12浠樺叏娆�-14宸插彂璐р�滆繖涓尯闂翠笖鍙戣揣鐘舵�佷负鈥濇湭浜や粯銆佸拰閮ㄥ垎浜や粯鈥滄椂锛岃嚜浠樻鏃ヨ捣绗�31澶╂湭鐢熸垚鈥濆鎴疯鍗曟渶缁堝彂璐ф棩鈥滄椂锛屾柟鍙互鎻愪氦鈥濆凡璐緟璐р�滅洰鐨勭殑澶囧搧鐢宠
+                //if(Sac.Status_1__c == '娉ㄦ畫' && (Sac.Status_2_Formula__c == '12 宸茶璐с兓浠樺叏娆�'||Sac.Status_2_Formula__c == '13 寰呭彂璐�')){
+                //    if((Date.today().addDays(-30)>Sac.Deposit_In_Full_Day__c)&&Sac.DeliveryDate__c == null){
+                if((Sac.Status_2_Formula__c == '12 宸茶璐с兓浠樺叏娆�' || Sac.Status_2_Formula__c == '13 寰呭彂璐�' || Sac.Status_2_Formula__c == '14 宸插彂璐�')
+                    && (Sac.DeliveryStatus__c == '鏈氦浠�' || Sac.DeliveryStatus__c == '閮ㄥ垎浜や粯')) {
+                    if((Date.today().addDays(-30) > Sac.Deposit_In_Full_Day__c) && Sac.Backorder_complete_day__c == null) {
+                //modify by lyh 20220606 end 宸茶喘寰呰揣閫昏緫璋冩暣
+                        return 'Fin';
+                    } else {
+                        return '缁忛攢鍟嗗唴绉戣鍗曚笉鍦ㄧ敵璇锋湡鍐咃紝涓嶈兘鐢宠澶囧搧';
+                    }
+                }else{
+                    return '缁忛攢鍟嗗唴绉戣鍗曠姸鎬佷笉绗﹀悎澶囧搧鐢宠璧勬牸锛屼笉鑳界敵璇峰鍝�';
+                }
+            }else if(Sac.Opp_Number__c.contains('SP')){
+                //modify by lyh 20220606 start 宸茶喘寰呰揣閫昏緫璋冩暣 
+                //瀹㈡埛SP璁㈠崟锛屾敞娈嬬姸鎬�2鏄��11浠樺畾閲�-14宸插彂璐р�滆繖涓尯闂翠笖鍙戣揣鐘舵�佷负鈥濇湭浜や粯銆佸拰閮ㄥ垎浜や粯鈥滄椂锛岃嚜浠樻鏃ヨ捣绗�61澶╂湭鐢熸垚鈥濆鎴疯鍗曟渶缁堝彂璐ф棩鈥滄椂锛屾柟鍙互鎻愪氦鈥濆凡璐緟璐р�滅洰鐨勭殑澶囧搧鐢宠
+                //if(Sac.Status_1__c == '娉ㄦ畫' && (Sac.Status_2_Formula__c == '11 宸茶璐с兓浠樿閲�'||Sac.Status_2_Formula__c == '12 宸茶璐с兓浠樺叏娆�'||Sac.Status_2_Formula__c == '13 寰呭彂璐�')){
+                //    if((Date.today().addDays(-60)>Sac.X30_Deposit_Day__c )&&Sac.DeliveryDate__c == null){
+                if((Sac.Status_2_Formula__c == '11 宸茶璐с兓浠樿閲�'||Sac.Status_2_Formula__c == '12 宸茶璐с兓浠樺叏娆�'||Sac.Status_2_Formula__c == '13 寰呭彂璐�'||Sac.Status_2_Formula__c=='14 宸插彂璐�')
+                    && (Sac.DeliveryStatus__c == '鏈氦浠�' || Sac.DeliveryStatus__c == '閮ㄥ垎浜や粯')) {
+                    if((Date.today().addDays(-60) > Sac.X30_Deposit_Day__c ) && Sac.Backorder_complete_day__c == null){
+                //modify by lyh 20220606 end 宸茶喘寰呰揣閫昏緫璋冩暣
+                        return 'Fin';
+                    }else{
+                        return '缁忛攢鍟哠P璁㈠崟涓嶅湪鐢宠鏈熷唴锛屼笉鑳界敵璇峰鍝�';
+                    }
+                }else{
+                    return '缁忛攢鍟哠P璁㈠崟鐘舵�佷笉绗﹀悎澶囧搧鐢宠璧勬牸锛屼笉鑳界敵璇峰鍝�';
+                }
+            }else{
+                return '娉ㄦ畫閿�鍞笭閬撶被鍒笉鍦ㄥ彲鐢宠澶囧搧鑼冨洿鍐�';
+            }
+        }else if(Sac.Opportunity__r.Sales_Root__c == 'OCM鐩存帴璨╁2'){
+            if(Sac.Opp_Number__c.contains('GI')||Sac.Opp_Number__c.contains('BF')||Sac.Opp_Number__c.contains('ET')){
+                //modify by lyh 20220606 start 宸茶喘寰呰揣閫昏緫璋冩暣 
+                //娉ㄦ畫鐘舵��2鏄��9宸插綍璁㈠崟鏈粯娆�-14宸插彂璐р�滆繖涓尯闂翠笖鍙戣揣鐘舵�佷负鈥濇湭浜や粯銆佸拰閮ㄥ垎浜や粯鈥滀笖鈥滈攢鍞笭閬撲负鐩撮攢鏃垛�濓紝GIR璁㈠崟鑷鍗曞綍鍏ユ棩璧风31澶�/鏈敓鎴愨�濆鎴疯鍗曟渶缁堝彂璐ф棩鈥滄椂锛屾柟鍙互鎻愪氦鈥濆凡璐緟璐р�滅洰鐨勭殑澶囧搧鐢宠
+                //if(Sac.Status_1__c == '娉ㄦ畫' && (Sac.Status_2_Formula__c == '09 宸插綍鍏ヨ鍗曟湭浠樻'||Sac.Status_2_Formula__c == '10 搴撳瓨宸查鐣欍兓鏈粯娆�'||Sac.Status_2_Formula__c == '11 宸茶璐с兓浠樿閲�'||Sac.Status_2_Formula__c == '12 宸茶璐с兓浠樺叏娆�'||Sac.Status_2_Formula__c == '13 寰呭彂璐�')){
+                //    if((Date.today().addDays(-30)>Sac.FirstApproveDate__c )&&Sac.DeliveryDate__c == null){
+                if((Sac.Status_2_Formula__c == '09 宸插綍鍏ヨ鍗曟湭浠樻'||Sac.Status_2_Formula__c == '10 搴撳瓨宸查鐣欍兓鏈粯娆�'||Sac.Status_2_Formula__c == '11 宸茶璐с兓浠樿閲�'||Sac.Status_2_Formula__c == '12 宸茶璐с兓浠樺叏娆�'||Sac.Status_2_Formula__c == '13 寰呭彂璐�'||Sac.Status_2_Formula__c=='14 宸插彂璐�')
+                    && (Sac.DeliveryStatus__c == '鏈氦浠�' || Sac.DeliveryStatus__c == '閮ㄥ垎浜や粯')){
+                    if((Date.today().addDays(-30) > Sac.FirstApproveDate__c ) && Sac.Backorder_complete_day__c == null) {
+                //modify by lyh 20220606 end 宸茶喘寰呰揣閫昏緫璋冩暣
+                        return 'Fin';
+                    }else{
+                        return 'OCM鐩撮攢鍐呯璁㈠崟涓嶅湪鐢宠鏈熷唴锛屼笉鑳界敵璇峰鍝�';
+                    }
+                }else{
+                    return 'OCM鐩撮攢鍐呯璁㈠崟鐘舵�佷笉绗﹀悎澶囧搧鐢宠璧勬牸锛屼笉鑳界敵璇峰鍝�';
+                }
+            }else if(Sac.Opp_Number__c.contains('SP')){
+                    //modify by lyh 20220606 start 宸茶喘寰呰揣閫昏緫璋冩暣 
+                    //娉ㄦ畫鐘舵��2鏄��9宸插綍璁㈠崟鏈粯娆�-14宸插彂璐р�滆繖涓尯闂翠笖鍙戣揣鐘舵�佷负鈥濇湭浜や粯銆佸拰閮ㄥ垎浜や粯鈥滀笖鈥滈攢鍞笭閬撲负鐩撮攢鏃垛�濓紝SP璁㈠崟61澶╂湭鐢熸垚鈥濆鎴疯鍗曟渶缁堝彂璐ф棩鈥滄椂锛屾柟鍙互鎻愪氦鈥濆凡璐緟璐р�滅洰鐨勭殑澶囧搧鐢宠
+                    //if(Sac.Status_1__c == '娉ㄦ畫' && (Sac.Status_2_Formula__c == '09 宸插綍鍏ヨ鍗曟湭浠樻'||Sac.Status_2_Formula__c == '10 搴撳瓨宸查鐣欍兓鏈粯娆�'||Sac.Status_2_Formula__c == '11 宸茶璐с兓浠樿閲�'||Sac.Status_2_Formula__c == '12 宸茶璐с兓浠樺叏娆�'||Sac.Status_2_Formula__c == '13 寰呭彂璐�')){
+                    //    if((Date.today().addDays(-60)>Sac.FirstApproveDate__c )&&Sac.DeliveryDate__c == null){
+                    if((Sac.Status_2_Formula__c == '09 宸插綍鍏ヨ鍗曟湭浠樻'||Sac.Status_2_Formula__c == '10 搴撳瓨宸查鐣欍兓鏈粯娆�'||Sac.Status_2_Formula__c == '11 宸茶璐с兓浠樿閲�'||Sac.Status_2_Formula__c == '12 宸茶璐с兓浠樺叏娆�'||Sac.Status_2_Formula__c == '13 寰呭彂璐�'||Sac.Status_2_Formula__c=='14 宸插彂璐�')
+                        && (Sac.DeliveryStatus__c == '鏈氦浠�' || Sac.DeliveryStatus__c == '閮ㄥ垎浜や粯')) {
+                        if((Date.today().addDays(-60) > Sac.FirstApproveDate__c ) && Sac.Backorder_complete_day__c == null) {
+                    //modify by lyh 20220606 end 宸茶喘寰呰揣閫昏緫璋冩暣   
+                            return 'Fin';
+                        }else{
+                            return 'OCM鐩撮攢SP璁㈠崟涓嶅湪鐢宠鏈熷唴锛屼笉鑳界敵璇峰鍝�';
+                        }
+                    }else{
+                        return 'OCM鐩撮攢SP璁㈠崟鐘舵�佷笉绗﹀悎澶囧搧鐢宠璧勬牸锛屼笉鑳界敵璇峰鍝�';
+                    }
+                }else{
+                    return '娉ㄦ畫閿�鍞笭閬撶被鍒笉鍦ㄥ彲鐢宠澶囧搧鑼冨洿鍐呫��';
+                }
+        }else{
+            return '閿�鍞笭閬撴湭鐭ワ紝涓嶈兘鏂板缓';
+        }
+     }
+
+
+//bp2
+    //public static String RentalApplyCheckForSA(String raid,String SaID) {
+    //    List<String> ProList = new List<String>();
+    //    if(raid!=null){
+    //        Rental_Apply__c Ra = [select id,
+    //            Product_category__c,
+    //            ProductNameNum1__c,
+    //            ProductNameNum10__c,
+    //            ProductNameNum2__c,
+    //            ProductNameNum3__c,
+    //            ProductNameNum4__c,
+    //            ProductNameNum5__c,
+    //            ProductNameNum6__c,
+    //            ProductNameNum7__c,
+    //            ProductNameNum8__c,
+    //            ProductNameNum9__c
+    //        from
+    //            Rental_Apply__c
+    //        where 
+    //            id=: Raid];
+    //        ProList.add(Ra.ProductNameNum1__c);
+    //         ProList.add(Ra.ProductNameNum2__c);
+    //          ProList.add(Ra.ProductNameNum3__c);
+    //           ProList.add(Ra.ProductNameNum4__c);
+    //            ProList.add(Ra.ProductNameNum5__c);
+    //             ProList.add(Ra.ProductNameNum6__c);
+    //              ProList.add(Ra.ProductNameNum7__c);
+    //               ProList.add(Ra.ProductNameNum8__c);
+    //                ProList.add(Ra.ProductNameNum9__c);
+    //                 ProList.add(Ra.ProductNameNum10__c);
+    //    List<asset> ast = [select
+    //                            id,
+                                
+    //                            Backorder__c 
+    //                        from
+    //                            asset
+    //                        where
+    //                            Backorder__c =:SaID];
+    //    for(asset asl : ast){
+    //        for(String proStr : ProList){
+    //            if(asl.Id == proStr){
+    //                return '浜у搧宸插彂璐э紝涓嶈兘鐢宠澶囧搧';
+    //            }
+    //        }
+    //    }
+    //    }
+        
+    
+    //    Statu_Achievements__c Sac = [select id,
+    //        SalesChannel__c,
+    //        Status_1__c,
+    //        Status_2_Formula__c,
+    //        Opp_Number__c,
+    //        CreatedDate,
+    //        FirstApproveDate__c,
+    //        Opportunity__r.Sales_Root__c,
+    //        X30_Deposit_Day__c,
+    //        Deposit_In_Full_Day__c,
+    //        DeliveryDate__c
+    //    from Statu_Achievements__c where id = :SaID];
+        
+        
+        
+    //    if(Sac.Opportunity__r.Sales_Root__c == '璨╁2搴�'){
+    //        if(Sac.Opp_Number__c.contains('GI')||Sac.Opp_Number__c.contains('BF')||Sac.Opp_Number__c.contains('ET') ){
+    //            if(Sac.Status_1__c == '娉ㄦ畫' && (Sac.Status_2_Formula__c == '12 宸茶璐с兓浠樺叏娆�'||Sac.Status_2_Formula__c == '13 寰呭彂璐�')){
+    //                if((Date.today().addDays(-30)>Sac.Deposit_In_Full_Day__c)&&Sac.DeliveryDate__c == null){
+    //                    return 'Fin';
+    //                }else{
+    //                    return '缁忛攢鍟嗗唴绉戣鍗曚笉鍦ㄧ敵璇锋湡鍐咃紝涓嶈兘鐢宠澶囧搧';
+    //                }
+    //            }else{
+    //                return '缁忛攢鍟嗗唴绉戣鍗曠姸鎬佷笉绗﹀悎澶囧搧鐢宠璧勬牸锛屼笉鑳界敵璇峰鍝�';
+    //            }
+    //        }else if(Sac.Opp_Number__c.contains('SP')){
+    //            if(Sac.Status_1__c == '娉ㄦ畫' && (Sac.Status_2_Formula__c == '11 宸茶璐с兓浠樿閲�'||Sac.Status_2_Formula__c == '12 宸茶璐с兓浠樺叏娆�'||Sac.Status_2_Formula__c == '13 寰呭彂璐�')){
+    //                if((Date.today().addDays(-60)>Sac.X30_Deposit_Day__c )&&Sac.DeliveryDate__c == null){
+    //                    return 'Fin';
+    //                }else{
+    //                    return '缁忛攢鍟哠P璁㈠崟涓嶅湪鐢宠鏈熷唴锛屼笉鑳界敵璇峰鍝�';
+    //                }
+    //            }else{
+    //                return '缁忛攢鍟哠P璁㈠崟鐘舵�佷笉绗﹀悎澶囧搧鐢宠璧勬牸锛屼笉鑳界敵璇峰鍝�';
+    //            }
+    //        }else{
+    //            return 'Denied';
+    //        }
+    //    }else if(Sac.Opportunity__r.Sales_Root__c == 'OCM鐩存帴璨╁2'){
+    //        if(Sac.Opp_Number__c.contains('GI')||Sac.Opp_Number__c.contains('BF')||Sac.Opp_Number__c.contains('ET')){
+    //            if(Sac.Status_1__c == '娉ㄦ畫' && (Sac.Status_2_Formula__c == '09 宸插綍鍏ヨ鍗曟湭浠樻'||Sac.Status_2_Formula__c == '10 搴撳瓨宸查鐣欍兓鏈粯娆�'||Sac.Status_2_Formula__c == '11 宸茶璐с兓浠樿閲�'||Sac.Status_2_Formula__c == '12 宸茶璐с兓浠樺叏娆�'||Sac.Status_2_Formula__c == '13 寰呭彂璐�')){
+    //                if((Date.today().addDays(-30)>Sac.FirstApproveDate__c )&&Sac.DeliveryDate__c == null){
+    //                    return 'Fin';
+    //                }else{
+    //                    return 'OCM鐩撮攢鍐呯涓嶅湪鐢宠鏈熷唴锛屼笉鑳界敵璇峰鍝�';
+    //                }
+    //            }else{
+    //                 return 'OCM鐩撮攢鍐呯璁㈠崟鐘舵�佷笉绗﹀悎澶囧搧鐢宠璧勬牸锛屼笉鑳界敵璇峰鍝�';
+    //            }
+    //        }else if(Sac.Opp_Number__c.contains('SP')){
+    //            if(Sac.Status_1__c == '娉ㄦ畫' && (Sac.Status_2_Formula__c == '09 宸插綍鍏ヨ鍗曟湭浠樻'||Sac.Status_2_Formula__c == '10 搴撳瓨宸查鐣欍兓鏈粯娆�'||Sac.Status_2_Formula__c == '11 宸茶璐с兓浠樿閲�'||Sac.Status_2_Formula__c == '12 宸茶璐с兓浠樺叏娆�'||Sac.Status_2_Formula__c == '13 寰呭彂璐�')){
+    //                if((Date.today().addDays(-60)>Sac.FirstApproveDate__c )&&Sac.DeliveryDate__c == null){
+    //                    return 'Fin';
+    //                }else{
+    //                    return '鐩撮攢SP璁㈠崟涓嶅湪鐢宠鏈熷唴锛屼笉鑳界敵璇峰鍝�';
+    //                }
+    //            }else{
+    //                 return 'OCM鐩撮攢SP璁㈠崟鐘舵�佷笉绗﹀悎澶囧搧鐢宠璧勬牸锛屼笉鑳界敵璇峰鍝�';
+    //            }
+    //        }else{
+    //            return 'Fin';
+    //        }
+    //    }else{
+    //        return '閿�鍞笭閬撴湭鐭ワ紝涓嶈兘鏂板缓';
+    //    }
+    //}
+
+// bp2
+    ///**
+    //澶囧搧鏄惁鍙互缁х画鎿嶄綔鐨勭鎺�
+    //*/
+    //public static String rentalContiuneCheck(List<Rental_Apply__c> newList,Map<Id, Rental_Apply__c> oldMap){
+    //    List<String> RaidList = new List<String>();
+    //    for(Rental_Apply__c ra : newList){
+    //        RaidList.add(ra.id);
+    //    }
+    //    List<Rental_Apply__c> RaTarList = [select Campaign__c,Repair__c,
+    //                                            Campaign__r.Status,Repair__r.Repair_Final_Inspection_Date__c,Repair__r.Repair_Shipped_Date__c
+    //                                        from Rental_Apply__c 
+    //                                        where id=:RaidList];
+    //    for(Rental_Apply__c RaTar : RaTarList){
+    //    String RsStr = '';
+    //        if( RaTar.Campaign__r.Status == '鍙栨秷'||
+    //                RaTar.Campaign__r.Status == '鍙栨秷鐢宠涓�'||
+    //                    RaTar.Campaign__r.Status == '宸叉彁浜ゆ姤鍛�'||
+    //                        RaTar.Campaign__r.Status == '宸茬粨鏉�'){
+    //            RsStr = RentalApplyWebService.rentalContiuneinfoCheck(newList,oldMap);
+    //            if(RsStr == 'Denied'){
+    //                return '瀛︿細宸茬粨鏉燂紝鐢宠鍗曚笉鑳界户缁搷浣滀簡';
+    //            }else{
+    //                return 'Fin';
+    //            }
+                
+    //        }else if(   RaTar.Repair__r.Repair_Final_Inspection_Date__c!=null){
+    //            RsStr = RentalApplyWebService.rentalContiuneinfoCheck(newList,oldMap);
+    //            if(RsStr == 'Denied'){
+    //                return '瀛樺湪淇悊鏈�缁堟娴嬫棩锛岀敵璇峰崟涓嶈兘缁х画浜�';
+    //            }else{
+    //                return 'Fin';
+    //            }
+    //        }else if(   RaTar.Repair__r.Repair_Shipped_Date__c!=null){
+    //            RsStr = RentalApplyWebService.rentalContiuneinfoCheck(newList,oldMap);
+    //            if(RsStr == 'Denied'){
+    //                return '瀛樺湪RC淇悊杩旈�佹棩锛岀敵璇峰崟涓嶈兘缁х画浜�';
+    //            }else{
+    //                return 'Fin';
+    //            }
+    //        }else{
+    //            return 'Fin';
+    //        }
+    //    }
+    //    return 'Fin';
+    //}
+//bp2
+//    public static String rentalContiuneinfoCheck(List<Rental_Apply__c> newList,Map<Id, Rental_Apply__c> oldMap){
+//        for(Rental_Apply__c Rac : newList){
+//        if(
+//    //bp2  Trigger.oldMap.get(Rac.Id).get('HP_received_ng_num__c') != Rac.HP_received_ng_num__c ||
+//            Trigger.oldMap.get(Rac.Id).get('StockDown_ng_num__c') != Rac.StockDown_ng_num__c ||
+//             Trigger.oldMap.get(Rac.Id).get('Asset_return_time__c') != Rac.Asset_return_time__c ||
+//              Trigger.oldMap.get(Rac.Id).get('Count_Extend__c') != Rac.Count_Extend__c ||
+//                Trigger.oldMap.get(Rac.Id).get('Max_Extend_workday__c') != Rac.Max_Extend_workday__c ||
+//    //bp2        Trigger.oldMap.get(Rac.Id).get('Lost_item_ng_num__c') != Rac.Lost_item_ng_num__c ||
+//                  Trigger.oldMap.get(Rac.Id).get('Lost_item_finish__c') != Rac.Lost_item_finish__c ||
+//                   Trigger.oldMap.get(Rac.Id).get('Last_Assigned_Date__c') != Rac.Last_Assigned_Date__c ||
+//                    Trigger.oldMap.get(Rac.Id).get('Return_dadeline_final__c') != Rac.Return_dadeline_final__c ||
+//                     Trigger.oldMap.get(Rac.Id).get('Rental_Apply_Equipment_Set_Cnt__c') != Rac.Rental_Apply_Equipment_Set_Cnt__c ||
+//                      Trigger.oldMap.get(Rac.Id).get('Pre_inspection_ng_num__c') != Rac.Pre_inspection_ng_num__c ||
+//                       Trigger.oldMap.get(Rac.Id).get('Shippment_ng_num__c') != Rac.Shippment_ng_num__c ||
+//                        Trigger.oldMap.get(Rac.Id).get('ShelfUp_ng_num__c') != Rac.ShelfUp_ng_num__c ||
+//                         Trigger.oldMap.get(Rac.Id).get('Loaner_received_ng_num__c') != Rac.Loaner_received_ng_num__c ||
+//                          Trigger.oldMap.get(Rac.Id).get('Arrival_wh_cnt__c') != Rac.Arrival_wh_cnt__c ||
+//                           Trigger.oldMap.get(Rac.Id).get('Shippment_loaner_cnt__c') != Rac.Shippment_loaner_cnt__c ||
+//                            Trigger.oldMap.get(Rac.Id).get('Shipment_requested_cnt__c') != Rac.Shipment_requested_cnt__c ||
+//                             Trigger.oldMap.get(Rac.Id).get('Pre_inspection_ng_cnt2__c') != Rac.Pre_inspection_ng_cnt2__c ||
+//                              Trigger.oldMap.get(Rac.Id).get('Pre_inspection_ng_cnt__c') != Rac.Pre_inspection_ng_cnt__c ||
+//                               Trigger.oldMap.get(Rac.Id).get('Shippment_loaner_time__c') != Rac.Shippment_loaner_time__c ||
+//                                Trigger.oldMap.get(Rac.Id).get('Asset_loaner_closed_date__c') != Rac.Asset_loaner_closed_date__c ||
+//                                 Trigger.oldMap.get(Rac.Id).get('Asset_loaner_start_date__c') != Rac.Asset_loaner_start_date__c ||
+//                                  Trigger.oldMap.get(Rac.Id).get('Disposal_num__c') != Rac.Disposal_num__c ||
+//                                   Trigger.oldMap.get(Rac.Id).get('Asset_return_ng_num__c') != Rac.Asset_return_ng_num__c ||
+//                                    Trigger.oldMap.get(Rac.Id).get('Received_Confirm_NG_amount__c') != Rac.Received_Confirm_NG_amount__c ||
+//                                     Trigger.oldMap.get(Rac.Id).get('Received_Confirm_NG_Not_Return__c') != Rac.Received_Confirm_NG_Not_Return__c ||
+////bp2                                 Trigger.oldMap.get(Rac.Id).get('Loaner_received_time__c') != Rac.Loaner_received_time__c ||
+//                                       Trigger.oldMap.get(Rac.Id).get('Return_Track_Company__c') != Rac.Return_Track_Company__c ||
+//                                        Trigger.oldMap.get(Rac.Id).get('Return_Distrubutor_Method__c') != Rac.Return_Distrubutor_Method__c ||
+//                                         Trigger.oldMap.get(Rac.Id).get('Return_Trake_Staff__c') != Rac.Return_Trake_Staff__c ||
+//                                          Trigger.oldMap.get(Rac.Id).get('Return_Track_Number__c') != Rac.Return_Track_Number__c ||
+//                                          Trigger.oldMap.get(Rac.Id).get('HP_received_sign_day__c') != Rac.HP_received_sign_day__c ||
+//                                         Trigger.oldMap.get(Rac.Id).get('HP_received_sign_rich__c') != Rac.HP_received_sign_rich__c ||
+//                                        Trigger.oldMap.get(Rac.Id).get('HP_received_sign_text__c') != Rac.HP_received_sign_text__c ||
+//                                       Trigger.oldMap.get(Rac.Id).get('HP_received_sign_NG__c') != Rac.HP_received_sign_NG__c ||
+//                                      Trigger.oldMap.get(Rac.Id).get('HP_received_sign_NG_Reason__c') != Rac.HP_received_sign_NG_Reason__c ||
+//                                     Trigger.oldMap.get(Rac.Id).get('AssetManageConfirm__c') != Rac.AssetManageConfirm__c ||
+//                                    Trigger.oldMap.get(Rac.Id).get('Loaner_cancel_request__c') != Rac.Loaner_cancel_request__c ||
+//                                   Trigger.oldMap.get(Rac.Id).get('Status__c') != Rac.Status__c 
+//        ){
+//        return 'Fin';
+//    }
+//}   
+//    return 'Denied';
+//    }
+}
\ No newline at end of file
diff --git a/force-app/main/default/classes/RentalApplyWebService.cls-meta.xml b/force-app/main/default/classes/RentalApplyWebService.cls-meta.xml
new file mode 100644
index 0000000..94f6f06
--- /dev/null
+++ b/force-app/main/default/classes/RentalApplyWebService.cls-meta.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
+    <apiVersion>40.0</apiVersion>
+    <status>Active</status>
+</ApexClass>
diff --git a/force-app/main/default/classes/loanerArrangedEmailController.cls b/force-app/main/default/classes/loanerArrangedEmailController.cls
new file mode 100644
index 0000000..bb34d2f
--- /dev/null
+++ b/force-app/main/default/classes/loanerArrangedEmailController.cls
@@ -0,0 +1,95 @@
+public with sharing class loanerArrangedEmailController {
+
+	
+
+    public loanerArrangedEmailController() {
+    }
+
+    @AuraEnabled
+    public static InitData init(String recordId) {
+    	String statusSting = Label.StatusProcessState;
+		List<String> status = statusSting.split(',');
+    	InitData res = new InitData();
+    	try {
+    	    Rental_Apply__c rac = [SELECT Id, Status__c, Campaign__c, RC_return_to_office__c, Repair_Final_Inspection_Date_F__c, Repair__c, Assigned_Not_Shipment__c, Demo_purpose1__c, Contract_pdf_updated__c, Wei_Assigned_Cnt__c from Rental_Apply__c where Id = :recordId];
+
+    	    if( rac.Campaign__c != null ){
+    	    	//鑾峰彇瀛︿細瀵硅薄
+    	    	Campaign camp = [select Id, Status, Rental_Apply_Flag__c,IF_Approved__c,Approved_Status__c, Meeting_Approved_No__c from Campaign where id = :rac.Campaign__c];
+    	    	res.CampaignId = camp.Id;
+    	    	res.CampaignStatus = camp.Status;
+    	    	res.IFApproved = camp.IF_Approved__c;
+	    	    res.MeetingApprovedNo = camp.Meeting_Approved_No__c;
+	    	    res.ApprovedStatus = camp.Approved_Status__c;
+    	    }   
+    	    res.Id = recordId;   
+    	    res.RaStatus = rac.Status__c;
+    	    res.WeiAssignedCnt = Integer.valueOf(rac.Wei_Assigned_Cnt__c);
+    	    res.AssignedNotShipment = Integer.valueOf(rac.Assigned_Not_Shipment__c);
+    	    res.DemoPurpose1 = rac.Demo_purpose1__c;
+    	    res.ContractPdfUpdated = rac.Contract_pdf_updated__c;
+    	    res.RepairId = rac.Repair__c;
+    	    res.RepairFinalInspectionDateF = rac.Repair_Final_Inspection_Date_F__c;
+    	    res.RCReturnToOffice = rac.RC_return_to_office__c;
+    	    res.StatusList = status;
+    	}
+    	catch (Exception e) {
+    	    System.debug(LoggingLevel.INFO, '****e:' + e);
+    	}
+    	system.debug('res======'+res);
+    	return res;
+    }
+
+    
+    //鑾峰彇澶囧搧鍊熷嚭涓�鏍�
+    @AuraEnabled
+    public static Integer getRentalApplyEquipmentSet(String recordId) {
+    	Rental_Apply__c tempRa = [SELECT Id, Bollow_Date__c from Rental_Apply__c where Id = :recordId];
+    	List<Rental_Apply_Equipment_Set__c> tempRaEquipSetList = new List<Rental_Apply_Equipment_Set__c>();
+    	Integer pageLength ;
+    	if(tempRa.Bollow_Date__c != null) {
+    		tempRaEquipSetList = [SELECT Id from Rental_Apply_Equipment_Set__c where Rental_Apply__c = :recordId AND Shippment_loaner_time__c != null and RAES_Status__c != '宸插垎閰�' and RAES_Status__c != '鍙栨秷鍒嗛厤'];
+    	}else {
+    		tempRaEquipSetList = [SELECT Id from Rental_Apply_Equipment_Set__c where Rental_Apply__c = :recordId AND RAES_Status__c != '宸插垎閰�' and RAES_Status__c != '鍙栨秷鍒嗛厤'];
+    	}
+    	//
+    	if(tempRaEquipSetList.size()>0) {
+			Integer setLength = tempRaEquipSetList.size();
+			pageLength = Math.mod(setLength,10) == 0 ? setLength/10 : Math.round(setLength) + 1;
+    	}
+    	return pageLength;
+    }
+
+    public class InitData{
+		@AuraEnabled
+		public String Id;
+		@AuraEnabled
+		public String CampaignStatus;	//瀛︿細鐘舵��
+		@AuraEnabled
+		public String CampaignId;	//瀛︿細Id
+		@AuraEnabled
+		public String RaStatus;		//澶囧搧鍊熷嚭鐢宠鐘舵��
+		@AuraEnabled
+		public Integer WeiAssignedCnt;		//鏈垎閰嶄欢鏁�  Wei_Assigned_Cnt__c
+		@AuraEnabled
+		public Integer AssignedNotShipment;	//宸插垎閰嶆湭鍑哄簱鎸囩ず  Assigned_Not_Shipment__c
+		@AuraEnabled
+		public String DemoPurpose1;			//浣跨敤鐩殑1	 Demo_purpose1__c
+		@AuraEnabled
+		public Boolean ContractPdfUpdated;	//鍚堝悓涔﹀凡涓婁紶	Contract_pdf_updated__c
+		@AuraEnabled
+		public String RepairId;				//瀛︿細.淇悊Id
+		@AuraEnabled
+		public Date RepairFinalInspectionDateF;		//淇悊鏈�缁堟娴嬫棩F  	Repair_Final_Inspection_Date_F__c
+		@AuraEnabled
+		public Date RCReturnToOffice;		//RC淇悊鍝佽繑閫佹棩		RC_return_to_office__c
+		@AuraEnabled
+		public Boolean IFApproved;			//瀛︿細.鏄惁闇�瑕佺敵璇峰喅瑁�
+		@AuraEnabled
+		public String MeetingApprovedNo;	//瀛︿細.浼氳鍐宠缂栫爜
+		@AuraEnabled
+		public String ApprovedStatus;		//瀛︿細.鍐宠鐘舵��	Approved_Status__c
+		@AuraEnabled
+		public List<String> StatusList;
+	}
+}
\ No newline at end of file
diff --git a/force-app/main/default/classes/loanerArrangedEmailController.cls-meta.xml b/force-app/main/default/classes/loanerArrangedEmailController.cls-meta.xml
new file mode 100644
index 0000000..d75b058
--- /dev/null
+++ b/force-app/main/default/classes/loanerArrangedEmailController.cls-meta.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
+    <apiVersion>51.0</apiVersion>
+    <status>Active</status>
+</ApexClass>
diff --git a/force-app/main/default/lwc/lexLoanerArrangedEmail/lexLoanerArrangedEmail.css b/force-app/main/default/lwc/lexLoanerArrangedEmail/lexLoanerArrangedEmail.css
new file mode 100644
index 0000000..ebb43d9
--- /dev/null
+++ b/force-app/main/default/lwc/lexLoanerArrangedEmail/lexLoanerArrangedEmail.css
@@ -0,0 +1,10 @@
+.exampleHolder{
+    position: relative;
+    display: inline-block;
+    width: 80px;
+    height: 80px;
+    text-align: center;
+}
+.container .uiContainerManager{
+	display: none !important;
+}
\ No newline at end of file
diff --git a/force-app/main/default/lwc/lexLoanerArrangedEmail/lexLoanerArrangedEmail.html b/force-app/main/default/lwc/lexLoanerArrangedEmail/lexLoanerArrangedEmail.html
new file mode 100644
index 0000000..3eff9e8
--- /dev/null
+++ b/force-app/main/default/lwc/lexLoanerArrangedEmail/lexLoanerArrangedEmail.html
@@ -0,0 +1,5 @@
+<template>
+    <div class="EquipmentRentalPDF" if:true={IsLoading}>
+        <lightning-spinner alternative-text="Loading" size="medium"></lightning-spinner>
+    </div>
+</template>
\ No newline at end of file
diff --git a/force-app/main/default/lwc/lexLoanerArrangedEmail/lexLoanerArrangedEmail.js b/force-app/main/default/lwc/lexLoanerArrangedEmail/lexLoanerArrangedEmail.js
new file mode 100644
index 0000000..3916190
--- /dev/null
+++ b/force-app/main/default/lwc/lexLoanerArrangedEmail/lexLoanerArrangedEmail.js
@@ -0,0 +1,102 @@
+import { LightningElement, track, wire, api } from 'lwc';
+import { CurrentPageReference,NavigationMixin } from 'lightning/navigation';
+import { CloseActionScreenEvent } from 'lightning/actions';
+
+import init from '@salesforce/apex/loanerArrangedEmailController.init';
+import getRentalApplyEquipmentSet from '@salesforce/apex/loanerArrangedEmailController.getRentalApplyEquipmentSet';
+import approvalCheck from '@salesforce/apex/RentalApplyWebService.approvalCheck';
+import setShipment_request from '@salesforce/apex/RentalApplyWebService.approvalCheck';
+export default class lexLoanerArrangedEmail extends LightningElement {
+	@api recordId;
+	IsLoading = true;
+
+	@wire(CurrentPageReference)
+	getStateParameters(currentPageReference) {
+		if(currentPageReference) {
+			const urlValue = currentPageReference.state.recordId;
+			if(urlValue) {
+				let str = `${urlValue}`;
+		        this.recordId = str;
+			}
+		}
+	}
+
+	connectedCallback() {
+		init({
+			recordId: this.recordId
+		}).then(result => {
+			console.log(this.recordId);
+			console.log('result==='+JSON.stringify(result));
+			if(result != null) {
+				if( result.WeiAssignedCnt > 0 ) {
+					alert("鐢宠鍗曞唴瀛樺湪鏈垎閰嶇殑閰嶅锛岃鍒嗛厤澶囧搧鎴栧垎鍓茬敵璇峰崟");
+				}else if(result.CampaignStatus == "鍙栨秷") {
+					alert("瀛︿細鍙栨秷锛屼笉鍙嚭搴撴寚绀�"); 
+				}else if (result.RaStatus == "宸插嚭搴撴寚绀�" && result.AssignedNotShipment == 0){
+					alert("鎵�鏈夌殑鍊熷嚭澶囧搧Set涓�瑙堥兘杩涜杩囧嚭搴撴寚绀轰簡");
+				}else if (result.AssignedNotShipment == 0) {
+					alert("娌℃湁鍙互鍑哄簱鎸囩ず鐨勬槑缁�"); 
+				}else if (result.DemoPurpose1 == "闀挎湡鍊熷嚭" && result.ContractPdfUpdated == 0){
+					alert("闀挎湡鍊熷嚭鏃讹紝蹇呴』鍏堜笂浼犲绾︿功"); 
+				}else if (result.RepairId != '' && (result.RepairFinalInspectionDateF != null && result.RepairFinalInspectionDateF != '') || (result.RCReturnToOffice != null && result.RCReturnToOffice != '')){
+					alert("淇悊鏈夋渶缁堟娴嬫棩鎴栦慨鐞嗗搧杩旈�佹棩锛屼笉鍙嚭搴撴寚绀�"); 
+				}else if (result.IFApproved == "true" && (result.MeetingApprovedNo == null || result.MeetingApprovedNo == "")){
+					alert("娌℃湁鍐宠鍙风殑锛屾殏涓嶈兘鍑哄��,璇锋洿鏂拌鍐充俊鎭��"); 
+				}else if (result.IFApproved == "true" && result.MeetingApprovedNo != "" && result.StatusList.indexOf(records[0].Approved_Status__c) != -1){
+					alert("宸茬敵璇峰喅瑁佷絾鍐宠鐘舵�佷笉绗﹀悎鏉′欢銆�"); 
+				}else {
+					approvalCheck({
+						rentalApplyId: this.recordId
+					}).then(res=>{
+						if (res != '1') {
+							alert(rs1);
+						} else {
+							//bp2 var rs2 = sforce.apex.execute("RentalApplyWebService", "reserve", {rentalApplyId: raid});
+							//bp2 if (rs2 != '1') {
+							//bp2 alert(rs2);
+							//bp2 } else {
+							//var rs1 = sforce.apex.execute("RentalApplyWebService", "setShipment_request", {raid : "{!Rental_Apply__c.Id}"}); 
+
+							setShipment_request({
+								raid: this.recordId
+							}).then(res=>{
+								if (res == "鐘舵�佹洿鏂板埌宸插嚭搴撴寚绀�") { 
+									alert("鐘舵�佹洿鏂板埌宸插嚭搴撴寚绀�");
+									print();
+									setTimeout(function() {
+										location.href = "/{!Rental_Apply__c.Id}"; 
+									},100);
+								}else {
+									alert(res);
+								}
+							}).catch(e=>{
+								console.log('approvalCheck==='+e);
+							})
+						}
+					}).catch(e=>{
+						console.log('setShipment_request==='+e);
+					})				
+				}
+				this.dispatchEvent(new CloseActionScreenEvent());
+			}
+		})
+	}
+
+	print() {
+		getRentalApplyEquipmentSet({
+			recordId: this.recordId
+		}).then(result => {
+			window.open("https://ocsm--partial.sandbox.lightning.force.com/apex/FixtureRentalPDF?raid=" + this.recordId + "&page=" + result);
+		})
+	}
+
+	fixDate(date){
+		var Month = fixTime(date.getMonth() + 1);
+		var Day = fixTime(date.getDate());
+		var UTC = date.toUTCString();
+		var Time = UTC.substring(UTC.indexOf(':')-2, UTC.indexOf(':')+6);
+		var Minutes = fixTime(date.getMinutes());
+		var Seconds = fixTime(date.getSeconds());
+		return date.getFullYear() + "-" + Month + "-" + Day + "T" + Time;
+	}
+}
\ No newline at end of file
diff --git a/force-app/main/default/lwc/lexLoanerArrangedEmail/lexLoanerArrangedEmail.js-meta.xml b/force-app/main/default/lwc/lexLoanerArrangedEmail/lexLoanerArrangedEmail.js-meta.xml
new file mode 100644
index 0000000..e261be9
--- /dev/null
+++ b/force-app/main/default/lwc/lexLoanerArrangedEmail/lexLoanerArrangedEmail.js-meta.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
+    <apiVersion>54.0</apiVersion>
+    <isExposed>true</isExposed>
+    <targets>
+        <target>lightning__RecordPage</target>
+        <target>lightning__AppPage</target>
+        <target>lightning__HomePage</target>
+        <target>lightning__RecordAction</target>
+    </targets>
+</LightningComponentBundle>
\ No newline at end of file

--
Gitblit v1.9.1