using System.Dynamic;
|
using Microsoft.AspNetCore.Mvc;
|
using PadApplication.Entites.DbModels;
|
using PadApplication.Entites.Dto;
|
using PadApplication.Services;
|
using PadApplication.util;
|
|
namespace PadApplication.Controllers;
|
|
/// <summary>
|
/// 刀具台账控制器,提供刀具相关的接口
|
/// </summary>
|
[ApiController]
|
[Route("api/[controller]")]
|
[Route("[controller]")] // 允许 /MesCutterLedger/... 形式的路由,兼容前端当前写法
|
public class MesCutterLedgerController : ControllerBase
|
{
|
private readonly MesCutterLedgerManager m = new();
|
|
// 加入 sdjs、xdjs 为可空 decimal,保持与前端 JSON 字段名一致
|
public record ToolActionRequest(
|
string workOrderNo,
|
string machineNo,
|
string toolNo,
|
string type,
|
int? useLimit,
|
decimal? sdjs,
|
decimal? xdjs
|
);
|
|
public record FormDataRequest(
|
string workOrderNo,
|
string machineNo
|
);
|
|
/// <summary>
|
/// 刀具查询(支持编号或名称模糊查询)MesCutterLedger
|
/// </summary>
|
/// <param name="req">查询关键字请求体</param>
|
/// <returns>刀具列表</returns>
|
[HttpPost("QueryTools")]
|
public ResponseResult QueryTools([FromBody] MesCutterLedger req)
|
{
|
try
|
{
|
dynamic resultInfos = new ExpandoObject();
|
var queryResult = m.QueryTools(req.searchKey, req.pageIndex, req.pageSize);
|
resultInfos.tbBillList = queryResult.tbBillList;
|
resultInfos.total = queryResult.total;
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = resultInfos
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
|
/// <summary>
|
/// 上下刀操作(上刀type=0,下刀type=1)
|
/// 接收 JSON 请求体(Content-Type: application/json),并将 sdjs/xdjs 一并传入服务层
|
/// </summary>
|
[HttpPost("SubmitToolAction")]
|
public IActionResult SubmitToolAction([FromBody] ToolActionRequest req)
|
{
|
try
|
{
|
var result = m.SubmitToolAction(
|
req.workOrderNo,
|
req.machineNo,
|
req.toolNo,
|
req.type,
|
req.useLimit,
|
req.sdjs,
|
req.xdjs
|
);
|
|
return Ok(new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = result
|
});
|
}
|
catch (Exception ex)
|
{
|
return Ok(ResponseResult.ResponseError(ex));
|
}
|
}
|
|
/// <summary>
|
/// 获取刀具表单数据(根据工单号和机台编码)
|
/// </summary>
|
[HttpPost("GetFormData")]
|
public ResponseResult GetFormData([FromBody] FormDataRequest req)
|
{
|
try
|
{
|
var data = m.GetFormData(req.workOrderNo, req.machineNo);
|
return new ResponseResult
|
{
|
status = 0,
|
message = "OK",
|
data = data
|
};
|
}
|
catch (Exception ex)
|
{
|
return ResponseResult.ResponseError(ex);
|
}
|
}
|
}
|