服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-12-08 006c12987d7dc7c2081fbf6715ebea98b93fdca0
Tiger.Business.MES/Common/WoContext.cs
@@ -10,20 +10,20 @@
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>
        /// 从工单批次字典中获取一个工单批次对象
@@ -35,7 +35,7 @@
        {
            if (ExistsBatch(workorder, lineCode, batchNo))
            {
                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())
                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;
@@ -52,15 +52,56 @@
        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
            {
@@ -78,12 +119,20 @@
            }
        }
        /// 从工单批次字典中删除一个工单的所有批次对象
        /// </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
            {
@@ -98,6 +147,15 @@
                Logger.Default.Fatal(ex, $"从工单批次字典中删除一个工单批次[{batchNo}]对象异常");
                return false;
            }
        }
        /// 从工单批次字典中删除一个工单批次对象
        /// </summary>
        /// <param name="batchNo"></param>
        /// <returns></returns>
        public bool RemoveBatch(string batchNo)
        {
            return Remove(batchNo);
        }
        /// <summary>
@@ -148,8 +206,7 @@
                {
                    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());
@@ -209,8 +266,7 @@
                {
                    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()