服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-09-25 0fdb04b7c451d7c59b226c25425722afd3364916
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
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.Entitys.MES.Position;
 
namespace Tiger.Business.MES.Transaction
{
    /// <summary>
    /// 采集工序事务
    /// </summary>
    public class CollectNode : Position, ICollectNode
    {
        public new ICollectNode Init(string id, string apiHost, string userCode, string postCode)
        {
            base.Init(id, apiHost, userCode, postCode);
            Logger.Console.Info($"User[{userCode}] start a {this.GetType().Name}[{postCode}] Transaction[ID: {TransID}]");
            return this;
        }
 
        #region Propertys & Variables
 
        #endregion Propertys & Variables
 
        #region Functions
        /// <summary>
        /// 采集工序:提交操作数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ApiAction<SubmitOutput>> Submit(SubmitInput input)
        {
            var action = new ApiAction<SubmitOutput>(new SubmitOutput());
            try
            {
                //工步列表为空或者工序节点工步有未完成时,优先完成工序节点工步
                if (Steps.IsNullOrEmpty() || !IsFinishNodeSteps)
                {
                    //先判断当前工单不为空且当前岗位在当前工单是不是首站,如果是则不允许变更当前工单,尝试把条码绑定到当前工单
                    if (!CurBatch.IsNullOrEmpty() && CurBatch.IsFirstNode(PostCode))
                    {
                        //更新CurBatch
                        CurBatch?.Update();
                        //提交数据
                        action = NodeSubmit(action, input);
                        //更新工序信息
                        if (!action.IsSuccessed)
                        {
                            var info = WoContext.GetSnOperInfo(input.SN).Data;
                            info.InputQty = CurOperInfo(input.Locale).InputQty;
                            action.Data.OperInfo = info;
                        }
                        else if (!IsFinishAllSteps)
                        {
                            action.Data.OperInfo = SetOperNodeInfo(CurOperInfo(input.Locale));
                        }
                    }
                    //当前岗位在当前工单不是首站,则查找条码已绑定的工单当作当前工单
                    else
                    {
                        var wosns = Biz.Db.Queryable<BIZ_MES_WO_BATCH, BIZ_MES_WO_SN>((q, s) => new JoinQueryInfos(JoinType.Inner, q.ORDER_NO == s.WORK_ORDER))
                                                        .ByAuth(input.AuthOption).Where((q, s) => s.STATUS < BIZ_MES_WO_SN.STATUSs.Finished.GetValue())
                                                        .Where((q, s) => s.SN == input.SN || s.FLOW_SN == input.SN || s.TRAY_SN == input.SN).Select((q, s) => new { Batch = q, SN = s }).ToList();
 
                        //查找到条码已绑定的工单
                        if (!wosns.IsNullOrEmpty())
                        {
                            if (wosns.First().Batch.ACT_LINE != CurLine.LINE_CODE)
                            {
                                action.Data.ShortMsg = new("产线错误", ShortMessage.Types.Error);
                                action.Data.OperInfo = new();
                                action.IsSuccessed = false;
                                //action.LocaleMsg = new($"条码[{0}]已在产线[{1}]投入生产,请在正确岗位扫描");
                                action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.NotCorrectLine", input.SN, wosns.First().Batch.ACT_LINE);
                            }
                            else
                            {
                                if (CurBatch?.Batch?.ORDER_NO != wosns.First().Batch.ORDER_NO)
                                {
                                    //条码已绑定的工单不等于当前工单则重新选择工单
                                    var result = await SelectOrder(new() { AuthOption = input.AuthOption, OrderNo = wosns.First().Batch.ORDER_NO });
                                    if (!result.IsSuccessed)
                                    {
                                        action.Data.ShortMsg = new("工单异常", ShortMessage.Types.Error);
                                        action.Data.OperInfo = new();
                                        action.IsSuccessed = result.IsSuccessed;
                                        action.LocaleMsg = result.LocaleMsg;
                                        return action;
                                    }
                                }
                                //更新CurBatch
                                CurBatch?.Update();
                                //条码过站
                                action = NodeSubmit(action, input);
                                if (!action.IsSuccessed && !CurWipSNs.Any())
                                {
                                    var info = WoContext.GetSnOperInfo(input.SN).Data;
                                    info.InputQty = CurOperInfo(input.Locale).InputQty;
                                    action.Data.OperInfo = info;
                                }
                                else if (!IsFinishAllSteps)
                                {
                                    action.Data.OperInfo = SetOperNodeInfo(CurOperInfo(input.Locale));
                                }
                            }
                        }
                        //查找不到条码已绑定的工单
                        else
                        {
                            //没有当前工单,则先选择工单后再扫描条码
                            if (CurBatch.IsNullOrEmpty())
                            {
                                action.Data.ShortMsg = new("未选择工单", ShortMessage.Types.Error);
                                action.Data.OperInfo = new();
                                action.IsSuccessed = false;
                                //action.LocaleMsg = new($"未选择工单,请先选择要生产的工单");
                                action.LocaleMsg = new("MES.Transaction.CollectNode.Submit.NotSelectOrderException");
                            }
                            //有当前工单且不是投入,则提示条码未投入生产,请先去首站扫描
                            else
                            {
                                action.Data.ShortMsg = new("未投入生产", ShortMessage.Types.Error);
                                action.Data.OperInfo = new();
                                action.IsSuccessed = false;
                                //action.LocaleMsg = new($"条码[{input.SN}]尚未投入生产,请先去首站扫描", input.SN);
                                action.LocaleMsg = new("MES.Transaction.CollectNode.Submit.NotInputException", input.SN);
                            }
                        }
                    }
                }
                //完成工序节点工步后,后开始执行当前工序的行为工步
                else if (IsFinishNodeSteps && !IsFinishAllSteps)
                {
                    //更新CurBatch
                    CurBatch?.Update();
 
                    var submitStep = Steps.Where(q => q.ID == input.CurStepID && !q.IsFinished).FirstOrDefault();
                    //如果客户端返回的当前工步ID找不到未完成的行为工步,则直接开始下一个行为工步
                    if (submitStep.IsNullOrEmpty())
                    {
                        action = BeginNextActionStep(input);
                    }
                    else
                    {
                        action = submitStep.Submit(input);
                        //如果当前工步已完成,开始执行下一工步
                        if (action.IsSuccessed && submitStep.IsFinished)
                        {
                            action = BeginNextActionStep(input);
                        }
                        //如果当前工步未完成
                        else
                        {
                            //行为执行出错,工步被重置
                            if (Steps.IsNullOrEmpty())
                            {
                                action.LocaleMsg = new(Biz.T(action.LocaleMsg, input.Locale) + Biz.T(Biz.L("MES.Transaction.Position.RescanSN"), input.Locale));
                            }
                            else
                            {
                                action.Data.SetValue(CurBatch, CurStep, CurStep?.ID, IsFinishAllSteps);
                            }
                        }
                    }
                    //如果所有工步都完成
                    if (IsFinishAllSteps)
                    {
                        action = DoIfFinishAllSteps(action, input.Locale);
                    }
                    else
                    {
                        action.Data.OperInfo = CurOperInfo(input.Locale);
                    }
                }
                //没有可执行的工步
                else
                {
                    action.Data.ShortMsg = new("重置扫描", ShortMessage.Types.Error);
                    action.Data.OperInfo = CurOperInfo(input.Locale);
                    ResetNode();
                    action.IsSuccessed = false;
                    //action.LocaleMsg = new($"岗位[{CurPosition.POST_CODE}]工步执行异常,请重新扫描产品条码", CurPosition.POST_CODE);
                    action.LocaleMsg = new("MES.Transaction.CollectNode.Submit.WorkStepException", CurPosition.POST_CODE);
                }
            }
            catch (Exception ex)
            {
                action.Data.ShortMsg = new("工序异常", ShortMessage.Types.Error);
                action.Data.OperInfo = CurOperInfo(input.Locale);
                ResetNode();
                //action.CatchExceptionWithLog(ex, $"采集工序:提交操作数据异常");
                action.CatchExceptionWithLog(ex, Biz.L("MES.Transaction.CollectNode.SubmitException"));
            }
            return action;
        }
 
        /// <summary>
        /// 工序节点工步提交数据
        /// </summary>
        /// <param name="action"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public ApiAction<SubmitOutput> NodeSubmit(ApiAction<SubmitOutput> action, SubmitInput input)
        {
            var curNode = CurBatch.GetNode(PostCode);
            try
            {
                //当工步列表为空,则执行当前工序的必要逻辑当作第一个工序节点,完成后按需求创建后续的工步列表
                if (Steps.IsNullOrEmpty())
                {
                    BeginAt = DateTime.Now;
                    //判断工单实时状态判断是否可以生产
                    var woStatus = CurBatch.CheckCanProduce(curNode);
                    if (!woStatus.IsSuccessed)
                    {
                        woStatus.Data.ShortMsg = new("工单异常", ShortMessage.Types.Error);
                        return woStatus;
                    }
 
                    var wipSNs = Biz.Db.Queryable<MES_WIP_DATA>().IncludesAllFirstLayer().Where(q => q.SN == input.SN || q.FLOW_SN == input.SN || q.TRAY_SN == input.SN).ToList();
                    if (wipSNs.IsNullOrEmpty())
                    {
                        var wipSN = new MES_WIP_DATA()
                        {
                            SN = input.SN,
                            FLOW_SN = input.SN,
                            STATUS = MES_WIP_DATA.STATUSs.Init.GetValue(),
                            ITEM_CODE = CurBatch.WO.ITEM_CODE,
                            WORK_ORDER = CurBatch.Batch.ORDER_NO,
                            BATCH_NO = CurBatch.Batch.BATCH_NO,
                            FTY_CODE = CurFactory.FTY_CODE,
                            WS_CODE = CurWorkshop.WS_CODE,
                            LINE_CODE = CurLine.LINE_CODE,
                            POST_CODE = CurPosition.POST_CODE,
                            HOLD_FLAG = "N",
                            REWORK_FLAG = CurBatch.WO.ORDER_TYPE == BIZ_MES_WO.ORDER_TYPEs.Rework.GetValue() ? "Y" : "N",
                            FINISHED_FLAG = "N",
                            INV_FLAG = "N",
                            DFT_FLAG = "N",
                            DFT_COUNT = 0,
                        };
                        wipSNs.Add(wipSN);
                    }
 
                    //如果条码不是当前工单或者产线的则报错
                    if (wipSNs.Any(q => q.WORK_ORDER != CurBatch.WO.ORDER_NO || q.LINE_CODE != CurLine.LINE_CODE))
                    {
                        if (wipSNs.First().LINE_CODE == CurLine.LINE_CODE)
                        {
                            action.Data.ShortMsg = new("工单错误", ShortMessage.Types.Error);
                            action.IsSuccessed = false;
                            //action.LocaleMsg = new($"产品[{CurSN}]不属于当前工单,请切换到工单[{wipSNs.First().WORK_ORDER}]后再扫描");
                            action.LocaleMsg = new("MES.Transaction.CollectNode.NodeSubmit.WoError", input.SN, wipSNs.First().WORK_ORDER);
                            return action;
                        }
                        else
                        {
                            action.Data.ShortMsg = new("产线错误", ShortMessage.Types.Error);
                            action.IsSuccessed = false;
                            //action.LocaleMsg = new($"产品[{CurSN}]已在产线[{wipSNs.First().LINE_CODE}]投产,请到产线[{wipSNs.First().LINE_CODE}]扫描");
                            action.LocaleMsg = new("MES.Transaction.CollectNode.NodeSubmit.LineError", input.SN, wipSNs.First().LINE_CODE);
                            return action;
                        }
                    }
 
                    //非法过站防呆:进入工序时要增加判断条码是否按流程过站
                    var canGotoNext = CurBatch.CanGotoNext(input, wipSNs.First(), curNode);
                    if (!canGotoNext.IsSuccessed)
                    {
                        woStatus.Data.ShortMsg = new("进站错误", ShortMessage.Types.Error);
                        return canGotoNext;
                    }
 
                    //绑定条码到工单
                    foreach (var wipSN in wipSNs)
                    {
                        if (!CurBatch.WoSNs.Any(q => q.WIP_ID == wipSN.ID))
                        {
                            CurBatch.WoSNs.Add(new()
                            {
                                WORK_ORDER = CurBatch.Batch.ORDER_NO,
                                WIP_ID = wipSN.ID,
                                SN = wipSN.SN,
                                FLOW_SN = wipSN.SN,
                                TRAY_SN = wipSN.TRAY_SN,
                                STATUS = BIZ_MES_WO_SN.STATUSs.NotInput.GetValue(),
                            });
                        }
                    }
 
                    //更新工单条码明细信息
                    var woSNs = CurBatch.WoSNs.Where(q => wipSNs.Any(w => q.SN == w.SN)).ToList();
                    foreach (var woSN in woSNs)
                    {
                        woSN.AUTH_ORG = CurBatch.WO.AUTH_ORG;
                        woSN.AUTH_PROD = CurLine.LINE_CODE;
                        woSN.BATCH_NO = CurBatch.Batch.BATCH_NO;
                    }
 
                    //条码过站
                    foreach (var wipSN in wipSNs)
                    {
                        wipSN.AUTH_ORG = CurBatch.WO.AUTH_ORG;
                        wipSN.AUTH_PROD = CurLine.LINE_CODE;
                        wipSN.STATUS = MES_WIP_DATA.STATUSs.OK.GetValue();//wipSN.STATUS > 0 ? MES_WIP_DATA.STATUSs.OK.GetValue() : wipSN.STATUS;
                        wipSN.ROT_CODE = CurBatch.WO.ROUTE_CODE;
                        wipSN.NODE_ID = curNode.ID;
                        wipSN.NODE_NAME = curNode.NODE_NAME;
                        wipSN.FTY_CODE = CurFactory.FTY_CODE;
                        wipSN.WS_CODE = CurWorkshop.WS_CODE;
                        wipSN.LINE_CODE = CurLine.LINE_CODE;
                        wipSN.POST_CODE = CurPosition.POST_CODE;
                        wipSN.OPER_CODE = curNode.OPER_CODE;
                        wipSN.SEGMENT = curNode.SEGMENT;
                        wipSN.OPERATION_TIME = DateTime.Now;
                        var curShiftPeriod = GetShiftPeriodForNow();
                        if (!curShiftPeriod.IsNullOrEmpty())
                        {
                            wipSN.SFTS_CODE = curShiftPeriod.ShiftSys.SFTS_CODE;
                            wipSN.SFT_CODE = curShiftPeriod.Shift.SFT_CODE;
                            wipSN.PRD_CODE = curShiftPeriod.Period.PRD_CODE;
                        }
                        //如果是投入站
                        if (curNode.IS_INPUT == "Y")
                        {
                            var woSN = woSNs.First(q => q.SN == wipSN.SN);
                            woSN.STATUS = BIZ_MES_WO_SN.STATUSs.Inputed.GetValue();
                            wipSN.STATUS = MES_WIP_DATA.STATUSs.Input.GetValue();
                            wipSN.INLINE_DATE = DateTime.Now;
                        }
                        //如果是产出站
                        if (curNode.IS_OUTPUT == "Y")
                        {
                            var woSN = woSNs.First(q => q.SN == wipSN.SN);
                            woSN.STATUS = BIZ_MES_WO_SN.STATUSs.Finished.GetValue();
                            wipSN.STATUS = MES_WIP_DATA.STATUSs.Finished.GetValue();
                            wipSN.OUTLINE_DATE = DateTime.Now;
                        }
                        //如果有提交不良
                        if (!input.DFT_CODE.IsNullOrEmpty())
                        {
                            wipSN.STATUS = MES_WIP_DATA.STATUSs.NG.GetValue();
                            wipSN.DFT_FLAG = "Y";
                            wipSN.DFT_COUNT++;
                            wipSN.DFT_CODE = input.DFT_CODE;
                            var dft = CurBatch.Defects.FirstOrDefault(q => q.DFT_CODE == wipSN.DFT_CODE);
                            var defect = new MES_WIP_DFT()
                            {
                                AUTH_ORG = wipSN.AUTH_ORG,
                                AUTH_PROD = wipSN.LINE_CODE,
                                WIP_ID = wipSN.ID,
                                SN = wipSN.SN,
                                STATUS = MES_WIP_DFT.STATUSs.WaitHandle.GetValue(),
                                ITEM_CODE = wipSN.ITEM_CODE,
                                WORK_ORDER = wipSN.WORK_ORDER,
                                BATCH_NO = wipSN.BATCH_NO,
                                ROT_CODE = wipSN.ROT_CODE,
                                NODE_ID = wipSN.NODE_ID,
                                NODE_NAME = wipSN.NODE_NAME,
                                FTY_CODE = wipSN.FTY_CODE,
                                WS_CODE = wipSN.WS_CODE,
                                LINE_CODE = wipSN.LINE_CODE,
                                POST_CODE = wipSN.POST_CODE,
                                OPER_CODE = wipSN.OPER_CODE,
                                SEGMENT = wipSN.SEGMENT,
                                DFT_CODE = dft.DFT_CODE,
                                DFT_NAME = dft.DFT_NAME,
                                DFT_LEVEL = dft.DFT_LEVEL,
                                FLOW_SN = wipSN.FLOW_SN,
                                TRAY_SN = wipSN.TRAY_SN,
                                INNER_SN = wipSN.INNER_SN,
                                CARTON_SN = wipSN.CARTON_SN,
                                PALLET_SN = wipSN.PALLET_SN,
                                INV_FLAG = wipSN.INV_FLAG,
                                OPERATION_TIME = DateTime.Now,
                                SFTS_CODE = wipSN.SFTS_CODE,
                                SFT_CODE = wipSN.SFT_CODE,
                                PRD_CODE = wipSN.PRD_CODE,
                                OBA_BATCH = wipSN.OBA_BATCH,
                                LOCK_BATCH = wipSN.LOCK_BATCH,
                            };
                            CurDefects.Add(defect);
                        }
                    }
 
                    //工单开工
                    CurBatch.StartWorking(UserCode);
 
                    //把当前条码增加到当前条码列表
                    CurWipSNs = wipSNs;
                    CurWipSNHiss.Clear();
                    foreach (var wipSN in wipSNs)
                    {
                        var his = new MES_WIP_HIS(wipSN, $"工单[{wipSN.WORK_ORDER}]条码[{wipSN.SN}]在岗位[{wipSN.POST_CODE}]过站工序[{wipSN.NODE_NAME}]成功");
                        wipSN.History.Add(his);
                        CurWipSNHiss.Add(his);
                    }
 
                    //创建变量克隆对象用于传入DBSubmitAction中保存当前需要暂存的数据值
                    var _woSns = woSNs.Clone();
                    var _wipSns = wipSNs.Clone();
                    var _wipHiss = CurWipSNHiss.Clone();
                    var _defect = CurDefects.Clone();
                    var _curNode = curNode.Clone();
                    var _Batch = CurBatch.Batch.Clone();
 
                    //初始化工步列表
                    Steps.Clear();
                    var curStep = new WorkStep(IWorkStep.NodeTypes.Node, this)
                    {
                        Name = "扫描产品",
                        Sequence = Steps.Count + 1,
                        Node = curNode,
                        OperSetting = CurBatch.NodeSets.FirstOrDefault(q => q.NODE_ID == curNode.ID),
                        DBSubmitAction = () =>
                        {
                            //使用统一的事务DB对象
                            var db = GetCommitDB();
                            //数据保存逻辑
                            db.Storageable(_woSns, UserCode).ExecuteCommand();
                            db.Storageable(_wipSns, UserCode).ExecuteCommand();
                            db.Storageable(_wipHiss, UserCode).ExecuteCommand();
                            //如果有不良则保存
                            if (_defect.Any())
                            {
                                db.Storageable(_defect, UserCode).ExecuteCommand();
                            }
                            //如果是投入站
                            if (_curNode.IS_INPUT == "Y")
                            {
                                db.Updateable<BIZ_MES_WO>().SetColumns(q => q.INPUT_QTY == q.INPUT_QTY + _woSns.Count).Where(q => q.ORDER_NO == _Batch.ORDER_NO).ExecuteCommand();
                                db.Updateable<BIZ_MES_WO_BATCH>().SetColumns(q => q.INPUT_QTY == q.INPUT_QTY + _woSns.Count).Where(q => q.BATCH_NO == _Batch.BATCH_NO).ExecuteCommand();
                            }
                            //如果是产出站
                            if (_curNode.IS_OUTPUT == "Y")
                            {
                                db.Updateable<BIZ_MES_WO>().SetColumns(q => q.OUTPUT_QTY == q.OUTPUT_QTY + _woSns.Count).Where(q => q.ORDER_NO == _Batch.ORDER_NO).ExecuteCommand();
                                db.Updateable<BIZ_MES_WO_BATCH>().SetColumns(q => q.OUTPUT_QTY == q.OUTPUT_QTY + _woSns.Count).Where(q => q.BATCH_NO == _Batch.BATCH_NO).ExecuteCommand();
                            }
                        }
                    };
                    Steps.Add(curStep);
 
                    //有需要用户提交信息则添加工序节点的其他工步
 
                    //最后添加当前工序的行为工步
                    try
                    {
                        GenerateSteps(curStep);
                    }
                    catch (System.Exception ex)
                    {
                        ResetNode();
                        //action.CatchExceptionWithLog(ex, $"{curNode.NODE_NAME}:工序行为工步生成异常,请检查工序行为设置");
                        action.CatchExceptionWithLog(ex, Biz.L("MES.Transaction.CollectNode.NodeSubmit.GenerateStepsException", curNode.NODE_NAME));
                    }
 
                    //完成第一个工序节点工步
                    curStep.IsFinished = true;
                    curStep.Status = StepStatus.Finished;
                    CurStep = curStep;
                }
                else if (!IsFinishNodeSteps)
                {
                    var curStep = Steps.Where(q => q.NodeType == IWorkStep.NodeTypes.Node && !q.IsFinished).OrderBy(q => q.Sequence).First();
 
                    //根据工序节点工步的序号处理相应工步的处理逻辑
                    switch (curStep.Sequence)
                    {
                        case 2:
                            {
                                //第二工步的处理逻辑
 
 
                                //完成当前工序节点工步
                                curStep.IsFinished = true;
                                curStep.Status = StepStatus.Finished;
                                CurStep = curStep;
                            }
                            break;
                        default:
                            break;
                    }
                }
 
                //未完成所有工步
                if (!IsFinishAllSteps)
                {
                    //未完成所有工序节点工步
                    if (!IsFinishNodeSteps)
                    {
                        var next = Steps.Where(q => q.NodeType == IWorkStep.NodeTypes.Node && !q.IsFinished).OrderBy(q => q.Sequence).First();
                        //设置后续可执行的工步列表
                        NextSteps.Clear();
                        NextSteps.Add(next);
                        //根据后续工步返回ApiAction
                        action.Data.SetValue(CurBatch, CurStep, next.ID, IsFinishAllSteps);
 
                        //根据工序节点工步的序号返回相应的操作提示
                        switch (next.Sequence)
                        {
                            case 2:
                                //action.LocaleMsg = new($"请执行第二步");
                                action.LocaleMsg = new("MES.Transaction.CollectNode.第二步操作提示");
                                break;
                            default:
                                break;
                        }
                    }
                    //已完成所有工序节点工步,开始执行行为工步
                    else
                    {
                        action = BeginNextActionStep(input);
                    }
                }
                //已完成所有工步
                if (IsFinishAllSteps)
                {
                    action.Data.SetValue(CurBatch, CurStep, "", IsFinishAllSteps);
                    action = DoIfFinishAllSteps(action, input.Locale);
                }
            }
            catch (Exception ex)
            {
                action.Data.ShortMsg = new("工步异常", ShortMessage.Types.Error);
                ResetNode();
                //action.CatchExceptionWithLog(ex, $"{curNode.NODE_NAME}:工序节点工步提交数据异常,请检查工序节点设置");
                action.CatchExceptionWithLog(ex, Biz.L("MES.Transaction.CollectNode.NodeSubmitException", curNode.NODE_NAME));
            }
            return action;
        }
 
        /// <summary>
        /// 完成所有工步后执行
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        public ApiAction<SubmitOutput> DoIfFinishAllSteps(ApiAction<SubmitOutput> action, string locale)
        {
            //保存数据库
            SaveStepsCommitActionToDB();
 
            //保存成功,返回过站消息
            CurOperInfo(locale).InputQty += CurWipSNs.Count;
            action.Data.OperInfo = SetOperNodeInfo(CurOperInfo(locale));
            action.Data.ShortMsg = new("过站成功", ShortMessage.Types.Success);
            //action.LocaleMsg = new($"工单[{CurWipSN.WORK_ORDER}]的条码[{CurWipSN.SN}]在岗位[{CurWipSN.POST_CODE}]工序[{CurWipSN.NODE_NAME}]过站成功,状态[{CurWipSN.STATUS.GetEnumDesc<MES_WIP_DATA.STATUSs>()}]");
            action.LocaleMsg = new("MES.Transaction.CollectNode.ScanSn.PassSuccess", CurWipSNs.First().WORK_ORDER, CurSN, CurWipSNs.First().POST_CODE, CurWipSNs.First().NODE_NAME,CurWipSNs.First().STATUS.GetEnumDesc<MES_WIP_DATA.STATUSs>());
            
            //重置工序
            ResetNode();
            return action;
        }
        #endregion Functions
 
        public override bool Close(bool needSaveHistoryLog = false)
        {
            //needSaveHistoryLog = true;
            //保存操作日志
 
            this.IsFinished = true;
            return IsFinished ? base.Close(needSaveHistoryLog) : IsFinished;
        }
    }//endClass
}