李彤
2023-03-16 cb4bae31a02af72fea30e1a57c1d498eabef5d01
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
trigger UserToContact on User (before insert, before update, after insert, after update) {
    if(StaticParameter.EscapeContactToUser){
        system.debug('StaticParameter.EscapeContactToUser'+StaticParameter.EscapeContactToUser);
        return;
    }
    List<String> userEmployeeNoList = new List<String>();
    List<String> userInterfaceList = new List<String>();
    List<String> noList = new List<String>();
    List<String> noToInterfaceList = new List<String>();
    User old = null;
    for (User local : Trigger.New) {
        if (Trigger.isUpdate) {
            old = Trigger.oldMap.get(local.Id);
        }
 
        //20230303 lt DB202302421915 start 
        if(Trigger.isBefore && Trigger.isUpdate && local.Pregnant_Rest__c != old.Pregnant_Rest__c){
            if(old.Pregnant_Rest__c == FALSE && local.Pregnant_Rest__c == TRUE){
                local.Maternity_leave_StartDate__c = Date.today();
            }
            if(old.Pregnant_Rest__c == TRUE && local.Pregnant_Rest__c == FALSE){
                local.Maternity_leave_EndDate__c = Date.today();
            }
        }
        //20230303 lt DB202302421915 end
 
        if (String.isNotBlank(local.Employee_No__c)  
                            && ( Trigger.isInsert 
                            || old.Test_staff__c != local.Test_staff__c
                            || old.IsActive != local.IsActive
                            || old.LastName != local.LastName
                            || old.FirstName != local.FirstName
                            || old.Notes_File_Name__c != local.Notes_File_Name__c //NOTES用户文件名
                            || old.Email != local.Email  //メール Email
                            || old.Stay_or_not__c != local.Stay_or_not__c // 在职/离职 Stay_or_not__c
                            || old.Employee_No__c != local.Employee_No__c  //员工号码 Employee_No_manual__c
                            || old.Job_Category__c != local.Job_Category__c  //职种 Job_Category_picklist__c
                            || old.ZongjianApprovalManager__c != local.ZongjianApprovalManager__c  //总监 ZongjianApprovalManager__c
                            || old.Hire_Date__c != local.Hire_Date__c  //入职日 Hire_date_text__c
                            || old.OnlinePlatformBuchang__c != local.OnlinePlatformBuchang__c  //部长 OnlinePlatformBuchang__c
                            || old.OnlinePlatformManager__c != local.OnlinePlatformManager__c  //经理 OnlinePlatformManager__c
                            || old.FederationIdentifier != local.FederationIdentifier //联盟ID FederationIdentifier
                            //用户的工作地(人事)改变更新到联系人上 thh 2022-02-17 start
                            || old.Work_Location_HR__c != local.Work_Location_HR__c 
                            //用户的工作地(人事)改变更新到联系人上 thh 2022-02-17 end
                            || old.Salesdepartment__c != local.Salesdepartment__c //  销售本部 Saleddepartment_text__c
                            || old.Category5__c != local.Category5__c // 部 Category5__c
                            || old.Category6__c != local.Category6__c // 课 Category6__c
                            || old.Province__c != local.Province__c // 省 Province__c
                            || old.Null_Update__c != local.Null_Update__c //ods处理历史数据
                            )
                    ) {
            
            if (local.SendToComPlat__c == true && old.SendToComPlat__c == false) {
                userInterfaceList.add(local.Employee_No__c.toLowerCase());
                userInterfaceList.add(local.Employee_No__c.toUpperCase());
                // if ( local.Stay_or_not__c != '待入职' && Trigger.isAfter) {
                //     noToInterfaceList.add(local.Id);
                // }
                continue;
                
            } else {
                userEmployeeNoList.add(local.Employee_No__c);
                if ( local.Stay_or_not__c != '待入职' && local.ProfileId !=System.Label.ProfileId_2J1 && Trigger.isAfter) {
                    noList.add(local.Id);
                }
                continue;
            } 
 
        }
        // system.debug('UserToContact'+old.HR_Post__c+'==='+local.HR_Post__c);
        if (String.isNotBlank(local.Employee_No__c) && (Trigger.isInsert 
                            || old.Mobile_Phone__c != local.Mobile_Phone__c  //手机号码2 MobilePhone
                            || old.Work_Location__c != local.Work_Location__c  //工作地 Work_Location_manual__c
                            //用户的工作地(人事)改变更新到联系人上 thh 2022-02-16 start
                            || old.Work_Location_HR__c != local.Work_Location_HR__c 
                            //用户的工作地(人事)改变更新到联系人上 thh 2022-02-16 end
                            //|| old.Post__c != local.Post__c  //职位 Post_picklist__c
                            || old.HR_Post__c != local.HR_Post__c//HR通用职级 //20220425  LLIU-CCY9TA you
                            || old.PositionSubsequence__c != local.PositionSubsequence__c//20220428 LLIU-CDW5ZW you 岗位子序列
                            || old.Rank__c != local.Rank__c//20220512 you LLIU-CDW5ZW start 职级
                            || old.Gender__c != local.Gender__c  //性别 Gender_text__c
                            || old.Pregnant_Rest__c != local.Pregnant_Rest__c // 是否产假 Pregnant_Rest__c
                            || old.Dept__c != local.Dept__c  //本部 dept__c
                            ) 
                    ) { 
            userEmployeeNoList.add(local.Employee_No__c.toLowerCase());
            userEmployeeNoList.add(local.Employee_No__c.toUpperCase());
                
        }
    }
 
    if (Trigger.isAfter && (Trigger.isInsert || Trigger.isUpdate)) {
        if (userEmployeeNoList.size() > 0) {
            ControllerUtil.upsertFutureContact(userEmployeeNoList); 
        }
        if (userInterfaceList.size() > 0) {
            ControllerUtil.upsertFutureContactInterface(userInterfaceList); 
        } 
        if (noList.size() > 0) {
            NFM621Controller.callout('',  noList);
        }
        // if (noToInterfaceList.size() > 0) {
        //     NFM621Controller.executefuture('',  noToInterfaceList);
        // }
    }
 
    //add     wangweipeng                  2021/12/23               start
    //如果是hr更新了user数据,那么把更新或修改的user Id赋值给hr表上的User__c字段
    if (Trigger.isAfter && (Trigger.isInsert || Trigger.isUpdate)) {
        List<String> userIdList = new List<String>();
        Map<String,Id> userIdMap = new Map<String,Id>();
        for (User newu : Trigger.New) {
            User oldu = null;
            if (Trigger.isUpdate) {
                oldu = Trigger.oldMap.get(newu.Id);
            }
            //以下是ods更新user表的字段
            if(String.isNotBlank(newu.Employee_No__c)
                && newu.IsMEBG__c == true
                && (Trigger.isInsert  
                    || oldu.Group_sales_dept__c != newu.Group_sales_dept__c//统括本部
                    || oldu.Dept__c != newu.Dept__c//本部
                    || oldu.Category5__c != newu.Category5__c//部
                    || oldu.Category6__c != newu.Category6__c//课
                    || oldu.Employee_No__c != newu.Employee_No__c//员工编码
                    || oldu.Hire_Date__c != newu.Hire_Date__c//入职日期
                    || oldu.Email != newu.Email//电子邮件
                    || oldu.Mobile_Phone__c != newu.Mobile_Phone__c//手机号码
                    //|| oldu.Post__c != newu.Post__c//职位
                    || oldu.HR_Post__c != newu.HR_Post__c//HR通用职级 //20220425  LLIU-CCY9TA you
                    || oldu.PositionSubsequence__c != newu.PositionSubsequence__c//20220428 LLIU-CDW5ZW you 岗位子序列
                    || oldu.Rank__c != newu.Rank__c//20220512 you LLIU-CDW5ZW start 职级
                    || oldu.Job_Category__c != newu.Job_Category__c//职种
                    //用户的工作地(人事)改变,更新HR信息上的用户字段 thh 2022-02-17 start
                    || oldu.Work_Location_HR__c != newu.Work_Location_HR__c 
                    //用户的工作地(人事)改变,更新HR信息上的用户字段 thh 2022-02-17 end
                    || oldu.Product_specialist_incharge_product__c != newu.Product_specialist_incharge_product__c//负责产品(主)
                    || oldu.Sales_Speciality__c != newu.Sales_Speciality__c//销售工作内容
                    || oldu.Work_Location__c != newu.Work_Location__c//工作地
                    || oldu.Stay_or_not__c != newu.Stay_or_not__c//在职/已离职
                    || oldu.QuitDate__c != newu.QuitDate__c//离职日期
                    || oldu.Alias != newu.Alias //别名
                    || oldu.Null_Update__c != newu.Null_Update__c //ods处理历史数据
                    )
                )
            {
                //员工编码小写
                userIdList.add(newu.Employee_No__c.toLowerCase());
                userIdMap.put(newu.Employee_No__c.toLowerCase(), newu.Id);
                //员工编码大写
                userIdList.add(newu.Employee_No__c.toUpperCase());
                userIdMap.put(newu.Employee_No__c.toUpperCase(), newu.Id);
            }
        }
        if(userIdList != null && userIdList.size() > 0){
            ControllerUtil.updateFutureOds(userIdList,userIdMap);
        }
    }
    //add     wangweipeng                  2021/12/23               start
    
    /* 2018-12-10 CHAN-B6W86D 根据简档进行权限设置 start */
    UserProfileHandler handler = new UserProfileHandler();
    handler.run();
    /* 2018-12-10 CHAN-B6W86D 根据简档进行权限设置 end*/
    Integer i = 0;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
}