服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2025-01-01 77771c41aa9f7f1f242c79b95fc2a8c82bd7c6c8
Tiger.Business.MES/WorkAction/WipExtInfo.cs
@@ -16,6 +16,7 @@
    {
        #region Propertys & Variables
        #region 固定写法,工序中的必要信息
        public DbClient MainDB { get; set; }
        public bool IsFinished { get; set; } = false;
        public IWorkStep CurStep { get; set; }
        public IPosition CurPosition { get; set; }
@@ -34,6 +35,7 @@
        public void Init(IWorkStep curStep, IPosition position, MES_WO_NODE_ACT nodeAct, MES_WO_ACTION setting)
        {
            #region 固定写法,给默认变量赋值
            MainDB = position.MainDB;
            CurStep = curStep;
            CurPosition = position;
            NodeAct = nodeAct;
@@ -42,9 +44,9 @@
            //获取扩展字段定义
            var seq = Setting.ITEM_CODE.ToInt32();
            ExtInfo = Biz.Db.Queryable<BAS_WIP_EXT>().Where(q => q.SEQ == seq).First();
            ExtInfo = MainDB.Queryable<BAS_WIP_EXT>().Where(q => q.SEQ == seq).First();
            //获取当前SN的扩展信息
            CurWipExt = Biz.Db.Queryable<MES_WIP_EXT>().Where(q => CurPosition.CurWipSNs.Any(w => w.SN == q.SN)).ToList();
            CurWipExt = MainDB.Queryable<MES_WIP_EXT>().Where(q => CurPosition.CurWipSNs.Any(w => w.SN == q.SN)).ToList();
            foreach (var wipSN in CurPosition.CurWipSNs)
            {
                if (!CurWipExt.Any(q => q.SN == wipSN.SN))
@@ -54,9 +56,13 @@
                        AUTH_ORG = wipSN.AUTH_ORG,
                        AUTH_PROD = wipSN.AUTH_PROD,
                        SN = wipSN.SN,
                        WIP_ID = wipSN.ID,
                    });
                }
            }
            CurStep.Message = Biz.L("扫描要绑定的标签");
            CurStep.Status = StepStatus.Normal;
        }
        /// <summary>
@@ -81,7 +87,10 @@
            action.LocaleMsg = GetBeginMsg();
            //如果返回成功则认为当前行为可以开始执行,否则返回失败
            CurStep.Message = Biz.L("绑定开始");
            CurStep.Status = StepStatus.Normal;
            action.IsSuccessed = true;
            action.Data.ShortMsg = new("绑定开始", ShortMessage.Types.Success);
            return action;
        }
@@ -114,12 +123,18 @@
                //验证扫描的条码是否SN的扩展信息的标签
                if (input.SN.IsNullOrEmpty())
                {
                    CurStep.Message = Biz.L("绑定失败");
                    CurStep.Status = StepStatus.Error;
                    action.Data.ShortMsg = new("绑定失败", ShortMessage.Types.Failed);
                    action.IsSuccessed = isOK = false;
                    //action.LocaleMsg = new Locale($"错误:[{ExtInfo.FIELD_NAME}]标签条码不能为空,请重新扫描");
                    action.LocaleMsg = new Locale("MES.WorkAction.WipExtInfo.SnEmptyError", ExtInfo.FIELD_NAME);
                }
                if (CurPosition.CurWipSNs.Any(w => w.SN == input.SN))
                {
                    CurStep.Message = Biz.L("绑定失败");
                    CurStep.Status = StepStatus.Error;
                    action.Data.ShortMsg = new("绑定失败", ShortMessage.Types.Failed);
                    action.IsSuccessed = isOK = false;
                    //action.LocaleMsg = new Locale($"错误:扫描到产品条码[{input.SN}],请重新扫描[{ExtInfo.FIELD_NAME}]标签条码");
                    action.LocaleMsg = new Locale("MES.WorkAction.WipExtInfo.ScanProdSnError", input.SN, ExtInfo.FIELD_NAME);
@@ -129,14 +144,16 @@
                if (isOK)
                {
                    CurWipExt.GetType().GetProperty($"FIELD_{ExtInfo.SEQ.ToString("00")}")?.SetValue(CurWipExt, input.SN);
                    action = End();
                    action = End(input);
                }
                //都没有物料验证通过,则返回错误信息
            }
            catch (System.Exception ex)
            {
                CurStep.Message = Biz.L("绑定异常");
                CurStep.Status = StepStatus.Error;
                action.Data.ShortMsg = new("绑定异常", ShortMessage.Types.Exception);
                action.CatchExceptionWithLog(ex, $"扩展信息绑定行为:产品[{CurPosition.CurSN}]绑定[{ExtInfo.FIELD_NAME}]标签条码[{input.SN}]保存异常");
                action.IsSuccessed = false;
                //action.LocaleMsg = new($"产品[{CurPosition.CurWipSN.SN}]绑定[{ExtInfo.FIELD_NAME}]标签条码[{input.SN}]保存异常,工序已重置,请重新扫描进站产品条码");
@@ -150,7 +167,7 @@
        /// 结束执行工序行为
        /// </summary>
        /// <returns></returns>
        public ApiAction<SubmitOutput> End()
        public ApiAction<SubmitOutput> End(SubmitInput input)
        {
            var action = new ApiAction<SubmitOutput>(new SubmitOutput());
@@ -162,6 +179,7 @@
                {
                    AUTH_ORG = CurPosition.WorkBatch.WO.AUTH_ORG,
                    AUTH_PROD = CurPosition.CurLine.LINE_CODE,
                    WIP_ID = wipSn.ID,
                    HIS_ID = CurPosition.CurWipSNHiss.First(q => q.SN == wipSn.SN).ID,
                    SN = wipSn.SN,
                    STATUS = wipSn.STATUS,
@@ -179,7 +197,11 @@
                    POST_CODE = wipSn.POST_CODE,
                    OPER_CODE = wipSn.OPER_CODE,
                    SEGMENT = wipSn.SEGMENT,
                    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,
                    OPERATION_TIME = DateTime.Now,
                    SFTS_CODE = wipSn.SFTS_CODE,
                    SFT_CODE = wipSn.SFT_CODE,
@@ -188,20 +210,27 @@
                    ACT_SN = wipSn.SN,
                    ACT_VALUE_1 = CurWipExt.ToJson(),
                    ACT_RESULT = "Y",
                    ELAPSED_TIME = CurStep.GetElapsedTime().TotalMilliseconds.ToInt64(),
                    TRACE_INFO = $"产品[{CurPosition.CurSN}]绑定[{ExtInfo.FIELD_NAME}]标签条码[{CurWipExt.GetType().GetProperty($"FIELD_{ExtInfo.SEQ.ToString("00")}")?.GetValue(CurWipExt)?.ToString()}]保存成功",
                };
                wipActs.Add(wipAct);
            }
            //创建变量克隆对象用于传入DBSubmitAction中保存当前需要暂存的数据值
            var _wipActs = wipActs.Clone();
            var _CurWipExt = CurWipExt.Clone();
            //保存数据
            CurStep.DBSubmitAction = () =>
            {
                var db = CurPosition.GetCommitDB();
                db.Storageable(wipActs, CurPosition.UserCode).ExecuteCommand();
                db.Storageable(CurWipExt, CurPosition.UserCode).ExecuteCommand();
                db.Storageable(_wipActs, CurPosition.UserCode).ExecuteCommand();
                db.Storageable(_CurWipExt, CurPosition.UserCode).ExecuteCommand();
            };
            IsFinished = true;
            CurStep.Message = Biz.L("绑定完成");
            CurStep.Status = StepStatus.Finished;
            action.Data.ShortMsg = new("绑定完成", ShortMessage.Types.Success);
            //action.LocaleMsg = new($"产品[{CurPosition.CurWipSN.SN}]绑定[{ExtInfo.FIELD_NAME}]标签条码[{CurWipExt.GetType().GetProperty($"FIELD_{ExtInfo.SEQ.ToString("00")}")?.GetValue(CurWipExt)?.ToString()}]保存成功");
            action.LocaleMsg = new("MES.WorkAction.WipExtInfo.SaveSuccess", CurPosition.CurSN, ExtInfo.FIELD_NAME, CurWipExt.GetType().GetProperty($"FIELD_{ExtInfo.SEQ.ToString("00")}")?.GetValue(CurWipExt)?.ToString());
            return action;