| | |
| | | using Tiger.IBusiness; |
| | | using Tiger.Model.Entitys.MES.Position; |
| | | using Tiger.Business.MES; |
| | | using static Microsoft.CodeAnalysis.CSharp.SyntaxTokenParser; |
| | | using Org.BouncyCastle.Ocsp; |
| | | |
| | | namespace Tiger.Business |
| | | { |
| | |
| | | return this; |
| | | } |
| | | |
| | | public void Update() |
| | | public void Update(bool updateAll = false) |
| | | { |
| | | var wo = Biz.Db.Queryable<BIZ_MES_WO>().Where(q => q.ORDER_NO == OrderNo).IncludesAllFirstLayer().First(); |
| | | var batch = Biz.Db.Queryable<BIZ_MES_WO_BATCH>().Where(q => q.BATCH_NO == Batch.BATCH_NO).First(); |
| | | if (WoContext.WoBatchDic.ContainsKey(batch.BATCH_NO)) |
| | | { |
| | | if (wo.STATUS > BIZ_MES_WO.STATUSs.Working.GetValue() || batch.STATUS > BIZ_MES_WO_BATCH.STATUSs.Working.GetValue()) |
| | | if (wo.STATUS < BIZ_MES_WO.STATUSs.Release.GetValue() || batch.STATUS > BIZ_MES_WO_BATCH.STATUSs.Working.GetValue()) |
| | | { |
| | | WoContext.WoBatchDic.Remove(Batch.BATCH_NO); |
| | | } |
| | | else if(wo.UPDATE_TIME > WO.UPDATE_TIME || batch.UPDATE_TIME > Batch.UPDATE_TIME) |
| | | else if(updateAll || wo.UPDATE_TIME > WO.UPDATE_TIME || batch.UPDATE_TIME > Batch.UPDATE_TIME) |
| | | { |
| | | GetBatchInfo(); |
| | | } |
| | |
| | | action.LocaleMsg = new("MES.WorkBatch.WoStatusCanNotWork", WO.ORDER_NO, Batch.STATUS.GetEnumDesc<BIZ_MES_WO.STATUSs>()); |
| | | } |
| | | //工单批次投入数量减去报废数量如果大于等于计划数量,则不允许生产 |
| | | //if (curNode.IS_INPUT == "Y" && Batch.INPUT_QTY - Batch.SCRAP_QTY >= Batch.PLAN_QTY) |
| | | if (curNode.IS_FIRST_NODE == "Y" && WoSNs.Count(q => q.STATUS > BIZ_MES_WO_SN.STATUSs.NotInput.GetValue() && q.BATCH_NO == Batch.BATCH_NO) - Batch.SCRAP_QTY >= Batch.PLAN_QTY) |
| | | if (curNode.IS_FIRST_NODE == "Y" && WoSNs.Count(q => q.BATCH_NO == Batch.BATCH_NO && BIZ_MES_WO_SN.STATUSs.NotInput.GetValue() < q.STATUS && q.STATUS <= BIZ_MES_WO_SN.STATUSs.Finished.GetValue()) >= Batch.PLAN_QTY) |
| | | { |
| | | action.IsSuccessed = false; |
| | | action.Data.SetValue(this, null); |
| | | //action.LocaleMsg = new($"工单批次[{0}]已投入 {1},其中报废 {2},以满足计划数量[{3}],无需继续投入"); |
| | | action.LocaleMsg = new("MES.WorkBatch.BatchInputEnough", Batch.BATCH_NO, WoSNs.Count(q => q.BATCH_NO == Batch.BATCH_NO), Batch.SCRAP_QTY, Batch.PLAN_QTY); |
| | | action.LocaleMsg = new("MES.WorkBatch.BatchInputEnough", Batch.BATCH_NO, WoSNs.Count(q => q.BATCH_NO == Batch.BATCH_NO), WoSNs.Count(q => q.BATCH_NO == Batch.BATCH_NO && q.STATUS > BIZ_MES_WO_SN.STATUSs.Finished.GetValue()), Batch.PLAN_QTY); |
| | | } |
| | | //工单投入数量减去报废数量如果大于等于计划数量,则不允许生产 |
| | | if (curNode.IS_FIRST_NODE == "Y" && WoSNs.Count(q => q.STATUS > BIZ_MES_WO_SN.STATUSs.NotInput.GetValue() && q.WORK_ORDER == WO.ORDER_NO) - WO.SCRAP_QTY >= WO.PLAN_QTY) |
| | | if (curNode.IS_FIRST_NODE == "Y" && WoSNs.Count(q =>q.WORK_ORDER == WO.ORDER_NO && BIZ_MES_WO_SN.STATUSs.NotInput.GetValue() < q.STATUS && q.STATUS <= BIZ_MES_WO_SN.STATUSs.Finished.GetValue()) >= WO.PLAN_QTY) |
| | | { |
| | | action.IsSuccessed = false; |
| | | action.Data.SetValue(this, null); |
| | | //action.LocaleMsg = new($"工单[{0}]已投入 {1},其中报废 {2},以满足计划数量[{3}],无需继续投入"); |
| | | action.LocaleMsg = new("MES.WorkBatch.WoInputEnough", WO.ORDER_NO, WoSNs.Count(q => q.WORK_ORDER == WO.ORDER_NO), WO.SCRAP_QTY, WO.PLAN_QTY); |
| | | action.LocaleMsg = new("MES.WorkBatch.WoInputEnough", WO.ORDER_NO, WoSNs.Count(q => q.WORK_ORDER == WO.ORDER_NO), WoSNs.Count(q => q.WORK_ORDER == WO.ORDER_NO && q.STATUS > BIZ_MES_WO_SN.STATUSs.Finished.GetValue()), WO.PLAN_QTY); |
| | | } |
| | | |
| | | return action; |
| | |
| | | { |
| | | //在前置工序查找还有没有后续工序没完成的前置工序 |
| | | var prepIDs = curNode.PrepNodeIDs.Where(id => |
| | | Edges.Any(e => e.SRC_NODE == id && !wipSN.History.Any(h => h.WORK_ORDER == WO.ORDER_NO && h.NODE_ID == e.TGT_NODE && h.IsFinished)) |
| | | Edges.Any(e => e.SRC_NODE == id && !wipSN.History.Any(h => h.WORK_ORDER == WO.ORDER_NO && h.UNBIND_FLAG != "Y" && h.NODE_ID == e.TGT_NODE && h.IsFinished)) |
| | | ).ToList(); |
| | | foreach (var prepID in prepIDs) |
| | | { |
| | |
| | | var result = new List<MES_WO_NODE>(); |
| | | var nextNodes = Nodes.Where(q => q.Operation.OPER_TYPE != MES_OPERATION.OPER_TYPEs.Repair.GetValue() |
| | | && Edges.Any(e => e.SRC_NODE == parent.ID && e.TGT_NODE == q.ID) |
| | | && !wipSN.History.Any(h => h.WORK_ORDER == WO.ORDER_NO && h.NODE_ID == q.ID && h.IsFinished) |
| | | && !wipSN.History.Any(h => h.WORK_ORDER == WO.ORDER_NO && h.UNBIND_FLAG != "Y" && h.NODE_ID == q.ID && h.IsFinished) |
| | | ).ToList(); |
| | | //尝试将当前工序的后续工序添加到可以执行的工序列表 |
| | | foreach (var next in nextNodes) |
| | | { |
| | | //查找有没有前置工序找不到已良品过站的历史记录,若有则不允许继续执行 |
| | | if (!next.PrepNodeIDs.Any(id => !wipSN.History.Any(h => h.WORK_ORDER == WO.ORDER_NO && h.NODE_ID == id && h.IsFinished)) || parent.IS_FIRST_NODE == "Y") |
| | | if (!next.PrepNodeIDs.Any(id => !wipSN.History.Any(h => h.WORK_ORDER == WO.ORDER_NO && h.UNBIND_FLAG != "Y" && h.NODE_ID == id && h.IsFinished)) || parent.IS_FIRST_NODE == "Y") |
| | | { |
| | | var setting = NodeSets.FirstOrDefault(q => q.NODE_ID == next.ID); |
| | | //后续工序是启用的,则添加 |
| | |
| | | { |
| | | //在前置工序查找还有没有后续工序没完成的前置工序 |
| | | var prepIDs = curNode.PrepNodeIDs.Where(id => |
| | | Edges.Any(e => e.SRC_NODE == id && !wipSN.History.Any(h => h.WORK_ORDER == WO.ORDER_NO && h.NODE_ID == e.TGT_NODE && h.IsFinished)) |
| | | Edges.Any(e => e.SRC_NODE == id && !wipSN.History.Any(h => h.WORK_ORDER == WO.ORDER_NO && h.UNBIND_FLAG != "Y" && h.NODE_ID == e.TGT_NODE && h.IsFinished)) |
| | | ).ToList(); |
| | | foreach (var prepID in prepIDs) |
| | | { |
| | |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 从工单中移除正在生产的条码 |
| | | /// </summary> |
| | | /// <param name="wipList"></param> |
| | | /// <returns></returns> |
| | | public ApiAction RemoveWipSn(List<MES_WIP_DATA> wipList, string user) |
| | | { |
| | | var action = UnbindWipSnFromWO(WO, wipList, user); |
| | | //移除成功则处理工单缓存中的数据 |
| | | if (action.IsSuccessed) |
| | | { |
| | | Update(true); |
| | | } |
| | | |
| | | return action; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 从工单中解绑正在生产的条码 |
| | | /// </summary> |
| | | /// <param name="wo"></param> |
| | | /// <param name="wipList"></param> |
| | | /// <returns></returns> |
| | | public static ApiAction UnbindWipSnFromWO(BIZ_MES_WO wo, List<MES_WIP_DATA> wipList, string user) |
| | | { |
| | | var action = new ApiAction(); |
| | | |
| | | var wipIDs = wipList.Select(q => q.ID); |
| | | var batchs = wipList.Where(q => !q.BATCH_NO.IsNullOrEmpty()).GroupBy(q => new { q.BATCH_NO }).Select(g => new { |
| | | g.Key.BATCH_NO, |
| | | Qty = g.Count(), |
| | | FinishQty = g.Count(q => q.STATUS == MES_WIP_DATA.STATUSs.Finished.GetValue()), |
| | | }); |
| | | var db = Biz.Db; |
| | | var dbTran = db.UseTran(() => |
| | | { |
| | | //BIZ_MES_WO |
| | | wo.INPUT_QTY -= wipList.Count; |
| | | wo.OUTPUT_QTY -= wipList.Count(q => q.STATUS == MES_WIP_DATA.STATUSs.Finished.GetValue()); |
| | | wo.SCRAP_QTY += wipList.Count; |
| | | db.Updateable(wo, user).UpdateColumns(q => new { q.INPUT_QTY, q.OUTPUT_QTY, q.SCRAP_QTY, q.UPDATE_USER, q.UPDATE_TIME }).ExecuteCommand(); |
| | | //BIZ_MES_WO_BATCH |
| | | foreach (var batch in batchs) |
| | | { |
| | | db.Updateable<BIZ_MES_WO_BATCH>(user) |
| | | .SetColumns(q => q.INPUT_QTY == q.INPUT_QTY - batch.Qty) |
| | | .SetColumns(q => q.OUTPUT_QTY == q.OUTPUT_QTY - batch.FinishQty) |
| | | .SetColumns(q => q.SCRAP_QTY == q.SCRAP_QTY + batch.Qty) |
| | | .Where(q => q.BATCH_NO == q.BATCH_NO) |
| | | .ExecuteCommand(); |
| | | } |
| | | //BIZ_MES_WO_SN |
| | | db.Updateable<BIZ_MES_WO_SN>(user) |
| | | .SetColumns(q => q.STATUS == BIZ_MES_WO_SN.STATUSs.Offline.GetValue()) |
| | | .Where(q => q.WORK_ORDER == wo.ORDER_NO && wipIDs.Contains(q.WIP_ID)) |
| | | .ExecuteCommand(); |
| | | //MES_WIP_DATA & MES_WIP_HIS |
| | | var wipHiss = new List<MES_WIP_HIS>(); |
| | | foreach (var wipSN in wipList.Where(q => q.STATUS != MES_WIP_DATA.STATUSs.Offline.GetValue())) |
| | | { |
| | | wipSN.STATUS = MES_WIP_DATA.STATUSs.Offline.GetValue(); |
| | | wipSN.UNBIND_FLAG = "Y"; |
| | | wipSN.NODE_ID = ""; |
| | | wipSN.NODE_NAME = "下线退库"; |
| | | wipSN.OPERATION_TIME = DateTime.Now; |
| | | var his = new MES_WIP_HIS(wipSN, $"工单[{wipSN.WORK_ORDER}]条码[{wipSN.SN}]下线"); |
| | | wipHiss.Add(his); |
| | | } |
| | | db.Storageable(wipList, user).ExecuteCommand(); |
| | | db.Storageable(wipHiss, user).ExecuteCommand(); |
| | | db.Updateable<MES_WIP_HIS>(user) |
| | | .SetColumns(q => q.UNBIND_FLAG == "Y") |
| | | .Where(q => q.WORK_ORDER == wo.ORDER_NO && wipIDs.Contains(q.WIP_ID)) |
| | | .ExecuteCommand(); |
| | | //MES_WIP_PKG |
| | | var curpkg = db.Queryable<MES_WIP_PKG>().Where(q => wipIDs.Contains(q.WIP_ID)).ToList(); |
| | | db.Deleteable(curpkg).ExecuteCommand(); |
| | | var pkgs = new List<MES_WIP_PKG>(); |
| | | do |
| | | { |
| | | var parentSns = curpkg.Where(q => !q.PARENT_SN.IsNullOrEmpty()).Select(q => q.PARENT_SN).Distinct(); |
| | | curpkg = db.Queryable<MES_WIP_PKG>().Where(q => parentSns.Contains(q.SN)).ToList(); |
| | | foreach (var pkg in curpkg) |
| | | { |
| | | pkg.QTY = db.Queryable<MES_WIP_PKG>().Where(q => q.PARENT_SN == pkg.SN).Sum(q => q.QTY); |
| | | pkgs.Add(pkg); |
| | | } |
| | | } |
| | | while (curpkg.Any()); |
| | | db.Updateable(curpkg, user).ExecuteCommand(); |
| | | //MES_WIP_DFT,在上仓库装配和维修之前,先把不良记录标记为已处理 |
| | | db.Updateable<MES_WIP_DFT>(user) |
| | | .SetColumns(q => q.STATUS == MES_WIP_DFT.STATUSs.Resolved.GetValue()) |
| | | .Where(q => q.WORK_ORDER == wo.ORDER_NO && wipIDs.Contains(q.WIP_ID)) |
| | | .ExecuteCommand(); |
| | | }); |
| | | if (!dbTran.IsSuccess) |
| | | { |
| | | //抛出异常 |
| | | throw dbTran.ErrorException; |
| | | } |
| | | |
| | | return action; |
| | | } |
| | | #endregion |
| | | |
| | | /// <summary> |