/// <summary> /// 将id部门下的人员转到parentid部门下 /// </summary> /// <param name="id"></param> /// <param name="parentid"></param> private static void DepartmentUserMove(string id, int parentid) { GetDepartmentList DepartmentList = DepartmentBll.GetList(); var dddd = DepartmentList.department.Where(e => e.id.Equals(id)).ToList().FirstOrDefault(); if (dddd != null) { //钉钉中存在该部门,检查该部门下是否有人,没人的并且重复的部门删除钉钉中该部门,并且删除钉钉关系表和钉钉树关系表 GetDepartmentForUserList UserList = DepartmentBll.GetByDepartmentIdForUserInfoList(dddd.id); Console.Write("\n" + dddd.name + " DD_ID=" + dddd.id + ",其下共有" + UserList.userlist.Count + "个人!\r\n"); foreach (var Useritem in UserList.userlist) { string EmployeeJson = EmployeeForDingTalkBll.GetEmployee(Useritem.userid); EmployeeEntity Emodel = JsonHelper.JsonToModel <EmployeeEntity>(EmployeeJson); Emodel.department = new List <int>() { parentid }; string param = Emodel.ToJson(); Result uResult = EmployeeBll.Update(param); if (uResult.errcode != "0") { Console.Write("\r\n" + uResult.errmsg + "\r\n"); } } } }
private static void OperationRepeatData3() { GetDepartmentList DepartmentList = DepartmentBll.GetList(); string sql = @" with ta as( select * from DepartmentResult where ESB_DepartmentID in( select ESB_DepartmentID from DepartmentResult group by ESB_DepartmentID having count(1)>1 ) ),tb as( select a.* from [PM.WebApi].dbo.V_Effective_Tbiz_DepartmentInfo a inner join [PM.WebApi].dbo.V_Effective_Tbiz_DepartmentTreeas b on a.DepartmentId=b.TreeNode ),tc as( select tb.fullname a,ta.* from ta left join tb on ta.ESB_DepartmentName=tb.FullName where tb.fullname is null ),td as( select a.* from [PM.WebApi].dbo.V_Effective_Tbiz_DepartmentInfo a inner join tc on tc.ESB_DepartmentId=a.DepartmentId ) select distinct td.fullname aa,tc.* from tc right join td on tc.ESB_DepartmentId=td.DepartmentId order by td.fullname "; string sql2 = @" with ta as( select * from DepartmentResult where ESB_DepartmentID in( select ESB_DepartmentID from DepartmentResult group by ESB_DepartmentID having count(1)>1 ) ),tb as( select a.* from [PM.WebApi].dbo.V_Effective_Tbiz_DepartmentInfo a inner join [PM.WebApi].dbo.V_Effective_Tbiz_DepartmentTreeas b on a.DepartmentId=b.TreeNode ),tc as( select tb.fullname a,ta.* from ta left join tb on ta.ESB_DepartmentName=tb.FullName where tb.fullname is null ),td as( select a.* from [PM.WebApi].dbo.V_Effective_Tbiz_DepartmentInfo a inner join tc on tc.ESB_DepartmentId=a.DepartmentId ),te as( select a.* from td inner join DepartmentResult a on td.DepartmentID=a.ESB_DepartmentID and td.FullName=a.ESB_DepartmentName )select '' aa,'' a ,* from te order by ESB_DepartmentID "; SqlSugarClient Ddb = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.DingTalkConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true, InitKeyType = InitKeyType.Attribute }); List <DepartmentResult> list = Ddb.Ado.SqlQuery <DepartmentResult>(sql); List <DepartmentResult> list2 = Ddb.Ado.SqlQuery <DepartmentResult>(sql2); foreach (var item in list) { var dddd = DepartmentList.department.Where(e => e.id.Equals(item.id)).ToList().FirstOrDefault(); if (dddd != null) { //钉钉中存在该部门,检查该部门下是否有人,没人的并且重复的部门删除钉钉中该部门,并且删除钉钉关系表和钉钉树关系表 GetDepartmentForUserList UserList = DepartmentBll.GetByDepartmentIdForUserInfoList(dddd.id); Console.Write("\n" + dddd.name + " DD_ID=" + dddd.id + ",其下共有" + UserList.userlist.Count + "个人!\r\n"); string id = list2.Where(it => it.ESB_DepartmentID.Equals(item.ESB_DepartmentID)).FirstOrDefault().id; if (UserList.userlist.Count != 0) { //将该部门下的人迁移到正确的部门下 foreach (var Useritem in UserList.userlist) { string EmployeeJson = EmployeeForDingTalkBll.GetEmployee(Useritem.userid); EmployeeEntity Emodel = JsonHelper.JsonToModel <EmployeeEntity>(EmployeeJson); Emodel.department = new List <int>() { Convert.ToInt32(id) }; string param = Emodel.ToJson(); Result uResult = EmployeeBll.Update(param); if (uResult.errcode != "0") { Console.Write("\r\n" + uResult.errmsg + "\r\n"); } } //删除钉钉中的部门 var a = DepartmentBll.Delete(dddd.id); //删除钉钉关系表和钉钉树关系表 int i = Ddb.Deleteable <DepartmentResult>().Where(it => it.id.Equals(item.id)).ExecuteCommand(); i = Ddb.Deleteable <DepartmentTrees>().Where(it => it.DD_Id.Equals(item.id)).ExecuteCommand(); } } } Console.Write("\r\n处理完毕"); }
public ResponseModel Post(string signature, string timestamp, string nonce, [FromBody] RequestModel model) { ResponseModel result = new ResponseModel(); var Ddb = DBHelper.Ddb; var Edb = DBHelper.Edb; _log.Info("请求参数为: signature=" + signature + "×tamp=" + timestamp + "&nonce=" + nonce + ", FromBody=" + JsonHelper.JsonSerializer(model) + "\n"); DingTalkCrypt dingTalkCrypt = new DingTalkCrypt(JsonConfigurationHelper.GetAppSettings("DingTalkSettings", "CallBack_Token"), JsonConfigurationHelper.GetAppSettings("DingTalkSettings", "CallBack_SuiteKey"), JsonConfigurationHelper.GetAppSettings("DingTalkSettings", "CorpID")); int decryptMsgcount = 1; int encryptMsgCount = 1; string dd_result = ""; string sEncryptMsg = ""; string msg_signature = ""; decryptMsgcount = dingTalkCrypt.DecryptMsg(signature, timestamp, nonce, model.encrypt, ref dd_result); result.timeStamp = timestamp; result.nonce = nonce; try { if (decryptMsgcount == 0) { ContactsEventModel contactsEventModel = JsonConvert.DeserializeObject <ContactsEventModel>(dd_result); if (contactsEventModel.EventType == "check_url") { encryptMsgCount = dingTalkCrypt.EncryptMsg("success", timestamp, nonce, ref sEncryptMsg, ref msg_signature); result.encrypt = sEncryptMsg; result.msg_signature = msg_signature; _log.Error(JsonConvert.SerializeObject(result)); return(result); } List <DingTalkCallBackLog> LogList = new List <DingTalkCallBackLog>(); int sqlExeCount = 0; if (contactsEventModel.UserId != null) { foreach (var item in contactsEventModel.UserId) { DingTalkCallBackLog log = new DingTalkCallBackLog { UserId = item, EventType = contactsEventModel.EventType, TimeStamp = contactsEventModel.TimeStamp }; LogList.Add(log); } if (LogList.Count > 0) { sqlExeCount = Ddb.Insertable(LogList).ExecuteCommand(); } if (sqlExeCount > 0) { encryptMsgCount = dingTalkCrypt.EncryptMsg("success", timestamp, nonce, ref sEncryptMsg, ref msg_signature); if (encryptMsgCount == 0) { List <DingTalkCallBackOperation> userList = new List <DingTalkCallBackOperation>(); //日志记录成功后,根据钉钉回调的员工,检查hr中该员工状态为在职的人员 var user = Edb.Queryable <V_EmployeeToDingTalk>().Where(it => contactsEventModel.UserId.Contains(it.UserId) && it.Enabled == 1).ToList(); foreach (var item in user) { //将员工为在职的人员重新添加到钉钉中 bool b = EmployeeForDingTalkBll.AddEmployee(Edb, Ddb, item); DingTalkCallBackOperation DD_User = new DingTalkCallBackOperation(); DD_User.EventType = contactsEventModel.EventType; DD_User.TimeStamp = contactsEventModel.TimeStamp; DD_User.UserId = item.UserId; DD_User.CreateDate = DateTime.Now; if (b) { DD_User.IsOperation = 1; } userList.Add(DD_User); } if (userList.Count > 0) { sqlExeCount = Ddb.Insertable(userList).ExecuteCommand(); _log.Debug(sqlExeCount + "条数据执行成功\n"); } result.encrypt = sEncryptMsg; result.msg_signature = msg_signature; } else { _log.Error("将消息加密,返回加密后字符串失败,返回加密前的参数为:" + dd_result + ",返回编码为: " + encryptMsgCount + "\n"); } } } else { _log.Error("钉钉传递的UserList为空,返回解密前的参数为:" + JsonHelper.JsonSerializer(model) + ",返回编码为: " + decryptMsgcount + "\n"); } } else { _log.Error("回调失败,请求参数为: signature = " + signature + " & timestamp = " + timestamp + " & nonce = " + nonce + ", FromBody = " + JsonHelper.JsonSerializer(model) + "\n错误详情如下:\n"); } } catch (Exception ex) { _log.Error("回调失败,请求参数为: signature = " + signature + " & timestamp = " + timestamp + " & nonce = " + nonce + ", FromBody = " + JsonHelper.JsonSerializer(model) + "\n错误详情如下:\n" + ex); } return(result); }