public without sharing class NFM603Controller {

    private static final String LOG_TYPE = 'NFM603';
    // private static final String API = '/admin/api/scd/save';
    private static final String API = '/admin/api/repair/save';

    // 2022-05-05      zyh     update      start
    private static List < BatchIF_Log__c > logList = new List < BatchIF_Log__c > ();
    private static List < BatchIF_Log__c > rowList = new List < BatchIF_Log__c > ();
    private static Map < Id,BatchIF_Log__c > logMap = new Map < Id,BatchIF_Log__c > ();
    // 2022-05-05      zyh     update      end
    public static Integer status;
    public static String message;
    public class RepairOrderInfo {
        //修理信息
        public String repairOrderNo; //报修单号
        public String repairOrderNo2; //报修子单号
        public String SAPrepairNo; //SAP修理单号（new）
        public String repairNo; //修理单号
        public String hospitalCd; //医院编号
        public String strategicDepartmenCd; //战略科室编码
        public String departmentCd; //科室编码
        public String region; //大区
        public String province; //省市
        public String city; //市
        public String repairApplicant; //修理委托人
        public String repairApplicantID; //修理委托人统一ID(new)===预留
    
        public String FSERepairOrderCreateDate; //FSE申请修理时间(new)
        public String SAPRepairOrderCreateDate; //SAP申请修理时间(new)
        public String equipmentModel; //设备型号
        public String equipmentCd; //机身编码
        public String On_site_repair; //服务方式
        public String ContractName; //维修合同名称(new)
        public String ContractData; //维修合同记录类型(new)
        public String ContractNo; //维修合同号码
        public String ContractStartDate; //维修合同开始日
        public String ContractEndDate; //维修合同结束日
        public String MultiYearContractName; //多年保合同名称(new)
        public String MultiYearContractNo; //多年保合同编号
        public String MultiYearContractStartDate; //多年保合同开始日
        public String MultiYearContractEndDate; //多年保合同结束日
        public String MultiYearContractData; //多年保合同记录类型(new)
        public Boolean isRepairWarrantyObj; //再490修理保修对象
        public String RepairType; //修理区分-------------------
        public String QuotationGread; //报价等级(new)
        public String detectionResult; //检测结果
        //LLIU-CG53S9 LY 20220711 start
        public String isContractUser;    //是否合同用户
        public String oldRepairNo;       //原修理单号
        public String closeRepairDate;   //修理单关闭日
        //LLIU-CG53S9 LY 20220711 end
        public String cus_dn; //DN号
        //修理增加OTS运单号字段 thh 20220308 start
        public String OTSRepairOrder;
        //修理增加OTS运单号字段 thh 20220308 end

        //送修物流
        public String deliveryLogisticsMode; //送修物流方式
        public String engineerSendDate; //工程师修理品寄送日
        public String deliveryLogisticsNo; //送修物流单号
        public String DeliveryLogisticsAnnotation; //送修物流信息备注
        public String returnLogisticsMode; //返送物流方式
        public String returnLogisticsNo; //返送物流单号
        public String returnLogisticsRemark; //返送物流备注信息
        public String returnStage; //维修品返送所处阶段
        public String returnLogisticsSendTime; //返送物流发送时间+++++++++++++
        public String returnLogisticsReceiveTime; //返送物流签收时间++++++++++++
        //服务进程-进修
        public String repairproductsRevDate; //故障品接收日
        public String FSErepairApplyDate; //FSE修理申请日
        public String logisticsSendDate; //物流发送日
        public String logisticsReceiveDate; //物流接收日
        public String SAPrepairApplyDate; //SAP修理申请日
        public String RCacceptanceDate; //修理品RC受理日
        public String inspectionDate; //修理检测日
        public String FirstQuotationDate; //初次报价日
        public String planQuotationDate; //计划上门报价日
        public String ActualQuotationDate; //实际上门报价日
        public String quotationDate; //报价日
        public String priceApprovalDate; //减价申请批准日
        public Decimal finalQuotationPrice; //最终报价金额-----------------
        public String userAgreeDAte; //用户同意日
        public String partsCompleteDate; //零件齐备完毕日
        public String repairStartDate; //修理开始日
        public String repairCompleteExpectedDate; //修理完成预计日
        public String repairCompleteDate; //修理完成日
        public String finalTestDate; //最终检测日
        public String RCreturnDate; //RC修理品返送日
        public String ReturnsProductWay; //返品方式
        public String officeLogisticsReceiveDate; //办事处物流接收日
        public String invoiceDate; //开发票日
        public String userReturnDate; //修理品用户返送日
        public String acceptanceFormSendDate; //验收单现场寄送日
        public String acceptanceFormReceivedDate; //验收单收到日
        public String invoiceReceiveDate; //发票接收日
        public String latestPayDate; //最新回款日
        public String payCompleteDate; //回款完毕日
        public String incomeReckoninDate; //收入计入日
        public String abandonPayDate; //放弃回款日
        public String cancelRepairDate; //修理取消日
        public String repairOrderCompleteDate; //修理单完成日
        public Boolean applySpareEquip; //是否申请备品
        public String supplySpareEquip; //是否提供备品
        public FaultDesc[] FaultDesc;
        public SparePartsLendingRecord[] SparePartsLendingRecord;
        //===================================================
        public String RcSorcDate; //RC转SORC日
        public String SorcAcceptDate; //SORC受理日
        public String SorcOgzDate; //SORC转OGZ日
        public String OgzAcceptDate; //OGZ受理日

    }
    public class FaultDesc {
        //故障描述
        public String repairPosition; //修理部位
        public String faultDescription; //故障描述
        //修理内容
        public String repairContentDesc; //修理内容描述
    }
    public class SparePartsLendingRecord {
        //备品出借记录
        public String spareEquipapplicationNo; //备品申请编号
        public String spareEquipLendingDate; //备品出借日期 
        public String spareEquipMode; //出借备品型号
    }
    @future(callout = true)
    public static void callout(String iflog_Id, List < String > repairOrderIdList) {
        //BatchIF_Log__c iflog = [Select Id, Name, Log__c, ErrorLog__c from BatchIF_Log__c where Id = :iflog_Id];
        String sql = 'Select Id, Name, Log__c, ErrorLog__c from BatchIF_Log__c where Id = \'' + iflog_Id + '\'';
        List < BatchIF_Log__c > iflogs = DataBase.query(sql);
        if (iflogs == null || iflogs.size() == 0) {
            executefuture(null, repairOrderIdList);
        } else {
            executefuture(iflogs.get(0), repairOrderIdList);
        }

    }

    public static void executefuture(BatchIF_Log__c iflog, List < String > repairOrderIdList) {
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmmss');
        if (iflog != null) {
            iflog.ErrorLog__c = '';
        } else {
            iflog = new BatchIF_Log__c();
            iflog.Type__c = LOG_TYPE;
            iflog.ErrorLog__c = '';
            iflog.Log__c = 'callout start \n';
            iflog.MessageGroupNumber__c = nowStr;
        }
        List < RepairOrderInfo > repairs = new List < RepairOrderInfo > ();
        List < RepairOrderInfo > repairs1 = new List < RepairOrderInfo > ();
        BatchIF_Log__c rowData = null;
        List < Repair__c > repairList = new List < Repair__c > ();
        if (repairOrderIdList != null && repairOrderIdList.size() > 0) {
            repairList = [select id, Name, 
                RepairSubOrder__r.RepairOrderNo__c,
                RepairSubOrder__r.RepairSubOrderNo__c,
                Hospital__r.Management_Code__c,
                SAP_Service_Repair_No__c,
                Account__r.Management_Code__c,
                Department_Name__c,
                Account_Management_Code__c,
                Hospital__r.Salesdepartment_HP__c,
                State_Hospital__c,
                Hospital__r.City_Master__r.Name,
                Incharge_Staff__r.Employee_No__c,
                CreatedBy.Employee_No__c,
                FSE_ApplyForRepair_time__c,
                SAP_Transfer_time__c,
                Delivered_Product__r.Product_Name__c,
                Delivered_Product__r.SerialNumber,
                Maintenance_Contract__r.Name,
                Maintenance_Contract__r.RecordType.Name,
                Management_Code__c,
                Contract_Start_Date__c,
                Contract_End_Date__c,
                VM_Maintenance_Contract__r.Name,
                VM_Maintenance_Contract__r.Management_Code__c,
                VM_Maintenance_Contract__r.startDateGurantee__c,
                VM_Maintenance_Contract__r.endDateGurantee__c,
                VM_Maintenance_Contract__r.RecordType.Name,
                ReRepairObject_result__c,
                Repair_Severity_Rank__c,
                Repair_Rank__c,
                InspectionResultFlag__c,
                DeliveryLogisticsMode__c,
                engineerSendDate__c,
                DeliveryLogisticsNo__c,
                ReturnLogisticsMode__c,
                ReturnLogisticsNo__c,
                ReturnLogisticsRemark__c,
                ReturnStage__c,
                ReturnOrderSendTime__c,
                ReturnLogisticsReceiveTime__c,
                On_Site_Repair_Order_Date__c,
                FSE_ApplyForRepair_Day__c,
                LogisticsSendTime__c,
                LogisticsReceiveTime__c,
                SAP_Transfer_day__c,
                Repair_Ordered_Date__c,
                Repair_Inspection_Date__c,
                Repair_Firstestimated_Date_formula__c,
                PlanQuotationTime__c,
                ActualQuotationStartTime__c,
                Repair_Quotation_date__c,
                Repair_Discount_approval_Date_formula__c,
                Discount_Price_formula__c,
                Agreed_Date__c,
                part_arrangement_complete__c,
                Repair_Start_Date__c,
                Planned_Repair_Completed_Date__c,
                Repair_Completed_Date__c,
                Repair_Final_Inspection_Date__c,
                Repair_Shipped_Date__c,
                OfficeLogisticsReceiveDate__c,
                Invoice_Date__c,
                Repair_Returned_To_HP_Date__c,
                Facility_Return_Receipt_Collection_reque__c,
                Receipt_received_date__c,
                Billing_Received_Date__c,
                Latest_Collect_Date_Priority__c,
                Received_Date__c,
                Facility_Return_Receipt_Collection_Date__c,
                BaddebtsDate__c,
                repair_cancel_date__c,
                RepairOrder_Complete_Day__c,
                if_Rental_Apply__c, On_site_repair__c,
                Offer_Rental_New__c,
                RcSorcDate__c,
                SorcAcceptDate__c,
                SorcOgzDate__c,
                RcOgzDate__c,
                Returns_Product_waySAP__c,
                DnNO__c,
                OgzAcceptDate__c,
                DeliveryLogisticsAnnotation__c,
                Department_Class__r.Management_Code__c,
                Repair_Ordered_DateTime__c,
                Repair_Inspection_DateTime__c,
                repair_cancel_dateTime__c,
                RcSorcDateTime__c,
                SorcAcceptDateTime__c,
                OgzAcceptDateTime__c,
                part_arrangement_complete_DateTime__c,
                Repair_Start_DateTime__c,
                Repair_Completed_DateTime__c,
                Repair_Final_Inspection_DateTime__c,
                Repair_Shipped_DateTime__c,
                Repair_Discount_approval_DateTime_form__c,
                // 2022-05-20   zyh   update  start
                Repair_Estimated_Date__c,  
                Repair_Estimated_date_formula__c,
                // 2022-05-20   zyh   update  end
                Agreed_DateTime__c,
                //修理增加OTS运单号字段 thh 20220308 start
                OTSRepairOrder__c
                //修理增加OTS运单号字段 thh 20220308 end
                //LLIU-CG53S9 LY 20220711 start
                ,IF_ContractUser__c
                ,Old_Name__c
                ,SAP_not_accept_repair_result__c
                //LLIU-CG53S9 LY 20220711 end
                from Repair__c where id in: repairOrderIdList
            ];
        }
        String logstr = iflog.Log__c + ' ' + 'NumberOfRecord=' + repairList.size() + '\n' + repairList[0].Name + '\n';
        try {
            List < Id > repairIdList = new List < Id > ();
            for (Repair__c repair: repairList) {
                repairIdList.add(repair.Id);
            }
            // 故障描述
            Map < id, List < FaultDesc >> reasonMap = getFaultDescMap(repairOrderIdList);
            // 备品出借记录 查找备品出借一览明细的 产品型号
            Map < id, List < SparePartsLendingRecord >> rentalMap = getrentalMap(repairIdList);

            // String downSDt = ''; 2022-5-10   zyh  update
            // String downEDt = ''; 2022-5-10   zyh  update
            // String upSDt = ''; 2022-5-10   zyh  update
            // String upEDt = ''; 2022-5-10   zyh  update


            for (Repair__c repair: repairList) {
                RepairOrderInfo info = new RepairOrderInfo();
                info.repairOrderNo = repair.RepairSubOrder__r.RepairOrderNo__c;
                info.repairOrderNo2 = repair.RepairSubOrder__r.RepairSubOrderNo__c;
                info.repairNo = repair.Name; //修理单号
                info.hospitalCd = repair.Hospital__r.Management_Code__c; //医院编码
                info.SAPrepairNo = repair.SAP_Service_Repair_No__c; //SAP修理单号
                info.strategicDepartmenCd = repair.Department_Class__r.Management_Code__c; //战略科室编码
                info.departmentCd = repair.Account_Management_Code__c; //科室编码
                info.region = repair.Hospital__r.Salesdepartment_HP__c; //大区
                info.province = repair.State_Hospital__c; //省
                info.city = repair.Hospital__r.City_Master__r.Name; //--------------市
                info.repairApplicant = repair.Incharge_Staff__r.Employee_No__c; //---------修理委託人
                info.repairApplicantID = repair.Incharge_Staff__r.Employee_No__c; //修理委托人统一ID
                info.FSERepairOrderCreateDate = NFMUtil.formatDateTime2Str(repair.FSE_ApplyForRepair_time__c); // FSE申请修理时间
                info.SAPRepairOrderCreateDate = NFMUtil.formatDateTime2Str(repair.SAP_Transfer_time__c); //SAP修理申请时间
                info.equipmentModel = repair.Delivered_Product__r.Product_Name__c; //设备型号
                info.equipmentCd = repair.Delivered_Product__r.SerialNumber; //----------机身编码
                info.On_site_repair = repair.On_site_repair__c; //================服务方式=============待定
                info.ContractName = repair.Maintenance_Contract__r.Name; //维修合同名称
                info.ContractData = repair.Maintenance_Contract__r.RecordType.Name; //维修合同记录类型
                info.ContractNo = repair.Management_Code__c; //维修合同编码
                info.ContractStartDate = NFMUtil.formatDate2StrDateTime(repair.Contract_Start_Date__c); //维修合同开始日期
                info.ContractEndDate = NFMUtil.formatDate2StrDateTime(repair.Contract_End_Date__c); //维修合同结束日期
                info.MultiYearContractName = repair.VM_Maintenance_Contract__r.Name; //多年保合同名称
                info.MultiYearContractNo = repair.VM_Maintenance_Contract__r.Management_Code__c; //-------多年保合同编号
                info.MultiYearContractStartDate = NFMUtil.formatDate2StrDateTime(repair.VM_Maintenance_Contract__r.startDateGurantee__c); //多年保合同开始日
                info.MultiYearContractEndDate = NFMUtil.formatDate2StrDateTime(repair.VM_Maintenance_Contract__r.endDateGurantee__c); //多年保合同结束日
                info.MultiYearContractData = repair.VM_Maintenance_Contract__r.RecordType.Name; //多年保记录类型
                info.isRepairWarrantyObj = repair.ReRepairObject_result__c; //再修理保修对象
                info.RepairType = repair.Repair_Severity_Rank__c; //修理区分----------
                info.QuotationGread = repair.Repair_Rank__c; //报价等级
                info.detectionResult = repair.InspectionResultFlag__c; //检测结果
                //LLIU-CG53S9 LY 20220711 start
                info.isContractUser = repair.IF_ContractUser__c ? 'true' : 'false'; //是否合同用户
                info.oldRepairNo = repair.Old_Name__c; //原修理受付番号
                info.closeRepairDate = NFMUtil.formatDate2StrDateTime(repair.SAP_not_accept_repair_result__c); //修理单关闭日
                //LLIU-CG53S9 LY 20220711 end
                info.FaultDesc = reasonMap.get(repair.id); //故障描述List
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                info.deliveryLogisticsMode = repair.DeliveryLogisticsMode__c; //送修物流方式======自己写字段
                //update                wangweipeng     2022/02/16                start
                //info.engineerSendDate = NFMUtil.formatDate2StrDateTime(repair.engineerSendDate__c); // 工程师修理品寄送日
                info.engineerSendDate = NFMUtil.formatDateTime2Str(repair.engineerSendDate__c); // 工程师修理品寄送日
                //update                wangweipeng     2022/02/16                end
                info.deliveryLogisticsNo = repair.DeliveryLogisticsNo__c; //送修物流单号======自己写字段
                info.returnLogisticsMode = repair.ReturnLogisticsMode__c; //返送物流方式======自己写字段
                info.DeliveryLogisticsAnnotation = repair.DeliveryLogisticsAnnotation__c; //送修物流信息备注
                info.returnLogisticsNo = repair.ReturnLogisticsNo__c; //返送物流单号======自己写字段
                info.returnLogisticsRemark = repair.ReturnLogisticsRemark__c; //返送物流备注信息======自己写字段
                info.returnStage = repair.ReturnStage__c; //维修品返送所处阶段======自己写字段
                info.returnLogisticsSendTime = NFMUtil.formatDateTime2Str(repair.ReturnOrderSendTime__c); //返送物流发送时间======自己写字段
                info.returnLogisticsReceiveTime = NFMUtil.formatDateTime2Str(repair.ReturnLogisticsReceiveTime__c); //返送物流签收时间======自己写字段
                info.repairproductsRevDate = NFMUtil.formatDate2StrDateTime(repair.On_Site_Repair_Order_Date__c); //故障品接收日
                //update                wangweipeng     2022/02/16                start
                //info.FSErepairApplyDate = NFMUtil.formatDate2StrDateTime(repair.FSE_ApplyForRepair_Day__c); //FSE修理申请日======自己写字段
                info.FSErepairApplyDate = NFMUtil.formatDateTime2Str(repair.FSE_ApplyForRepair_time__c); // FSE修理申请时间
                //update                wangweipeng     2022/02/16                end
                info.logisticsSendDate = NFMUtil.formatDateTime2Str(repair.LogisticsSendTime__c); //物流发送日======自己写字段
                info.logisticsReceiveDate = NFMUtil.formatDateTime2Str(repair.LogisticsReceiveTime__c); //物流接收日======自己写字段
                //update                wangweipeng     2022/02/16                start
                //info.SAPrepairApplyDate = NFMUtil.formatDate2StrDateTime(repair.SAP_Transfer_day__c); //SAP修理申请日======自己写字段
                info.SAPrepairApplyDate = NFMUtil.formatDateTime2Str(repair.SAP_Transfer_time__c); // SAP修理申请时间
                //info.RCacceptanceDate = NFMUtil.formatDate2StrDateTime(repair.Repair_Ordered_Date__c); //修理品RC受理日
                info.RCacceptanceDate = NFMUtil.formatDateTime2Str(repair.Repair_Ordered_DateTime__c); //4.修理品RC受理日（小程序）
                //info.inspectionDate = NFMUtil.formatDate2StrDateTime(repair.Repair_Inspection_Date__c); //修理检测日
                info.inspectionDate = NFMUtil.formatDateTime2Str(repair.Repair_Inspection_DateTime__c); //5.修理检测日（小程序）
                // info.FirstQuotationDate = NFMUtil.formatDate2StrDateNewTime(repair.Repair_Firstestimated_Date_formula__c); //初次报价日      2022-05-20    zyh   注释
                info.FirstQuotationDate = NFMUtil.formatDate2StrDateNewTime(repair.Repair_Estimated_Date__c); //初次报价日       2022-05-20    zyh   add
                //info.priceApprovalDate = NFMUtil.formatDate2StrDateTime(repair.Repair_Discount_approval_Date_formula__c); //减价申请批准日
                info.priceApprovalDate = NFMUtil.formatDateTime2Str(repair.Repair_Discount_approval_DateTime_form__c); //减价申请批准日（小程序）
                // info.quotationDate = NFMUtil.formatDate2StrDateNewTime(repair.Repair_Quotation_date__c); //报价日     2022-05-20  zyh   注释
                info.quotationDate = NFMUtil.formatDate2StrDateNewTime(repair.Repair_Estimated_date_formula__c); //报价日      2022-05-20    zyh    add
                //info.cancelRepairDate = NFMUtil.formatDate2StrDateTime(repair.repair_cancel_date__c); //修理取消日
                info.cancelRepairDate = NFMUtil.formatDateTime2Str(repair.repair_cancel_dateTime__c); //修理取消日（小程序）
                //info.userAgreeDAte = NFMUtil.formatDate2StrDateTime(repair.Agreed_Date__c); //用户同意日
                info.userAgreeDAte = NFMUtil.formatDateTime2Str(repair.Agreed_DateTime__c); //7.用户同意日（小程序）
                //info.partsCompleteDate = NFMUtil.formatDate2StrDateTime(repair.part_arrangement_complete__c); //零件齐备完毕日
                info.partsCompleteDate = NFMUtil.formatDateTime2Str(repair.part_arrangement_complete_DateTime__c); //零件齐备完毕日
                //info.repairStartDate = NFMUtil.formatDate2StrDateTime(repair.Repair_Start_Date__c); //修理开始日
                info.repairStartDate = NFMUtil.formatDateTime2Str(repair.Repair_Start_DateTime__c); //8.修理开始日（小程序）
                //info.repairCompleteDate = NFMUtil.formatDate2StrDateTime(repair.Repair_Completed_Date__c); //修理完成日
                info.repairCompleteDate = NFMUtil.formatDateTime2Str(repair.Repair_Completed_DateTime__c); //9.修理完成日（小程序）
                //info.finalTestDate = NFMUtil.formatDate2StrDateTime(repair.Repair_Final_Inspection_Date__c); //最终检测日
                info.finalTestDate = NFMUtil.formatDateTime2Str(repair.Repair_Final_Inspection_DateTime__c); //10.最终检测日（小程序）
                //update                wangweipeng     2022/02/16                end
                info.planQuotationDate = NFMUtil.formatDateTime2Str(repair.PlanQuotationTime__c); //计划报价日======自己写字段
                info.ActualQuotationDate = NFMUtil.formatDateTime2Str(repair.ActualQuotationStartTime__c); //实际报价日======自己写字段
                info.finalQuotationPrice = repair.Discount_Price_formula__c; //最终报价金额======自己写字段
                info.repairCompleteExpectedDate = NFMUtil.formatDate2StrDateTime(repair.Planned_Repair_Completed_Date__c); //修理完成预计日

                info.RCreturnDate = null; //RC修理品返送日
                info.ReturnsProductWay = null; //返品方式  
                if (repair.Repair_Shipped_Date__c != null && String.isNotBlank(repair.Returns_Product_waySAP__c)) {
                    //info.RCreturnDate = NFMUtil.formatDate2StrDateTime(repair.Repair_Shipped_Date__c); //RC修理品返送日
                    info.RCreturnDate = NFMUtil.formatDateTime2Str(repair.Repair_Shipped_DateTime__c); //RC修理品返送日  wangweipeng     2022/02/16
                    info.ReturnsProductWay = repair.Returns_Product_waySAP__c; //返品方式    
                }

                info.officeLogisticsReceiveDate = NFMUtil.formatDateTime2Str(repair.OfficeLogisticsReceiveDate__c); //办事处物流接收日======自己写字段-SAP提供物流信息
                info.invoiceDate = NFMUtil.formatDate2StrDateTime(repair.Invoice_Date__c); //开发票日
                info.userReturnDate = NFMUtil.formatDate2StrDateTime(repair.Repair_Returned_To_HP_Date__c); //修理品用户返送日
                info.acceptanceFormSendDate = NFMUtil.formatDate2StrDateTime(repair.Facility_Return_Receipt_Collection_reque__c); //验收单现场寄送日
                info.acceptanceFormReceivedDate = NFMUtil.formatDate2StrDateTime(repair.Receipt_received_date__c); //验收单收到日
                info.invoiceReceiveDate = NFMUtil.formatDate2StrDateTime(repair.Billing_Received_Date__c); //发票接收日
                info.latestPayDate = NFMUtil.formatDate2StrDateTime(repair.Latest_Collect_Date_Priority__c); //最新回款日
                info.payCompleteDate = NFMUtil.formatDate2StrDateTime(repair.Received_Date__c); //回款完毕日
                info.incomeReckoninDate = NFMUtil.formatDate2StrDateTime(repair.Facility_Return_Receipt_Collection_Date__c); //收入计入日
                info.abandonPayDate = NFMUtil.formatDate2StrDateTime(repair.BaddebtsDate__c); //放弃回款日
                info.repairOrderCompleteDate = NFMUtil.formatDate2StrDateTime(repair.RepairOrder_Complete_Day__c); //修理单完成日
                info.applySpareEquip = repair.if_Rental_Apply__c; //是否申请备品======自己写字段
                info.supplySpareEquip = repair.Offer_Rental_New__c + ''; //是否提供备品
                info.SparePartsLendingRecord = rentalMap.get(repair.Id);

                //update        wangweipeng         2022/02/16           start
                //info.RcSorcDate = NFMUtil.formatDate2StrDateTime(repair.RcSorcDate__c);//RC转SORC日
                info.RcSorcDate = NFMUtil.formatDateTime2Str(repair.RcSorcDateTime__c);//RC转SORC日（小程序）
                //info.SorcAcceptDate = NFMUtil.formatDate2StrDateTime(repair.SorcAcceptDate__c);//SORC受理日
                info.SorcAcceptDate = NFMUtil.formatDateTime2Str(repair.SorcAcceptDateTime__c);//SORC受理日（小程序）
                //info.OgzAcceptDate = NFMUtil.formatDate2StrDateTime(repair.OgzAcceptDate__c);//OGZ受理日
                info.OgzAcceptDate = NFMUtil.formatDateTime2Str(repair.OgzAcceptDateTime__c);//OGZ受理日（小程序）
                //update        wangweipeng         2022/02/16           end

                // info.SorcOgzDate = NFMUtil.formatDate2StrDateTime(repair.SorcOgzDate__c);RcOgzDate__c

                //update   zhangyuheng    2022/03/07
                info.SorcOgzDate = NFMUtil.formatDate2StrDateTime(repair.RcOgzDate__c);

                info.cus_dn = repair.DnNO__c;
                //修理增加OTS运单号字段 thh 20220308 start
                info.OTSRepairOrder = repair.OTSRepairOrder__c;
                //修理增加OTS运单号字段 thh 20220308 end

                //报价日、初次报价日、RC修理品RC受理日（小程序）时间判断   zyh  20220315   start
                // downSDt = DownStartDt(); // 2022-5-10   zyh  update  定义上下班时间同步修改
                // downEDt = DownEndDt(); // 2022-5-10   zyh  update  定义上下班时间同步修改
                // upSDt = UpStartDt(); // 2022-5-10   zyh  update  定义上下班时间同步修改
                // upEDt = UpEndDt(); // 2022-5-10   zyh  update  定义上下班时间同步修改
                // 2022-05-07  zyh     update  start
                if (String.isNotBlank(info.FirstQuotationDate)) {
                    info.FirstQuotationDate = info.FirstQuotationDate.deleteWhitespace();
                }
                if (String.isNotBlank(info.quotationDate)) {
                    info.quotationDate = info.quotationDate.deleteWhitespace();
                }
                // 2022-05-07  zyh     update  end
                //定义下班时间
                if (String.valueOf(info.FirstQuotationDate) >= String.valueOf(DownStartDt(info.FirstQuotationDate)) && String.valueOf(info.FirstQuotationDate) <= String.valueOf(DownEndDt(info.FirstQuotationDate))) {
                    info.FirstQuotationDate = DownDt(info.FirstQuotationDate);//初次报价日
                }
                if (String.valueOf(info.RCacceptanceDate) >= String.valueOf(DownStartDt(info.RCacceptanceDate)) && String.valueOf(info.RCacceptanceDate) <= String.valueOf(DownEndDt(info.RCacceptanceDate))) {
                    info.RCacceptanceDate = DownDt(info.RCacceptanceDate);//4.修理品RC受理日
                }
                if (String.valueOf(info.quotationDate) >= String.valueOf(DownStartDt(info.quotationDate)) && String.valueOf(info.quotationDate) <= String.valueOf(DownEndDt(info.quotationDate))) {
                    info.quotationDate = DownDt(info.quotationDate);//报价日
                }
                if (String.valueOf(info.FSErepairApplyDate) >= String.valueOf(DownStartDt(info.FSErepairApplyDate)) && String.valueOf(info.FSErepairApplyDate) <= String.valueOf(DownEndDt(info.FSErepairApplyDate))) {
                    info.FSErepairApplyDate = DownDt(info.FSErepairApplyDate);//FSE修理申请时间  2022-05-06--zyh--add
                }
                if (String.valueOf(info.RCreturnDate) >= String.valueOf(DownStartDt(info.RCreturnDate)) && String.valueOf(info.RCreturnDate) <= String.valueOf(DownEndDt(info.RCreturnDate))) {
                    info.RCreturnDate = DownDt(info.RCreturnDate);//RC修理品返送日  2022-05-06--zyh--add
                }
                if (String.valueOf(info.finalTestDate) >= String.valueOf(DownStartDt(info.finalTestDate)) && String.valueOf(info.finalTestDate) <= String.valueOf(DownEndDt(info.finalTestDate))) {
                    info.finalTestDate = DownDt(info.finalTestDate);//10.最终检测日（小程序）  2022-05-06--zyh--add
                }
                if (String.valueOf(info.userAgreeDAte) >= String.valueOf(DownStartDt(info.userAgreeDAte)) && String.valueOf(info.userAgreeDAte) <= String.valueOf(DownEndDt(info.userAgreeDAte))) {
                    info.userAgreeDAte = DownDt(info.userAgreeDAte);//7.用户同意日（小程序）  2022-05-06--zyh--add
                }
                if (String.valueOf(info.engineerSendDate) >= String.valueOf(DownStartDt(info.engineerSendDate)) && String.valueOf(info.engineerSendDate) <= String.valueOf(DownEndDt(info.engineerSendDate))) {
                    info.engineerSendDate = DownDt(info.engineerSendDate);//工程师修理品寄送日  2022-05-06--zyh--add
                }
                //定义上班时间
                if (String.valueOf(info.FirstQuotationDate) >= String.valueOf(UpStartDt(info.FirstQuotationDate)) && String.valueOf(info.FirstQuotationDate) <= String.valueOf(UpEndDt(info.FirstQuotationDate))) {
                    info.FirstQuotationDate = UpDt(info.FirstQuotationDate);//初次报价日
                }
                if (String.valueOf(info.RCacceptanceDate) >= String.valueOf(UpStartDt(info.RCacceptanceDate)) && String.valueOf(info.RCacceptanceDate) <= String.valueOf(UpEndDt(info.RCacceptanceDate))) {
                    info.RCacceptanceDate = UpDt(info.RCacceptanceDate);//4.修理品RC受理日
                }
                if (String.valueOf(info.quotationDate) >= String.valueOf(UpStartDt(info.quotationDate)) && String.valueOf(info.quotationDate) <= String.valueOf(UpEndDt(info.quotationDate))) {
                    info.quotationDate = UpDt(info.quotationDate);//报价日
                }
                if (String.valueOf(info.FSErepairApplyDate) >= String.valueOf(UpStartDt(info.FSErepairApplyDate)) && String.valueOf(info.FSErepairApplyDate) <= String.valueOf(UpEndDt(info.FSErepairApplyDate))) {
                    info.FSErepairApplyDate = UpDt(info.FSErepairApplyDate);//FSE修理申请时间  2022-05-06--zyh--add
                }
                if (String.valueOf(info.RCreturnDate) >= String.valueOf(UpStartDt(info.RCreturnDate)) && String.valueOf(info.RCreturnDate) <= String.valueOf(UpEndDt(info.RCreturnDate))) {
                    info.RCreturnDate = UpDt(info.RCreturnDate);//RC修理品返送日  2022-05-06--zyh--add
                }
                if (String.valueOf(info.finalTestDate) >= String.valueOf(UpStartDt(info.finalTestDate)) && String.valueOf(info.finalTestDate) <= String.valueOf(UpEndDt(info.finalTestDate))) {
                    info.finalTestDate = UpDt(info.finalTestDate);//10.最终检测日（小程序）  2022-05-06--zyh--add
                }
                if (String.valueOf(info.userAgreeDAte) >= String.valueOf(UpStartDt(info.userAgreeDAte)) && String.valueOf(info.userAgreeDAte) <= String.valueOf(UpEndDt(info.userAgreeDAte))) {
                    info.userAgreeDAte = UpDt(info.userAgreeDAte);//7.用户同意日（小程序）  2022-05-06--zyh--add
                }
                if (String.valueOf(info.engineerSendDate) >= String.valueOf(UpStartDt(info.engineerSendDate)) && String.valueOf(info.engineerSendDate) <= String.valueOf(UpEndDt(info.engineerSendDate))) {
                    info.engineerSendDate = UpDt(info.engineerSendDate);//工程师修理品寄送日  2022-05-06--zyh--add
                }
                //报价日、初次报价日、RC修理品RC受理日（小程序）时间判断   zyh  20220315   end
                repairs.add(info);
                System.debug('repairs1:' + repairs);
            }
            logstr += '\nend';
            if (repairs.size() > 0) {
                // 2022-08-19   zyh  小程序异步处理，恢复批量发送   start
                /*rowData = NFMUtil.makeRowData(iflog, LOG_TYPE, repairs);
                if (String.isBlank(rowData.MessageGroupNumber__c)) {
                    rowData.MessageGroupNumber__c = nowStr;
                }
                execute(rowData, iflog);*/
                // 2022-08-19   zyh  小程序异步处理，恢复批量发送   end
                // 2022-05-05      zyh     update      start
                /*for (RepairOrderInfo roi : repairs ) {
                    repairs1.add(roi);
                    rowData = NFMUtil.makeRowData(iflog, LOG_TYPE, repairs1);
                    // 2022-05-07  zyh     update  start
                    if (String.isBlank(rowData.MessageGroupNumber__c)) {
                        rowData.MessageGroupNumber__c = nowStr;
                    }
                    // 2022-05-07  zyh     update  end
                    execute1(rowData, iflog);
                    // rowData = NFMUtil.makeRowData(iflog, LOG_TYPE, repairs);
                    // execute(rowData, iflog);
                    repairs1 = new List < RepairOrderInfo > ();
                }  // 2022-08-19   zyh  小程序异步处理，恢复批量发送
                */
                for (Integer i=1;  i <= repairs.size();i++ ) {
                    if(Math.mod(i, 20) > 0 ){
                        repairs1.add(repairs[i-1]);
                        if(i == repairs.size()){
                            rowData = NFMUtil.makeRowData(iflog, LOG_TYPE, repairs1);
                            if (String.isBlank(rowData.MessageGroupNumber__c)) {
                                rowData.MessageGroupNumber__c = nowStr;
                            }
                            execute1(rowData, iflog);
                        }
                    }else{
                        repairs1.add(repairs[i-1]);
                        rowData = NFMUtil.makeRowData(iflog, LOG_TYPE, repairs1);
                        if (String.isBlank(rowData.MessageGroupNumber__c)) {
                            rowData.MessageGroupNumber__c = nowStr;
                        }
                        execute1(rowData, iflog);
                        repairs1 = new List < RepairOrderInfo > ();
                    }
                    
                } 
                upsert logList;
                upsert rowList;  // 2022-08-19   zyh  小程序异步处理，恢复批量发送
                // 2022-05-11  zyh     update start
                if (logMap.size() > 0) {
                    delete logMap.values();
                }
                // 2022-05-11  zyh     update end
                // delete logMap.values();
                // 2022-05-05      zyh     update      end
                // upsert rowData;
            }
        } catch (Exception e) {
            // 发生错误时
            System.debug(Logginglevel.ERROR, LOG_TYPE + iflog.Name + ':' + e.getMessage());
            System.debug(Logginglevel.ERROR, LOG_TYPE + iflog.Name + ':' + e.getStackTraceString());
            logstr += e.getMessage();
            iflog.ErrorLog__c += e.getMessage() + '\n';
            iflog.ErrorLog__c += e.getStackTraceString() + '\n';
            iflog.Log__c = iflog.Log__c + logstr;
            upsert iflog;
        }
        if (rowData != null) {
            upsert rowData;
        }

    }
    /**
     * 接口发送失败 根据BatchLogId进行手动发送
     * @Author   XHL
     * @DateTime 2021-07-22
     * @param    rowDataId  [BatchLogId]
     */
    public static void ManualExecute(String rowDataId) {
        List < BatchIF_Log__c > row = [select id, name, MessageGroupNumber__c, retry_cnt__c,
            RowDataFlg__c, ErrorLog__c, Type__c,
            Log__c, Log2__c, Log3__c, Log4__c, Log5__c, Log6__c,
            Log7__c, Log8__c, Log9__c, Log10__c, Log11__c, Log12__c
            from BatchIF_Log__c
            where id =: rowDataId
        ];
        if (row.size() > 0) execute(row[0], null);
    }
    /**
     * 逻辑正常执行发送
     * @Author   XHL
     * @DateTime 2021-07-22
     * @param    rowDataSFDC [BatchLogId]
     * @param    iflog       [执行情况记录]
     */
    public static void execute(BatchIF_Log__c rowDataSFDC, BatchIF_Log__c iflog) {
        Integer batch_retry_max_cnt = Integer.valueOf(System.Label.batch_retry_max_cnt);

        String logstr = rowDataSFDC.Name + ' start\n';
        if (iflog == null) {
            iflog = new BatchIF_Log__c();
            iflog.Type__c = LOG_TYPE;
            iflog.MessageGroupNumber__c = rowDataSFDC.MessageGroupNumber__c;
            iflog.Log__c = logstr;
            iflog.ErrorLog__c = '';

        } else {
            iflog.Type__c = LOG_TYPE;
            iflog.MessageGroupNumber__c = rowDataSFDC.MessageGroupNumber__c;
            logstr = iflog.Log__c;
        }

        try {
            String data = NFMUtil.getRowDataStr(rowDataSFDC);
            String status = NFMUtil.sendToAWS(data, API);
            System.debug('NFM603Log--status->' + status);

            if ('OK'.equals(status)) {
                logstr += status + '\n';
                rowDataSFDC.retry_cnt__c = 0;
            } else {
                // rowDataSFDC = NFMUtil.LogAutoSend(rowDataSFDC, null, status);    //2022-06-24   zyh   注释：重发逻辑修改
                //2022-06-24   zyh   update   start
                if (rowDataSFDC.retry_cnt__c == null) rowDataSFDC.retry_cnt__c = 0;
                if (rowDataSFDC.retry_cnt__c < batch_retry_max_cnt) {
                    rowDataSFDC.retry_cnt__c++;
                    LogAutoSendSchedule.logId = rowDataSFDC.Id;
                    LogAutoSendSchedule.assignOneMinute();
                }
                if (rowDataSFDC.retry_cnt__c >= batch_retry_max_cnt) {
                    rowDataSFDC.ErrorLog__c = 'status:' + status +
                                          '\n错误次数已经超过自动送信设定的最大次数，请手动送信';
                }
                //2022-06-24   zyh   update   end
            }

        } catch (Exception ex) {
            // TODO IOException
            // 错误发生时
            logstr += ex.getMessage();
            iflog.ErrorLog__c += ex.getMessage() + '\n';
            iflog.ErrorLog__c += ex.getStackTraceString() + '\n';
            if(!Test.isRunningTest()){
                // rowDataSFDC = NFMUtil.LogAutoSend(rowDataSFDC, ex, null);    //2022-06-24   zyh   注释：重发逻辑修改
                //2022-06-24   zyh   update   start
                if (rowDataSFDC.retry_cnt__c == null) rowDataSFDC.retry_cnt__c = 0;
                if (rowDataSFDC.retry_cnt__c < batch_retry_max_cnt){
                    rowDataSFDC.retry_cnt__c++;
                    LogAutoSendSchedule.logId = rowDataSFDC.Id;
                    LogAutoSendSchedule.assignOneMinute();
                }
                if (rowDataSFDC.retry_cnt__c >= batch_retry_max_cnt){
                    rowDataSFDC.ErrorLog__c = ex.getMessage() + '\n' + ex.getStackTraceString() + '\n' + rowDataSFDC.ErrorLog__c+'错误次数已经超过自动送信设定的最大次数，请手动送信';
                }
                //2022-06-24   zyh   update   end
            }
        }
        iflog.Log__c = logstr;
        upsert iflog;
        upsert rowDataSFDC;
        // logList.add(iflog);
        // rowList.add(rowDataSFDC);

    }
    // 2022-05-05      zyh     update      start
    public static void execute1(BatchIF_Log__c rowDataSFDC, BatchIF_Log__c iflog) {
        Integer batch_retry_max_cnt = Integer.valueOf(System.Label.batch_retry_max_cnt);

        String logstr = rowDataSFDC.Name + ' start\n';
        // String logstr = rowDataSFDC.MessageGroupNumber__c + ' start\n';
        if (iflog == null) {
            iflog = new BatchIF_Log__c();
            iflog.Type__c = LOG_TYPE;
            iflog.MessageGroupNumber__c = rowDataSFDC.MessageGroupNumber__c;
            iflog.Log__c = logstr;
            iflog.ErrorLog__c = '';

        } else {
            // iflog.Type__c = LOG_TYPE;
            // iflog.MessageGroupNumber__c = rowDataSFDC.MessageGroupNumber__c;
            // logstr = iflog.Log__c;
            // 2022-05-11  zyh     update start
            if (String.isNotBlank(iflog.Id)) {
                logMap.put(iflog.Id, iflog);
            }
            // 2022-05-11  zyh     update end
            // logMap.put(iflog.Id, iflog);
            iflog = new BatchIF_Log__c();
            iflog.Type__c = LOG_TYPE;
            iflog.MessageGroupNumber__c = rowDataSFDC.MessageGroupNumber__c;
            iflog.Log__c = logstr;
            iflog.ErrorLog__c = '';
        }

        try {
            String data = NFMUtil.getRowDataStr(rowDataSFDC);
            String status = NFMUtil.sendToAWS(data, API);
            System.debug('NFM603Log--status->' + status);

            if ('OK'.equals(status)) {
                logstr += status + '\n';
                rowDataSFDC.retry_cnt__c = 0;
            } else {
                // rowDataSFDC = NFMUtil.LogAutoSend(rowDataSFDC, null, status);    //2022-06-24   zyh   注释：重发逻辑修改
                //2022-06-24   zyh   update   start
                if (rowDataSFDC.retry_cnt__c == null) rowDataSFDC.retry_cnt__c = 0;
                if (rowDataSFDC.retry_cnt__c < batch_retry_max_cnt) {
                    rowDataSFDC.retry_cnt__c++;
                    LogAutoSendSchedule.logId = rowDataSFDC.Id;
                    LogAutoSendSchedule.assignOneMinute();
                }
                if (rowDataSFDC.retry_cnt__c >= batch_retry_max_cnt) {
                    rowDataSFDC.ErrorLog__c = 'status:' + status +
                                          '\n错误次数已经超过自动送信设定的最大次数，请手动送信';
                }
                //2022-06-24   zyh   update   end
            }

        } catch (Exception ex) {
            // TODO IOException
            // 错误发生时
            logstr += ex.getMessage();
            iflog.ErrorLog__c += ex.getMessage() + '\n';
            iflog.ErrorLog__c += ex.getStackTraceString() + '\n';
            if(!Test.isRunningTest()){
                // rowDataSFDC = NFMUtil.LogAutoSend(rowDataSFDC, ex, null);    //2022-06-24   zyh   注释：重发逻辑修改
                //2022-06-24   zyh   update   start
                if (rowDataSFDC.retry_cnt__c == null) rowDataSFDC.retry_cnt__c = 0;
                if (rowDataSFDC.retry_cnt__c < batch_retry_max_cnt){
                    rowDataSFDC.retry_cnt__c++;
                    LogAutoSendSchedule.logId = rowDataSFDC.Id;
                    LogAutoSendSchedule.assignOneMinute();
                }
                if (rowDataSFDC.retry_cnt__c >= batch_retry_max_cnt){
                    rowDataSFDC.ErrorLog__c = ex.getMessage() + '\n' + ex.getStackTraceString() + '\n' + rowDataSFDC.ErrorLog__c+'错误次数已经超过自动送信设定的最大次数，请手动送信';
                }
                //2022-06-24   zyh   update   end
            }
        }
        iflog.Log__c = logstr;
        // upsert iflog;
        // upsert rowDataSFDC;
        logList.add(iflog);
        rowList.add(rowDataSFDC);

    } // 2022-08-19   zyh  小程序异步处理，恢复批量发送   

    // 2022-05-05      zyh     update      end
    // 故障描述
    private static Map < id, List < FaultDesc >> getFaultDescMap(List < String > repairOrderIdList) {
        List < Repair_reason__c > reasonList =
            [SELECT Id, DescriptionName__c, LocationName__c, ActivityDescription__c, Repair__c
                FROM Repair_reason__c
                WHERE Repair__c
                IN: repairOrderIdList
            ];
        Map < id, List < FaultDesc >> reasonMap = new Map < id, List < FaultDesc >> ();
        for (Repair_reason__c reason: reasonList) {
            List < FaultDesc > temp = reasonMap.get(reason.Repair__c);
            if (temp == null) {
                temp = new List < FaultDesc > ();
            }
            FaultDesc faulDesc = new FaultDesc();
            faulDesc.repairPosition = reason.LocationName__c; //修理部位
            faulDesc.faultDescription = reason.DescriptionName__c; //故障描述
            faulDesc.repairContentDesc = reason.ActivityDescription__c; //修理内容描述
            temp.add(faulDesc);
            reasonMap.put(reason.Repair__c, temp);
        }

        return reasonMap;


    }

    // 备品出借记录
    private static Map < id, List < SparePartsLendingRecord >> getrentalMap(List < Id > repairIdList) {
        List < Rental_Apply_Equipment_Set_Detail__c > equipList = [
            SELECT Name, Repair__c, Bollow_Date__c, Fixture_Model_No__c, Fixture_Model_No_F__c, Cancel_Select__c,
            Rental_Apply_Equipment_Set__r.Rental_Apply__r.Name,
            Rental_Apply_Equipment_Set__r.Bollow_Date__c,
            Rental_Apply_Equipment_Set__r.Rental_Apply__r.Repair__c
            FROM Rental_Apply_Equipment_Set_Detail__c WHERE Cancel_Select__c = false AND Rental_Apply_Equipment_Set__r.Rental_Apply__r.Repair__c IN: repairIdList
        ];
        Map < id, List < SparePartsLendingRecord >> rentalMap = new Map < id, List < SparePartsLendingRecord >> ();

        for (Rental_Apply_Equipment_Set_Detail__c detail: equipList) {
            String repairId = detail.Rental_Apply_Equipment_Set__r.Rental_Apply__r.Repair__c;
            List < SparePartsLendingRecord > renList = rentalMap.get(repairId);
            if (renList == null) {
                renList = new List < SparePartsLendingRecord > ();
            }
            SparePartsLendingRecord splr = new SparePartsLendingRecord();
            splr.spareEquipapplicationNo = detail.Rental_Apply_Equipment_Set__r.Rental_Apply__r.Name; //备品申请编号
            splr.spareEquipLendingDate = NFMUtil.formatDate2StrDateTime(detail.Rental_Apply_Equipment_Set__r.Bollow_Date__c); //备品出借日期
            splr.spareEquipMode = detail.Fixture_Model_No_F__c;
            renList.add(splr);
            rentalMap.put(repairId, renList);
        }
        return rentalMap;
    }

    public static Set < Id > NFM603_Ids = new Set < Id > ();
    // public static Map<Id,Id> rprIdMap = new Map<Id,Id>();
    
    public static void NFM603Trigger(List < Repair__c > newList, Map < Id, Repair__c > newMap, List < Repair__c > oldList, Map < Id, Repair__c > oldMap) {
        List < String > rprIds = new List < String > ();
        Map < Id, Id > rprIdMap = new Map < Id, Id > ();
        if (Trigger.isAfter) {
            if (Trigger.isInsert) {
                for (Repair__c rpr: newList) {
                    if (rpr.status__c == '1.受理完毕') {
                        if (NFM603Controller.NFM603_Ids.contains(rpr.Id) == false) {
                            if (String.isNotBlank(rpr.RepairSubOrder__c)) {
                                NFM603Controller.NFM603_Ids.add(rpr.Id);
                                rprIdMap.put(rpr.Id, rpr.Id);
                            }

                        }
                    }
                }
            }


            if (Trigger.isUpdate) {
                for (Repair__c rpr: newList) {
                    Repair__c oldrpr = oldMap.get(rpr.Id);
                    // 修理有报修子单号，并且 待发送AWS为false 发送给AWS
                    if (String.isNotBlank(rpr.RepairSubOrder__c) && !rpr.AwaitToSendAWS__c) {
                        if (((rpr.status__c == '0.申请完毕' || rpr.status__c == '1.受理完毕' || rpr.Status1__c == '0.删除') && (oldrpr.SAP_Transfer_time__c == null && rpr.SAP_Transfer_time__c != null)) || 
                            (rpr.Address_type__c == 'X' && (rpr.Address_Type_Index__c != oldrpr.Address_Type_Index__c)) || 
                            //  2022/4/6    zhangyuheng update start
                            (rpr.OTSRepairOrder__c != oldrpr.OTSRepairOrder__c) || // OTS订单号有值，发送AWS
                            //  2022/4/6    zhangyuheng update end
                            //  2022/4/7    zhangyuheng update start
                            (rpr.DeliveryLogisticsNo__c != oldrpr.DeliveryLogisticsNo__c) || // 送修物流单号有值，发送AWS
                            // ((rpr.Discount_Price_formula__c != oldrpr.Discount_Price_formula__c) && rpr.Repair_Firstestimated_Date_formula__c != null) || // 报价金额发生改变且初次报价日有值，发送AWS
                            ((rpr.Returns_Product_waySAP__c != oldrpr.Returns_Product_waySAP__c) && rpr.Repair_Shipped_DateTime__c != null) || // 送修方式发生改变且寄送日有值，发送AWS
                            //  2022/4/7    zhangyuheng update end
                            //  2022/4/18    zhangyuheng update start
                            (rpr.FSE_ApplyForRepair_time__c != oldrpr.FSE_ApplyForRepair_time__c) ||                   // FSE申请修理日发生改变，发送AWS
                            (rpr.Repair_Ordered_DateTime__c != oldrpr.Repair_Ordered_DateTime__c) ||                   // 4.修理品RC受理日（小程序）发生改变，发送AWS
                            // (rpr.Repair_Firstestimated_Date__c != oldrpr.Repair_Firstestimated_Date__c) ||             // 初次报价日（不用）发生改变，发送AWS   2022-05-20  zyh 注释
                            (rpr.Repair_Estimated_Date__c != oldrpr.Repair_Estimated_Date__c) ||             // 报价日（不用）--初次报价日用发生改变，发送AWS    2022-05-20    zyh    add
                            (rpr.Repair_Shipped_DateTime__c != oldrpr.Repair_Shipped_DateTime__c) ||                   // 11.RC修理品返送日（小程序）发生改变，发送AWS
                            (rpr.Repair_Final_Inspection_DateTime__c != oldrpr.Repair_Final_Inspection_DateTime__c) || // 10.最终检测日（小程序）发生改变，发送AWS
                            (rpr.Agreed_DateTime__c != oldrpr.Agreed_DateTime__c) ||                                   //7.用户同意日（小程序）发生改变，发送AWS
                            (rpr.Agreed_Date__c != oldrpr.Agreed_Date__c) ||                                           // 7.用户同意日发生改变，发送AWS
                            (rpr.engineerSendDate__c != oldrpr.engineerSendDate__c)                                    //修理品寄送日发生改变，发送AWS
                            //  2022/4/18    zhangyuheng update start
                            //LLIU-CG53S9(状态是已删除的修理单要同步到服务系统) LY 20220713 start
                            || (rpr.SAP_not_accept_repair_result__c != oldrpr.SAP_not_accept_repair_result__c)         //修理单关闭日
                            //LLIU-CG53S9(状态是已删除的修理单要同步到服务系统) LY 20220713 end
                            ) {
                            if (NFM603Controller.NFM603_Ids.contains(rpr.Id) == false) {
                                NFM603Controller.NFM603_Ids.add(rpr.Id);
                                rprIdMap.put(rpr.Id, rpr.Id);
                                System.debug('111111111111111111112222222222');
                            }
                        }
                        //  2022/4/19    zhangyuheng update start
                        // 如果同期中的修理报价（Repair_Quotation_Id__c）为空，判断初次报价日和报价金额
                        if (rpr.Repair_Quotation_Id__c != oldrpr.Repair_Quotation_Id__c) {
                            if (NFM603Controller.NFM603_Ids.contains(rpr.Id) == false) {
                                NFM603Controller.NFM603_Ids.add(rpr.Id);
                                rprIdMap.put(rpr.Id, rpr.Id);
                            }
                        }
                        if (rpr.Repair_Quotation_Id__c == null) {
                            // 如果初次报价日（不用）或折扣后金额（不用）发生改变，发送AWS
                            if (rpr.Discount_Price__c != oldrpr.Discount_Price__c || rpr.Repair_Estimated_Date__c != oldrpr.Repair_Estimated_Date__c) {
                                if (NFM603Controller.NFM603_Ids.contains(rpr.Id) == false) {
                                    NFM603Controller.NFM603_Ids.add(rpr.Id);
                                    rprIdMap.put(rpr.Id, rpr.Id);
                                }
                            }
                        }
                        // 如果同期中的修理报价（Repair_Quotation_Id__c）不为空，在RepairQuoteTrigger.ChangeRepair进行判断触发
                        //  2022/4/19    zhangyuheng update end
                        
                        //  2022/4/6    zhangyuheng update start
                        //OTS订单号有值，发送AWS
                        // if ((oldrpr.OTSRepairOrder__c == null && String.isNotBlank(rpr.OTSRepairOrder__c)) || rpr.OTSRepairOrder__c != oldrpr.OTSRepairOrder__c) {
                        //     if (NFM603Controller.NFM603_Ids.contains(rpr.Id) == false) {
                        //         NFM603Controller.NFM603_Ids.add(rpr.Id);
                        //         rprIdMap.put(rpr.Id, rpr.Id);
                        //     }
                        // }
                        //  2022/4/6    zhangyuheng update end
                        //  2022/4/7    zhangyuheng update start
                        //送修物流单号有值，发送AWS
                        // if ((oldrpr.DeliveryLogisticsNo__c == null && String.isNotBlank(rpr.DeliveryLogisticsNo__c))  || rpr.DeliveryLogisticsNo__c != oldrpr.DeliveryLogisticsNo__c) {
                        //     if (NFM603Controller.NFM603_Ids.contains(rpr.Id) == false) {
                        //         NFM603Controller.NFM603_Ids.add(rpr.Id);
                        //         rprIdMap.put(rpr.Id, rpr.Id);
                        //     }
                        // }
                        //报价金额发生改变且初次报价日有值，发送AWS
                        // if ((rpr.Discount_Price_formula__c != oldrpr.Discount_Price_formula__c) && rpr.Repair_Firstestimated_Date_formula__c != null) {
                        //     if (NFM603Controller.NFM603_Ids.contains(rpr.Id) == false) {
                        //         NFM603Controller.NFM603_Ids.add(rpr.Id);
                        //         rprIdMap.put(rpr.Id, rpr.Id);
                        //     }
                        // }
                        // if ((rpr.Returns_Product_waySAP__c != oldrpr.Returns_Product_waySAP__c) && rpr.Repair_Shipped_DateTime__c != null) {
                        //     if (NFM603Controller.NFM603_Ids.contains(rpr.Id) == false) {
                        //         NFM603Controller.NFM603_Ids.add(rpr.Id);
                        //         rprIdMap.put(rpr.Id, rpr.Id);
                        //     }
                        // }
                        //  2022/4/7    zhangyuheng update end
                        //  2022/4/18    zhangyuheng update start
                        // FSE申请修理日发生改变，发送AWS
                        // if (rpr.FSE_ApplyForRepair_time__c != oldrpr.FSE_ApplyForRepair_time__c) {
                        //     if (NFM603Controller.NFM603_Ids.contains(rpr.Id) == false) {
                        //         NFM603Controller.NFM603_Ids.add(rpr.Id);
                        //         rprIdMap.put(rpr.Id, rpr.Id);
                        //     }
                        // }
                        // 4.修理品RC受理日（小程序）发生改变，发送AWS
                        // if (rpr.Repair_Ordered_DateTime__c != oldrpr.Repair_Ordered_DateTime__c) {
                        //     if (NFM603Controller.NFM603_Ids.contains(rpr.Id) == false) {
                        //         NFM603Controller.NFM603_Ids.add(rpr.Id);
                        //         rprIdMap.put(rpr.Id, rpr.Id);
                        //     }
                        // }
                        // 初次报价日（不用）发生改变，发送AWS
                        // if (rpr.Repair_Firstestimated_Date__c != oldrpr.Repair_Firstestimated_Date__c) {
                        //     if (NFM603Controller.NFM603_Ids.contains(rpr.Id) == false) {
                        //         NFM603Controller.NFM603_Ids.add(rpr.Id);
                        //         rprIdMap.put(rpr.Id, rpr.Id);
                        //     }
                        // }
                        // 11.RC修理品返送日（小程序）发生改变，发送AWS
                        // if (rpr.Repair_Shipped_DateTime__c != oldrpr.Repair_Shipped_DateTime__c) {
                        //     if (NFM603Controller.NFM603_Ids.contains(rpr.Id) == false) {
                        //         NFM603Controller.NFM603_Ids.add(rpr.Id);
                        //         rprIdMap.put(rpr.Id, rpr.Id);
                        //     }
                        // }
                        // 10.最终检测日（小程序）发生改变，发送AWS
                        // if (rpr.Repair_Final_Inspection_DateTime__c != oldrpr.Repair_Final_Inspection_DateTime__c) {
                        //     if (NFM603Controller.NFM603_Ids.contains(rpr.Id) == false) {
                        //         NFM603Controller.NFM603_Ids.add(rpr.Id);
                        //         rprIdMap.put(rpr.Id, rpr.Id);
                        //     }
                        // }
                        //  2022/4/18    zhangyuheng update end
                        // 测试环境测试用，上线前请注掉
                        // if (rpr.Repair_Firstestimated_Date__c != oldrpr.Repair_Firstestimated_Date__c) {
                        //     if (NFM603Controller.NFM603_Ids.contains(rpr.Id) == false) {
                        //         NFM603Controller.NFM603_Ids.add(rpr.Id);
                        //         // rprIds.add(rpr.Id);
                        //         rprIdMap.put(rpr.Id, rpr.Id);
                        //     }
                        // }
                        // if (rpr.Repair_Shipped_Date__c != oldrpr.Repair_Shipped_Date__c) {
                        //     if (NFM603Controller.NFM603_Ids.contains(rpr.Id) == false) {
                        //         NFM603Controller.NFM603_Ids.add(rpr.Id);
                        //         rprIdMap.put(rpr.Id, rpr.Id);
                        //     }
                        // }
                        // 测试环境测试用，上线前请注掉
                    }

                }
            }

            rprIds = rprIdMap.values();

            if (rprIds.size() > 0) {
                BatchIF_Log__c iflog = new BatchIF_Log__c();
                iflog.Type__c = LOG_TYPE;
                iflog.Log__c = 'callout start\n';
                insert iflog;
                // 2022-04-29     zyh      update     start
                if(UserInfo.getUserId().equals(System.Label.interfaceUserID)){
                    NFM603Controller.executefuture(iflog, rprIds);
                }else{
                    NFM603Controller.callout(iflog.Id, rprIds);
                }
                // 2022-04-29     zyh      update     end
            }
        } else {
            if (Trigger.isUpdate) {
                for (Repair__c rpr: newList) {
                    Repair__c oldrpr = oldMap.get(rpr.Id);
                    // 修理的报修子单字段有值，修理单状态编号变更 需 发送AWS
                    if (String.isNotBlank(rpr.RepairSubOrder__c) && rpr.RepairOrderStatusCode__c != oldrpr.RepairOrderStatusCode__c) {
                        rpr.AwaitToSendAWS__c = true;
                    }
                }
            }
        }
    }

    //报价日、初次报价日、RC修理品RC受理日（小程序）时间方法   zyh  20220315   start
    //下班开始时间
    public static String DownStartDt(String dt){
        // String timenow = Datetime.now().format('yyyyMMddHHmmss'); 2022-5-10   zyh  update
        // String dt = NFMUtil.formatDate2Str(Date.today()); 2022-5-10   zyh  update
        String rtn = null;
        if (dt == null) {
            return rtn;
        }
        dt = dt.substring(0,8); // 2022-5-10   zyh  update
        rtn = String.valueOf(dt);
        rtn = rtn.replaceAll('-', '');
        if (rtn >= '40001231') {
            rtn = '99991231';
        } else if (rtn < '19000101') {
            rtn = '19000101';
        }
        return rtn + '173001';
    }
    //下班结束时间
    public static String DownEndDt(String dt){
        // String dt = NFMUtil.formatDate2Str(Date.today()); 2022-5-10   zyh  update
        String rtn = null;
        if (dt == null) {
            return rtn;
        }
        dt = dt.substring(0,8); // 2022-5-10   zyh  update
        rtn = String.valueOf(dt);
        rtn = rtn.replaceAll('-', '');
        if (rtn >= '40001231') {
            rtn = '99991231';
        } else if (rtn < '19000101') {
            rtn = '19000101';
        }
        return rtn + '235959';
    }
    //上班开始时间
    public static String UpStartDt(String dt){
        // String dt = NFMUtil.formatDate2Str(Date.today()); 2022-5-10   zyh  update
        String rtn = null;
        if (dt == null) {
            return rtn;
        }
        dt = dt.substring(0,8); // 2022-5-10   zyh  update
        rtn = String.valueOf(dt);
        rtn = rtn.replaceAll('-', '');
        if (rtn >= '40001231') {
            rtn = '99991231';
        } else if (rtn < '19000101') {
            rtn = '19000101';
        }
        return rtn + '000000';
    }
    //上班结束时间
    public static String UpEndDt(String dt){
        // String dt = NFMUtil.formatDate2Str(Date.today()); 2022-5-10   zyh  update
        String rtn = null;
        if (dt == null) {
            return rtn;
        }
        dt = dt.substring(0,8); // 2022-5-10   zyh  update
        rtn = String.valueOf(dt);
        rtn = rtn.replaceAll('-', '');
        if (rtn >= '40001231') {
            rtn = '99991231';
        } else if (rtn < '19000101') {
            rtn = '19000101';
        }
        return rtn + '084459';
    }
    //上班定义时间
    public static String UpDt(String dt){
        // String dt = NFMUtil.formatDate2Str(Date.today()); 2022-5-10   zyh  update
        String rtn = null;
        if (dt == null) {
            return rtn;
        }
        dt = dt.substring(0,8); // 2022-5-10   zyh  update
        rtn = String.valueOf(dt);
        rtn = rtn.replaceAll('-', '');
        if (rtn >= '40001231') {
            rtn = '99991231';
        } else if (rtn < '19000101') {
            rtn = '19000101';
        }
        return rtn + '090000';
    }
    //下班定义时间
    public static String DownDt(String dt){
        // String dt = NFMUtil.formatDate2Str(Date.today()); 2022-5-10   zyh  update
        String rtn = null;
        if (dt == null) {
            return rtn;
        }
        dt = dt.substring(0,8); // 2022-5-10   zyh  update
        rtn = String.valueOf(dt);
        rtn = rtn.replaceAll('-', '');
        if (rtn >= '40001231') {
            rtn = '99991231';
        } else if (rtn < '19000101') {
            rtn = '19000101';
        }
        return rtn + '170000';
    }
    //报价日、初次报价日、RC修理品RC受理日（小程序）时间方法   zyh  20220315   end

}