高章伟
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
@isTest
private class SolutionProjectRequirementsTriggerTest {
 
    private static User getUser() {
        String timenow = Datetime.now().format('yyyyMMddHHmmss');
        User user1 = new User(Test_staff__c = true, LastName = 'TestMao', FirstName = 'TestMaoF',
                Alias = 'hp', CommunityNickname = 'TestMao', Email = 'Test@sunbridge.com',
                Username = 'Test' + timenow + '@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP',
                TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja',
                ProfileId = System.Label.ProfileId_SystemAdmin,
                Dept__c = '医疗华北营业本部', Job_Category__c = '销售服务', Province__c = '北京');
 
        List<Profile> p = [Select Id From Profile Where Name = '2S1_销售医院担当'];
        System.assertEquals(p.size(), 1);
        System.runAs(new User(Id = Userinfo.getUserId())) {
            insert user1;
        }
        return user1;
    }
 
    static testMethod void testMethod2(){
 
        User user = getUser();
 
        
 
        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;
 
        List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'];
        if (rectHp.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_Class_GI'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'];
        if (rectDpt.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', 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;
        User hpOwner2 = new User(Test_staff__c = true, LastName = 'hp2', FirstName = 'owner', Alias = 'hp2', 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 hpOwner2;
 
        // 病院作成
        Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id, GI_Product_Leader__c = System.UserInfo.getName().replace(' ', ''));
        insert hp;
 
        Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];
        Account dc2 = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_BF'];
 
        // 診療科を作る
        NFM001Controller.isRunning = false;
        Account dpt = new Account(RecordTypeId = rectDpt[0].Id);
        dpt.Name         = '*';
        dpt.Department_Name__c  = 'TestDepart';
        dpt.ParentId            = dc.Id;
        dpt.Department_Class__c = dc.Id;
        dpt.Hospital__c         = hp.Id;
        insert dpt;
 
        SolutionProjectRequirements__c solProjecthb = new SolutionProjectRequirements__c();
        solProjecthb.Name = 'Test';
        solProjecthb.HospitalOwner__c = user.Id;
        solProjecthb.Sales_Assistant__c = user.Id;
        solProjecthb.GIR_Assistant__c = user.Id;
        solProjecthb.Project_Type__c = '新建大楼';
        solProjecthb.Purpose_Proposal__c = '促进销售商谈';
        solProjecthb.Hospital__c = hp.Id;
        solProjecthb.Department_Class__c = dpt.Id;
        insert solProjecthb;
 
   
    }
 
    static testMethod void testMethod1() {
        User user = getUser();
        Datetime ocsmDate = Datetime.now();
        String ocsmPeriod = '';
        if(ocsmDate.month() == 1 || ocsmDate.month() == 2 || ocsmDate.month() == 3){
            ocsmPeriod = ocsmPeriod = ocsmDate.year()-1868+'P';
        }else{
            ocsmPeriod = ocsmDate.year()-1867+'P';
        }
        GIRSolutionAreaNumber__c girsolution = new GIRSolutionAreaNumber__c();
        girsolution.Name = ocsmPeriod;
        girsolution.GIRSolutionXN__c = 1;
        girsolution.GIRSolutionXB__c = 1;
        girsolution.GIRSolutionDB__c = 1;
        girsolution.GIRSolutionHN__c = 1;
        girsolution.GIRSolutionHB__c = 1;
        girsolution.GIRSolutionHD__c = 1;
        // girsolution.Name = 'daqu';
        insert girsolution;
 
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }
 
        List<Address_Level__c> addrressList = new List<Address_Level__c>();
        Address_Level__c addresshb = new Address_Level__c();
        addresshb.Level1_Code__c = 'CN-01';
        addrressList.add(addresshb);
        Address_Level__c addressxb = new Address_Level__c();
        addressxb.Level1_Code__c = 'CN-03';
        addrressList.add(addressxb);
        Address_Level__c addressdb = new Address_Level__c();
        addressdb.Level1_Code__c = 'CN-13';
        addrressList.add(addressdb);
        Address_Level__c addresshd = new Address_Level__c();
        addresshd.Level1_Code__c = 'CN-16';
        addrressList.add(addresshd);
        Address_Level__c addresshn = new Address_Level__c();
        addresshn.Level1_Code__c = 'CN-22';
        addrressList.add(addresshn);
        Address_Level__c addressxn = new Address_Level__c();
        addressxn.Level1_Code__c = 'CN-25';
        addrressList.add(addressxn);
        insert addrressList;
 
        List<Account> acclist = new List<Account>();
        Account companyHb = new Account();
        companyHb.RecordTypeId = rectCo[0].Id;
        companyHb.AgentCode_Ext__c = '99999991';
        companyHb.Name         = 'GIRTestCompany';
        companyHb.State_Master__c = addresshb.Id;
        acclist.add(companyHb);
        Account companyxb = new Account();
        companyxb.RecordTypeId = rectCo[0].Id;
        companyxb.AgentCode_Ext__c = '99999992';
        companyxb.Name         = 'GIRTestCompany';
        companyxb.State_Master__c = addressxb.Id;
        acclist.add(companyxb);
        Account companydb = new Account();
        companydb.RecordTypeId = rectCo[0].Id;
        companydb.AgentCode_Ext__c = '99999993';
        companydb.Name         = 'GIRTestCompany';
        companydb.State_Master__c = addressdb.Id;
        acclist.add(companydb);
        Account companyhd = new Account();
        companyhd.RecordTypeId = rectCo[0].Id;
        companyhd.AgentCode_Ext__c = '99999994';
        companyhd.Name         = 'GIRTestCompany';
        companyhd.State_Master__c = addresshd.Id;
        acclist.add(companyhd);
        Account companyHn = new Account();
        companyHn.RecordTypeId = rectCo[0].Id;
        companyHn.AgentCode_Ext__c = '99999995';
        companyHn.Name         = 'GIRTestCompany';
        companyHn.State_Master__c = addresshn.Id;
        acclist.add(companyHn);
        Account companyxn = new Account();
        companyxn.RecordTypeId = rectCo[0].Id;
        companyxn.AgentCode_Ext__c = '99999996';
        companyxn.Name         = 'GIRTestCompany';
        companyxn.State_Master__c = addressxn.Id;
        acclist.add(companyxn);
        insert acclist;
 
        List<SolutionProjectRequirements__c> solproList  = new List<SolutionProjectRequirements__c>();
        SolutionProjectRequirements__c solProjecthb = new SolutionProjectRequirements__c();
        solProjecthb.Name = 'Test';
        solProjecthb.HospitalOwner__c = user.Id;
        solProjecthb.Sales_Assistant__c = user.Id;
        solProjecthb.GIR_Assistant__c = user.Id;
        solProjecthb.Project_Type__c = '新建大楼';
        solProjecthb.Purpose_Proposal__c = '促进销售商谈';
        solProjecthb.Hospital__c = companyHb.Id;
        solproList.add(solProjecthb);
        
        SolutionProjectRequirements__c solProjectxb = new SolutionProjectRequirements__c();
        solProjectxb.Name = 'Test';
        solProjectxb.HospitalOwner__c = user.Id;
        solProjectxb.Sales_Assistant__c = user.Id;
        solProjectxb.GIR_Assistant__c = user.Id;
        solProjectxb.Project_Type__c = '新建大楼';
        solProjectxb.Purpose_Proposal__c = '促进销售商谈';
        solProjectxb.Hospital__c = companyxb.Id;
        solproList.add(solProjectxb);
 
        SolutionProjectRequirements__c solProjectdb = new SolutionProjectRequirements__c();
        solProjectdb.Name = 'Test';
        solProjectdb.HospitalOwner__c = user.Id;
        solProjectdb.Sales_Assistant__c = user.Id;
        solProjectdb.GIR_Assistant__c = user.Id;
        solProjectdb.Project_Type__c = '新建大楼';
        solProjectdb.Purpose_Proposal__c = '促进销售商谈';
        solProjectdb.Hospital__c = companydb.Id;
        solproList.add(solProjectdb);
 
        SolutionProjectRequirements__c solProjecthd = new SolutionProjectRequirements__c();
        solProjecthd.Name = 'Test';
        solProjecthd.HospitalOwner__c = user.Id;
        solProjecthd.Sales_Assistant__c = user.Id;
        solProjecthd.GIR_Assistant__c = user.Id;
        solProjecthd.Project_Type__c = '新建大楼';
        solProjecthd.Purpose_Proposal__c = '促进销售商谈';
        solProjecthd.Hospital__c = companyhd.Id;
        solproList.add(solProjecthd);
 
        SolutionProjectRequirements__c solProjecthn = new SolutionProjectRequirements__c();
        solProjecthn.Name = 'Test';
        solProjecthn.HospitalOwner__c = user.Id;
        solProjecthn.Sales_Assistant__c = user.Id;
        solProjecthn.GIR_Assistant__c = user.Id;
        solProjecthn.Project_Type__c = '新建大楼';
        solProjecthn.Purpose_Proposal__c = '促进销售商谈';
        solProjecthn.Hospital__c = companyHn.Id;
        solproList.add(solProjecthn);
 
        SolutionProjectRequirements__c solProjectxn = new SolutionProjectRequirements__c();
        solProjectxn.Name = 'Test';
        solProjectxn.HospitalOwner__c = user.Id;
        solProjectxn.Sales_Assistant__c = user.Id;
        solProjectxn.GIR_Assistant__c = user.Id;
        solProjectxn.Project_Type__c = '新建大楼';
        solProjectxn.Purpose_Proposal__c = '促进销售商谈';
        solProjectxn.Hospital__c = companyxn.Id;
        solproList.add(solProjectxn);
        insert solproList;
 
        girsolution.GIRSolutionXN__c = 100;
        girsolution.GIRSolutionXB__c = 100;
        girsolution.GIRSolutionDB__c = 100;
        girsolution.GIRSolutionHN__c = 100;
        girsolution.GIRSolutionHB__c = 100;
        girsolution.GIRSolutionHD__c = 100;
        girsolution.Name = ocsmPeriod;
        update girsolution;
 
        for(SolutionProjectRequirements__c sol : solproList){
            sol.Area_Number__c = '';
        }
        
        update solproList;
 
    }
}