服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
18 小时以前 a960900364d19bbf0ad7923a57989609e7fce798
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
using Rhea.Common;
using Tiger.IBusiness;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Tiger.Model;
using Tiger.Model.Sharetronic.Shelf;
using System.ComponentModel;
 
namespace Tiger.Business.MES.Transaction
{
    /// <summary>
    /// SMT上料调度事务
    /// </summary>
    public class LoadingMaterial : MESTransactionBase, ILoadingMaterial
    {
        public ILoadingMaterial Init(string id, string userCode, string apiHost, string orgCode)
        {
            TransID = id;
            UserCode = userCode;
            ApiHost = apiHost;
            OrgCode = orgCode;
            Logger.Console.Info($"Start {this.GetType().Name} Transaction[ID: {TransID}]");
            return this;
        }
 
        #region Propertys & Variables
 
        public string UserCode { get; set; }
        public long UserId { get; set; }
        public string OrgCode { get; set; }
        public string CurSmtCode { get; set; }
        public string CurrSlotNo { get; set; }
        /// <summary>
        /// 步骤类型
        /// </summary>
        public enum Step_Types
        {
            /// <summary>
            /// 扫描机器编码
            /// </summary>
            [Description("机器编码")]
            SmtCode,
            /// <summary>
            /// 扫描槽位
            /// </summary>
            [Description("槽位")]
            SlotNo,
            /// <summary>
            /// 扫描飞达
            /// </summary>
            [Description("Feeder")]
            Feeder,
            /// <summary>
            /// 扫描料盘SN
            /// </summary>
            [Description("料盘码")]
            SN,
        }
 
        /// <summary>
        /// 完成状态
        /// </summary>
        public enum Statuss
        {
            /// <summary>
            /// 扫描机器编码完成
            /// </summary>
            [Description("机器编码完成")]
            SmtCodeOK,
            /// <summary>
            /// 扫描槽位完成
            /// </summary>
            [Description("槽位完成")]
            SlotNoOK,
            /// <summary>
            /// 扫描飞达完成
            /// </summary>
            [Description("Feeder完成")]
            FeederOK,
            /// <summary>
            /// 扫描料盘SN完成
            /// </summary>
            [Description("料盘码完成")]
            SnOK,
            /// <summary>
            /// 当前机器完成
            /// </summary>
            [Description("当前机器完成")]
            CurrCompleted,
            /// <summary>
            /// 全部完成
            /// </summary>
            [Description("全部完成")]
            Completed,
        }
 
        #endregion Propertys & Variables
 
        #region Functions
 
        /// <summary>
        /// 扫描条码上料
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ApiAction<SmtLoadingReturn>> ScanItem(SmtLoadingInput input)
        {
            var action = new ApiAction<SmtLoadingReturn>();
            try
            {
                if (input.Code.IsNullOrEmpty())
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L($"{EnumHelper.GetEnum<Step_Types>(input.Step).GetDesc()}不能为空");
                    return action;
                }
 
                //01根据上料步骤执行相应方法
                switch (EnumHelper.GetEnum<Step_Types>(input.Step))
                {
                    case Step_Types.SmtCode:
                        action = ExecuteSmtCode(input);
                        break;
                    case Step_Types.SlotNo:
                        action = ExecuteSlotNo(input);
                        break;
                    case Step_Types.Feeder:
                        action = ExecuteFeeder(input);
                        break;
                    case Step_Types.SN:
                        action = ExecuteSN(input);
                        break;
                }
                if (!action.IsSuccessed) { return action; }
 
                //02保存上料数据
 
                //03查看未上料列表
                SmtTool smtTool = new();
                var actionSmtTool = await smtTool.GetNotLoadingMaterial(input);
                if (actionSmtTool.IsSuccessed)
                {
                    //带入机器编码查询,如果没有未上料的项,说明当前机器所有槽位均已完成上料!
                    if (actionSmtTool.Data.Count == 0)
                    {
                        var _input = input.Clone();
                        _input.machineCode = "";
                        action.LocaleMsg = Biz.L($"当前机器所有槽位均已完成上料!");
                        var _actionSmtTool = await smtTool.GetNotLoadingMaterial(_input);
                        if (_actionSmtTool.IsSuccessed)
                        {
                            //不带入机器编码查询,如果没有未上料的项,说明当前线别所有机器均已完成上料!
                            if (_actionSmtTool.Data.Count == 0)
                            {
                                action.LocaleMsg = Biz.L($"当前线别所有机器均已完成上料");
                            }
                        }
                        else
                        {
                            action.IsSuccessed = false;
                            action.LocaleMsg = Biz.L($"获取未上料列表失败!");
                        }
                    }
                }
                else
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L($"获取未上料列表失败!");
                }
 
                //action.Data = new ProdReqOutput()
                //{
                //    SN = CurInv.SN,
                //    ItemCode = CurInv.ItemInfo.ITEM_CODE,
                //    Qty = CurInv.CurPkg.QTY,
                //    CutQty = CurInv.CurPkg.QTY - cutQty,
                //    isCutting = isCutting,
                //    isExceed = isExceed,
                //    ReqNo = req.BILLCODE,
                //    regionCode = CurInv.Region.REGION_CODE,
                //    locationCode = CurInv.Location?.LOCATION_CODE,
                //};
            }
            catch (Exception ex)
            {
                action.CatchExceptionWithLog(ex, $"扫描物料[{input.Code}]复核异常");
            }
            return action;
        }
 
        /// <summary>
        /// 01扫描机器编码操作
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private ApiAction<SmtLoadingReturn> ExecuteSmtCode(SmtLoadingInput input) {
            var action = new ApiAction<SmtLoadingReturn>();
            SmtLoadingReturn loadingReturn = new();
            try
            {
                if (Biz.Db.Queryable<SMT_WO_TABLE>().Where(x => x.WORK_ORDER == input.moCode && x.LINE_CODE == input.lineCode && x.PROD_CODE == input.prodCode && x.SMT_CODE == input.Code).Any())
                {
                    CurSmtCode = input.Code;
                    action.IsSuccessed = true;
                    action.LocaleMsg = Biz.L($"机器编码验证通过!");
                    loadingReturn.SmtCode = CurSmtCode;
                    loadingReturn.Step = (int)Step_Types.SmtCode;
                    loadingReturn.Status = (int)Statuss.SmtCodeOK;
                }
                else
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L($"料站表中不存在此机器编码,请确认料站表是否正确上传!");
                }
                action.Data = loadingReturn;
            }
            catch (Exception ex)
            {
                action.CatchExceptionWithLog(ex, $"扫描机器编码异常");
            }
            return action;
        }
 
        /// <summary>
        /// 02扫描槽位操作
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private ApiAction<SmtLoadingReturn> ExecuteSlotNo(SmtLoadingInput input)
        {
            var action = new ApiAction<SmtLoadingReturn>();
            SmtLoadingReturn loadingReturn = new();
            try
            {
                if (Biz.Db.Queryable<SMT_WO_TABLE>().Where(x => x.WORK_ORDER == input.moCode && x.LINE_CODE == input.lineCode && x.PROD_CODE == input.prodCode && x.SMT_CODE == CurSmtCode && x.SLOT_NO == input.Code).Any())
                {
                    CurrSlotNo = input.Code;
                    action.IsSuccessed = true;
                    action.LocaleMsg = Biz.L($"槽位验证通过!");
                    loadingReturn.SmtCode = CurSmtCode;
                    loadingReturn.SlotNo = CurrSlotNo;
                    loadingReturn.Step = (int)Step_Types.SlotNo;
                    loadingReturn.Status = (int)Statuss.SlotNoOK;
                    loadingReturn.LoadingCount = Biz.Db.Queryable<SMT_LOADING>().Where(x=> x.WORK_ORDER == input.moCode && x.LINE_CODE == input.lineCode && x.PROD_CODE == input.prodCode && x.SMT_CODE == CurSmtCode && x.SLOT_NO == input.Code).Count();
                }
                else
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L($"此槽位[{input.Code}]不存在或料站表未上传!");
                }
                action.Data = loadingReturn;
            }
            catch (Exception ex)
            {
                action.CatchExceptionWithLog(ex, $"扫描槽位异常");
            }
            return action;
        }
 
        /// <summary>
        /// 03扫描飞达操作
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private ApiAction<SmtLoadingReturn> ExecuteFeeder(SmtLoadingInput input)
        {
            var action = new ApiAction<SmtLoadingReturn>();
            SmtLoadingReturn loadingReturn = new();
            try
            {
                var _feeder = Biz.Db.Queryable<SMT_FEEDER>().Where(x => x.FEEDER_CODE == input.Code).First();
                //检查飞达保养维护情况
                if (_feeder.FEEDER_TYPE.IsNullOrEmpty())
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L($"此飞达[{input.Code}]未维护类型信息!");
                    return action;
                }
                if (_feeder.FEEDER_TYPE != input.feederType)
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L($"此Feeder[{input.Code}]类型不一致!要求的类型:[{_feeder.FEEDER_TYPE}];当前Feeder的类型:[{input.feederType}]");
                    return action;
                }
                if (_feeder.USED_COUNT >= _feeder.MAX_COUNT)
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L($"此Feeder[{input.Code}]已达最大使用次数,请保养后再使用!");
                    return action;
                }
                var _loading = Biz.Db.Queryable<SMT_LOADING>().Where(x => x.FEEDER_CODE == input.Code).First();
                if (_loading!=null)
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = Biz.L($"此Feeder[{input.Code}]已被占用!线别:[{_loading.LINE_CODE}],工单:[{_loading.WORK_ORDER}],机器:[{_loading.SMT_CODE}],槽位:[{_loading.SLOT_NO}]");
                    return action;
                }
                action.LocaleMsg = Biz.L($"此Feeder验证通过!");
                loadingReturn.SmtCode = CurSmtCode;
                loadingReturn.SlotNo = CurrSlotNo;
                loadingReturn.Step = (int)Step_Types.Feeder;
                loadingReturn.Status = (int)Statuss.FeederOK;
                loadingReturn.LoadingCount = Biz.Db.Queryable<SMT_LOADING>().Where(x => x.WORK_ORDER == input.moCode && x.LINE_CODE == input.lineCode && x.PROD_CODE == input.prodCode && x.SMT_CODE == CurSmtCode && x.FEEDER_CODE == input.Code && x.SLOT_NO == CurrSlotNo).Count();
            }
            catch (Exception ex)
            {
                action.CatchExceptionWithLog(ex, $"扫描Feeder异常");
            }
            return action;
        }
 
        /// <summary>
        /// 04扫描物料条码操作
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private ApiAction<SmtLoadingReturn> ExecuteSN(SmtLoadingInput input)
        {
            var action = new ApiAction<SmtLoadingReturn>();
            try
            {
 
            }
            catch (Exception ex)
            {
                action.CatchExceptionWithLog(ex, $"扫描料盘码异常");
            }
            return action;
        }
 
        #endregion Functions
 
        public override bool Close(bool needSaveHistoryLog = false)
        {
            //needSaveHistoryLog = true;
            //保存操作日志
 
            this.IsFinished = true;
            return IsFinished ? base.Close(needSaveHistoryLog) : IsFinished;
        }
    }//endClass
}