服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
2024-08-13 cb0739bdf301ce8a70bd5fe7d2d6f5e994e01194
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using Microsoft.AspNetCore.Http;
using Rhea.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tiger.IBusiness;
using static Tiger.Business.Biz;
 
namespace Tiger.Business.MES
{
    /// <summary>
    /// 工单 上下文
    /// </summary>
    public class WoContext
    {
        #region 工单管理
        /// <summary>
        /// 
        /// </summary>
        public static Dictionary<string, WorkBatch> WoBatchDic { get; set; } = new Dictionary<string, WorkBatch>();
 
        /// <summary>
        /// 从工单批次字典中获取一个工单批次对象
        /// </summary>
        /// <param name="workorder"></param>
        /// <param name="lineCode"></param>
        /// <returns></returns>
        public static WorkBatch GetBatch(string workorder, string lineCode)
        {
            return WoBatchDic.FirstOrDefault(q => q.Value.Batch.ORDER_NO == workorder && q.Value.Batch.ACT_LINE == lineCode).Value;
        }
 
        /// <summary>
        /// 判断工单批次是否存在于工单批次字典中
        /// </summary>
        /// <param name="workorder"></param>
        /// <param name="lineCode"></param>
        /// <returns></returns>
        public static bool ExistsBatch(string workorder, string lineCode)
        {
            return WoBatchDic.Any(q => q.Value.Batch.ORDER_NO == workorder && q.Value.Batch.ACT_LINE == lineCode);
        }
 
        /// 从工单批次字典中删除一个工单批次对象
        /// </summary>
        /// <param name="batchNo"></param>
        /// <param name="lineCode"></param>
        /// <returns></returns>
        public static bool RemoveWo(string workorder)
        {
            try
            {
                var list = WoBatchDic.Keys.ToList().Where(q => q.Contains(workorder));
                foreach (var batch in list)
                {
                    WoBatchDic.Remove(batch);
                }
                return true;
            }
            catch (Exception ex)
            {
                Logger.Default.Fatal(ex, $"从工单批次字典中删除一个工单[{workorder}]对象异常");
                return false;
            }
        }
 
        /// 从工单批次字典中删除一个工单批次对象
        /// </summary>
        /// <param name="batchNo"></param>
        /// <param name="lineCode"></param>
        /// <returns></returns>
        public static bool RemoveBatch(string batchNo)
        {
            try
            {
                if (WoBatchDic.ContainsKey(batchNo))
                {
                    WoBatchDic.Remove(batchNo);
                }
                return true;
            }
            catch (Exception ex)
            {
                Logger.Default.Fatal(ex, $"从工单批次字典中删除一个工单批次[{batchNo}]对象异常");
                return false;
            }
        }
        #endregion
    }
}