From 7281004dc3854ed59e9164dcd27a59c8c2cf6667 Mon Sep 17 00:00:00 2001 From: qinchulong <qinchulong@hnkhzn.com> Date: 星期六, 12 十月 2024 15:16:55 +0800 Subject: [PATCH] 初始化 --- 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_Services/Sys_UserService.cs | 193 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 193 insertions(+), 0 deletions(-) diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Services/Sys_UserService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Services/Sys_UserService.cs" new file mode 100644 index 0000000..6e86a58 --- /dev/null +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Services/Sys_UserService.cs" @@ -0,0 +1,193 @@ +锘縰sing WIDESEA_Core.Authorization; +using WIDESEA_Core; +using WIDESEA_Core.BaseServices; +using WIDESEA_Core.Const; +using WIDESEA_Core.Helper; +using WIDESEA_Core.HttpContextUser; +using WIDESEA_IServices; +using WIDESEA_Model; +using WIDESEA_Model.Models; +using WIDESEA_IRepository; +using WIDESEA_Core.BaseRepository; +using System.Net; + +namespace WIDESEA_Services +{ + public class Sys_UserService : ServiceBase<Sys_User, ISys_UserRepository>, ISys_UserService + { + private readonly IUnitOfWorkManage _unitOfWorkManage; + public Sys_UserService(ISys_UserRepository repository, IUnitOfWorkManage unitOfWorkManage) : base(repository) + { + _unitOfWorkManage = unitOfWorkManage; + } + + public WebResponseContent Login(LoginInfo loginInfo) + { + WebResponseContent content = new WebResponseContent(); + try + { + //BaseDal.QueryFirst(x => x.UserName == loginInfo.UserName); + + string msg = string.Empty; + + #region 涓存椂浣跨敤 + try + { + loginInfo.Password = loginInfo.Password.EncryptDES(AppSecret.User); + } + catch + { + + } + #endregion + + UserInfo user = BaseDal.GetUserInfo(loginInfo.UserName, loginInfo.Password); + if (user != null) + { + string token = JwtHelper.IssueJwt(new TokenModelJwt() + { + UserId = user.UserId, + RoleId = user.RoleId, + }); + + content = WebResponseContent.Instance.OK(data: new { token, userName = user.UserTrueName, img = user.HeadImageUrl }); + } + else + { + content = WebResponseContent.Instance.Error("璐﹀彿鎴栧瘑鐮侀敊璇�"); + } + } + catch (Exception ex) + { + content = WebResponseContent.Instance.Error(ex.Message); + } + + return content; + } + + public override WebResponseContent UpdateData(SaveModel saveModel) + { + UpdateIgnoreColOnExecute = x => + { + return new List<string> + { + nameof(Sys_User.UserPwd), + nameof(Sys_User.SystemType), + nameof(Sys_User.TenantId) + }; + }; + return base.UpdateData(saveModel); + } + + public override WebResponseContent AddData(SaveModel saveModel) + { + string pwd = "123456"; + string uesrName = saveModel.MainData[nameof(Sys_User.UserName).FirstLetterToLower()].ToString(); + saveModel.MainData[nameof(Sys_User.UserPwd).FirstLetterToLower()] = pwd.EncryptDES(AppSecret.User); + + WebResponseContent content = base.AddData(saveModel); + if (content.Status) + { + return WebResponseContent.Instance.OK($"鐢ㄦ埛鏂板缓鎴愬姛.甯愬彿{uesrName}瀵嗙爜{pwd}"); + } + else + { + return content; + } + } + + /// <summary> + /// 涓汉涓績鑾峰彇褰撳墠鐢ㄦ埛淇℃伅 + /// </summary> + /// <returns></returns> + public WebResponseContent GetCurrentUserInfo() + { + var data = BaseDal.QueryFirst(x => x.User_Id == App.User.UserId, s => new + { + s.User_Id, + s.UserName, + s.UserTrueName, + s.Address, + s.PhoneNo, + s.Email, + s.Remark, + s.Gender, + s.RoleName, + s.HeadImageUrl, + s.CreateDate + }); + return WebResponseContent.Instance.OK(null, data); + } + + /// <summary> + /// 淇敼瀵嗙爜 + /// </summary> + /// <param name="parameters"></param> + /// <returns></returns> + public WebResponseContent ModifyPwd(string oldPwd, string newPwd) + { + WebResponseContent content = WebResponseContent.Instance; + oldPwd = oldPwd?.Trim(); + newPwd = newPwd?.Trim(); + string message = ""; + try + { + if (string.IsNullOrEmpty(oldPwd)) return WebResponseContent.Instance.Error("鏃у瘑鐮佷笉鑳戒负绌�"); + if (string.IsNullOrEmpty(newPwd)) return WebResponseContent.Instance.Error("鏂板瘑鐮佷笉鑳戒负绌�"); + if (newPwd.Length < 6) return WebResponseContent.Instance.Error("瀵嗙爜涓嶈兘灏戜簬6浣�"); + + int userId = App.User.UserId; + string userCurrentPwd = BaseDal.QueryFirst(x => x.User_Id == userId, s => s.UserPwd); + + string _oldPwd = oldPwd.EncryptDES(AppSecret.User); + if (_oldPwd != userCurrentPwd) return WebResponseContent.Instance.Error("鏃у瘑鐮佷笉姝g‘"); + + string _newPwd = newPwd.EncryptDES(AppSecret.User); + if (userCurrentPwd == _newPwd) return WebResponseContent.Instance.Error("鏂板瘑鐮佷笉鑳戒笌鏃у瘑鐮佺浉鍚�"); + + + BaseDal.UpdateData(new Sys_User + { + User_Id = userId, + UserPwd = _newPwd, + LastModifyPwdDate = DateTime.Now + }, new List<string> + { + nameof(Sys_User.LastModifyPwdDate), + nameof(Sys_User.UserPwd) + }); + + content = WebResponseContent.Instance.OK("瀵嗙爜淇敼鎴愬姛"); + } + catch (Exception ex) + { + message = ex.Message; + content = WebResponseContent.Instance.Error("鏈嶅姟鍣ㄤ簡鐐归棶棰�,璇风◢鍚庡啀璇�"); + } + return content; + } + public WebResponseContent UpdateInfo(int user_Id, string roleName, string userName, string userTrueName, string address, int gender, string remark) + { + WebResponseContent content = new WebResponseContent(); + + var userInfo = BaseDal.QueryFirst(x => x.User_Id == user_Id); + if (userInfo != null) + { + userInfo.RoleName= roleName; + userInfo.UserName = userName; + userInfo.UserTrueName = userTrueName; + userInfo.Address = address; + userInfo.Gender = gender; + userInfo.Remark = remark; + userInfo.ModifyDate = DateTime.Now; + BaseDal.UpdateData(userInfo); + content = WebResponseContent.Instance.OK("涓汉淇℃伅淇敼鎴愬姛"); + } + else + { + content = WebResponseContent.Instance.Error("鏈嶅姟鍣ㄤ簡鐐归棶棰�,璇风◢鍚庡啀璇�"); + } + return content; + } + } +} -- Gitblit v1.9.3