liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
@isTest
public  class lexConsumabletargetformControllerTest {
    @isTest
    static void Test1(){
        Address_Level__c al = new Address_Level__c();
        al.Name = '東京';
        al.Level1_Code__c = 'CN-99';
        al.Level1_Sys_No__c = '999999';
        insert al;
        Date today = Date.today();
        Integer year = today.year();
        Integer month = today.month();
        String fiscalYearValue = '';
        if(month<4){
            fiscalYearValue = 'FY'+String.valueOf(year);
        }else{
            fiscalYearValue = 'FY'+String.valueOf(year+1);
        }
        RecordType recByoin = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name='病院' limit 1];
        User currentUser = [SELECT Alias FROM User WHERE Id = :UserInfo.getUserId()];
        String userAlias = currentUser.Alias;
        Account hospital = new Account(Name = 'テスト病院');
        hospital.RecordTypeId = recByoin.id;
        hospital.Site = 'テスト病院部門';
        hospital.Alias_Name2__c = 'テスト病院別名';
        hospital.ET_owner__c = UserInfo.getUserId();
        hospital.ET_Product_Leader__c = userAlias;
        insert hospital;
 
        List<ConsumableTargetManage__c> CTMAList = new List<ConsumableTargetManage__c>();
        ConsumableTargetManage__c CTMAobj = new ConsumableTargetManage__c();
        CTMAobj.Category3__c = '基干';
        CTMAobj.Category4__c = '异物钳';
        CTMAobj.TargetNumber__c = 2;
        CTMAobj.StrategicDepartment__c = null;
        CTMAobj.Hospital__c = hospital.Id;
        CTMAobj.PlannedNewOpeningTime__c = Date.today();
        CTMAobj.OCM_Year__c = fiscalYearValue;
        if(CTMAobj.Category3__c=='ENG耗材'){
            CTMAobj.productType__c = '外科耗材';
        }else {
            CTMAobj.productType__c = 'ET耗材';
        }
        CTMAobj.ConsumableTargetManageKey__c = CTMAobj.Hospital__c+'-'+CTMAobj.Category3__c+'-'+CTMAobj.Category4__c+'-'+CTMAobj.OCM_Year__c;
        CTMAList.add(CTMAobj);
        String SubmitManageApprovedata = JSON.serialize(CTMAList);
        String rsualt = lexConsumabletargetformController.SubmitApprovals(SubmitManageApprovedata);
        lexConsumabletargetformController.selectAllConsumableTargetManagecopy(fiscalYearValue);
        List<Map<String,String>> options = lexConsumabletargetformController.getPicklistValues('ConsumableTargetManage__c','productType__c',true);
        List<ConsumableTargetManage__c> rtn = lexConsumabletargetformController.selectAllConsumableTargetManage(fiscalYearValue,options[1].get('value'));
        Set<String> mySet = new Set<String>();
        for (ConsumableTargetManage__c value : rtn) {
            mySet.add(value.H_Salesdepartment_HP__c+'-'+fiscalYearValue+'-'+value.Category3__c+'-'+value.Category4__c);
        }
        
        List<String> arrays = new List<String>();
        arrays.addAll(mySet);
        String ETASPKeyListstr = JSON.serialize(arrays);
        lexConsumabletargetformController.selectETASP(ETASPKeyListstr);
        lexConsumabletargetformController.selectSDepartmentByHospital(hospital.Id);
        List<Address_Level__c> sh = lexConsumabletargetformController.selectState_Master();
        lexConsumabletargetformController.selectCityMasterByStateMaste(sh[0].Id);
        lexConsumabletargetformController.selectConsumableTargetManageByCondition(fiscalYearValue,'ET耗材','新开','','','','');
        ConsumableData a= new ConsumableData();
        List<ConsumableData> ALIST = new List<ConsumableData>();
        a.id = rtn[0].Id;
        a.consumableTargetManageKey = rtn[0].ConsumableTargetManageKey__c;
        a.hospital = rtn[0].Hospital__c;
        a.category3 = rtn[0].Category3__c;
        a.category4 = rtn[0].Category4__c;
        a.issuesAndPlans = rtn[0].IssuesAndPlans__c;
        a.actualUsageNum1 = 1;
        a.actualUsageNum2 = 1;
        a.actualUsageNum3 = 1;
        a.actualUsageNum4 = 1;
        a.actualUsageNum5 = 1;
        a.actualUsageNum6 = 1;
        a.actualUsageNum7 = 1;
        a.actualUsageNum8 = 1;
        a.actualUsageNum9 = 1;
        a.actualUsageNum10 = 1;
        a.actualUsageNum11= 1;
        a.actualUsageNum12= 1;
        ALIST.add(a);
        String ALISTSTR = JSON.serialize(ALIST);
        lexConsumabletargetformController.saveIms(ALISTSTR,fiscalYearValue);
    
    }
    @isTest
    static void myUnitTest() {
        //医院
        Date today = Date.today();
        Integer year = today.year();
        Integer month = today.month();
        String fiscalYearValue = '';
        if(month<4){
            fiscalYearValue = 'FY'+String.valueOf(year);
        }else{
            fiscalYearValue = 'FY'+String.valueOf(year+1);
        }
        List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Agency'];
        if (rectHp.size() == 0) {
            return;
        } 
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', 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);
        
        User thisUser = [select Id from User where Id = :UserInfo.getUserId() ];
        System.runAs ( thisUser ){
            insert hpOwner;
            // 省
            Address_Level__c al = new Address_Level__c();
            al.Name = '广东省';
            al.Level1_Code__c = 'CN-99';
            al.Level1_Sys_No__c = '999999';
            insert al;
            // 市
            Address_Level2__c al2 = new Address_Level2__c();
            al2.Level1_Code__c = 'CN-99';
            al2.Level1_Sys_No__c = '999999';
            al2.Level1_Name__c = '广东省';
            al2.Name = '深圳市';
            al2.Level2_Code__c = 'CN-9999';
            al2.Level2_Sys_No__c = '9999999';
            al2.Address_Level__c = al.id;
            insert al2;
            RecordType recByoin = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name='病院' limit 1];
            Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = thisUser.Id);
            hp.Name = 'test hospital';
            hp.RecordTypeId = recByoin.id;
            hp.FSE_GI_Main_Leader__c = thisUser.Id;
            hp.FSE_SP_Main_Leader__c = thisUser.Id;
            hp.State_Master__c = al.id;
            hp.ET_owner__c = UserInfo.getUserId();
            hp.City_Master__c = al2.id;
            insert hp;
            OCM_Management_Province__c mp1 = new OCM_Management_Province__c();
            mp1.Name = '深圳';
            mp1.Province__c = '广州省';
            mp1.Window1__c = hpOwner.Id;
            mp1.ET_DataWindow__c = hpOwner.Id;
            mp1.ET_BusinessWindow__c = hpOwner.Id;
            mp1.ET_Assistant1__c = hpOwner.Id;
            mp1.ET_Assistant2__c = hpOwner.Id;
            mp1.ENG_DataWindow__c = hpOwner.Id;
            mp1.ENG_BusinessWindow__c = hpOwner.Id;
            insert mp1;
            // List<ConsumableTargetManage__c> CTMAList = new List<ConsumableTargetManage__c>();
            ConsumableTargetManage__c CTMAobj = new ConsumableTargetManage__c();
            CTMAobj.Category3__c = '基干';
            CTMAobj.Category4__c = '异物钳';
            CTMAobj.TargetNumber__c = 2;
            CTMAobj.StrategicDepartment__c = null;
            CTMAobj.Hospital__c = hp.Id;
            CTMAobj.PlannedNewOpeningTime__c = Date.today();
            CTMAobj.OCM_Year__c = fiscalYearValue;
            if(CTMAobj.Category3__c=='ENG耗材'){
                CTMAobj.productType__c = '外科耗材';
            }else {
                CTMAobj.productType__c = 'ET耗材';
            }
            CTMAobj.ConsumableTargetManageKey__c = CTMAobj.Hospital__c+'-'+CTMAobj.Category3__c+'-'+CTMAobj.Category4__c+'-'+CTMAobj.OCM_Year__c;
            // CTMAList.add(CTMAobj);
            insert CTMAobj;
            // 共享计划创建
            String rowCause = Schema.ConsumableTargetManage__Share.RowCause.OCSMToIMSUser__c;
            ConsumableTargetManage__Share tmsshare = new ConsumableTargetManage__Share();
            tmsshare.RowCause= rowCause;//手动
            tmsshare.ParentId = CTMAobj.id;
            tmsshare.UserOrGroupId = hpOwner.Id;
            tmsshare.AccessLevel = 'Read';//编辑
            insert tmsshare;
        }
    }
    @isTest
    static void myUnitTest2() {
        //医院
        Date today = Date.today();
        Integer year = today.year();
        Integer month = today.month();
        String fiscalYearValue = '';
        if(month<4){
            fiscalYearValue = 'FY'+String.valueOf(year);
        }else{
            fiscalYearValue = 'FY'+String.valueOf(year+1);
        }
        List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Agency'];
        if (rectHp.size() == 0) {
            return;
        } 
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', 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);
        
        User thisUser = [select Id from User where Id = :UserInfo.getUserId() ];
        System.runAs ( thisUser ){
            insert hpOwner;
            // 省
            Address_Level__c al = new Address_Level__c();
            al.Name = '广东省';
            al.Level1_Code__c = 'CN-99';
            al.Level1_Sys_No__c = '999999';
            insert al;
            // 市
            Address_Level2__c al2 = new Address_Level2__c();
            al2.Level1_Code__c = 'CN-99';
            al2.Level1_Sys_No__c = '999999';
            al2.Level1_Name__c = '广东省';
            al2.Name = '深圳市';
            al2.Level2_Code__c = 'CN-9999';
            al2.Level2_Sys_No__c = '9999999';
            al2.Address_Level__c = al.id;
            insert al2;
            RecordType recByoin = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name='病院' limit 1];
            Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = thisUser.Id);
            hp.Name = 'test hospital';
            hp.RecordTypeId = recByoin.id;
            hp.FSE_GI_Main_Leader__c = thisUser.Id;
            hp.FSE_SP_Main_Leader__c = thisUser.Id;
            hp.State_Master__c = al.id;
            hp.ET_owner__c = UserInfo.getUserId();
            hp.City_Master__c = al2.id;
            insert hp;
            OCM_Management_Province__c mp1 = new OCM_Management_Province__c();
            mp1.Name = '深圳';
            mp1.Province__c = '广州省';
            mp1.Window1__c = hpOwner.Id;
            mp1.ET_DataWindow__c = hpOwner.Id;
            mp1.ET_BusinessWindow__c = hpOwner.Id;
            mp1.ENG_Assistant1__c = hpOwner.Id;
            mp1.ENG_Assistant2__c = hpOwner.Id;
            mp1.ENG_DataWindow__c = hpOwner.Id;
            mp1.ENG_BusinessWindow__c = hpOwner.Id;
            insert mp1;
            // List<ConsumableTargetManage__c> CTMAList = new List<ConsumableTargetManage__c>();
            ConsumableTargetManage__c CTMAobj = new ConsumableTargetManage__c();
            CTMAobj.Category3__c = 'ENG耗材';
            CTMAobj.Category4__c = 'PK';
            CTMAobj.TargetNumber__c = 2;
            CTMAobj.StrategicDepartment__c = null;
            CTMAobj.Hospital__c = hp.Id;
            CTMAobj.PlannedNewOpeningTime__c = Date.today();
            CTMAobj.OCM_Year__c = fiscalYearValue;
            if(CTMAobj.Category3__c=='ENG耗材'){
                CTMAobj.productType__c = '外科耗材';
            }else {
                CTMAobj.productType__c = 'ET耗材';
            }
            CTMAobj.ConsumableTargetManageKey__c = CTMAobj.Hospital__c+'-'+CTMAobj.Category3__c+'-'+CTMAobj.Category4__c+'-'+CTMAobj.OCM_Year__c;
            // CTMAList.add(CTMAobj);
            insert CTMAobj;
            // 共享计划创建
            String rowCause = Schema.ConsumableTargetManage__Share.RowCause.OCSMToIMSUser__c;
            ConsumableTargetManage__Share tmsshare = new ConsumableTargetManage__Share();
            tmsshare.RowCause= rowCause;//手动
            tmsshare.ParentId = CTMAobj.id;
            tmsshare.UserOrGroupId = hpOwner.Id;
            tmsshare.AccessLevel = 'Read';//编辑
            insert tmsshare;
        }
    }
    public class ConsumableData {
        String id;
        String consumableTargetManageKey;
        String hospital;
        String category3;
        String category4;
        String issuesAndPlans;
        Integer actualUsageNum1;
        Integer actualUsageNum2;
        Integer actualUsageNum3;
        Integer actualUsageNum4;
        Integer actualUsageNum5;
        Integer actualUsageNum6;
        Integer actualUsageNum7;
        Integer actualUsageNum8;
        Integer actualUsageNum9;
        Integer actualUsageNum10;
        Integer actualUsageNum11;
        Integer actualUsageNum12;
    }
}