111
This commit is contained in:
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BLL.APIService
|
||||
{
|
||||
public class SyncUserInfoService
|
||||
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";
|
||||
@@ -28,25 +28,29 @@ namespace BLL.APIService
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
if (item.ppsHrOtherEmp==null || string.IsNullOrEmpty(item.ppsHrOtherEmp.bgdid))
|
||||
if (item.ppsHrOtherEmp == null || string.IsNullOrEmpty(item.ppsHrOtherEmp.bgdid))
|
||||
{
|
||||
Model.SyncDataUserLogs log3 = new Model.SyncDataUserLogs();
|
||||
log3.BatchNo = batchNo;
|
||||
@@ -87,7 +91,7 @@ namespace BLL.APIService
|
||||
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"))
|
||||
else if ((item.section.ToUpper() == "CTT" && item.position.Contains("Manager")) || item.section.ToUpper() == "CTT" && item.position.Contains("General Manager"))
|
||||
{
|
||||
//不处理
|
||||
//判断是否存在部门
|
||||
@@ -107,11 +111,16 @@ namespace BLL.APIService
|
||||
if (IsExistsDepart(dic, item.section))
|
||||
{
|
||||
departId = dic[item.section]; //取出本地数据库部门ID
|
||||
UpdateDepartInfo(userId, item.section); //更新部门表数据
|
||||
|
||||
//eftEffectiveDate有值说明此人已离职
|
||||
if (!item.ppsHrOtherEmp.leftEffectiveDate.HasValue)
|
||||
{
|
||||
UpdateDepartInfo(userId, item.section); //更新部门表数据
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
departId = InsertDepartInfo(dic,userId, item.section); //插入本地数据库部门
|
||||
departId = InsertDepartInfo(dic, userId, item.section); //插入本地数据库部门
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -127,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(dic,itemUserId, itemDepartCode); //插入本地部门表数据
|
||||
departId = InsertDepartInfo(dic, itemUserId, itemDepartCode); //插入本地部门表数据
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -149,17 +161,19 @@ 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);
|
||||
departId = InsertDepartInfoChilds(dic, parentUserId, item.section);
|
||||
}
|
||||
else
|
||||
{
|
||||
departId = InsertDepartInfo(dic,parentUserId, parentDepatCode); //插入他上级用户所在的部门到部门表中去
|
||||
departId = InsertDepartInfo(dic, parentUserId, parentDepatCode); //插入他上级用户所在的部门到部门表中去
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
log.DepatId = departId;
|
||||
@@ -181,7 +195,7 @@ namespace BLL.APIService
|
||||
#region 同步用户
|
||||
Model.SyncDataUserLogs log2 = new Model.SyncDataUserLogs();
|
||||
string resultId = string.Empty;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
log2.BatchNo = batchNo;
|
||||
@@ -197,7 +211,7 @@ namespace BLL.APIService
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
resultId = UpdateUserInfo(item, departId);
|
||||
log.UserId = resultId;
|
||||
log.DataType = 1; //同步用户类型数据
|
||||
@@ -209,13 +223,13 @@ namespace BLL.APIService
|
||||
{
|
||||
log.UserId = resultId;
|
||||
log.DataType = 1;
|
||||
log2.Remark =$"同步失败:{ex.Message}";
|
||||
log2.Remark = $"同步失败:{ex.Message}";
|
||||
log2.IsSuccess = false;
|
||||
}
|
||||
//这里记录同步用户的日志
|
||||
logList.Add(log2);
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -227,6 +241,205 @@ namespace BLL.APIService
|
||||
}
|
||||
}
|
||||
|
||||
//public static void GetSyncUserInfo1()
|
||||
//{
|
||||
// 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);
|
||||
// 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}");
|
||||
// var userInfo = data.data;
|
||||
// string batchNo= DateTime.Now.ToString("yyyyMMddHHmmss");
|
||||
// DateTime syncTime = DateTime.Now;
|
||||
// foreach (var item in userInfo)
|
||||
// {
|
||||
// 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.DepatId = string.Empty;
|
||||
// log3.UserId = string.Empty;
|
||||
// log3.IsSuccess = false;
|
||||
// log3.Remark = $"当前账号为空:{JsonHelper.SerializeObject(item)}";
|
||||
// logList.Add(log3);
|
||||
// continue;
|
||||
// }
|
||||
// var account = item.ppsHrOtherEmp.bgdid;// 当前json的账号
|
||||
// var manager = item.ppsHrOtherEmp.manager; //当前经理的员工号
|
||||
// account = account.ToLower();
|
||||
// var user = dicUser.ContainsKey(account); //判断当前账号是否在我们数据库中
|
||||
// string userId = user ? dicUser[account] : null; //存在那就是把用户id取出来,否则用户id就是null
|
||||
|
||||
// #region 同步部门
|
||||
// //部门id
|
||||
// string departId = "";
|
||||
// Model.SyncDataUserLogs log = new Model.SyncDataUserLogs();
|
||||
// try
|
||||
// {
|
||||
// log.BatchNo = batchNo;
|
||||
// log.CreatedTime = syncTime;
|
||||
// //如果是经理,总经理,总监
|
||||
// if (item.section.ToUpper() == "CTT" && item.position.Contains("Director"))
|
||||
// {
|
||||
// //判断是否存在部门
|
||||
// if (IsExistsDepart(dic, item.section))
|
||||
// {
|
||||
// departId = dic[item.section]; //取出本地数据库部门ID
|
||||
// UpdateDepartInfo(userId, item.section); //更新部门表数据
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// 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
|
||||
// UpdateDepartInfo(userId, item.section); //更新部门表数据
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// departId = InsertDepartInfo(dic,userId, item.section); //插入本地数据库部门
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //查找当前用户的上级经理是谁
|
||||
// var parentUser = userInfo.Where(t => t.ppsHrOtherEmp.bycstaffNo == manager).FirstOrDefault();
|
||||
// if (parentUser == null)
|
||||
// {
|
||||
// //找不到就是他自己
|
||||
// string itemDepartCode = item.section.ToUpper();
|
||||
// string itemUserId = userId;
|
||||
// //判断当前自身的部门是否存在
|
||||
// if (IsExistsDepart(dic, itemDepartCode))
|
||||
// {
|
||||
// departId = dic[itemDepartCode]; //取出自身部门所在的部门ID
|
||||
// UpdateDepartInfo(itemUserId, itemDepartCode); //更新自身部门的部门数据。
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// departId = InsertDepartInfo(dic,itemUserId, itemDepartCode); //插入本地部门表数据
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //找到了就是上级的用户部门+LeaderID;
|
||||
// string parentDepatCode = parentUser.section.ToUpper(); //上级部门编号
|
||||
// string parentAccount = parentUser.ppsHrOtherEmp.bgdid; //上级用户的账号
|
||||
// if (!string.IsNullOrEmpty(parentAccount))
|
||||
// parentAccount = parentAccount.ToLower();
|
||||
// else
|
||||
// parentAccount = string.Empty;
|
||||
|
||||
// var parentLocalUser = dicUser.ContainsKey(parentAccount); //查找本地数据库的上级用户是否存在
|
||||
// string parentUserId = parentLocalUser ? dicUser[parentAccount] : null;
|
||||
// //上级用户所在的部门已经存在
|
||||
// if (IsExistsDepart(dic, parentDepatCode))
|
||||
// {
|
||||
// //departId = dic[parentDepatCode]; //取出他上级用户所在的部门ID
|
||||
// UpdateDepartInfo(parentUserId, parentDepatCode); //更新部门信息
|
||||
// //并且插入自己子部门信息
|
||||
// departId=InsertDepartInfoChilds(dic,parentUserId, item.section);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// departId = InsertDepartInfo(dic,parentUserId, parentDepatCode); //插入他上级用户所在的部门到部门表中去
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// log.DepatId = departId;
|
||||
// log.DataType = 0; //同步部门类型数据
|
||||
// log.Remark = "同步成功";
|
||||
// log.IsSuccess = true;
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// log.DepatId = departId;
|
||||
// log.DataType = 0;
|
||||
// log.Remark = ex.Message;
|
||||
// log.IsSuccess = false;
|
||||
// }
|
||||
// //这里记录同步部门的日志
|
||||
// logList.Add(log);
|
||||
// #endregion
|
||||
|
||||
// #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)
|
||||
// {
|
||||
// //插入
|
||||
// resultId = InsertUserInfo(item, departId);
|
||||
// log.UserId = resultId;
|
||||
// log.DataType = 1;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
|
||||
// resultId = UpdateUserInfo(item, departId);
|
||||
// log.UserId = resultId;
|
||||
// log.DataType = 1; //同步用户类型数据
|
||||
// }
|
||||
// log2.Remark = "同步成功";
|
||||
// log2.IsSuccess = true;
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// log.UserId = resultId;
|
||||
// log.DataType = 1;
|
||||
// log2.Remark =$"同步失败:{ex.Message}";
|
||||
// log2.IsSuccess = false;
|
||||
// }
|
||||
// //这里记录同步用户的日志
|
||||
// logList.Add(log2);
|
||||
// #endregion
|
||||
|
||||
|
||||
// }
|
||||
|
||||
// AddSyncLogs(logList);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// ErrLogInfo.WriteLog("请求失败:返回结果:" + result);
|
||||
// }
|
||||
//}
|
||||
|
||||
#region 私有方法
|
||||
/// <summary>
|
||||
/// 获取所有的BU
|
||||
@@ -236,9 +449,7 @@ namespace BLL.APIService
|
||||
{
|
||||
return BLL.Funs.DB.Base_Depart.ToList()
|
||||
.ToDictionary(t => t.DepartCode.ToUpper(), t => t.DepartId);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有的User
|
||||
@@ -309,6 +520,7 @@ namespace BLL.APIService
|
||||
}
|
||||
return result.DepartId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断是否存在BU
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user