public bool Delete(UserQueryForm user) { ISqlMapper mapper = Common.GetMapperFromSession(); UserDao userdao = new UserDao(mapper); User_RoleDao urdao = new User_RoleDao(mapper); UserInfoDao uidao = new UserInfoDao(mapper); UserQueryForm uform = new UserQueryForm { ID = user.ID }; userdao.Delete(uform); UserInfoQueryForm uiform = new UserInfoQueryForm { ID = user.ID, }; uidao.Delete(uiform); User_RoleQueryForm urform = new User_RoleQueryForm { UserID = user.ID, }; urdao.Delete(urform); SOAFramework.Library.WeiXin.WeiXinApi.User.Delete(user.Name); return(true); }
public List <string> Handle(ActivityAuth auth) { ISqlMapper mapper = Common.GetMapperFromSession(); RoleDao roledao = new RoleDao(mapper); User_RoleDao urdao = new User_RoleDao(mapper); List <string> result = new List <string>(); var role = roledao.Query(new RoleQueryForm { ID = auth.Value, IsDeleted = 0 }).FirstOrDefault(); if (role != null) { var userrole = urdao.Query(new User_RoleQueryForm { RoleID = role.ID }); if (userrole != null) { foreach (var ur in userrole) { if (!result.Contains(ur.UserID)) { result.Add(ur.UserID); } } } } return(result); }
public List<string> Handle(ActivityAuth auth) { List<string> result = new List<string>(); ISqlMapper mapper = Common.GetMapperFromSession(); UserBLL bll = new UserBLL(); string userid = bll.GetCurrentUser().User.ID; //string userid = "16"; RoleDao roledao = new RoleDao(mapper); User_RoleDao urdao = new User_RoleDao(mapper); string[] roleids = auth.Value.Split(','); var subroles = roledao.Query(new RoleQueryForm { ParentIDs = roleids.ToList() }); var urs = urdao.Query(new User_RoleQueryForm { UserID = userid }); var roles = subroles.FindAll(t => urs.Exists(p => p.RoleID == t.ID)); if (roles == null || roles.Count == 0) { result.Add(userid); } else { IWorkflowAuthorityHandler handler = new RoleWorkflowAuthorityHandler(); foreach (var role in roles) { if (roleids.Any(t => t == role.ParentID)) { result.AddRange(handler.Handle(new ActivityAuth { Value = role.ParentID, })); } } } return result; }
public UserleaderWorkflowAuthority() { ISqlMapper mapper = Common.GetMapperFromSession(); roledao = new RoleDao(mapper); urdao = new User_RoleDao(mapper); }
public LoginResultForm Login(string username, string password) { LoginResultForm result = new LoginResultForm(); ISqlMapper mapper = MapperHelper.GetMapper(); UserDao userdao = new UserDao(mapper); UserInfoDao userInfoDao = new UserInfoDao(mapper); RoleDao roleDao = new RoleDao(mapper); User_RoleDao urdao = new User_RoleDao(mapper); LogonHistoryDao historyDao = new LogonHistoryDao(mapper); MenuDao menudao = new MenuDao(mapper); Menu_RoleDao mrdao = new Menu_RoleDao(mapper); var user = userdao.Query(new UserQueryForm { Name = username, Password = password }).FirstOrDefault(); if (user != null) { if (user.Enabled == 0) throw new Exception("该用户已被禁用,请联系管理员!"); string token = Guid.NewGuid().ToString().Replace("-", ""); var userinfo = userInfoDao.Query(new UserInfoQueryForm { ID = user.ID }).FirstOrDefault(); var ur = urdao.Query(new User_RoleQueryForm { UserID = user.ID }); List<string> roleidlist = new List<string>(); ur.ForEach(t => { roleidlist.Add(t.RoleID); }); var roles = roleDao.Query(new RoleQueryForm { IDs = roleidlist }); var mrs = mrdao.Query(new Menu_RoleQueryForm { RoleIDs = roleidlist }); var menuids = (from mr in mrs select mr.MenuID).Distinct().ToList(); result.Menu = menudao.Query(new MenuQueryForm { IDs = menuids, Enabled = 1 }); UserEntireInfo u = new UserEntireInfo { User = user, UserInfo = userinfo, Role = roles, }; CacheItem item = new CacheItem(token, u); LogonHistory history = new LogonHistory { LogonTime = DateTime.Now, Token = token, UserID = user.ID, ActiveTime = DateTime.Now, }; historyDao.Add(history); result.User = u; result.token = token; cache.AddItem(item, 1800); //MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "login user:"******",token:" + token }, SOAFramework.Library.CacheEnum.FormMonitor); return result; } else { throw new Exception("用户名或者密码错误!请输入正确的用户名和密码!"); } }
private void button10_Click(object sender, EventArgs e) { UserBLL bll = new UserBLL(); RoleBLL rolebll = new RoleBLL(); User_RoleDao dao = new User_RoleDao(); var urs = dao.Query(new User_RoleQueryForm { UserID = "155f1092db4043a0b9ecd62a60ffc51d" }).ToList(); var roleids = (from ur in urs select ur.RoleID).ToList(); var role = rolebll.Query(new RoleQueryForm { IDs = roleids }).ToList(); var result = rolebll.GetUserSubUserIDs("155f1092db4043a0b9ecd62a60ffc51d"); }
/// <summary> /// 获得角色下的所有用户以及角色子级下的所有角色 /// </summary> /// <param name="roleid"></param> /// <returns></returns> public List <string> GetRoleUserIDs(string roleid) { ISqlMapper mapper = Common.GetMapperFromSession(); User_RoleDao urdao = new User_RoleDao(mapper); var roles = GetAllSubRoles(roleid); var roleids = (from r in roles select r.ID).ToList(); var urs = urdao.Query(new User_RoleQueryForm { RoleIDs = roleids }); return((from u in urs select u.UserID).ToList()); }
public List<string> GetUserIDList(List<ActivityAuth> auth) { var mapper = Common.GetMapperFromSession(); List<string> result = new List<string>(); RoleDao roledao = new RoleDao(mapper); User_RoleDao urdao = new User_RoleDao(mapper); UserBLL userbll = new UserBLL(); foreach (var au in auth) { IWorkflowAuthorityHandler handler = WorkflowAuthorityFactory.CreateHandler(au.Type.ToLower()); result.AddRange(handler.Handle(au)); } return result; }
public List <string> GetUserIDList(List <ActivityAuth> auth) { var mapper = Common.GetMapperFromSession(); List <string> result = new List <string>(); RoleDao roledao = new RoleDao(mapper); User_RoleDao urdao = new User_RoleDao(mapper); UserBLL userbll = new UserBLL(); foreach (var au in auth) { IWorkflowAuthorityHandler handler = WorkflowAuthorityFactory.CreateHandler(au.Type.ToLower()); result.AddRange(handler.Handle(au)); } return(result); }
/// <summary> /// 获得用户角色子级下的所有用户 /// </summary> /// <param name="userid"></param> /// <returns></returns> public List <string> GetUserSubUserIDs(string userid) { UserBLL userbll = new UserBLL(); ISqlMapper mapper = Common.GetMapperFromSession(); User_RoleDao urdao = new User_RoleDao(mapper); RoleDao roledao = new RoleDao(mapper); var urs = urdao.Query(new User_RoleQueryForm { UserID = userid }); List <string> useridlist = new List <string>(); //检查用户的角色有没有全数据权限 var roles = roledao.QueryRoleByUserID(userid); foreach (var role in roles) { if (role.DataAccessType == (int)DataAccesssEnum.All) { return(null); } } useridlist.Add(userid); List <Role> list = new List <Role>(); foreach (var ur in urs) { list.AddRange(GetAllSubRoles(ur.RoleID)); } var roleids = (from r in list select r.ID).ToList(); if (roleids.Count == 0) { return(useridlist); } var users = urdao.Query(new User_RoleQueryForm { RoleIDs = roleids }); useridlist.AddRange((from u in users select u.UserID).ToList()); return(useridlist); }
public string Add(User user, UserInfo ui, List<Role> roles) { ISqlMapper mapper = MapperHelper.GetMapper(); UserDao dao = new UserDao(mapper); UserInfoDao uidao = new UserInfoDao(mapper); User_RoleDao urdao = new User_RoleDao(mapper); string id = dao.Add(user); if (ui != null) { ui.ID = id; uidao.Add(ui); } if (roles != null) { foreach (var role in roles) { urdao.Add(new User_Role { UserID = id, RoleID = role.ID }); } } return id; }
public List <string> Handle(ActivityAuth auth) { List <string> result = new List <string>(); ISqlMapper mapper = Common.GetMapperFromSession(); UserBLL bll = new UserBLL(); string userid = bll.GetCurrentUser().User.ID; //string userid = "16"; RoleDao roledao = new RoleDao(mapper); User_RoleDao urdao = new User_RoleDao(mapper); string[] roleids = auth.Value.Split(','); var subroles = roledao.Query(new RoleQueryForm { ParentIDs = roleids.ToList() }); var urs = urdao.Query(new User_RoleQueryForm { UserID = userid }); var roles = subroles.FindAll(t => urs.Exists(p => p.RoleID == t.ID)); if (roles == null || roles.Count == 0) { result.Add(userid); } else { IWorkflowAuthorityHandler handler = new RoleWorkflowAuthorityHandler(); foreach (var role in roles) { if (roleids.Any(t => t == role.ParentID)) { result.AddRange(handler.Handle(new ActivityAuth { Value = role.ParentID, })); } } } return(result); }
public List<string> Handle(ActivityAuth auth) { ISqlMapper mapper = Common.GetMapperFromSession(); RoleDao roledao = new RoleDao(mapper); User_RoleDao urdao = new User_RoleDao(mapper); List<string> result = new List<string>(); var role = roledao.Query(new RoleQueryForm { ID = auth.Value, IsDeleted = 0 }).FirstOrDefault(); if (role != null) { var userrole = urdao.Query(new User_RoleQueryForm { RoleID = role.ID }); if (userrole != null) { foreach (var ur in userrole) { if (!result.Contains(ur.UserID)) { result.Add(ur.UserID); } } } } return result; }
/// <summary> /// 查询所有用户 /// </summary> /// <returns></returns> public List <FullUser> Query(FullUserQueryForm form) { ISqlMapper mapper = Common.GetMapperFromSession(); FullUserDao dao = new FullUserDao(mapper); User_RoleDao urdao = new User_RoleDao(mapper); RoleDao roledao = new RoleDao(mapper); var userlist = dao.Query(form); var userids = (from u in userlist select u.ID).ToList(); var urs = urdao.Query(new User_RoleQueryForm { UserIDs = userids }); var roleids = (from ur in urs select ur.RoleID).Distinct().ToList(); var roles = roledao.Query(new RoleQueryForm { IDs = roleids }); foreach (var u in userlist) { var ur_temp = urs.FindAll(t => t.UserID == u.ID); var rolelist = (from ur in ur_temp join r in roles on ur.RoleID equals r.ID select r).ToList(); u.RoleList = rolelist; } return(userlist); }
/// <summary> /// 获得用户角色子级下的所有用户 /// </summary> /// <param name="userid"></param> /// <returns></returns> public List<string> GetUserSubUserIDs(string userid) { UserBLL userbll = new UserBLL(); ISqlMapper mapper = MapperHelper.GetMapper(); User_RoleDao urdao = new User_RoleDao(mapper); RoleDao roledao = new RoleDao(mapper); var urs = urdao.Query(new User_RoleQueryForm { UserID = userid }); List<string> useridlist = new List<string>(); //检查用户的角色有没有全数据权限 var roles = roledao.QueryRoleByUserID(userid); foreach (var role in roles) { if (role.DataAccessType == (int)DataAccesssEnum.All) return null; } useridlist.Add(userid); List<Role> list = new List<Role>(); foreach (var ur in urs) { list.AddRange(GetAllSubRoles(ur.RoleID)); } var roleids = (from r in list select r.ID).ToList(); if (roleids.Count == 0) return useridlist; var users = urdao.Query(new User_RoleQueryForm { RoleIDs = roleids }); useridlist.AddRange((from u in users select u.UserID).ToList()); return useridlist; }
public List <InitApprovalResultForm> Query(List <string> projectids, List <string> taskids, string currentuserid) { #region init dao List <InitApprovalResultForm> result = new List <InitApprovalResultForm>(); if (projectids == null || projectids.Count == 0) { return(new List <InitApprovalResultForm>()); } ISqlMapper mapper = Common.GetMapperFromSession(); ProjectDao dao = new ProjectDao(mapper); Customer_ProjectDao cpdao = new Customer_ProjectDao(mapper); Customer_AssetDao cadao = new Customer_AssetDao(mapper); Asset_ProjectDao apdao = new Asset_ProjectDao(mapper); WorkflowDao workflowdao = new WorkflowDao(mapper); ActivityDao activitydao = new ActivityDao(mapper); ApprovalDao appvoraldao = new ApprovalDao(mapper); TaskDao taskdao = new TaskDao(mapper); UserInfoDao uidao = new UserInfoDao(mapper); User_RoleDao urdao = new User_RoleDao(mapper); TrackingChangeOwnerDao tcodao = new TrackingChangeOwnerDao(mapper); TrackingMortgageDao tmdao = new TrackingMortgageDao(mapper); LinkDao linkdao = new LinkDao(mapper); Role_Module_ActionDao rmadao = new Role_Module_ActionDao(mapper); ReturnBackConfirmDao rbcdao = new ReturnBackConfirmDao(mapper); CreditReceiverInfoDao cridao = new CreditReceiverInfoDao(mapper); #endregion #region 查询数据 List <Customer_Project> cps = new List <Customer_Project>(); List <Customer_Asset> cas = new List <Customer_Asset>(); List <Asset_Project> aps = new List <Asset_Project>(); List <Activity> activities = new List <Activity>(); List <Approval> approvals = new List <Approval>(); List <Task> tasks = new List <Task>(); List <TrackingChangeOwner> tco = new List <TrackingChangeOwner>(); List <TrackingMortgage> tm = new List <TrackingMortgage>(); List <string> projectidlist = new List <string>(); List <string> workflowids = new List <string>(); List <CreditReceiverInfo> criList = new List <CreditReceiverInfo>(); List <Link> links = new List <Link>(); List <ReturnBackConfirm> returnBackMoneyInfo = new List <ReturnBackConfirm>(); List <Workflow> workflows = null; List <Project> list = null; var rma = rmadao.Query(new Role_Module_ActionQueryForm { }); if (taskids != null && taskids.Count > 0) { tasks = taskdao.Query(new TaskQueryForm { IDs = taskids }); workflowids = (from t in tasks select t.WorkflowID).Distinct().ToList(); workflows = workflowdao.Query(new WorkflowQueryForm { IDs = workflowids }); activities = activitydao.Query(new ActivityQueryForm { WorkflowIDs = workflowids }); approvals = appvoraldao.Query(new ApprovalQueryForm { WorkflowIDs = workflowids }); projectidlist = (from w in workflows select w.ProcessID).ToList(); list = dao.Query(new ProjectQueryForm { IDs = projectidlist }); } else if (projectids != null && projectids.Count > 0) { list = dao.Query(new ProjectQueryForm { IDs = projectids }); projectidlist = (from p in list select p.ID).ToList(); workflows = workflowdao.Query(new WorkflowQueryForm { ProcessIDs = projectidlist }); workflowids = (from w in workflows select w.ID).ToList(); if (workflowids.Count > 0) { activities = activitydao.Query(new ActivityQueryForm { WorkflowIDs = workflowids }); approvals = appvoraldao.Query(new ApprovalQueryForm { WorkflowIDs = workflowids }); tasks = taskdao.Query(new TaskQueryForm { WorkflowIDs = workflowids }); } } else { return(result); } if (projectidlist.Count > 0) { cps = cpdao.Query(new Customer_ProjectQueryForm { ProjectIDs = projectidlist }); cas = cadao.Query(new Customer_AssetQueryForm { ProjectIDs = projectidlist }); aps = apdao.Query(new Asset_ProjectQueryForm { ProjectIDs = projectidlist }); } var users = uidao.Query(new UserInfoQueryForm { }); var userroles = urdao.Query(new User_RoleQueryForm { }); criList = cridao.Query(new CreditReceiverInfoQueryForm { ProjectIDs = projectids }); tco = tcodao.Query(new TrackingChangeOwnerQueryForm { ProjectIDs = projectidlist }); tm = tmdao.Query(new TrackingMortgageQueryForm { ProjectIDs = projectidlist }); returnBackMoneyInfo = rbcdao.Query(new ReturnBackConfirmQueryForm { ProjectIDs = projectidlist }); //从缓存中取得 var customers = TableCacheHelper.GetDataFromCache <Customer>(typeof(CustomerDao)); var assets = TableCacheHelper.GetDataFromCache <Asset>(typeof(AssetDao)); #endregion #region 处理废单权限 //处理废单权限 var hasDisplayDiscard = (from ur in userroles join r in rma on ur.RoleID equals r.RoleID where r.ModuleID == "4" && r.ActionID == "4" && ur.UserID == currentuserid select r).FirstOrDefault(); #endregion foreach (Project project in list) { var data = QueryDetail(project, customers, assets, cps, cas, aps, workflows, activities, approvals, tasks, users, userroles, tco, tm, returnBackMoneyInfo, criList, currentuserid); if (hasDisplayDiscard != null) { data.DisplayDiscard = true; } result.Add(data); } return(result); }
/// <summary> /// 获得角色下的所有用户以及角色子级下的所有角色 /// </summary> /// <param name="roleid"></param> /// <returns></returns> public List<string> GetRoleUserIDs(string roleid) { ISqlMapper mapper = MapperHelper.GetMapper(); User_RoleDao urdao = new User_RoleDao(mapper); var roles = GetAllSubRoles(roleid); var roleids = (from r in roles select r.ID).ToList(); var urs = urdao.Query(new User_RoleQueryForm { RoleIDs = roleids }); return (from u in urs select u.UserID).ToList(); }
public bool Delete(UserQueryForm user) { ISqlMapper mapper = Common.GetMapperFromSession(); UserDao userdao = new UserDao(mapper); User_RoleDao urdao = new User_RoleDao(mapper); UserInfoDao uidao = new UserInfoDao(mapper); UserQueryForm uform = new UserQueryForm { ID = user.ID }; userdao.Delete(uform); UserInfoQueryForm uiform = new UserInfoQueryForm { ID = user.ID, }; uidao.Delete(uiform); User_RoleQueryForm urform = new User_RoleQueryForm { UserID = user.ID, }; urdao.Delete(urform); SOAFramework.Library.WeiXin.WeiXinApi.User.Delete(user.Name); return true; }
/// <summary> /// 查询所有用户 /// </summary> /// <returns></returns> public List<FullUser> Query(FullUserQueryForm form) { ISqlMapper mapper = Common.GetMapperFromSession(); FullUserDao dao = new FullUserDao(mapper); User_RoleDao urdao = new User_RoleDao(mapper); RoleDao roledao = new RoleDao(mapper); var userlist = dao.Query(form); var userids = (from u in userlist select u.ID).ToList(); var urs = urdao.Query(new User_RoleQueryForm { UserIDs = userids }); var roleids = (from ur in urs select ur.RoleID).Distinct().ToList(); var roles = roledao.Query(new RoleQueryForm { IDs = roleids }); foreach (var u in userlist) { var ur_temp = urs.FindAll(t => t.UserID == u.ID); var rolelist = (from ur in ur_temp join r in roles on ur.RoleID equals r.ID select r).ToList(); u.RoleList = rolelist; } return userlist; }
public string Add(Model.User user, UserInfo ui, List<string> roleidlist) { #region risk user ISqlMapper mapper = Common.GetMapperFromSession(); if (user == null) { throw new Exception("user不能为null!"); } UserDao dao = new UserDao(mapper); var exist = dao.Query(new UserQueryForm { Name = user.Name }); if (exist.Count > 0) throw new Exception("已存在用户名:" + user.Name); if (string.IsNullOrEmpty(ui.WX) && string.IsNullOrEmpty(ui.Mobile)) throw new Exception("微信号或者手机不能为空"); string id = dao.Add(user); if (ui == null) { ui = new UserInfo(); } UserInfoDao infodao = new UserInfoDao(mapper); ui.ID = id; infodao.Add(ui); if (roleidlist == null) return id; User_RoleDao urdao = new User_RoleDao(mapper); foreach (var role in roleidlist) { User_Role ur = new User_Role { RoleID = role, UserID = user.ID }; urdao.Add(ur); } #endregion #region weixin user RoleDao roledao = new RoleDao(mapper); var roles = roledao.Query(new RoleQueryForm { IDs = roleidlist }); var weixinids = (from r in roles where !string.IsNullOrEmpty(r.WeiXinID) select Convert.ToInt32(r.WeiXinID)).ToArray(); try { SOAFramework.Library.WeiXin.WeiXinApi.User.Create(new SOAFramework.Library.WeiXin.User { department = weixinids, enable = 1, mobile = ui.Mobile, name = ui.CnName, weixinid = ui.WX, userid = user.Name, }); } catch (SOAFramework.Library.WeiXin.WeiXinException ex) { switch (ex.Code) { case "60004": case "60003": foreach (var role in roles) { //部门不存在就新建部门 Role parentrole = null; if (!string.IsNullOrEmpty(role.ParentID)) roledao.Query(new RoleQueryForm { ID = role.ParentID }).FirstOrDefault(); var department = new SOAFramework.Library.WeiXin.Department { name = role.Name, }; if (parentrole != null) department.parentid = parentrole.WeiXinID; var response = SOAFramework.Library.WeiXin.WeiXinApi.Department.Create(department); roledao.Update(new RoleUpdateForm { Entity = new Role { WeiXinID = response.id }, RoleQueryForm = new RoleQueryForm { ID = role.ID }, }); } SOAFramework.Library.WeiXin.WeiXinApi.User.Create(new SOAFramework.Library.WeiXin.User { department = weixinids, enable = 1, mobile = ui.Mobile, name = ui.CnName, weixinid = ui.WX, userid = user.Name, }); break; case "60102"://用户已存在 SOAFramework.Library.WeiXin.WeiXinApi.User.Update(new SOAFramework.Library.WeiXin.User { department = weixinids, mobile = ui.Mobile, name = ui.CnName, weixinid = ui.WX, userid = user.Name, }); break; default: throw ex; } } #endregion return id; }
public bool Update(Model.User user, UserInfo ui, List<string> roleidlist) { #region risk update ISqlMapper mapper = Common.GetMapperFromSession(); UserDao udao = new UserDao(mapper); UserInfoDao uidao = new UserInfoDao(mapper); if (user != null) { Model.User entity = new User { ID = user.ID, Enabled = user.Enabled, }; udao.Update(new UserUpdateForm { Entity = entity, UserQueryForm = new UserQueryForm { ID = user.ID } }); } if (ui != null) { uidao.Update(new UserInfoUpdateForm { Entity = ui, UserInfoQueryForm = new UserInfoQueryForm { ID = ui.ID } }); } if (roleidlist != null) { User_RoleDao urdao = new User_RoleDao(mapper); urdao.Delete(new User_RoleQueryForm { UserID = user.ID }); foreach (var role in roleidlist) { User_Role ur = new User_Role { RoleID = role, UserID = user.ID }; urdao.Add(ur); } } #endregion #region weixin api RoleDao roledao = new RoleDao(mapper); var roles = roledao.Query(new RoleQueryForm { IDs = roleidlist }); var weixinids = (from r in roles where !string.IsNullOrEmpty(r.WeiXinID) select Convert.ToInt32(r.WeiXinID)).ToArray(); var user_temp = udao.Query(new UserQueryForm { ID = user.ID }).FirstOrDefault(); var ui_temp = uidao.Query(new UserInfoQueryForm { ID = user.ID }).FirstOrDefault(); try { SOAFramework.Library.WeiXin.WeiXinApi.User.Update(new SOAFramework.Library.WeiXin.User { department = weixinids, mobile = ui_temp.Mobile, name = ui_temp.CnName, weixinid = ui_temp.WX, userid = user_temp.Name, enable = 1, }); } catch (SOAFramework.Library.WeiXin.WeiXinException ex) { switch (ex.Code) { case "60111"://如果微信上不存在用户,就新建 SOAFramework.Library.WeiXin.WeiXinApi.User.Create(new SOAFramework.Library.WeiXin.User { enable = 1, userid = user_temp.Name, name = ui_temp.CnName, mobile = ui_temp.Mobile, weixinid = ui_temp.WX, department = weixinids, }); break; default: throw ex; } } #endregion return true; }
public bool Update(User user, UserInfo ui, List<Role> roles) { ISqlMapper mapper = MapperHelper.GetMapper(); UserDao dao = new UserDao(mapper); UserInfoDao uidao = new UserInfoDao(mapper); User_RoleDao urdao = new User_RoleDao(mapper); var updateuser = GetUserFormCache(); dao.Update(new UserUpdateForm { Entity = new User { Enabled = user.Enabled, LastUpdateTime = DateTime.Now, LastUpdator = updateuser?.User.ID, }, UserQueryForm = new UserQueryForm { ID = user.ID } }); if (ui != null) { if (uidao.Query(new UserInfoQueryForm { ID = user.ID }).FirstOrDefault() == null) { ui.ID = user.ID; uidao.Add(ui); } else { uidao.Update(new UserInfoUpdateForm { Entity = ui, UserInfoQueryForm = new UserInfoQueryForm { ID = user.ID } }); } } urdao.Delete(new User_RoleQueryForm { UserID = user.ID }); if (roles != null) { foreach (var role in roles) { urdao.Add(new User_Role { UserID = user.ID, RoleID = role.ID }); } } return true; }
public List<FullUser> Query(FullUserQueryForm form) { ISqlMapper mapper = MapperHelper.GetMapper(); UserDao dao = new UserDao(mapper); User_RoleDao urdao = new User_RoleDao(mapper); RoleDao roledao = new RoleDao(mapper); var users = dao.QueryFullUser(form); var userids = (from u in users select u.ID).ToList(); var urs = urdao.Query(new User_RoleQueryForm { UserIDs = userids }); var roleids = (from ur in urs select ur.RoleID).Distinct().ToList(); var roles = roledao.Query(new RoleQueryForm { IDs = roleids }); foreach (var u in users) { u.Roles = (from ur in urs join role in roles on ur.RoleID equals role.ID where ur.UserID.Equals(u.ID) select role).ToList(); } return users; }
public string Add(Model.User user, UserInfo ui, List <string> roleidlist) { #region risk user ISqlMapper mapper = Common.GetMapperFromSession(); if (user == null) { throw new Exception("user不能为null!"); } UserDao dao = new UserDao(mapper); var exist = dao.Query(new UserQueryForm { Name = user.Name }); if (exist.Count > 0) { throw new Exception("已存在用户名:" + user.Name); } if (string.IsNullOrEmpty(ui.WX) && string.IsNullOrEmpty(ui.Mobile)) { throw new Exception("微信号或者手机不能为空"); } string id = dao.Add(user); if (ui == null) { ui = new UserInfo(); } UserInfoDao infodao = new UserInfoDao(mapper); ui.ID = id; infodao.Add(ui); if (roleidlist == null) { return(id); } User_RoleDao urdao = new User_RoleDao(mapper); foreach (var role in roleidlist) { User_Role ur = new User_Role { RoleID = role, UserID = user.ID }; urdao.Add(ur); } #endregion #region weixin user RoleDao roledao = new RoleDao(mapper); var roles = roledao.Query(new RoleQueryForm { IDs = roleidlist }); var weixinids = (from r in roles where !string.IsNullOrEmpty(r.WeiXinID) select Convert.ToInt32(r.WeiXinID)).ToArray(); try { SOAFramework.Library.WeiXin.WeiXinApi.User.Create(new SOAFramework.Library.WeiXin.User { department = weixinids, enable = 1, mobile = ui.Mobile, name = ui.CnName, weixinid = ui.WX, userid = user.Name, }); } catch (SOAFramework.Library.WeiXin.WeiXinException ex) { switch (ex.Code) { case "60004": case "60003": foreach (var role in roles) { //部门不存在就新建部门 Role parentrole = null; if (!string.IsNullOrEmpty(role.ParentID)) { roledao.Query(new RoleQueryForm { ID = role.ParentID }).FirstOrDefault(); } var department = new SOAFramework.Library.WeiXin.Department { name = role.Name, }; if (parentrole != null) { department.parentid = parentrole.WeiXinID; } var response = SOAFramework.Library.WeiXin.WeiXinApi.Department.Create(department); roledao.Update(new RoleUpdateForm { Entity = new Role { WeiXinID = response.id }, RoleQueryForm = new RoleQueryForm { ID = role.ID }, }); } SOAFramework.Library.WeiXin.WeiXinApi.User.Create(new SOAFramework.Library.WeiXin.User { department = weixinids, enable = 1, mobile = ui.Mobile, name = ui.CnName, weixinid = ui.WX, userid = user.Name, }); break; case "60102": //用户已存在 SOAFramework.Library.WeiXin.WeiXinApi.User.Update(new SOAFramework.Library.WeiXin.User { department = weixinids, mobile = ui.Mobile, name = ui.CnName, weixinid = ui.WX, userid = user.Name, }); break; default: throw ex; } } #endregion return(id); }
public bool Update(Model.User user, UserInfo ui, List <string> roleidlist) { #region risk update ISqlMapper mapper = Common.GetMapperFromSession(); UserDao udao = new UserDao(mapper); UserInfoDao uidao = new UserInfoDao(mapper); if (user != null) { Model.User entity = new User { ID = user.ID, Enabled = user.Enabled, }; udao.Update(new UserUpdateForm { Entity = entity, UserQueryForm = new UserQueryForm { ID = user.ID } }); } if (ui != null) { uidao.Update(new UserInfoUpdateForm { Entity = ui, UserInfoQueryForm = new UserInfoQueryForm { ID = ui.ID } }); } if (roleidlist != null) { User_RoleDao urdao = new User_RoleDao(mapper); urdao.Delete(new User_RoleQueryForm { UserID = user.ID }); foreach (var role in roleidlist) { User_Role ur = new User_Role { RoleID = role, UserID = user.ID }; urdao.Add(ur); } } #endregion #region weixin api RoleDao roledao = new RoleDao(mapper); var roles = roledao.Query(new RoleQueryForm { IDs = roleidlist }); var weixinids = (from r in roles where !string.IsNullOrEmpty(r.WeiXinID) select Convert.ToInt32(r.WeiXinID)).ToArray(); var user_temp = udao.Query(new UserQueryForm { ID = user.ID }).FirstOrDefault(); var ui_temp = uidao.Query(new UserInfoQueryForm { ID = user.ID }).FirstOrDefault(); try { SOAFramework.Library.WeiXin.WeiXinApi.User.Update(new SOAFramework.Library.WeiXin.User { department = weixinids, mobile = ui_temp.Mobile, name = ui_temp.CnName, weixinid = ui_temp.WX, userid = user_temp.Name, enable = 1, }); } catch (SOAFramework.Library.WeiXin.WeiXinException ex) { switch (ex.Code) { case "60111": //如果微信上不存在用户,就新建 SOAFramework.Library.WeiXin.WeiXinApi.User.Create(new SOAFramework.Library.WeiXin.User { enable = 1, userid = user_temp.Name, name = ui_temp.CnName, mobile = ui_temp.Mobile, weixinid = ui_temp.WX, department = weixinids, }); break; default: throw ex; } } #endregion return(true); }