高章伟
2022-03-18 a0bc3e3af59aed35334bdc38256a7a1dfe8aecf3
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
@isTest
private class NFM204RestTest {
    
    @isTest 
    static void test_method_one() {
            
        // product
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'Prd1';
        prd1.ProductCode            = 'Prd1';
        prd1.Repair_Product_Code__c = 'Prd1_RP';
        prd1.Name                   = 'Prd1';
        prd1.Manual_Entry__c        = false;
        prd1.Category2__c = '本体';
        prd1.Category3__c = '纤维镜';
        prd1.Category4__c = 'CV';
        prd1.Category5__c = '260SL系列';
        prd1.Asset_Model_No__c = '1001';
        insert prd1;
 
        // 产品注册证
        Product_Register__c prc = new Product_Register__c();
        prc.Name = 'SFDC测试用2018001';
        prc.MD5EncryptionKey__c = '53E322978D1B614830580290534EFB48';
        insert prc;
 
        Product_Register__c prc2 = new Product_Register__c();
        prc2.Name = 'FYL';
        prc2.MD5EncryptionKey__c = '071AD0CE5B2FA631EAFD086A814D461A';
        insert prc2;
 
        // 产品-注册证关系
        Product_Register_Link__c prl = new Product_Register_Link__c();
        prl.Product_Register__c = prc.id;
        prl.Product2__c = prd1.id;
        insert prl;
 
        // IF转送表
        BatchIF_Transfer__c trans1 = new BatchIF_Transfer__c();
        trans1.Table__c = 'Product2';
        trans1.Column__c = 'Product_Status__c';
        trans1.External_Value__c = '20';
        trans1.Internal_Value__c = '正常销售';
        insert trans1;
 
        BatchIF_Transfer__c trans2 = new BatchIF_Transfer__c();
        trans2.Table__c = 'Product_Register__c';
        trans2.Column__c = 'RegisterNoStatus__c';
        trans2.External_Value__c = '20';
        trans2.Internal_Value__c = '有效';
        insert trans2;
 
            NFM204Rest.GeDatas GeDatas = new NFM204Rest.GeDatas();
        NFM204Rest.GeData GeData = new NFM204Rest.GeData();
        GeDatas.GeData = new NFM204Rest.GeData[]{GeData};
 
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
 
        // 其余产品注册证
        GeData.MaterialNo = 'Prd1';
        GeData.MaterialStatus = '20';
        GeData.RegisterNo = 'SFDC测试用2018001'; 
        GeData.RegisterNoStatus = '20';
        GeData.ValidFrom = '20180522';
        GeData.ValidTo = '20220521';
        GeData.MaterialStatusType = null;
        GeData.PrdCompanyAddr = '1111111111111111111111111111111111111111111111111111111111111111111';
        GeData.PrdCompanyAddr += '2222222222222222222222222222222222222222222222222222222222222222222';
        GeData.PrdCompanyAddr += '3333333333333333333333333333333333333333333333333333333333333333333';
        GeData.PrdCompanyAddr += '4444444444444444444444444444444444444444444444444444444444444444444';
 
        NFMUtil.Monitoring Monitoring = GeDatas.Monitoring;
        BatchIF_Log__c rowData = NFMUtil.saveRowData(Monitoring, 'NFM204', GeDatas.GeData);
        NFM204Rest.executefuture(rowData.Id);
 
 
        // 测试FYL产品注册证
        GeData.MaterialNo = 'Prd1';
        GeData.MaterialStatus = '20';
        GeData.RegisterNo = 'FYL'; 
        GeData.RegisterNoStatus = '50';
        GeData.ValidFrom = null;
        GeData.MaterialStatusType = null;
        GeData.PrdCompanyAddr = '1111111111111111111111111111111111111111111111111111111111111111111';
        GeData.PrdCompanyAddr += '2222222222222222222222222222222222222222222222222222222222222222222';
        GeData.PrdCompanyAddr += '3333333333333333333333333333333333333333333333333333333333333333333';
        GeData.PrdCompanyAddr += '4444444444444444444444444444444444444444444444444444444444444444444';
 
 
        rowData = NFMUtil.saveRowData(Monitoring, 'NFM204', GeDatas.GeData);
        NFM204Rest.executefuture(rowData.Id);
 
        // 测试异常
        GeData.MaterialNo = 'Prd1';
        GeData.MaterialStatus = '20';
        GeData.RegisterNo = 'SFDC测试用2018001'; 
        GeData.RegisterNoStatus = '50';
        GeData.ValidFrom = 'ZZZZ';
        GeData.MaterialStatusType = null;
 
 
        rowData = NFMUtil.saveRowData(Monitoring, 'NFM204', GeDatas.GeData);
        NFM204Rest.executefuture(rowData.Id);
        //System.Test.stopTest();
 
    }                                      
    
    @isTest static void test_method_two() {
        Test.startTest();
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'Prd1';
        prd1.ProductCode            = 'Prd1';
        prd1.Repair_Product_Code__c = 'Prd1_RP';
        prd1.Name                   = 'Prd1';
        prd1.Manual_Entry__c        = false;
        prd1.Category2__c = '本体';
        prd1.Category3__c = '纤维镜';
        prd1.Category4__c = 'CV';
        prd1.Category5__c = '260SL系列';
        prd1.Asset_Model_No__c = '1001';
        insert prd1;
        String JsonMsg = '{"Monitoring":{"TransmissionDateTime":"201812201320","Text":"","Tag":"MSGH","Sender":"SFDC","Receiver":"SPO","NumberOfRecord":"1","MessageType":"NFM204","MessageGroupNumber":"20180001722190"},"GeData":[{"Z3PLAuthorizedNo":"","Z3PLAuthorized":"","YXQX":"1年","ValidTo":null,"ValidFrom":null,"Unit":null,"TransCondition":null,"StroageCondition":null,"RegisterNoStatus":"50","RegisterNoClass_Old":"","RegisterNoClass_New":"","RegisterNo":"FYL","ProductName":"SSC6024 : Sof-Curl 输尿管支架管 6Fr.X 24cm","PrdValidTo":null,"PrdValidFrom":null,"PrdCompanyLicense":"","PrdCompanyAddr":"","Other3":null,"Other2":null,"Other1":null,"Model":"SSC6024 ","MedPrdClass":"","MaterialStatusType":null,"MaterialStatus":"10","MaterialNo":"SSC6024","MaterialGroup":null,"BusinessScope":"","AuthorizedCompany_SH":"","AuthorizedCompany":"","ApprovedDate_SH":null,"ApprovedDate":null}]}';
        req.requestURI = 'services/apexrest/NFM204/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM204Rest.execute();
 
        Test.stopTest();
    }
    
}