using JSMachine.WMS.App.Dto; using JSMachine.WMS.App.IService; using JSMachine.WMS.Common.Dto.Business; using JSMachine.WMS.RPC.ErpRPC.Dto.Out; using JSMachine.WMS.WebHost.Models; using Microsoft.AspNetCore.Mvc; using SqlSugar; namespace JSMachine.WMS.WebHost.Controllers { [Route("api/[controller]/[action]")] public class UserInfoController : ControllerBase { private readonly IUserInfoService _userInfoService; public UserInfoController(IUserInfoService userInfoService) { _userInfoService = userInfoService; } /// /// 获取所有用户信息 /// /// [HttpGet] public async Task>> GetAll() { var users = await _userInfoService.GetListByExpression(p => true, nameof(UserInfoDto.CreationTime), OrderByType.Desc); return new ApiResult> { ResultCode = "200", Data = users }; } /// /// 根据ID获取用户信息 /// /// 用户ID /// [HttpGet("{id}")] public async Task> GetById(Guid id) { var user = await _userInfoService.GetSingalByExpression(p => p.Id == id); if (user == null) { return new ApiResult { ResultCode = "404", ErrorMsg = "用户不存在" }; } return new ApiResult { ResultCode = "200", Data = user }; } /// /// 创建新用户 /// /// 用户信息 /// [HttpPost] public async Task> Create([FromBody] UserInfoDto userDto) { if (userDto == null) { return new ApiResult { ResultCode = "400", ErrorMsg = "请求参数不能为空" }; } var result = await _userInfoService.Add(userDto); return new ApiResult { ResultCode = "200", Data = result }; } /// /// 更新用户信息 /// /// 用户ID /// 更新后的用户信息 /// [HttpPut("{id}")] public async Task> Update(Guid id, [FromBody] UserInfoDto userDto) { if (userDto == null) { return new ApiResult { ResultCode = "400", ErrorMsg = "请求参数不能为空" }; } var existingUser = await _userInfoService.GetSingalByExpression(p => p.Id == id); if (existingUser == null) { return new ApiResult { ResultCode = "404", ErrorMsg = "用户不存在" }; } // 更新用户信息 var result = await _userInfoService.EditSingal(userDto); return new ApiResult { ResultCode = "200", Data = result }; } /// /// 删除用户 /// /// 用户ID /// [HttpDelete("{id}")] public async Task> Delete(Guid id) { var existingUser = await _userInfoService.GetSingalByExpression(p => p.Id == id); if (existingUser == null) { return new ApiResult { ResultCode = "404", ErrorMsg = "用户不存在" }; } var result = await _userInfoService.DeleteById(id); return new ApiResult { ResultCode = "200", Data = result }; } [HttpPost] public async Task> Login([FromBody] UserInfoDto userInfo) { if (userInfo == null || string.IsNullOrEmpty(userInfo.UserId) || string.IsNullOrEmpty(userInfo.Password)) return new ApiResult { ResultCode = "500", ErrorMsg = "参数不合法" }; UserInfoDto validUser = await _userInfoService.GetSingalByExpression(p=>p.UserId== userInfo.UserId&&p.Password== userInfo.Password); if (validUser == null) return new ApiResult { ResultCode = "500", ErrorMsg = "用户名或密码错误" }; return new ApiResult { ResultCode="200",Data=new UserPermission {Token=Guid.NewGuid().ToString("N"),UserInfo= validUser } }; } } }