| | |
| | | |
| | | // 盘点功能(新) |
| | | |
| | | internal static SimpleResult CheckOutboundOnce(CheckOutboundOnceInfo model) { |
| | | var taskName = TaskName.盘点理货出库; |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | |
| | | try { |
| | | var locCntrRel = db.Queryable<TN_Loc_Container>().First(a => a.S_CNTR_CODE == model.cntrCode); |
| | | if (locCntrRel == null) { |
| | | return BuildSimpleResult(3, $"容器 {model.cntrCode} 没有找到对应的货位"); |
| | | } |
| | | |
| | | // 起点位置:取放货区(有货物、没有锁、已启用) |
| | | var startLoc = db.Queryable<TN_Location>().First(a => a.S_CODE == locCntrRel.S_LOC_CODE && a.N_CURRENT_NUM == 1 && a.N_LOCK_STATE == 0 && a.S_LOCK_STATE == "无" && a.C_ENABLE == "Y" && Settings.Areas[AreaIndex.H货架区].Contains(a.S_AREA_CODE)); |
| | | if (startLoc == null) { |
| | | return BuildSimpleResult(2, $"起点位置 {locCntrRel.S_LOC_CODE} 不符合出库条件"); |
| | | } |
| | | |
| | | // 终点位置:货架(没有货物,没有锁) |
| | | var endLoc = db.Queryable<TN_Location>().First(a => a.S_CODE == model.endLoc && a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && a.S_LOCK_STATE == "无" && a.C_ENABLE == "Y"); |
| | | if (endLoc == null) { |
| | | return BuildSimpleResult(4, $"终点位置 {model.endLoc} 不具备放货条件"); |
| | | } |
| | | |
| | | var countOrder = db.Queryable<TN_AG_Count_Order>().Where(o => o.S_CNTR_CODE == locCntrRel.S_CNTR_CODE).First(); |
| | | if (countOrder == null) { |
| | | return BuildSimpleResult(6, $"没有找到对应容器{model.cntrCode}的盘点单号!"); |
| | | } |
| | | countOrder.N_B_STATE = 1; |
| | | |
| | | var unFinishedCount = db.Queryable<TN_AG_Count_Order>().Where(a => a.S_CP_NO == countOrder.S_CP_NO && a.S_COUNT_NO != countOrder.S_COUNT_NO && a.N_B_STATE == 0).Count(); |
| | | |
| | | 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 (unFinishedCount == 0 && db.Updateable<TN_AG_Count_Plan>().SetColumns(a =>a.N_B_STATE == 1).Where(a => a.S_CP_NO == countOrder.S_CP_NO).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return BuildSimpleResult(500, |
| | | $"更新盘点计划单状态为1失败!单号:{countOrder.S_CP_NO}"); |
| | | } |
| | | |
| | | if (db.Updateable<TN_AG_Count_Order>(countOrder).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return BuildSimpleResult(500, |
| | | $"更新盘点单状态为1失败:"+ JsonConvert.SerializeObject(countOrder)); |
| | | } |
| | | |
| | | 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(); |
| | | return BuildSimpleResult(500, |
| | | $"生成 {taskName} 失败,容器号 {cntID} ,起点 {startLoc.S_CODE} ,终点货位 {endLoc.S_CODE}"); |
| | | } |
| | | |
| | | 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(); |
| | | return BuildSimpleResult(500, |
| | | $"生成 {taskName} 失败,容器号 {cntID} ,起点 {startLoc.S_CODE} ,终点货架 {endLoc.S_CODE}"); |
| | | } |
| | | |
| | | if (db.Insertable<TN_Task>(task).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return BuildSimpleResult(500, |
| | | $"生成 {taskName} 失败,容器号 {cntID} ,起点 {startLoc.S_CODE} ,终点货架 {endLoc.S_CODE}"); |
| | | } |
| | | |
| | | tran.CommitTran(); |
| | | return BuildSimpleResult(0, |
| | | $"生成 {taskName} 成功,容器号 {cntID} ,起点 {startLoc.S_CODE} ,终点货架 {endLoc.S_CODE}"); |
| | | } |
| | | } |
| | | catch (Exception ex) { |
| | | return BuildSimpleResult(1, $"发生了异常:{ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | // 备用:盘点相关功能(恢复)------------------------------ |
| | | |
| | |
| | | return BuildSimpleResult(4, $"当前物料所在容器{locCntrRel.S_CNTR_CODE}物料信息没有生成对应的盘点差异表!"); |
| | | } |
| | | |
| | | |
| | | countDiff.F_QTY = cgDetail.F_QTY; |
| | | countDiff.F_ACTUAL_QTY = model.qty; |
| | | //countDiff.S_ITEM_CODE = cgDetail.S_ITEM_CODE; |
| | | |
| | | cgDetail.F_QTY = model.qty; |
| | | //if (db.Insertable<TN_Count_Diff>(countDiff).ExecuteCommand() <= 0) { |
| | | // return BuildSimpleResult(3, $"插入盘点差异表失败"); |
| | | //} |
| | | using (var tran = db.Ado.UseTran()) { |
| | | if (db.Updateable<TN_AG_Count_Diff>(countDiff).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return BuildSimpleResult(5, $"插入盘点差异表失败"); |
| | | } |
| | | |
| | | if (db.Updateable<TN_AG_Count_Diff>(countDiff).ExecuteCommand() <= 0) { |
| | | return BuildSimpleResult(5, $"插入盘点差异表失败"); |
| | | if (db.Updateable<TN_CG_Detail>(cgDetail).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | return BuildSimpleResult(5, $"更新物料信息失败"); |
| | | } |
| | | |
| | | tran.CommitTran(); |
| | | } |
| | | |
| | | return BuildSimpleResult(0, "盘点差异完成"); |