File was renamed from HH.WCS.Mobox3/HH.WCS.Mobox3.EmersonWCS/wms/WMSHelper.cs |
| | |
| | | using HH.WCS.EmersonWcs.api; |
| | | using HH.WCS.EmersonWcs.LISTA.models; |
| | | using HH.WCS.EmersonWcs.models.other; |
| | | using HH.WCS.EmersonWcs.util; |
| | | using HH.WCS.Emerson.api; |
| | | using HH.WCS.Emerson.LISTA.models; |
| | | using HH.WCS.Emerson.models.other; |
| | | using HH.WCS.Emerson.util; |
| | | using Newtonsoft.Json; |
| | | using Opc.Ua; |
| | | using System; |
| | |
| | | using System.Security.Cryptography; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using static HH.WCS.EmersonWcs.api.ApiModel; |
| | | using static HH.WCS.Emerson.api.ApiModel; |
| | | |
| | | namespace HH.WCS.EmersonWcs.wms |
| | | namespace HH.WCS.Emerson.wms |
| | | { |
| | | /// <summary> |
| | | /// wms管到作业 |
| | |
| | | var distribution = db.Queryable<TN_Distribution_CNTR>().Where(a => a.N_B_STATE == 1).ToList(); |
| | | if (distribution.Count > 0) |
| | | { |
| | | |
| | | foreach (var item in distribution) |
| | | try |
| | | { |
| | | LogHelper.Info($"托盘{item.S_CNTR_CODE}开始出库"); |
| | | Location endloc = new Location(); |
| | | Location startloc = new Location(); |
| | | string endZone = "CKFJQ"; |
| | | |
| | | |
| | | //根据托盘编码找托盘货位表 |
| | | var LocCntr = ContainerHelper.GetLocCntrByCntr(item.S_CNTR_CODE); |
| | | if (LocCntr != null) |
| | | foreach (var item in distribution) |
| | | { |
| | | startloc = LocationHelper.GetLocListbyloc(LocCntr.S_LOC_CODE).First(); |
| | | if (startloc == null) |
| | | LogHelper.Info($"托盘{item.S_CNTR_CODE}开始出库"); |
| | | Location endloc = new Location(); |
| | | Location startloc = new Location(); |
| | | string endZone = "CKFJQ"; |
| | | |
| | | |
| | | //根据托盘编码找托盘货位表 |
| | | var LocCntr = ContainerHelper.GetLocCntrByCntr(item.S_CNTR_CODE); |
| | | if (LocCntr != null) |
| | | { |
| | | LogHelper.Info($"根据托盘货位绑定关系-货位:{LocCntr.S_LOC_CODE}未找到货位信息"); |
| | | } |
| | | else |
| | | { |
| | | if (string.IsNullOrEmpty(item.S_EXIT_LOC_CODE)) |
| | | startloc = LocationHelper.GetLocListbyloc(LocCntr.S_LOC_CODE).First(); |
| | | if (startloc == null) |
| | | { |
| | | //根据终点库区货位和物料计算货位 |
| | | var endlocations = LocationHelper.GetLocListAny(endZone).OrderBy(a => a.N_ROW).ToList(); |
| | | endloc = ApiHelper.FindEndcolByLocList(endlocations); |
| | | LogHelper.Info($"根据托盘货位绑定关系-货位:{LocCntr.S_LOC_CODE}未找到货位信息"); |
| | | } |
| | | else |
| | | { |
| | | endloc = LocationHelper.GetLoc(item.S_EXIT_LOC_CODE); |
| | | |
| | | } |
| | | |
| | | if (endloc == null && endloc.N_LOCK_STATE == 0 && endloc.N_CURRENT_NUM == 0) |
| | | { |
| | | LogHelper.Info($"终点货位:{item.S_EXIT_LOC_CODE}不可用"); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | LogHelper.Info($"根据托盘编码:{item.S_CNTR_CODE}未找到托盘货位绑定关系"); |
| | | } |
| | | if (startloc != null && endloc != null) |
| | | { |
| | | //创建wcs任务 |
| | | var wcsTask = new WCSTask |
| | | { |
| | | S_CODE = WCSHelper.GenerateTaskNo(), |
| | | S_TYPE = "出库", |
| | | S_START_LOC = startloc.S_CODE, |
| | | S_END_LOC = endloc.S_CODE, |
| | | N_CNTR_COUNT = 1, |
| | | N_SCHEDULE_TYPE = 1, |
| | | S_CNTR_CODE = item.S_CNTR_CODE, |
| | | N_START_LAYER = startloc.N_LAYER, |
| | | N_END_LAYER = endloc.N_LAYER, |
| | | S_START_WH = startloc.S_WH_CODE, |
| | | S_END_WH = endloc.S_WH_CODE, |
| | | S_START_AREA = startloc.S_AREA_CODE, |
| | | S_END_AREA = endloc.S_AREA_CODE, |
| | | S_EQ_NO = item.S_BS_NO, |
| | | }; |
| | | LogHelper.Info("创建任务:" + JsonConvert.SerializeObject(wcsTask), "CreateTask"); |
| | | if (WCSHelper.CreateTask(wcsTask)) |
| | | { |
| | | LogHelper.Info("创建任务成功"); |
| | | // LocationHelper.LockLoc(startloc.S_CODE, 2); |
| | | // LocationHelper.LockCntr(item.S_CNTR_CODE, 2); |
| | | LocationHelper.LockLoc(endloc.S_CODE, 1); |
| | | item.N_B_STATE = 2; |
| | | db.Updateable(item).UpdateColumns(it => new { it.N_B_STATE }).ExecuteCommand(); |
| | | |
| | | //修改出库单状态 |
| | | var distributions = db.Queryable<TN_Distribution_CNTR>().Where(a => a.N_B_STATE == 1 && a.S_BS_NO == item.S_BS_NO).ToList(); |
| | | if (distributions.Count > 0) |
| | | { |
| | | |
| | | LogHelper.Info($"托盘{item.S_CNTR_CODE}创建任务完成,出库单{item.S_BS_NO}存在未完成的出库任务,不允许修改出库单状态"); |
| | | |
| | | } |
| | | else |
| | | { |
| | | var outbound = db.Queryable<TN_Outbound_Order>().Where(a => a.S_NO == item.S_BS_NO).First(); |
| | | if (outbound != null && outbound.N_B_STATE != 3) |
| | | if (string.IsNullOrEmpty(item.S_EXIT_LOC_CODE)) |
| | | { |
| | | outbound.N_B_STATE = 3; |
| | | db.Updateable(outbound).UpdateColumns(it => new { it.N_B_STATE }).ExecuteCommand(); |
| | | LogHelper.Info($"出库单{item.S_BS_NO}创建任务完成,修改出库单状态"); |
| | | //根据终点库区货位和物料计算货位 |
| | | var endlocations = LocationHelper.GetLocListAny(endZone).OrderBy(a => a.N_ROW).ToList(); |
| | | endloc = ApiHelper.FindEndcolByLocList(endlocations); |
| | | } |
| | | else |
| | | { |
| | | endloc = LocationHelper.GetLoc(item.S_EXIT_LOC_CODE); |
| | | |
| | | } |
| | | if (endloc == null) |
| | | { |
| | | LogHelper.Info($"终点货位:{item.S_EXIT_LOC_CODE}不可用"); |
| | | return; |
| | | } |
| | | if (endloc.N_LOCK_STATE != 0 || endloc.N_CURRENT_NUM != 0) |
| | | { |
| | | LogHelper.Info($"终点货位:{item.S_EXIT_LOC_CODE}不可用"); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | LogHelper.Info("创建任务失败"); |
| | | LogHelper.Info($"根据托盘编码:{item.S_CNTR_CODE}未找到托盘货位绑定关系"); |
| | | } |
| | | if (startloc != null && endloc != null) |
| | | { |
| | | //创建wcs任务 |
| | | var wcsTask = new WCSTask |
| | | { |
| | | S_CODE = WCSHelper.GenerateTaskNo(), |
| | | S_TYPE = "出库", |
| | | S_START_LOC = startloc.S_CODE, |
| | | S_END_LOC = endloc.S_CODE, |
| | | N_CNTR_COUNT = 1, |
| | | N_SCHEDULE_TYPE = 1, |
| | | S_CNTR_CODE = item.S_CNTR_CODE, |
| | | N_START_LAYER = startloc.N_LAYER, |
| | | N_END_LAYER = endloc.N_LAYER, |
| | | S_START_WH = startloc.S_WH_CODE, |
| | | S_END_WH = endloc.S_WH_CODE, |
| | | S_START_AREA = startloc.S_AREA_CODE, |
| | | S_END_AREA = endloc.S_AREA_CODE, |
| | | S_EQ_NO = item.S_BS_NO, |
| | | }; |
| | | LogHelper.Info("创建任务:" + JsonConvert.SerializeObject(wcsTask), "CreateTask"); |
| | | if (WCSHelper.CreateTask(wcsTask)) |
| | | { |
| | | LogHelper.Info("创建任务成功"); |
| | | // LocationHelper.LockLoc(startloc.S_CODE, 2); |
| | | // LocationHelper.LockCntr(item.S_CNTR_CODE, 2); |
| | | LocationHelper.LockLoc(endloc.S_CODE, 1); |
| | | item.N_B_STATE = 2; |
| | | db.Updateable(item).UpdateColumns(it => new { it.N_B_STATE }).ExecuteCommand(); |
| | | |
| | | //修改出库单状态 |
| | | var distributions = db.Queryable<TN_Distribution_CNTR>().Where(a => a.N_B_STATE == 1 && a.S_BS_NO == item.S_BS_NO).ToList(); |
| | | if (distributions.Count > 0) |
| | | { |
| | | LogHelper.Info($"托盘{item.S_CNTR_CODE}创建任务完成,出库单{item.S_BS_NO}存在未完成的出库任务,不允许修改出库单状态"); |
| | | } |
| | | else |
| | | { |
| | | var outbound = db.Queryable<TN_Outbound_Order>().Where(a => a.S_NO == item.S_BS_NO).First(); |
| | | if (outbound != null && outbound.N_B_STATE != 3) |
| | | { |
| | | outbound.N_B_STATE = 3; |
| | | db.Updateable(outbound).UpdateColumns(it => new { it.N_B_STATE }).ExecuteCommand(); |
| | | LogHelper.Info($"出库单{item.S_BS_NO}创建任务完成,修改出库单状态"); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | LogHelper.Info("创建任务失败"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | Console.WriteLine("起点终点货位为空,请检查日志"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | Console.WriteLine("起点终点货位为空,请检查日志"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogHelper.Info($"CreateOutTask Error :{ex}"); |
| | | throw; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | |
| | | var result = true; |
| | | try |
| | | { |
| | | |
| | | |
| | | var itemlist = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE == task.S_CNTR_CODE).ToList(); |
| | | if (itemlist.Count > 0) |
| | | { |
| | |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | else |
| | | { |
| | | LogHelper.Info($"根据托盘:{task.S_CNTR_CODE}未找到托盘物料明细数据"); |
| | | } |
| | | } |