public object SyncToolsDepts() { try { DataTable dt = deptBll.GetDataTable(string.Format("select deptid,unitid,keys from BIS_TOOLSDEPT")); foreach (DataRow dr in dt.Rows) { DepartmentEntity dept = deptBll.GetEntity(dr[0].ToString()); if (dept != null) { SstmsService.CheckHeader header = new SstmsService.CheckHeader(); header.Key = dr[2].ToString(); List <SstmsService.DictionaryEntry> dic = new List <SstmsService.DictionaryEntry>(); SstmsService.DictionaryEntry de = new SstmsService.DictionaryEntry(); de.Key = "LaterID"; de.Value = dr[1].ToString(); dic.Add(de); de = new SstmsService.DictionaryEntry(); de.Key = "Identify"; de.Value = ""; dic.Add(de); // 实例化服务对象 SstmsService.DataServiceSoapClient service = new SstmsService.DataServiceSoapClient(); SstmsService.PersonInfo[] data = service.GetPersonsPage(header, dic.ToArray <SstmsService.DictionaryEntry>(), 1, 1000).List; DepartmentEntity org = deptBll.GetEntity(dept.OrganizeId); foreach (SstmsService.PersonInfo per in data) { string unitId = per.OwnerDeptID; string userId = ""; string roleName = "承包商级用户"; string roleId = "c5530ccf-e84e-4df8-8b27-fd8954a9bbe9"; if (dt.Rows.Count > 0) { string nature = dept.Nature; switch (nature) { case "部门": roleName = "部门级用户"; roleId = "6c094cef-cca3-4b41-a71b-6ee5e6b89008"; break; case "专业": roleName = "专业级用户"; roleId = "e3062d59-2484-4046-a420-478886d58656"; break; case "班组": roleName = "班组级用户"; roleId = "d9432a6e-5659-4f04-9c10-251654199714"; break; case "厂级": roleName = "公司级用户"; roleId = "aece6d68-ef8a-4eac-a746-e97f0067fab5"; break; case "省级": roleName = "省级用户"; roleId = "9a834c93-ff60-440e-845d-79b311eeacae"; break; } roleName += ",普通用户"; roleId += ",2a878044-06e9-4fe4-89f0-ba7bd5a1bde6"; UserEntity user = userBll.GetUserByIdCard(per.IdentifyID); if (user == null) { // userId = user.UserId; //} //else //{ user = new UserEntity(); user.UserId = Guid.NewGuid().ToString(); user.Account = per.IdentifyID; userId = user.UserId; // } user.MSN = "1"; user.UserType = "一般工作人员"; user.EnCode = per.TraID; user.Degrees = user.DegreesID = per.Degrees; user.Birthday = per.BirthDay; user.RoleId = roleId; user.RoleName = roleName; user.IdentifyID = per.IdentifyID; user.Gender = per.Sex; user.Nation = per.Nation; user.Email = per.Email; user.EnterTime = per.EntranceDate; user.RealName = per.PersonName; user.Degrees = per.Degrees; user.Native = per.Native; user.DepartureTime = per.LeaveDate; user.Telephone = per.TelPhone; user.IsPresence = per.IsOut == "是" ? "0" : "1"; user.Password = "******"; user.DepartmentId = dept.DepartmentId; user.DepartmentCode = dept.EnCode; user.OrganizeId = dept.OrganizeId; user.OrganizeCode = org.EnCode; user.Craft = per.Category; user.IsEpiboly = roleName.Contains("承包商") || roleName.Contains("分包商") ? "1" : "0"; if (user.ModifyDate != null) { if (per.OperDate > user.ModifyDate) { userBll.SaveForm(userId, user); } } else { userBll.SaveForm(userId, user); } } } } } } Task.Factory.StartNew(() => { string fileName = DateTime.Now.ToString("yyyyMMdd") + ".log"; System.IO.File.AppendAllText(HttpContext.Current.Server.MapPath("~/logs/") + fileName, string.Format("{0}:同步工具箱人员信息成功\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); }); return(new { Code = 1, message = "同步工具箱人员信息成功" }); } catch (Exception ex) { Task.Run(() => { string fileName = DateTime.Now.ToString("yyyyMMdd") + ".log"; System.IO.File.AppendAllText(HttpContext.Current.Server.MapPath("~/logs/") + fileName, string.Format("{0}:{1}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ex.Message)); }); return(new { code = 0, message = ex.Message }); } }
//[WebMethod(Description="新增人员信息")] public string createEmployee(SyncUserInfo userInfo) { try { string str = ReturnCode(0); DataTable table = deptBll.GetDataTable(string.Format("select userid from base_user where upper(account)='{0}'", userInfo.uid.ToUpper())); if (table.Rows.Count > 0) { if (!string.IsNullOrEmpty(userInfo.displayName)) { str = this.updateEmployee(userInfo.uid, userInfo.displayName); } if (str != this.ReturnCode(0)) { return(str); } if (!string.IsNullOrEmpty(userInfo.email)) { str = this.updateEmployeEmail(userInfo.uid, userInfo.email); } if (str != this.ReturnCode(0)) { return(str); } if (!string.IsNullOrEmpty(userInfo.password)) { str = this.updateEmployeePassword(userInfo.uid, userInfo.password); } str = this.enableOrNotEmployee(userInfo, 1); str = this.UpdateAccountType(userInfo.uid.ToUpper()); } else { try { string enCode = new ERCHTMS.Busines.SystemManage.DataItemDetailBLL().GetItemValue("hrdl", "FactoryEncode"); //查询电厂编码 string orgId = ""; //电厂ID string orgCode = ""; //电厂编码 string deptId = ""; //部门Id string deptCode = ""; //部门编码 if (!string.IsNullOrEmpty(enCode)) { DepartmentEntity dept = deptBll.GetEntityByCode(enCode);//获取电厂信息 if (dept != null) { orgId = dept.DepartmentId; orgCode = enCode; //判断是否存在临时人员的部门节点,不存在则新建 DataTable dtDept = deptBll.GetDataTable(string.Format("select DepartmentId,encode from BASE_DEPARTMENT where parentid='{0}' and fullname='临时人员' and Nature='部门'", orgId)); if (dtDept.Rows.Count > 0) { deptId = dtDept.Rows[0][0].ToString(); deptCode = dtDept.Rows[0][1].ToString(); } else { //新建临时人员的部门节点 dept = new DepartmentEntity { FullName = "临时人员", ParentId = orgId, Nature = "部门", Description = "临时人员", IsOrg = 0, Industry = "电力" }; deptBll.SaveForm("", dept); deptId = dept.DepartmentId; deptCode = dept.EnCode; } dtDept.Dispose(); } } //新增的人员直接挂在临时人员的部门节点,后期由电厂管理员手动调整人完善员信息 ERCHTMS.Entity.BaseManage.UserEntity user = new Entity.BaseManage.UserEntity(); user.UserId = Guid.NewGuid().ToString(); user.RealName = userInfo.displayName; user.Account = userInfo.uid; user.Email = userInfo.email; user.Password = userInfo.password; user.DepartmentId = deptId; user.DepartmentCode = deptCode; user.OrganizeCode = orgCode; user.OrganizeId = orgId; user.RoleId = "2a878044-06e9-4fe4-89f0-ba7bd5a1bde6"; user.RoleName = "普通用户"; user.IsPresence = "1"; user.AccountType = "1"; user.Mobile = userInfo.mobile; user.EnCode = userInfo.empno; //user.WeChat = userInfo.deptId; //user.OICQ = userInfo.password; new ERCHTMS.Busines.BaseManage.UserBLL().SaveForm("", user, 1); return(this.ReturnCode(0)); } catch (Exception ex) { LdapDataLog(Newtonsoft.Json.JsonConvert.SerializeObject(ex), 4); return(this.ReturnCode(11)); } } return(str); } catch (Exception ex) { LdapDataLog(Newtonsoft.Json.JsonConvert.SerializeObject(ex), 4); return(this.ReturnCode(10)); } }