服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-07-14 1bcccbe20fc973961418663de789b513784f490c
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
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 string StepID { 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(string stepID, IPosition position, MES_WO_NODE_ACT nodeAct, MES_WO_ACTION setting)
        {
            StepID = stepID;
            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>();
            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":
                                    var itemInfo = Biz.Db.Queryable<BAS_ITEM>().Where(q => q.ITEM_CODE == CurPosition.CurWipSN.ITEM_CODE).First();
                                    return itemInfo.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
    }
}