高章伟
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
@isTest
private class RepPAEDecisionRecordControllerTest {
    static testMethod void myUnitTest() {
        List < RecordType > rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account'
            and Name = '病院'
        ];
        if (rectCo.size() == 0) {
            return;
        }
        List < RecordType > rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account'
            and Name IN('診療科 消化科', '診療科 呼吸科') order by Name desc
        ];
        if (rectDpt.size() == 0) {
            return;
        }
        List < RecordType > rectAs = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Asset'
            and Name = '备品'
        ];
        if (rectAs.size() == 0) {
            return;
        }
        Account company1 = new Account();
        company1.RecordTypeId = rectCo[0].Id;
        company1.Name = '病院テスト1';
        List < Account > hps = new Account[] {
            company1
        };
        insert hps;
        List < Account > dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = : company1.Id order by Department_Class_Label__c];
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name = '*';
        depart1.Department_Name__c = '診療科1';
        depart1.ParentId = dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c = company1.Id;
        insert depart1;
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c = 'HistoryPrd1';
        prd1.ProductCode = 'HistoryPrd1';
        prd1.Repair_Product_Code__c = 'HistoryPrd1_RP';
        prd1.Name = 'HistoryPrd1';
        prd1.Manual_Entry__c = false;
        prd1.Extend_new_product_gurantee__c = true;
        prd1.Extend_Gurantee_Start__c = Date.today().addDays(-60);
        prd1.Extend_Gurantee_End__c = Date.today().addDays(60);
        insert prd1;
        Oly_TriggerHandler.bypass('AssetHandler');
        Asset ast = new Asset();
        ast.RecordTypeId = rectAs[0].Id;
        ast.SerialNumber = 'abcdefg';
        ast.Name = '测试资产1';
        ast.AccountId = depart1.Id;
        ast.Department_Class__c = dc1s[0].Id;
        ast.Hospital__c = company1.Id;
        ast.Product2Id = prd1.Id;
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate = Date.today();
        ast.Manage_type__c = '个体管理';
        ast.FirstApproveDate_old__c = Date.today().addDays(-30);
        insert ast;
        Report__c rep = new Report__c();
        rep.VOC_Informer_Contact__c = '139';
        rep.Comment__c = '测试';
        rep.Manual_Name__c = '测试医院/科室/经销商';
        insert rep;
        System.Test.startTest();
        PageReference page4 = new PageReference('/apex/RepPAEDecisionRecord?ReportId=' + rep.id + '&RecordTypeIds=ASACDecision');
        System.Test.setCurrentPage(page4);
        RepPAEDecisionRecordController controller4 = new RepPAEDecisionRecordController(new ApexPages.StandardController(rep));
        
        controller4.CancelineFlag = 2;
        // 初始化测试
        controller4.init();
        controller4.toIntake();
        controller4.paedRecordDetailView[0].paedrdd.PAED_ManagementCode__c = 'T001';
        controller4.paedRecordDetailView[0].paedrdd.PAE_Judge__c = 'nonPAE';
        controller4.paedRecordDetailView[0].paedrdd.PAED_Status__c = '有效';
        controller4.SaveAndClose();
        PAE_DecisionRecord__c newRCPAED_IdList = [SELECT LastModifiedDate,PAE_Report__c, Id, Name, LastModifiedById, RecordType.DeveloperName FROM PAE_DecisionRecord__c limit 1];
        
        // PAE_DecisionRecord__c newRCPAED_IdList = [SELECT LastModifiedDate, Id, Name, LastModifiedById, RecordType.DeveloperName FROM PAE_DecisionRecord__c where PAE_Report__c = : rep.id And RecordType.DeveloperName = 'ASRCDecision'
        //     Order by LastModifiedDate desc limit 1
        // ];
 
        PageReference page5 = new PageReference('RepPAEDecisionRecord?RecordTypeIds=ASRCDecision&Id=' + newRCPAED_IdList.id + '&ReportId=' + rep.id);
        System.Test.setCurrentPage(page5);
        RepPAEDecisionRecordController controller5 = new RepPAEDecisionRecordController(new ApexPages.StandardController(rep));
        // 初始化测试
        controller5.Id = newRCPAED_IdList.Id;
 
        controller5.init();
        controller5.paedRecordDetailView[0].paedrdd.PAED_ManagementCode__c = 'T002';
        controller5.paedRecordDetailView[0].paedrdd.PAE_Judge__c = 'nonPAE';
        controller5.paedRecordDetailView[0].paedrdd.PAED_Status__c = '有效';
        controller5.paedRecordDetailView[0].paedrdd.PAED_Reappear_Result__c = '不再現';
        controller5.InsertRow();
        controller5.paedRecordDetailView[1].paedrdd.PAED_ManagementCode__c = 'T003,T004,T005,T006';
        controller5.paedRecordDetailView[1].paedrdd.PAE_Judge__c = 'Unknown';
        controller5.paedRecordDetailView[1].paedrdd.PAED_Status__c = '有效';
        controller5.paedRecordDetailView[1].paedrdd.PAED_Reappear_Result__c = '不再現';
        controller5.RefreshOriginalInterface('String paedRecordId');
        controller5.InsertMoreRows();
        controller5.SaveAndClose();
        System.Test.stopTest();
    }
    static testMethod void myUnitTest01() {
        List < RecordType > rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account'
            and Name = '病院'
        ];
        if (rectCo.size() == 0) {
            return;
        }
        List < RecordType > rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account'
            and Name IN('診療科 消化科', '診療科 呼吸科') order by Name desc
        ];
        if (rectDpt.size() == 0) {
            return;
        }
        List < RecordType > rectAs = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Asset'
            and Name = '备品'
        ];
        if (rectAs.size() == 0) {
            return;
        }
        Account company1 = new Account();
        company1.RecordTypeId = rectCo[0].Id;
        company1.Name = '病院テスト1';
        List < Account > hps = new Account[] {
            company1
        };
        insert hps;
        List < Account > dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = : company1.Id order by Department_Class_Label__c];
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name = '*';
        depart1.Department_Name__c = '診療科1';
        depart1.ParentId = dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c = company1.Id;
        insert depart1;
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c = 'HistoryPrd1';
        prd1.ProductCode = 'HistoryPrd1';
        prd1.Repair_Product_Code__c = 'HistoryPrd1_RP';
        prd1.Name = 'HistoryPrd1';
        prd1.Manual_Entry__c = false;
        prd1.Extend_new_product_gurantee__c = true;
        prd1.Extend_Gurantee_Start__c = Date.today().addDays(-60);
        prd1.Extend_Gurantee_End__c = Date.today().addDays(60);
        insert prd1;
        Oly_TriggerHandler.bypass('AssetHandler');
        Asset ast = new Asset();
        ast.RecordTypeId = rectAs[0].Id;
        ast.SerialNumber = 'abcdefg';
        ast.Name = '测试资产1';
        ast.AccountId = depart1.Id;
        ast.Department_Class__c = dc1s[0].Id;
        ast.Hospital__c = company1.Id;
        ast.Product2Id = prd1.Id;
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate = Date.today();
        ast.Manage_type__c = '个体管理';
        ast.FirstApproveDate_old__c = Date.today().addDays(-30);
        insert ast;
        Report__c rep = new Report__c();
        rep.VOC_Informer_Contact__c = '139';
        rep.Comment__c = '测试';
        rep.Manual_Name__c = '测试医院/科室/经销商';
        insert rep;
        PAE_DecisionRecord__c record = new PAE_DecisionRecord__c(PAE_DetermineResults__c = 'nonPAE', // PAE判定结果
            PAE_ConfirmationDate__c = Date.valueOf('2020-05-06'), // OCSM QARA确认日
            PAE_Authenticator__c = '00510000005sEEM', // OCSM QARA确认者
            PAE_reappear_confirm__c = '未确认' // 再现结果确认
            
        );
        record.PAE_Report__c = rep.Id;
        record.RecordTypeId = Schema.SObjectType.PAE_DecisionRecord__c.getRecordTypeInfosByDeveloperName().get('ASACDecision').getRecordTypeId();
        insert record;
 
        PAE_DecisionRecordDetail__c pae = new PAE_DecisionRecordDetail__c(PAED_RCAC__c = 'Intake', // Intake/Final
            PAED_ManagementCode__c = 'test001', // Code
            PAED_Status__c = '有效', // 状态
            PAED_ConfirmationDate__c = Date.valueOf('2020-05-06'), // 确认日
            PAED_Affirmant__c = '00510000005sEEM', // 确认者
            isInterfaceCreate__c = false, // 是否通过接口新建
            PAE_Judge__c = 'nonPAE', // PAE判定
            PAED_Reappear_Result__c = '不再現', // 再现結果
            InspectionCategory109__c = '0');
        pae.PAE_DecisionRecordD__c = record.Id;
        pae.PAED_Report__c = rep.Id;
        insert pae;
 
        RSA_master_data__c psa = new RSA_master_data__c(RSS_CODE__C = 'Q001', IS_INTAKE_ESTIMATION__C = 'Intake,Estimation', IS_PAE__c = 'No', IS_INACTIVE__C = 'No');
        insert psa;
        RSA_master_data__c psa2 = new RSA_master_data__c(RSS_CODE__C = 'T002', IS_INTAKE_ESTIMATION__C = 'Intake,Estimation', IS_PAE__c = 'No', IS_INACTIVE__C = 'No');
        insert psa2;
        RSA_master_data__c psa3 = new RSA_master_data__c(RSS_CODE__C = 'T003', IS_INTAKE_ESTIMATION__C = 'Intake,Estimation', IS_PAE__c = 'No', IS_INACTIVE__C = 'No');
        insert psa3;
        RSA_master_data__c psa4 = new RSA_master_data__c(RSS_CODE__C = 'T004', IS_INTAKE_ESTIMATION__C = 'Intake,Estimation', IS_PAE__c = 'No', IS_INACTIVE__C = 'No');
        insert psa4;
        RSA_master_data__c psa5 = new RSA_master_data__c(RSS_CODE__C = 'T005', IS_INTAKE_ESTIMATION__C = 'Intake,Estimation', IS_PAE__c = 'No', IS_INACTIVE__C = 'No');
        insert psa5;
        RSA_master_data__c psa6 = new RSA_master_data__c(RSS_CODE__C = 'T006', IS_INTAKE_ESTIMATION__C = 'Intake,Estimation', IS_PAE__c = 'No', IS_INACTIVE__C = 'No');
        insert psa6;
        System.Test.startTest();
        PAE_DecisionRecord__c newRCPAED_IdList1 = [SELECT LastModifiedDate, Id, Name, LastModifiedById, RecordType.DeveloperName FROM PAE_DecisionRecord__c where PAE_Report__c = : rep.id And RecordType.DeveloperName = 'ASACDecision'
            Order by LastModifiedDate desc limit 1
        ];
        PageReference page4 = new PageReference('RepPAEDecisionRecord?RecordTypeIds=ASRCDecision&Id=' + newRCPAED_IdList1.id + '&ReportId=' + rep.id);
        System.Test.setCurrentPage(page4);
        // PageReference page4 = new PageReference('/apex/RepPAEDecisionRecord?ReportId=' + rep.id + '&RecordTypeIds=ASACDecision');
        // System.Test.setCurrentPage(page4);
        RepPAEDecisionRecordController controller4 = new RepPAEDecisionRecordController(new ApexPages.StandardController(rep));
        controller4.CancelineFlag = 2;
 
        // 初始化测试
        controller4.init();
        controller4.toIntake();
        controller4.paedRecordDetailView[0].paedrdd.PAED_ManagementCode__c = 'Q001';
        controller4.paedRecordDetailView[0].paedrdd.PAE_Judge__c = 'Unknown';
        controller4.paedRecordDetailView[0].paedrdd.PAED_Status__c = '有效';
        controller4.SaveAndClose();
        PAE_DecisionRecord__c newRCPAED_IdList = [SELECT LastModifiedDate, Id, Name, LastModifiedById, RecordType.DeveloperName FROM PAE_DecisionRecord__c where PAE_Report__c = : rep.id And RecordType.DeveloperName = 'ASACDecision'
            Order by LastModifiedDate desc limit 1
        ];
        PageReference page5 = new PageReference('RepPAEDecisionRecord?RecordTypeIds=ASRCDecision&Id=' + newRCPAED_IdList.id + '&ReportId=' + rep.id);
        System.Test.setCurrentPage(page5);
        RepPAEDecisionRecordController controller5 = new RepPAEDecisionRecordController(new ApexPages.StandardController(rep));
        // 初始化测试
        controller5.CancelineFlag = 3;
        controller5.init();
        controller5.InsertRow();
        controller5.paedRecordDetailView[0].paedrdd.PAED_ManagementCode__c = 'T002';
        controller5.paedRecordDetailView[0].paedrdd.PAE_Judge__c = 'Unknown';
        controller5.paedRecordDetailView[0].paedrdd.PAED_Status__c = '有效';
        controller5.paedRecordDetailView[0].paedrdd.PAED_Reappear_Result__c = '不再現';
        controller5.InsertRow();
        controller5.paedRecordDetailView[1].paedrdd.PAED_ManagementCode__c = 'T003,T004,T005,T006';
        controller5.paedRecordDetailView[1].paedrdd.PAE_Judge__c = 'Unknown';
        controller5.paedRecordDetailView[1].paedrdd.PAED_Status__c = '有效';
        controller5.paedRecordDetailView[1].paedrdd.PAED_Reappear_Result__c = '不再現';
        controller5.RefreshOriginalInterface('String paedRecordId');
        controller5.InsertMoreRows();
        controller5.SaveAndClose();
        System.Test.stopTest();
    }
  
     static testMethod void myUnitTest5() {
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        // ユーザー作成
        User hpOwner = new User(Job_Category__c = '销售服务', Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner;
        // 取引先作成
        List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectHp.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科','診療科 普外科') order by Name desc];
        if (rectDpt.size() == 0) {
            return;
        }
        Account hp1 = new Account(RecordTypeId = rectHp[0].Id, Name = 'testHp1', OwnerId = hpOwner.Id);
        insert hp1;
 
        List<Account> dc1s = [Select Id, Name, Department_Class_Label__c from Account where Parent.Id = :hp1.Id and Department_Class_Label__c in ('消化科', '呼吸科') order by Department_Class_Label__c];
        
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[1].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = '診療科1';
        depart1.ParentId            = dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c         = hp1.Id;
        
        insert depart1;
        
        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.Category3__c = '';
        prd1.Category4__c = 'CV';
        
        insert prd1;
        
        Asset ast1 = new Asset();
        ast1.Name                   = '保有設備1';
        ast1.Hospital__c            = hp1.Id;
        ast1.Department_Class__c    = dc1s[0].Id;
        ast1.AccountId              = depart1.Id;
        ast1.Product2Id             = prd1.Id;
        ast1.SerialNumber           = 'SerialNumber1';
        ast1.Guarantee_period_for_products__c = Date.today();
        ast1.InstallDate                      = Date.today();
        
        insert ast1;
 
         Report__c rep = new Report__c();
        rep.VOC_Informer_Contact__c = '139';
        rep.Comment__c = '测试';
        rep.Manual_Name__c = '测试医院/科室/经销商';
        insert rep;
        
 
        System.Test.startTest();
        PageReference page = new PageReference('/apex/PAEDecisionRecord?RepairId='+rep.id+'&RecordTypeIds=ASRCDecision');
        System.Test.setCurrentPage(page);
        RepPAEDecisionRecordController controller = new RepPAEDecisionRecordController(new ApexPages.StandardController(rep));
        controller.CancelineFlag = 2;
        controller.intakePAEReappearConfirm = 'nonull';
        controller.editFlag = false;
        controller.RecordTypeName='';
        controller.isOSH = true;
        // 初始化测试
        controller.init();
        controller.paedRecordDetailView[0].paedrdd.PAED_ManagementCode__c = '';
        controller.paedRecordDetailView[0].paedrdd.PAE_Judge__c = 'nonPAE';
        controller.paedRecordDetailView[0].paedrdd.PAED_Status__c = '有效';
        controller.paedRecordDetailView[0].paedrdd.PAED_Reappear_Result__c = '再現';
        controller.InsertMoreRows();
        controller.SaveAndClose();
        //-------------------
        
        RepPAEDecisionRecordController controller2 = new RepPAEDecisionRecordController(new ApexPages.StandardController(rep));
        // 初始化测试
        controller2.init();
        
        controller2.paedRecordDetailView[0].paedrdd.PAED_ManagementCode__c = 'T002';
        controller2.paedRecordDetailView[0].paedrdd.PAE_Judge__c = 'nonPAE';
        controller2.paedRecordDetailView[0].paedrdd.PAED_Status__c = '有效';
        controller2.paedRecordDetailView[0].paedrdd.PAED_Reappear_Result__c = '不再現';
 
        controller2.InsertRow();
        controller2.paedRecordDetailView[1].paedrdd.PAED_ManagementCode__c = 'T003,T004';
        controller2.paedRecordDetailView[1].paedrdd.PAE_Judge__c = 'Unknown';
        controller2.paedRecordDetailView[1].paedrdd.PAED_Status__c = '有效';
        controller2.paedRecordDetailView[1].paedrdd.PAED_Reappear_Result__c = '不再現';
        controller2.InsertMoreRows();
        controller2.SaveAndClose();
    
    }
    
    
}