using HH.WCS.Mobox3.ZS7412.device;
|
using HH.WCS.Mobox3.ZS7412.process;
|
using HH.WCS.Mobox3.ZS7412.util;
|
using HH.WCS.Mobox3.ZS7412.wms;
|
using Newtonsoft.Json;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Threading;
|
using static HH.WCS.Mobox3.ZS7412.api.ApiModel;
|
using static HH.WCS.Mobox3.ZS7412.api.OtherModel;
|
|
namespace HH.WCS.Mobox3.ZS7412.api {
|
/// <summary>
|
/// api接口辅助类
|
/// </summary>
|
public class ApiHelper {
|
static ApiHelper() {
|
|
}
|
/// <summary>
|
/// 创建任务
|
/// </summary>
|
/// <param name="model"></param>
|
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, "");
|
}
|
|
}
|
}
|
/// <summary>
|
/// 创建入库单主子表
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
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<PutawayDetail>();
|
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;
|
}
|
|
/// <summary>
|
/// 创建发货单主子表
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
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<ShippingDetail>();
|
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;
|
}
|
|
|
|
|
/// <summary>
|
/// pad入库
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
internal static SimpleResult Instock(InstockInfo model) {
|
var result = new SimpleResult();
|
//pda入库
|
//1 判断起点有没有任务,有没有入库锁
|
var loc = LocationHelper.GetLoc(model.start);
|
if (loc != null && loc.N_LOCK_STATE == 0) {
|
//2 根据终点库区计算终点
|
var end = WMSHelper.GetInstockEnd(model.item, model.endArea);
|
if (end != null) {
|
var cntrCode = ContainerHelper.GenerateCntrNo();
|
var wcsTask = new WCSTask
|
{
|
S_OP_NAME = "入库",
|
S_CODE = WCSHelper.GenerateTaskNo(),
|
S_TYPE = "下线入库",
|
S_START_LOC = model.start,
|
S_END_LOC = end.S_CODE,
|
S_SCHEDULE_TYPE = "NDC",
|
N_CNTR_COUNT = 1,
|
S_CNTR_CODE = cntrCode,
|
N_START_LAYER = 1,
|
N_END_LAYER = end.N_CURRENT_NUM + 1
|
};
|
if (ContainerHelper.BindNewCntrItem(model.start,cntrCode, model.item) && WCSHelper.CreateTask(wcsTask)) {
|
LocationHelper.LockLoc(model.start, 2);
|
LocationHelper.LockLoc(end.S_CODE, 1);
|
result.resultCode = 0;
|
result.resultMsg = $"任务创建成功,任务号为{wcsTask.S_CODE},终点为{end.S_CODE}";
|
}
|
}
|
else {
|
result.resultCode = 2;
|
result.resultMsg = "未获取到入库终点";
|
}
|
}
|
else {
|
result.resultCode = 1;
|
result.resultMsg = "起点有任务未完成";
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 移库
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
internal static SimpleResult shiftStock(ShiftStockInfo model)
|
{
|
var result = new SimpleResult();
|
//1 根据起点库区、排 确定起始货位
|
var startLoc = WMSHelper.GetShiftStockStart(model.item, model.startArea, model.startRow);
|
if (startLoc != null && startLoc.N_LOCK_STATE == 0)
|
{
|
//2 根据终点库区计算终点
|
var end = WMSHelper.GetShiftStockEnd(model.item, model.endArea, model.startRow);
|
if (end != null && end.N_LOCK_STATE == 0)
|
{
|
var wcsTask = new WCSTask
|
{
|
S_OP_NAME = "移库",
|
S_CODE = WCSHelper.GenerateTaskNo(),
|
S_TYPE = "移库",
|
S_START_LOC = startLoc.S_CODE,
|
S_END_LOC = end.S_CODE,
|
S_SCHEDULE_TYPE = "NDC",
|
N_CNTR_COUNT = 1,
|
S_CNTR_CODE = startLoc.LocCntrRel.S_CNTR_CODE,
|
N_START_LAYER = startLoc.N_CURRENT_NUM,
|
N_END_LAYER = end.N_CURRENT_NUM + 1
|
};
|
if (WCSHelper.CreateTask(wcsTask))
|
{
|
LocationHelper.LockLoc(startLoc.S_CODE, 2);
|
LocationHelper.LockLoc(end.S_CODE, 1);
|
result.resultCode = 0;
|
result.resultMsg = $"任务创建成功,任务号为{wcsTask.S_CODE},终点为{end.S_CODE}";
|
}
|
}
|
else
|
{
|
result.resultCode = 2;
|
result.resultMsg = "未获取到移库终点";
|
}
|
}
|
else
|
{
|
result.resultCode = 1;
|
result.resultMsg = "未获取到移库起点";
|
}
|
return result;
|
}
|
|
internal static CodeInfo GetCodeInfo(string code, string org) {
|
//return new CodeInfo { Fitemid_XK=code, FSourceNo="123456"};
|
CodeInfo result = null;
|
try {
|
var db = new SqlHelper<object>().GetInstance(Settings.SqlServer1);
|
var nameP = new SugarParameter("@FBarCode", code);
|
var orgP = new SugarParameter("@Forg", org);
|
//var ageP = new SugarParameter("@age", null, true);//设置为output
|
//var dt = db.Ado.UseStoredProcedure().GetDataTable("sp_school", nameP, ageP);//返回dt
|
result = db.Ado.UseStoredProcedure().SqlQuery<CodeInfo>("WMS_FBarCode", nameP, orgP).First();//返回List
|
Console.WriteLine($"读存储过程成功,result={result}");
|
}
|
catch (Exception ex) {
|
Console.WriteLine(ex.Message);
|
}
|
return result;
|
}
|
|
|
|
|
public class AddTaskModel {
|
public string From { get; set; }
|
public string To { get; set; }
|
public string No { get; set; }
|
}
|
public class TN_LocationModel {
|
public string TN_Location { get; set; }
|
}
|
public class CodeInfo {
|
/// <summary>
|
/// 生产订单内码
|
/// </summary>
|
public string FInterID { get; set; }
|
/// <summary>
|
/// 生产订单编号
|
/// </summary>
|
public string FSourceNo { get; set; }
|
/// <summary>
|
/// 批号
|
/// </summary>
|
public string FGMPBatchNo { get; set; }
|
public string FState { get; set; }
|
/// <summary>
|
/// 物料编码(内码就是编码)
|
/// </summary>
|
public string Fitemid_XK { get; set; }
|
/// <summary>
|
/// 分录id
|
/// </summary>
|
public string Fentryid { get; set; }
|
}
|
public class NoteInfo : CodeInfo {
|
public string WmsBillNo { get; set; }
|
}
|
}
|
}
|