This commit is contained in:
2026-02-10 15:41:06 +08:00
parent 51d772994f
commit 31be7ae4b8
183 changed files with 29172 additions and 9245 deletions
+2 -1
View File
@@ -90,7 +90,8 @@ namespace BLL
studyWo = x.Study_wo,
cteInvolved = x.Cte_involved,
capexPlanNo = x.Capex_plan_no,
cdi = x.CDI
cdi = x.CDI,
projectManagerAccount=x.ProjectManagerAccount
}).ToList();
return getEproject;
+147 -62
View File
@@ -10,14 +10,14 @@ namespace BLL.APIService
public class SyncUserInfoService
{
private const string GETTOKENAPI = "https://ppsintf.basf-ypc.net.cn/ppsinterface/token/getToken";
private const string GETHRINfOAPI = "https://ppsintf.basf-ypc.net.cn/ppsinterface/interfaceInfo/getHrInfo";
private const string GETHRINfOAPI = "https://ppsintf.basf-ypc.net.cn/ppsinterface/interfaceInfo/getHrInfo?start=1&nums=3000";
public static string GetUserToken()
{
string username = "itinforadm";
string password = "B9$hxQ@?t<p*";
string result = BLL.Common.HttpHelper.HttpPostRequest(GETTOKENAPI,$"username={username}&password={password}",string.Empty);
string result = BLL.Common.HttpHelper.HttpPostRequest(GETTOKENAPI, $"username={username}&password={password}", string.Empty);
var data = JsonHelper.DeserializeJsonToObject<ResultData>(result);
if ("200"==data.code)
if ("200" == data.code)
{
return data.token;
}
@@ -26,35 +26,36 @@ namespace BLL.APIService
ErrLogInfo.WriteLog("请求失败:返回结果:" + result);
return null;
}
}
/// <summary>
/// 获取HR信息并进行逻辑处理
/// </summary>
public static void GetSyncUserInfo()
{
// var token = GetUserToken(); //获取接口token
var token = GetUserToken(); //获取接口token
var dic = GetDepartList(); //把本地数据库中的部门全部取出作为字典
var dicUser = GetUserInfoByAccount(); //同上把所有用户取出来
string file = System.Web.HttpContext.Current.Server.MapPath("~/data.txt");
string result = System.IO.File.ReadAllText(file);
//string result = BLL.Common.HttpHelper.HttpPostRequest(GETHRINfOAPI, "", token);
//string file = System.Web.HttpContext.Current.Server.MapPath("~/data.txt");
//string result = System.IO.File.ReadAllText(file);
string result = BLL.Common.HttpHelper.HttpPostRequest(GETHRINfOAPI, "", token);
var data = JsonHelper.DeserializeJsonToObject<ResultData<List<UserInfo>>>(result);
List<Model.SyncDataUserLogs> logList = new List<Model.SyncDataUserLogs>();
if (data.code == "200")
{
//ErrLogInfo.WriteLog($"userinfo={data.data}");
// ErrLogInfo.WriteLog($"userinfo={data.data}");
var userInfo = data.data;
string batchNo= DateTime.Now.ToString("yyyyMMddHHmmss");
string batchNo = DateTime.Now.ToString("yyyyMMddHHmmss");
DateTime syncTime = DateTime.Now;
foreach (var item in userInfo)
{
var account = item.ppsHrOtherEmp.bgdid;// 当前json的账号
if (string.IsNullOrEmpty(account))
if (item.ppsHrOtherEmp == null || string.IsNullOrEmpty(item.ppsHrOtherEmp.bgdid))
{
Model.SyncDataUserLogs log3 = new Model.SyncDataUserLogs();
log3.BatchNo = batchNo;
log3.CreatedTime = syncTime;
log3.DataType = 3;
log3.DataType = 3; //错误在账号信息类型
log3.DepatId = string.Empty;
log3.UserId = string.Empty;
log3.IsSuccess = false;
@@ -62,6 +63,7 @@ namespace BLL.APIService
logList.Add(log3);
continue;
}
var account = item.ppsHrOtherEmp.bgdid;// 当前json的账号
var manager = item.ppsHrOtherEmp.manager; //当前经理的员工号
account = account.ToLower();
var user = dicUser.ContainsKey(account); //判断当前账号是否在我们数据库中
@@ -76,7 +78,7 @@ namespace BLL.APIService
log.BatchNo = batchNo;
log.CreatedTime = syncTime;
//如果是经理,总经理,总监
if (item.position.Contains("Manager") || item.position.Contains("Director") || item.position.Contains("General Manager"))
if (item.section.ToUpper() == "CTT" && item.position.Contains("Director"))
{
//判断是否存在部门
if (IsExistsDepart(dic, item.section))
@@ -86,7 +88,39 @@ namespace BLL.APIService
}
else
{
departId = InsertDepartInfo(userId, item.section); //插入本地数据库部门
departId = InsertDepartInfo(dic, userId, item.section); //插入本地数据库部门
}
}
else if ((item.section.ToUpper() == "CTT" && item.position.Contains("Manager")) || item.section.ToUpper() == "CTT" && item.position.Contains("General Manager"))
{
//不处理
//判断是否存在部门
if (IsExistsDepart(dic, item.section))
{
departId = dic[item.section]; //取出本地数据库部门ID
// UpdateDepartInfo(null, item.section); //更新部门表数据
}
else
{
departId = InsertDepartInfo(dic, null, item.section); //插入本地数据库部门
}
}
else if ((item.position.Contains("Manager") || item.position.Contains("Director") || item.position.Contains("General Manager")))
{
//判断是否存在部门
if (IsExistsDepart(dic, item.section))
{
departId = dic[item.section]; //取出本地数据库部门ID
//eftEffectiveDate有值说明此人已离职
if (!item.ppsHrOtherEmp.leftEffectiveDate.HasValue)
{
UpdateDepartInfo(userId, item.section); //更新部门表数据
}
}
else
{
departId = InsertDepartInfo(dic, userId, item.section); //插入本地数据库部门
}
}
else
@@ -102,11 +136,14 @@ namespace BLL.APIService
if (IsExistsDepart(dic, itemDepartCode))
{
departId = dic[itemDepartCode]; //取出自身部门所在的部门ID
UpdateDepartInfo(itemUserId, itemDepartCode); //更新自身部门的部门数据。
if (!item.ppsHrOtherEmp.leftEffectiveDate.HasValue)
{
UpdateDepartInfo(itemUserId, itemDepartCode); //更新自身部门的部门数据。
}
}
else
{
departId = InsertDepartInfo(itemUserId, itemDepartCode); //插入本地部门表数据
departId = InsertDepartInfo(dic, itemUserId, itemDepartCode); //插入本地部门表数据
}
}
else
@@ -124,19 +161,23 @@ namespace BLL.APIService
//上级用户所在的部门已经存在
if (IsExistsDepart(dic, parentDepatCode))
{
departId = dic[parentDepatCode]; //取出他上级用户所在的部门ID
UpdateDepartInfo(parentUserId, parentDepatCode); //更新部门信息
//departId = dic[parentDepatCode]; //取出他上级用户所在的部门ID
if (!parentUser.ppsHrOtherEmp.leftEffectiveDate.HasValue)
{
UpdateDepartInfo(parentUserId, parentDepatCode); //更新部门信息
}
//并且插入自己子部门信息
departId = InsertDepartInfoChilds(dic, parentUserId, item.section);
}
else
{
departId = InsertDepartInfo(parentUserId, parentDepatCode); //插入他上级用户所在的部门到部门表中去
departId = InsertDepartInfo(dic, parentUserId, parentDepatCode); //插入他上级用户所在的部门到部门表中去
}
}
}
log.DepatId = departId;
log.DataType = 0;
log.DataType = 0; //同步部门类型数据
log.Remark = "同步成功";
log.IsSuccess = true;
}
@@ -154,11 +195,12 @@ namespace BLL.APIService
#region
Model.SyncDataUserLogs log2 = new Model.SyncDataUserLogs();
string resultId = string.Empty;
try
{
log2.BatchNo = batchNo;
log2.CreatedTime = syncTime;
log2.Josn = JsonHelper.SerializeObject(item);
//当前本地数据库用户表不存在此用户
if (!user)
{
@@ -169,9 +211,10 @@ namespace BLL.APIService
}
else
{
resultId = UpdateUserInfo(item, departId);
log.UserId = resultId;
log.DataType = 1;
log.DataType = 1; //同步用户类型数据
}
log2.Remark = "同步成功";
log2.IsSuccess = true;
@@ -180,12 +223,14 @@ namespace BLL.APIService
{
log.UserId = resultId;
log.DataType = 1;
log2.Remark =$"同步失败:{ex.Message}";
log2.Remark = $"同步失败:{ex.Message}";
log2.IsSuccess = false;
}
//这里记录同步用户的日志
logList.Add(log2);
#endregion
}
AddSyncLogs(logList);
@@ -201,28 +246,27 @@ namespace BLL.APIService
/// 获取所有的BU
/// </summary>
/// <returns></returns>
private static Dictionary<string,string> GetDepartList()
private static Dictionary<string, string> GetDepartList()
{
return BLL.Funs.DB.Base_Depart.ToList()
.ToDictionary(t => t.DepartCode.ToUpper(), t => t.DepartId);
}
/// <summary>
/// 获取所有的User
/// </summary>
/// <returns></returns>
private static Dictionary<string,string> GetUserInfoByAccount()
private static Dictionary<string, string> GetUserInfoByAccount()
{
return BLL.Funs.DB.Sys_User.Select(t => new { t.UserId, t.Account }).ToList()
.ToDictionary(t => t.Account.ToLower(), t => t.UserId);
}
/// <summary>
/// 更新BU
/// </summary>
/// <param name="leaderId"></param>
/// <param name="depatCode"></param>
private static void UpdateDepartInfo(string leaderId,string depatCode)
private static void UpdateDepartInfo(string leaderId, string depatCode)
{
//更新leader字段
if (!string.IsNullOrEmpty(leaderId))
@@ -235,22 +279,53 @@ namespace BLL.APIService
/// 新增BU
/// </summary>
/// <returns></returns>
private static string InsertDepartInfo(string leaderId, string depatCode)
private static string InsertDepartInfo(Dictionary<string, string> dic, string leaderId, string depatCode)
{
//插入部门信息,并且把leader字段写入
var depatModel = new Model.Base_Depart();
depatModel.DepartId = SQLHelper.GetNewID(typeof(Model.Base_Depart));
depatModel.DepartCode = depatCode;
depatModel.DepartName = depatCode;
depatModel.DepartLeader = leaderId;
BLL.DepartService.AddDepart(depatModel);
return depatModel.DepartId;
var result = Funs.DB.Base_Depart.FirstOrDefault(t => t.DepartCode == depatCode);
if (result == null)
{
//插入部门信息,并且把leader字段写入
var depatModel = new Model.Base_Depart();
depatModel.DepartId = SQLHelper.GetNewID(typeof(Model.Base_Depart));
depatModel.DepartCode = depatCode;
depatModel.DepartName = depatCode;
depatModel.DepartLeader = leaderId;
BLL.DepartService.AddDepart(depatModel);
if (!dic.ContainsKey(depatCode.ToUpper()))
{
dic.Add(depatCode.ToLower(), depatModel.DepartId);
}
return depatModel.DepartId;
}
return result.DepartId;
}
private static string InsertDepartInfoChilds(Dictionary<string, string> dic, string leaderId, string depatCode)
{
var result = Funs.DB.Base_Depart.FirstOrDefault(t => t.DepartCode == depatCode);
if (result == null)
{
//插入部门信息,并且把leader字段写入
var depatModel = new Model.Base_Depart();
depatModel.DepartId = SQLHelper.GetNewID(typeof(Model.Base_Depart));
depatModel.DepartCode = depatCode;
depatModel.DepartName = depatCode;
depatModel.DepartLeader = leaderId;
BLL.DepartService.AddDepart(depatModel);
if (!dic.ContainsKey(depatCode.ToUpper()))
{
dic.Add(depatCode.ToUpper(), depatModel.DepartId);
}
return depatModel.DepartId;
}
return result.DepartId;
}
/// <summary>
/// 判断是否存在BU
/// </summary>
/// <returns></returns>
private static bool IsExistsDepart(Dictionary<string,string> depatDbData, string departCode)
private static bool IsExistsDepart(Dictionary<string, string> depatDbData, string departCode)
{
return depatDbData.ContainsKey(departCode.ToUpper());
}
@@ -258,21 +333,18 @@ namespace BLL.APIService
/// <summary>
/// 插入用户信息
/// </summary>
private static string InsertUserInfo(UserInfo user,string departId)
private static string InsertUserInfo(UserInfo user, string departId)
{
var userModel = new Model.Sys_User();
userModel.UserId = SQLHelper.GetNewID(typeof(Model.Sys_User));
userModel.Account = user.ppsHrOtherEmp.bgdid;
userModel.UserName = user.name;
userModel.ChineseName = user.nameCN;
userModel.Email = user.emailAddress;
userModel.Email = user.ppsHrOtherEmp.eMailAddress;
userModel.DepartId = departId;
userModel.RoleId = "1d5e10a3-8a5c-4c6c-be43-8e439e785781"; //给一个默认roleId;
userModel.Password = Sys_UserService.GetEncryptionPassword(userModel.Account);
if (user.ppsHrOtherEmp.leftEffectiveDate.HasValue)
{
userModel.IsPost = user.ppsHrOtherEmp.leftEffectiveDate.HasValue ? false : true;
}
userModel.IsPost = user.ppsHrOtherEmp.leftEffectiveDate.HasValue ? false : true;
Funs.DB.Sys_User.InsertOnSubmit(userModel);
Funs.DB.SubmitChanges();
return userModel.UserId;
@@ -285,22 +357,34 @@ namespace BLL.APIService
{
//更新6个字段
var updateUser = Funs.DB.Sys_User.FirstOrDefault(e => e.Account == user.ppsHrOtherEmp.bgdid);
updateUser.UserName = user.name;
updateUser.ChineseName = user.nameCN;
updateUser.Email = user.emailAddress;
updateUser.DepartId = departId;
if (user.ppsHrOtherEmp.leftEffectiveDate.HasValue)
if (updateUser != null)
{
updateUser.IsPost = user.ppsHrOtherEmp.leftEffectiveDate.HasValue ? false : true;
updateUser.UserName = user.name;
updateUser.ChineseName = user.nameCN;
updateUser.Email = !string.IsNullOrEmpty(user.ppsHrOtherEmp.eMailAddress) ? user.ppsHrOtherEmp.eMailAddress : updateUser.Email;
if (!string.IsNullOrEmpty(departId))
updateUser.DepartId = departId;
if (user.ppsHrOtherEmp.leftEffectiveDate.HasValue)
{
updateUser.IsPost = user.ppsHrOtherEmp.leftEffectiveDate.HasValue ? false : true;
}
Funs.DB.SubmitChanges();
return updateUser.UserId;
}
Funs.DB.SubmitChanges();
return updateUser.UserId;
return string.Empty;
}
/// <summary>
/// 记录logos日志
/// </summary>
private static void AddSyncLogs(List<Model.SyncDataUserLogs> logs)
{
string sql = "delete from SyncDataUserLogs";
SQLHelper.ExecutSql(sql);
Funs.DB.SyncDataUserLogs.InsertAllOnSubmit(logs);
Funs.DB.SubmitChanges();
}
@@ -371,7 +455,7 @@ namespace BLL.APIService
public string sappersonnelNumber { get; set; }
}
internal class ppsHrCertificateList
{
public long id { get; set; }
@@ -391,7 +475,8 @@ namespace BLL.APIService
public string bycstaffNo { get; set; }
}
internal class ppsHrTrainingList {
internal class ppsHrTrainingList
{
public long id { get; set; }
public string courseName { get; set; }
@@ -401,11 +486,11 @@ namespace BLL.APIService
}
[Serializable]
internal class ResultData<T>:ResultData
internal class ResultData<T> : ResultData
{
public new T data { get; set; }
public ResultData<T> SetResult(string code,T resultData,string message=null)
public ResultData<T> SetResult(string code, T resultData, string message = null)
{
this.code = code;
this.data = resultData;
@@ -415,7 +500,7 @@ namespace BLL.APIService
[Serializable]
internal class ResultData
{
public ResultData SetResult(string code,object data,string msg = null)
public ResultData SetResult(string code, object data, string msg = null)
{
this.code = code;
this.msg = msg;