| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | using HH.WCS.Mobox3.DSZSH.core; |
| | | using HH.WCS.Mobox3.DSZSH.models; |
| | | using HH.WCS.Mobox3.DSZSH.util; |
| | | using HH.WCS.Mobox3.DSZSH.wms; |
| | | |
| | | using Newtonsoft.Json; |
| | | using Org.BouncyCastle.Asn1.Tsp; |
| | | |
| | | using SqlSugar; |
| | | |
| | | using Swashbuckle.Swagger; |
| | | |
| | | using static HH.WCS.Mobox3.DSZSH.api.ApiModel; |
| | | using static HH.WCS.Mobox3.DSZSH.api.OtherModel; |
| | | using static HH.WCS.Mobox3.DSZSH.Config; |
| | | |
| | | namespace HH.WCS.Mobox3.DSZSH.api { |
| | | public class ApiHelper { |
| | | /// <summary> |
| | | /// 好运箱-满箱下线入库(PDA) |
| | | /// 满箱下线入库 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | public static SimpleResult GoodpackOffline(GoodpackOfflineInfo model) { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var info = ""; |
| | | |
| | | var taskName = TaskName.H好运箱_满箱下线入库; // 用于生成任务类型、打印日志信息 |
| | | var startAreaName = AreaName.M满箱操作区; |
| | | var endAreaName = AreaName.M满箱货架区; |
| | | var taskInfo = ETask.M满箱下线入库.Info(); |
| | | const string preLog = "API:满箱下线入库:"; |
| | | const string cntrType = "好运箱"; |
| | | |
| | | try { |
| | | // 将PDA提供的物料编码与贴标机的信息比对 |
| | | var cgDetail = db.Queryable<TN_CG_Detail>() |
| | | .Where(d => d.S_ITEM_CODE == model.ItemCode && d.S_BATCH_NO == model.BatchNo) // 指定:物料编码、批次号 |
| | | .Where(d => d.N_ITEM_STATE == 1 && d.S_ITEM_STATE == "待检") // 新增物料,故物料状态应该为 1待检 |
| | | // TODO model 中 数量、规格是否也参与比对 待后续要求 |
| | | .First(); |
| | | if (model.Num <= 0) { |
| | | return NewSimpleResult(400, preLog + $"物料数量'{model.Num}'不合法!要求:物料数量>0"); |
| | | } |
| | | |
| | | // 检查货品容器表:是否已经存在贴标机传递的待入库物料信息 |
| | | // TODO:数量,规格是否也参与比对? |
| | | var cgDetail = db.Queryable<TN_CG_Detail>().Where(d => d.S_ITEM_CODE == model.ItemCode && d.S_BATCH_NO == model.BatchNo && d.N_ITEM_STATE == 1 && d.S_ITEM_STATE == "待检").First(); |
| | | if (cgDetail == null) { |
| | | info = $"PDA扫码物料信息与贴标机传递的信息不一致:" + JsonConvert.SerializeObject(model); |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(2, info); |
| | | return NewSimpleResult(1, preLog + $"没有在[货品明细表]中找到[物料编码='{model.ItemCode}',批次号='{model.BatchNo}']的物料!请检查:PDA扫码物料信息与贴标机传递的信息是否一致!要求:物料状态='待检'"); |
| | | } |
| | | |
| | | // 起点货位绑定后,可以不立即设置N_CURRENT_NUM为1 |
| | | // 因为AGV取货后就会恢复0,而且货位上锁后不会被访问到 |
| | | var startLoc = db.Queryable<TN_Location>() |
| | | .Where(l => l.S_CODE == model.StartLoc) // 指定:起点货位号 |
| | | .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y") // 筛选:未上锁 |
| | | .Where(l => l.N_CURRENT_NUM == 0) // 起点绑定前没有容器 |
| | | .Where(l => Settings.AreaMap[startAreaName].Contains(l.S_AREA_CODE)) // 起点货区符合任务要求 |
| | | .First(); |
| | | |
| | | // 查询起点货位:数量=0 |
| | | var startLoc = db.Queryable<TN_Location>().Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y" && l.S_CODE == model.StartLoc && taskInfo.StartAreas.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM == 0).First(); |
| | | if (startLoc == null) { |
| | | info = $"在'{startAreaName}'中没有找到起点货位{model.StartLoc},或不具备取货要求:未上锁、绑定前无货物"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(3, info); |
| | | return NewSimpleResult(2, preLog + $"没有找到起点货位'{model.StartLoc}'!要求:锁状态='无',当前容器数量=0,所在库区={LogObject(taskInfo.StartAreas)}"); |
| | | } |
| | | |
| | | // 绑定货位和容器号 |
| | | var locCntrRel = new TN_Loc_Container { |
| | | S_LOC_CODE = model.StartLoc, |
| | | S_CNTR_CODE = cgDetail.S_CNTR_CODE, |
| | | S_CNTR_TYPE = "好运箱", |
| | | }; |
| | | // 和满托下线入库的逻辑一致,由于容器移动不会更改绑定信息,所以必须删除旧数据 |
| | | var old = WCSHelper.GetLocCntrCg(cgDetail.S_CNTR_CODE, skipCgDetail: true); |
| | | |
| | | // TODO 满箱入库算法待优化 |
| | | var endLoc = db.Queryable<TN_Location>() |
| | | .Where(l => Settings.AreaMap[endAreaName].Contains(l.S_AREA_CODE)) // 终点货区符合任务要求 |
| | | .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y") // 筛选:未上锁 |
| | | .Where(l => l.N_CURRENT_NUM == 0) // 筛选:空货位 |
| | | .OrderBy(l => l.N_LAYER) // 按货架最低排序 |
| | | .First(); |
| | | // 绑定货位容器,起点货位当前数量=1 |
| | | var locCntrRel = WCSHelper.BindLocCntr(ref startLoc, cgDetail.S_CNTR_CODE); |
| | | locCntrRel.S_CNTR_TYPE = cntrType; |
| | | |
| | | // 查询终点货位 |
| | | // Order:按货位层数,从小到大排列 |
| | | var endLoc = db.Queryable<TN_Location>().Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y" && taskInfo.EndAreas.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM == 0).OrderBy(l => new { l.N_LAYER }).First(); |
| | | if (endLoc == null) { |
| | | info = $"在'{endAreaName}'中没有找到合适的终点货位,需要满足:未上锁、无货物"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | return NewSimpleResult(3, preLog + $"没有找到合适的终点货位!要求:锁状态='无',当前容器数量=0,所在库区={LogObject(taskInfo.EndAreas)}"); |
| | | } |
| | | |
| | | var cntId = locCntrRel.S_CNTR_CODE; |
| | | var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, taskName); |
| | | |
| | | LocationHelper.LockLoc(ref startLoc, 2); // 起点出库锁 |
| | | LocationHelper.LockLoc(ref endLoc, 1); // 终点入库锁 |
| | | // 更新[起点/终点]锁状态,创建任务 |
| | | WCSHelper.LockStartLoc(ref startLoc); |
| | | WCSHelper.LockEndLoc(ref endLoc); |
| | | var task = WCSHelper.BuildTask(startLoc, endLoc, locCntrRel.S_CNTR_CODE, taskInfo.TaskName); |
| | | |
| | | using (var tran = db.Ado.UseTran()) { |
| | | if (db.Insertable<TN_Loc_Container>(locCntrRel).ExecuteCommand() <= 0) { |
| | | info = $"插入货位容器关系失败:" + JsonConvert.SerializeObject(locCntrRel); |
| | | // 删除/更新旧[货位/容器/物料]信息 |
| | | if (old.LocCntrRel != null && db.Deleteable(old.LocCntrRel).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(5, info); |
| | | return NewSimpleResult(500, preLog + $"删除[旧货位容器关系]失败!数据:{LogObject(old.LocCntrRel)}"); |
| | | } |
| | | if (old.Location != null && db.Updateable(old.Location).UpdateColumns(l => new { l.N_CURRENT_NUM, l.T_MODIFY }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(500, preLog + $"更新[旧货位|当前容器数量]失败!货位='{old.Location.S_CODE}',数量=>{old.Location.N_CURRENT_NUM}"); |
| | | } |
| | | |
| | | if (db.Updateable<TN_Location>(startLoc).UpdateColumns(it => new { |
| | | it.N_LOCK_STATE, |
| | | it.S_LOCK_STATE, |
| | | it.S_LOCK_OP, |
| | | it.T_MODIFY |
| | | }).ExecuteCommand() <= 0) { |
| | | // 插入新绑定的[货位-容器]表 |
| | | if (db.Insertable(locCntrRel).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = $"生成任务'{taskName}'失败:更新起点货位{startLoc.S_CODE}锁状态失败"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(5, info); |
| | | return NewSimpleResult(500, preLog + $"插入[容器货位绑定表]失败!数据:{LogObject(locCntrRel)}"); |
| | | } |
| | | |
| | | if (db.Updateable<TN_Location>(endLoc).UpdateColumns(it => new { |
| | | it.N_LOCK_STATE, |
| | | it.S_LOCK_STATE, |
| | | it.S_LOCK_OP, |
| | | it.T_MODIFY |
| | | }).ExecuteCommand() <= 0) { |
| | | // 更新[起点/终点]锁状态,创建任务 |
| | | if (db.Updateable(startLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, it.T_MODIFY, it.N_CURRENT_NUM, }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = $"生成任务'{taskName}'失败:更新终点货位{endLoc.S_CODE}锁状态失败"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(5, info); |
| | | return NewSimpleResult(500, preLog + $"更新[起点货位锁状态]失败!起点='{startLoc.S_CODE}',锁状态=>'出库锁'"); |
| | | } |
| | | if (db.Updateable(endLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, it.T_MODIFY, }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(500, preLog + $"更新[终点货位锁状态]失败!终点='{endLoc.S_CODE}',锁状态=>'入库锁'"); |
| | | } |
| | | if (db.Insertable(task).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(500, preLog + $"生成任务'{task.S_TYPE}'失败!任务号={task.S_CODE},容器号={task.S_CNTR_CODE},起点={task.S_START_LOC},终点={task.S_END_LOC}"); |
| | | } |
| | | |
| | | if (db.Insertable<TN_Task>(task).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = $"生成任务'{taskName}'失败,容器号{cntId},起点{startLoc.S_CODE},终点货架{endLoc.S_CODE}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(5, info); |
| | | } |
| | | |
| | | // 提交数据库更改 |
| | | tran.CommitTran(); |
| | | info = $"生成任务'{taskName}'成功,容器号{cntId},起点{startLoc.S_CODE},终点货架{endLoc.S_CODE}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(0, info); |
| | | return NewSimpleResult(0, preLog + $"生成任务'{task.S_TYPE}'成功!任务号={task.S_CODE},容器号={task.S_CNTR_CODE},起点={task.S_START_LOC},终点={task.S_END_LOC}"); |
| | | } |
| | | } |
| | | catch (Exception ex) { |
| | | info = $"发生了异常:{ex.Message}"; |
| | | LogHelper.InfoEx(ex); |
| | | return NewSimpleResult(1, info); |
| | | return NewSimpleResult(ex, preLog); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 托盘-空托入库(PDA) |
| | | /// 空托入库 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | public static SimpleResult EmptyInboundPallet(EmptyInboundInfo model) { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var info = ""; |
| | | |
| | | var taskName = TaskName.T托盘_空托入库; |
| | | var startAreaName = AreaName.K空托入库接驳区; |
| | | var endAreaName = AreaName.K空托存放区; |
| | | var taskInfo = ETask.K空托入库.Info(); |
| | | const string preLog = "API:空托入库:"; |
| | | const string cntrType = "托盘"; |
| | | |
| | | try { |
| | | // 现在PDA没有单独的绑定流程,绑定在入库时完成 |
| | | var startLoc = db.Queryable<TN_Location>() |
| | | .Where(l => l.S_CODE == model.StartLoc) // 指定:起点货位 |
| | | .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y") // 筛选:未上锁 |
| | | .Where(l => l.N_CURRENT_NUM == 0) // 绑定前货位为空 |
| | | .Where(l => Settings.AreaMap[startAreaName].Contains(l.S_AREA_CODE)) // 起点货区符合任务要求 |
| | | .First(); |
| | | |
| | | // 查询起点货位:数量=0 |
| | | var startLoc = db.Queryable<TN_Location>().Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y" && l.S_CODE == model.StartLoc && taskInfo.StartAreas.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM == 0).First(); |
| | | if (startLoc == null) { |
| | | info = $"起点位置{model.StartLoc}不存在或不具备取货要求"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(2, info); |
| | | return NewSimpleResult(1, preLog + $"没有找到起点货位'{model.StartLoc}'!要求:锁状态='无';当前容器数量=0;所在库区={LogObject(taskInfo.StartAreas)}"); |
| | | } |
| | | |
| | | // 绑定货位和容器号 |
| | | var locCntrRel = new TN_Loc_Container { |
| | | S_LOC_CODE = model.StartLoc, |
| | | S_CNTR_CODE = model.CntrCode, |
| | | S_CNTR_TYPE = "托盘", |
| | | }; |
| | | // 查询容器表:容器类型字段 |
| | | var cntr = db.Queryable<TN_Container>().Where(c => c.S_CODE == model.CntrCode).First(); |
| | | if (cntr == null) { |
| | | return NewSimpleResult(2, preLog + $"容器'{model.CntrCode}'在[容器表]中不存在,请在前台页面中维护!"); |
| | | } |
| | | if (cntr.S_TYPE != cntrType) { |
| | | return NewSimpleResult(3, preLog + $"容器'{model.CntrCode}'在[容器表]中的类型为'{cntr.S_TYPE}',与输入的容器类型'{cntrType}'不同!"); |
| | | } |
| | | |
| | | // 空箱入库时,如果存在旧的绑定数据,删除 |
| | | var old = WCSHelper.GetLocCntrCg(model.CntrCode); |
| | | |
| | | // TODO 暂定选择最低层按区位顺序入库,后面待修改 |
| | | var endLoc = db.Queryable<TN_Location>() |
| | | .Where(l => Settings.AreaMap[endAreaName].Contains(l.S_AREA_CODE)) // 终点货区符合任务要求 |
| | | .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y") // 筛选:未上锁 |
| | | .Where(l => l.N_CURRENT_NUM == 0) |
| | | .OrderBy(l => new { l.N_LAYER, l.N_ROW, l.N_COL }) |
| | | .First(); |
| | | // 绑定货位容器,起点货位当前数量=1 |
| | | var locCntrRel = WCSHelper.BindLocCntr(ref startLoc, cntr.S_CODE); |
| | | locCntrRel.S_CNTR_TYPE = cntrType; |
| | | |
| | | // 查询终点货位 |
| | | // Order:层数从低到高,行,列 |
| | | var endLoc = db.Queryable<TN_Location>().Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y" && taskInfo.EndAreas.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM == 0).OrderBy(l => new { l.N_LAYER, l.N_ROW, l.N_COL }).First(); |
| | | if (endLoc == null) { |
| | | info = $"在'{endAreaName}'中没有找到合适的终点货位,需要满足:未上锁、无货物"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | return NewSimpleResult(3, preLog + $"没有找到合适的终点货位!要求:锁状态='无';当前容器数量=0;所在库区={LogObject(taskInfo.EndAreas)}"); |
| | | } |
| | | |
| | | var cntId = locCntrRel.S_CNTR_CODE; |
| | | var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, taskName); |
| | | |
| | | LocationHelper.LockLoc(ref startLoc, 2); // 起点出库锁 |
| | | LocationHelper.LockLoc(ref endLoc, 1); // 终点入库锁 |
| | | // 起点终点上锁,创建任务 |
| | | WCSHelper.LockStartLoc(ref startLoc); |
| | | WCSHelper.LockEndLoc(ref endLoc); |
| | | var task = WCSHelper.BuildTask(startLoc, endLoc, locCntrRel.S_CNTR_CODE, taskInfo.TaskName); |
| | | |
| | | using (var tran = db.Ado.UseTran()) { |
| | | if (db.Insertable<TN_Loc_Container>(locCntrRel).ExecuteCommand() <= 0) { |
| | | info = $"插入货位容器关系失败:" + JsonConvert.SerializeObject(locCntrRel); |
| | | if (old.CgDetail != null && db.Deleteable(old.CgDetail).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | return NewSimpleResult(500, preLog + $"删除[旧物料信息]失败!数据:{LogObject(old.CgDetail)}"); |
| | | } |
| | | |
| | | if (db.Updateable<TN_Location>(startLoc).UpdateColumns(it => new { |
| | | it.N_LOCK_STATE, |
| | | it.S_LOCK_STATE, |
| | | it.S_LOCK_OP, |
| | | it.T_MODIFY |
| | | }).ExecuteCommand() <= 0) { |
| | | if (old.LocCntrRel != null && db.Deleteable(old.LocCntrRel).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = $"生成任务'{taskName}'失败:更新起点货位{startLoc.S_CODE}锁状态失败"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | return NewSimpleResult(500, preLog + $"删除[旧货位容器关系]失败!数据:{LogObject(old.LocCntrRel)}"); |
| | | } |
| | | |
| | | if (db.Updateable<TN_Location>(endLoc).UpdateColumns(it => new { |
| | | it.N_LOCK_STATE, |
| | | it.S_LOCK_STATE, |
| | | it.S_LOCK_OP, |
| | | it.T_MODIFY |
| | | }).ExecuteCommand() <= 0) { |
| | | if (old.Location != null && db.Updateable(old.Location).UpdateColumns(l => new { l.N_CURRENT_NUM, l.T_MODIFY }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = $"生成任务'{taskName}'失败:更新终点货位{endLoc.S_CODE}锁状态失败"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | return NewSimpleResult(500, preLog + $"更新[旧货位|当前容器数量]失败!货位='{old.Location.S_CODE}',数量=>{old.Location.N_CURRENT_NUM}"); |
| | | } |
| | | |
| | | if (db.Insertable<TN_Task>(task).ExecuteCommand() <= 0) { |
| | | if (db.Insertable(locCntrRel).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = $"生成任务'{taskName}'失败,容器号{cntId},起点{startLoc.S_CODE},终点货架{endLoc.S_CODE}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | return NewSimpleResult(500, preLog + $"插入[货位容器绑定表]失败!数据:{LogObject(locCntrRel)}"); |
| | | } |
| | | |
| | | // 更新[起点/终点]锁状态,创建任务 |
| | | if (db.Updateable(startLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, it.T_MODIFY, it.N_CURRENT_NUM, }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(500, preLog + $"更新[起点货位锁状态]失败!起点='{startLoc.S_CODE}',锁状态=>'出库锁'"); |
| | | } |
| | | if (db.Updateable(endLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, it.T_MODIFY, }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(500, preLog + $"更新[终点货位锁状态]失败!终点='{endLoc.S_CODE}',锁状态=>'入库锁'"); |
| | | } |
| | | if (db.Insertable(task).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(500, preLog + $"生成任务'{task.S_TYPE}'失败!任务号={task.S_CODE},容器号={task.S_CNTR_CODE},起点={task.S_START_LOC},终点={task.S_END_LOC}"); |
| | | } |
| | | |
| | | // 提交数据库更改 |
| | | tran.CommitTran(); |
| | | info = $"生成任务'{taskName}'成功,容器号{cntId},起点{startLoc.S_CODE},终点货架{endLoc.S_CODE}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(0, info); |
| | | return NewSimpleResult(0, preLog + $"生成任务'{task.S_TYPE}'成功!任务号={task.S_CODE},容器号={task.S_CNTR_CODE},起点={task.S_START_LOC},终点={task.S_END_LOC}"); |
| | | } |
| | | } |
| | | catch (Exception ex) { |
| | | info = $"发生了异常:{ex.Message}"; |
| | | LogHelper.InfoEx(ex); |
| | | return NewSimpleResult(1, info); |
| | | return NewSimpleResult(ex, preLog); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 好运箱-空箱入库(PDA) |
| | | /// 空箱入库 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static SimpleResult EmptyInboundGoodpack(EmptyInboundInfo model) { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var info = ""; |
| | | |
| | | var taskName = TaskName.H好运箱_空箱入库; |
| | | var startAreaName = AreaName.K空箱入库接驳区; |
| | | var endAreaName = AreaName.K空箱货架区; |
| | | var taskInfo = ETask.K空箱入库.Info(); |
| | | const string preLog = "API:空箱入库:"; |
| | | const string cntrType = "好运箱"; |
| | | |
| | | try { |
| | | var startLoc = db.Queryable<TN_Location>() |
| | | .Where(l => l.S_CODE == model.StartLoc) |
| | | .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y") |
| | | .Where(l => l.N_CURRENT_NUM == 0) // 绑定前货位为空 |
| | | .Where(l => Settings.AreaMap[startAreaName].Contains(l.S_AREA_CODE)) // 起点货区符合任务要求 |
| | | .First(); |
| | | |
| | | // 查询起点货位:数量=0 |
| | | var startLoc = db.Queryable<TN_Location>().Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y").Where(l => l.S_CODE == model.StartLoc && taskInfo.StartAreas.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM == 0).First(); |
| | | if (startLoc == null) { |
| | | info = $"起点位置{model.StartLoc}不存在或不具备取货要求"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(2, info); |
| | | return NewSimpleResult(1, preLog + $"没有找到起点货位'{model.StartLoc}'!要求:锁状态='无';当前容器数量=0;所在库区={LogObject(taskInfo.StartAreas)}"); |
| | | } |
| | | |
| | | // 绑定货位和容器号 |
| | | var locCntrRel = new TN_Loc_Container { |
| | | S_LOC_CODE = model.StartLoc, |
| | | S_CNTR_CODE = model.CntrCode, |
| | | S_CNTR_TYPE = "好运箱", |
| | | }; |
| | | // 查询容器表:容器类型字段 |
| | | var cntr = db.Queryable<TN_Container>().Where(c => c.S_CODE == model.CntrCode).First(); |
| | | if (cntr == null) { |
| | | return NewSimpleResult(1, $"容器'{model.CntrCode}'在[容器表]中不存在,请在前台页面中维护!"); |
| | | } |
| | | if (cntr.S_TYPE != cntrType) { |
| | | return NewSimpleResult(2, preLog + $"容器'{model.CntrCode}'在[容器表]中的类型是'{cntr.S_TYPE},不是'{cntrType}'!"); |
| | | } |
| | | |
| | | // TODO 暂定选择最低层顺序入库,后面待修改 |
| | | var endLoc = db.Queryable<TN_Location>() |
| | | .Where(l => Settings.AreaMap[endAreaName].Contains(l.S_AREA_CODE)) |
| | | .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y") |
| | | .Where(l => l.N_CURRENT_NUM == 0) |
| | | .OrderBy(l => new { l.N_LAYER }) |
| | | .First(); |
| | | // 空箱入库时,如果存在旧的绑定数据,删除 |
| | | var old = WCSHelper.GetLocCntrCg(model.CntrCode); |
| | | |
| | | // 绑定货位容器,起点货位当前数量=1 |
| | | var locCntrRel = WCSHelper.BindLocCntr(ref startLoc, model.CntrCode); |
| | | locCntrRel.S_CNTR_TYPE = cntrType; |
| | | |
| | | // 查询终点货位 |
| | | // Order:层数从低到高,行,列 |
| | | var endLoc = db.Queryable<TN_Location>().Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y").Where(l => taskInfo.EndAreas.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM == 0).OrderBy(l => new { l.N_LAYER, l.N_ROW, l.N_COL }).First(); |
| | | if (endLoc == null) { |
| | | info = $"在'{endAreaName}'中没有找到合适的终点货位,需要满足:未上锁、无货物"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | return NewSimpleResult(3, preLog + $"没有找到合适的终点货位!要求:锁状态='无';当前容器数量=0;所在库区={LogObject(taskInfo.EndAreas)}"); |
| | | } |
| | | |
| | | var cntId = locCntrRel.S_CNTR_CODE; |
| | | var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, taskName); |
| | | |
| | | LocationHelper.LockLoc(ref startLoc, 2); // 起点出库锁 |
| | | LocationHelper.LockLoc(ref endLoc, 1); // 终点入库锁 |
| | | WCSHelper.LockStartLoc(ref startLoc); |
| | | WCSHelper.LockEndLoc(ref endLoc); |
| | | var task = WCSHelper.BuildTask(startLoc, endLoc, locCntrRel.S_CNTR_CODE, taskInfo.TaskName); |
| | | |
| | | using (var tran = db.Ado.UseTran()) { |
| | | if (db.Insertable<TN_Loc_Container>(locCntrRel).ExecuteCommand() <= 0) { |
| | | info = $"插入货位容器关系失败:" + JsonConvert.SerializeObject(locCntrRel); |
| | | if (old.CgDetail != null && db.Deleteable(old.CgDetail).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | return NewSimpleResult(500, preLog + $"删除[旧物料信息]失败!数据:{LogObject(old.CgDetail)}"); |
| | | } |
| | | if (old.LocCntrRel != null && db.Deleteable(old.LocCntrRel).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(500, preLog + $"删除[旧货位容器关系]失败!数据:{LogObject(old.LocCntrRel)}"); |
| | | } |
| | | if (old.Location != null && db.Updateable(old.Location).UpdateColumns(l => new { l.N_CURRENT_NUM, l.T_MODIFY }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(500, preLog + $"更新[旧货位|当前容器数量]失败!货位='{old.Location.S_CODE}',数量=>{old.Location.N_CURRENT_NUM}"); |
| | | } |
| | | |
| | | if (db.Updateable<TN_Location>(startLoc).UpdateColumns(it => new { |
| | | it.N_LOCK_STATE, |
| | | it.S_LOCK_STATE, |
| | | it.S_LOCK_OP, |
| | | it.T_MODIFY |
| | | }).ExecuteCommand() <= 0) { |
| | | if (db.Insertable(locCntrRel).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = $"生成任务'{taskName}'失败:更新起点货位{startLoc.S_CODE}锁状态失败"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | return NewSimpleResult(500, preLog + $"插入[货位容器关系]失败:" + LogObject(locCntrRel)); |
| | | } |
| | | |
| | | if (db.Updateable<TN_Location>(endLoc).UpdateColumns(it => new { |
| | | it.N_LOCK_STATE, |
| | | it.S_LOCK_STATE, |
| | | it.S_LOCK_OP, |
| | | it.T_MODIFY |
| | | }).ExecuteCommand() <= 0) { |
| | | // 更新[起点/终点]锁状态,创建任务 |
| | | if (db.Updateable(startLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, it.T_MODIFY, it.N_CURRENT_NUM, }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = $"生成任务'{taskName}'失败:更新终点货位{endLoc.S_CODE}锁状态失败"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | return NewSimpleResult(500, preLog + $"更新[起点货位锁状态]失败!起点='{startLoc.S_CODE}',锁状态=>'出库锁'"); |
| | | } |
| | | if (db.Updateable(endLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, it.T_MODIFY, }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(500, preLog + $"更新[终点货位锁状态]失败!终点='{endLoc.S_CODE}',锁状态=>'入库锁'"); |
| | | } |
| | | if (db.Insertable(task).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(500, preLog + $"生成任务'{task.S_TYPE}'失败!任务号={task.S_CODE},容器号={task.S_CNTR_CODE},起点={task.S_START_LOC},终点={task.S_END_LOC}"); |
| | | } |
| | | |
| | | if (db.Insertable<TN_Task>(task).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = $"生成任务'{taskName}'失败,容器号{cntId},起点{startLoc.S_CODE},终点货架{endLoc.S_CODE}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | } |
| | | |
| | | // 提交数据库更改 |
| | | tran.CommitTran(); |
| | | info = $"生成任务'{taskName}'成功,容器号{cntId},起点{startLoc.S_CODE},终点货架{endLoc.S_CODE}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(0, info); |
| | | return NewSimpleResult(0, preLog + $"生成任务'{task.S_TYPE}'成功!任务号={task.S_CODE},容器号={task.S_CNTR_CODE},起点={task.S_START_LOC},终点={task.S_END_LOC}"); |
| | | } |
| | | } |
| | | catch (Exception ex) { |
| | | info = $"发生了异常:{ex.Message}"; |
| | | LogHelper.InfoEx(ex); |
| | | return NewSimpleResult(1, info); |
| | | return NewSimpleResult(ex, preLog); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 托盘-空托上线(PDA) |
| | | /// 空托上线出库 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | public static SimpleResult EmptyOnlinePallet(EmptyOnlinePalletInfo model) { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var info = ""; |
| | | |
| | | var taskName = TaskName.T托盘_空托上线; |
| | | var startAreaName = AreaName.K空托存放区; |
| | | var taskInfo = ETask.K空托上线出库.Info(); |
| | | const string preLog = "API:空托上线出库:"; |
| | | const string cntrType = "托盘"; |
| | | |
| | | try { |
| | | // 查容器-物料类型表 |
| | | var cntrItemRel = db.Queryable<TN_Container_ItemType>() |
| | | .Where(i => i.S_CNTR_CODE == model.CntId && i.S_CNTR_TYPE == "托盘") |
| | | .First(); |
| | | // 如果表中存在这个托盘信息,且物料类型与上线所需物料不符,报错 |
| | | // 如果不存在,不作限制(视作第一次上线) |
| | | if (cntrItemRel != null && cntrItemRel.S_ITEM_CODE != model.ItemCode) { |
| | | info = $"容器{model.CntId}已经与物料类型{cntrItemRel.S_ITEM_CODE}绑定,无法用于装载物料{model.ItemCode}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(2, info); |
| | | // 查询容器表:容器类型字段 |
| | | var cntr = db.Queryable<TN_Container>().Where(c => c.S_CODE == model.CntId).First(); |
| | | if (cntr == null) { |
| | | return NewSimpleResult(1, $"容器'{model.CntId}'在[容器表]中不存在,请在前台页面中维护!"); |
| | | } |
| | | if (cntr.S_TYPE != cntrType) { |
| | | return NewSimpleResult(2, preLog + $"容器'{model.CntId}'在[容器表]中的类型是'{cntr.S_TYPE},不是'{cntrType}'!"); |
| | | } |
| | | |
| | | var startLoc = db.Queryable<TN_Location>() |
| | | .LeftJoin<TN_Loc_Container>((l, c) => l.S_CODE == c.S_LOC_CODE) // 联表:货位容器关系表 |
| | | .Where((l, c) => c.S_CNTR_CODE == model.CntId) // 找指定容器号 |
| | | .Where(l => Settings.AreaMap[startAreaName].Contains(l.S_AREA_CODE)) // 限定在空托存放区中找容器货位 |
| | | .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y") // 筛选:没有锁状态 |
| | | .Where(l => l.N_CURRENT_NUM == 1) // 筛选:有货货位 |
| | | .First(); |
| | | var needUpdateContainer = false; |
| | | if (string.IsNullOrEmpty(cntr.S_SPEC)) { |
| | | // TEMP 目前流程:如果容器表中规格 (物料编码) 为空,根据流程的物料信息写入 |
| | | // 待定:后面可能会更改流程,或者用其他信息 (如物料类型/规格) 作为容器的规格 |
| | | |
| | | needUpdateContainer = true; |
| | | cntr.S_SPEC = model.ItemCode; |
| | | LogHelper.Info($"容器'{model.CntId}'在[容器表]中[规格(物料编码)]为空,将物料编码'{model.ItemCode}'写入容器的规格"); |
| | | } |
| | | else if (cntr.S_SPEC != model.ItemCode) { |
| | | return NewSimpleResult(3, $"容器'{model.CntId}'已经与物料类型'{cntr.S_SPEC}'绑定,无法用于装载物料'{model.ItemCode}'!"); |
| | | } |
| | | |
| | | var startLoc = db.Queryable<TN_Location>().LeftJoin<TN_Loc_Container>((l, c) => l.S_CODE == c.S_LOC_CODE).Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y").Where((l, c) => taskInfo.StartAreas.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM == 1 && c.S_CNTR_CODE == model.CntId && c.S_CNTR_TYPE == cntrType).First(); |
| | | if (startLoc == null) { |
| | | info = $"在空托存放区中,找不到符合{model.ItemCode}物料,且编码为{model.CntId}的空托盘"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(3, info); |
| | | return NewSimpleResult(3, preLog + $"没有找到合适的起点货位!要求:锁状态='无';当前容器数量=1;所在库区={LogObject(taskInfo.StartAreas)},绑定容器编码='{model.CntId}',绑定容器类型='{cntrType}'"); |
| | | } |
| | | |
| | | var endLoc = db.Queryable<TN_Location>() |
| | | //.Where(l => Settings.AreaMap[AreaName.B包装区].Contains(l.S_AREA_CODE)) |
| | | .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y") // 筛选:未上锁 |
| | | .Where(l => l.N_CURRENT_NUM == 0) // 筛选:空货位 |
| | | .First(); |
| | | |
| | | // 查询终点货位 |
| | | var endLoc = db.Queryable<TN_Location>().Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y").Where(l => taskInfo.EndAreas.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM == 0).First(); |
| | | if (endLoc == null) { |
| | | info = $"终点位置 不存在或不具备放货要求"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | return NewSimpleResult(5, preLog + $"没有找到合适的终点货位!要求:锁状态='无';当前容器数量=0;所在库区={LogObject(taskInfo.EndAreas)}"); |
| | | } |
| | | |
| | | var cntId = model.CntId; |
| | | var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, taskName); |
| | | WCSHelper.LockStartLoc(ref startLoc); |
| | | WCSHelper.LockEndLoc(ref endLoc); |
| | | var task = WCSHelper.BuildTask(startLoc, endLoc, model.CntId, taskInfo.TaskName); |
| | | |
| | | LocationHelper.LockLoc(ref startLoc, 2); // 起点出库锁 |
| | | LocationHelper.LockLoc(ref endLoc, 1); // 终点入库锁 |
| | | cntr.S_SOURCE = task.S_CODE; // 用任务号作为容器更新的依据 |
| | | cntr.T_MODIFY = DateTime.Now; |
| | | |
| | | using (var tran = db.Ado.UseTran()) { |
| | | if (db.Updateable<TN_Location>(startLoc).UpdateColumns(it => new { |
| | | it.N_LOCK_STATE, |
| | | it.S_LOCK_STATE, |
| | | it.S_LOCK_OP, |
| | | it.T_MODIFY |
| | | }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = $"生成任务'{taskName}'失败:更新起点货位{startLoc.S_CODE}锁状态失败"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | if (needUpdateContainer && db.Updateable(cntr).UpdateColumns(c => new { c.S_SPEC, c.S_SOURCE, c.T_MODIFY }).ExecuteCommand() <= 0) { |
| | | return NewSimpleResult(500, preLog + $"更新[容器表]失败!数据:{LogObject(cntr)}"); |
| | | } |
| | | |
| | | if (db.Updateable<TN_Location>(endLoc).UpdateColumns(it => new { |
| | | it.N_LOCK_STATE, |
| | | it.S_LOCK_STATE, |
| | | it.S_LOCK_OP, |
| | | it.T_MODIFY |
| | | }).ExecuteCommand() <= 0) { |
| | | // 更新[起点/终点]锁状态,创建任务 |
| | | if (db.Updateable(startLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, it.T_MODIFY, it.N_CURRENT_NUM, }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = $"生成任务'{taskName}'失败:更新终点货位{endLoc.S_CODE}锁状态失败"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | return NewSimpleResult(500, preLog + $"更新[起点货位锁状态]失败!起点='{startLoc.S_CODE}',锁状态=>'出库锁'"); |
| | | } |
| | | if (db.Updateable(endLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, it.T_MODIFY, }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(500, preLog + $"更新[终点货位锁状态]失败!终点='{endLoc.S_CODE}',锁状态=>'入库锁'"); |
| | | } |
| | | if (db.Insertable(task).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(500, preLog + $"生成任务'{task.S_TYPE}'失败!任务号={task.S_CODE},容器号={task.S_CNTR_CODE},起点={task.S_START_LOC},终点={task.S_END_LOC}"); |
| | | } |
| | | |
| | | if (db.Insertable<TN_Task>(task).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = $"生成任务'{taskName}'失败,容器号{cntId},起点{startLoc.S_CODE},终点货架{endLoc.S_CODE}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | } |
| | | |
| | | // 提交数据库更改 |
| | | tran.CommitTran(); |
| | | info = $"生成任务'{taskName}'成功,容器号{cntId},起点{startLoc.S_CODE},终点货架{endLoc.S_CODE}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(0, info); |
| | | return NewSimpleResult(0, preLog + $"生成任务'{task.S_TYPE}'成功!任务号={task.S_CODE},容器号={task.S_CNTR_CODE},起点={task.S_START_LOC},终点={task.S_END_LOC}"); |
| | | } |
| | | } |
| | | catch (Exception ex) { |
| | | info = $"发生了异常:{ex.Message}"; |
| | | LogHelper.InfoEx(ex); |
| | | return NewSimpleResult(1, info); |
| | | return NewSimpleResult(ex, preLog); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 好运箱-空箱上线(PDA) |
| | | /// 空箱上线出库 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | public static SimpleResult EmptyOnlineGoodpack(EmptyOnlineGoodpackInfo model) { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var info = ""; |
| | | |
| | | var taskName = TaskName.H好运箱_空箱上线; |
| | | var startAreaName = AreaName.K空托存放区; |
| | | var taskInfo = ETask.K空箱上线出库.Info(); |
| | | const string preLog = "API:空箱上线出库:"; |
| | | const string cntrType = "好运箱"; |
| | | |
| | | try { |
| | | var startLoc = db.Queryable<TN_Location>() |
| | | .LeftJoin<TN_Loc_Container>((l, c) => l.S_CODE == c.S_LOC_CODE) |
| | | .Where((l, c) => c.S_CNTR_CODE == model.CntId) |
| | | .Where(l => Settings.AreaMap[startAreaName].Contains(l.S_AREA_CODE)) |
| | | .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y") |
| | | .Where(l => l.N_CURRENT_NUM == 1) |
| | | .First(); |
| | | var cntr = db.Queryable<TN_Container>().Where(c => c.S_CODE == model.CntId).First(); |
| | | if (cntr == null) { |
| | | return NewSimpleResult(1, preLog + $"容器'{model.CntId}'在[容器表]中不存在,请在前台页面中维护!"); |
| | | } |
| | | if (cntr.S_TYPE != cntrType) { |
| | | return NewSimpleResult(2, preLog + $"容器'{model.CntId}'在[容器表]中的类型='{cntr.S_TYPE}',不是'{cntrType}'!"); |
| | | } |
| | | |
| | | var startLoc = db.Queryable<TN_Location>().LeftJoin<TN_Loc_Container>((l, c) => l.S_CODE == c.S_LOC_CODE).Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y").Where((l, c) => taskInfo.StartAreas.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM == 1 && c.S_CNTR_CODE == model.CntId && c.S_CNTR_TYPE == cntrType).First(); |
| | | if (startLoc == null) { |
| | | info = $"在'{startAreaName}'中,找不到编码为{model.CntId}的空好运箱"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(2, info); |
| | | return NewSimpleResult(2, preLog + $"没有找到合适的起点货位!要求:锁状态='无',当前容器数量=1,所在库区={LogObject(taskInfo.StartAreas)},绑定容器编码='{model.CntId}',绑定容器类型='{cntrType}'"); |
| | | } |
| | | |
| | | var endLoc = db.Queryable<TN_Location>() |
| | | //.Where(l => Settings.AreaMap[AreaName.B包装区].Contains(l.S_AREA_CODE)) |
| | | .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y") // 筛选:未上锁 |
| | | .Where(l => l.N_CURRENT_NUM == 0) |
| | | .First(); |
| | | |
| | | var endLoc = db.Queryable<TN_Location>().Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y") |
| | | .Where(l => taskInfo.EndAreas.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM == 0).First(); |
| | | if (endLoc == null) { |
| | | info = $"终点位置 不存在或不具备放货要求"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | return NewSimpleResult(3, preLog + $"没有找到合适的终点货位!要求:锁状态='无',当前容器数量=0,所在库区={LogObject(taskInfo.EndAreas)}"); |
| | | } |
| | | |
| | | var cntId = model.CntId; |
| | | var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, taskName); |
| | | |
| | | LocationHelper.LockLoc(ref startLoc, 2); // 起点出库锁 |
| | | LocationHelper.LockLoc(ref endLoc, 1); // 终点入库锁 |
| | | |
| | | WCSHelper.LockStartLoc(ref startLoc); |
| | | WCSHelper.LockEndLoc(ref endLoc); |
| | | var task = WCSHelper.BuildTask(startLoc, endLoc, model.CntId, taskInfo.TaskName); |
| | | |
| | | using (var tran = db.Ado.UseTran()) { |
| | | if (db.Updateable<TN_Location>(startLoc).UpdateColumns(it => new { |
| | | it.N_LOCK_STATE, |
| | | it.S_LOCK_STATE, |
| | | it.S_LOCK_OP, |
| | | it.T_MODIFY |
| | | }).ExecuteCommand() <= 0) { |
| | | // 更新[起点/终点]锁状态,创建任务 |
| | | if (db.Updateable(startLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, it.T_MODIFY, it.N_CURRENT_NUM, }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = $"生成任务'{taskName}'失败:更新起点货位{startLoc.S_CODE}锁状态失败"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | return NewSimpleResult(500, preLog + $"更新[起点货位锁状态]失败!起点='{startLoc.S_CODE}',锁状态=>'出库锁'"); |
| | | } |
| | | if (db.Updateable(endLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, it.T_MODIFY, }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(500, preLog + $"更新[终点货位锁状态]失败!终点='{endLoc.S_CODE}',锁状态=>'入库锁'"); |
| | | } |
| | | if (db.Insertable(task).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(500, preLog + $"生成任务'{task.S_TYPE}'失败!任务号={task.S_CODE},容器号={task.S_CNTR_CODE},起点={task.S_START_LOC},终点={task.S_END_LOC}"); |
| | | } |
| | | |
| | | if (db.Updateable<TN_Location>(endLoc).UpdateColumns(it => new { |
| | | it.N_LOCK_STATE, |
| | | it.S_LOCK_STATE, |
| | | it.S_LOCK_OP, |
| | | it.T_MODIFY |
| | | }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = $"生成任务'{taskName}'失败:更新终点货位{endLoc.S_CODE}锁状态失败"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | } |
| | | |
| | | if (db.Insertable<TN_Task>(task).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = $"生成任务'{taskName}'失败,容器号{cntId},起点{startLoc.S_CODE},终点货架{endLoc.S_CODE}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | } |
| | | |
| | | // 提交数据库更改 |
| | | tran.CommitTran(); |
| | | info = $"生成任务'{taskName}'成功,容器号{cntId},起点{startLoc.S_CODE},终点货架{endLoc.S_CODE}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(0, info); |
| | | return NewSimpleResult(0, preLog + $"生成任务'{task.S_TYPE}'成功!任务号={task.S_CODE},容器号={task.S_CNTR_CODE},起点={task.S_START_LOC},终点={task.S_END_LOC}"); |
| | | } |
| | | } |
| | | catch (Exception ex) { |
| | | info = $"发生了异常:{ex.Message}"; |
| | | LogHelper.InfoEx(ex); |
| | | return NewSimpleResult(1, info); |
| | | return NewSimpleResult(ex, preLog); |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 抽检-合格回库(PDA) |
| | | /// 抽检合格回库 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | public static SimpleResult QualifiedBack(QualifiedBackInfo model) { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var info = ""; |
| | | |
| | | var taskName = TaskName.C抽检_合格回库; |
| | | var startAreaName = AreaName.C抽检区; |
| | | var taskInfo = ETask.C抽检合格回库.Info(); |
| | | const string preLog = "API:抽检合格回库"; |
| | | |
| | | try { |
| | | var cgDetail = db.Queryable<TN_CG_Detail>() |
| | | .Where(d => d.S_ITEM_CODE == model.ItemCode && d.S_CNTR_CODE == model.CntrCode) |
| | | .First(); |
| | | |
| | | .Where(d => d.S_ITEM_CODE == model.ItemCode && d.S_CNTR_CODE == model.CntrCode).First(); |
| | | if (cgDetail == null) { |
| | | return NewSimpleResult(2, "没有找到待回库的抽检物料:" + JsonConvert.SerializeObject(model)); |
| | | return NewSimpleResult(2, preLog + "没有找到待回库的抽检物料:" + LogObject(model)); |
| | | } |
| | | |
| | | var locCntrRel = db.Queryable<TN_Loc_Container>() |
| | | .Where(c => c.S_CNTR_CODE == cgDetail.S_CNTR_CODE) |
| | | .First(); |
| | | var locCntrRel = db.Queryable<TN_Loc_Container>().Where(c => c.S_CNTR_CODE == cgDetail.S_CNTR_CODE).First(); |
| | | if (locCntrRel == null) { |
| | | return NewSimpleResult(3, preLog + $"容器{model.CntrCode}在货位容器关系表中不存在"); |
| | | } |
| | | |
| | | var startLoc = db.Queryable<TN_Location>() |
| | | .Where(l => l.S_CODE == locCntrRel.S_LOC_CODE) |
| | | .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y") // 筛选:未上锁 |
| | | .Where(l => l.N_CURRENT_NUM == 1) |
| | | .Where(l => Settings.AreaMap[startAreaName].Contains(l.S_AREA_CODE)) // 起点货区符合任务要求 |
| | | .First(); |
| | | |
| | | var startLoc = db.Queryable<TN_Location>().Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y" && l.S_CODE == locCntrRel.S_LOC_CODE && taskInfo.StartAreas.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM == 1).First(); |
| | | if (startLoc == null) { |
| | | info = $"在'{startAreaName}'中没有找到容器{model.CntrCode}的起点货位,或不具备取货要求:未上锁、有货物"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(0, info); |
| | | return NewSimpleResult(4, preLog + $"没有找到合适的起点货位!要求:锁状态='无',当前容器数量=1,所在库区={LogObject(taskInfo.StartAreas)}"); |
| | | } |
| | | |
| | | var endLoc = new TN_Location(); |
| | | if (locCntrRel.S_CNTR_TYPE == "托盘") { |
| | | endLoc = db.Queryable<TN_Location>() |
| | | .Where(l => Settings.AreaMap[AreaName.M满托货架区].Contains(l.S_AREA_CODE)) |
| | | .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y") // 筛选:未上锁 |
| | | .Where(l => l.N_CURRENT_NUM == 0) // 筛选:空货位 |
| | | .First(); |
| | | } |
| | | else if (locCntrRel.S_CNTR_TYPE == "好运箱") { |
| | | endLoc = db.Queryable<TN_Location>() |
| | | .Where(l => Settings.AreaMap[AreaName.M满箱货架区].Contains(l.S_AREA_CODE)) |
| | | .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y") // 筛选:未上锁 |
| | | .Where(l => l.N_CURRENT_NUM == 0) |
| | | .First(); |
| | | } |
| | | else { |
| | | return NewSimpleResult(2, $"托盘类型{locCntrRel.S_CNTR_TYPE}不合法:托盘号{locCntrRel.S_CNTR_CODE}"); |
| | | } |
| | | |
| | | var endAreas = locCntrRel.S_CNTR_CODE == "托盘" ? taskInfo.EndAreas_Pallet : taskInfo.EndAreas_Goodpack; |
| | | var endLoc = db.Queryable<TN_Location>().Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y" && endAreas.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM == 0).First(); |
| | | if (endLoc == null) { |
| | | info = "查询:没有找到合适的终点货位"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(3, info); |
| | | return NewSimpleResult(3, preLog + $"没有找到合适的终点货位!要求:锁状态='无',当前容器数量=0,所在库区={LogObject(endAreas)}"); |
| | | } |
| | | |
| | | cgDetail.N_ITEM_STATE = 0; |
| | | cgDetail.S_ITEM_STATE = "合格"; |
| | | cgDetail.T_MODIFY = DateTime.Now; |
| | | |
| | | var cntId = locCntrRel.S_CNTR_CODE; |
| | | var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, taskName); |
| | | var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, taskInfo.TaskName); |
| | | |
| | | LocationHelper.LockLoc(ref startLoc, 2); // 起点出库锁 |
| | | LocationHelper.LockLoc(ref endLoc, 1); // 终点入库锁 |
| | | WCSHelper.LockStartLoc(ref startLoc); |
| | | WCSHelper.LockEndLoc(ref endLoc); |
| | | |
| | | using (var tran = db.Ado.UseTran()) { |
| | | if (db.Updateable<TN_CG_Detail>(cgDetail).UpdateColumns(it => |
| | | new { it.N_ITEM_STATE, it.S_ITEM_STATE }).ExecuteCommand() <= 0) { |
| | | if (db.Updateable(cgDetail).UpdateColumns(it => new { it.N_ITEM_STATE, it.S_ITEM_STATE, it.T_MODIFY }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = "修改物料状态为合格 失败"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | return NewSimpleResult(500, preLog + $"更新[物料明细表]失败!物料号='{cgDetail.S_ITEM_CODE}',物料状态=>'合格'"); |
| | | } |
| | | |
| | | if (db.Updateable<TN_Location>(startLoc).UpdateColumns(it => new { |
| | | it.N_LOCK_STATE, |
| | | it.S_LOCK_STATE, |
| | | it.S_LOCK_OP, |
| | | it.T_MODIFY |
| | | }).ExecuteCommand() <= 0) { |
| | | // 更新[起点/终点]锁状态,创建任务 |
| | | if (db.Updateable(startLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, it.T_MODIFY, it.N_CURRENT_NUM, }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = $"生成 {taskName} 失败,容器号 {cntId} ,起点 {startLoc.S_CODE} ,终点货位 {endLoc.S_CODE}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | return NewSimpleResult(500, preLog + $"更新[起点货位锁状态]失败!起点='{startLoc.S_CODE}',锁状态=>'出库锁'"); |
| | | } |
| | | if (db.Updateable(endLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, it.T_MODIFY, }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(500, preLog + $"更新[终点货位锁状态]失败!终点='{endLoc.S_CODE}',锁状态=>'入库锁'"); |
| | | } |
| | | if (db.Insertable(task).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(500, preLog + $"生成任务'{task.S_TYPE}'失败!任务号={task.S_CODE},容器号={task.S_CNTR_CODE},起点={task.S_START_LOC},终点={task.S_END_LOC}"); |
| | | } |
| | | |
| | | if (db.Updateable<TN_Location>(endLoc).UpdateColumns(it => new { |
| | | it.N_LOCK_STATE, |
| | | it.S_LOCK_STATE, |
| | | it.S_LOCK_OP, |
| | | it.T_MODIFY |
| | | }).ExecuteCommand() <= 0) { |
| | | |
| | | tran.RollbackTran(); |
| | | info = $"生成 {taskName} 失败,容器号 {cntId} ,起点 {startLoc.S_CODE} ,终点货架 {endLoc.S_CODE}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | } |
| | | |
| | | if (db.Insertable<TN_Task>(task).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = $"生成 {taskName} 失败,容器号 {cntId} ,起点 {startLoc.S_CODE} ,终点货架 {endLoc.S_CODE}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | } |
| | | |
| | | // 提交数据库更改 |
| | | tran.CommitTran(); |
| | | return NewSimpleResult(0, |
| | | $"生成 {taskName} 成功,容器号 {cntId} ,起点 {startLoc.S_CODE} ,终点货架 {endLoc.S_CODE}"); |
| | | return NewSimpleResult(0, preLog + $"生成任务'{task.S_TYPE}'成功!任务号={task.S_CODE},容器号={task.S_CNTR_CODE},起点={task.S_START_LOC},终点={task.S_END_LOC}"); |
| | | } |
| | | } |
| | | catch (Exception ex) { |
| | | info = $"发生了异常:{ex.Message}"; |
| | | LogHelper.InfoEx(ex); |
| | | return NewSimpleResult(1, info); |
| | | return NewSimpleResult(ex, preLog); |
| | | } |
| | | } |
| | | public static SimpleResult UnqualifiedShift(UnqualifiedShiftInfo model) { |
| | | var taskName = TaskName.C抽检_不合格移库; |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var info = ""; |
| | | try { |
| | | |
| | | if (!Settings.AreaMap[AreaName.C抽检异常区].Contains(model.EndArea)) { |
| | | info = $"终点库区{model.EndArea}不属于{AreaName.C抽检异常区}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(1, info); |
| | | /// <summary> |
| | | /// 抽检不合格移库 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | public static SimpleResult UnqualifiedShift(UnqualifiedShiftInfo model) { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var taskInfo = ETask.C抽检不合格移库.Info(); |
| | | const string preLog = "API:抽检不合格移库:"; |
| | | |
| | | try { |
| | | if (!taskInfo.EndAreas.Contains(model.EndArea)) { |
| | | return NewSimpleResult(1, preLog + $"终点库区'{model.EndArea}'不满足条件!需要:货区={LogObject(taskInfo.EndAreas)}"); |
| | | } |
| | | |
| | | var cgDetail = db.Queryable<TN_CG_Detail>() |
| | | .Where(d => d.S_ITEM_CODE == model.ItemCode && d.S_CNTR_CODE == model.CntrCode) |
| | | .First(); |
| | | |
| | | .Where(d => d.S_ITEM_CODE == model.ItemCode && d.S_CNTR_CODE == model.CntrCode).First(); |
| | | if (cgDetail == null) { |
| | | |
| | | return NewSimpleResult(2, "没有找到待回库的抽检物料"); |
| | | return NewSimpleResult(2, preLog + $"没有在[物料明细表]中找到物料!要求:物料编码='{model.ItemCode}',容器编码='{model.CntrCode}'"); |
| | | } |
| | | |
| | | var locCntrRel = db.Queryable<TN_Loc_Container>() |
| | | .Where(c => c.S_CNTR_CODE == cgDetail.S_CNTR_CODE) |
| | | .First(); |
| | | var locCntrRel = db.Queryable<TN_Loc_Container>().Where(c => c.S_CNTR_CODE == cgDetail.S_CNTR_CODE).First(); |
| | | if (locCntrRel == null) { |
| | | return NewSimpleResult(3, preLog + $"在[货位容器关系表]中没有找到容器'{model.CntrCode}'!"); |
| | | } |
| | | |
| | | //var startLoc = db.Queryable<TN_Location>() |
| | | // .LeftJoin<TN_Loc_Container>((l, c) => l.S_CODE == c.S_LOC_CODE) |
| | | // .Where((l, c) => c.S_CNTR_CODE == cgDetail.S_CNTR_CODE) // 指定容器号 |
| | | // .Where(a => a.N_LOCK_STATE == 0 && a.S_LOCK_STATE == "无" && a.C_ENABLE == "Y") // 筛选:未上锁 |
| | | // .First(); |
| | | |
| | | var startLoc = db.Queryable<TN_Location>() |
| | | .Where(l => l.S_CODE == locCntrRel.S_LOC_CODE) |
| | | .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y") // 筛选:未上锁 |
| | | .Where(l => l.N_CURRENT_NUM == 1) |
| | | .Where(l => Settings.AreaMap[AreaName.C抽检区].Contains(l.S_AREA_CODE)) // 起点货区符合任务要求 |
| | | .First(); |
| | | |
| | | // 查询起点货位:数量=1 |
| | | var startLoc = db.Queryable<TN_Location>().Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y" && l.S_CODE == locCntrRel.S_LOC_CODE && taskInfo.StartAreas.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM == 1).First(); |
| | | if (startLoc == null) { |
| | | info = "没有找到合适的起点货位"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(0, info); |
| | | return NewSimpleResult(1, preLog + $"没有找到起点货位'{locCntrRel.S_LOC_CODE}'!要求:锁状态='无';当前容器数量=1;所在库区={LogObject(taskInfo.StartAreas)}"); |
| | | } |
| | | |
| | | var endLoc = db.Queryable<TN_Location>() |
| | | .Where(l => l.S_AREA_CODE == model.EndArea) |
| | | .Where(a => a.N_LOCK_STATE == 0 && a.S_LOCK_STATE == "无" && a.C_ENABLE == "Y") // 筛选:未上锁 |
| | | .Where(a => a.N_CURRENT_NUM == 0) |
| | | .First(); |
| | | |
| | | var endLoc = db.Queryable<TN_Location>().Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y" && l.S_AREA_CODE == model.EndArea && l.N_CURRENT_NUM == 0).First(); |
| | | if (endLoc == null) { |
| | | return NewSimpleResult(3, "查询:没有找到合适的终点货位"); |
| | | return NewSimpleResult(3, preLog + $"没有找到合适的终点货位!要求:锁状态='无',当前容器数量=0,所在库区='{model.EndArea}'"); |
| | | } |
| | | |
| | | cgDetail.N_ITEM_STATE = 2; |
| | | cgDetail.S_ITEM_STATE = "不合格"; |
| | | |
| | | var cntId = locCntrRel.S_CNTR_CODE; |
| | | var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, taskName); |
| | | |
| | | LocationHelper.LockLoc(ref startLoc, 2); // 起点出库锁 |
| | | LocationHelper.LockLoc(ref endLoc, 1); // 终点入库锁 |
| | | WCSHelper.LockStartLoc(ref startLoc); |
| | | WCSHelper.LockEndLoc(ref endLoc); |
| | | var task = WCSHelper.BuildTask(startLoc, endLoc, locCntrRel.S_CNTR_CODE, taskInfo.TaskName); |
| | | |
| | | using (var tran = db.Ado.UseTran()) { |
| | | if (db.Updateable<TN_CG_Detail>(cgDetail).UpdateColumns(it => |
| | | new { it.N_ITEM_STATE, it.S_ITEM_STATE }).ExecuteCommand() <= 0) { |
| | | if (db.Updateable(cgDetail).UpdateColumns(it => new { it.N_ITEM_STATE, it.S_ITEM_STATE }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = "修改物料状态为合格 失败"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | return NewSimpleResult(500, preLog + $"更新[货品明细表]失败!物料号='{cgDetail}',物料状态=>'{cgDetail.S_ITEM_STATE}'"); |
| | | } |
| | | |
| | | if (db.Updateable<TN_Location>(startLoc).UpdateColumns(it => new { |
| | | it.N_LOCK_STATE, |
| | | it.S_LOCK_STATE, |
| | | it.S_LOCK_OP, |
| | | it.T_MODIFY |
| | | }).ExecuteCommand() <= 0) { |
| | | // 更新[起点/终点]锁状态,创建任务 |
| | | if (db.Updateable(startLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, it.T_MODIFY, it.N_CURRENT_NUM, }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = $"生成 {taskName} 失败,容器号 {cntId} ,起点 {startLoc.S_CODE} ,终点货位 {endLoc.S_CODE}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | return NewSimpleResult(500, preLog + $"更新[起点货位锁状态]失败!起点='{startLoc.S_CODE}',锁状态=>'出库锁'"); |
| | | } |
| | | if (db.Updateable(endLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, it.T_MODIFY, }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(500, preLog + $"更新[终点货位锁状态]失败!终点='{endLoc.S_CODE}',锁状态=>'入库锁'"); |
| | | } |
| | | if (db.Insertable(task).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(500, preLog + $"生成任务'{task.S_TYPE}'失败!任务号={task.S_CODE},容器号={task.S_CNTR_CODE},起点={task.S_START_LOC},终点={task.S_END_LOC}"); |
| | | } |
| | | |
| | | if (db.Updateable<TN_Location>(endLoc).UpdateColumns(it => new { |
| | | it.N_LOCK_STATE, |
| | | it.S_LOCK_STATE, |
| | | it.S_LOCK_OP, |
| | | it.T_MODIFY |
| | | }).ExecuteCommand() <= 0) { |
| | | |
| | | tran.RollbackTran(); |
| | | info = $"生成 {taskName} 失败,容器号 {cntId} ,起点 {startLoc.S_CODE} ,终点货架 {endLoc.S_CODE}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | } |
| | | |
| | | if (db.Insertable<TN_Task>(task).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = $"生成 {taskName} 失败,容器号 {cntId} ,起点 {startLoc.S_CODE} ,终点货架 {endLoc.S_CODE}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | } |
| | | |
| | | // 提交数据库更改 |
| | | tran.CommitTran(); |
| | | return NewSimpleResult(0, |
| | | $"生成 {taskName} 成功,容器号 {cntId} ,起点 {startLoc.S_CODE} ,终点货架 {endLoc.S_CODE}"); |
| | | return NewSimpleResult(0, preLog + $"生成任务'{task.S_TYPE}'成功!任务号={task.S_CODE},容器号={task.S_CNTR_CODE},起点={task.S_START_LOC},终点={task.S_END_LOC}"); |
| | | } |
| | | } |
| | | catch (Exception ex) { |
| | | info = $"发生了异常:{ex.Message}"; |
| | | LogHelper.InfoEx(ex); |
| | | return NewSimpleResult(1, info); |
| | | } |
| | | } |
| | | |
| | | public static SimpleResult RestBack(RestBackInfo model) { |
| | | var taskName = TaskName.W尾箱回库; |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var info = ""; |
| | | try { |
| | | var startLoc = db.Queryable<TN_Location>() |
| | | .Where(l => l.S_CODE == model.StartLoc) |
| | | .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y") // 筛选:未上锁 |
| | | .Where(l => l.N_CURRENT_NUM == 1) |
| | | .First(); |
| | | |
| | | var locCntrRel = db.Queryable<TN_Loc_Container>() |
| | | .Where(c => c.S_LOC_CODE == model.StartLoc) |
| | | .First(); |
| | | |
| | | if (locCntrRel == null) { |
| | | info = $"没有找到起点货位{model.StartLoc},或不具备取货要求:未上锁、有货物"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(3, info); |
| | | } |
| | | |
| | | var endLoc = new TN_Location(); |
| | | if (locCntrRel.S_CNTR_TYPE == "托盘") { |
| | | endLoc = db.Queryable<TN_Location>() |
| | | .Where(l => Settings.AreaMap[AreaName.M满托货架区].Contains(l.S_AREA_CODE)) |
| | | .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y") // 筛选:未上锁 |
| | | .Where(l => l.N_CURRENT_NUM == 0) // 起点绑定前没有容器 |
| | | .First(); |
| | | } |
| | | else if (locCntrRel.S_CNTR_TYPE =="好运箱"){ |
| | | endLoc = db.Queryable<TN_Location>() |
| | | .Where(l => Settings.AreaMap[AreaName.M满箱货架区].Contains(l.S_AREA_CODE)) |
| | | .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y") // 筛选:未上锁 |
| | | .Where(l => l.N_CURRENT_NUM == 0) // 起点绑定前没有容器 |
| | | .First(); |
| | | } |
| | | else { |
| | | endLoc = null; |
| | | } |
| | | |
| | | if (endLoc == null) { |
| | | info = "查询:没有找到合适的终点货位"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(3, info); |
| | | } |
| | | var cntId = locCntrRel.S_CNTR_CODE; |
| | | var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, taskName); |
| | | |
| | | LocationHelper.LockLoc(ref startLoc, 2); // 起点出库锁 |
| | | LocationHelper.LockLoc(ref endLoc, 1); // 终点入库锁 |
| | | |
| | | using (var tran = db.Ado.UseTran()) { |
| | | if (db.Updateable<TN_Location>(startLoc).UpdateColumns(it => new { |
| | | it.N_LOCK_STATE, |
| | | it.S_LOCK_STATE, |
| | | it.S_LOCK_OP, |
| | | it.T_MODIFY |
| | | }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = $"生成 {taskName} 失败,容器号 {cntId} ,起点 {startLoc.S_CODE} ,终点货位 {endLoc.S_CODE}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | } |
| | | |
| | | if (db.Updateable<TN_Location>(endLoc).UpdateColumns(it => new { |
| | | it.N_LOCK_STATE, |
| | | it.S_LOCK_STATE, |
| | | it.S_LOCK_OP, |
| | | it.T_MODIFY |
| | | }).ExecuteCommand() <= 0) { |
| | | |
| | | tran.RollbackTran(); |
| | | info = $"生成 {taskName} 失败,容器号 {cntId} ,起点 {startLoc.S_CODE} ,终点货架 {endLoc.S_CODE}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | } |
| | | |
| | | if (db.Insertable<TN_Task>(task).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = $"生成 {taskName} 失败,容器号 {cntId} ,起点 {startLoc.S_CODE} ,终点货架 {endLoc.S_CODE}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | } |
| | | |
| | | tran.CommitTran(); |
| | | info = $"生成 {taskName} 成功,容器号 {cntId} ,起点 {startLoc.S_CODE} ,终点货架 {endLoc.S_CODE}"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(0, info); |
| | | } |
| | | } |
| | | catch (Exception ex) { |
| | | info = $"发生了异常:{ex.Message}"; |
| | | LogHelper.InfoEx(ex); |
| | | return NewSimpleResult(1, info); |
| | | return NewSimpleResult(ex, preLog); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 成品胶出库(WMS) |
| | | /// 尾料回库/余料回库 |
| | | /// </summary> |
| | | /// <remarks> |
| | | /// WMS提供出库的物料类型与数量,调用接口由WCS生成具体的出库任务,然后WCS后台轮询处理 |
| | | /// </remarks> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | public static SimpleResult RestBack(RestBackInfo model) { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var taskInfo = ETask.W尾料回库.Info(); |
| | | const string preLog = "API:尾料回库:"; |
| | | |
| | | try { |
| | | var startLoc = db.Queryable<TN_Location>().Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y" && l.S_CODE == model.StartLoc && l.N_CURRENT_NUM == 1).First(); |
| | | if (startLoc == null) { |
| | | return NewSimpleResult(2, $"没有找到起点货位'{model.StartLoc}'!要求:锁状态='无';当前容器数量=1"); |
| | | } |
| | | |
| | | var locCntrRel = db.Queryable<TN_Loc_Container>().Where(c => c.S_LOC_CODE == model.StartLoc).First(); |
| | | if (locCntrRel == null) { |
| | | return NewSimpleResult(3, preLog + $"没有找到起点货位{model.StartLoc}所绑定的容器"); |
| | | } |
| | | |
| | | var endAreas = locCntrRel.S_CNTR_CODE == "托盘" ? taskInfo.EndAreas_Pallet : taskInfo.EndAreas_Goodpack; |
| | | var endLoc = db.Queryable<TN_Location>().Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "无" && l.C_ENABLE == "Y" && endAreas.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM == 0).First(); |
| | | if (endLoc == null) { |
| | | return NewSimpleResult(3, preLog + $"没有找到合适的终点货位!要求:锁状态='无',当前容器数量=0,所在库区={LogObject(endAreas)}"); |
| | | } |
| | | |
| | | var cntId = locCntrRel.S_CNTR_CODE; |
| | | |
| | | WCSHelper.LockStartLoc(ref startLoc); |
| | | WCSHelper.LockEndLoc(ref endLoc); |
| | | var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, taskInfo.TaskName); |
| | | |
| | | using (var tran = db.Ado.UseTran()) { |
| | | //if (db.Insertable(locCntrRel).ExecuteCommand() <= 0) { |
| | | // tran.RollbackTran(); |
| | | // return NewSimpleResult(500, preLog + $"插入[容器货位绑定表]失败!数据:{LogObject(locCntrRel)}"); |
| | | //} |
| | | |
| | | // 更新[起点/终点]锁状态,创建任务 |
| | | if (db.Updateable(startLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, it.T_MODIFY, it.N_CURRENT_NUM, }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(500, preLog + $"更新[起点货位锁状态]失败!起点='{startLoc.S_CODE}',锁状态=>'出库锁'"); |
| | | } |
| | | if (db.Updateable(endLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, it.T_MODIFY, }).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(500, preLog + $"更新[终点货位锁状态]失败!终点='{endLoc.S_CODE}',锁状态=>'入库锁'"); |
| | | } |
| | | if (db.Insertable(task).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(500, preLog + $"生成任务'{task.S_TYPE}'失败!任务号={task.S_CODE},容器号={task.S_CNTR_CODE},起点={task.S_START_LOC},终点={task.S_END_LOC}"); |
| | | } |
| | | |
| | | // 提交数据库更改 |
| | | tran.CommitTran(); |
| | | return NewSimpleResult(0, preLog + $"生成任务'{task.S_TYPE}'成功!任务号={task.S_CODE},容器号={task.S_CNTR_CODE},起点={task.S_START_LOC},终点={task.S_END_LOC}"); |
| | | } |
| | | } |
| | | catch (Exception ex) { |
| | | return NewSimpleResult(ex, preLog); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 成品胶出库(PDA) 待定,暂时不需要此功能 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | public static SimpleResult FinishedOutbound(FinishedOutboundInfo model) { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var orderNo = GenerateOrderNo("出库单号", "ON"); |
| | | var info = ""; |
| | | try { |
| | | if (string.IsNullOrEmpty(orderNo)) { |
| | | info = "出库单号不能为空"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(2, info); |
| | | } |
| | | var taskInfo = ETask.C成品胶出库.Info(); |
| | | const string preLog = "API:成品胶出库:"; |
| | | |
| | | var cgDetailList = SelectCgByTotalQty(model); |
| | | try { |
| | | var orderNo = GenerateOrderNo("出库单号", "CKD"); |
| | | |
| | | var cgDetailList = SelectCgByTotalQty(model.Qty, model.ItemCode, model.BatchNo, model.CntrType, model.ForcedOut); |
| | | |
| | | if (cgDetailList.Count == 0) { |
| | | info = "没有合适的物料可以出库"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(3, info); |
| | | return NewSimpleResult(3, preLog + $"没有合适的物料可以出库"); |
| | | } |
| | | |
| | | var order = new TN_Outbound_Order { |
| | |
| | | S_ITEM_CODE = model.ItemCode, |
| | | S_BATCH = model.BatchNo, |
| | | N_END_NUM = model.Qty, |
| | | //F_OUT_QTY = cgDetailList.Sum(a => a.N_QTY), |
| | | S_END_AREA = model.EndArea |
| | | }; |
| | | |
| | |
| | | } |
| | | |
| | | using (var tran = db.Ado.UseTran()) { |
| | | if (db.Insertable<TN_Outbound_Order>(order).ExecuteCommand() <= 0) { |
| | | if (db.Insertable(order).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = "生成出库单失败:" + JsonConvert.SerializeObject(order); |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(2, info); |
| | | return NewSimpleResult(2, preLog + "生成出库单失败:" + LogObject(order)); |
| | | } |
| | | |
| | | if (db.Insertable<TN_Outbound_Detail>(detailList).ExecuteCommand() <= 0) { |
| | | if (db.Insertable(detailList).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = "生成出库单明细失败"; |
| | | LogHelper.Info(info); |
| | | return NewSimpleResult(4, info); |
| | | return NewSimpleResult(4, preLog + "生成出库单明细失败:" + LogObject(detailList)); |
| | | } |
| | | |
| | | tran.CommitTran(); |
| | | } |
| | | |
| | | return NewSimpleResult(0, "生成出库单成功"); |
| | | return NewSimpleResult(0, preLog + "生成出库单成功"); |
| | | } |
| | | catch (Exception ex) { |
| | | info = $"发生了异常:{ex.Message}"; |
| | | LogHelper.InfoEx(ex); |
| | | return NewSimpleResult(1, info); |
| | | return NewSimpleResult(ex, preLog); |
| | | } |
| | | } |
| | | |
| | |
| | | /// <returns></returns> |
| | | public static SimpleResult FinishedOutboundForce(FinishedOutboundInfo model) { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var orderNo = GenerateOrderNo("出库单号", "ON"); |
| | | var info = ""; |
| | | var taskInfo = ETask.C成品胶出库.Info(); |
| | | const string preLog = "API:成品胶出库:"; |
| | | |
| | | try { |
| | | if (string.IsNullOrEmpty(orderNo)) { |
| | | return NewSimpleResult(2, "出库单号不能为空"); |
| | | var orderNo = GenerateOrderNo("出库单号", "CKD"); |
| | | |
| | | var cgDetailList = SelectCgByTotalQty(model.Qty, model.ItemCode, model.BatchNo, model.CntrType, model.ForcedOut); |
| | | |
| | | if (cgDetailList.Count == 0) { |
| | | return NewSimpleResult(3, preLog + $"没有合适的物料可以出库"); |
| | | } |
| | | |
| | | var order = new TN_Outbound_Order { |
| | | S_NO = orderNo, |
| | | S_ITEM_CODE = model.ItemCode, |
| | | S_BATCH = model.BatchNo, |
| | | N_END_NUM = model.Qty, |
| | | S_END_AREA = model.EndArea |
| | | }; |
| | | |
| | | var detailList = new List<TN_Outbound_Detail>(); |
| | | foreach (var cgDetail in cgDetailList) { |
| | | var detail = new TN_Outbound_Detail { |
| | | S_OO_NO = orderNo, |
| | | S_ITEM_CODE = cgDetail.S_ITEM_CODE, |
| | | S_BATCH_NO = cgDetail.S_BATCH_NO, |
| | | S_CNTR_CODE = cgDetail.S_CNTR_CODE, |
| | | N_COUNT = cgDetail.N_ITEM_NUM, |
| | | S_END_AREA = model.EndArea |
| | | }; |
| | | detailList.Add(detail); |
| | | } |
| | | |
| | | using (var tran = db.Ado.UseTran()) { |
| | | |
| | | var cgDetailList = SelectCgByTotalQty(model); |
| | | |
| | | if (cgDetailList.Count == 0) { |
| | | return NewSimpleResult(3, "没有合适的物料可以出库"); |
| | | } |
| | | |
| | | foreach (var cgDetail in cgDetailList) { |
| | | var detail = new TN_Outbound_Detail { |
| | | S_OO_NO = orderNo, |
| | | S_ITEM_CODE = cgDetail.S_ITEM_CODE, |
| | | S_BATCH_NO = cgDetail.S_BATCH_NO, |
| | | S_CNTR_CODE = cgDetail.S_CNTR_CODE, |
| | | S_END_AREA = model.EndArea |
| | | }; |
| | | |
| | | if (db.Insertable<TN_Outbound_Detail>(detail).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(4, "生成出库单明细失败:" + JsonConvert.SerializeObject(detail)); |
| | | } |
| | | } |
| | | |
| | | var order = new TN_Outbound_Order { |
| | | S_NO = orderNo, |
| | | S_ITEM_CODE = model.ItemCode, |
| | | S_BATCH = model.BatchNo, |
| | | N_END_NUM = model.Qty, |
| | | //F_OUT_QTY = cgDetailList.Sum(a => a.N_QTY), |
| | | S_END_AREA = model.EndArea |
| | | }; |
| | | |
| | | if (db.Insertable<TN_Outbound_Order>(order).ExecuteCommand() <= 0) { |
| | | if (db.Insertable(order).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(5, "生成出库单失败:" + JsonConvert.SerializeObject(order)); |
| | | return NewSimpleResult(2, preLog + "生成出库单失败:" + LogObject(order)); |
| | | } |
| | | |
| | | if (db.Insertable(detailList).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewSimpleResult(4, preLog + "生成出库单明细失败:" + LogObject(detailList)); |
| | | } |
| | | |
| | | tran.CommitTran(); |
| | | } |
| | | |
| | | return NewSimpleResult(0, "生成出库单成功"); |
| | | return NewSimpleResult(0, preLog + "生成出库单成功"); |
| | | } |
| | | catch (Exception ex) { |
| | | info = $"发生了异常:{ex.Message}"; |
| | | LogHelper.InfoEx(ex); |
| | | return NewSimpleResult(1, info); |
| | | return NewSimpleResult(ex, preLog); |
| | | } |
| | | } |
| | | |
| | | public static List<TN_CG_Detail> SelectCgByTotalQty(FinishedOutboundInfo model) { |
| | | public static List<TN_CG_Detail> SelectCgByTotalQty(int qty, string itemCode, string batchNo, string cntrType = "", bool forcedOut = true) { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var result = new List<TN_CG_Detail>(); |
| | | var targetNum = model.Qty; |
| | | var info = ""; |
| | | var targetNum = qty; |
| | | try { |
| | | var targetCg = db.Queryable<TN_CG_Detail>() |
| | | .Where(a => a.S_ITEM_CODE == model.ItemCode && a.S_BATCH_NO == model.BatchNo) |
| | | .Where(a => a.S_ITEM_CODE == itemCode && a.S_BATCH_NO == batchNo) |
| | | .Where(a => a.N_ITEM_NUM > targetNum) |
| | | .OrderBy(a => a.N_ITEM_NUM, OrderByType.Asc).First(); |
| | | if (targetCg != null) //刚好有一行满足条件 |
| | |
| | | return result; |
| | | } |
| | | |
| | | // NOTE 根据总量选detail时,是否需要考虑货位的高低? |
| | | // NOTE 根据总量选detail时,是否需要考虑货位的高低? |
| | | |
| | | var sortedMaterials = new List<TN_CG_Detail>(); |
| | | |
| | | if (model.ForcedOut) { |
| | | var cntrTypeList = new List<string>(); |
| | | if (cntrType == "") { |
| | | cntrTypeList = new List<string> { "托盘", "好运箱" }; // 不指定托盘类型,二者均可 |
| | | } |
| | | else { |
| | | cntrTypeList.Add(cntrType); |
| | | } |
| | | |
| | | if (forcedOut) { |
| | | sortedMaterials = db.Queryable<TN_CG_Detail, TN_Loc_Container>((d, c) => d.S_CNTR_CODE == c.S_CNTR_CODE) |
| | | .Where(d => d.S_ITEM_CODE == model.ItemCode && d.S_BATCH_NO == model.BatchNo && d.N_ITEM_NUM > 0) |
| | | .Where((d, c) => c.S_CNTR_TYPE == model.CntrType) |
| | | .Where(d => d.S_ITEM_CODE == itemCode && d.S_BATCH_NO == batchNo && d.N_ITEM_NUM > 0) |
| | | .Where((d, c) => cntrTypeList.Contains(c.S_CNTR_TYPE)) |
| | | .Where(d => d.N_ITEM_STATE == 0 && d.S_ITEM_STATE == "合格" |
| | | || d.N_ITEM_STATE == 1 && d.S_ITEM_STATE == "待检") |
| | | .OrderBy(d => d.N_ITEM_NUM, OrderByType.Desc) |
| | |
| | | } |
| | | else { |
| | | sortedMaterials = db.Queryable<TN_CG_Detail, TN_Loc_Container>((d, c) => d.S_CNTR_CODE == c.S_CNTR_CODE) |
| | | .Where(d => d.S_ITEM_CODE == model.ItemCode && d.S_BATCH_NO == model.BatchNo && d.N_ITEM_NUM > 0) |
| | | .Where((d, c) => c.S_CNTR_TYPE == model.CntrType) |
| | | .Where(d => d.S_ITEM_CODE == itemCode && d.S_BATCH_NO == batchNo && d.N_ITEM_NUM > 0) |
| | | .Where((d, c) => cntrTypeList.Contains(c.S_CNTR_TYPE)) |
| | | .Where(d => d.N_ITEM_STATE == 0 && d.S_ITEM_STATE == "合格") |
| | | .OrderBy(d => d.N_ITEM_NUM, OrderByType.Desc) |
| | | .OrderBy(d => d.N_ITEM_STATE, OrderByType.Asc).ToList(); |
| | | } |
| | | |
| | | |
| | | if (sortedMaterials.Count == 0) //没有满足条件的 |
| | | { |
| | |
| | | } |
| | | } |
| | | catch (Exception ex) { |
| | | info = $"发生了异常:{ex.Message}"; |
| | | LogHelper.InfoEx(ex); |
| | | return result; |
| | | } |
| | |
| | | private static string GenerateOrderNo(string snType, string prefix) { |
| | | var id = SYSHelper.GetSerialNumber(snType, prefix); |
| | | var date = DateTime.Now.ToString("yyMMdd"); |
| | | return $"{prefix}{date}{id.ToString().PadLeft(4, '0')}"; |
| | | return $"{prefix}{date}-{id.ToString().PadLeft(4, '0')}"; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 博实物料信息下发同步 |
| | | /// 博实物料信息下发同步 (只针对好运箱) |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | public static MesResult CgInfoSync(CgInfoSyncInfo model) { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var random = new Random(); |
| | | var info = ""; |
| | | const string preLog = "API:博实下发物料信息:"; |
| | | const string cntrType = "好运箱"; |
| | | |
| | | try { |
| | | if (string.IsNullOrEmpty(model.ItemCode)) { |
| | | return NewMesResult(400, preLog + $"物料编码'{model.ItemCode}'不能为空!"); |
| | | } |
| | | if (string.IsNullOrEmpty(model.CntrCode)) { |
| | | return NewMesResult(400, preLog + $"容器编码'{model.CntrCode}'不能为空!"); |
| | | } |
| | | if (string.IsNullOrEmpty(model.BatchNo)) { |
| | | return NewMesResult(400, preLog + $"批次号'{model.BatchNo}'不能为空!"); |
| | | } |
| | | if (model.ItemNum <= 0) { |
| | | return NewMesResult(400, preLog + $"物料数量'{model.ItemNum}'不合法!要求:物料数量>0"); |
| | | } |
| | | |
| | | // TEMP 目前流程:对博实下发的信息也进行检查,未找到就报错,后面有需求再更改 |
| | | var cntr = db.Queryable<TN_Container>() |
| | | .Where(c => c.S_CODE == model.CntrCode) // 对于前台程序而言,S_CODE就是主键,维护时必定唯一 |
| | | .First(); |
| | | |
| | | if (cntr == null) { |
| | | return NewMesResult(1, preLog + $"容器'{model.CntrCode}'在[容器表]中不存在,请在前台页面中维护!"); |
| | | } |
| | | if (cntr.S_TYPE != cntrType) { |
| | | return NewMesResult(2, preLog + $"容器'{model.CntrCode}'在[容器表]中的类型为'{cntr.S_TYPE}',与当前容器类型'{cntrType}'不同!"); |
| | | } |
| | | |
| | | // 将下发的信息先存储到CG表中 (此时托盘没有与产线处的货位绑定) |
| | | var detail = new TN_CG_Detail { |
| | | S_ITEM_CODE = model.ItemCode, |
| | | S_ITEM_NAME = model.ItemName, |
| | | S_CNTR_CODE = GenerateOrderNo("容器号", "CN"), // NOTE 容器号:目前随机(后期可能会指定,或者PDA绑定时再填入) |
| | | S_BATCH_NO = model.BatchNo, |
| | | S_ITEM_CODE = model.ItemCode, // NOT NULL |
| | | S_ITEM_NAME = model.ItemName, |
| | | S_CNTR_CODE = model.CntrCode, // NOT NULL 料箱编号 (待定,现在暂时设定为博实下发) |
| | | S_BATCH_NO = model.BatchNo, // NOT NULL |
| | | S_STANDARD = model.Standard, |
| | | S_NET_WEIGHT = model.NetWeight, |
| | | S_QUALITY_GRADE = model.QualityGrade, |
| | | //N_PRODUCT_LINE = random.Next(0, 3), // NOTE 产线号:目前随机(后期可能会指定,或者PDA绑定时再填入) |
| | | }; |
| | | |
| | | //var locCntrRel = new TN_Loc_Container { |
| | | // //S_LOC_CODE = Settings.Config.ProductionLines[detail.N_PRODUCT_LINE].OffLoc[0], // 好运箱的位置是操作区,不是产线 |
| | | // S_CNTR_CODE = detail.S_CNTR_CODE, |
| | | // S_CNTR_TYPE = "好运箱", // 贴标机只针对好运箱 |
| | | //}; |
| | | // 产线号的逻辑待定,现在设定为博实下发产线号,看后续需求变更 |
| | | // 好运箱起点为产线货位,人工将好运箱从产线上取下,搬运到满好运箱操作区 |
| | | //var startLocCode = ""; |
| | | //if (model.ProdLineId.Trim() == "3") { |
| | | // startLocCode = ""; |
| | | //} |
| | | |
| | | using (var tran = db.Ado.UseTran()) { |
| | | if (db.Insertable<TN_CG_Detail>(detail).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = "插入物料信息失败:" + JsonConvert.SerializeObject(detail); |
| | | return NewMesResult(2, info); |
| | | } |
| | | //if (model.ProdLineId.Trim() != "3" || model.ProdLineId.Trim() != "4") { |
| | | // info = $"不合法的产线号{model.ProdLineId}:好运箱产线号必须为 3 或 4"; |
| | | // LogHelper.Info(info); |
| | | // return NewMesResult(2, info); |
| | | //} |
| | | |
| | | //if (db.Insertable<TN_Loc_Container>(locCntrRel).ExecuteCommand() <= 0) { |
| | | // tran.RollbackTran(); |
| | | // info = "插入物料信息失败:" + JsonConvert.SerializeObject(detail); |
| | | // return NewWmsResult(2, info); |
| | | //} |
| | | |
| | | tran.CommitTran(); |
| | | if (db.Insertable(detail).ExecuteCommand() <= 0) { |
| | | return NewMesResult(500, preLog + $"插入[物料明细表]失败!数据:{LogObject(detail)}"); |
| | | } |
| | | |
| | | info = "插入物料信息成功"; |
| | | return NewMesResult(0, info); |
| | | return NewMesResult(500, preLog + $"插入[物料明细表]成功!数据:{LogObject(detail)}"); |
| | | } |
| | | catch (Exception ex) { |
| | | info = $"发生了异常:{ex.Message}"; |
| | | LogHelper.InfoEx(ex); |
| | | return NewMesResult(1, info); |
| | | return NewMesResult(-1, preLog + $"发生了异常:{ex.Message}\n\n{ex.StackTrace}\n"); |
| | | } |
| | | } |
| | | |
| | | public static ErpResult ErpSendOutboundOrder(ErpSendOutboundOrderInfo model) { |
| | | public static ErpResult ErpSendOutboundPlan(ErpSendOutboundPlanInfo model) { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var orderNo = GenerateOrderNo("出库单号", "ON"); |
| | | var info = ""; |
| | | var orderNo = GenerateOrderNo("出库单号", "CKD"); |
| | | const string preLog = "API:ERP下发出库计划单:"; |
| | | try { |
| | | if (string.IsNullOrEmpty(orderNo)) { |
| | | info = "出库单号不能为空"; |
| | | LogHelper.Info(info); |
| | | return NewErpResult(2, info); |
| | | if (model.pzjs <= 0) { |
| | | return NewErpResult(400, preLog + $"物料数量(pzjs)'{model.pzjs}'不合法!要求:物料数量>0"); |
| | | } |
| | | |
| | | var cgDetailList = SelectCgByTotalQty(new FinishedOutboundInfo { |
| | | BatchNo = model.BatchNo, |
| | | CntrType= model.CntrType, |
| | | ItemCode= model.ItemCode, |
| | | EndArea= model.EndArea, |
| | | ForcedOut= model.ForcedOut, |
| | | Qty= model.Qty, |
| | | Spe = model.Spe |
| | | }); |
| | | var outboundPlan = db.Queryable<TN_Outbound_Plan>() |
| | | .Where(p => p.JHDH == model.jhdh).First(); |
| | | if (outboundPlan != null) { |
| | | return NewErpResult(1, preLog + $"计划单号'{model.jhdh}'已在[出库计划单]中存在!"); |
| | | } |
| | | |
| | | if (cgDetailList.Count == 0) { |
| | | info = "没有合适的物料可以出库"; |
| | | LogHelper.Info(info); |
| | | return NewErpResult(3, info); |
| | | outboundPlan = new TN_Outbound_Plan { |
| | | JHDH = model.jhdh, // 计划单号 (唯一标识) |
| | | CKZT = model.ckzt, // 出库状态 (需要返回) |
| | | JHLB = model.jhlb, // 计划类别 |
| | | CKDH = model.ckdh, // 参考单号 |
| | | CPH = model.cph, // 车牌号 |
| | | YSFS = model.ysfs, // 运输方式 |
| | | CPZT = model.cpzt, // 产品状态 |
| | | MDDW = model.mddw, // 买断单位 |
| | | CPDM = model.cpdm, // 产品代码 |
| | | CPLB = model.cplb, // 产品类别 |
| | | CPLBMX = model.cplbmx, // 产品类别明细 |
| | | PP = model.pp, // 品牌 |
| | | DJ = model.dj, // 等级 (需要返回) |
| | | GH = model.gh, // 罐号 |
| | | PH = model.ph, // 批号 (需要返回) |
| | | BZLX = model.bzlx, // 包装类型 |
| | | PZDH = model.pzdh, // 派装单号 |
| | | PZD_DW = model.pzd_dw, // 派装单单位 |
| | | PZD_DYBH = model.pzd_dybh, // 派装单调运编号 |
| | | PZJS = model.pzjs, // 派装件数 |
| | | PZSL = model.pzsl, // 派装数量 |
| | | PZ_RQ = model.pz_rq, // 派装日期(yyyy-mm-dd) |
| | | PZ_CZRQ = model.pz_czrq, // 派装操作日期 |
| | | PZ_ZFBJ = model.pz_zfbj, // 派装作废标记 |
| | | PZ_ZFRQ = model.pz_zfrq, // 派装作废日期 |
| | | PZ_BZ = model.pz_bz, // 派装备注 |
| | | CKDBH = model.ckdbh, // 出库单编号 |
| | | SFJS = model.sfjs, // 实发件数 (需要返回) |
| | | SFSL = model.sfsl, // 实发数量 (需要返回) |
| | | SFCS = model.sfcs, // 实发车数 (需要返回) |
| | | ZCSJ = model.zcsj, // 装车时间 (需要返回) |
| | | JLDW = model.jldw, // 计量单位 (需要返回) |
| | | FHRQ = model.fhrq, // 发货日期 (需要返回) |
| | | CKDM = model.ckdm, // 仓库代码 (需要返回) |
| | | FHR = model.fhr, // 发货人 (需要返回) |
| | | CZYDM = model.czydm, // 操作员 (需要返回) |
| | | SHR_USERNAME = model.shr_username, // 审核人 |
| | | SHRQ = model.shrq, // 审核日期 |
| | | ZFBJ = model.zfbj, // 作废标记 |
| | | ZFRQ = model.zfrq, // 作废日期 |
| | | JSDW = model.jsdw, // 结算单位 |
| | | SHDW = model.shdw, // 收货单位 |
| | | YSDW = model.ysdw, // 运输单位 |
| | | LXR = model.lxr, // 联系人 |
| | | RY_ZXG = model.ry_zxg, // 装卸工 (需要返回) |
| | | RY_CCSJ = model.ry_ccsj, // 叉车司机 (需要返回) |
| | | ERPHX_JHDH = model.erphx_jhdh, // erp交货单号 |
| | | ERPHX_WLBM = model.erphx_wlbm, // erp物料编码 |
| | | ERPHX_WLMC = model.erphx_wlmc, // erp物料名称 |
| | | ERPHX_CJRQ = model.erphx_cjrq, // erp创建日期 |
| | | HW = model.hw, // 货位 (需要返回) |
| | | HWZT = model.hwzt // 货位状态 (需要返回) |
| | | }; |
| | | |
| | | //var cgDetailList = SelectCgByTotalQty( |
| | | // qty: (int)model.pzsl, |
| | | // itemCode: model.cpdm, |
| | | // batchNo: model.ph |
| | | // ); |
| | | |
| | | //if (cgDetailList.Count == 0) { |
| | | // info = "没有合适的物料可以出库"; |
| | | // LogHelper.Info(info); |
| | | // return NewErpResult(3, info); |
| | | //} |
| | | |
| | | var cgDetail = db.Queryable<TN_CG_Detail>().Where(d => d.S_ITEM_CODE == model.cpdm && d.N_ITEM_NUM >= model.pzjs).First(); |
| | | if (cgDetail == null ) { |
| | | return NewErpResult(2, preLog + $"在[货品明细表]中没有找到合适的物料!要求:物料编码='{model.cpdm}',物料数量>={model.pzjs}"); |
| | | } |
| | | |
| | | var order = new TN_Outbound_Order { |
| | | S_NO = orderNo, |
| | | S_ITEM_CODE = model.ItemCode, |
| | | S_BATCH = model.BatchNo, |
| | | N_END_NUM = model.Qty, |
| | | //F_OUT_QTY = cgDetailList.Sum(a => a.N_QTY), |
| | | S_END_AREA = model.EndArea, |
| | | S_BS_NO = model.ErpNo, |
| | | //S_ITEM_CODE = model.cpdm, |
| | | //S_BATCH = model.ph, |
| | | //N_END_NUM = (int)model.pzsl, |
| | | S_ITEM_CODE = model.cpdm, |
| | | S_BATCH = cgDetail.S_BATCH_NO, |
| | | N_END_NUM = (int)model.pzjs, |
| | | S_END_AREA = "QCCKQ", // ERP下发出库任务为汽车出库区 |
| | | S_BS_NO = model.jhdh, |
| | | S_BS_TYPE = "ERP", |
| | | }; |
| | | |
| | | var detailList = new List<TN_Outbound_Detail>(); |
| | | foreach (var cgDetail in cgDetailList) { |
| | | var detail = new TN_Outbound_Detail { |
| | | S_OO_NO = orderNo, |
| | | S_ITEM_CODE = cgDetail.S_ITEM_CODE, |
| | | S_BATCH_NO = cgDetail.S_BATCH_NO, |
| | | S_CNTR_CODE = cgDetail.S_CNTR_CODE, |
| | | N_COUNT = cgDetail.N_ITEM_NUM, |
| | | S_END_AREA = model.EndArea |
| | | }; |
| | | detailList.Add(detail); |
| | | } |
| | | //foreach (var cgDetail in cgDetailList) { |
| | | // var detail = new TN_Outbound_Detail { |
| | | // S_OO_NO = orderNo, |
| | | // S_ITEM_CODE = cgDetail.S_ITEM_CODE, |
| | | // S_BATCH_NO = cgDetail.S_BATCH_NO, |
| | | // S_CNTR_CODE = cgDetail.S_CNTR_CODE, |
| | | // N_COUNT = cgDetail.N_ITEM_NUM, |
| | | // S_END_AREA = order.S_END_AREA, // order为detail的每一个货位设置终点值 |
| | | // S_BS_NO = order.S_BS_NO, |
| | | // S_BS_TYPE= order.S_BS_TYPE, |
| | | // }; |
| | | // detailList.Add(detail); |
| | | //} |
| | | var detail = new TN_Outbound_Detail { |
| | | S_OO_NO = orderNo, |
| | | S_ITEM_CODE = cgDetail.S_ITEM_CODE, |
| | | S_BATCH_NO = cgDetail.S_BATCH_NO, |
| | | S_CNTR_CODE = cgDetail.S_CNTR_CODE, |
| | | N_COUNT = cgDetail.N_ITEM_NUM, |
| | | S_END_AREA = order.S_END_AREA, // order为detail的每一个货位设置终点值 |
| | | S_BS_NO = order.S_BS_NO, |
| | | S_BS_TYPE = order.S_BS_TYPE, |
| | | }; |
| | | detailList.Add(detail); |
| | | |
| | | using (var tran = db.Ado.UseTran()) { |
| | | if (db.Insertable<TN_Outbound_Order>(order).ExecuteCommand() <= 0) { |
| | | if (db.Insertable(order).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = "生成出库单失败:" + JsonConvert.SerializeObject(order); |
| | | LogHelper.Info(info); |
| | | return NewErpResult(2, info); |
| | | return NewErpResult(500, preLog + $"生成[出库单]失败!数据:{LogObject(order)}"); |
| | | } |
| | | |
| | | if (db.Insertable<TN_Outbound_Detail>(detailList).ExecuteCommand() <= 0) { |
| | | if (db.Insertable(detailList).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | info = "生成出库单明细失败"; |
| | | LogHelper.Info(info); |
| | | return NewErpResult(4, info); |
| | | return NewErpResult(500, preLog + $"生成[出库单明细]失败!数据:{LogObject(detailList)}"); |
| | | } |
| | | |
| | | if (db.Insertable(outboundPlan).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return NewErpResult(500, preLog + $"生成[出库单计划记录表]失败!数据:{LogObject(outboundPlan)}"); |
| | | } |
| | | |
| | | tran.CommitTran(); |
| | | return NewErpResult(0, preLog + $"生成[出库单]成功!出库单:{LogObject(order)}\n出库单明细:{LogObject(detail)}"); |
| | | } |
| | | |
| | | return NewErpResult(0, "生成出库单成功"); |
| | | } |
| | | catch (Exception ex) { |
| | | info = $"发生了异常:{ex.Message}"; |
| | | LogHelper.InfoEx(ex); |
| | | return NewErpResult(1, info); |
| | | return NewErpResult(1, preLog + $"发生了异常:{ex.Message}\n\n{ex.StackTrace}\n"); |
| | | } |
| | | } |
| | | |
| | | private static string LogObject(object obj) { |
| | | return JsonConvert.SerializeObject(obj).Replace("\"", "'"); |
| | | } |
| | | } |
| | | } |