服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-08-21 b4bd82fdbace031a81ab40963c8344d5eaa4a772
增加雅达三码合一行为,用于厂内条码绑定并打印客户条码
已修改4个文件
已添加2个文件
280 ■■■■■ 文件已修改
Tiger.Api/Language.db 补丁 | 查看 | 原始文档 | blame | 历史
Tiger.Business.MES/Transaction/PackingNode.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tiger.Business.MES/Transaction/Position.cs 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tiger.Business.MES/WorkAction/ThreeInOne.cs 251 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tiger.Business/MES/Biz.WorkBatch.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tiger.IBusiness/MES/WorkAction/IThreeInOne.cs 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tiger.Api/Language.db
Binary files differ
Tiger.Business.MES/Transaction/PackingNode.cs
@@ -96,7 +96,7 @@
                                    action.Data.ShortMsg = new("请扫描产品", ShortMessage.Types.Error);
                                    action.Data.OperInfo = new();
                                    action.IsSuccessed = false;
                                    action.LocaleMsg = new($"条码[{0}]是载具条码,请扫描载具中的产品条码继续包装操作");
                                    //action.LocaleMsg = new($"条码[{0}]是载具条码,请扫描载具中的产品条码继续包装操作");
                                    action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.OnlyMinPackage", input.SN);
                                    return action;
                                }
Tiger.Business.MES/Transaction/Position.cs
@@ -71,7 +71,7 @@
        /// æ˜¯å¦éœ€è¦ä¸´æ—¶å­˜å‚¨æ•°æ®åº“提交操作,待需要的时候再提交
        /// </summary>
        public bool NeedTemporaryStoreDBCommitAction { get; set; } = false;
        protected List<Action> DBCommitList { get; set; } = new();
        protected Dictionary<string, List<Action>> DBCommitList { get; set; } = new();
        protected List<Position> NodeCommitList { get; set; } = new();
        protected Dictionary<string, OperInfo> OperInfoDic { get; set; } = new();
        protected OperInfo CurOperInfo { get; set; }
@@ -360,10 +360,12 @@
        protected void SaveStepsCommitActionToDB()
        {
            //保存工步的数据库提交操作到提交操作列表
            var commitList = new List<Action>();
            foreach (var step in Steps.OrderBy(q => q.Sequence))
            {
                DBCommitList.Add(step.DBSubmitAction);
                commitList.Add(step.DBSubmitAction);
            }
            DBCommitList.Add(CurSN, commitList);
            //如果不需要临时存储数据库提交操作,则把提交操作列表提交到数据库
            if (!NeedTemporaryStoreDBCommitAction)
            {
@@ -373,9 +375,12 @@
                var dbTran = GetCommitDB().UseTran(() =>
                {
                    //在同一个事务中保存所有工步的数据
                    foreach (var action in DBCommitList)
                    foreach (var wipSn in DBCommitList.Keys)
                    {
                        action.Invoke();
                        foreach (var action in DBCommitList[wipSn])
                        {
                            action.Invoke();
                        }
                    }
                });
                if (dbTran.IsSuccess)
Tiger.Business.MES/WorkAction/ThreeInOne.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,251 @@
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.IBusiness.MES.WorkAction;
using Tiger.Model;
using Tiger.Model.Entitys.MES.Position;
namespace Tiger.Business.MES.WorkAction
{
    public class ThreeInOne : IThreeInOne
    {
        #region Propertys & Variables
        #region å›ºå®šå†™æ³•,工序中的必要信息
        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; }
        #endregion
        public MES_CUST_SN CurCSN  { 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 void Init(IWorkStep curStep, IPosition position, MES_WO_NODE_ACT nodeAct, MES_WO_ACTION setting)
        {
            #region å›ºå®šå†™æ³•,给默认变量赋值
            CurStep = curStep;
            CurPosition = position;
            NodeAct = nodeAct;
            Setting = setting;
            #endregion
            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();
        }
        /// <summary>
        /// èŽ·å–è¡Œä¸ºå¼€å§‹çš„æç¤ºä¿¡æ¯
        /// </summary>
        /// <returns></returns>
        public Locale GetBeginMsg()
        {
            var msg = new Locale("MES.WorkAction.ThreeInOne.BeginMsg", CurPosition.CurSN);
            //var msg = new Locale($"开始检查条码[{CurPosition.CurSN}]的是否已绑定客户条码");
            return msg;
        }
        /// <summary>
        /// å°è¯•开始执行工序行为
        /// </summary>
        /// <returns></returns>
        public ApiAction<SubmitOutput> TryBegin(SubmitInput input)
        {
            var action = new ApiAction<SubmitOutput>(new SubmitOutput());
            //只允许单个产品进行客户条码绑定
            if (CurPosition.CurWipSNs.Count > 1)
            {
                action.Data.ShortMsg = new("请扫描产品", ShortMessage.Types.Error);
                //action.LocaleMsg = new($"条码[{0}]是包装/载具条码,请重新扫描单个厂内条码进行客户条码绑定");
                action.LocaleMsg = new("MES.WorkAction.ThreeInOne.NotProductSN", CurPosition.CurSN);
                //重置工序操作
                CurPosition.ResetNode();
                action.IsSuccessed = false;
                return action;
            }
            var wipSn = CurPosition.CurWipSNs.First();
            CurCSN = Biz.Db.Queryable<MES_CUST_SN>().Where(q => q.FLOW_SN == wipSn.SN).First();
            //厂内条码已绑定客户条码,直接结束行为
            if (!CurCSN.IsNullOrEmpty())
            {
                CurCSN.WORK_ORDER = CurPosition.WorkBatch.WO.ORDER_NO;
                CurCSN.ITEM_CODE = CurPosition.WorkBatch.WO.ITEM_CODE;
                End();
            }
            //厂内条码未绑定客户条码
            else
            {
                //如果客户条码标签模板为空则不需要打印,等待扫描客户条码进行绑定
                if (Label.IsNullOrEmpty())
                {
                    action.Data.Data = new
                    {
                        NeedPrint = false,
                        Label = "",
                    };
                    action.Data.ShortMsg = new("扫描客户标签", ShortMessage.Types.Normal);
                    //action.LocaleMsg = new Locale($"请扫描厂内条码[{0}]需要绑定客户条码");
                    action.LocaleMsg = new Locale("MES.WorkAction.ThreeInOne.BeginScan", wipSn.SN);
                }
                else
                {
                    //设置打印变量值
                    Label = CurPosition.SetLabelVariables(LabelPV, Label);
                    action.Data.Data = new
                    {
                        NeedPrint = true,
                        Label,
                    };
                    action.Data.ShortMsg = new("打印客户标签", ShortMessage.Types.Normal);
                    //action.LocaleMsg = new Locale($"开始打印厂内条码[{0}]对应的客户条码");
                    action.LocaleMsg = new Locale("MES.WorkAction.ThreeInOne.BeginPrint", wipSn.SN);
                }
            }
            //如果返回成功则认为当前行为可以开始执行,否则返回失败
            action.IsSuccessed = true;
            return action;
        }
        /// <summary>
        /// å·¥åºè¡Œä¸ºæäº¤æ•°æ®
        /// </summary>
        /// <returns></returns>
        public ApiAction<SubmitOutput> Submit(SubmitInput input)
        {
            var action = new ApiAction<SubmitOutput>(new SubmitOutput());
            var csn = input.Data;
            CurCSN = Biz.Db.Queryable<MES_CUST_SN>().Where(q => q.CUST_SN == input.Data).First() ?? new()
            {
                CUST_SN = input.Data,
            };
            //客户条码已绑定其他厂内条码
            if (!CurCSN.FLOW_SN.IsNullOrEmpty() && CurCSN.FLOW_SN != CurPosition.CurWipSNs.First().SN)
            {
                action.Data.ShortMsg = new("绑定失败", ShortMessage.Types.Failed);
                action.IsSuccessed = false;
                //action.LocaleMsg = new($"厂内条码[{0}]绑定客户条码[{1}]失败,客户条码已绑定厂内条码[{2}]");
                action.LocaleMsg = new("MES.WorkAction.ThreeInOne.BindingOtherSN", CurPosition.CurWipSNs.First().SN, CurCSN.CUST_SN, CurCSN.FLOW_SN);
                //如果行为设置为出错需要重置工序操作
                if (NodeAct.NEED_RESET == "Y")
                {
                    CurPosition.ResetNode();
                }
            }
            //客户条码不属于当前工单的客户
            else if (CurCSN.CUST_CODE.IsNullOrEmpty(CurPosition.WorkBatch.WO.CUST_CODE) != CurPosition.WorkBatch.WO.CUST_CODE)
            {
                action.Data.ShortMsg = new("绑定失败", ShortMessage.Types.Failed);
                action.IsSuccessed = false;
                //action.LocaleMsg = new($"客户条码[{0}]属于客户[{1}],与当前工单的客户[{2}]不一致");
                action.LocaleMsg = new("MES.WorkAction.ThreeInOne.NotSameCustomer", CurCSN.CUST_SN, CurCSN.CUST_CODE, CurPosition.WorkBatch.WO.CUST_CODE);
                //如果行为设置为出错需要重置工序操作
                if (NodeAct.NEED_RESET == "Y")
                {
                    CurPosition.ResetNode();
                }
            }
            //提交数据执行失败
            else
            {
                CurCSN.CUST_CODE = CurPosition.WorkBatch.WO.CUST_CODE;
                CurCSN.FLOW_SN = CurPosition.CurWipSNs.First().SN;
                CurCSN.WORK_ORDER = CurPosition.WorkBatch.WO.ORDER_NO;
                CurCSN.ITEM_CODE = CurPosition.WorkBatch.WO.ITEM_CODE;
                action = End();
            }
            return action;
        }
        /// <summary>
        /// ç»“束执行工序行为
        /// </summary>
        /// <returns></returns>
        public ApiAction<SubmitOutput> End()
        {
            var action = new ApiAction<SubmitOutput>(new SubmitOutput());
            //记录行为操作记录
            var wipActs = new List<MES_WIP_ACT>();
            foreach (var wipSn in CurPosition.CurWipSNs)
            {
                var wipAct = new MES_WIP_ACT()
                {
                    AUTH_ORG = CurPosition.WorkBatch.WO.AUTH_ORG,
                    AUTH_PROD = CurPosition.CurLine.LINE_CODE,
                    HIS_ID = CurPosition.CurWipSNHiss.First(q => q.SN == wipSn.SN).ID,
                    WIP_ID = wipSn.ID,
                    SN = wipSn.SN,
                    STATUS = wipSn.STATUS,
                    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,
                    ACT_ID = NodeAct.ID,
                    ACT_NAME = NodeAct.ACT_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,
                    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,
                    PRD_CODE = wipSn.PRD_CODE,
                    ACT_TYPE = NodeAct.ACT_TYPE,
                    ACT_SN = wipSn.SN,
                    ACT_VALUE_1 = Label.LABEL_CODE,
                    ACT_VALUE_2 = Label.Variables.ToJson(),
                    ACT_RESULT = "Y",
                    TRACE_INFO = $"厂内条码[{0}]已绑定客户条码[{1}]成功",
                };
                wipActs.Add(wipAct);
            }
            //创建变量克隆对象用于传入DBSubmitAction中保存当前需要暂存的数据值
            var _wipActs = wipActs.Clone();
            var _CurCSN = CurCSN.Clone();
            //保存数据
            CurStep.DBSubmitAction = () =>
            {
                var db = CurPosition.GetCommitDB();
                db.Storageable(_wipActs, CurPosition.UserCode).ExecuteCommand();
                db.Storageable(_CurCSN, CurPosition.UserCode).ExecuteCommand();
            };
            IsFinished = true;
            action.Data.ShortMsg = new("客户条码已绑定", ShortMessage.Types.Success);
            //action.LocaleMsg = new($"厂内条码[{0}]已绑定客户条码[{1}]完成", Label.LABEL_NAME);
            action.LocaleMsg = new("MES.WorkAction.ThreeInOne.BindingComplete", CurCSN.FLOW_SN, CurCSN.CUST_SN);
            return action;
        }
        #endregion Functions
    }
}
Tiger.Business/MES/Biz.WorkBatch.cs
@@ -140,7 +140,7 @@
                    action.IsSuccessed = false;
                    action.Data.SetValue(this, null);
                    action.LocaleMsg = new($"工单批次[{0}]已投入 {1},其中报废 {2},以满足计划数量[{3}],无需继续投入");
                    action.LocaleMsg = new("MES.WorkBatch.WoInputEnough", Batch.BATCH_NO, Batch.INPUT_QTY, Batch.SCRAP_QTY, Batch.PLAN_QTY);
                    action.LocaleMsg = new("MES.WorkBatch.WoInputEnough", Batch.BATCH_NO, WoSNs.Count(q => q.BATCH_NO == Batch.BATCH_NO), Batch.SCRAP_QTY, Batch.PLAN_QTY);
                }
                return action;
Tiger.IBusiness/MES/WorkAction/IThreeInOne.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,12 @@
using Newtonsoft.Json;
using Rhea.Common;
using System;
using Tiger.Model;
namespace Tiger.IBusiness.MES.WorkAction
{
    public interface IThreeInOne : IWorkAction
    {
    }
}