From a952b09858f9d6490a397051c7fdea59f82ebeb0 Mon Sep 17 00:00:00 2001 From: 张宇恒 <bxyun0@163.com> Date: 星期五, 06 五月 2022 10:37:55 +0800 Subject: [PATCH] 批量数据拆分处理 --- force-app/main/default/classes/NFM603Controller.cls | 242 ++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 200 insertions(+), 42 deletions(-) diff --git a/force-app/main/default/classes/NFM603Controller.cls b/force-app/main/default/classes/NFM603Controller.cls index 693757a..a94ba2a 100644 --- a/force-app/main/default/classes/NFM603Controller.cls +++ b/force-app/main/default/classes/NFM603Controller.cls @@ -4,6 +4,11 @@ // 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 { @@ -140,6 +145,7 @@ 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) { @@ -419,8 +425,20 @@ } logstr += '\nend'; if (repairs.size() > 0) { - rowData = NFMUtil.makeRowData(iflog, LOG_TYPE, repairs); - execute(rowData, iflog); + // 2022-05-05 zyh update start + for (RepairOrderInfo roi : repairs ) { + repairs1.add(roi); + rowData = NFMUtil.makeRowData(iflog, LOG_TYPE, repairs1); + execute1(rowData, iflog); + // rowData = NFMUtil.makeRowData(iflog, LOG_TYPE, repairs); + // execute(rowData, iflog); + repairs1 = new List < RepairOrderInfo > (); + } + upsert logList; + upsert rowList; + delete logMap.values(); + // 2022-05-05 zyh update end + // upsert rowData; } } catch (Exception e) { // 鍙戠敓閿欒鏃� @@ -495,14 +513,72 @@ logstr += ex.getMessage(); iflog.ErrorLog__c += ex.getMessage() + '\n'; iflog.ErrorLog__c += ex.getStackTraceString() + '\n'; - rowDataSFDC = NFMUtil.LogAutoSend(rowDataSFDC, ex, null); + if(!Test.isRunningTest()){ + rowDataSFDC = NFMUtil.LogAutoSend(rowDataSFDC, ex, null); + } } 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.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; + 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); + } + + } 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); + } + } + iflog.Log__c = logstr; + // upsert iflog; + // upsert rowDataSFDC; + logList.add(iflog); + rowList.add(rowDataSFDC); } + // 2022-05-05 zyh update end // 鏁呴殰鎻忚堪 private static Map < id, List < FaultDesc >> getFaultDescMap(List < String > repairOrderIdList) { List < Repair_reason__c > reasonList = @@ -584,59 +660,135 @@ Repair__c oldrpr = oldMap.get(rpr.Id); // 淇悊鏈夋姤淇瓙鍗曞彿锛屽苟涓� 寰呭彂閫丄WS涓篺alse 鍙戦�佺粰AWS if (String.isNotBlank(rpr.RepairSubOrder__c) && !rpr.AwaitToSendAWS__c) { - if (((rpr.status__c == '0.鐢宠瀹屾瘯' || rpr.status__c == '1.鍙楃悊瀹屾瘯') && (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))) { + if (((rpr.status__c == '0.鐢宠瀹屾瘯' || rpr.status__c == '1.鍙楃悊瀹屾瘯') && (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璁㈠崟鍙锋湁鍊硷紝鍙戦�丄WS + // 2022/4/6 zhangyuheng update end + // 2022/4/7 zhangyuheng update start + (rpr.DeliveryLogisticsNo__c != oldrpr.DeliveryLogisticsNo__c) || // 閫佷慨鐗╂祦鍗曞彿鏈夊�硷紝鍙戦�丄WS + // ((rpr.Discount_Price_formula__c != oldrpr.Discount_Price_formula__c) && rpr.Repair_Firstestimated_Date_formula__c != null) || // 鎶ヤ环閲戦鍙戠敓鏀瑰彉涓斿垵娆℃姤浠锋棩鏈夊�硷紝鍙戦�丄WS + ((rpr.Returns_Product_waySAP__c != oldrpr.Returns_Product_waySAP__c) && rpr.Repair_Shipped_DateTime__c != null) || // 閫佷慨鏂瑰紡鍙戠敓鏀瑰彉涓斿瘎閫佹棩鏈夊�硷紝鍙戦�丄WS + // 2022/4/7 zhangyuheng update end + // 2022/4/18 zhangyuheng update start + (rpr.FSE_ApplyForRepair_time__c != oldrpr.FSE_ApplyForRepair_time__c) || // FSE鐢宠淇悊鏃ュ彂鐢熸敼鍙橈紝鍙戦�丄WS + (rpr.Repair_Ordered_DateTime__c != oldrpr.Repair_Ordered_DateTime__c) || // 4.淇悊鍝丷C鍙楃悊鏃ワ紙灏忕▼搴忥級鍙戠敓鏀瑰彉锛屽彂閫丄WS + (rpr.Repair_Firstestimated_Date__c != oldrpr.Repair_Firstestimated_Date__c) || // 鍒濇鎶ヤ环鏃ワ紙涓嶇敤锛夊彂鐢熸敼鍙橈紝鍙戦�丄WS + (rpr.Repair_Shipped_DateTime__c != oldrpr.Repair_Shipped_DateTime__c) || // 11.RC淇悊鍝佽繑閫佹棩锛堝皬绋嬪簭锛夊彂鐢熸敼鍙橈紝鍙戦�丄WS + (rpr.Repair_Final_Inspection_DateTime__c != oldrpr.Repair_Final_Inspection_DateTime__c) || // 10.鏈�缁堟娴嬫棩锛堝皬绋嬪簭锛夊彂鐢熸敼鍙橈紝鍙戦�丄WS + (rpr.Agreed_DateTime__c != oldrpr.Agreed_DateTime__c) || //7.鐢ㄦ埛鍚屾剰鏃ワ紙灏忕▼搴忥級鍙戠敓鏀瑰彉锛屽彂閫丄WS + (rpr.Agreed_Date__c != oldrpr.Agreed_Date__c) || // 7.鐢ㄦ埛鍚屾剰鏃ュ彂鐢熸敼鍙橈紝鍙戦�丄WS + (rpr.engineerSendDate__c != oldrpr.engineerSendDate__c) //淇悊鍝佸瘎閫佹棩鍙戠敓鏀瑰彉锛屽彂閫丄WS + // 2022/4/18 zhangyuheng update start + ) { if (NFM603Controller.NFM603_Ids.contains(rpr.Id) == false) { NFM603Controller.NFM603_Ids.add(rpr.Id); rprIdMap.put(rpr.Id, rpr.Id); } } + // 2022/4/19 zhangyuheng update start + // 濡傛灉鍚屾湡涓殑淇悊鎶ヤ环锛圧epair_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) { + // 濡傛灉鍒濇鎶ヤ环鏃ワ紙涓嶇敤锛夋垨鎶樻墸鍚庨噾棰濓紙涓嶇敤锛夊彂鐢熸敼鍙橈紝鍙戦�丄WS + 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); + } + } + } + // 濡傛灉鍚屾湡涓殑淇悊鎶ヤ环锛圧epair_Quotation_Id__c锛変笉涓虹┖锛屽湪RepairQuoteTrigger.ChangeRepair杩涜鍒ゆ柇瑙﹀彂 + // 2022/4/19 zhangyuheng update end // 2022/4/6 zhangyuheng update start //OTS璁㈠崟鍙锋湁鍊硷紝鍙戦�丄WS - 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); - } - } + // 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 //閫佷慨鐗╂祦鍗曞彿鏈夊�硷紝鍙戦�丄WS - 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); - } - } + // 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); + // } + // } //鎶ヤ环閲戦鍙戠敓鏀瑰彉涓斿垵娆℃姤浠锋棩鏈夊�硷紝鍙戦�丄WS - if (((rpr.Discount_Price_formula__c != oldrpr.Discount_Price_formula__c) || rpr.Discount_Price_formula__c != null) && 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); - } - } + // 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鐢宠淇悊鏃ュ彂鐢熸敼鍙橈紝鍙戦�丄WS + // 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.淇悊鍝丷C鍙楃悊鏃ワ紙灏忕▼搴忥級鍙戠敓鏀瑰彉锛屽彂閫丄WS + // 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); + // } + // } + // 鍒濇鎶ヤ环鏃ワ紙涓嶇敤锛夊彂鐢熸敼鍙橈紝鍙戦�丄WS + // 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淇悊鍝佽繑閫佹棩锛堝皬绋嬪簭锛夊彂鐢熸敼鍙橈紝鍙戦�丄WS + // 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.鏈�缁堟娴嬫棩锛堝皬绋嬪簭锛夊彂鐢熸敼鍙橈紝鍙戦�丄WS + // 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); - } - } + // 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); + // } + // } // 娴嬭瘯鐜娴嬭瘯鐢紝涓婄嚎鍓嶈娉ㄦ帀 } @@ -650,7 +802,13 @@ iflog.Type__c = LOG_TYPE; iflog.Log__c = 'callout start\n'; insert iflog; - NFM603Controller.callout(iflog.Id, rprIds); + // 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) { -- Gitblit v1.9.1