using 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; 
 | 
using WIDESEA_Repository; 
 | 
  
 | 
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("旧密码不正确"); 
 | 
  
 | 
                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 ModifyUserPwd(string password,string userName) 
 | 
        { 
 | 
            WebResponseContent webResponse = new WebResponseContent(); 
 | 
            if (string.IsNullOrEmpty(password) || string.IsNullOrEmpty(userName)) 
 | 
            { 
 | 
                return webResponse.Error("参数不完整"); 
 | 
            } 
 | 
            if (password.Length < 6) return webResponse.Error("密码长度不能少于6位"); 
 | 
  
 | 
             
 | 
            Sys_User user = BaseDal.QueryFirst(x => x.UserName == userName); 
 | 
            if (user == null) 
 | 
            { 
 | 
                return webResponse.Error("用户不存在"); 
 | 
            } 
 | 
            user.UserPwd = password.EncryptDES(AppSecret.User); 
 | 
            BaseDal.UpdateData(user); 
 | 
            //如果用户在线,强制下线 
 | 
            //UserContext.Current.LogOut(user.User_Id); 
 | 
            return webResponse.OK("密码修改成功"); 
 | 
        } 
 | 
        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; 
 | 
        } 
 | 
    } 
 | 
} 
 |