张宇恒
2022-05-06 a952b09858f9d6490a397051c7fdea59f82ebeb0
批量数据拆分处理
2个文件已修改
94 ■■■■■ 已修改文件
force-app/main/default/classes/NFM603Controller.cls 86 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NFM603ControllerTest.cls 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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) {
            // 发生错误时
@@ -502,9 +520,65 @@
        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 =
@@ -728,7 +802,13 @@
                iflog.Type__c = LOG_TYPE;
                iflog.Log__c = 'callout start\n';
                insert iflog;
                NFM603Controller.executefuture(iflog, 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) {
force-app/main/default/classes/NFM603ControllerTest.cls
@@ -305,5 +305,13 @@
        Database.executeBatch(new NFM603Batch(idList),100);
        Test.stopTest();
    }
    @isTest
    static void NFM603execute(){
        List<BatchIF_Log__c> logList = [select id from BatchIF_Log__c];
        Test.startTest();
        BatchIF_Log__c iflog = logList[0];
        NFM603Controller.ManualExecute(iflog.Id);
        Test.stopTest();
    }
}