| | |
| | | using Tiger.IBusiness; |
| | | using Tiger.Model; |
| | | using Tiger.Model.Entitys.MES.Position; |
| | | using static Tiger.Business.Biz; |
| | | |
| | | namespace Tiger.Business |
| | | { |
| | | /// <summary> |
| | | /// 工单 上下文 |
| | | /// </summary> |
| | | public class WoContext |
| | | public class WoContext : IWoContext |
| | | { |
| | | #region 工单管理 |
| | | /// <summary> |
| | | /// |
| | | /// 工单批次缓存字典 |
| | | /// </summary> |
| | | public static Dictionary<string, WorkBatch> WoBatchDic { get; set; } = new Dictionary<string, WorkBatch>(); |
| | | public Dictionary<string, IWorkBatch> GetWoBatchDic() => WoBatchDic.ToDictionary(k => k.Key, v => v.Value as IWorkBatch); |
| | | |
| | | /// <summary> |
| | | /// 从工单批次字典中获取一个工单批次对象 |
| | |
| | | /// <param name="workorder"></param> |
| | | /// <param name="lineCode"></param> |
| | | /// <returns></returns> |
| | | public static WorkBatch GetBatch(string workorder, string lineCode, string batchNo = "") |
| | | public static WorkBatch GetBatch(string workorder, string lineCode, string batchNo = "", bool canDoWork = true) |
| | | { |
| | | if (ExistsBatch(workorder, lineCode, batchNo)) |
| | | { |
| | | return WoBatchDic.FirstOrDefault(q => !q.Value.Batch.IsNullOrEmpty() && q.Value.Batch.ORDER_NO == workorder && q.Value.Batch.ACT_LINE == lineCode && (batchNo.IsNullOrEmpty() || q.Value.Batch.BATCH_NO == batchNo)).Value; |
| | | return WoBatchDic.WhereIF(canDoWork, q => q.Value.Batch?.STATUS == BIZ_MES_WO_BATCH.STATUSs.Release.GetValue() || q.Value.Batch?.STATUS == BIZ_MES_WO_BATCH.STATUSs.Working.GetValue()) |
| | | .FirstOrDefault(q => !q.Value.Batch.IsNullOrEmpty() && q.Value.Batch.ORDER_NO == workorder && q.Value.Batch.ACT_LINE == lineCode && (batchNo.IsNullOrEmpty() || q.Value.Batch.BATCH_NO == batchNo)).Value; |
| | | } |
| | | return null; |
| | | } |
| | |
| | | public static bool ExistsBatch(string workorder, string lineCode, string batchNo = "", bool canDoWork = false) |
| | | { |
| | | return WoBatchDic.WhereIF(canDoWork, q => !q.Value.Batch.IsNullOrEmpty() && (q.Value.Batch.STATUS == BIZ_MES_WO_BATCH.STATUSs.Release.GetValue() || q.Value.Batch.STATUS == BIZ_MES_WO_BATCH.STATUSs.Working.GetValue())) |
| | | .Any(q => q.Value.Batch.ORDER_NO == workorder && q.Value.Batch.ACT_LINE == lineCode && (batchNo.IsNullOrEmpty() || q.Value.Batch.BATCH_NO == batchNo)); |
| | | .Any(q => q.Value.Batch?.ORDER_NO == workorder && q.Value.Batch?.ACT_LINE == lineCode && (batchNo.IsNullOrEmpty() || q.Value.Batch?.BATCH_NO == batchNo)); |
| | | } |
| | | |
| | | /// 从工单批次字典中删除一个工单批次对象 |
| | | /// 根据工单号,增加一个工单对象到工单批次字典中 |
| | | /// </summary> |
| | | /// <param name="batchNo"></param> |
| | | /// <param name="workorder"></param> |
| | | /// <returns></returns> |
| | | public static WorkBatch Add(string workorder) |
| | | { |
| | | var wb = new WorkBatch(workorder).Init(""); |
| | | WoBatchDic.Add(workorder, wb); |
| | | return wb; |
| | | } |
| | | |
| | | /// 根据工单号和产线,增加一个工单批次对象到工单批次字典中 |
| | | /// </summary> |
| | | /// <param name="workorder"></param> |
| | | /// <param name="lineCode"></param> |
| | | /// <returns></returns> |
| | | public static bool RemoveWo(string workorder) |
| | | public static WorkBatch Add(string workorder, string linecode) |
| | | { |
| | | var wb = new WorkBatch(workorder).Init(linecode); |
| | | WoBatchDic.Add(wb.Batch.BATCH_NO, wb); |
| | | return wb; |
| | | } |
| | | |
| | | /// 根据工单号,增加一个工单对象到工单批次字典中 |
| | | /// </summary> |
| | | /// <param name="workorder"></param> |
| | | /// <returns></returns> |
| | | public IWorkBatch AddWo(string workorder) |
| | | { |
| | | return Add(workorder); |
| | | } |
| | | |
| | | /// 根据工单号和产线,增加一个工单批次对象到工单批次字典中 |
| | | /// </summary> |
| | | /// <param name="workorder"></param> |
| | | /// <param name="lineCode"></param> |
| | | /// <returns></returns> |
| | | public IWorkBatch AddBatch(string workorder, string linecode) |
| | | { |
| | | return Add(workorder, linecode); |
| | | } |
| | | |
| | | /// 从工单批次字典中删除一个工单的所有批次对象 |
| | | /// </summary> |
| | | /// <param name="workorder"></param> |
| | | /// <returns></returns> |
| | | public static bool RemoveAll(string workorder) |
| | | { |
| | | try |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | /// 从工单批次字典中删除一个工单的所有批次对象 |
| | | /// </summary> |
| | | /// <param name="workorder"></param> |
| | | /// <returns></returns> |
| | | public bool RemoveWo(string workorder) |
| | | { |
| | | return RemoveAll(workorder); |
| | | } |
| | | |
| | | /// 从工单批次字典中删除一个工单批次对象 |
| | | /// </summary> |
| | | /// <param name="batchNo"></param> |
| | | /// <param name="lineCode"></param> |
| | | /// <returns></returns> |
| | | public static bool RemoveBatch(string batchNo) |
| | | public static bool Remove(string batchNo) |
| | | { |
| | | try |
| | | { |
| | |
| | | Logger.Default.Fatal(ex, $"从工单批次字典中删除一个工单批次[{batchNo}]对象异常"); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /// 从工单批次字典中删除一个工单批次对象 |
| | | /// </summary> |
| | | /// <param name="batchNo"></param> |
| | | /// <returns></returns> |
| | | public bool RemoveBatch(string batchNo) |
| | | { |
| | | return Remove(batchNo); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | if (!WoBatchDic.Any(q => q.Value.WO.ORDER_NO == wipSNs.First().WORK_ORDER)) |
| | | { |
| | | var wb = new WorkBatch(wipSNs.First().WORK_ORDER).Init(""); |
| | | WoBatchDic.Add(wb.Batch.BATCH_NO, wb); |
| | | Add(wipSNs.First().WORK_ORDER); |
| | | } |
| | | var wo = WoBatchDic.FirstOrDefault(q => q.Value.WO.ORDER_NO == wipSNs.First().WORK_ORDER).Value; |
| | | action.Data = wo.GetNextNodes(wipSNs.First()); |
| | |
| | | { |
| | | if (!WoBatchDic.Any(q => q.Value.WO.ORDER_NO == wipSNs.First().WORK_ORDER)) |
| | | { |
| | | var wb = new WorkBatch(wipSNs.First().WORK_ORDER).Init(""); |
| | | WoBatchDic.Add(wipSNs.First().BATCH_NO, wb); |
| | | Add(wipSNs.First().WORK_ORDER); |
| | | } |
| | | var wo = WoBatchDic.FirstOrDefault(q => q.Value.WO.ORDER_NO == wipSNs.First().WORK_ORDER).Value; |
| | | action.Data = new() |