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
@isTest
private class SubAuthorizedBatchTest {
    public static Account account1 = new Account();
    public static Account account2 = new Account();
    public static Contact contact1 = new Contact();
    public static Contact contact2 = new Contact();
    @isTest static void test_one() {
        account1.Name = 'test1医院';
        account1.RecordTypeId = '01210000000QemG';
        insert account1;
        contact2.AccountId = account1.Id;
        contact2.FirstName = '責任者';
        contact2.LastName = 'test2医院';
        insert contact2;
        List<user> userList = new List<user>();
        Profile p = [select Id from Profile where Name = '系统管理员'];
        UserRole ur = [ SELECT Id, Name FROM UserRole where Name = 'OCSM SFDC管理员'];
        UserRole urtop = [ SELECT Id, Name FROM UserRole where Name = '总经理'];
        UserRole urdown = [ SELECT Id, Name FROM UserRole where Name = '信息系统本部'];
        string userinfoId = UserInfo.getUserId();
 
        User tempUser = [select id from user where id = : userinfoId];
        User user1 = 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');
 
 
        user1.ProfileId = p.Id;
 
        user1.UserRoleId  = ur.id;
        User user2;
        User user3;
        system.runAs(tempUser) {
            userList.add(user1);
 
            user2 = new User(Test_staff__c = true, LastName = 'hp',
                             FirstName = 'owner', Alias = 'hp',
                             CommunityNickname = 'hpOwner1', Email = '2olympus_hpowner@sunbridge.com',
                             Username = '2olympus_hpowner@sunbridge.com', IsActive = true,
                             EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo',
                             LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja');
 
            user2.ProfileId = p.Id;
 
            user2.UserRoleId  = urtop.id;
 
            userList.add(user2);
 
 
            insert userList;
            user3 = new User(Test_staff__c = true, LastName = 'hp',
                             FirstName = 'owner', Alias = 'hp',
                             CommunityNickname = 'hpOwner2', Email = '3olympus_hpowner@sunbridge.com',
                             Username = '3olympus_hpowner@sunbridge.com', IsActive = true,
                             EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo',
                             LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja');
 
 
            user3.ProfileId = p.Id;
 
            user3.UserRoleId  = urdown.id;
 
            user3.ZongjianApprovalManager__c = user1.id;
            user3.TongkuoZongjian__c = user1.id;
            user3.BuchangApprovalManager__c = user1.id;
            user3.BuchangApprovalManagerSales__c = user1.id;
            user3.JingliApprovalManager__c = user1.id;
            user3.SalesManager__c = user1.id;
            user3.ManagerId = user1.id;
            user3.JingliEquipmentManager__c = user1.id;
            user3.Buzhang_Equipment_Manager__c = user1.id;
            insert user3;
        }
        system.runAs(user1) {
            SubAuthorized__c tempSubAuthor = new SubAuthorized__c();
            tempSubAuthor.Status__c  = '已批准';
            tempSubAuthor.AuthorizedStartDate__c = Date.today().adddays(1);
            tempSubAuthor.AuthorizedEndDate__c = Date.today().adddays(2);
            tempSubAuthor.Authorizee__c = user2.id;
            tempSubAuthor.Authorizer__c = user1.id;
            insert tempSubAuthor;
        }
        Database.executeBatch(new SubAuthorizedBatch(), 1);
 
    }
    @isTest static void test_two() {
        account1.Name = 'test1医院';
        account1.RecordTypeId = '01210000000QemG';
        insert account1;
        contact2.AccountId = account1.Id;
        contact2.FirstName = '責任者';
        contact2.LastName = 'test2医院';
        insert contact2;
        List<user> userList = new List<user>();
        Profile p = [select Id from Profile where Name = '系统管理员'];
        UserRole ur = [ SELECT Id, Name FROM UserRole where Name = 'OCSM SFDC管理员'];
        UserRole urtop = [ SELECT Id, Name FROM UserRole where Name = '总经理'];
        UserRole urdown = [ SELECT Id, Name FROM UserRole where Name = '信息系统本部'];
        string userinfoId = UserInfo.getUserId();
 
        User tempUser = [select id from user where id = : userinfoId];
        User user1 = new User(Test_staff__c = true, LastName = 'hp',
                              FirstName = 'owner', Alias = 'hp',
                              CommunityNickname = '4hpOwner', Email = '5olympus_hpowner@sunbridge.com',
                              Username = '4olympus_hpowner@sunbridge.com', IsActive = true,
                              EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo',
                              LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja');
 
 
        user1.ProfileId = p.Id;
 
        user1.UserRoleId  = ur.id;
        User user2;
        User user3;
        system.runAs(tempUser) {
            userList.add(user1);
 
            user2 = new User(Test_staff__c = true, LastName = 'hp',
                             FirstName = 'owner', Alias = 'hp',
                             CommunityNickname = '5hpOwner1', Email = '5olympus_hpowner@sunbridge.com',
                             Username = '5olympus_hpowner@sunbridge.com', IsActive = true,
                             EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo',
                             LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja');
 
            user2.ProfileId = p.Id;
 
            user2.UserRoleId  = urtop.id;
 
            userList.add(user2);
 
 
            insert userList;
        }
        system.runAs(user1) {
            SubAuthorized__c tempSubAuthor = new SubAuthorized__c();
            tempSubAuthor.Status__c  = '已批准';
            tempSubAuthor.IsAuthorize__c     = true;
            tempSubAuthor.AuthorizedStartDate__c = Date.today().adddays(-10);
            tempSubAuthor.AuthorizedEndDate__c = Date.today().adddays(-1);
            tempSubAuthor.Authorizee__c = user2.id;
            tempSubAuthor.Authorizer__c = user1.id;
            insert tempSubAuthor;
        }
        system.runAs(tempUser) {
            user3 = new User(Test_staff__c = true, LastName = 'hp',
                             FirstName = 'owner', Alias = 'hp',
                             CommunityNickname = '6hpOwner2', Email = '6olympus_hpowner@sunbridge.com',
                             Username = '6olympus_hpowner@sunbridge.com', IsActive = true,
                             EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo',
                             LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja');
 
 
            user3.ProfileId = p.Id;
 
            user3.UserRoleId  = urdown.id;
 
            user3.ZongjianApprovalManager_copy__c = user1.id;
            user3.TongkuoZongjian_copy__c = user1.id;
            user3.BuchangApprovalManager_copy__c = user1.id;
            user3.BuchangApprovalManagerSales_copy__c = user1.id;
            user3.JingliApprovalManager_copy__c = user1.id;
            user3.SalesManager_copy__c = user1.id;
            user3.ManagerId_copy__c = user1.id;
            user3.JingliEquipmentManager_copy__c = user1.id;
            user3.Buzhang_Equipment_Manager_copy__c = user1.id;
            insert user3;
        }
 
        Database.executeBatch(new SubAuthorizedBatch(), 1);
 
    }
}