123 lines
5.3 KiB
C#
123 lines
5.3 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 成品仓即时库存
|
|
/// </summary>
|
|
[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<QiniuOptions> option,
|
|
IExportExcelService exportExcelServic, IProductInventoryService roductInventoryService) {
|
|
_loginService = loginService;
|
|
_basicsRepositories = basicsRepositories;
|
|
_repositories = repositories;
|
|
_option = option?.Value;
|
|
_exportExcelService = exportExcelServic;
|
|
_roductInventoryService = roductInventoryService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取仓库
|
|
/// </summary>
|
|
/// <param name="name">仓库模糊匹配 不必填</param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("GetUcStock")]
|
|
public async Task<ResultList<UcStockHeadOfficeResponse>> GetUcStock([FromQuery] string name)
|
|
{
|
|
var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]);
|
|
if (loginInfo == null || loginInfo.UserInfo == null)
|
|
return ResultList<UcStockHeadOfficeResponse>.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<UcStockHeadOfficeResponse>.ReSuccess(r);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 列表
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("GetList")]
|
|
public async Task<ResultPagedNumber2List<ProductInventoryQueryResponse>> GetPagedList([FromBody] ProductInventoryQueryRequest dto)
|
|
{
|
|
var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]);
|
|
if (loginInfo == null || loginInfo.UserInfo == null)
|
|
return ResultPagedNumber2List<ProductInventoryQueryResponse>.ReFailure(ResultCodes.Token_Invalid_Error);
|
|
|
|
var (list, count, details) = await _repositories.GetListAsync(dto);
|
|
var result = ResultPagedNumber2List<ProductInventoryQueryResponse>.ReSuccess(list,count,details);
|
|
return result;
|
|
}
|
|
/// <summary>
|
|
/// 导出
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("Export")]
|
|
public Task<Result<string>> Export([FromBody] ProductInventoryQueryRequest dto)
|
|
{
|
|
var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]);
|
|
if (loginInfo == null)
|
|
return Task.FromResult(Result<string>.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<ProductInventoryQueryResponse, ProductInventoryQueryRequest>(dto, fileName, loginInfo.UserInfo.StaffId, loginInfo.UserInfo.CompanyId, FileDownLoadOrderType.ProductInventory);
|
|
});
|
|
|
|
return Task.FromResult(Result<string>.ReSuccess(res));
|
|
}
|
|
/// <summary>
|
|
/// 刷新数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("Refresh")]
|
|
public async Task<Result> 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();
|
|
}
|
|
}
|
|
}
|