高章伟
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
@isTest
private class TypeMaintenanceContractBatchTest {
    static testMethod void TypeMaintenanceContractBatch() {
        ControllerUtil.EscapeNFM001Trigger = true;
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.FSE_SP_Main_Leader__c = UserInfo.getUserId();
        hospital.FSE_GI_Main_Leader__c = UserInfo.getUserId();
        insert hospital;
 
        // 戦略科室を得る
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = : hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
 
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
        dep.Name = 'test dep';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
 
        // 维修合同を作成する
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.status__c ='契約';
        contract.Maintenance_Contract_No__c = 'Kami_Contract_No';
        contract.Contract_Conclusion_Date__c = Date.today();
        contract.Hospital__c = hospital.Id;
        contract.Department_Class__c = strategicDep[0].Id;
        contract.Department__c = dep.Id;
        contract.Contract_Start_Date__c = Date.today()-3;
        contract.Contract_End_Date__c = Date.today();
        contract.SalesOfficeCode_selection__c = '北京RC';
 
        Maintenance_Contract__c contract2 = contract.clone();
        contract2.Maintenance_Contract_No__c = 'Kami_Contract_No_2';
        contract2.Contract_Start_Date__c = Date.today()-3;
        contract2.Contract_End_Date__c = Date.today();
 
        Maintenance_Contract__c contract3 = contract.clone();
        contract3.Maintenance_Contract_No__c = 'Kami_Contract_No_3';
        contract3.Contract_Start_Date__c = Date.today()-3000;
        contract3.Contract_End_Date__c = Date.today()-600;
 
        insert new Maintenance_Contract__c[] {contract,contract2};
 
        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;
        insert prd1;
 
        Asset ast1 = new Asset();
        ast1.Name= '保有設備1';
        ast1.Hospital__c= hospital.Id;
        ast1.Department_Class__c= strategicDep[0].Id;
        ast1.AccountId= dep.Id;
        ast1.Product2Id= prd1.Id;
        ast1.SerialNumber= 'SerialNumber1';
        ast1.Guarantee_period_for_products__c = Date.today();
        ast1.InstallDate= null;
 
        Asset ast2 = ast1.clone();
        ast2.Name= '保有設備2';
        ast2.SerialNumber= 'SerialNumber2';
        ast2.Guarantee_period_for_products__c = Date.today();
        ast2.InstallDate= Date.today()-400;
 
        Asset ast3 = ast1.clone();
        ast3.Name= '保有設備3';
        ast3.SerialNumber= 'SerialNumber3';
        ast3.InstallDate= Date.today()-39;
 
        insert new Asset[] {ast1,ast2,ast3};
 
        Maintenance_Contract_Asset__c mca1 = new Maintenance_Contract_Asset__c();
        mca1.Asset__c = ast1.Id;
        mca1.Maintenance_Contract__c = contract.id;
 
        Maintenance_Contract_Asset__c mca2 = new Maintenance_Contract_Asset__c();
        mca2.Asset__c = ast2.Id;
        mca2.Maintenance_Contract__c = contract.id;
        Maintenance_Contract_Asset__c mca3 = new Maintenance_Contract_Asset__c();
        mca3.Asset__c = ast3.Id;
        mca3.Maintenance_Contract__c = contract.id;
 
        Maintenance_Contract_Asset__c mca4 = new Maintenance_Contract_Asset__c();
        mca4.Asset__c = ast1.Id;
        mca4.Maintenance_Contract__c = contract2.id;
        Maintenance_Contract_Asset__c mca5 = new Maintenance_Contract_Asset__c();
        mca5.Asset__c = ast2.Id;
        mca5.Maintenance_Contract__c = contract2.id;
        Maintenance_Contract_Asset__c mca6 = new Maintenance_Contract_Asset__c();
        mca6.Asset__c = ast3.Id;
        mca6.Maintenance_Contract__c = contract2.id;
 
        insert new Maintenance_Contract_Asset__c[] {mca1,mca2,mca3,mca4,mca5,mca6};
 
        List<String> IdList=new List<String> {hospital.Id};
        Database.executeBatch(new TypeMaintenanceContractBatch(IdList));
        Database.executeBatch(new TypeMaintenanceContractBatch());
    }
    static testMethod void Type2MaintenanceContractBatch() {
        ControllerUtil.EscapeNFM001Trigger = true;
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.FSE_SP_Main_Leader__c = UserInfo.getUserId();
        hospital.FSE_GI_Main_Leader__c = UserInfo.getUserId();
        insert hospital;
 
        // 戦略科室を得る
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = : hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
 
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
        dep.Name = 'test dep';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
 
        // 维修合同を作成する
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.status__c ='契約';
        contract.Maintenance_Contract_No__c = 'Kami_Contract_No';
        contract.Contract_Conclusion_Date__c = Date.today();
        contract.Hospital__c = hospital.Id;
        contract.Department_Class__c = strategicDep[0].Id;
        contract.Department__c = dep.Id;
        contract.Contract_Start_Date__c = Date.today()-3;
        contract.Contract_End_Date__c = Date.today();
        contract.SalesOfficeCode_selection__c = '北京RC';
 
        Maintenance_Contract__c contract2 = contract.clone();
        contract2.Maintenance_Contract_No__c = 'Kami_Contract_No_2';
        contract2.Contract_Start_Date__c = Date.today()-3;
        contract2.Contract_End_Date__c = Date.today();
 
        Maintenance_Contract__c contract3 = contract.clone();
        contract3.Maintenance_Contract_No__c = 'Kami_Contract_No_3';
        contract3.Contract_Start_Date__c = Date.today()-3000;
        contract3.Contract_End_Date__c = Date.today()-600;
 
        insert new Maintenance_Contract__c[] {contract,contract2};
 
        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;
        insert prd1;
 
        Asset ast1 = new Asset();
        ast1.Name= '保有設備1';
        ast1.Hospital__c= hospital.Id;
        ast1.Department_Class__c= strategicDep[0].Id;
        ast1.AccountId= dep.Id;
        ast1.Product2Id= prd1.Id;
        ast1.SerialNumber= 'SerialNumber1';
        ast1.Guarantee_period_for_products__c = Date.today();
        ast1.InstallDate= null;
 
        Asset ast2 = ast1.clone();
        ast2.Name= '保有設備2';
        ast2.SerialNumber= 'SerialNumber2';
        ast2.Guarantee_period_for_products__c = Date.today();
        ast2.InstallDate= Date.today()-400;
 
        Asset ast3 = ast1.clone();
        ast3.Name= '保有設備3';
        ast3.SerialNumber= 'SerialNumber3';
        ast3.InstallDate= Date.today()-39;
 
        insert new Asset[] {ast1,ast2,ast3};
 
        Maintenance_Contract_Asset__c mca1 = new Maintenance_Contract_Asset__c();
        mca1.Asset__c = ast1.Id;
        mca1.Maintenance_Contract__c = contract.id;
 
        Maintenance_Contract_Asset__c mca2 = new Maintenance_Contract_Asset__c();
        mca2.Asset__c = ast2.Id;
        mca2.Maintenance_Contract__c = contract.id;
        Maintenance_Contract_Asset__c mca3 = new Maintenance_Contract_Asset__c();
        mca3.Asset__c = ast3.Id;
        mca3.Maintenance_Contract__c = contract.id;
 
        Maintenance_Contract_Asset__c mca4 = new Maintenance_Contract_Asset__c();
        mca4.Asset__c = ast1.Id;
        mca4.Maintenance_Contract__c = contract2.id;
        Maintenance_Contract_Asset__c mca5 = new Maintenance_Contract_Asset__c();
        mca5.Asset__c = ast2.Id;
        mca5.Maintenance_Contract__c = contract2.id;
        Maintenance_Contract_Asset__c mca6 = new Maintenance_Contract_Asset__c();
        mca6.Asset__c = ast3.Id;
        mca6.Maintenance_Contract__c = contract2.id;
 
        insert new Maintenance_Contract_Asset__c[] {mca1,mca2,mca3,mca4,mca5,mca6};
 
        List<String> IdList=new List<String> {hospital.Id};
        Database.executeBatch(new Type2MaintenanceContractBatch(IdList));
        Database.executeBatch(new Type2MaintenanceContractBatch());
    }
 
    static testMethod void Type3MaintenanceContractBatch() {
        ControllerUtil.EscapeNFM001Trigger = true;
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        hospital.FSE_SP_Main_Leader__c = UserInfo.getUserId();
        hospital.FSE_GI_Main_Leader__c = UserInfo.getUserId();
        insert hospital;
 
        // 戦略科室を得る
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = : hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
 
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
        dep.Name = 'test dep';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
 
        // 维修合同を作成する
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.status__c ='契約';
        contract.Maintenance_Contract_No__c = 'Kami_Contract_No';
        contract.Contract_Conclusion_Date__c = Date.today();
        contract.Hospital__c = hospital.Id;
        contract.Department_Class__c = strategicDep[0].Id;
        contract.Department__c = dep.Id;
        contract.Contract_Start_Date__c = Date.today()-3;
        contract.Contract_End_Date__c = Date.today();
        contract.SalesOfficeCode_selection__c = '北京RC';
 
        Maintenance_Contract__c contract2 = contract.clone();
        contract2.Maintenance_Contract_No__c = 'Kami_Contract_No_2';
        contract2.Contract_Start_Date__c = Date.today()-3;
        contract2.Contract_End_Date__c = Date.today();
 
        Maintenance_Contract__c contract3 = contract.clone();
        contract3.Maintenance_Contract_No__c = 'Kami_Contract_No_3';
        contract3.Contract_Start_Date__c = Date.today()-3000;
        contract3.Contract_End_Date__c = Date.today()-600;
 
        insert new Maintenance_Contract__c[] {contract,contract2};
 
        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;
        insert prd1;
 
        Asset ast1 = new Asset();
        ast1.Name= '保有設備1';
        ast1.Hospital__c= hospital.Id;
        ast1.Department_Class__c= strategicDep[0].Id;
        ast1.AccountId= dep.Id;
        ast1.Product2Id= prd1.Id;
        ast1.SerialNumber= 'SerialNumber1';
        ast1.Guarantee_period_for_products__c = Date.today();
        ast1.InstallDate= null;
 
        Asset ast2 = ast1.clone();
        ast2.Name= '保有設備2';
        ast2.SerialNumber= 'SerialNumber2';
        ast2.Guarantee_period_for_products__c = Date.today();
        ast2.InstallDate= Date.today()-400;
 
        Asset ast3 = ast1.clone();
        ast3.Name= '保有設備3';
        ast3.SerialNumber= 'SerialNumber3';
        ast3.InstallDate= Date.today()-39;
 
        insert new Asset[] {ast1,ast2,ast3};
 
        Maintenance_Contract_Asset__c mca1 = new Maintenance_Contract_Asset__c();
        mca1.Asset__c = ast1.Id;
        mca1.Maintenance_Contract__c = contract.id;
 
        Maintenance_Contract_Asset__c mca2 = new Maintenance_Contract_Asset__c();
        mca2.Asset__c = ast2.Id;
        mca2.Maintenance_Contract__c = contract.id;
        Maintenance_Contract_Asset__c mca3 = new Maintenance_Contract_Asset__c();
        mca3.Asset__c = ast3.Id;
        mca3.Maintenance_Contract__c = contract.id;
 
        Maintenance_Contract_Asset__c mca4 = new Maintenance_Contract_Asset__c();
        mca4.Asset__c = ast1.Id;
        mca4.Maintenance_Contract__c = contract2.id;
        Maintenance_Contract_Asset__c mca5 = new Maintenance_Contract_Asset__c();
        mca5.Asset__c = ast2.Id;
        mca5.Maintenance_Contract__c = contract2.id;
        Maintenance_Contract_Asset__c mca6 = new Maintenance_Contract_Asset__c();
        mca6.Asset__c = ast3.Id;
        mca6.Maintenance_Contract__c = contract2.id;
 
        insert new Maintenance_Contract_Asset__c[] {mca1,mca2,mca3,mca4,mca5,mca6};
 
        List<String> IdList=new List<String> {hospital.Id};
        Database.executeBatch(new Type3MaintenanceContractBatch(IdList));
        Database.executeBatch(new Type3MaintenanceContractBatch());
    }
}