using JiepeiWMS.Common.HttpContextUser; using JiepeiWMS.Extends; using JiepeiWMS.IServices; using JiepeiWMS.Model; using JiepeiWMS.Model.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System; using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; namespace JiepeiWMS.Api.Controllers { [Route("api/[controller]/[action]")] [ApiController] [Authorize(Permissions.Name)] public class WMProductLocationController : ControllerBase { /// /// 商品库位 /// private readonly IWMProductLocationServices _wMProductLocationServices; private readonly ISysUserInfoServices _sysUserInfoServices; private readonly ISysOrgServices _BllSysOrg; readonly IUser _user; public WMProductLocationController(IWMProductLocationServices WMProductLocationServices, ISysUserInfoServices SysUserInfoServices, ISysOrgServices BllSysOrg, IUser user) { _wMProductLocationServices = WMProductLocationServices; _sysUserInfoServices = SysUserInfoServices; _BllSysOrg = BllSysOrg; _user = user; } /// /// 查询列表 /// /// 页数 /// 关键字 /// 条数 /// [HttpGet] public async Task>> Index(int page = 1, string key = "", int intPageSize = 20) { if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key)) { key = ""; } Expression> whereExpression = s => s.Id > 0; //筛选主体Id var userInfoModel = await _sysUserInfoServices.QueryById(_user.ID); if (userInfoModel != null) { whereExpression = whereExpression.And(s => s.SysOrgId == userInfoModel.SysOrgId); } if (!string.IsNullOrWhiteSpace(key)) { whereExpression = whereExpression.And(s => s.LocationName != null && s.LocationName.Contains(key.Trim())); } var productLocation = await _wMProductLocationServices.QueryPage(whereExpression, page, intPageSize, " Id desc "); foreach (var item in productLocation.data) { var UserInfoModel = await _sysUserInfoServices.QueryById(item.AdminId); if (UserInfoModel != null) { item.AdminName = UserInfoModel.uRealName; } } return new MessageModel>() { msg = "获取成功", success = productLocation.dataCount >= 0, response = productLocation }; } /// /// 获取列表 /// /// [HttpGet] [AllowAnonymous] public async Task> Get(int id = 0) { var locationList = await _wMProductLocationServices.Query(x => x.IsUse == true); locationList = locationList.Where(x => x.SysOrgId == _user.SysOrgId).ToList(); return new MessageModel() { msg = "获取成功", success = true, response = new { locationList } }; } /// /// 添加 /// /// /// [HttpPost] public async Task> Add([FromBody] WMProductLocation request) { var data = new MessageModel(); var ProductLocation = await _wMProductLocationServices.GetModel(w => w.LocationName == request.LocationName); if (ProductLocation != null) { data.msg = "库位名称已存在"; return data; } request.AdminId = _user.ID; request.CreateTime = DateTime.Now; request.LocationNumFree = request.LocationStockNum; request.SysOrgId = _user.SysOrgId; var id = await _wMProductLocationServices.Add(request); data.success = id > 0; if (data.success) { data.response = id.ObjToString(); data.msg = "添加成功"; } return data; } /// /// 更新 /// /// /// [HttpPut] public async Task> Update([FromBody] WMProductLocation request) { var data = new MessageModel(); if (request.Id > 0) { var ProductLocation = await _wMProductLocationServices.GetModel(w => w.LocationName == request.LocationName && w.Id != request.Id); if (ProductLocation != null) { data.msg = "库位名称已存在"; return data; } request.UpdateTime = DateTime.Now; request.LocationNumFree = request.LocationStockNum; data.success = await _wMProductLocationServices.Update(request); if (data.success) { data.msg = "更新成功"; data.response = request?.Id.ObjToString(); } } return data; } /// /// 删除 /// /// /// //[HttpDelete] //public async Task> Delete(int id = 0) //{ // var data = new MessageModel(); // if (id > 0) // { // var detail = await _wMProductLocationServices.QueryById(id); // detail.IsUse = false; // if (detail != null) // { // data.success = await _wMProductLocationServices.Update(detail); // if (data.success) // { // data.msg = "删除成功"; // data.response = detail?.Id.ObjToString(); // } // } // } // return data; //} } }