using HH.WCS.DaYang.device;
using HH.WCS.DaYang.process;
using HH.WCS.DaYang.util;
using HH.WCS.DaYang.wms;
using Newtonsoft.Json;
using NLog.Fluent;
using Opc.Ua;
using SqlSugar;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using static HH.WCS.DaYang.api.ApiModel;
using static HH.WCS.DaYang.api.OtherModel;
namespace HH.WCS.DaYang.api
{
///
/// api接口辅助类
///
public class ApiHelper
{
static ApiHelper()
{
}
internal static void AddTask(AddTaskModel model)
{
if (!WCSHelper.CheckExist(model.No))
{
if (LocationHelper.CheckExist(model.From) && LocationHelper.CheckExist(model.To))
{
WCSHelper.CreateTask(model.No, model.From, model.To, "搬运", 99, "");
}
}
}
internal static SimpleResult Putaway_Order_In(Putaway_Order_In model)
{
var result = new SimpleResult();
//创建入库单主子表
var po = WMSHelper.GetPutawayOrder(model.Data.arrival_no);
if (po == null)
{
po = new PutawayOrder { S_NO = model.Data.arrival_no, S_BS_TYPE = model.Data.op_type };
po.Details = new List();
if (model.Data.items.Count > 0)
{
model.Data.items.ForEach(a =>
{
po.Details.Add(new PutawayDetail
{
S_PUTAWAY_NO = model.Data.arrival_no,
N_ROW_NO = po.Details.Count + 1,
S_ITEM_CODE = a.item_code,
F_QTY = a.qty,
S_BATCH_NO = a.batch_no,
});
});
WMSHelper.CreatePutawayOrder(po);
}
}
return result;
}
internal static SimpleResult PalletSorting(PalletSorting model)
{
var result = new SimpleResult();
//校验入库单数量,不可以超,成功后插入托盘物料表,更新入库单累计数量
//也可以直接lua查询入库单数量,做校验
var info = WMSHelper.GetPutawayOrderDetail(model.arrival_no, model.item_code);
if (info != null)
{
if (info.F_QTY - info.F_ACC_B_QTY >= model.qty)
{
// 插入到托盘明细表
var cntr = ContainerHelper.GetCntr(model.cntr_code, true);
if (cntr != null)
{
ContainerHelper.BindCntrItem(cntr, model.item_code, info.S_BATCH_NO, model.qty, model.arrival_no);
//更新入库单累计绑定数量
info.F_ACC_B_QTY += model.qty;
WMSHelper.UpdatePutawayOrderDetailQty(info);
}
else
{
result.resultCode = 2;
result.resultMsg = "获取托盘信息失败";
}
}
else
{
result.resultCode = 1;
result.resultMsg = "累计码盘数量超出入库单数量";
}
}
else
{
result.resultCode = 3;
result.resultMsg = $"未找到入库单{model.arrival_no}";
}
return result;
}
internal static SimpleResult OutboundOrder(OutboundOrder model)
{
var result = new SimpleResult();
//创建发货单,人工点确认后生成分拣单,没有缺货的自动更新为失败,有货的更新为执行中
//创建入库单主子表
var po = WMSHelper.GetShippingOrder(model.Data.out_no);
if (po == null)
{
po = new ShippingOrder { S_NO = model.Data.out_no, S_BS_TYPE = model.Data.op_type };
po.Details = new List();
if (model.Data.items.Count > 0)
{
model.Data.items.ForEach(a =>
{
po.Details.Add(new ShippingDetail
{
S_SHIPPING_NO = model.Data.out_no,
N_ROW_NO = po.Details.Count + 1,
S_ITEM_CODE = a.item_code,
F_QTY = a.qty,
S_BATCH_NO = a.batch_no,
});
});
WMSHelper.CreateShippingOrder(po);
}
}
return result;
}
private static object lockObj = new object();
///
/// 创建任务
///
///
///
internal static Result createtask(CreateTaskModel model)
{
Result result = new Result { Code = 0, Msg = "创建成功" };
if (model == null)
{
result.Code = -1;
result.Msg = "入参为空";
return result;
}
var db = new SqlHelper