using System.Dynamic;
|
using MES.Service.Dto.webApi;
|
using MES.Service.Modes;
|
using MES.Service.service.Warehouse;
|
using MES.Service.util;
|
using Microsoft.AspNetCore.Mvc;
|
|
namespace MESApplication.Controllers.Warehouse;
|
|
[ApiController]
|
[Route("api/[controller]")]
|
public class MesInvItemStocksController : ControllerBase
|
{
|
private readonly MesInvItemStocksManager m = new();
|
|
/// <summary>
|
/// 获取可退货物料库存(旧版本,保留兼容)
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost("GetReturnableStocks")]
|
public ResponseResult GetReturnableStocks()
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
resultInfos.tbBillList = m.GetReturnableStocks();
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
/// <summary>
|
/// 获取可退货物料库存(带分页和搜索)
|
/// </summary>
|
/// <param name="searchDto">搜索请求参数</param>
|
/// <returns></returns>
|
[HttpPost("GetReturnableStocksWithPaging")]
|
public ResponseResult GetReturnableStocksWithPaging([FromBody] ReturnableStockSearchDto searchDto)
|
{
|
try
|
{
|
var result = m.GetReturnableStocks(searchDto);
|
return new ResponseResult
|
{
|
status = 0,
|
message = "查询成功",
|
data = result
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
/// <summary>
|
/// 生成退料请求单
|
/// </summary>
|
/// <param name="dto">退料请求参数</param>
|
/// <returns></returns>
|
[HttpPost("CreateReturnMaterialRequest")]
|
public ResponseResult CreateReturnMaterialRequest([FromBody] ItemStockQueryDto dto)
|
{
|
try
|
{
|
var result = m.CreateReturnMaterialRequest(dto);
|
if (result)
|
{
|
return new ResponseResult
|
{
|
status = 0,
|
message = "退料请求单生成成功",
|
data = null
|
};
|
}
|
else
|
{
|
return new ResponseResult
|
{
|
status = 1,
|
message = "退料请求单生成失败",
|
data = null
|
};
|
}
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
/// <summary>
|
/// 导出可退货物料库存为Excel
|
/// </summary>
|
/// <param name="searchDto">搜索请求参数</param>
|
/// <returns>Excel文件</returns>
|
[HttpPost("ExportReturnableStocks")]
|
public IActionResult ExportReturnableStocks([FromBody] ReturnableStockSearchDto searchDto)
|
{
|
try
|
{
|
var fileBytes = m.ExportReturnableStocksToExcel(searchDto);
|
var fileName = $"可退货物料库存_{DateTime.Now:yyyyMMddHHmmss}.xlsx";
|
|
return File(fileBytes,
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
fileName);
|
}
|
catch (Exception ex)
|
{
|
return BadRequest(new ResponseResult
|
{
|
status = 1,
|
message = $"导出失败: {ex.Message}",
|
data = null
|
});
|
}
|
}
|
}
|