服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-07-16 415d9d76d0f73f804c7ac9e51591bd15c7d84517
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using MailKit.Search;
using Rhea.Common;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tiger.IBusiness;
using Tiger.Model;
using Tiger.Model.Entitys.MES.Position;
 
namespace Tiger.Business.MES.WorkAction
{
    public class PrintLabel : IPrintLabel
    {
        #region Propertys & Variables
        public bool IsFinished { get; set; } = false;
        public IWorkStep CurStep { get; set; }
        public IPosition CurPosition { get; set; }
        public MES_WO_NODE_ACT NodeAct { get; set; }
        public MES_WO_ACTION Setting { get; set; }
        public BAS_LABEL_TEMP Label { get; set; }
        public List<BAS_LABEL_PV> LabelPV { get; set; }
        #endregion Propertys & Variables
 
        #region Functions
        /// <summary>
        /// 开始执行工序行为
        /// </summary>
        /// <returns></returns>
        public ApiAction<SubmitOutput> Begin(IWorkStep curStep, IPosition position, MES_WO_NODE_ACT nodeAct, MES_WO_ACTION setting)
        {
            CurStep = curStep;
            CurPosition = position;
            NodeAct = nodeAct;
            Setting = setting;
            var action = new ApiAction<SubmitOutput>();
 
            Label = Biz.Db.Queryable<BAS_LABEL_TEMP>().Where(q => q.LABEL_CODE == setting.LABEL_CODE).IncludesAllFirstLayer().First();
            LabelPV = Biz.Db.Queryable<BAS_LABEL_PV>().ToList();
            foreach (var item in Label.Variables)
            {
                switch (item.VAR_TYPE.GetEnum<BAS_LABEL_VAR.VAR_TYPEs>())
                {
                    case BAS_LABEL_VAR.VAR_TYPEs.Constant:
                        item.Value = item.VAR_VALUE;
                        break;
                    case BAS_LABEL_VAR.VAR_TYPEs.ProcessVariable:
                        item.Value = GetProcessValue(item);
                        break;
                    case BAS_LABEL_VAR.VAR_TYPEs.DateVariable:
                        item.Value = DateTime.Now.ToString(item.VAR_VALUE);
                        break;
                    case BAS_LABEL_VAR.VAR_TYPEs.CustomVariable:
                    default:
                        item.Value = "";
                        break;
                }
            }
            action.Data.StepActCode = nodeAct.Definition.ACT_CODE;
            action.Data.Data = Label;
            return action;
        }
        /// <summary>
        /// 工序行为提交数据
        /// </summary>
        /// <returns></returns>
        public ApiAction<SubmitOutput> Submit(SubmitInput input)
        {
            var action = new ApiAction<SubmitOutput>();
            if (input.Data.ToBoolean())
            {
                action = End();
            }
            else
            {
                //重置当前工序
                CurPosition.ResetSteps();
                action.IsSuccessed = false;
                //action.LocaleMsg = new($"标签{Label.LABEL_NAME}[{Label.LABEL_CODE}]打印失败,请重新扫描产品条码", Label.LABEL_NAME);
                action.LocaleMsg = new("MES.WorkAction.PrintLabel.PrintFail", Label.LABEL_NAME, Label.LABEL_CODE);
            }
            return action;
        }
        /// <summary>
        /// 结束执行工序行为
        /// </summary>
        /// <returns></returns>
        public ApiAction<SubmitOutput> End()
        {
            var action = new ApiAction<SubmitOutput>();
 
            var wipAct = new MES_WIP_ACT()
            {
                HIS_ID = CurPosition.CurWipSNHis.ID,
                SN = CurPosition.CurWipSN.SN,
                STATUS = CurPosition.CurWipSN.STATUS,
                ITEM_CODE = CurPosition.CurWipSN.ITEM_CODE,
                WORK_ORDER = CurPosition.CurWipSN.WORK_ORDER,
                BATCH_NO = CurPosition.CurWipSN.BATCH_NO,
                ROT_CODE = CurPosition.CurWipSN.ROT_CODE,
                NODE_ID = CurPosition.CurWipSN.NODE_ID,
                NODE_NAME = CurPosition.CurWipSN.NODE_NAME,
                ACT_ID = NodeAct.ID,
                ACT_NAME = NodeAct.ACT_NAME,
                FTY_CODE = CurPosition.CurWipSN.FTY_CODE,
                WS_CODE = CurPosition.CurWipSN.WS_CODE,
                LINE_CODE = CurPosition.CurWipSN.LINE_CODE,
                POST_CODE = CurPosition.CurWipSN.POST_CODE,
                OPER_CODE = CurPosition.CurWipSN.OPER_CODE,
                SEGMENT = CurPosition.CurWipSN.SEGMENT,
                TRAY_SN = CurPosition.CurWipSN.TRAY_SN,
                OPERATION_TIME = DateTime.Now,
                SFTS_CODE = CurPosition.CurWipSN.SFTS_CODE,
                SFT_CODE = CurPosition.CurWipSN.SFT_CODE,
                PRD_CODE = CurPosition.CurWipSN.PRD_CODE,
                ACT_TYPE = NodeAct.ACT_TYPE,
                ACT_SN = CurPosition.CurWipSN.SN,
                ACT_VALUE_1 = Label.LABEL_CODE,
                ACT_VALUE_2 = Label.Variables.ToJson(),
                ACT_RESULT = "Y",
                TRACE_INFO = $"标签{Label.LABEL_NAME}[{Label.LABEL_CODE}]打印成功",
            };
 
            //保存数据
            CurStep.DBSubmitAction = () =>
            {
                var db = CurPosition.GetCommitDB();
                db.Storageable(wipAct, CurPosition.UserCode).ExecuteCommand();
            };
 
            IsFinished = true;
            //action.LocaleMsg = new($"标签{Label.LABEL_NAME}[{Label.LABEL_CODE}]打印成功", Label.LABEL_NAME);
            action.LocaleMsg = new("MES.WorkAction.PrintLabel.PrintSuccess", Label.LABEL_NAME, Label.LABEL_CODE);
            return action;
        }
 
        public string GetProcessValue(BAS_LABEL_VAR lv)
        {
            var pv = LabelPV.FirstOrDefault(q => q.VAR_CODE == lv.VAR_VALUE);
            if (!pv.IsNullOrEmpty())
            {
                switch (pv.VAR_TYPE.GetEnum<BAS_LABEL_PV.VAR_TYPEs>())
                {
                    case BAS_LABEL_PV.VAR_TYPEs.ServerMethod:
                        {
                            switch (pv.VAR_METHOD)
                            {
                                case "GetSN":
                                    return CurPosition.CurWipSN.SN;
                                case "GetBAS_ITEM":
                                    return Biz.Db.Queryable<BAS_ITEM>().Where(q => q.ITEM_CODE == CurPosition.CurWipSN.ITEM_CODE).First()?.ToJson();
                                case "GetCustomer":
                                    return CurPosition.WorkBatch.Batch.ToJson();
                                default:
                                    return "";
                            }
                        }
                    case BAS_LABEL_PV.VAR_TYPEs.WebApiWebApi:
                        break;
                    case BAS_LABEL_PV.VAR_TYPEs.StoredProcedure:
                        break;
                    default:
                        break;
                }
            }
            return "action";
        }
 
        #endregion Functions
    }
}