高章伟
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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
@isTest
private class NFM208RestTest {
    static testMethod void testNFM028_void() {
        List<BatchIF_Transfer__c> transfers = new List<BatchIF_Transfer__c>();
        BatchIF_Transfer__c transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Account';
        transfer.Column__c         = 'Sales_Shop_Class__c';
        transfer.External_Value__c = '04';
        transfer.Internal_Value__c = '04Internal';
        transfers.add(transfer);
        transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Account';
        transfer.Column__c         = 'Sales_Shop_Class__c';
        transfer.External_Value__c = '05';
        transfer.Internal_Value__c = '05Internal';
        transfers.add(transfer);
        insert transfers;
 
        //新建助残
        // List<Statu_Achievements__c> sac = new List<Statu_Achievements__c>();
        // Statu_Achievements__c sa = new Statu_Achievements__c();
        // sa.Opportunity__c = '0061000000n0GuYAAU'; //测试意向询价
        // sa.ContractNO__c  = 'SH-GI-182431'; //假想的合同编号
        // sa.Order_no_without_0__c  =  '30087883'; //假想的凭证号码
        // sa.ContractAmount__c = '1900000'; //合同金额 不能为空
        // sac.add(sa);
        // insert sac;
 
        //新建几个保有设备
 
        // 病院作成
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        insert hospital;
        // 战略科室
        Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
        // 科室
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
        dep.Name = 'test dep';
        dep.AgentCode_Ext__c = '9999998';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
        
        // 产品
        Product2 pro1 = new Product2(Name='name01',IsActive=true,Family='GI',Asset_Model_No__c='n01',Serial_Lot_No__c='S/N tracing',ProductCode_Ext__c='pc01',Manual_Entry__c=false);
        Product2 pro2 = new Product2(Name='name02',IsActive=true,Family='GI',Asset_Model_No__c='n02',Serial_Lot_No__c='Lot tracing',ProductCode_Ext__c='pc02',Manual_Entry__c=false);
        Product2 pro3 = new Product2(Name='name03',IsActive=true,Family='GI',Asset_Model_No__c='n03',Serial_Lot_No__c='Lot tracing',ProductCode_Ext__c='pc03',Manual_Entry__c=false);
        Product2 pro4 = new Product2(Name='name04',IsActive=true,Family='GI',Asset_Model_No__c='n04',Serial_Lot_No__c='Lot tracing',ProductCode_Ext__c='pc04',Manual_Entry__c=false);
        Product2 pro5 = new Product2(Name='name05',IsActive=true,Family='GI',Asset_Model_No__c='n05',Serial_Lot_No__c='Lot tracing',ProductCode_Ext__c='pc05',Manual_Entry__c=false);
        Product2 pro6 = new Product2(Name='name06',IsActive=true,Family='GI',Asset_Model_No__c='n06',Serial_Lot_No__c='Lot tracing',ProductCode_Ext__c='pc06',Manual_Entry__c=false);
        insert new Product2[] {pro1, pro2,pro3,pro4,pro5,pro6};
        
 
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
 
        // 资产
        Asset asset1 = new Asset(Asset_Owner__c = 'Olympus');
        asset1.RecordTypeId = System.Label.Asset_RecordType;
        asset1.SerialNumber = 'ass01';
        asset1.Internal_Asset_number__c = 'ian01';
        asset1.Name = 'ass01';
        asset1.AccountId = dep.Id;
        asset1.Department_Class__c = strategicDep[0].Id;
        asset1.Hospital__c = hospital.Id;
        asset1.Product2Id = pro1.Id;
        asset1.Internal_asset_location__c = '北京';
        asset1.SerialNumber = '9412222';
        asset1.Product_Serial_No__c = 'N1021430:9412222';
        asset1.ProductionDate__c = Date.today();
        asset1.Guaranteen_end__c = Date.today().addDays(+10);
        asset1.Order_No__c = '150024';
        
        Asset asset2 = new Asset(Asset_Owner__c = 'Olympus');
        asset2.RecordTypeId = System.Label.Asset_RecordType;
        asset2.SerialNumber = 'ass02';
        asset2.Internal_Asset_number__c = 'ian02';
        asset2.Name = 'ass02';
        asset2.AccountId = dep.Id;
        asset2.Department_Class__c = strategicDep[0].Id;
        asset2.Hospital__c = hospital.Id;
        asset2.Product2Id = pro2.Id;
        asset2.Internal_asset_location__c = '北京';
        asset2.SerialNumber = '9412236';
        asset2.Product_Serial_No__c = 'N1021430:9412236';
        asset2.ProductionDate__c = Date.today();
        asset2.Guaranteen_end__c =  Date.today().addDays(+10);
        asset2.Order_No__c = '150024';
 
        Asset asset3 = new Asset(Asset_Owner__c = 'Olympus');
        asset3.RecordTypeId = System.Label.Asset_RecordType;
        asset3.SerialNumber = 'ass03';
        asset3.Internal_Asset_number__c = 'ian03';
        asset3.Name = 'ass03';
        asset3.AccountId = dep.Id;
        asset3.Department_Class__c = strategicDep[0].Id;
        asset3.Hospital__c = hospital.Id;
        asset3.Product2Id = pro3.Id;
        asset3.Internal_asset_location__c = '上海';
        asset3.SerialNumber = '8439612';
        asset3.Product_Serial_No__c = 'N1401661:8439612';
        asset3.ProductionDate__c = Date.today();
        asset3.Guaranteen_end__c = Date.today().addDays(+10);
        asset3.Order_No__c = '150024';
 
        Asset asset4 = new Asset(Asset_Owner__c = 'Olympus');
        asset4.RecordTypeId = System.Label.Asset_RecordType;
        asset4.SerialNumber = 'ass04';
        asset4.Internal_Asset_number__c = 'ian04';
        asset4.Name = 'ass04';
        asset4.AccountId = dep.Id;
        asset4.Department_Class__c = strategicDep[0].Id;
        asset4.Hospital__c = hospital.Id;
        asset4.Product2Id = pro4.Id;
        asset4.Internal_asset_location__c = '广东';
        asset4.SerialNumber = '8439617';
        asset4.Product_Serial_No__c = 'N1401661:8439617';
        asset4.ProductionDate__c = Date.today();
        asset4.Guaranteen_end__c =  Date.today().addDays(+10);
        asset4.Order_No__c = '150024';
 
        Asset asset5 = new Asset(Asset_Owner__c = 'Olympus');
        asset5.RecordTypeId = System.Label.Asset_RecordType;
        asset5.SerialNumber = 'ass05';
        asset5.Internal_Asset_number__c = 'ian05';
        asset5.Name = 'ass05';
        asset5.AccountId = dep.Id;
        asset5.Department_Class__c = strategicDep[0].Id;
        asset5.Hospital__c = hospital.Id;
        asset5.Product2Id = pro5.Id;
        asset5.Internal_asset_location__c = '广州';
        asset5.SerialNumber = '8439626';
        asset5.Product_Serial_No__c = 'N1401661:8439626';
        asset5.ProductionDate__c = Date.today();
        asset5.Guaranteen_end__c =  Date.today().addDays(+10);
        asset5.Order_No__c = '150024';
 
        Asset asset6 = new Asset(Asset_Owner__c = 'Olympus');
        asset6.RecordTypeId = System.Label.Asset_RecordType;
        asset6.SerialNumber = 'ass06';
        asset6.Internal_Asset_number__c = 'ian06';
        asset6.Name = 'ass06';
        asset6.AccountId = dep.Id;
        asset6.Department_Class__c = strategicDep[0].Id;
        asset6.Hospital__c = hospital.Id;
        asset6.Product2Id = pro6.Id;
        asset6.Internal_asset_location__c = '北京';
        asset6.SerialNumber = '6577842';
        asset6.Product_Serial_No__c = 'N2644060:6577842';
        asset6.ProductionDate__c = Date.today();
        asset6.Guaranteen_end__c =  Date.today().addDays(+10);
        asset6.Order_No__c = '150024';
        
        insert new Asset[] {asset1, asset2,asset3,asset4,asset5,asset6};
 
        // System.Test.startTest();
       
          
        // System.Test.stopTest();
        Test.startTest();
 
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        String JsonMsg = '[{"ProductCode": "N1021430","ReturnProductModel": [{"SerialNumber": "9412222","ManagementNumber": "N1021430:9412222","CreateDate": "","EndDate": ""}, {"SerialNumber": "9412236","ManagementNumber": "N1021430:9412236","CreateDate": "2019-10-09T15:04:44.7545165+08:00","EndDate": "2022-10-11T15:04:44.7545165+08:00"}]}, {"ProductCode": "N1401661","ReturnProductModel": [{"SerialNumber": "8439612","ManagementNumber": "N1401661:8439612","CreateDate": "","EndDate": ""}, {"SerialNumber": "8439626","ManagementNumber": "N1401661:8439626","CreateDate": "","EndDate": ""}, {"SerialNumber": "8439617","ManagementNumber": "N1401661:8439617","CreateDate": "","EndDate": ""}]}, {"ProductCode": "N2644060","ReturnProductModel": [{"SerialNumber": "6577842","ManagementNumber": "N2644060:6577842","CreateDate": "","EndDate": ""}]}]';
        req.requestURI = 'services/apexrest/NFM208/getProduct';
        req.httpMethod = 'GET';
        req.addParameter('ContractNumber' ,'150024');
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response = res;
 
        NFM208Rest.getProduct();
 
        Test.stopTest();
        
    }
     // @isTest 
     // static void test_method_execute() {
 
       
    //}
        
}