沙世明
2022-09-13 bfca7a84bec815da594f1d12558535ed06d2490b
force-app/main/default/classes/NFM103Controller.cls
@@ -110,7 +110,16 @@
        //20220330 lt WLIG-CCT9UG 【委托】关于市场多年保计提金调整  start
        public String QuotationDate;
        //20220330 lt WLIG-CCT9UG 【委托】关于市场多年保计提金调整  end
        //XLIU-CGAD3Z 【委托】备品相关字段传输至SAP LY 20220714 start
        public String BollowDate;          //备品中心出库日
        public String IfRentalApply;      //是否申请备品
        public String OfferRental;         //是否提供备品(NEW)
        //XLIU-CGAD3Z 【委托】备品相关字段传输至SAP LY 20220714 end
        //URF限次合同2期 xxf 20220811 start
        public String Series;
        //URF限次合同2期 xxf 20220811 end
        //再注册分析 需求 新增字段 20220811
        public String Reanalysis;
    }
    ////NFM103修改Rest end
@@ -118,6 +127,7 @@
    // Repair__cのId
    public static Set<Id> NFM103_Ids = new Set<Id>();
    public static String debug_msg = '';
    public static String rprId = '' ;   //2022-07-14  zyh  add
    // on Repair__c (after insert, after update)
    // 新規修理、or 受付用の項目を編集した時(RepairOrderStatusCode__c = A95時のみ 受付用の項目を編集 できます)
@@ -174,6 +184,16 @@
                            NFM103Controller.debug_msg += 'NFM103_callout_update_' + rpr.Name;
                        }
                    }
                    //XLIU-CGAD3Z 【委托】备品相关字段传输至SAP LY 20220714 start
                    if (rpr.SAPRepairNo__c !=null && (oldMap.get(rpr.Id).Bollow_Date__c != rpr.Bollow_Date__c ||oldMap.get(rpr.Id).if_Rental_Apply__c !=rpr.if_Rental_Apply__c || oldMap.get(rpr.Id).Offer_Rental_New__c != rpr.Offer_Rental_New__c)){
                        if (NFM103Controller.NFM103_Ids.contains(rpr.Id) == false) {
                            NFM103_Ids.add(rpr.Id);
                            rprIds.add(rpr.Id);
                            updMap.put(rpr.Id, new Repair__c(Id = rpr.Id,Address_type__c = 'A'));
                            NFM103Controller.debug_msg += 'NFM103_callout_update2_' + rpr.Name;
                        }
                    }
                    //XLIU-CGAD3Z 【委托】备品相关字段传输至SAP LY 20220714 end
//                    // RepairOrderStatusCode__c = A95 (取消修理受理)の時だけ 受付用の項目を編集した時、再度 SAP に送信
//                    // TODO SAP側 同じ番号の再送はできるか?、使ってないかも!!
//                    else if (NFM103Controller.NFM103_Ids.contains(rpr.Id) == false && rpr.RepairOrderStatusCode__c == 'A95') {
@@ -204,7 +224,18 @@
            insert iflog;
            iflog = [Select Id, Name from BatchIF_Log__c where Id = :iflog.Id];
            System.debug(Logginglevel.DEBUG, 'NFM103_' + iflog.Name + ' start');                  // callout の中 end のlogを出します
            NFM103Controller.callout(iflog.Id, rprIds);
            // 20220902 ljh XLIU-CHSD8G update start
            // NFM103Controller.callout(iflog.Id, rprIds, null);
            String uid = UserInfo.getUserId();
            String BUid = System.Label.Batch_User_Id;
            System.debug('zheli');
            if (uid.substring(0,15) == BUid.substring(0,15)) {
                NFM103Controller.calloutNotfuture(iflog.Id, rprIds, null);
            }else{
                NFM103Controller.callout(iflog.Id, rprIds, null);
            }
            // 20220902 ljh XLIU-CHSD8G update end
        }
        System.debug('-----NFM103Trigger end');
    }
@@ -214,11 +245,14 @@
     *
     * @param iflog_Id           ログテーブルのId
     * @param repairIds          送信対象修理
     * @param reanalysisFlag     再注册分析使用 --- 再修理分析状态
     */
    @future (callout = true)
    public static void callout(String iflog_Id, List<Id> repairIds) {
    public static void callout(String iflog_Id, List<Id> repairIds, String reanalysisFlag) {
       calloutNotfuture( iflog_Id,  repairIds,  reanalysisFlag);
    }
    //20220902 ljh 新增(复制callout)方法
    public static void calloutNotfuture(String iflog_Id, List<Id> repairIds, String reanalysisFlag) {
        if (repairIds == null || repairIds.size() == 0) {
            return;
        }
@@ -341,6 +375,20 @@
                                         //20220330 lt WLIG-CCT9UG 【委托】关于市场多年保计提金调整  start
                                         ,Delivered_Product__r.Backorder__r.Opportunity__r.SAP_Send_OK_Date__c
                                         //20220330 lt WLIG-CCT9UG 【委托】关于市场多年保计提金调整  end
                                         //XLIU-CEX8A6 中文标签导入-SFDC传输型号修改(优先对应) 20220602 LY Start
                                         ,Delivered_Product__r.Product2.Chinese_Labels__c
                                         //XLIU-CEX8A6 中文标签导入-SFDC传输型号修改(优先对应) 20220602 LY End
                                         //XLIU-CGAD3Z 【委托】备品相关字段传输至SAP LY 20220714 start
                                         ,Bollow_Date__c       //备品中心出库日
                                         ,if_Rental_Apply__c   //是否申请备品
                                         ,Offer_Rental_New__c  //是否提供备品(NEW)
                                         //XLIU-CGAD3Z 【委托】备品相关字段传输至SAP LY 20220714 end
                                         //URF限次合同2期 xxf 20220811 start
                                         ,Delivered_Product__r.Product2.ProductURF__c
                                         ,Delivered_Product__r.Product2.ProductURF__r.URFLimitSerial__c
                                         ,URF_Reapir__c
                                         ,Maintenance_Contract__r.URF_Contract__c
                                         //URF限次合同2期 xxf 20220811 end
                                         from Repair__c where Id IN :repairIds];          // 削除データを検索しないはず、All ROWS いらないはず
            System.debug(Logginglevel.DEBUG, 'NFM103_ recptList.size()=' + recptList.size());
@@ -362,9 +410,17 @@
                element.DepartmentNo              = rpr.Account__r.Management_Code__c;
                element.SAPAgentNo                = rpr.Dealer__r.Management_Code__c;
                element.RepairOTCode              = rpr.Delivered_Product__r.Product2.ProductCode;
                //LJPH-C7Z8AP LY Start
                element.RepairModel               = rpr.Delivered_Product__r.Product2.Asset_Model_No__c;
                // LJPH-C9SB9C LHJ 特殊对应 Start
                //element.RepairModel               = rpr.Delivered_Product__r.Product2.Asset_Model_No__c;
                //LJPH-C9SB9C LHJ 特殊对应 Start
                //XLIU-CEX8A6 中文标签导入-SFDC传输型号修改(优先对应) 20220602 LY Start
                if (String.isBlank(rpr.Delivered_Product__r.Product2.Chinese_Labels__c)) {
                    element.RepairModel               = rpr.Delivered_Product__r.Product2.Asset_Model_No__c;
                } else {
                    element.RepairModel               = rpr.Delivered_Product__r.Product2.Chinese_Labels__c;
                }
                //XLIU-CEX8A6 中文标签导入-SFDC传输型号修改(优先对应) 20220602 LY End
                if (element.RepairModel == 'G400') {
                    element.RepairModel = '777000';
                } else if (element.RepairModel == 'EU-ME2(KEYBOARD)') {
@@ -395,7 +451,7 @@
                element.TradeType                 = NFMUtil.getMapValue(transferMap, 'Trade__c', rpr.Delivered_Product__r.Backorder__r.Opportunity__r.Trade__c, iflog);
                //20220330 lt WLIG-CCT9UG 【委托】关于市场多年保计提金调整  start
                element.QuotationDate = NFMUtil.formatDateTime2StrSprit2(rpr.Delivered_Product__r.Backorder__r.Opportunity__r.SAP_Send_OK_Date__c).replaceAll('/', '');
                element.QuotationDate = rpr.Delivered_Product__r.SerMarGuranteeType__c != '市场多年保修'  ? '' : NFMUtil.formatDateTime2StrSprit2(rpr.Delivered_Product__r.Backorder__r.Opportunity__r.SAP_Send_OK_Date__c).replaceAll('/', '');
                //20220330 lt WLIG-CCT9UG 【委托】关于市场多年保计提金调整  end
                // 多年保修 LHJ Start
@@ -490,11 +546,37 @@
                 element.Address                    = rpr.Detailed_Address__c;   //详细地址
                 element.Postal                     = rpr.address_ZipCode__c;    //邮编
                 element.ReturnType                 = NFMUtil.getMapValue(ReturnsProductWayMap,'Returns_Product_way__c', rpr.Returns_Product_way__c, iflog);//返品方式
                 element.UpdateStatus               = rpr.Address_type__c;    //申请修理时间
                 // modify by liu 20220909 再注册项目NFM103接口连通测试时追加对应 start
                 // element.UpdateStatus               = rpr.Address_type__c;    //申请修理时间
                 if (String.isNotBlank(reanalysisFlag)) {
                    element.UpdateStatus               = 'X';    //申请修理时间
                 } else {
                    element.UpdateStatus               = rpr.Address_type__c;    //申请修理时间
                 }
                 // modify by liu 20220909 再注册项目NFM103接口连通测试时追加对应 end
                 //add by wangweipeng  2021/07/14   end
                 //add pi 密文 sushanhu 20220222 start
                 element.DataId                     =rpr.AWS_Data_Id__c;//aws存储凭证
                 //add pi 密文 sushanhu 20220222 end
                 //XLIU-CGAD3Z 【委托】备品相关字段传输至SAP LY 20220714 start
                 element.BollowDate                =NFMUtil.formatDate2Str(rpr.Bollow_Date__c);       //备品中心出库日
                 element.IfRentalApply             =rpr.if_Rental_Apply__c ? 'X':'';   //是否申请备品
                 element.OfferRental               =rpr.Offer_Rental_New__c ? 'X':'';  //是否提供备品(NEW)
                 //XLIU-CGAD3Z 【委托】备品相关字段传输至SAP LY 20220714 end
                 //URF限次合同2期 xxf 20220811 start
                 if (rpr.Maintenance_Contract__r.URF_Contract__c == true && rpr.Delivered_Product__r.Product2.ProductURF__c !=null) {
                    element.Series                 =rpr.Delivered_Product__r.Product2.ProductURF__r.URFLimitSerial__c =='URF-P'?'P':'V';   //限次合同系列
                 }else{
                    element.Series                 =null;
                 }
                 //URF限次合同2期 xxf 20220811 end
                 rprId = rpr.Id;   //2022-07-14  zyh  add
                 //再注册分析 需求 新增字段 20220811 sx start
                 element.Reanalysis                = reanalysisFlag;
                 //再注册分析 需求 新增字段 20220811 sx end
            }
@@ -525,14 +607,27 @@
                // NFM103修改Rest end
                execute(rowData, iflog);
            }
            logstr += '\nStatus:' + status;
            logstr += '\nStatus:' + status ;
            // WLIG-BXQBH6 start 保存回复内容
            logstr += '\nResponse:' + responseBody;
            System.debug('SAPRepairNo2:' + SAPRepairNo);
            if(string.isNotEmpty(SAPRepairNo)){
                System.debug('SAPRepairNo3:' + SAPRepairNo);
                Repair__c rpr = new repair__c(id = repairIds[0], SAPRepairNo__c = SAPRepairNo);
                System.debug('rpr1:' + rpr);
                update rpr;
            }
            // WLIG-BXQBH6 end 保存回复内容
            //备品相关字段传输至SAP LY 20220908 start
            List <Repair__c> rprflag = new List <Repair__c>();
            for (Id idflag :repairIds){
                Repair__c rprnew = new repair__c();
                rprnew.id = idflag;
                rprnew.Address_type__c = '';
                rprflag.add(rprnew);
            }
            update rprflag;
            //备品相关字段传输至SAP LY 20220908 end
            logstr += '\nend';
        } catch (Exception ex) {
            // エラーが発生した場合
@@ -579,6 +674,11 @@
            logstr = iflog.Log__c;
        }
        try {
            // if (rowData.retry_cnt__c >= 1) {
            // }else {
            //     List<BatchIF_Log__c> logList = [Select Id, Name, Log__c, ErrorLog__c from BatchIF_Log__c where Id = :rowData.Id];
            //     BatchIF_Log__c log1 = logList[9];
            // }  //2022-07-18   zyh 注释
            // NFM103修改Rest start
            // Nfm103Sync.HTTPS_Port stub = new Nfm103Sync.HTTPS_Port();
            // stub.timeout_x = 100000; // timeout in milliseconds
@@ -597,8 +697,8 @@
            // NFMUtil.response response =
            //     NFMUtil.sendToSapStatusAndBody(rowDataStr, NFMUtil.NFM103_ENDPOINT);
                //update to aws 20220222 sushanhu start for PIPL
               PIHelper.PIIntegration NFM103AWS =PIHelper.getPIIntegrationInfo('NFM103');
               NFMUtil.response response =     NFMUtil.sendToPiAWS(rowDataStr, NFM103AWS.newUrl,NFM103AWS.token);
            PIHelper.PIIntegration NFM103AWS =PIHelper.getPIIntegrationInfo('NFM103');
            NFMUtil.response response =     NFMUtil.sendToPiAWS(rowDataStr, NFM103AWS.newUrl,NFM103AWS.token);
                //update to aws 20220222 sushanhu end for PIPL
            status = response.status;
            system.debug('AWS Response status:'+status);
@@ -613,6 +713,7 @@
                NFM103Response =
                    (NFM103Response) JSON.deserializeStrict(ResponseBody, NFM103Response.class);
            }
            System.debug('NFM103Response.SAPRepairNo:' + NFM103Response.response[0].LOG.SAPRepairNo);
            if (NFM103Response.response != null &&
                    NFM103Response.response.size() > 0 &&
                    NFM103Response.response[0].LOG != null &&
@@ -620,6 +721,23 @@
                    SAPRepairNo = NFM103Response.response[0].LOG.SAPRepairNo;
            }
            System.debug('SAPRepairNo1===:' + SAPRepairNo);
            //2022-07-14  zyh  add   start
            // if (rowData.retry_cnt__c != 2) {
            //     String srn = NFM103Response.Response[9].LOG.SAPRepairNo;
            // }
            String repairNo1 = nfm103.RepairRequest.GeneralData[0].SFDCRepairNo;
            System.debug('repairNo1--------------------1:' + repairNo1);
            List<Repair__c> repairList = [SELECT Id From Repair__c Where Name = :repairNo1];
            if(string.isNotEmpty(SAPRepairNo)){
                System.debug('SAPRepairNo3-1:' + SAPRepairNo);
                System.debug('rprId--------------------1:' + rprId);
                Repair__c rpr = new repair__c(id = repairList[0].Id, SAPRepairNo__c = SAPRepairNo);
                System.debug('rpr1-1:' + rpr);
                update rpr;
            }
            //2022-07-14  zyh  add   end
            rowData.retry_cnt__c = 0;
            //add           wangweipeng                       2022/02/18               start
            //如果为true,证明是重新发送的接口,需要把日志记录下
@@ -683,6 +801,7 @@
            iflog.ErrorLog__c += ex.getMessage() + '\n';
            iflog.ErrorLog__c += ex.getStackTraceString() + '\n';
                System.debug('标记0--------------------1:' + rowData.retry_cnt__c);
            //---Gaozw---add
            if (rowData.retry_cnt__c == null) rowData.retry_cnt__c = 0;
            if (rowData.retry_cnt__c < batch_retry_max_cnt) {