hwh
2024-06-27 b1ccdb760b9c16200831a2617caf9318b1be86b3
Wms/Wms/Controllers/BasisController.cs
@@ -20,6 +20,7 @@
using System.Security.Cryptography;
using System.Data;
using Model.ModelDto.LogDto;
using Utility;
namespace Wms.Controllers
{
@@ -44,6 +45,7 @@
        private readonly IFunSettingServer _setting; //功能设定
        private readonly IInterfaceServer _interface;//接口管理
        private readonly IOperationSysServer _operation; //操作日志
        private readonly UserManager _userManager;
        /// <summary>
        /// 构造函数
        /// </summary>
@@ -58,7 +60,7 @@
        /// <param name="department">部门</param>
        /// <param name="setting">功能设定</param>
        /// <param name="operation">操作日志</param>
        public BasisController(ICustomerServer customerSvc, ILogisticsInfoServer logisticsSvc, IUserInforServer userInforServer, IRolesServer rolesServer, IRoleRightServer roleRightServer, IRBACServer rBACServer, IUnitServer unitSvc, IPackagServer packagServer, IMaterialsServer mate, IDepartmentServer department, IFunSettingServer setting, IInterfaceServer interfaceS, IOperationSysServer operation)
        public BasisController(ICustomerServer customerSvc, ILogisticsInfoServer logisticsSvc, IUserInforServer userInforServer, IRolesServer rolesServer, IRoleRightServer roleRightServer, IRBACServer rBACServer, IUnitServer unitSvc, IPackagServer packagServer, IMaterialsServer mate, IDepartmentServer department, IFunSettingServer setting, IInterfaceServer interfaceS, IOperationSysServer operation, UserManager userManager)
        {
            _customerSvc = customerSvc;//客户Svc
            _logisticsSvc = logisticsSvc;//物流Svc
@@ -73,6 +75,7 @@
            _setting = setting; //功能设定
            _interface = interfaceS;//接口管理
            _operation = operation; //操作日志
            _userManager = userManager;
        }
        //基本信息管理
@@ -89,15 +92,10 @@
        /// <param name="Status">状态</param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetUserRoleList(string UserName, string DepartmentNo, string RoleNo, string Status)
        [ServiceFilter(typeof(ApiResponseActionFilter))]
        public async Task<List<UserInfoDto>> GetUserRoleList(string UserName, string DepartmentNo, string RoleNo, string Status)
        {
            List<UserInfoDto> userdtolist = _userInforServer.GetUserRoleList(UserName, DepartmentNo, RoleNo, Status);
            return Ok(new
            {
                data = userdtolist,
                code = 0,
                mes = "成功"
            });
            return await _userInforServer.GetUserRoleList(UserName, DepartmentNo, RoleNo, Status);
        }
        /// <summary>
@@ -106,15 +104,10 @@
        /// <param name="id">用户id</param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetUserinfoListById(int id)
        [ServiceFilter(typeof(ApiResponseActionFilter))]
        public async Task<SysUserInfor> GetUserinfoListById(int id)
        {
            SysUserInfor userinfo = _userInforServer.GetUserInfoById(id);
            return Ok(new
            {
                data = userinfo,
                code = 0,
                msg = "成功"
            });
            return await _userInforServer.GetUserInfoById(id);
        }
@@ -125,38 +118,13 @@
        /// <returns></returns>
        /// <exception cref="System.Exception">捕获异常</exception>
        [HttpPost]
        public async Task<IActionResult> InsertUserinfo(UserInfoDto UserInfoDto)
        [ServiceFilter(typeof(ApiResponseActionFilter))]
        public async Task InsertUserinfo(UserInfoDto UserInfoDto)
        {
            //捕获异常
            try
            {
                //获取当前操作用户id
                var claimsIdentity = this.User.Identity as ClaimsIdentity;
                var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
                int uid = Convert.ToInt32(userId);
                UserInfoDto.CreateUser = uid;
                int i = await _userInforServer.InsertUserInfo(UserInfoDto);
            UserInfoDto.CreateUser = _userManager.UserId;
            await _userInforServer.InsertUserInfo(UserInfoDto);
            await _operation.InsertOperation("系统设置", "用户管理", UserInfoDto.UserNo, "添加", "添加用户信息 用户号:" + UserInfoDto.UserNo, _userManager.UserId);
                //判断是否新增成功
                if (i == 0)
                {
                    return Ok(new { data = i, code = 1, msg = "新增失败" });
                }
                else if (i == 3)
                {
                    return Ok(new { data = i, code = 3, msg = "用户名或登录名重复" });
                }
                else
                {
                    await _operation.InsertOperation("系统设置", "用户管理", UserInfoDto.UserNo, "添加", "添加用户信息 用户号:" + UserInfoDto.UserNo, uid);
                    return Ok(new { data = i, code = 0, msg = "新增成功" });
                }
            }
            catch (System.Exception ex)
            {
                //抛出异常
                throw new System.Exception("新增用户异常", ex);
            }
        }
@@ -167,34 +135,13 @@
        /// <returns></returns>
        /// <exception cref="System.Exception">异常</exception>
        [HttpGet]
        public async Task<IActionResult> DeleteUserInfo(int userids)
        [ServiceFilter(typeof(ApiResponseActionFilter))]
        public async Task DeleteUserInfo(int userids)
        {
            //异常
            try
            {
                //获取用户信息
                SysUserInfor user = _userInforServer.GetUserInfoById(userids);
                //获取当前操作用户id
                var claimsIdentity = this.User.Identity as ClaimsIdentity;
                var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
                int uid = Convert.ToInt32(userId);
                int i = await _userInforServer.DeleteUserinfo(user);
                //判断是否删除成功
                if (i == 0)
                {
                    return Ok(new { data = i, code = 1, msg = "删除失败" });
                }
                else
                {
                    await _operation.InsertOperation("系统设置", "用户管理", user.UserNo, "删除", "删除用户信息 用户号:" + user.UserNo, uid);
                    return Ok(new { data = i, code = 0, msg = "删除成功" });
                }
            }
            catch (System.Exception ex)
            {
                //抛出异常
                throw new System.Exception("删除用户信息异常", ex);
            }
            //获取用户信息
            SysUserInfor user = await _userInforServer.GetUserInfoById(userids);
            await _userInforServer.DeleteUserinfo(user);
            await _operation.InsertOperation("系统设置", "用户管理", user.UserNo, "删除", "删除用户信息 用户号:" + user.UserNo, _userManager.UserId);
        }
@@ -205,41 +152,13 @@
        /// <returns></returns>
        /// <exception cref="System.Exception">捕获异常</exception>
        [HttpPost]
        public async Task<IActionResult> UpdateUserinfo(UserInfoDto userdto)
        [ServiceFilter(typeof(ApiResponseActionFilter))]
        public async Task UpdateUserinfo(UserInfoDto userdto)
        {
            //捕获异常
            try
            {
                //获取当前操作用户id
                var claimsIdentity = this.User.Identity as ClaimsIdentity;
                var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
                int uid = Convert.ToInt32(userId);
                //userdto.UpdateUser = Convert.ToInt32(userId);
                //更改人
                userdto.UpdateUser = uid;
            userdto.UpdateUser = _userManager.UserId;
            await _userInforServer.UpdateUserinfo(userdto);
            await _operation.InsertOperation("系统设置", "用户管理", userdto.UserNo, "修改", "修改用户信息 用户号:" + userdto.UserNo, _userManager.UserId);
                //编辑用户信息
                int i = await _userInforServer.UpdateUserinfo(userdto);
                //判断是否编辑成功
                if (i == 0)
                {
                    return Ok(new { data = i, code = 1, msg = "编辑失败" });
                }
                else if (i == 3)
                {
                    return Ok(new { data = i, code = 1, msg = "用户名或登录名重复" });
                }
                else
                {
                    await _operation.InsertOperation("系统设置", "用户管理", userdto.UserNo, "修改", "修改用户信息 用户号:" + userdto.UserNo, uid);
                    return Ok(new { data = i, code = 0, msg = "编辑成功" });
                }
            }
            catch (System.Exception ex)
            {
                //抛出异常
                throw new System.Exception("编辑用户信息异常", ex);
            }
        }
@@ -252,26 +171,21 @@
        /// </summary>
        /// <param name="PassWord">用户原密码</param>
        /// <returns></returns>
        [HttpGet]
        public int GetUserUptPassById(string PassWord, int userId)
        {
            ////获取当前操作用户id
            //var claimsIdentity = this.User.Identity as ClaimsIdentity;
            //var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
            //int uid = Convert.ToInt32(userId);
            //根据用户id获取用户密码
            SysUserInfor user = _userInforServer.GetUserInfoById(userId);
            //判断原密码是否正确
            if (user.PassWord == PassWord)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        //[HttpGet]
        //public async int GetUserUptPassById(string PassWord, int userId)
        //{
        //    //根据用户id获取用户密码
        //    SysUserInfor user = await _userInforServer.GetUserInfoById(userId);
        //    //判断原密码是否正确
        //    if (user.PassWord == PassWord)
        //    {
        //        return 1;
        //    }
        //    else
        //    {
        //        return 0;
        //    }
        //}
        ///// <param name="userId">用户id</param>
        /// <summary>
@@ -283,69 +197,28 @@
        /// <returns></returns>
        /// <exception cref="Exception">捕获异常</exception>
        [HttpGet]
        public async Task<IActionResult> UptUserPassWord(string pwdOld, string pwdNew, string pwdNewTwo/*, int userId*/)
        [ServiceFilter(typeof(ApiResponseActionFilter))]
        public async Task UptUserPassWord(string pwdOld, string pwdNew, string pwdNewTwo/*, int userId*/)
        {
            //捕获异常
            try
            pwdOld = Md5Tools.CalcMd5(pwdOld);
            pwdNew = Md5Tools.CalcMd5(pwdNew);
            pwdNewTwo = Md5Tools.CalcMd5(pwdNewTwo);
            //获取当前操作用户id
            SysUserInfor user = await _userInforServer.GetUserInfoById(_userManager.UserId);
            if (user == null)
            {
                pwdOld = Md5Tools.CalcMd5(pwdOld);
                pwdNew = Md5Tools.CalcMd5(pwdNew);
                pwdNewTwo = Md5Tools.CalcMd5(pwdNewTwo);
                //获取当前操作用户id
                var claimsIdentity = this.User.Identity as ClaimsIdentity;
                var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
                int uid = Convert.ToInt32(userId);
                //判断原密码是否正确
                int a = GetUserUptPassById(pwdOld, uid);
                if (a == 1)
                {
                    //修改密码
                    int i = await _userInforServer.UptUserPassWord(pwdOld, pwdNew, pwdNewTwo, uid);
                    if (i == 0)
                    {
                        return Ok(new
                        {
                            data = i,
                            code = 1,
                            msg = "修改失败"
                        });
                    }
                    //判断两次新密码是否一致
                    else if (i == 3)
                    {
                        return Ok(new
                        {
                            data = i,
                            code = 0,
                            msg = "修改成功 请重新登录"
                        });
                    }
                    else
                    {
                        return Ok(new
                        {
                            data = i,
                            code = 0,
                            msg = "修改成功 请重新登录"
                        });
                    }
                }
                else
                {
                    //错误
                    return Ok(new
                    {
                        data = a,
                        code = 1,
                        msg = "原密码不正确"
                    });
                }
                throw Oops.Bah("找不到用户信息");
            }
            catch (Exception ex)
            if (user.PassWord != pwdOld)
            {
                //抛出异常
                throw new Exception("修改密码异常", ex);
                throw Oops.Bah("原密码不正确");
            }
            else
            {
                //修改密码
                int i = await _userInforServer.UptUserPassWord(pwdNew, _userManager.UserId);
                if (i <= 0)
                    throw Oops.Bah("修改密码失败");
            }
        }
        /// <summary>
@@ -353,30 +226,10 @@
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult IsPassWordTime()
        [ServiceFilter(typeof(ApiResponseActionFilter))]
        public async Task<int> IsPassWordTime()
        {
            //捕获异常
            try
            {
                //获取当前操作用户id
                var claimsIdentity = this.User.Identity as ClaimsIdentity;
                var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
                int uid = Convert.ToInt32(userId);
                //判断原密码是否正确
                int a = _userInforServer.IsPassWordTime(uid);
                return Ok(new
                {
                    data = a,
                    code = 0,
                    msg = "修改失败"
                });
            }
            catch (Exception ex)
            {
                //抛出异常
                throw new Exception("修改密码异常", ex);
            }
            return await _userInforServer.IsPassWordTime(_userManager.UserId);
        }
        #endregion
@@ -1283,7 +1136,7 @@
                matedto.CreateUser = uid;
                //新增
                int i = await _mate.AddMate(matedto);
                await _operation.InsertOperation("基础信息", "物料管理", matedto.SkuNo, "添加", "添加物料信息 物料号:" + matedto.SkuNo, uid);
                return Ok(new { data = i, code = 0, msg = "成功" });
@@ -1291,7 +1144,7 @@
            catch (Exception ex)
            {
                //抛出异常 
                return Ok(new { code = 1, msg = "新增物料异常"+ ex.Message });
                return Ok(new { code = 1, msg = "新增物料异常" + ex.Message });
            }
        }
@@ -1385,7 +1238,7 @@
            catch (Exception ex)
            {
                //抛出异
                return Ok(new { code = 1, msg = "编辑物料异常"+ex.Message });
                return Ok(new { code = 1, msg = "编辑物料异常" + ex.Message });
            }
        }
@@ -1612,7 +1465,7 @@
        {
            try
            {
                var bolls = _customerSvc.GetCustomerList(model.CustomerNo,model.CustomerName, model.Type, model.LinkMan, model.Phone, model.Page, model.Limit, out int count);
                var bolls = _customerSvc.GetCustomerList(model.CustomerNo, model.CustomerName, model.Type, model.LinkMan, model.Phone, model.Page, model.Limit, out int count);
                return Ok(new { code = 0, count, msg = "客户信息", data = bolls });
            }