using AutoMapper; using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using Model.ModelDto.SysDto; using WMS.Entity.SysEntity; using WMS.IBLL.ISysServer; using WMS.IDAL.ISysInterface; using System.Security.Cryptography; using OracleInternal.Secure.Network; using Utility.Tools; using System.Linq; namespace WMS.BLL.SysServer { public class UserInforServer : IUserInforServer { public IUserInforRepository UserSvc { get; set; } readonly IMapper _mapper; private readonly IFunSettingServer _setting; public UserInforServer(IUserInforRepository userSvc, IMapper mapper, IFunSettingServer setting) { UserSvc = userSvc; _mapper = mapper; _setting = setting; } public bool LoginAdmin(string loginName, string loginPwd, out int adminId) { //loginPwd = Md5Tools.CalcMd5(loginPwd); var date = UserSvc.GetAllAsync().First(m => m.UserName == loginName && m.PassWord == loginPwd); if (date != null) //账号密码是否正确 { if (date.Status == "0") //当前账号是否正常启用 { //最后登陆时间 UserSvc.UptUserLoginTime(date.Id); adminId = date.Id; return true; } else //当前账号被禁用 { adminId = 0; return true; } } else //账号密码不正确或没有此账号 { adminId = 0; return false; } } public SysUserInfor CeShi() { var date = UserSvc.ceshi(); return date; } /// /// 获取用户角色信息 /// /// public List GetUserRoleList(string UserName, string DepartmentNo, string RoleNo, string Status) { string str = "select user1.Id Id,user1.UserNo UserNo,user1.UserName UserName,user1.RealName RealName,user1.PassWord PassWord,user1.JobNo JobNo,user1.Status Status,user1.Sex Sex,user1.Nationality Nationality,user1.CreateTime CreateTime,user1.CreateUser CreateUser,user1.Paper Paper,user1.Phone Phone,user1.Email Email,user1.Addres Addres,user1.Demo Demo,role.RoleName,user2.RealName CreateUserName,depa.DepartmentName DepartmentName from SysUserInfor user1 left join SysRoles role on user1.RoleNo = role.RoleNo left join SysUserInfor user2 on user1.CreateUser = user2.Id left join SysDepartment depa on user1.DepartmentNo = depa.DepartmentNo where user1.IsDel = '0'"; //判断登录名称是否为空 if (!string.IsNullOrEmpty(UserName)) { str += $" and user1.UserName like '%{UserName}%'"; } //判断部门号是否为0 if (!string.IsNullOrEmpty(DepartmentNo)) { str += $" and user1.DepartmentNo = '{DepartmentNo}'"; } //判断角色号是否为空 if (!string.IsNullOrEmpty(RoleNo)) { str += $" and user1.RoleNo = '{RoleNo}'"; } //判断状态是否为空 if (!string.IsNullOrEmpty(Status)) { str += $" and user1.Status = '{Status}'"; } List userInfoDtos = UserSvc.GetUserRoleList(str); //var arr = Md5Tools.CalcMd5(userInfoDtos[3].PassWord); return userInfoDtos; } /// /// 根据编号获取用户信息列表 /// /// 用户编号 /// 用户登录名 /// 用户ID /// public int GetUserInfoByNo(string userNo, string userName,int id) { string str = $"select * from SysUserInfor where IsDel=0 and (UserNo = '{userNo}' or UserName = '{userName}') "; if (id!=0) { str += $"and Id != {id} "; } List user = UserSvc.GetUserInfoByNo(str); return user.Count; } /// /// 新增用户信息 /// /// 用户视图模型 /// /// 异常 public async Task InsertUserInfo(UserInfoDto UserInfoDto) { //异常 try { //数据模型映射 SysUserInfor userinfo = _mapper.Map(UserInfoDto); //判断用户号是否唯一 int count = GetUserInfoByNo(userinfo.UserNo,userinfo.UserName,0); int i = 0; if (count > 0) { i = 3; } else if (count ==0) { //新增用户 i = await UserSvc.InsertUserInfo(userinfo); } return i; } catch (Exception ex) { //抛出异常 throw new Exception("新增用户信息异常", ex); } } /// /// 删除用户信息 /// /// 用户实体模型 /// /// 异常 public async Task DeleteUserinfo(SysUserInfor user) { //异常 try { //删除 int i = await UserSvc.DeleteUserinfo(user); //返回数据 return i; } catch (Exception ex) { //抛出异常 throw new Exception("删除用户信息异常", ex); } } /// /// 编辑用户信息 /// /// 用户Dto /// /// 异常exception> public async Task UpdateUserinfo(UserInfoDto userdto) { //异常 try { //映射数据模型 SysUserInfor userlist = _mapper.Map(userdto); //判断用户号是否唯一 int count = GetUserInfoByNo(userdto.UserNo, userdto.UserName,userdto.Id); int i = 0; if (count > 0) { i = 3; } else if (count == 0) { //编辑 i = await UserSvc.UpdateUserinfo(userlist); } return i; } catch (Exception ex) { //抛出异常 throw new Exception("编辑用户信息异常", ex); } } /// /// 根据id获取用户信息列表 /// /// 用户id /// public SysUserInfor GetUserInfoById(int userids) { //获取信息列表 SysUserInfor user= UserSvc.GetUserInfoById(userids); //返回数据 return user; } /// /// 修改用户密码 /// /// 原密码 /// 新密码 /// 确认密码 /// 用户id /// /// 捕获异常 public async Task UptUserPassWord(string pwdOld, string pwdNew, string pwdNewTwo, int userId) { //捕获异常 try { //验证两次新密码是否一致 if (pwdNew == pwdNewTwo) { int i = await UserSvc.UptUserPassWord(pwdOld, pwdNew, pwdNewTwo, userId); return i; } else { return 3; } } catch (Exception ex) { //抛出异常 throw new Exception("修改密码异常",ex); } } /// /// x天后提醒用户修改密码 /// /// /// public int IsPassWordTime(int userId) { //捕获异常 try { SysFunSetting funSettings = _setting.GetFunSettingByNo("Fun026"); if (funSettings != null && funSettings.IsEnable == "NO") { SysUserInfor userinfo = UserSvc.GetAllAsync().First(m => m.Id == userId); if (userinfo.SetPasswordTime != null) { int days = string.IsNullOrEmpty(funSettings.SetValue) ? 30 : Convert.ToInt32(funSettings.SetValue); bool isTime = userinfo.SetPasswordTime.Value.AddDays(days) < DateTime.Now; if (isTime) { return 1; } } } return 0; } catch (Exception ex) { //抛出异常 throw new Exception("修改密码异常", ex); } } } }