涂煌豪
2022-05-16 d075f9ef422d029599749fcf65c44740dbe4d8f9
【委托】电子签收单RPA系统迁移
2个文件已修改
12个文件已添加
443 ■■■■■ 已修改文件
force-app/main/default/classes/LogAutoSendBatch.cls 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NFM116Batch.cls 69 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NFM116Batch.cls-meta.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NFM116BatchSchedule.cls 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NFM116BatchSchedule.cls-meta.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NFM116BatchScheduleTest.cls 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NFM116BatchScheduleTest.cls-meta.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NFM116BatchTest.cls 72 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NFM116BatchTest.cls-meta.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NFM116Controller.cls 150 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NFM116Controller.cls-meta.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NFM116ControllerTest.cls 58 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NFM116ControllerTest.cls-meta.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NFMUtil.cls 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/LogAutoSendBatch.cls
@@ -172,6 +172,11 @@
                NFM114Rest.main(rowData.Id);
            }
            // 2021/12/1 fxk add End
            // // 电子签收单发送SAP接口 thh 20220427 start
            if (strType_c == 'NFM116') {
                NFM116Controller.execute(rowData,null);
            }
            // // 电子签收单发送SAP接口 thh 20220427 end
            // 三方接口
            if (strType_c == 'NFM201') {
                NFM201Controller.execute(rowData, null);
@@ -257,15 +262,18 @@
            if (strType_c == 'NFM621') {
                NFM621Controller.execute(rowData, null);
            }
            // if (strType_c == 'NFM624') {//智慧医疗pk
            //     NFM624Rest.main(rowData.Id);
            // }
            if (strType_c == 'NFM624') {//智慧医疗pk
                NFM624Rest.main(rowData.Id);
            }
            if (strType_c == 'NFM622') {
                NFM622Controller.execute(rowData, null);
            }
            // if (strType_c == 'NFM112') {//先款后修pk
            //     NFM112Controller.execute(rowData, null);
            // }
            if (strType_c == 'NFM112') {//先款后修pk
                NFM112Controller.ManualExecute(rowData.id);
            }
            if (strType_c == 'NFM113') {//先款后修pk
                NFM113Rest.main(rowData.id);
            }
            if (strType_c == 'NFM701') {
                NFM701Controller.execute(rowData, null);
            }
@@ -275,9 +283,9 @@
            if (strType_c == 'NFM703') {
                NFM703Controller.execute(rowData, null);
            }
            // if (strType_c == 'NFM704') {
            //     NFM704Rest.executefuture(rowData.Id);
            // }
            if (strType_c == 'NFM704') {
                NFM704Rest.executefuture(rowData.Id);
            }
            if (strType_c == 'NFM705') {
                NFM705Rest.main(rowData.Id);
            }
force-app/main/default/classes/NFM116Batch.cls
New file
@@ -0,0 +1,69 @@
global class NFM116Batch implements Database.Batchable<sObject>, Database.AllowsCallouts {
    // 设定发送指定签收单的ID
    public String setId;
    // 设定执行日期
    public Date setDate;
    // 是否发送指定日期30天之后的签收单
    public Boolean isAfterDate = false;
    // 是否发送指定的签收单
    public Boolean isAppoint = false;
    // 设定发送的签收单的IdList
    public List<String> setIdList;
    // Default 发送当日符合条件的签收单
    global NFM116Batch() {
        this.setDate = Date.today();
    }
    // 发送指定日期符合条件的签收单, eg: testDate = Date.newInstance(2022, 05, 02),发送20220501完成签收的签收单
    global NFM116Batch(Date testDate) {
        this.setDate = testDate;
    }
    // 发送在指定日期30天之后的所有符合条件的签收单(isAfterDate为true的时候)
    global NFM116Batch(Date testDate, Boolean isAfterDate) {
        this.setDate = testDate;
        this.isAppoint = true;
        this.isAfterDate = isAfterDate;
    }
    // 发送指定Id的签收单
    global NFM116Batch(String setId) {
        this.setId = setId;
        this.isAppoint = true;
    }
    // 发送指定IdList的签收单
    global NFM116Batch(List<String> setIdList) {
        this.setIdList = setIdList;
        this.isAppoint = true;
    }
    global Database.QueryLocator start(Database.BatchableContext bc) {
        String query = 'select Id from eSignForm__c where agencyAcceptSAPResult__c != null and HPAcceptSAPResult__c != null ';
        if(String.isNotBlank(setId)){
            query += ' and Id =: setId ';
        } else if (setIdList != null && setIdList.size() > 0) {
            query += ' and Id IN: setIdList ';
        } else if(!isAppoint){
            query += ' and SAPReportDate__c = ' + setDate.addDays(-1).format().replace('/', '-') ;
        } else if(isAfterDate){
            query += ' and SAPReportDate__c > ' + setDate.addDays(-30).format().replace('/', '-') ;
        }
        System.debug('thhquery:' + query);
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, List<eSignForm__c> eSignFormList) {
        List<String> eSignFormIdList = new List<String>();
        if(eSignFormList.size() > 0){
            for(eSignForm__c es : eSignFormList){
                eSignFormIdList.add(es.Id);
            }
        }
        System.debug('eSignFormIdList1:' + eSignFormIdList);
        if(eSignFormIdList.size() > 0){
            NFM116Controller.executeNotFuture(null, eSignFormIdList);
        }
    }
    global void finish(Database.BatchableContext BC) {
    }
}
force-app/main/default/classes/NFM116Batch.cls-meta.xml
New file
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>54.0</apiVersion>
    <status>Active</status>
</ApexClass>
force-app/main/default/classes/NFM116BatchSchedule.cls
New file
@@ -0,0 +1,6 @@
global class NFM116BatchSchedule implements Schedulable {
    global void execute(SchedulableContext SC) {
        Id execBTId = Database.executeBatch(new NFM116Batch(), 200);
    }
}
force-app/main/default/classes/NFM116BatchSchedule.cls-meta.xml
New file
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>54.0</apiVersion>
    <status>Active</status>
</ApexClass>
force-app/main/default/classes/NFM116BatchScheduleTest.cls
New file
@@ -0,0 +1,20 @@
@isTest
private class NFM116BatchScheduleTest {
    static testMethod void testExecute() {
        // This test runs a scheduled job at midnight Sept. 3rd. 2022
        String CRON_EXP = '0 0 0 3 9 ? 2022';
        System.Test.startTest();
        // Schedule the test job
        String jobId = System.schedule('NFM116BatchScheduleTest', CRON_EXP, new NFM116BatchSchedule());
        // Get the information from the CronTrigger API object
        CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId];
        // Verify the expressions are the same
        System.assertEquals(CRON_EXP, ct.CronExpression);
        // Verify the job has not run
        System.assertEquals(0, ct.TimesTriggered);
        // Verify the next time the job will run
        System.assertEquals('2022-09-03 00:00:00', String.valueOf(ct.NextFireTime));
        System.Test.StopTest();
    }
}
force-app/main/default/classes/NFM116BatchScheduleTest.cls-meta.xml
New file
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>54.0</apiVersion>
    <status>Active</status>
</ApexClass>
force-app/main/default/classes/NFM116BatchTest.cls
New file
@@ -0,0 +1,72 @@
@isTest
private class NFM116BatchTest {
    @TestSetup
    static void makeData(){
        Opportunity opp = new Opportunity();
        opp.Opportunity_No__c = 'XB-153P-06-S151289';
        opp.Opportunity_Category__c = 'ET';
        opp.StageName = '目標';
        opp.Authorized_DB_No__c = 'XB-153P-06-S151289';
        opp.Name = '::XB-153P-06-S151289';
        opp.Close_Forecasted_Date__c = Date.today();
        opp.CloseDate = Date.today();
        opp.Opp_Confirmation_Day__c = Date.today();
        insert opp;
        Statu_Achievements__c Statu1 = new Statu_Achievements__c();
        Statu1.ContractNO__c = 'SH-ET-191025';
        Statu1.Opportunity__c = opp.Id;
        Statu1.ContractAmount__c = 100;
        insert Statu1;
        eSignForm__c es = new eSignForm__c();
        es.Statu_Achievements__c = Statu1.Id;
        es.DNName__c = '11223344';
        es.agencyAutoSignUpStatus__c = '已批准';
        es.agencySignUpDate__c = Date.today().addDays(-1);
        es.salesManageConfirmDate__c  = Date.today().addDays(-1);
        es.HPSignUpStatus__c = '已批准';
        es.HPSignUpDate__c = Date.today().addDays(-1);
        es.HPConfirmDate__c = Date.today().addDays(-1);
        es.end_User__c = '契約';
        insert es;
        eSignFormLineItem__c esi = new eSignFormLineItem__c();
        esi.Count__c = 2;
        esi.agencyGoodStatus__c = '完好';
        esi.eSignForm__c = es.Id;
        insert esi;
        eSignFormLineItem__c esi2 = new eSignFormLineItem__c();
        esi2.Count__c = 2;
        esi2.agencyGoodStatus__c = '完好';
        esi2.eSignForm__c = es.Id;
        insert esi2;
    }
    static testMethod void testMethod1(){
        Test.startTest();
        Database.executeBatch(new NFM116Batch(), 200);
        Test.stopTest();
    }
    static testMethod void testMethod2(){
        Test.startTest();
        Database.executeBatch(new NFM116Batch(Date.today()), 200);
        Test.stopTest();
    }
    static testMethod void testMethod3(){
        Test.startTest();
        Database.executeBatch(new NFM116Batch(Date.today().addDays(-30), true), 200);
        Test.stopTest();
    }
    static testMethod void testMethod4(){
        Test.startTest();
        eSignForm__c es = [select Id from eSignForm__c];
        Database.executeBatch(new NFM116Batch(es.Id), 200);
        Test.stopTest();
    }
    static testMethod void testMethod5(){
        Test.startTest();
        eSignForm__c es = [select Id from eSignForm__c];
        Database.executeBatch(new NFM116Batch(new List<String>{es.id}), 200);
        Test.stopTest();
    }
}
force-app/main/default/classes/NFM116BatchTest.cls-meta.xml
New file
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>54.0</apiVersion>
    <status>Active</status>
</ApexClass>
force-app/main/default/classes/NFM116Controller.cls
New file
@@ -0,0 +1,150 @@
public with sharing class NFM116Controller {
    public static String status;
    public class OnlineSigns {
        public NFMUtil.Monitoring Monitoring;
        public OnlineSign[] OnlineSign;
    }
    public class OnlineSign {
        public String SoNo;
        public String DeliveryNote;
        public String DealerResult;
        public String DealerDate;
        public String HospitalResult;
        public String HospitalDate;
    }
     /**
     * NFM116の送信処理
     *
     * @param iflog_Id          //日志表的ID
     * @param OnlineSignIdList  //要发送的签收单的ID
     */
    @future (callout=true)
    public static void callout(String iflog_Id, List<String> OnlineSignIdList) {
        executeNotFuture(iflog_Id, OnlineSignIdList);
    }
    public static void executeNotFuture(String iflog_Id, List<String> OnlineSignIdList) {
        if (OnlineSignIdList == null || OnlineSignIdList.size() == 0) {
            return;
        }
        //MessageGroupNumber的获取
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        if(String.isNotBlank(iflog_Id)){
            iflog = [Select Id, Name, Log__c, ErrorLog__c, MessageGroupNumber__c from BatchIF_Log__c where Id = :iflog_Id];
        } else{
            iflog.MessageGroupNumber__c = nowStr;
        }
        iflog.Log__c = 'callout start\n';
        iflog.Type__c = 'NFM116';
        iflog.ErrorLog__c = '';
        String logstr = iflog.Log__c + '\nNumberOfRecord=' + OnlineSignIdList.size();
        //Monitoring的设定
        OnlineSigns onlineSigns = new OnlineSigns();
        onlineSigns.Monitoring = new NFMUtil.Monitoring();
        onlineSigns.Monitoring.TransmissionDateTime = nowStr;
        onlineSigns.Monitoring.Text                 = '';
        onlineSigns.Monitoring.Tag                  = 'MSGH';
        onlineSigns.Monitoring.Sender               = 'SFDC';
        onlineSigns.Monitoring.Receiver             = 'SAP';
        onlineSigns.Monitoring.NumberOfRecord       = '' + OnlineSignIdList.size();
        onlineSigns.Monitoring.MessageType          = 'NFM116';
        onlineSigns.Monitoring.MessageGroupNumber   = iflog.Name;
        BatchIF_Log__c rowData = new BatchIF_Log__c();
        try {
            List<eSignForm__c> eSignFormList = [select Id, SANumber__c, DNName__c, agencyAcceptSAPResult__c, HPAcceptSAPResult__c, agencyAccOrSAPConfirmDate__c,
                                                    hpAccOrSAPConfirmDate__c from eSignForm__c where Id IN :OnlineSignIdList];
            System.debug('eSignFormList1:' + eSignFormList);
            onlineSigns.OnlineSign = new List<OnlineSign>();
            for(eSignForm__c eSignForm : eSignFormList){
                OnlineSign onlineSign = new OnlineSign();
                onlineSign.SoNo           = eSignForm.SANumber__c;
                onlineSign.DeliveryNote   = eSignForm.DNName__c;
                onlineSign.DealerResult   = eSignForm.agencyAcceptSAPResult__c;
                onlineSign.DealerDate     = NFMUtil.formatDate2Str(eSignForm.agencyAccOrSAPConfirmDate__c);
                onlineSign.HospitalResult = eSignForm.HPAcceptSAPResult__c;
                onlineSign.HospitalDate   = NFMUtil.formatDate2Str(eSignForm.hpAccOrSAPConfirmDate__c);
                onlineSigns.OnlineSign.add(onlineSign);
            }
            if(onlineSigns.OnlineSign.size() > 0){
                NFMUtil.Monitoring Monitoring   = new NFMUtil.Monitoring();
                Monitoring.Tag                  = onlineSigns.Monitoring.Tag;
                Monitoring.Sender               = onlineSigns.Monitoring.Sender;
                Monitoring.Receiver             = onlineSigns.Monitoring.Receiver;
                Monitoring.MessageType          = onlineSigns.Monitoring.MessageType;
                Monitoring.MessageGroupNumber   = onlineSigns.Monitoring.MessageGroupNumber;
                Monitoring.NumberOfRecord       = onlineSigns.Monitoring.NumberOfRecord;
                Monitoring.TransmissionDateTime = onlineSigns.Monitoring.TransmissionDateTime;
                Monitoring.Text                 = '';
                rowData = NFMUtil.makeRowData(Monitoring, 'NFM116', onlineSigns);
                execute(rowData, iflog);
            }
            logstr += '\nend';
        } catch(Exception ex) {
            System.debug(Logginglevel.ERROR, 'NFM116_' + iflog.Name + ':' + ex.getMessage());
            System.debug(Logginglevel.ERROR, 'NFM116_' + iflog.Name + ':' + ex.getStackTraceString());
            logstr += ex.getMessage();
            iflog.ErrorLog__c += ex.getMessage() + '\n';
            iflog.ErrorLog__c += ex.getStackTraceString() + '\n';
        }
        System.debug('thhrowData--->'+rowData);
        if (rowData != null) {
            upsert rowData;
        }
        iflog.Log__c = logstr;
        upsert iflog;
    }
    public static void execute(BatchIF_Log__c rowData, BatchIF_Log__c iflog) {
        Integer batch_retry_max_cnt = Integer.valueOf(System.Label.batch_retry_max_cnt);
        String rowDataStr = NFMUtil.getRowDataStr(rowData);
        OnlineSigns onlineSigns = (OnlineSigns) JSON.deserialize(rowDataStr, OnlineSigns.class);
        String logstr = onlineSigns.Monitoring.MessageGroupNumber + ' start\n';
        Boolean needUpdateIflog = false;
        if (iflog == null) {
            needUpdateIflog = true;
            iflog = new BatchIF_Log__c();
            iflog.Log__c = logstr;
            iflog.ErrorLog__c = '';
        } else {
            logstr = iflog.Log__c;
        }
        iflog.Type__c = 'NFM116';
        iflog.MessageGroupNumber__c = onlineSigns.Monitoring.MessageGroupNumber;
        try{
            //发送接口
            status = NFMUtil.sendToSapRet(rowDataStr, NFMUtil.NFM116_ENDPOINT);
            System.debug('NFM116Log--status->' + status);
            if ('Accepted'.equals(status)) {
                logstr += 'status:' + status + '\n';
                rowData.retry_cnt__c = 0;
            }
        } catch (Exception ex) {
            System.debug(Logginglevel.ERROR, 'NFM116_' + iflog.Name + ':' + ex.getMessage());
            System.debug(Logginglevel.ERROR, 'NFM116_' + iflog.Name + ':' + ex.getStackTraceString());
            logstr += ex.getMessage();
            iflog.ErrorLog__c += ex.getMessage() + '\n';
            iflog.ErrorLog__c += ex.getStackTraceString() + '\n';
            if (rowData.retry_cnt__c == null) rowData.retry_cnt__c = 0;
            if (rowData.retry_cnt__c < batch_retry_max_cnt) {
                rowData.retry_cnt__c++;
                LogAutoSendSchedule.assignOneMinute();
            }
            if (rowData.retry_cnt__c >= batch_retry_max_cnt) {
                rowData.ErrorLog__c = ex.getMessage() + '\n' + ex.getStackTraceString() + '\n' + rowData.ErrorLog__c+'错误次数已经超过自动送信设定的最大次数,请手动送信';
            }
        }
        iflog.Log__c = logstr;
        if (needUpdateIflog) {
            upsert iflog;
            upsert rowData;
        }
    }
}
force-app/main/default/classes/NFM116Controller.cls-meta.xml
New file
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>54.0</apiVersion>
    <status>Active</status>
</ApexClass>
force-app/main/default/classes/NFM116ControllerTest.cls
New file
@@ -0,0 +1,58 @@
@isTest
private class NFM116ControllerTest {
    @TestSetup
    static void makeData(){
        Opportunity opp = new Opportunity();
        opp.Opportunity_No__c = 'XB-153P-06-S151289';
        opp.Opportunity_Category__c = 'ET';
        opp.StageName = '目標';
        opp.Authorized_DB_No__c = 'XB-153P-06-S151289';
        opp.Name = '::XB-153P-06-S151289';
        opp.Close_Forecasted_Date__c = Date.today();
        opp.CloseDate = Date.today();
        opp.Opp_Confirmation_Day__c = Date.today();
        insert opp;
        Statu_Achievements__c Statu1 = new Statu_Achievements__c();
        Statu1.ContractNO__c = 'SH-ET-191025';
        Statu1.Opportunity__c = opp.Id;
        Statu1.ContractAmount__c = 100;
        insert Statu1;
        eSignForm__c es = new eSignForm__c();
        es.Statu_Achievements__c = Statu1.Id;
        es.DNName__c = '11223344';
        es.agencyAutoSignUpStatus__c = '已批准';
        es.agencySignUpDate__c = Date.today().addDays(-1);
        es.agencyConfirmDate__c = Date.today().addDays(-1);
        es.HPSignUpStatus__c = '已批准';
        es.HPSignUpDate__c = Date.today().addDays(-1);
        es.HPConfirmDate__c = Date.today().addDays(-1);
        insert es;
        eSignFormLineItem__c esi = new eSignFormLineItem__c();
        esi.Count__c = 2;
        esi.agencyGoodStatus__c = '完好';
        esi.eSignForm__c = es.Id;
        insert esi;
        eSignFormLineItem__c esi2 = new eSignFormLineItem__c();
        esi2.Count__c = 2;
        esi2.agencyGoodStatus__c = '完好';
        esi2.eSignForm__c = es.Id;
        insert esi2;
    }
    static testMethod void testMethod1() {
        List<eSignForm__c> eSignFormList = [select id from eSignForm__c];
        List<String> eSignFormIdList = new List<String>();
        for(eSignForm__c es : eSignFormList){
            eSignFormIdList.add(es.Id);
        }
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.Log__c = 'test start \n';
        insert iflog;
        Test.startTest();
        NFM116Controller.callout(iflog.Id, eSignFormIdList);
        Test.stopTest();
    }
}
force-app/main/default/classes/NFM116ControllerTest.cls-meta.xml
New file
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>54.0</apiVersion>
    <status>Active</status>
</ApexClass>
force-app/main/default/classes/NFMUtil.cls
@@ -63,6 +63,9 @@
    public static String NFM703_ENDPOINT = null;
    public static String NFM115_ENDPOINT = null;
    // 电子签收单SFDC2SAP thh 20220427 start
    public static String NFM116_ENDPOINT = null;
    // 电子签收单SFDC2SAP thh 20220427 end
    public static String NFM112_ENDPOINT = null;
@@ -126,6 +129,11 @@
            NFM112_ENDPOINT = 'http://wdp.olympus.com.cn:8089/RESTAdapter/NFM112';
            NFM115_ENDPOINT = 'https://wdp.olympus.com.cn:44301/RESTAdapter/NFM115';
            // sanbox电子签收单SFDC2SAP thh 20220427 start
            NFM116_ENDPOINT = 'https://wdp.olympus.com.cn:44301/RESTAdapter/NFM116';
            // sanbox电子签收单SFDC2SAP thh 20220427 end
            // 新服务系统 测试环境
            AWS_DOMAIN = 'https://olympus.bqbot.com';
              // 新服务系统 本地环境(临时)
@@ -185,6 +193,10 @@
            //样本管理
            NFM115_ENDPOINT = 'https://wdp.olympus.com.cn:44302/RESTAdapter/NFM115';
            // 电子签收单SFDC2SAP thh 20220427 start
            NFM116_ENDPOINT = 'https://wdp.olympus.com.cn:44302/RESTAdapter/NFM116';
            // 电子签收单SFDC2SAP thh 20220427 end
 // 新服务系统
            AWS_DOMAIN = 'https://svc-elb.olympuschina.com';