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++;
|
}
|