buli
2023-07-11 0c4796706fc9473d069b620321a54b20a119906c
force-app/main/default/classes/EquipmentSetShippmentReceived3Controller.cls
@@ -38,9 +38,12 @@
            esdIdMap.put(esd.rec.Id, esd.isChecked);
        }
        String qryString = 'select Combine_Pack__c, Name, Id, DeliveryCompany_SlipNo__c,DeliveryType__c,Distributor_method__c,DeliveryCompany__c,Wh_Staff__c '
                + 'from FixtureDeliverySlip__c '
                + 'where Name =\''+ slip.Name +'\' and DeliveryType__c = \'发货\'';
        String qryString =
            'select Combine_Pack__c, Name, Id, DeliveryCompany_SlipNo__c,DeliveryType__c,Distributor_method__c,DeliveryCompany__c,Wh_Staff__c ' +
            'from FixtureDeliverySlip__c ' +
            'where Name =\'' +
            slip.Name +
            '\' and DeliveryType__c = \'发货\'';
        if (String.isNotBlank(slip.Distributor_method__c)) {
            qryString += ' and Distributor_method__c = \''+ slip.Distributor_method__c +'\'';
        }
@@ -56,15 +59,57 @@
            }
            slip = slipList[0];
            List<Rental_Apply_Equipment_Set_Detail__c> eList = [select Rental_Apply__c, Rental_Apply__r.Shippment_ng_num__c, Rental_Apply__r.Pre_inspection_ng_num__c, SerialNumber_F__c, Rental_Apply_Equipment_Set__r.Inspection_not_finish__c, Fixture_Name_F__c, Rental_Apply_Equipment_Set__r.Fixture_Set__r.Name, Rental_Apply_Equipment_Set__r.Rental_Apply__r.Name, Rental_Apply_Equipment_Set__r.Name, Pre_inspection_time__c, StockDown__c, StockDown_time__c, Id, Name, Asset__c, Asset__r.Name, Asset__r.SerialNumber, Asset__r.Product_Serial_No__c,
                           Asset__r.Remark__c, Asset__r.ImageAsset__c, Asset__r.ImageSerial__c, Asset__r.ImageAssetUploadedTime__c, Asset__r.ImageSerialUploadedTime__c,
                           Loaner_CDS_Info__c, Inspection_result__c, Check_lost_Item__c, Pre_disinfection__c, Water_leacage_check__c, Inspection_result_after__c, Arrival_in_wh__c,
                           Asset__r.Pre_Reserve_RAES_Detail__c, Asset__r.Pre_Reserve_RAES_Detail__r.After_Inspection_time__c,
                           Inspection_result_after_ng__c, Inspection_result_ng__c, Lost_item_giveup__c, CDS_complete__c, Loaner_accsessary__c
                      from Rental_Apply_Equipment_Set_Detail__c
                     where (DeliverySlip__c = :slip.Id or Id in :esdIdMap.keySet())
                       and Cancel_Select__c = False and Return_DeliverySlip__c = null
                     order by Rental_Apply_Equipment_Set__r.Rental_Apply__r.Name, Rental_Apply_Equipment_Set__r.Name, Rental_Apply_Equipment_Set__c, Name];
            List<Rental_Apply_Equipment_Set_Detail__c> eList = [
                SELECT
                    Rental_Apply__c,
                    Rental_Apply__r.Shippment_ng_num__c,
                    Rental_Apply__r.Pre_inspection_ng_num__c,
                    SerialNumber_F__c,
                    Rental_Apply_Equipment_Set__r.Inspection_not_finish__c,
                    Fixture_Name_F__c,
                    Rental_Apply_Equipment_Set__r.Fixture_Set__r.Name,
                    Rental_Apply_Equipment_Set__r.Rental_Apply__r.Name,
                    Rental_Apply_Equipment_Set__r.Name,
                    Pre_inspection_time__c,
                    StockDown__c,
                    StockDown_time__c,
                    Id,
                    Name,
                    Asset__c,
                    Asset__r.Name,
                    Asset__r.SerialNumber,
                    Asset__r.Product_Serial_No__c,
                    Asset__r.Remark__c,
                    Asset__r.ImageAsset__c,
                    Asset__r.ImageSerial__c,
                    Asset__r.ImageAssetUploadedTime__c,
                    Asset__r.ImageSerialUploadedTime__c,
                    Loaner_CDS_Info__c,
                    Inspection_result__c,
                    Check_lost_Item__c,
                    Pre_disinfection__c,
                    Water_leacage_check__c,
                    Inspection_result_after__c,
                    Arrival_in_wh__c,
                    Asset__r.Pre_Reserve_RAES_Detail__c,
                    Asset__r.Pre_Reserve_RAES_Detail__r.After_Inspection_time__c,
                    Inspection_result_after_ng__c,
                    Inspection_result_ng__c,
                    Lost_item_giveup__c,
                    CDS_complete__c,
                    Loaner_accsessary__c
                FROM Rental_Apply_Equipment_Set_Detail__c
                WHERE
                    (DeliverySlip__c = :slip.Id
                    OR Id IN :esdIdMap.keySet())
                    AND Cancel_Select__c = FALSE
                    AND Return_DeliverySlip__c = NULL
                ORDER BY
                    Rental_Apply_Equipment_Set__r.Rental_Apply__r.Name,
                    Rental_Apply_Equipment_Set__r.Name,
                    Rental_Apply_Equipment_Set__c,
                    Name
            ];
            esdList.clear();
            for (Rental_Apply_Equipment_Set_Detail__c esd : eList) {
@@ -85,11 +130,21 @@
        List<String> ids = ApplyId.split(',');
        Set<String> checkedIds = new Set<String>(CheckedId.split(':'));
        CheckedId = null;
        List<Rental_Apply_Equipment_Set__c> esList = [select Rental_Apply__r.Name, First_RAESD_Model_No_F__c, First_RAESD__r.SerialNumber_F__c, First_RAESD__r.Loaner_asset_no__c, Rental_Apply__c, Id, RAES_Status__c, Name, Shippment_loaner_time2__c
                                    from Rental_Apply_Equipment_Set__c
                                    where (Rental_Apply__r.Name in :ids or Id in :ids)
                                      AND Cancel_Select__c = False
                                    order by Rental_Apply__r.Name, Id];
        List<Rental_Apply_Equipment_Set__c> esList = [
            SELECT
                Rental_Apply__r.Name,
                First_RAESD_Model_No_F__c,
                First_RAESD__r.SerialNumber_F__c,
                First_RAESD__r.Loaner_asset_no__c,
                Rental_Apply__c,
                Id,
                RAES_Status__c,
                Name,
                Shippment_loaner_time2__c
            FROM Rental_Apply_Equipment_Set__c
            WHERE (Rental_Apply__r.Name IN :ids OR Id IN :ids) AND Cancel_Select__c = FALSE
            ORDER BY Rental_Apply__r.Name, Id
        ];
        Set<Id> esIds = new Set<Id>();
        Set<Id> esdIds = new Set<Id>();
        Set<Id> applySet = new Set<Id>();
@@ -102,15 +157,55 @@
            esdIds.add(raesd.rec.Id);
        }
        List<Rental_Apply_Equipment_Set_Detail__c> eList = [
                select Rental_Apply__c, Rental_Apply__r.Shippment_ng_num__c, Rental_Apply__r.Pre_inspection_ng_num__c, SerialNumber_F__c, Rental_Apply_Equipment_Set__r.Inspection_not_finish__c, Fixture_Name_F__c, Rental_Apply_Equipment_Set__r.Fixture_Set__r.Name, Rental_Apply_Equipment_Set__r.Rental_Apply__r.Name, Rental_Apply_Equipment_Set__r.Name, Pre_inspection_time__c, StockDown__c, StockDown_time__c, Id, Name, Asset__c, Asset__r.Name, Asset__r.SerialNumber, Asset__r.Product_Serial_No__c,
                       Asset__r.Remark__c, Asset__r.ImageAsset__c, Asset__r.ImageSerial__c, Asset__r.ImageAssetUploadedTime__c, Asset__r.ImageSerialUploadedTime__c,
                       Loaner_CDS_Info__c, Inspection_result__c, Check_lost_Item__c, Pre_disinfection__c, Water_leacage_check__c, Inspection_result_after__c, Arrival_in_wh__c,
                       Asset__r.Pre_Reserve_RAES_Detail__c, Asset__r.Pre_Reserve_RAES_Detail__r.After_Inspection_time__c,
                       Inspection_result_after_ng__c, Inspection_result_ng__c, Lost_item_giveup__c, CDS_complete__c, Loaner_accsessary__c
                  from Rental_Apply_Equipment_Set_Detail__c
                 where Rental_Apply_Equipment_Set__c in :esIds and DeliverySlip__c = null and Return_DeliverySlip__c = null //and Inspection_result__c <> null and Shipment_request_time2__c <> null
                   and Cancel_Select__c = False
                 order by Rental_Apply_Equipment_Set__r.Rental_Apply__r.Name, Rental_Apply_Equipment_Set__r.Name, Rental_Apply_Equipment_Set__c, Name
            SELECT
                Rental_Apply__c,
                Rental_Apply__r.Shippment_ng_num__c,
                Rental_Apply__r.Pre_inspection_ng_num__c,
                SerialNumber_F__c,
                Rental_Apply_Equipment_Set__r.Inspection_not_finish__c,
                Fixture_Name_F__c,
                Rental_Apply_Equipment_Set__r.Fixture_Set__r.Name,
                Rental_Apply_Equipment_Set__r.Rental_Apply__r.Name,
                Rental_Apply_Equipment_Set__r.Name,
                Pre_inspection_time__c,
                StockDown__c,
                StockDown_time__c,
                Id,
                Name,
                Asset__c,
                Asset__r.Name,
                Asset__r.SerialNumber,
                Asset__r.Product_Serial_No__c,
                Asset__r.Remark__c,
                Asset__r.ImageAsset__c,
                Asset__r.ImageSerial__c,
                Asset__r.ImageAssetUploadedTime__c,
                Asset__r.ImageSerialUploadedTime__c,
                Loaner_CDS_Info__c,
                Inspection_result__c,
                Check_lost_Item__c,
                Pre_disinfection__c,
                Water_leacage_check__c,
                Inspection_result_after__c,
                Arrival_in_wh__c,
                Asset__r.Pre_Reserve_RAES_Detail__c,
                Asset__r.Pre_Reserve_RAES_Detail__r.After_Inspection_time__c,
                Inspection_result_after_ng__c,
                Inspection_result_ng__c,
                Lost_item_giveup__c,
                CDS_complete__c,
                Loaner_accsessary__c
            FROM Rental_Apply_Equipment_Set_Detail__c
            WHERE
                Rental_Apply_Equipment_Set__c IN :esIds
                AND DeliverySlip__c = NULL
                AND Return_DeliverySlip__c = NULL //and Inspection_result__c <> null and Shipment_request_time2__c <> null
                AND Cancel_Select__c = FALSE
            ORDER BY
                Rental_Apply_Equipment_Set__r.Rental_Apply__r.Name,
                Rental_Apply_Equipment_Set__r.Name,
                Rental_Apply_Equipment_Set__c,
                Name
        ];
        //esdList.clear();
        for (Rental_Apply_Equipment_Set_Detail__c esd : eList) {
@@ -143,14 +238,24 @@
            system.debug('==================='+Id);
            // 当前User
            String userid = Userinfo.getUserId();
            User user = [select Id,Name from User where Id = :userid];
            User user = [SELECT Id, Name FROM User WHERE Id = :userid];
            List<Rental_Apply_Equipment_Set__c> esList;
            List<String> ids = Id.split(',');
            esList = [select Rental_Apply__r.Name, First_RAESD_Model_No_F__c, First_RAESD__r.SerialNumber_F__c, First_RAESD__r.Loaner_asset_no__c, Rental_Apply__c, Id, RAES_Status__c, Name, Shippment_loaner_time2__c
                                        from Rental_Apply_Equipment_Set__c
                                       where (Rental_Apply__r.Name in :ids or Id in:ids)
                                         AND Cancel_Select__c = False
                                       order by Rental_Apply__r.Name, Id];
            esList = [
                SELECT
                    Rental_Apply__r.Name,
                    First_RAESD_Model_No_F__c,
                    First_RAESD__r.SerialNumber_F__c,
                    First_RAESD__r.Loaner_asset_no__c,
                    Rental_Apply__c,
                    Id,
                    RAES_Status__c,
                    Name,
                    Shippment_loaner_time2__c
                FROM Rental_Apply_Equipment_Set__c
                WHERE (Rental_Apply__r.Name IN :ids OR Id IN :ids) AND Cancel_Select__c = FALSE
                ORDER BY Rental_Apply__r.Name, Id
            ];
         //   if (Step_status == '追加') {
            //} else {
@@ -211,21 +316,60 @@
            // system.debug('All::::'+Rac.repair__c);
            //  system.debug('All::::'+Ra_c.RAES_Status__c);
            // 本番暂不上线该功能,启用后不能入库操作感觉不对
        }
        // 备品set明细
        List<Rental_Apply_Equipment_Set_Detail__c> eList = [
                select Rental_Apply__c, Rental_Apply__r.Shippment_ng_num__c, Rental_Apply__r.Pre_inspection_ng_num__c, SerialNumber_F__c, Rental_Apply_Equipment_Set__r.Inspection_not_finish__c, Fixture_Name_F__c, Rental_Apply_Equipment_Set__r.RAES_Status__c, Rental_Apply_Equipment_Set__r.Fixture_Set__r.Name, Rental_Apply_Equipment_Set__r.Rental_Apply__r.Name, Rental_Apply_Equipment_Set__r.Name, Pre_inspection_time__c, StockDown__c, StockDown_time__c, Id, Name, Asset__c, Asset__r.Name, Asset__r.SerialNumber, Asset__r.Product_Serial_No__c,
                       Asset__r.Remark__c, Asset__r.ImageAsset__c, Asset__r.ImageSerial__c, Asset__r.ImageAssetUploadedTime__c, Asset__r.ImageSerialUploadedTime__c,
                       Loaner_CDS_Info__c, Inspection_result__c, Check_lost_Item__c, Pre_disinfection__c, Water_leacage_check__c, Inspection_result_after__c, Arrival_in_wh__c,
                       Asset__r.Pre_Reserve_RAES_Detail__c, Asset__r.Pre_Reserve_RAES_Detail__r.After_Inspection_time__c,
                       Inspection_result_after_ng__c, Inspection_result_ng__c, Lost_item_giveup__c, CDS_complete__c, Loaner_accsessary__c
                  from Rental_Apply_Equipment_Set_Detail__c
                 where Rental_Apply_Equipment_Set__c in :esIds and DeliverySlip__c = null and Return_DeliverySlip__c = null//and Shipment_request_time__c <> null
                   and Cancel_Select__c = False
                 order by Rental_Apply_Equipment_Set__r.Rental_Apply__r.Name, Rental_Apply_Equipment_Set__r.Name, Rental_Apply_Equipment_Set__c, Name
            SELECT
                Rental_Apply__c,
                Rental_Apply__r.Shippment_ng_num__c,
                Rental_Apply__r.Pre_inspection_ng_num__c,
                SerialNumber_F__c,
                Rental_Apply_Equipment_Set__r.Inspection_not_finish__c,
                Fixture_Name_F__c,
                Rental_Apply_Equipment_Set__r.RAES_Status__c,
                Rental_Apply_Equipment_Set__r.Fixture_Set__r.Name,
                Rental_Apply_Equipment_Set__r.Rental_Apply__r.Name,
                Rental_Apply_Equipment_Set__r.Name,
                Pre_inspection_time__c,
                StockDown__c,
                StockDown_time__c,
                Id,
                Name,
                Asset__c,
                Asset__r.Name,
                Asset__r.SerialNumber,
                Asset__r.Product_Serial_No__c,
                Asset__r.Remark__c,
                Asset__r.ImageAsset__c,
                Asset__r.ImageSerial__c,
                Asset__r.ImageAssetUploadedTime__c,
                Asset__r.ImageSerialUploadedTime__c,
                Loaner_CDS_Info__c,
                Inspection_result__c,
                Check_lost_Item__c,
                Pre_disinfection__c,
                Water_leacage_check__c,
                Inspection_result_after__c,
                Arrival_in_wh__c,
                Asset__r.Pre_Reserve_RAES_Detail__c,
                Asset__r.Pre_Reserve_RAES_Detail__r.After_Inspection_time__c,
                Inspection_result_after_ng__c,
                Inspection_result_ng__c,
                Lost_item_giveup__c,
                CDS_complete__c,
                Loaner_accsessary__c
            FROM Rental_Apply_Equipment_Set_Detail__c
            WHERE
                Rental_Apply_Equipment_Set__c IN :esIds
                AND DeliverySlip__c = NULL
                AND Return_DeliverySlip__c = NULL //and Shipment_request_time__c <> null
                AND Cancel_Select__c = FALSE
            ORDER BY
                Rental_Apply_Equipment_Set__r.Rental_Apply__r.Name,
                Rental_Apply_Equipment_Set__r.Name,
                Rental_Apply_Equipment_Set__c,
                Name
        ];
        //Set<Id> lockId = new Set<Id>();
        //for (Rental_Apply_Equipment_Set_Detail__c esd : eList) {
@@ -293,7 +437,9 @@
            for (String raid : allcount.keySet()) {
                if (allcount.get(raid) > shipcount.get(raid).size()) {
                    Step_status = '追加';
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '申请单内存在未勾选的配套,请勾选全部配套或分割申请单!'));
                    ApexPages.addmessage(
                        new ApexPages.message(ApexPages.severity.Error, '申请单内存在未勾选的配套,请勾选全部配套或分割申请单!')
                    );
                }
            }
        }
@@ -334,31 +480,39 @@
    // 保存按钮
    public PageReference save() {
        List<String> raids = Raid.split(':');
        //检查是否可以继续
        List<Rental_Apply__c> RaTarList = [select Id,Name,Campaign__c,Repair__c,next_action__c
                                                ,QIS_number__r.ReplaceDeliveryDate__c,demo_purpose2__c
                                                ,Follow_UP_Opp__r.Shipping_Finished_Day_Func__c
                                                ,Campaign__r.Status
                                                ,Campaign__r.IF_Approved__c
                                                ,Campaign__r.Meeting_Approved_No__c // 20220315 ljh obpm备品决裁状态相关修改
                                                ,Campaign__r.Approved_Status__c     // 20220315 ljh obpm备品决裁状态相关修改
                                                ,repair__r.Return_Without_Repair_Date__c
                                                ,Repair__r.Repair_Final_Inspection_Date__c
                                                ,Repair__r.Repair_Shipped_Date__c
                                            from Rental_Apply__c
                                            where id in :raids];//20210602 ljh update 增加查询Name SFDC-C3LBNL
        List<Rental_Apply__c> RaTarList = [
            SELECT
                Id,
                Name,
                Campaign__c,
                Repair__c,
                next_action__c,
                QIS_number__r.ReplaceDeliveryDate__c,
                demo_purpose2__c,
                Follow_UP_Opp__r.Shipping_Finished_Day_Func__c,
                Campaign__r.Status,
                Campaign__r.IF_Approved__c,
                Campaign__r.Meeting_Approved_No__c, // 20220315 ljh obpm备品决裁状态相关修改
                Campaign__r.Approved_Status__c, // 20220315 ljh obpm备品决裁状态相关修改
                repair__r.Return_Without_Repair_Date__c,
                Repair__r.Repair_Final_Inspection_Date__c,
                AccDealerBlacklist__c, //贸易合规 you
                //,EquipmentGuaranteeFlg__c//贸易合规 you
                Repair__r.Repair_Shipped_Date__c
            FROM Rental_Apply__c
            WHERE id IN :raids
        ]; //20210602 ljh update 增加查询Name SFDC-C3LBNL
        // add lc 20220927 SFDC-CJ48VE 备品预计出库日逻辑调整 start
        Map<Id, String> rentalApplyNameMap = new Map<Id, String>();
        List<Rental_Apply_Equipment_Set__c> RAESRecords = [
                SELECT Id,Rental_Apply__c,Rental_Apply__r.Name 
                FROM Rental_Apply_Equipment_Set__c 
                WHERE Rental_Apply__c in :raids
                AND Cancel_Select__c = False
                AND Rental_Start_Date__c <> :Date.today()
                ORDER BY Rental_Apply__c];
            WHERE Rental_Apply__c IN :raids AND Cancel_Select__c = FALSE AND Rental_Start_Date__c != :Date.today()
            ORDER BY Rental_Apply__c
        ];
        for (Rental_Apply_Equipment_Set__c RAES : RAESRecords) {
            if (rentalApplyNameMap.isEmpty() || !rentalApplyNameMap.containsKey(RAES.Rental_Apply__c)) {
@@ -379,13 +533,19 @@
        String message6 = '';
        String message7 = '';// 20220315 ljh obpm备品决裁状态相关修改 end
        String message8 = '';//add lc 20220927 SFDC-CJ48VE 备品预计出库日逻辑调整
        String message9 = ''; //贸易合规 you
        // 要判断决裁状态不能是草稿/驳回/终止申请/取消/删除
        List<String> statusList = System.Label.StatusProcessState.split(',');
        Map<Id, Rental_Apply__c> RaMap = new Map<Id, Rental_Apply__c>();
        for (Rental_Apply__c RaTar : RaTarList) {
            // 20230215 ljh DB202301265636 学会取消申请也拦截 start
            // if( RaTar.Campaign__r.Status == '取消'){
            if( RaTar.Campaign__r.Status == '取消' || RaTar.Campaign__r.Status == '取消申请中'){
            //贸易合规 you
            // && RaTar.EquipmentGuaranteeFlg__c==false
            if (System.Label.TradeComplianceStatusFlagBP == 'true' && RaTar.AccDealerBlacklist__c == '1') {
                errorFlag = true;
                message9 += RaTar.Name + '、';
            } else if (RaTar.Campaign__r.Status == '取消' || RaTar.Campaign__r.Status == '取消申请中') {
            // 20230215 ljh DB202301265636 学会取消申请也拦截 end
                // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '学会已取消,不能继续操作了'));
                // return null;
@@ -397,13 +557,11 @@
                errorFlag = true;
                message1 += RaTar.Name+'、';
            }else if(RaTar.repair__r.Return_Without_Repair_Date__c!=null&&RaTar.repair__c!=null ){
                // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '未修理归还日不为空,不能出库'));
                // return null;
                errorFlag = true;
                message2 += RaTar.Name+'、';
            }else if(RaTar.Repair__r.Repair_Shipped_Date__c!=null){
                // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '存在RC修理返送日,不能继续了'));
                // return null;
                errorFlag = true;
@@ -413,7 +571,11 @@
            else if(RaTar.demo_purpose2__c=='已购待货' && RaTar.Follow_UP_Opp__r.Shipping_Finished_Day_Func__c!= null){
                errorFlag = true;
                message4 += RaTar.Name+'、';
            }else if(RaTar.demo_purpose2__c=='索赔QIS' && RaTar.next_action__c=='无偿更换' && RaTar.QIS_number__r.ReplaceDeliveryDate__c!= null){
            } else if (
                RaTar.demo_purpose2__c == '索赔QIS' &&
                RaTar.next_action__c == '无偿更换' &&
                RaTar.QIS_number__r.ReplaceDeliveryDate__c != null
            ) {
                errorFlag = true;
                message5 += RaTar.Name+'、';
            }
@@ -429,8 +591,12 @@
            else if(RaTar.Campaign__c!= null &&  RaTar.Campaign__r.IF_Approved__c && RaTar.Campaign__r.Meeting_Approved_No__c == null) {
                errorFlag = true;
                message6 += RaTar.Name + '、';
            }
            else if(RaTar.Campaign__c!= null &&  RaTar.Campaign__r.IF_Approved__c && RaTar.Campaign__r.Meeting_Approved_No__c != null && statusList.contains(RaTar.Campaign__r.Approved_Status__c)) {
            } else if (
                RaTar.Campaign__c != null &&
                RaTar.Campaign__r.IF_Approved__c &&
                RaTar.Campaign__r.Meeting_Approved_No__c != null &&
                statusList.contains(RaTar.Campaign__r.Approved_Status__c)
            ) {
                errorFlag = true;
                message7 += RaTar.Name + '、';
            }
@@ -486,6 +652,10 @@
            }
            // add lc 20220927 SFDC-CJ48VE 备品预计出库日逻辑调整 end
            if (String.isNotBlank(message9)) {
                message += '单号No.' + message9.removeEnd('、') + System.Label.IFTradeComplianceAlertBP;
            }
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,message));
            return null;
        }
@@ -508,13 +678,52 @@
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '未选择备品set,不能创建发货单'));
            return null;
        }
        eList = [select Rental_Apply__c, Rental_Apply__r.Shippment_ng_num__c, Rental_Apply__r.Pre_inspection_ng_num__c, Rental_Apply_Equipment_Set__r.Inspection_not_finish__c, Fixture_Name_F__c, Rental_Apply_Equipment_Set__r.Fixture_Set__r.Name, Rental_Apply_Equipment_Set__r.Rental_Apply__r.Name, Rental_Apply_Equipment_Set__r.Name, Pre_inspection_time__c, StockDown__c, StockDown_time__c, Id, Name, Asset__c, Asset__r.Name, Asset__r.SerialNumber, Asset__r.Product_Serial_No__c,
                           Asset__r.Remark__c, Asset__r.ImageAsset__c, Asset__r.ImageSerial__c, Asset__r.ImageAssetUploadedTime__c, Asset__r.ImageSerialUploadedTime__c,
                           Loaner_CDS_Info__c, Inspection_result__c, Check_lost_Item__c, Pre_disinfection__c, Water_leacage_check__c, Inspection_result_after__c, Arrival_in_wh__c,
                           Asset__r.Pre_Reserve_RAES_Detail__c, Asset__r.Pre_Reserve_RAES_Detail__r.After_Inspection_time__c,
                           Rental_Apply__r.Request_approval_time__c , Add_Request_approval_time__c ,ApplyToShipmentWorkTime__c, //20220309 ljh SFDC-CC6CLJ phase5上线课题131 提交申请到备品出库时长
                           Inspection_result_after_ng__c, Inspection_result_ng__c, Lost_item_giveup__c, CDS_complete__c, Loaner_accsessary__c,Key_product__c
                    from Rental_Apply_Equipment_Set_Detail__c where Id in :eSet for update];
        eList = [
            SELECT
                Rental_Apply__c,
                Rental_Apply__r.Shippment_ng_num__c,
                Rental_Apply__r.Pre_inspection_ng_num__c,
                Rental_Apply_Equipment_Set__r.Inspection_not_finish__c,
                Fixture_Name_F__c,
                Rental_Apply_Equipment_Set__r.Fixture_Set__r.Name,
                Rental_Apply_Equipment_Set__r.Rental_Apply__r.Name,
                Rental_Apply_Equipment_Set__r.Name,
                Pre_inspection_time__c,
                StockDown__c,
                StockDown_time__c,
                Id,
                Name,
                Asset__c,
                Asset__r.Name,
                Asset__r.SerialNumber,
                Asset__r.Product_Serial_No__c,
                Asset__r.Remark__c,
                Asset__r.ImageAsset__c,
                Asset__r.ImageSerial__c,
                Asset__r.ImageAssetUploadedTime__c,
                Asset__r.ImageSerialUploadedTime__c,
                Loaner_CDS_Info__c,
                Inspection_result__c,
                Check_lost_Item__c,
                Pre_disinfection__c,
                Water_leacage_check__c,
                Inspection_result_after__c,
                Arrival_in_wh__c,
                Asset__r.Pre_Reserve_RAES_Detail__c,
                Asset__r.Pre_Reserve_RAES_Detail__r.After_Inspection_time__c,
                Rental_Apply__r.Request_approval_time__c,
                Add_Request_approval_time__c,
                ApplyToShipmentWorkTime__c, //20220309 ljh SFDC-CC6CLJ phase5上线课题131 提交申请到备品出库时长
                Inspection_result_after_ng__c,
                Inspection_result_ng__c,
                Lost_item_giveup__c,
                CDS_complete__c,
                Loaner_accsessary__c,
                Key_product__c
            FROM Rental_Apply_Equipment_Set_Detail__c
            WHERE Id IN :eSet
            FOR UPDATE
        ];
        Boolean needSaveSet = false;
        Boolean needSaveDetail = false;
        Boolean needDeliverySlip = false;
@@ -542,7 +751,9 @@
            //wangweipeng   是否是重点产品       2021/08/30        end
            astForLock.add(esd.Asset__c);
            // 20220315 ljh SFDC-CC6CLJ phase5上线课题131 提交申请到备品出库时长 start
            Datetime keyDt = esd.Add_Request_approval_time__c != null?esd.Add_Request_approval_time__c:esd.Rental_Apply__r.Request_approval_time__c;
            Datetime keyDt = esd.Add_Request_approval_time__c != null
                ? esd.Add_Request_approval_time__c
                : esd.Rental_Apply__r.Request_approval_time__c;
            List<Rental_Apply_Equipment_Set_Detail__c> tempRaesdL;
            if(approvalMap.containsKey(keyDt)){
                tempRaesdL = approvalMap.get(keyDt);
@@ -553,10 +764,12 @@
            approvalMap.put(keyDt,tempRaesdL);
            // 20220315 ljh SFDC-CC6CLJ phase5上线课题131 提交申请到备品出库时长 end
        }
        List<Asset> astLock = [select Id
                 from Asset
                where id in :astForLock
                  for update];
        List<Asset> astLock = [
            SELECT Id
            FROM Asset
            WHERE id IN :astForLock
            FOR UPDATE
        ];
        if (Step_status == '明细') {
            needDeliverySlip = true;
            //if (slip.Id == null) {
@@ -564,18 +777,37 @@
            //    slip.Shippment_loaner_time__c = Datetime.now();
            //}
            if (slip.Id != null) {
                slip = [select Combine_Pack__c, Name, Id, DeliveryCompany_SlipNo__c,DeliveryType__c,Distributor_method__c,DeliveryCompany__c,Wh_Staff__c
                        from FixtureDeliverySlip__c
                        where Id =:slip.Id for update];
                slip = [
                    SELECT
                        Combine_Pack__c,
                        Name,
                        Id,
                        DeliveryCompany_SlipNo__c,
                        DeliveryType__c,
                        Distributor_method__c,
                        DeliveryCompany__c,
                        Wh_Staff__c
                    FROM FixtureDeliverySlip__c
                    WHERE Id = :slip.Id
                    FOR UPDATE
                ];
            }
            slip.Shippment_loaner_time__c = Datetime.now();
            needSaveDetail = true;
        }
        List<Rental_Apply__c> raList = [select Id, DeliverySlip__c, Campaign__c
                                        , Campaign__r.IF_Approved__c         // 20220315 ljh obpm备品决裁状态相关修改
                                        , Campaign__r.Meeting_Approved_No__r.Name // 20220315 ljh obpm备品决裁状态相关修改
                                        , Campaign__r.Approved_Status__c     // 20220315 ljh obpm备品决裁状态相关修改
                                        from Rental_Apply__c where Id in :raSet];
        List<Rental_Apply__c> raList = [
            SELECT
                Id,
                DeliverySlip__c,
                Campaign__c,
                Campaign__r.IF_Approved__c, // 20220315 ljh obpm备品决裁状态相关修改
                Campaign__r.Meeting_Approved_No__r.Name, // 20220315 ljh obpm备品决裁状态相关修改
                Campaign__r.Approved_Status__c, // 20220315 ljh obpm备品决裁状态相关修改
                Hospital__r.TradeComplianceStatus__c, //贸易合规 you
                Outbound_TradeStatus__c //贸易合规 you
            FROM Rental_Apply__c
            WHERE Id IN :raSet
        ];
        Savepoint sp = Database.setSavepoint();
        try {
            //if (needSaveSet) ControllerUtil.upRAdEquipmentSet(es);
@@ -583,16 +815,17 @@
                FixtureUtil.withoutUpsertObjects(new List<FixtureDeliverySlip__c>{ slip });
                //ControllerUtil.updRADeliverySlipDetail(slip);
                // 20220315 ljh SFDC-CC6CLJ phase5上线课题131 提交申请到备品出库时长 start
                map<String,Decimal> ApplyToShipmentMap = new map<String,Decimal>();
                map<String, Decimal> ApplyToShipmentMap = new Map<String, Decimal>();
                if(approvalMap.size() > 0 ){
                    // dtList[0] 第一个就是最小时间
                    List<Datetime> dtList = new List<Datetime>(approvalMap.keySet());
                    Date startDateSOQL  = date.newinstance(dtList[0].year(), dtList[0].month(), dtList[0].day());
                    List<OlympusCalendar__c> ocList = [SELECT Id, Date__c,IsWorkDay__c
                    List<OlympusCalendar__c> ocList = [
                        SELECT Id, Date__c, IsWorkDay__c
                                     FROM OlympusCalendar__c
                                    WHERE Date__c >= :startDateSOQL
                                      AND Date__c <= :Date.today()
                                    ORDER BY Date__c ASC];
                        WHERE Date__c >= :startDateSOQL AND Date__c <= :Date.today()
                        ORDER BY Date__c ASC
                    ];
                    Map<Date,String> ocMap = new Map<Date,String>();
                    for(OlympusCalendar__c oc:ocList){
                        String IsWorkDay = oc.IsWorkDay__c.format();
@@ -621,7 +854,14 @@
                        if(ocList[ocList.size() - 1].IsWorkDay__c == 0){
                            for(Integer i = ocList.size() - 1; i >= 0;i--){
                                if(ocList[i].IsWorkDay__c == 1){
                                    endTime = Datetime.newInstance(ocList[i].Date__c.addDays(1).year(),ocList[i].Date__c.addDays(1).month(),ocList[i].Date__c.addDays(1).day(),0,0,0);
                                    endTime = Datetime.newInstance(
                                        ocList[i].Date__c.addDays(1).year(),
                                        ocList[i].Date__c.addDays(1).month(),
                                        ocList[i].Date__c.addDays(1).day(),
                                        0,
                                        0,
                                        0
                                    );
                                    endDate = ocList[i].Date__c.addDays(1);
                                    endFlag = true;
                                    break;
@@ -667,7 +907,7 @@
                    //wangweipeng   是否是重点产品       2021/08/30        start
                    ra.Is_keyPoint_Product__c = keyPointProduct.get(ra.Id);
                    //wangweipeng   是否是重点产品       2021/08/30        start
                    ra.Outbound_TradeStatus__c = ra.Hospital__r.TradeComplianceStatus__c; //贸易合规 you
                    // 20220315 ljh obpm备品决裁状态相关修改 update start
                    //20220217 sx add 备品借出申请-决裁控制 No.4 出库成功时,把此时点的决裁编号和决裁状态写到决裁编号(出库)和决裁状态(出库)上
                    // if (!campMap.isEmpty() && campMap.containsKey(ra.Campaign__c) && campMap.get(ra.Campaign__c).IF_Approved__c){
@@ -683,6 +923,9 @@
            }
            //if (needSaveDetail) ControllerUtil.updRAEquipmentSetDetail(eList);
            if (needSaveDetail) {
                // 备品优化追加 20230518 lc Start
                RentalApplyEquipmentSetDetailHandler.skipUpdateAgain = true;
                // 备品优化追加 20230518 lc End
                FixtureUtil.withoutUpsertObjects(eList);
                FixtureUtil.withoutUpsertObjects(raList);
            }
@@ -718,7 +961,10 @@
            this.isChecked = checked;
            this.hasSended = false;
            if (rec.Asset__r.Pre_Reserve_RAES_Detail__c != null && rec.Asset__r.Pre_Reserve_RAES_Detail__r.After_Inspection_time__c != null) {
            if (
                rec.Asset__r.Pre_Reserve_RAES_Detail__c != null &&
                rec.Asset__r.Pre_Reserve_RAES_Detail__r.After_Inspection_time__c != null
            ) {
                this.quickCheck = Datetime.now() < rec.Asset__r.Pre_Reserve_RAES_Detail__r.After_Inspection_time__c + 30 ? true : false;
            } else {
                this.quickCheck = false;