| | |
| | | using FaceAI; |
| | | using System.Runtime.InteropServices; |
| | | using System.IO; |
| | | using WIDESEAWCS_DTO.Telescopic; |
| | | |
| | | namespace WIDESEAWCS_SystemServices |
| | | { |
| | |
| | | private readonly IRepository<Dt_FaceRecognition> _faceServer; |
| | | private readonly IRepository<Dt_Loginhsy> _LoginhsyServer; |
| | | private readonly IRepository<Dt_Maintenance> _MainServer; |
| | | public Sys_UserService(IRepository<Dt_Loginhsy> LoginhsyServer,IRepository<Dt_FaceRecognition> faceServer, IRepository<Sys_User> repository, IUnitOfWorkManage unitOfWorkManage, ICacheService cacheService, ISys_MenuService menuService, IRepository<Dt_Maintenance> MainServer) : base(repository) |
| | | private readonly IRepository<Sys_Role> _RoleServer; |
| | | private readonly IRepository<Dt_AuthorizationRecord> _AuthorizatRecServer; |
| | | |
| | | public Sys_UserService(IRepository<Dt_AuthorizationRecord> AuthorizatRecServer,IRepository<Sys_Role> RoleServer,IRepository<Dt_Loginhsy> LoginhsyServer,IRepository<Dt_FaceRecognition> faceServer, IRepository<Sys_User> repository, IUnitOfWorkManage unitOfWorkManage, ICacheService cacheService, ISys_MenuService menuService, IRepository<Dt_Maintenance> MainServer) : base(repository) |
| | | { |
| | | _faceServer = faceServer; |
| | | _LoginhsyServer = LoginhsyServer; |
| | |
| | | _cacheService = cacheService; |
| | | _menuService = menuService; |
| | | _MainServer = MainServer; |
| | | |
| | | _RoleServer = RoleServer; |
| | | _AuthorizatRecServer = AuthorizatRecServer; |
| | | } |
| | | |
| | | |
| | |
| | | IsLeader=addUserDTO.IsLeader, |
| | | RoleName = addUserDTO.rolename, |
| | | Enable = addUserDTO.enable, |
| | | Unit=addUserDTO.userunit, |
| | | UserPwd = "j79rYYvCz4vdhcboB1Ausg==", |
| | | //Userteam=addUserDTO.userteam, |
| | | Userteam=addUserDTO.userteam, |
| | | Dept_Id=addUserDTO.dept_Id, |
| | | //CardNumber=addUserDTO.carnuber, |
| | | CreateDate = DateTime.Now |
| | |
| | | { |
| | | UserAccount = addUserDTO.username, |
| | | Roleid = addUserDTO.roleid, |
| | | IsLeader=addUserDTO.IsLeader,//是否是组长 |
| | | IsLeader =addUserDTO.IsLeader,//是否是组长 |
| | | }; |
| | | _MainServer.AddData(Main); |
| | | |
| | |
| | | // 1. 查询用户 |
| | | var userList = BaseDal.QueryData(); |
| | | var sys = userList.FirstOrDefault(x => x.User_Id == addUserDTO.id); |
| | | //查找Dt_MaintenanceTeam中的数据 |
| | | var team = _MainServer.QueryData(x => x.UserAccount == sys.UserName).FirstOrDefault(); |
| | | if (sys == null) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "没找到该用户" }; |
| | | } |
| | | |
| | | //查找Dt_MaintenanceTeam中的数据 |
| | | var team = _MainServer.QueryData(x => x.UserAccount == sys.UserName).FirstOrDefault(); |
| | | if (team == null) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "没找到该用户的维护组信息" }; |
| | | } |
| | | |
| | | // 2. 检查账号是否修改,并判断是否重复//StringComparison.OrdinalIgnoreCase:表示忽略大小写进行比较,比如 "admin" 和 "ADMIN" 也认为是相等的 |
| | |
| | | sys.Role_Id = addUserDTO.roleid; |
| | | sys.RoleName = addUserDTO.rolename; |
| | | //sys.CardNumber = addUserDTO.carnuber; |
| | | //sys.Userteam = addUserDTO.userteam; |
| | | sys.Userteam = addUserDTO.userteam; |
| | | sys.Unit = addUserDTO.userunit; |
| | | sys.Dept_Id = addUserDTO.dept_Id; |
| | | sys.Enable = addUserDTO.enable; |
| | | //sys.Enable = addUserDTO.enable; |
| | | sys.IsLeader = addUserDTO.IsLeader;//更新用户表的是否是组长 |
| | | //如果人脸识别添加了这里就注释掉 |
| | | sys.HeadImageUrl = addUserDTO.path; |
| | |
| | | //} |
| | | |
| | | // 8. 更新数据库 |
| | | BaseDal.UpdateData(sys); |
| | | |
| | | //更新Dt_Maintenance表中的数据和user表中修改的一样 |
| | | team.UserAccount = addUserDTO.username;//账号 |
| | | team.Roleid = addUserDTO.roleid;//更新权限 |
| | | team.IsLeader = addUserDTO.IsLeader; |
| | | |
| | | var existAuthority = userList.FirstOrDefault(a => a.UserName == addUserDTO.username); |
| | | // 先缓存旧的 enable 值 |
| | | var oldEnable = sys.Enable; |
| | | |
| | | // 修改 enable |
| | | sys.Enable = addUserDTO.enable; |
| | | |
| | | // 然后比较旧值和新值 |
| | | if (oldEnable != addUserDTO.enable) |
| | | { |
| | | var authority = new Dt_AuthorizationRecord |
| | | { |
| | | Account = addUserDTO.username, |
| | | UserName = addUserDTO.usertruename, |
| | | UerUnit = addUserDTO.userunit, |
| | | UserTeam = addUserDTO.userteam, |
| | | EnableTime = addUserDTO.enable == 1 ? DateTime.Now : (DateTime?)null, //启用 |
| | | DisableTime = addUserDTO.enable == 0 ? DateTime.Now : (DateTime?)null,//不启用 |
| | | |
| | | }; |
| | | |
| | | |
| | | _AuthorizatRecServer.AddData(authority); |
| | | } |
| | | |
| | | |
| | | BaseDal.UpdateData(sys); |
| | | _MainServer.UpdateData(team); |
| | | |
| | | return new WebResponseContent { Status = true, Data = sys }; |
| | |
| | | return new WebResponseContent { Status = false, Message="失败"}; |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 表连接角色表,展示数据 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent YShowUserList(PaginationDTO pagination) |
| | | { |
| | | try |
| | | { |
| | | int totalCount = 0; |
| | | var Role = _RoleServer.Db.Queryable<Sys_Role>(); |
| | | var query = Role.InnerJoin<Sys_User>((a, b) => a.RoleId == b.Role_Id); |
| | | |
| | | //搜索关键字 |
| | | if (!string.IsNullOrEmpty(pagination.searchKeyword)) |
| | | { |
| | | query = query.Where((a, b) => |
| | | b.UserName.Contains(pagination.searchKeyword) || |
| | | b.UserTrueName.Contains(pagination.searchKeyword) || |
| | | b.PhoneNo.Contains(pagination.searchKeyword) || |
| | | a.RoleName.Contains(pagination.searchKeyword)); |
| | | } |
| | | //时间查询 |
| | | if (pagination.startDate.HasValue && pagination.endDate.HasValue) |
| | | { |
| | | query = query.Where((a, b) => b.CreateDate >= pagination.startDate.Value && b.CreateDate <= pagination.endDate.Value); |
| | | } |
| | | //排序 |
| | | if (!string.IsNullOrEmpty(pagination.sortField)) |
| | | { |
| | | var isAcs = pagination.sortOrder?.ToLower() == "asc"; |
| | | query = pagination.sortField.ToLower() switch |
| | | { |
| | | |
| | | |
| | | "CreateDate" => isAcs ? query.OrderBy((a, b) => b.CreateDate) : query.OrderByDescending((a, b) => b.CreateDate), |
| | | |
| | | _ => query.OrderByDescending((a, b) => b.Creater) // 默认按创建时间降序 |
| | | }; |
| | | |
| | | } |
| | | else |
| | | { |
| | | query = query.OrderByDescending((a, b) => b.Creater); |
| | | } |
| | | var reslut = query.Select((a, b) => new |
| | | { |
| | | b.User_Id, |
| | | b.UserName, |
| | | b.UserTrueName, |
| | | b.Unit, |
| | | b.Userteam, |
| | | b.Role_Id, |
| | | b.IsLeader, |
| | | //b.RoleName, |
| | | b.CardNumber, |
| | | b.PhoneNo, |
| | | b.UserPwd, |
| | | b.DeptName, |
| | | b.Dept_Id, |
| | | b.Email, |
| | | b.Enable, |
| | | b.Gender, |
| | | b.HeadImageUrl, |
| | | b.Address, |
| | | b.CreateDate, |
| | | b.Creater, |
| | | a.RoleName, |
| | | |
| | | }).ToPageList(pagination.pageIndex, pagination.pageSize, ref totalCount); |
| | | |
| | | |
| | | return new WebResponseContent |
| | | { |
| | | Status = true, |
| | | Data = new |
| | | { |
| | | totalCount = totalCount, |
| | | PageIndex = pagination.pageIndex, |
| | | PageSize = pagination.pageSize, |
| | | Items = reslut |
| | | } |
| | | }; |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | return new WebResponseContent { Status = false, Message = ex.Message }; |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | } |