using PadApplication.DB;
using PadApplication.Entites.DbModels;
using PadApplication.Entites.Dto;
using System.Net.Http;
using System.Text;
using Newtonsoft.Json;
using SqlSugar;
namespace PadApplication.Services;
///
/// 工单状态管理类,负责工单状态相关的数据操作
/// 继承自Repository基类,包含基础的CRUD操作
///
public class MesCutterLedgerManager : Repository
{
//private readonly MesQaItemsDetect02Manager
//mesQaItemsDetect02Manager = new();
///
/// 刀具查询(支持编号或名称模糊查询)
///
/// 查询关键字
/// 页码
/// 每页大小
/// 刀具查询结果
public MesCutterLedger QueryTools(string searchKey, int pageIndex, int pageSize)
{
var query = Db.Queryable()
.WhereIF(!string.IsNullOrEmpty(searchKey),
t => t.CutterId.Contains(searchKey) || t.CutterName.Contains(searchKey));
var total = query.Count();
var tbBillList = query
.OrderBy(t => t.CutterId)
.ToPageList(pageIndex, pageSize, ref total); // 使用ToPageList分页
return new MesCutterLedger
{
tbBillList = tbBillList,
total = total
};
}
///
/// 上下刀操作(上刀type=0,下刀type=1)
/// 仅负责参数转发,所有数据写入由存储过程完成。
///
/// 工单号
/// 机台编号
/// 刀具编号
/// 操作类型(上刀、下刀)
/// 使用上限
/// 存储过程执行结果
public object SubmitToolAction(string workOrderNo, string machineNo, string toolNo, string type, int? useLimit)
{
var parameters = new[]
{
new SugarParameter("V_WORK_ORDER_NO", workOrderNo),
new SugarParameter("V_MACHINE_NO", machineNo),
new SugarParameter("V_TOOL_NO", toolNo),
new SugarParameter("V_TYPE", type), // string 类型
new SugarParameter("V_USE_LIMIT", useLimit ?? (object)DBNull.Value)
};
try
{
var result = Db.Ado.SqlQuery