using HH.WCS.Mobox3.SXJK.core; using HH.WCS.Mobox3.SXJK.device; using HH.WCS.Mobox3.SXJK.models; using HH.WCS.Mobox3.SXJK.process; using HH.WCS.Mobox3.SXJK.util; using HH.WCS.Mobox3.SXJK.wms; using Newtonsoft.Json; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Threading; using static HH.WCS.Mobox3.SXJK.api.ApiModel; using static HH.WCS.Mobox3.SXJK.api.OtherModel; using static HH.WCS.Mobox3.SXJK.api.WmsController; using static HH.WCS.Mobox3.SXJK.api.WmsController.PutawayOrderIn; namespace HH.WCS.Mobox3.SXJK.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 bool putawayOrderSync(PutawayOrderIn model) { bool result = false; //创建入库单主子表 var po = WMSHelper.GetInStockList(model.ASNNo); if (po == null) { po = new InStockList() { S_ORGANIZATION_ID = model.organizationId, S_WAREHOUSE_ID = model.warehouseId, S_CUSTOMER_ID = model.customerId, S_ASN_NO = model.ASNNo, S_ASN_TYPE = model.ASNType, S_ASN_STATUS = model.asnStatus, S_ASN_REFERENCE1 = model.asnReference1, UDF01 = model.udf01, UDF02 = model.udf02, UDF03 = model.udf03, UDF04 = model.udf04, UDF05 = model.udf05, }; po.Details = new List(); if (model.Details.Count > 0) { model.Details.ForEach(a => { po.Details.Add(new InStockListChild { S_ASN_NO = a.ASNNo, S_SKU = a.sku, S_SKU_DESCR = a.skuDescr, N_QTY = float.Parse(a.qty), S_TRACE_ID = a.traceId, S_SERIAL_NO = a.serialNo, S_CONTAINER_WEIGHT = a.containerWeight == "" ? 0 : int.Parse(a.containerWeight), LOTATT01 = a.lotAtt01, LOTATT02 = a.lotAtt02, LOTATT03 = a.lotAtt03, LOTATT04 = a.lotAtt04, LOTATT05 = a.lotAtt05, LOTATT06 = a.lotAtt06, LOTATT07 = a.lotAtt07, LOTATT08 = a.lotAtt08, LOTATT09 = a.lotAtt09, LOTATT10 = a.lotAtt10, LOTATT11 = a.lotAtt11, LOTATT12 = a.lotAtt12, LOTATT13 = a.lotAtt13, LOTATT14 = a.lotAtt14, LOTATT15 = a.lotAtt15, LOTATT16 = a.lotAtt16, LOTATT17 = a.lotAtt17, LOTATT18 = a.lotAtt18 == "" ? "F" : a.lotAtt18, LOTATT19 = a.lotAtt19, LOTATT20 = a.lotAtt20, LOTATT21 = a.lotAtt21, LOTATT22 = a.lotAtt22, LOTATT23 = a.lotAtt23, LOTATT24 = a.lotAtt24 }); }); result = WMSHelper.CreateInStockList(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 bool outboundOrderSync(OutBoundOrder model) { bool result = false; //创建发货单,人工点确认后生成分拣单,没有缺货的自动更新为失败,有货的更新为执行中 //创建入库单主子表 var po = WMSHelper.GetOutStockList(model.orderNo); if (po == null) { po = new OutStockList() { S_ORGANIZATION_ID = model.organizationId, S_WAREHOUSE_ID = model.warehouseId, S_CUSTOMER_ID = model.customerId, S_ORDER_NO = model.orderNo, S_ORDER_TYPE = model.orderType, S_SO_STATUS = "待执行", S_SO_REFERENCE1 = model.soReference1, UDF01 = model.udf01, UDF02 = model.udf02, UDF03 = model.udf03, UDF04 = model.udf04, UDF05 = model.udf05, }; po.Details = new List(); if (model.Details.Count > 0) { model.Details.ForEach(a => { po.Details.Add(new OutStockListChild { S_ORDER_NO = a.orderNo, S_SKU = a.sku, S_SEQ_NO = a.seqNo, N_QTY = float.Parse(a.qty), LOTATT01 = a.lotAtt01, LOTATT02 = a.lotAtt02, LOTATT03 = a.lotAtt03, LOTATT04 = a.lotAtt04, LOTATT05 = a.lotAtt05, LOTATT06 = a.lotAtt06, LOTATT07 = a.lotAtt07, LOTATT08 = a.lotAtt08, LOTATT09 = a.lotAtt09, LOTATT10 = a.lotAtt10, LOTATT11 = a.lotAtt11, LOTATT12 = a.lotAtt12, LOTATT13 = a.lotAtt13, LOTATT14 = a.lotAtt14, LOTATT15 = a.lotAtt15, LOTATT16 = a.lotAtt16, LOTATT17 = a.lotAtt17, LOTATT18 = a.lotAtt18, LOTATT19 = a.lotAtt19, LOTATT20 = a.lotAtt20, LOTATT21 = a.lotAtt21, LOTATT22 = a.lotAtt22, LOTATT23 = a.lotAtt23, LOTATT24 = a.lotAtt24, UDF01 = a.udf01, UDF02 = a.udf02, UDF03 = a.udf03, UDF04 = a.udf04, UDF05 = a.udf05, }); }); result = WMSHelper.CreateOutStockList(po); } } return result; } /// /// 转移单同步 /// /// /// internal static bool transferOrderSync(TransferOrder model) { bool result = false; // 1.保存 转移单记录 //创建冻结单主子表 var po = WMSHelper.GetTransferList(model.tdocNo); if (po == null) { po = new TransferList() { S_ORGANIZATION_ID = model.organizationId, S_WAREHOUSE_ID = model.warehouseId, S_CUSTOMER_ID = model.customerId, S_TDOC_NO = model.tdocNo, S_TDOC_TYPE = model.tdocType, S_STATUS = model.status }; po.Details = new List(); if (model.Details.Count > 0) { model.Details.ForEach(a => { po.Details.Add(new TransferListChild { S_TDOC_NO = a.tdocNo, S_TRACE_ID = a.traceId, S_SERIAL_NO = a.serialNo, TOLOTATT01 = a.tolotAtt01, TOLOTATT02 = a.tolotAtt02, TOLOTATT03 = a.tolotAtt03, TOLOTATT04 = a.tolotAtt04, TOLOTATT05 = a.tolotAtt05, TOLOTATT06 = a.tolotAtt06, TOLOTATT07 = a.tolotAtt07, TOLOTATT08 = a.tolotAtt08, TOLOTATT09 = a.tolotAtt09, TOLOTATT10 = a.tolotAtt10, TOLOTATT11 = a.tolotAtt11, TOLOTATT12 = a.tolotAtt12, TOLOTATT13 = a.tolotAtt13, TOLOTATT14 = a.tolotAtt14, TOLOTATT15 = a.tolotAtt15, TOLOTATT16 = a.tolotAtt16, TOLOTATT17 = a.tolotAtt17, TOLOTATT18 = a.tolotAtt18, TOLOTATT19 = a.tolotAtt19, TOLOTATT20 = a.tolotAtt20, TOLOTATT21 = a.tolotAtt21, TOLOTATT22 = a.tolotAtt22, TOLOTATT23 = a.tolotAtt23, TOLOTATT24 = a.tolotAtt24, }); }); if (WMSHelper.CreateTransferList(po)) { foreach (var a in po.Details) { List cntrList = ContainerHelper.GetCntrItemRelBySerialNo(a.S_TRACE_ID,a.S_SERIAL_NO); if (cntrList != null && cntrList.Count > 0) { foreach (var cntr in cntrList) { cntr.LOTATT01 = a.TOLOTATT01; cntr.LOTATT02 = a.TOLOTATT02; cntr.LOTATT03 = a.TOLOTATT03; cntr.LOTATT04 = a.TOLOTATT04; cntr.LOTATT05 = a.TOLOTATT05; cntr.LOTATT06 = a.TOLOTATT06; cntr.LOTATT07 = a.TOLOTATT07; cntr.LOTATT08 = a.TOLOTATT08; cntr.LOTATT09 = a.TOLOTATT09; cntr.LOTATT10 = a.TOLOTATT10; cntr.LOTATT11 = a.TOLOTATT11; cntr.LOTATT12 = a.TOLOTATT12; cntr.LOTATT13 = a.TOLOTATT13; cntr.LOTATT14 = a.TOLOTATT14; cntr.LOTATT15 = a.TOLOTATT15; cntr.LOTATT16 = a.TOLOTATT16; cntr.LOTATT17 = a.TOLOTATT17; cntr.LOTATT18 = a.TOLOTATT18; cntr.LOTATT19 = a.TOLOTATT19; cntr.LOTATT20 = a.TOLOTATT20; cntr.LOTATT21 = a.TOLOTATT21; cntr.LOTATT22 = a.TOLOTATT22; cntr.LOTATT23 = a.TOLOTATT23; cntr.LOTATT24 = a.TOLOTATT24; ContainerHelper.UpdateCntrItemRel(cntr); } } } return true; } } } return result; } /// /// 移库单同步 /// /// /// internal static bool shiftingStockOrderSync(ShiftingStockOrder model) { bool result = false; //创建冻结单主子表 var po = WMSHelper.GetShiftingStockList(model.mdocNo); if (po == null) { po = new ShiftStockList() { S_ORGANIZATION_ID = model.organizationId, S_WAREHOUSE_ID = model.warehouseId, S_CUSTOMER_ID = model.customerId, S_MDOC_NO = model.mdocNo, S_MDOC_TYPE = model.mdocType, S_STATUS = "待执行", UDF01 = model.udf01, UDF02 = model.udf02, UDF03 = model.udf03, UDF04 = model.udf04, UDF05 = model.udf05, }; po.Details = new List(); if (model.Details.Count > 0) { model.Details.ForEach(a => { po.Details.Add(new ShiftStockListChild { S_MDOC_NO = a.mdocNo, S_TRACE_ID = a.traceId, S_TO_LOCATION = a.toLocation, UDF01 = a.udf01, UDF02 = a.udf02, UDF03 = a.udf03, UDF04 = a.udf04, UDF05 = a.udf05, }); }); result = WMSHelper.CreateShiftStockList(po); } } return result; } /// /// 冻结托盘(锁定托盘 状态码 4.冻结) /// /// /// internal static bool freezeOrderSync(FreezeOrder model) { bool result = false; //创建冻结单主子表 var po = WMSHelper.GetFreezeList(model.holdNo); if (po == null) { po = new FreezeList() { S_ORGANIZATION_ID = model.organizationId, S_WAREHOUSE_ID = model.warehouseId, S_CUSTOMER_ID = model.customerId, S_HOLD_NO = model.holdNo, S_STATUS = model.status, }; po.Details = new List(); List cntrList = new List(); if (model.Details.Count > 0) { model.Details.ForEach(a => { po.Details.Add(new FreezeListChild { S_HOLD_NO = a.holdNo, S_TRACE_ID = a.traceId, }); cntrList.Add(a.traceId); }); if (WMSHelper.CreateFreezeList(po)) { if (po.S_STATUS == "10") { // 冻结 result = ContainerHelper.UpdateCntrState(cntrList, 4); } else if (po.S_STATUS == "30") { // 释放 result = ContainerHelper.UpdateCntrState(cntrList, 0); } } } } return result; } internal static SimpleResult ShippingOrderExecute(ShippingOrderCheck model) { var result = new SimpleResult(); //检查库存,更新发货单,生成分拣单,自动合并波次 //这个后台做比较麻烦,mobox3库存在内存中,任务完成的时候无法增加,还是用c#直接管内存,计算比较方便 WMSHelper.CreateSortingOrder(model.out_nos.Split(',').ToList()); return result; } /// /// 后面要把方法放到wmsHelper中 /// /// /// internal static SimpleResult SortingResultCheck(List models) { //生成分拣结果,更新分拣明细状态 var result = new SimpleResult(); WMSHelper.SortingConfrim(models); return result; } /// /// 后面要把方法放到wmsHelper中 /// /// /// internal static SimpleResult Instock(InstockInfo model) { var result = new SimpleResult(); //pda入库,目前人工放货在巷道口,扫托盘,后台只能计算当前巷道的终点,单深位立库 //1,判断托盘信息,一种是码盘后的,默认enable是N,另一种是分拣回的 var cntr = ContainerHelper.GetCntr(model.cntr); if (cntr != null) { var sortingInfo = WMSHelper.GetSortingDetailByCntr(model.cntr); if (cntr.C_ENABLE == "Y" && sortingInfo != null && sortingInfo.Count > 0) { result.resultCode = 2; result.resultMsg = $"托盘{model.cntr}未分拣完成"; } } else { result.resultCode = 1; result.resultMsg = $"托盘{model.cntr}不存在"; } if (result.resultCode == 0) { //获取接驳位所在的巷道, 查找功能区,入库接驳位找逻辑库区(每个巷道一个逻辑库区) var fa = LocationHelper.GetFunctionAreaByCode(model.start, 2, 10); if (fa != null) { //创建入库作业,简单判断一下是否有可入货位,如果不判断,人工货放上去一直不能入,也不知道原因 var end = LocationHelper.GetZoneLoc(fa.S_MASTER_CODE); if (end != null) { //判断托盘是否已经生成任务,如果没有则生成 var wmsTask = WMSHelper.GetWmsTaskByCntr(model.cntr); if (wmsTask != null) { result.resultCode = 3; result.resultMsg = $"起点{model.start} 托盘{model.cntr}已经创建任务,请勿重复申请"; } else { wmsTask = new WMSTask { S_CNTR_CODE = model.cntr, S_CODE = WMSHelper.GenerateTaskNo(), S_START_LOC = model.start, S_END_LOC = end.S_LOC_CODE, N_TYPE = 1, S_TYPE = WMSTask.GetTypeStr(1), S_OP_DEF_CODE = "", S_OP_DEF_NAME = "pda入立库" }; if (WMSHelper.CreateWmsTask(wmsTask)) { LocationHelper.LockLoc(end.S_LOC_CODE, 1); result.resultMsg = $"创建作业成功,作业号{wmsTask.S_CODE}"; } } } else { result.resultCode = 3; result.resultMsg = $"起点{model.start}对应的逻辑库区{fa.S_MASTER_CODE}没有可用货位,请更换巷道"; } } else { result.resultCode = 3; result.resultMsg = $"起点{model.start}没有对应的逻辑库区,请在逻辑库区设置功能区-入库接驳位"; } } return result; } internal static SimpleResult SortingOrderExecute(SortingOrderCheck model) { var result = new SimpleResult(); //分拣单配货执行 WMSHelper.CreateSortingOrderDetail(model.s_no); return result; } internal static SimpleResult CheckSortingWholeCntr(CheckSortingWholeCntr model) { var result = new SimpleResult(); if (WMSHelper.CheckSortingWholeCntr(model.cntr, model.autoSort == 1)) { 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().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("WMS_FBarCode", nameP, orgP).First();//返回List Console.WriteLine($"读存储过程成功,result={result}"); } catch (Exception ex) { Console.WriteLine(ex.Message); } return result; } internal static SimpleResult PalletSorting1(PalletSorting1 model) { var result = new SimpleResult(); //校验入库单数量,不可以超,成功后插入托盘物料表,更新入库单累计数量 //也可以直接lua查询入库单数量,做校验 //先用bar_code读存储过程获取信息 var codeInfo = GetCodeInfo(model.bar_code, model.org); var info = WMSHelper.GetPutawayOrderDetail(model.bar_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.bar_code, info.S_BATCH_NO, model.qty, info.S_BATCH_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.bar_code}的入库单明细信息"; } return result; } /// /// 更新抽检信息 /// /// /// public static SimpleResult updateSpotCheckInfo(SpotCheckListModel model) { SimpleResult simpleResult = new SimpleResult(); SpotCheckList spot = WMSHelper.querySpotCheckList(model.S_ASN_NO, model.S_TRACE_ID); if (model.S_ISCONTINUE == "是") { WCSCore.putCheckSign(model.S_ASN_NO); } spot.S_STATUS = model.S_STATUS; spot.N_STATUS = model.N_STATUS; spot.S_QUALITY_STATUS = model.S_QUALITY_STATUS; spot.S_ISCONTINUE = model.S_ISCONTINUE; WMSHelper.updateSpotCheckList(spot); return simpleResult; } public class SpotCheckListModel { public string S_ASN_NO { get; set; } // 预期到货通知单 public string S_SKU { get; set; } // 物料号 public string S_TRACE_ID { get; set; } // 托盘号 public int N_STATUS { get; set; } // 状态 1.待出库 2.待检验 3.已检验 4.已回库 public string S_STATUS { get; set; } // 状态 1.待出库 2.待检验 3.已检验 4.已回库 public string S_LOC_CODE { get; set; } // 货位 public string S_QUALITY_STATUS { get; set; } // 质量状态 Y 合格 N 不合格 public string S_ISCONTINUE { get; set; } = "是"; // 是/否 } public class SafetyInfo { public string station_name { get; set; } // 1:取货请求进入 2:取货请求动作 4:取货后已离开 5:卸货请求进入 6:卸货请求动作 8:卸货后已离开 public int apply_code { get; set; } public int orderid { get; set; } //订单ID } public class SafetyResponse { public int code { get; set; } public string msg { get; set; } } public class GZAgvTaskState { public int OrderID { get; set; } //订单ID public string orderName { get; set; } public string OrderStatus { get; set; } //订单状态 public string agvIDList { get; set; } //小车编号 public int priority { get; set; } //订单优先级 public string currentDes { get; set; } //当前目的地 public string currentCmd { get; set; } public int errorCode { get; set; } public string deadLine { get; set; } public string createdTime { get; set; } public string extraInfo1 { get; set; } //扩展数据 public string extraInfo2 { get; set; } public string StatusChangeTime { get; set; } } 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 { /// /// 生产订单内码 /// public string FInterID { get; set; } /// /// 生产订单编号 /// public string FSourceNo { get; set; } /// /// 批号 /// public string FGMPBatchNo { get; set; } public string FState { get; set; } /// /// 物料编码(内码就是编码) /// public string Fitemid_XK { get; set; } /// /// 分录id /// public string Fentryid { get; set; } } public class NoteInfo : CodeInfo { public string WmsBillNo { get; set; } } } }