using PadApplication.DB;
using PadApplication.Entites.DbModels;
using PadApplication.Entites.Dto;
using System.Net.Http;
using System.Text;
using Newtonsoft.Json;
using SqlSugar;
using System.Data;
using System.Dynamic;
using SystemDataDbType = System.Data.DbType;
using Oracle.ManagedDataAccess.Client; // 新增:直接使用 Oracle 客户端以显式传递 RefCursor
namespace PadApplication.Services;
///
/// 工单状态管理类,负责工单状态相关的数据操作
/// 继承自Repository基类,包含基础的CRUD操作
///
public class MesCutterLedgerManager : Repository
{
//private readonly MesQaItemsDetect02Manager
//mesQaItemsDetect02Manager = new();
///
/// 刀具查询(支持编号或名称模糊查询)
/// 上机、报废、维修出库不查询
///
/// 查询关键字
/// 页码
/// 每页大小
/// 刀具查询结果
public MesCutterLedger QueryTools(string searchKey, int pageIndex, int pageSize)
{
var excludeTypes = new[] { "上机", "报废", "维修出库" };
var query = Db.Queryable()
.Where(t => !excludeTypes.Contains(t.CutterType))
.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,
decimal? sdjs = null,
decimal? xdjs = null,
decimal? modlLifeWorning = null) // 新增:寿命比预警值(0~1的小数)
{
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),
new SugarParameter("V_USE_LIMIT", useLimit ?? (object)DBNull.Value),
new SugarParameter("V_SDJS", sdjs ?? (object)DBNull.Value),
new SugarParameter("V_XDJS", xdjs ?? (object)DBNull.Value),
new SugarParameter("PO_OUTMSG", null) { Direction = ParameterDirection.Output, DbType = System.Data.DbType.String, Size = 200 },
new SugarParameter("PO_OUTSUM", null) { Direction = ParameterDirection.Output, DbType = System.Data.DbType.Int32 },
new SugarParameter("V_MODL_LIFE_WORNING", modlLifeWorning ?? (object)DBNull.Value) // 新增
};
try
{
Db.Ado.UseStoredProcedure().SqlQuery