using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; using System.Threading.Tasks; using WMS.Web.Core.Dto.OutStock; using WMS.Web.Core.Dto.ProductInventory; using WMS.Web.Core.Dto.SingleData; using WMS.Web.Core.Internal.Results; using WMS.Web.Domain.Infrastructure; using WMS.Web.Domain.IService.Public; using WMS.Web.Domain.Services.Public; using WMS.Web.Domain.Values; using WMS.Web.Repositories; using WMS.Web.Core; using WMS.Web.Domain.IService; using WMS.Web.Domain.Options; using Google.Protobuf.WellKnownTypes; using WMS.Web.Domain.Services; using Microsoft.Extensions.Options; using System.Linq; using WMS.Web.Core.Dto; namespace WMS.Web.Api.Controllers { /// /// 成品仓即时库存 /// [Route("api/[controller]")] [ApiController] public class ProductInventoryController : ControllerBase { private readonly ILoginService _loginService; private readonly IBasicsRepositories _basicsRepositories; private readonly IProductInventoryRepositories _repositories; private readonly QiniuOptions _option; private readonly IExportExcelService _exportExcelService; private readonly IProductInventoryService _roductInventoryService; public ProductInventoryController(ILoginService loginService, IBasicsRepositories basicsRepositories, IProductInventoryRepositories repositories, IOptions option, IExportExcelService exportExcelServic, IProductInventoryService roductInventoryService) { _loginService = loginService; _basicsRepositories = basicsRepositories; _repositories = repositories; _option = option?.Value; _exportExcelService = exportExcelServic; _roductInventoryService = roductInventoryService; } /// /// 获取仓库 /// /// 仓库模糊匹配 不必填 /// [HttpGet] [Route("GetUcStock")] public async Task> GetUcStock([FromQuery] string name) { var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]); if (loginInfo == null || loginInfo.UserInfo == null) return ResultList.ReFailure(ResultCodes.Token_Invalid_Error); var r = await _basicsRepositories.GetUcStockByHeadOfficeAsync(name, loginInfo.UserInfo.CompanyId); var response = r.Where(w => w.ManagementSystem == 1 || w.ManagementSystem == 4 || (w.ManagementSystem == 2 && !string.IsNullOrEmpty(w.WarehouseCodeOfJushuitan)) ||(w.ManagementSystem == 3 && !string.IsNullOrEmpty(w.WarehouseCodeOfLingxing))).ToList(); return ResultList.ReSuccess(r); } /// /// 列表 /// /// /// [HttpPost] [Route("GetList")] public async Task> GetPagedList([FromBody] ProductInventoryQueryRequest dto) { var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]); if (loginInfo == null || loginInfo.UserInfo == null) return ResultPagedNumber2List.ReFailure(ResultCodes.Token_Invalid_Error); var (list, count, details) = await _repositories.GetListAsync(dto); var result = ResultPagedNumber2List.ReSuccess(list,count,details); return result; } /// /// 导出 /// /// /// [HttpPost] [Route("Export")] public Task> Export([FromBody] ProductInventoryQueryRequest dto) { var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]); if (loginInfo == null) return Task.FromResult(Result.ReFailure(ResultCodes.Token_Invalid_Error)); string fileName = FileDownLoadOrderType.ProductInventory.GetRemark() + loginInfo.UserInfo.CompanyId + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx"; string res = _option.Url + fileName; Task.Run(async () => { await _exportExcelService.ExportList(dto, fileName, loginInfo.UserInfo.StaffId, loginInfo.UserInfo.CompanyId, FileDownLoadOrderType.ProductInventory); }); return Task.FromResult(Result.ReSuccess(res)); } /// /// 刷新数据 /// /// [HttpPost] [Route("Refresh")] public async Task Refresh() { var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]); if (loginInfo == null || loginInfo.UserInfo == null) return Result.ReFailure(ResultCodes.Token_Invalid_Error); return await _roductInventoryService.Refresh(); } } }