高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
@isTest(SeeAllData = false)
public with sharing class NFM212RestTest {
 
    /* 目前只是作为接数据用,且数据中没有关联其他表字段 故直接捏造接口日志
     *  未来如果增加逻辑,需要对应修改。
    */
 
    /* 测试固定折扣 正常+必填验证 */
    static testMethod void testNFM212_01() {
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.MessageGroupNumber__c = '20210601';
        iflog.Type__c ='NFM212' ;
        iflog.Log__c = '[{"SpoID":"","DealerNo":"20210601","ContractNo":"200202020","DateFrom":"2021-05-22","DateTo":"2022-05-31","DealerType":"测试一般折扣","DepartmentClass":"测试科室","ProductClass":"测试产品","GuaranteeDiscount":50,"Discount":48,"Area":"测试地区","Province":"测试省份","ApplyStatus":"完成"},{"SpoID":"SZZZZZZ","DealerNo":"","ContractNo":"200202020","DateFrom":"2021-05-22","DateTo":"2022-05-31","DealerType":"测试一般折扣","DepartmentClass":"测试科室","ProductClass":"测试产品","GuaranteeDiscount":50,"Discount":48,"Area":"测试地区","Province":"测试省份","ApplyStatus":"完成"},{"SpoID":"SZZZZZZ","DealerNo":"20210601","ContractNo":"","DateFrom":"2021-05-22","DateTo":"2022-05-31","DealerType":"测试一般折扣","DepartmentClass":"测试科室","ProductClass":"测试产品","GuaranteeDiscount":50,"Discount":48,"Area":"测试地区","Province":"测试省份","ApplyStatus":"完成"},{"SpoID":"SZZZZZZ","DealerNo":"20210601","ContractNo":"200202020","DateFrom":"","DateTo":"2022-05-31","DealerType":"测试一般折扣","DepartmentClass":"测试科室","ProductClass":"测试产品","GuaranteeDiscount":50,"Discount":48,"Area":"测试地区","Province":"测试省份","ApplyStatus":"完成"},{"SpoID":"SZZZZZZ","DealerNo":"20210601","ContractNo":"200202020","DateFrom":"2021-05-22","DateTo":"","DealerType":"测试一般折扣","DepartmentClass":"测试科室","ProductClass":"测试产品","GuaranteeDiscount":50,"Discount":48,"Area":"测试地区","Province":"测试省份","ApplyStatus":"完成"},{"SpoID":"SZZZZZZ","DealerNo":"20210601","ContractNo":"200202020","DateFrom":"2021-05-22","DateTo":"2022-05-31","DealerType":"","DepartmentClass":"测试科室","ProductClass":"测试产品","GuaranteeDiscount":50,"Discount":48,"Area":"测试地区","Province":"测试省份","ApplyStatus":"完成"},{"SpoID":"SZZZZZZ","DealerNo":"20210601","ContractNo":"200202020","DateFrom":"2021-05-22","DateTo":"2022-05-31","DealerType":"测试一般折扣","DepartmentClass":"测试科室","ProductClass":"测试产品","GuaranteeDiscount":null,"Discount":48,"Area":"测试地区","Province":"测试省份","ApplyStatus":"完成"},{"SpoID":"SZZZZZZ","DealerNo":"20210601","ContractNo":"200202020","DateFrom":"2021-05-22","DateTo":"2022-05-31","DealerType":"测试一般折扣","DepartmentClass":"测试科室","ProductClass":"测试产品","GuaranteeDiscount":50,"Discount":null,"Area":"测试地区","Province":"测试省份","ApplyStatus":"完成"},{"SpoID":"SZZZZZZ","DealerNo":"20210601","ContractNo":"200202020","DateFrom":"2021-05-22","DateTo":"","DealerType":"测试一般折扣","DepartmentClass":"测试科室","ProductClass":"测试产品","GuaranteeDiscount":50,"Discount":48,"Area":"测试地区","Province":"测试省份","ApplyStatus":""}]';
        iflog.RowDataFlg__c = true;
 
        insert iflog;
        System.Test.startTest();
        NFM212Rest.executefuture(iflog.id);
        System.Test.stopTest();
 
    }
        /* 测试固定折扣 正常+必填验证 */
        static testMethod void testNFM212_03() {
            BatchIF_Log__c iflog = new BatchIF_Log__c();
            iflog.MessageGroupNumber__c = '20211028';
            iflog.Type__c ='NFM212' ;
            iflog.Log__c = '[{"SpoID":"OCSMSH-8712","Province":"#39;上海市","ProductClass":"ET","GuaranteeDiscount":100,"Discount":45,"DepartmentClass":"KD/SD产品、K-201/203、MAJ-1351、NM-200L/U-0423及NM-400L/U-0423、FD-410LR/FD-430L/MAJ-233、MAJ-339、MAJ-249、MAJ-1058","DealerType":"产品","DealerNo":"20859","DateTo":"20220331","DateFrom":"20210401","ContractNo":"154P-HD014","Area":"华东","ApplyStatus":"同意"}]';
            iflog.RowDataFlg__c = true;
    
            insert iflog;
            System.Test.startTest();
            NFM212Rest.executefuture(iflog.id);
            System.Test.stopTest();
    
        }
    /* 测试报错 */
    static testMethod void testNFM212_02() {
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.MessageGroupNumber__c = '20210601';
        iflog.Type__c ='NFM212' ;
        iflog.Log__c = '[{"SpoID":"SZZZZZZ","DealerNo":"20210601","ContractNo":"200202020","DateFrom":"2021-05-22","DateTo":"2022-05-31","DealerType":"测试一般折扣","DepartmentClass":"测试科室","ProductClass":"测试产品","GuaranteeDiscount":50,"Discount":"48","Area":"测试地区","Province":"测试省份","ApplyStatus":"完成"}]';
        iflog.RowDataFlg__c = true;
 
        insert iflog;
        System.Test.startTest();
        NFM212Rest.executefuture(iflog.id);
        System.Test.stopTest();
 
    }
    /* 测试调用execute方法 */
    @isTest static void test_method_execute() {
 
        Test.startTest();
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        String JsonMsg = '{"Monitoring":{"Tag":"MSGH","Sender":"SPO","Receiver":"SFDC","MessageType":"NFM212","MessageGroupNumber":"20210000004695","NumberOfRecord":"4","TransmissionDateTime":"2021-06-23","Text":""},"Header":[{"SpoID":"OCSMSH-7862","Province":"#157;河南省","ProductClass":null,"GuaranteeDiscount":23,"Discount":12,"DepartmentClass":"BF","DealerType":"区域","DealerNo":"13122121","DateTo":"20220330","DateFrom":"20210310","ContractNo":"153P-XB001","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7863","Province":"#142;北京市","ProductClass":null,"GuaranteeDiscount":5,"Discount":10,"DepartmentClass":"GYN","DealerType":"区域","DealerNo":"31359","DateTo":"20220330","DateFrom":"20180302","ContractNo":"153P-HB016","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7864","Province":"#142;北京市","ProductClass":null,"GuaranteeDiscount":5,"Discount":20,"DepartmentClass":"OTH","DealerType":"区域","DealerNo":"31359","DateTo":"20220330","DateFrom":"20180302","ContractNo":"153P-HB016","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7865","Province":"#157;河南省","ProductClass":null,"GuaranteeDiscount":20,"Discount":10,"DepartmentClass":"GS","DealerType":"区域","DealerNo":"31360","DateTo":"20220330","DateFrom":"20210307","ContractNo":"153P-XB002","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7883","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":0,"Discount":2,"DepartmentClass":"奥辉(基层)-ENF","DealerType":"产品","DealerNo":"31385","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD015更2021-04-28更2021-04-28","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7884","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":0,"Discount":2,"DepartmentClass":"奥辉(基层)-GI","DealerType":"产品","DealerNo":"31385","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD015更2021-04-28更2021-04-28","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7885","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":0,"Discount":33,"DepartmentClass":"奥辉(基层)-OTH","DealerType":"产品","DealerNo":"31385","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD015更2021-04-28更2021-04-28","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7886","Province":"#142;北京市","ProductClass":null,"GuaranteeDiscount":10,"Discount":10,"DepartmentClass":"能量主机-GYN","DealerType":"产品","DealerNo":"31387","DateTo":"20220330","DateFrom":"20210506","ContractNo":"154P-HB001","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7887","Province":"#142;北京市","ProductClass":null,"GuaranteeDiscount":10,"Discount":10,"DepartmentClass":"能量主机-OTH","DealerType":"产品","DealerNo":"31387","DateTo":"20220330","DateFrom":"20210506","ContractNo":"154P-HB001","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7888","Province":"#142;北京市","ProductClass":null,"GuaranteeDiscount":10,"Discount":10,"DepartmentClass":"能量主机-GS","DealerType":"产品","DealerNo":"31387","DateTo":"20220330","DateFrom":"20210506","ContractNo":"154P-HB001","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7889","Province":"#142;北京市","ProductClass":null,"GuaranteeDiscount":10,"Discount":10,"DepartmentClass":"能量主机-URO","DealerType":"产品","DealerNo":"31387","DateTo":"20220330","DateFrom":"20210506","ContractNo":"154P-HB001","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7903","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":1,"Discount":1,"DepartmentClass":"OTH","DealerType":"区域","DealerNo":"31392","DateTo":"20220330","DateFrom":"20210512","ContractNo":"154P-HD021","Area":"西南","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7904","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":1,"Discount":1,"DepartmentClass":"GS","DealerType":"区域","DealerNo":"31392","DateTo":"20220330","DateFrom":"20210512","ContractNo":"154P-HD021","Area":"西南","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7905","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":1,"Discount":1,"DepartmentClass":"GI","DealerType":"区域","DealerNo":"31392","DateTo":"20220330","DateFrom":"20210512","ContractNo":"154P-HD021","Area":"西南","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7911","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":0,"Discount":33,"DepartmentClass":"ET","DealerType":"产品","DealerNo":"31396","DateTo":"20220330","DateFrom":"20210504","ContractNo":"154P-HD029","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7912","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":0,"Discount":3,"DepartmentClass":"奥辉(基层)-OTH","DealerType":"产品","DealerNo":"31388","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD030","Area":"华北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7913","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":0,"Discount":4,"DepartmentClass":"奥辉(基层)-GI","DealerType":"产品","DealerNo":"31388","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD030","Area":"华北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7914","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":0,"Discount":34,"DepartmentClass":"奥辉(基层)-URO","DealerType":"产品","DealerNo":"31388","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD030","Area":"华北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7928","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":0,"Discount":1,"DepartmentClass":"奥辉(基层)-OTH","DealerType":"产品","DealerNo":"31397","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD037","Area":"华北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7929","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":0,"Discount":2,"DepartmentClass":"奥辉(基层)-GI","DealerType":"产品","DealerNo":"31397","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD037","Area":"华北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7930","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":0,"Discount":3,"DepartmentClass":"奥辉(基层)-ENF","DealerType":"产品","DealerNo":"31397","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD037","Area":"华北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7931","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":0,"Discount":12,"DepartmentClass":"奥辉(基层)-OTH","DealerType":"产品","DealerNo":"31398","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD038","Area":"华北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7932","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":0,"Discount":23,"DepartmentClass":"奥辉(基层)-GS","DealerType":"产品","DealerNo":"31398","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD038","Area":"华北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7933","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":0,"Discount":34,"DepartmentClass":"奥辉(基层)-ENF","DealerType":"产品","DealerNo":"31398","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD038","Area":"华北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7934","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":0,"Discount":45,"DepartmentClass":"奥辉(基层)-BF","DealerType":"产品","DealerNo":"31398","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD038","Area":"华北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7938","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":0,"Discount":2,"DepartmentClass":"奥辉(基层)-OTH","DealerType":"产品","DealerNo":"31398","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD040","Area":"华北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7939","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":0,"Discount":2,"DepartmentClass":"奥辉(基层)-ENF","DealerType":"产品","DealerNo":"31398","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD040","Area":"华北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7940","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":0,"Discount":123,"DepartmentClass":"奥辉(基层)-BF","DealerType":"产品","DealerNo":"31398","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD040","Area":"华北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7947","Province":"#142;北京市","ProductClass":null,"GuaranteeDiscount":0,"Discount":12,"DepartmentClass":"奥辉(基层)-GYN","DealerType":"产品","DealerNo":"31401","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HB006","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7948","Province":"#142;北京市","ProductClass":null,"GuaranteeDiscount":0,"Discount":12,"DepartmentClass":"奥辉(基层)-OTH","DealerType":"产品","DealerNo":"31401","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HB006","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7949","Province":"#142;北京市","ProductClass":null,"GuaranteeDiscount":0,"Discount":12,"DepartmentClass":"奥辉(基层)-GS","DealerType":"产品","DealerNo":"31401","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HB006","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7950","Province":"#142;北京市","ProductClass":null,"GuaranteeDiscount":0,"Discount":12,"DepartmentClass":"奥辉(基层)-GI","DealerType":"产品","DealerNo":"31401","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HB006","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7951","Province":"#142;北京市","ProductClass":null,"GuaranteeDiscount":0,"Discount":12,"DepartmentClass":"奥辉(基层)-ENF","DealerType":"产品","DealerNo":"31401","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HB006","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7952","Province":"#142;北京市","ProductClass":null,"GuaranteeDiscount":0,"Discount":12,"DepartmentClass":"奥辉(基层)-BF","DealerType":"产品","DealerNo":"31401","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HB006","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7953","Province":"#142;北京市","ProductClass":null,"GuaranteeDiscount":0,"Discount":12,"DepartmentClass":"奥辉(基层)-URO","DealerType":"产品","DealerNo":"31401","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HB006","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7954","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":0,"Discount":2,"DepartmentClass":"ET","DealerType":"产品","DealerNo":"31403","DateTo":"20220330","DateFrom":"20210504","ContractNo":"154P-HD042","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7955","Province":"#142;北京市","ProductClass":null,"GuaranteeDiscount":0,"Discount":23232,"DepartmentClass":"ET","DealerType":"产品","DealerNo":"31404","DateTo":"20220330","DateFrom":"20200519","ContractNo":"154P-HB007","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7960","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":2,"Discount":2,"DepartmentClass":"奥辉-GYN","DealerType":"产品","DealerNo":"31405","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD044","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7961","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":2,"Discount":2,"DepartmentClass":"奥辉-OTH","DealerType":"产品","DealerNo":"31405","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD044","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7962","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":88,"Discount":99,"DepartmentClass":"GYN","DealerType":"区域","DealerNo":"31407","DateTo":"20220330","DateFrom":"20210506","ContractNo":"154P-HD049","Area":"西南","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7963","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":98,"Discount":89,"DepartmentClass":"OTH","DealerType":"区域","DealerNo":"31407","DateTo":"20220330","DateFrom":"20210506","ContractNo":"154P-HD049","Area":"西南","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7964","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":0,"Discount":99,"DepartmentClass":"SP耗材","DealerType":"产品","DealerNo":"31408","DateTo":"20220330","DateFrom":"20210506","ContractNo":"154P-HD050","Area":"西南","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7965","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":7,"Discount":1,"DepartmentClass":"奥辉-GYN","DealerType":"产品","DealerNo":"31405","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD053","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7966","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":8,"Discount":2,"DepartmentClass":"奥辉-OTH","DealerType":"产品","DealerNo":"31405","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD053","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7967","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":99,"Discount":3,"DepartmentClass":"奥辉-ENF","DealerType":"产品","DealerNo":"31405","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD053","Area":"西北","ApplyStatus":"同意"},{"SpoID":"OCSMSH-7980","Province":"#144;上海市","ProductClass":null,"GuaranteeDiscount":23,"Discount":3,"DepartmentClass":"ENF","DealerType":"区域","DealerNo":"31415","DateTo":"20230331","DateFrom":"20220401","ContractNo":"154P-HD060更2021-06-09","Area":"西北","ApplyStatus":"同意"}]}';
        req.requestURI = 'services/apexrest/NFM212/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM212Rest.execute();
 
        Test.stopTest();
    }
}