public static void DeleteForDingTalk(SqlSugarClient Ddb, List <V_EmployeeToDingTalk> EmpList, V_EmployeeToDingTalk item) { LogHelper log = LogFactory.GetLogger("InsertEmployeeForDingTalk"); Result Result = EmployeeBll.Delete(item.UserId); if (Result != null) { if (Result.errcode == "0") { EmpList.Add(item); //Console.Write("删除成功," + Result.errmsg + "\r\n"); } else { log.Error("\r\n EmployeeForDingTalkBll-DeleteForDingTalk() " + Result.errmsg + "; UserId=" + item.UserId); //Console.Write("\r\n" + Result.errmsg + "; UserId=" + item.UserId); } } else { //Console.Write("无返回数据"); } }
public static void AddEmployee(SqlSugarClient Edb, SqlSugarClient Ddb, V_EmployeeToDingTalk item) { LogHelper log = LogFactory.GetLogger("AddEmployee"); try { EmployeeEntity model = new EmployeeEntity(); string DD_DepartmentId = "1"; if (!item.ESB_DepartmentId.Equals("1000000001")) { try { DepartmentResult DD_DepModel = Ddb.Queryable <DepartmentResult>().With(SqlWith.NoLock).Where(it => it.ESB_DepartmentID.Equals(item.ESB_DepartmentId)).First(); if (DD_DepModel == null) { DD_DepartmentId = DepartmentForDingTalkBll.DD_DepartmentIsNullForDingTalk(Edb, Ddb, item.ESB_DepartmentId); } else { DD_DepartmentId = DD_DepModel.id; } } catch { DD_DepartmentId = "1"; } } model.userid = item.UserId; model.name = item.Name; model.department = new List <int>(new int[] { Convert.ToInt32(DD_DepartmentId) }); model.position = item.PositionName; model.mobile = item.Mobile; model.tel = item.Telephone; model.workPlace = ""; model.remark = ""; model.email = item.Email; model.jobnumber = item.UserId; model.isSenior = false; string param = model.ToJson(); EmployeeResult Result = EmployeeBll.Create(param); if (Result != null) { if (Result.errcode == "0") { //Console.Write("创建成功,UserId=" + Result.userid); } //该外部联系人已存在 || 手机号码在公司中已存在 else if (Result.errcode == "40026" || Result.errcode == "60104") { string res = EmployeeBll.Delete(model.userid).errcode; if (res != "0") { log.Error("\r\n EmployeeForDingTalkBll-AddEmployee() 手机号码在公司中已存在删除时报错,错误编号:" + res); } EmployeeResult Result2 = EmployeeBll.Create(model.ToJson()); if (Result2.errcode != "0") { if (Result2.errcode == "40022") { string Deletecode = EmployeeBll.Delete(model.userid).errcode; string Createcode = EmployeeBll.Create(model.ToJson()).errcode; if (Createcode != "0") { Createcode = EmployeeBll.Create(model.ToJson()).errcode; if (Createcode != "0" && Createcode != "40021") { log.Error("\r\n AddEmployee - 行号507 成功删除员工信息,但是创建员工信息时报错,错误编码如下:" + Createcode); } } //手机号码在公司中已存在 if (Result2.errcode == "60104") { log.Debug("\r\n EmployeeForDingTalkBll-AddEmployee() 手机号码在公司中已存在 时报错,信息如下" + Result2.errmsg + ",错误编码为:" + Result2.errcode + ", Json参数为:" + param); } else { log.Error("\r\n EmployeeForDingTalkBll-AddEmployee() 该外部联系人已存在 || 手机号码在公司中已存在 时报错,信息如下"+ Result2.errmsg + ",错误编码为:" + Result2.errcode + ", Json参数为:" + param); } Task.Factory.StartNew(() => { InsertErroUpdateEmployee(Ddb, model.userid, "", item.Mobile, Result.errcode); if (Deletecode != "0") { InsertErroUpdateEmployee(Ddb, model.userid, "", item.Mobile, "新增用户时,删除失败,错误编号:" + Deletecode); } if (Createcode != "0") { InsertErroUpdateEmployee(Ddb, model.userid, "", item.Mobile, "新增用户时,执行删除后创建失败,错误编号:" + Createcode); } }); } } } else { if (Result.errcode == "60103") { log.Debug("\r\n EmployeeForDingTalkBll-AddEmployee() " + Result.errmsg + ",错误编码为:" + Result.errcode + ",手机号为" + item.Mobile + ",用户id为" + item.UserId + " Json参数为:" + param); } else { log.Error("\r\n EmployeeForDingTalkBll-AddEmployee() " + Result.errmsg + ",错误编码为:" + Result.errcode); } Task.Factory.StartNew(() => { InsertErroUpdateEmployee(Ddb, model.userid, "", item.Mobile, "新增用户时创建失败,错误编号:" + Result.errcode); }); } } else { //Console.Write("无返回数据"); } } catch (Exception ex) { log.Error("\r\n EmployeeForDingTalkBll-AddEmployee() " + ex + "\r\n"); //Console.Write(ex.Message); } }
public static void InsertForDingTalk(SqlSugarClient Edb, SqlSugarClient Ddb, List <V_EmployeeToDingTalk> EmpList, V_EmployeeToDingTalk item) { LogHelper log = LogFactory.GetLogger("InsertEmployeeForDingTalk"); string DD_DepartmentId = "1"; if (!item.ESB_DepartmentId.Equals("1000000001")) { DepartmentResult DD_DepModel = Ddb.Queryable <DepartmentResult>().With(SqlWith.NoLock).Where(it => it.ESB_DepartmentID.Equals(item.ESB_DepartmentId)).First(); if (DD_DepModel == null) { DD_DepartmentId = DepartmentForDingTalkBll.DD_DepartmentIsNullForDingTalk(Edb, Ddb, item.ESB_DepartmentId); } else { DD_DepartmentId = DD_DepModel.id; } try { DD_DepartmentId = Ddb.Queryable <DepartmentResult>().With(SqlWith.NoLock).Where(it => it.ESB_DepartmentID.Equals(item.ESB_DepartmentId)).First().id; } catch (Exception ex) { Console.Write("根据ESB_DepartmentId获取对应的钉钉id时报错,该ID为" + item.ESB_DepartmentId + ",错误信息为:" + ex + "\r\n"); } } EmployeeEntity model = new EmployeeEntity(); model.userid = item.UserId; model.name = item.Name; model.department = new List <int>(new int[] { Convert.ToInt32(DD_DepartmentId) }); model.position = item.PositionName; model.mobile = item.Mobile; model.tel = item.Telephone; model.workPlace = ""; model.remark = ""; model.email = item.Email; model.jobnumber = item.UserId; model.isSenior = false; string param = model.ToJson(); EmployeeResult Result = EmployeeBll.Create(param); if (Result != null) { if (Result.errcode == "0") { EmpList.Add(item); //Console.Write("创建成功,UserId=" + Result.userid + "\r\n"); } else { //UserID在公司中已存在 if (Result.errcode == "60102") { string EmployeeJson = GetEmployee(item.UserId); model = Newtonsoft.Json.JsonConvert.DeserializeObject <EmployeeEntity>(EmployeeJson); model.userid = item.UserId; model.name = item.Name; model.department = new List <int>(new int[] { Convert.ToInt32(DD_DepartmentId) }); model.position = item.PositionName; model.mobile = item.Mobile; model.tel = item.Telephone; model.email = item.Email; model.jobnumber = item.UserId; param = model.ToJson(); Result res = EmployeeBll.Update(param); if (res != null) { if (res.errcode == "0") { EmpList.Add(item); //Console.Write("更新成功," + Result.errmsg); } else { log.Error("\r\n EmployeeForDingTalkBll-InsertForDingTalk() " + Result.errmsg + "; UserId=" + item.UserId); //Console.Write("\r\n" + Result.errmsg + "; UserId=" + item.UserId); } } else { //Console.Write("无返回数据"); } } else { if (Result.errcode == "60104") { log.Error("\r\n EmployeeForDingTalkBll-InsertForDingTalk() " + Result.errmsg + "; UserId=" + item.UserId); } else if (Result.errcode == "40026") { //该外部联系人已存在 AddEmployee(Edb, Ddb, item); EmpList.Add(item); } else { log.Error("\r\n EmployeeForDingTalkBll-InsertForDingTalk() " + Result.errmsg + "; UserId=" + item.UserId); } //Console.Write("\r\n" + Result.errmsg + "; UserId=" + item.UserId); } } } else { //Console.Write("无返回数据"); } }