using JiepeiWMS.Common.HttpContextUser; using JiepeiWMS.IServices; using JiepeiWMS.Model; using JiepeiWMS.Model.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using SqlSugar; using System.Threading.Tasks; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System; using JiepeiWMS.Extends; namespace JiepeiWMS.Api.Controllers { [Route("api/[controller]/[action]")] [ApiController] [Authorize(Permissions.Name)] public class WMWareHouseController : ControllerBase { /// /// 服务器接口,因为是模板生成,所以首字母是大写的,自己可以重构下 /// private readonly IWMWareHouseServices _wMWareHouseServices; private readonly ISysOrgServices _BllSysOrg; private readonly IUser _user; private readonly ISysUserInfoServices _sysUserInfoServices; /// /// /// /// /// public WMWareHouseController(IWMWareHouseServices WMWareHouseServices, ISysOrgServices BllSysOrg, IUser user, ISysUserInfoServices SysUserInfoServices) { _wMWareHouseServices = WMWareHouseServices; _BllSysOrg = BllSysOrg; _user = user; _sysUserInfoServices = SysUserInfoServices; } /// /// 仓库管理分页查询 /// /// /// /// /// [HttpGet] public async Task>> Get(int page = 1, string key = "", int intPageSize = 10) { if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key)) { key = ""; } //var data = await _wMWareHouseServices.QueryPage(a => a.Type >= 0 && ((a.Name != null && a.Name.Contains(key))), page, intPageSize, " Id desc "); Expression> whereExpression = wmw => wmw.Id > 0; //筛选主体Id whereExpression = whereExpression.And(wmw => wmw.SysOrgId == _user.SysOrgId); if (!string.IsNullOrWhiteSpace(key)) { whereExpression = whereExpression.And(wmw => wmw.Name != null && wmw.Name.Contains(key.Trim()) && wmw.IsUse != false); } var PageList = await _wMWareHouseServices.QueryTabsPage( (wmw, u) => new object[] { JoinType.Left,wmw.AdminId==u.uID }, (wmw, u) => new WMWareHouse() { Id = wmw.Id, Name = wmw.Name, Sort = wmw.Sort, Type = wmw.Type, IsUse = wmw.IsUse, CreateTime = wmw.CreateTime, UpdateTime = wmw.UpdateTime, AdminName = u.uRealName, Remark = wmw.Remark, SysOrgId = wmw.SysOrgId }, whereExpression, page, intPageSize, " Id desc" ); return new MessageModel>() { msg = "获取成功", success = PageList.dataCount > 0, response = PageList }; } /// /// 获取列表 /// /// [HttpGet] [AllowAnonymous] public async Task> GetList(int id = 0) { var wareHouseList = await _wMWareHouseServices.Query(x => x.IsUse == true); wareHouseList = wareHouseList.Where(x => x.SysOrgId == _user.SysOrgId).ToList(); return new MessageModel() { msg = "获取成功", success = true, response = new { wareHouseList } }; } /// /// 仓库管理添加操作 /// /// /// [HttpPost] public async Task> Post([FromBody] WMWareHouse WareHouseInfo) { var data = new MessageModel(); WareHouseInfo.AdminId = _user.ID; WareHouseInfo.SysOrgId = _user.SysOrgId; var id = await _wMWareHouseServices.Add(WareHouseInfo); data.success = id > 0; if (data.success) { data.response = id.ObjToString(); data.msg = "添加成功"; } return data; } /// /// 仓库管理编辑 /// /// /// [HttpPut] public async Task> Put([FromBody] WMWareHouse request) { var data = new MessageModel(); if (request.Id > 0) { data.success = await _wMWareHouseServices.Update(request); if (data.success) { data.msg = "更新成功"; data.response = request?.Id.ObjToString(); } } return data; } /// /// 仓库管理删除操作 /// /// /// [HttpDelete] public async Task> Delete(int id) { var data = new MessageModel(); if (id > 0) { var detail = await _wMWareHouseServices.QueryById(id); detail.IsUse = false; if (detail != null) { data.success = await _wMWareHouseServices.Update(detail); if (data.success) { data.msg = "删除成功"; data.response = detail?.Id.ObjToString(); } } } return data; } } }