高章伟
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
@isTest
private class OpportunityAndContactDailyUpdateTest {
    
   @testsetup
   private static void setup (){
            string profid = '00e10000000Y3o5';
        string rectHpID = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        List<String> classDeptStr = new List<String>();
        classDeptStr.add('Department_Class_GI');
        classDeptStr.add('Department_Class_ET');
        classDeptStr.add('Department_Class_BF');
        classDeptStr.add('Department_Class_GS');
        classDeptStr.add('Department_Class_URO');
        classDeptStr.add('Department_Class_GYN');
        classDeptStr.add('Department_Class_ENT');
        classDeptStr.add('Department_Class_OTH');
        List<RecordType> rectDept = [select Id,developername from RecordType where IsActive = true and SobjectType = 'Account' and developername  in:classDeptStr];
 
        Map<String,String> classDeptMap = new Map<String,String>();
 
        for(String Str : classDeptStr){
            for(RecordType rt : rectDept){
                if(rt.developername == Str){
                    classDeptMap.put(Str, rt.Id);
                }
            }
        }
        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 = profid);
        insert hpOwner;
 
 
        List<User> insertUser = new List<User>();
        user UserGI = New User(
 
            Alias = 'GI_User',
            Email='GI_User@testorg.com',
            EmailEncodingKey='UTF-8',
            LastName='testUserGI',
            Firstname ='GI',
            LanguageLocaleKey='zh_CN',
            LocaleSidKey='zh_CN',
            ProfileId = System.Label.ProfileId_SystemAdmin,
            TimeZoneSidKey='Asia/Shanghai',
            UserName='testUserGI@testorg.com');
        insertUser.add(UserGI);
        user UserET = New User(
 
            Alias = 'ET_User',
            Email='ET_User@testorg.com',
            EmailEncodingKey='UTF-8',
            LastName='testUserET',
            Firstname ='ET',
            LanguageLocaleKey='zh_CN',
            LocaleSidKey='zh_CN',
            ProfileId = System.Label.ProfileId_SystemAdmin,
            TimeZoneSidKey='Asia/Shanghai',
            UserName='testUserET@testorg.com');
        insertUser.add(UserET);
        user UserBF = New User(
 
            Alias = 'BF_User',
            Email='BF_User@testorg.com',
            EmailEncodingKey='UTF-8',
            LastName='testUserBF',
            Firstname ='BF',
            LanguageLocaleKey='zh_CN',
            LocaleSidKey='zh_CN',
            ProfileId = System.Label.ProfileId_SystemAdmin,
            TimeZoneSidKey='Asia/Shanghai',
            UserName='testUserBF@testorg.com');
        insertUser.add(UserBF);
        user UserGS = New User(
 
            Alias = 'SP_User',
            Email='SP_User@testorg.com',
            EmailEncodingKey='UTF-8',
            LastName='testUserGS',
            Firstname ='GS',
            LanguageLocaleKey='zh_CN',
            LocaleSidKey='zh_CN',
            ProfileId = System.Label.ProfileId_SystemAdmin,
            TimeZoneSidKey='Asia/Shanghai',
            UserName='testUserGS@testorg.com');
        insertUser.add(UserGS);
        user UserURO = New User(
 
            Alias = 'URO_User',
            Email='URO_User@testorg.com',
            EmailEncodingKey='UTF-8',
            LastName='testUserURO',
            Firstname ='URO',
            LanguageLocaleKey='zh_CN',
            LocaleSidKey='zh_CN',
            ProfileId = System.Label.ProfileId_SystemAdmin,
            TimeZoneSidKey='Asia/Shanghai',
            UserName='testUserURO@testorg.com');
        insertUser.add(UserURO);
        user UserGYN = New User(
 
            Alias = 'GYN_User',
            Email='GYN_User@testorg.com',
            EmailEncodingKey='UTF-8',
            LastName='testUserGYN',
            Firstname ='GYN',
            LanguageLocaleKey='zh_CN',
            LocaleSidKey='zh_CN',
            ProfileId = System.Label.ProfileId_SystemAdmin,
            TimeZoneSidKey='Asia/Shanghai',
            UserName='testUserGYN@testorg.com');
        insertUser.add(UserGYN);
        user UserENT = New User(
 
            Alias = 'ENT_User',
            Email='ENT_User@testorg.com',
            EmailEncodingKey='UTF-8',
            LastName='testUserENT',
            Firstname ='ENT',
            LanguageLocaleKey='zh_CN',
            LocaleSidKey='zh_CN',
            ProfileId = System.Label.ProfileId_SystemAdmin,
            TimeZoneSidKey='Asia/Shanghai',
            UserName='testUserENT@testorg.com');
        insertUser.add(UserENT);
        user UserFSE = New User(
 
            Alias = 'FSEUser',
            Email='FSE_User@testorg.com',
            EmailEncodingKey='UTF-8',
            LastName='testUserFSE',
            Firstname ='FSE',
            LanguageLocaleKey='zh_CN',
            LocaleSidKey='zh_CN',
            ProfileId = System.Label.ProfileId_SystemAdmin,
            TimeZoneSidKey='Asia/Shanghai',
            UserName='testUserFSE@testorg.com');
        insertUser.add(UserFSE);
        insert insertUser;
        integer i = 0;
 
         Map<String,String> NameTOno = New Map<String,String>();
        for(user usr : insertUser){
            NameTOno.put(usr.Id, usr.Employee_No__c);
        }
        Account Hospital = new Account(
                                name = 'Test Hospital',
                                RecordTypeId = rectHpId,
                                FSE_Main__c = UserFSE.Id,
                                ENT_owner_ID__c = UserENT.Id,
                                GYN_owner__c = UserGYN.Id,
                                URO_owner_ID__c = UserURO.Id,
                                SP_Main__c = UserGS.Id,
                                BF_owner__c = UserBF.Id,
                                ET_owner__c = UserET.Id,
                                GI_Main__c = UserGI.Id,
                                Is_Active__c  ='有効'
                                );
        insert Hospital;
 
        List<Account> dcs = 
        [Select Id, Name, Department_Class_Label__c 
        from Account 
        where Parent.Id = :Hospital.Id and Department_Class_Label__c = '呼吸科'];
        Account depart = new Account();
        depart.RecordTypeId = '01210000000QfmR';
        depart.Name         = '*';
        depart.Department_Name__c  = '診療科';
        depart.ParentId            = dcs[0].Id;
        depart.Department_Class__c = dcs[0].Id;
        depart.Hospital__c         = Hospital.Id;
        depart.OwnerId             = UserGS.Id;
        insert depart;
        Contact core = new Contact(email='jplumber@salesforce.com',
        firstname='Joe',
        lastname='Plumber',
        accountid=depart.id);
        insert core;
        Opportunity target = new Opportunity( Name = 'aiueo', StageName = 'contact', CloseDate = Date.today(),
                                            accountid=depart.id);
        target.Trade__c = '内貿';
        target.CurrencyIsoCode = 'CNY';
        target.Wholesale_Price__c = 9000;
        target.Sales_Root__c = 'AAA';
        insert target;
 
 
   }
 
    static testMethod void testMethod1() {
        list<account> acclist = [select id from account where name ='Test Hospital'];
        Id execBTId = Database.executeBatch(new OpportunityAndContactDailyUpdateBatch(), 5);
        execBTId = Database.executeBatch(new OpportunityAndContactDailyUpdateBatch('1.华北'), 5);
        execBTId = Database.executeBatch(new OpportunityAndContactDailyUpdateBatch(10, acclist[0].id, 
             acclist[0].id,
             acclist[0].id,
              acclist[0].id,
              acclist[0].id)
            , 5);
        execBTId = Database.executeBatch(new OpportunityAndContactDailyUpdateBatch(), 5);
 
    }
}