高章伟
2022-02-24 2aa8da8af66aa8ae00f25831aed6bb0364176e7b
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
@isTest
private class ConsumablesApplyOrLendBatchTest {
    static Account createHospital( String hospitalName) {
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE DeveloperName = 'HP'].id;
        hospital.GI_Product_Leader__c = '张三,陈华君,赵四,王五';
        hospital.BF_Product_Leader__c = '张三,陈华君,赵四,王五';
        hospital.GS_Product_Leader__c = '张三,陈华君,赵四,王五';
        hospital.URO_Produc_Leader__c = '张三,陈华君,赵四,王五';
        hospital.GYN_Product_Leader__c = '张三,陈华君,赵四,王五';
        hospital.ENT_Product_Leader__c = '张三,陈华君,赵四,王五';
        hospital.ET_Product_Leader__c = '张三,陈华君,赵四,王五';
        hospital.Name = hospitalName;
        
        insert hospital;
        StaticParameter.EscapeAccountTrigger = true;
        return hospital;
    }
    static List<Account> selectStrategicDep( Account hospital) {
        // 戦略科室を得る
        List<Account> strategicDep = [SELECT ID, Name,OwnerId FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
        return strategicDep;
    }
    static Account createDep( Account hospital, Account strategicDep) {
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE DeveloperName = 'Department_GI'].id;
        dep.Name = 'test dep';
        dep.ParentId = strategicDep.Id;
        dep.Department_Class__c = strategicDep.Id;
        dep.Hospital__c = hospital.Id;
        // dep.State_Text__c = '上海市';
        insert dep;
        return dep;
    }
    static testMethod void testMethod1() {     
       // 病院、戦略科室、診療科の情報を作成します
        Account hospital = createHospital( 'test hospital');
        Account[] strategicDep = selectStrategicDep( hospital);
        Account dep = createDep( hospital, strategicDep[0]);
 
        OPDPlan__c oPDPlan0 = new OPDPlan__c();
        oPDPlan0.Status__c = '完毕未报告';
        oPDPlan0.OPDPlan_ImplementDate__c = Date.today().addDays(1);
        oPDPlan0.NoOpp_Reason__c = 'HCP对应';
        insert oPDPlan0;
 
        Rental_Apply__c ra1 = new Rental_Apply__c();
        ra1.Name = 'test';
        //ra1.applyUser__c = user.Id;
        ra1.Status__c = FixtureUtil.raStatusMap.get(FixtureUtil.RaStatus.Cao_An_Zhong.ordinal());
        ra1.demo_purpose1__c = '其他';
        ra1.demo_purpose2__c = '其他';
        ra1.Request_shipping_day__c = Date.today().addDays(3);
        ra1.Hope_Lonaer_date_Num__c = 6;
        //ra1.Repair__c = repair01.Id;
        ra1.Hospital__c = hospital.Id;
        ra1.Strategic_dept__c = strategicDep[0].Id;
        ra1.Account__c = dep.Id;
        ra1.OPDPlan__c = oPDPlan0.id;
        
        insert ra1;
        List<Rental_Apply__c> raList = [SELECT id,OwnerId,Approver_of_Service_Department__c,Strategic_user__c,Strategic_dept__c,ShareStrategicUser__c FROM Rental_Apply__c WHERE Id = :ra1.Id ];
        System.assertEquals(1, raList.size());
 
        
 
        List<User> user = [select Id,Name from User where IsActive = true];
        strategicDep[0].OwnerId = user[0].Id;
        update strategicDep;
        System.Test.startTest();
        Database.executeBatch(new ConsumablesApplyOrLendBatch(),1);
        strategicDep[0].OwnerId = user[1].Id;
        update strategicDep;
        Database.executeBatch(new ConsumablesApplyOrLendBatch(strategicDep[0].id),1);
        System.Test.stopTest();
 
    }
 
 
    //add by rentx 2020-12-04 start
    static testMethod void testMethod2(){
    // 病院、戦略科室、診療科の情報を作成します
        Account hospital = createHospital( 'test hospital');
        Account[] strategicDep = selectStrategicDep( hospital);
        Account dep = createDep( hospital, strategicDep[0]);
 
        OPDPlan__c oPDPlan0 = new OPDPlan__c();
        oPDPlan0.Status__c = '完毕未报告';
        oPDPlan0.OPDPlan_ImplementDate__c = Date.today().addDays(1);
        oPDPlan0.NoOpp_Reason__c = 'HCP对应';
        insert oPDPlan0;
 
        Rental_Apply__c ra1 = new Rental_Apply__c();
        ra1.Name = 'test';
        ra1.Status__c = FixtureUtil.raStatusMap.get(FixtureUtil.RaStatus.Cao_An_Zhong.ordinal());
        ra1.demo_purpose1__c = '其他';
        ra1.demo_purpose2__c = '其他';
        ra1.Request_shipping_day__c = Date.today().addDays(3);
        ra1.Hope_Lonaer_date_Num__c = 6;
        ra1.Hospital__c = hospital.Id;
        ra1.Strategic_dept__c = strategicDep[0].Id;
        ra1.Account__c = dep.Id;
        ra1.OPDPlan__c = oPDPlan0.id;
        
        insert ra1;
        List<Rental_Apply__c> raList = [SELECT id,OwnerId,Approver_of_Service_Department__c,Strategic_user__c,Strategic_dept__c,ShareStrategicUser__c FROM Rental_Apply__c WHERE Id = :ra1.Id ];
        System.assertEquals(1, raList.size());
 
        
 
        List<User> user = [select Id,Name,Job_Category__c from User where IsActive = true AND Job_Category__c = '销售服务'];
        // List<User> user1 = [select Id,Name from User where IsActive = true AND Job_Category__c = '销售服务'];
        strategicDep[0].OwnerId = user[0].Id;
        strategicDep[0].Department_Class_Label__c = '消化科';
        update strategicDep;
 
        hospital.FSE_GI_Main_Leader__c = user[1].Id;
        hospital.FSE_SP_Main_Leader__c = user[1].Id;
        update hospital;
 
        // User user1 = new User();
        // for (User u :user ) {
        //     if (u.Job_Category__c== '销售服务') {
        //         user1 = u;
        //     }
        // }
 
        ra1.Person_In_Charge__c = user[2].Id;
        update ra1;
 
        System.debug('OCM_dept_category__c::'+ra1.OCM_dept_category__c);
        System.debug('Job_Category__c::'+ra1.Job_Category__c);
        System.debug('Strategic_userFSEGI__c::'+ra1.Strategic_userFSEGI__c);
 
        System.Test.startTest();
            Database.executeBatch(new ConsumablesApplyOrLendBatch(),1);
            strategicDep[0].OwnerId = user[1].Id;
            strategicDep[0].Department_Class_Label__c = '其他';
            update strategicDep;
            Database.executeBatch(new ConsumablesApplyOrLendBatch(strategicDep[0].id),1);
        System.Test.stopTest();
    }
 
    static testMethod void testMethod3(){
    // 病院、戦略科室、診療科の情報を作成します
        Account hospital = createHospital( 'test hospital');
        Account[] strategicDep = selectStrategicDep( hospital);
        Account dep = createDep( hospital, strategicDep[0]);
 
 
        OPDPlan__c oPDPlan0 = new OPDPlan__c();
        oPDPlan0.Status__c = '完毕未报告';
        oPDPlan0.OPDPlan_ImplementDate__c = Date.today().addDays(1);
        oPDPlan0.NoOpp_Reason__c = 'HCP对应';
        insert oPDPlan0;
 
 
        Rental_Apply__c ra1 = new Rental_Apply__c();
        ra1.Name = 'test';
        ra1.Status__c = FixtureUtil.raStatusMap.get(FixtureUtil.RaStatus.Cao_An_Zhong.ordinal());
        ra1.demo_purpose1__c = '其他';
        ra1.demo_purpose2__c = '其他';
        ra1.Request_shipping_day__c = Date.today().addDays(3);
        ra1.Hope_Lonaer_date_Num__c = 6;
        ra1.Hospital__c = hospital.Id;
        ra1.Strategic_dept__c = strategicDep[0].Id;
        ra1.Account__c = dep.Id;
        ra1.OPDPlan__c = oPDPlan0.id;
        
        insert ra1;
        List<Rental_Apply__c> raList = [SELECT id,OwnerId,Approver_of_Service_Department__c,Strategic_user__c,Strategic_dept__c,ShareStrategicUser__c FROM Rental_Apply__c WHERE Id = :ra1.Id ];
        // System.assertEquals(1, raList.size());
 
        
 
        List<User> user = [select Id,Name,Job_Category__c from User where IsActive = true AND Job_Category__c = '销售服务'];
        // List<User> user1 = [select Id,Name from User where IsActive = true AND Job_Category__c = '销售服务'];
        strategicDep[0].OwnerId = user[0].Id;
        strategicDep[0].Department_Class_Label__c = '普外科';
        update strategicDep;
 
        hospital.FSE_GI_Main_Leader__c = user[1].Id;
        hospital.FSE_SP_Main_Leader__c = user[1].Id;
        update hospital;
 
 
        ra1.Person_In_Charge__c = user[2].Id;
        update ra1;
 
        System.debug('OCM_dept_category__c::'+ra1.OCM_dept_category__c);
        System.debug('Job_Category__c::'+ra1.Job_Category__c);
        System.debug('Strategic_userFSEGI__c::'+ra1.Strategic_userFSEGI__c);
 
        System.Test.startTest();
            Database.executeBatch(new ConsumablesApplyOrLendBatch(),1);
            strategicDep[0].OwnerId = user[1].Id;
            strategicDep[0].Department_Class_Label__c = '其他';
            update strategicDep;
            Database.executeBatch(new ConsumablesApplyOrLendBatch(strategicDep[0].id),1);
        System.Test.stopTest();
    }
 
    //add by rentx 2020-12-04 end
    //add by wangweipeng 2021-10-19 start
    static testMethod void testMethod4(){
         //简档
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        //用户
        User u1 = new User(Test_staff__c = true, LastName = '张', FirstName = '三', Alias = '张 三',Work_Location__c = '北京', 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 u1;
        User u2 = new User(Test_staff__c = true, LastName = '赵', FirstName = '四', Alias = '赵 四',Work_Location__c = '重庆', CommunityNickname = 'hpOwner2', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner2@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert u2;
 
        User u3 = new User(Test_staff__c = true, LastName = '王', FirstName = '五', Alias = '王 五',Work_Location__c = '石家庄', CommunityNickname = 'hpOwner3', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner3@sunbridge.com', IsActive = false, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert u3;
 
    // 病院、戦略科室、診療科の情報を作成します
        Account hospital = createHospital( 'test hospital');
        Account[] strategicDep = selectStrategicDep( hospital);
        Account dep = createDep( hospital, strategicDep[0]);
 
        OPDPlan__c oPDPlan0 = new OPDPlan__c();
        oPDPlan0.Status__c = '完毕未报告';
        oPDPlan0.OPDPlan_ImplementDate__c = Date.today().addDays(1);
        oPDPlan0.NoOpp_Reason__c = 'HCP对应';
        insert oPDPlan0;
 
 
        Rental_Apply__c ra1 = new Rental_Apply__c();
        ra1.Name = 'test';
        ra1.Status__c = FixtureUtil.raStatusMap.get(FixtureUtil.RaStatus.Cao_An_Zhong.ordinal());
        ra1.demo_purpose1__c = '其他';
        ra1.demo_purpose2__c = '其他';
        ra1.Request_shipping_day__c = Date.today().addDays(3);
        ra1.Hope_Lonaer_date_Num__c = 6;
        ra1.Hospital__c = hospital.Id;
        ra1.Strategic_dept__c = strategicDep[0].Id;
        ra1.OPDPlan__c = oPDPlan0.id;
        ra1.Account__c = dep.Id;
        ra1.ProducLeader_Share__c = '';
        
        insert ra1;
        List<Rental_Apply__c> raList = [SELECT id,OwnerId,Approver_of_Service_Department__c,Strategic_user__c,Strategic_dept__c,ShareStrategicUser__c FROM Rental_Apply__c WHERE Id = :ra1.Id ];
 
        strategicDep[0].OwnerId = u1.Id;
        strategicDep[0].Department_Class_Label__c = '普外科';
        update strategicDep;
 
 
        hospital.FSE_GI_Main_Leader__c = u2.Id;
        hospital.FSE_SP_Main_Leader__c = u2.Id;
        update hospital;
 
        //备品借出申请 共享计划创建
        Rental_Apply__Share rass = new Rental_Apply__Share();
        rass.RowCause= 'Office_Assistant__c';//手动
        rass.ParentId = ra1.id;
        rass.UserOrGroupId = u2.Id;
        rass.AccessLevel = 'Read';//编辑
        insert rass;
 
        //备品借出申请 共享计划创建
        Rental_Apply__Share rasss = new Rental_Apply__Share();
        rasss.RowCause= 'RentalApplyProducLeaderShare__c';//手动
        rasss.ParentId = ra1.id;
        rasss.UserOrGroupId = u1.Id;
        rasss.AccessLevel = 'Read';//编辑
        insert rasss;
 
 
        Database.executeBatch(new ConsumablesApplyOrLendBatch(),1);
 
        ra1.ShareStrategicUser__c = u2.Id;
        ra1.hospitalLeaderGI__c = u2.Id;
        ra1.hospitalLeaderSP__c = u2.Id;
        ra1.ProducLeader_Share__c = u1.Id;
        update ra1;
 
 
        System.Test.startTest();
            Database.executeBatch(new ConsumablesApplyOrLendBatch(),1);
        System.Test.stopTest();
    }
 
    //add by wangweipeng 2021-10-19 end
}