//同步关注状态 public void TBGZSTATUS(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo) { try { JH_Auth_Branch branchModel = new JH_Auth_BranchB().GetEntity(d => d.DeptRoot == -1 && d.ComId == UserInfo.User.ComId); #region 步用户关注状态 WXHelp wx = new WXHelp(UserInfo.QYinfo); GetDepartmentMemberInfoResult yg = wx.WX_GetDepartmentMemberInfo(branchModel.WXBMCode.Value); if (yg != null && yg.userlist != null) { foreach (var u in yg.userlist) { JH_Auth_User user = new JH_Auth_UserB().GetEntity(d => d.ComId == UserInfo.User.ComId && d.UserName == u.userid); if (user != null && u != null && (u.status == 1 || u.status == 4)) { user.isgz = u.status.ToString(); new JH_Auth_UserB().Update(user); } } } } catch (Exception ex) { msg.ErrorMsg = ex.Message; } #endregion }
/// <summary> /// 同步通讯录 /// </summary> /// <param name="context"></param> /// <param name="msg"></param> /// <param name="P1">初始化密码</param> /// <param name="P2"></param> /// <param name="UserInfo"></param> #region 企业号相关 /// <summary> /// 将系统的组织架构同步到微信中去 /// </summary> /// <param name="context"></param> /// <param name="msg"></param> /// <param name="P1"></param> /// <param name="P2"></param> /// <param name="UserInfo"></param> public void TBBRANCHUSER(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo) { //判断是否启用微信后,启用部门需要同步添加微信部门 if (UserInfo.QYinfo.IsUseWX == "Y") { #region 步部门 //系统部门 List <JH_Auth_Branch> branchList = new JH_Auth_BranchB().GetEntities(d => d.ComId == UserInfo.User.ComId && d.WXBMCode == null).ToList(); WXHelp wx = new WXHelp(UserInfo.QYinfo); //微信部门 GetDepartmentListResult bmlist = wx.WX_GetBranchList(""); foreach (JH_Auth_Branch branch in branchList) { List <DepartmentList> departList = bmlist.department.Where(d => d.name == branch.DeptName).ToList(); WorkJsonResult result = null; if (departList.Count() > 0) { branch.WXBMCode = int.Parse(departList[0].id.ToString()); result = wx.WX_UpdateBranch(branch); } else { int branchWxCode = int.Parse(wx.WX_CreateBranchTB(branch).ToString()); branch.WXBMCode = branchWxCode; } new JH_Auth_BranchB().Update(branch); } #endregion #region 步人员 JH_Auth_Branch branchModel = new JH_Auth_BranchB().GetEntity(d => d.DeptRoot == -1 && d.ComId == UserInfo.User.ComId); GetDepartmentMemberInfoResult yg = wx.WX_GetDepartmentMemberInfo(branchModel.WXBMCode.Value); List <JH_Auth_User> userList = new JH_Auth_UserB().GetEntities(d => d.ComId == UserInfo.User.ComId && d.UserName != "administrator").ToList(); foreach (JH_Auth_User user in userList) { if (yg.userlist.Where(d => d.name == user.UserName || d.mobile == user.mobphone).Count() > 0) { wx.WX_UpdateUser(user); } else { wx.WX_CreateUser(user); } } #endregion } }
/// <summary> /// 从企业微信同步到系统里 /// </summary> /// <param name="context"></param> /// <param name="msg"></param> /// <param name="P1"></param> /// <param name="P2"></param> /// <param name="UserInfo"></param> public void TBTXL(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo) { try { int bmcount = 0; int rycount = 0; if (P1 == "") { msg.ErrorMsg = "请输入初始密码"; return; } WXHelp wx = new WXHelp(UserInfo.QYinfo); #region 更新部门 GetDepartmentListResult bmlist = wx.WX_GetBranchList(""); foreach (var wxbm in bmlist.department.OrderBy(d => d.parentid)) { var bm = new JH_Auth_BranchB().GetEntity(p => p.ComId == UserInfo.User.ComId && p.WXBMCode == wxbm.id); if (bm == null) { #region 新增部门 JH_Auth_Branch jab = new JH_Auth_Branch(); jab.WXBMCode = int.Parse(wxbm.id.ToString()); jab.ComId = UserInfo.User.ComId; jab.DeptName = wxbm.name; jab.DeptDesc = wxbm.name; jab.DeptShort = int.Parse(wxbm.order.ToString()); if (wxbm.parentid == 0)//如果是跟部门,设置其跟部门为-1 { jab.DeptRoot = -1; } else { var bm1 = new JH_Auth_BranchB().GetEntity(p => p.ComId == UserInfo.User.ComId && p.WXBMCode == wxbm.parentid); jab.DeptRoot = bm1.DeptCode; jab.Remark1 = new JH_Auth_BranchB().GetBranchNo(UserInfo.User.ComId.Value, jab.DeptRoot); } new JH_Auth_BranchB().Insert(jab); jab.Remark1 = new JH_Auth_BranchB().GetBranchNo(UserInfo.User.ComId.Value, jab.DeptRoot) + jab.DeptCode; new JH_Auth_BranchB().Update(jab); bmcount = bmcount + 1; #endregion } else { //同步部门时放弃更新现有部门 } } #endregion #region 更新人员 JH_Auth_Branch branchModel = new JH_Auth_BranchB().GetEntity(d => d.DeptRoot == -1 && d.ComId == UserInfo.User.ComId); GetDepartmentMemberInfoResult yg = wx.WX_GetDepartmentMemberInfo(branchModel.WXBMCode.Value); foreach (var u in yg.userlist) { var user = new JH_Auth_UserB().GetUserByUserName(UserInfo.QYinfo.ComId, u.userid); if (user == null) { #region 新增人员 JH_Auth_User jau = new JH_Auth_User(); jau.ComId = UserInfo.User.ComId; jau.UserName = u.userid; jau.UserPass = CommonHelp.GetMD5(P1); jau.UserRealName = u.name; jau.Sex = u.gender == 1 ? "男" : "女"; if (u.department.Length > 0) { int id = int.Parse(u.department[0].ToString()); var bm1 = new JH_Auth_BranchB().GetEntity(p => p.ComId == UserInfo.User.ComId && p.WXBMCode == id); jau.BranchCode = bm1.DeptCode; jau.remark = bm1.Remark1.Split('-')[0];//用户得部门路径 } jau.mailbox = u.email; jau.mobphone = u.mobile; jau.zhiwu = string.IsNullOrEmpty(u.position) ? "员工" : u.position; jau.IsUse = "Y"; if (u.status == 1 || u.status == 4) { jau.isgz = u.status.ToString(); } jau.txurl = u.avatar; new JH_Auth_UserB().Insert(jau); rycount = rycount + 1; #endregion //为所有人增加普通员工的权限 JH_Auth_Role rdefault = new JH_Auth_RoleB().GetEntity(p => p.ComId == UserInfo.User.ComId && p.isSysRole == "Y" && p.RoleName == "员工");//找到默认角色 if (rdefault != null) { JH_Auth_UserRole jaurdefault = new JH_Auth_UserRole(); jaurdefault.ComId = UserInfo.User.ComId; jaurdefault.RoleCode = rdefault.RoleCode; jaurdefault.UserName = jau.UserName; new JH_Auth_UserRoleB().Insert(jaurdefault); } } else { //同步人员时放弃更新现有人员 #region 更新人员 user.UserRealName = u.name; if (u.department.Length > 0) { int id = int.Parse(u.department[0].ToString()); var bm1 = new JH_Auth_BranchB().GetEntity(p => p.ComId == UserInfo.User.ComId && p.WXBMCode == id); user.BranchCode = bm1.DeptCode; } user.mailbox = u.email; user.mobphone = u.mobile; user.zhiwu = string.IsNullOrEmpty(u.position) ? "员工" : u.position; user.Sex = u.gender == 1 ? "男" : "女"; if (u.status == 1 || u.status == 4) { user.IsUse = "Y"; user.isgz = u.status.ToString(); } else if (u.status == 2) { user.IsUse = "N"; } user.txurl = u.avatar; new JH_Auth_UserB().Update(user); #endregion } #region 更新角色(职务) if (!string.IsNullOrEmpty(u.position)) { var r = new JH_Auth_RoleB().GetEntity(p => p.ComId == UserInfo.User.ComId && p.RoleName == u.position); if (r == null) { JH_Auth_Role jar = new JH_Auth_Role(); jar.ComId = UserInfo.User.ComId; jar.RoleName = u.position; jar.RoleDec = u.position; jar.PRoleCode = 0; jar.isSysRole = "N"; jar.IsUse = "Y"; jar.leve = 0; jar.DisplayOrder = 0; new JH_Auth_RoleB().Insert(jar); JH_Auth_UserRole jaur = new JH_Auth_UserRole(); jaur.ComId = UserInfo.User.ComId; jaur.RoleCode = jar.RoleCode; jaur.UserName = u.userid; new JH_Auth_UserRoleB().Insert(jaur); } else { } } #endregion } #endregion msg.Result1 = bmcount; msg.Result2 = rycount; } catch (Exception ex) { msg.ErrorMsg = ex.ToString(); } }