服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-10-14 c4de1972bbf4152bba19107c24647db3606db68a
优化包装信息保存逻辑
已修改1个文件
已添加2个文件
268 ■■■■■ 文件已修改
Tiger.Business.MES/WorkAction/PackingAction.cs 41 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tiger.Business.MES/WorkAction/YadaWoReport.cs 215 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tiger.IBusiness.MES/WorkAction/IYadaWoReport.cs 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tiger.Business.MES/WorkAction/PackingAction.cs
@@ -818,6 +818,7 @@
                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,
@@ -879,13 +880,27 @@
                                .SetColumns(q => q.TRAY_SN == CurPkg.Item.Package.SN)
                                .SetColumns(q => q.INNER_SN == q.CARTON_SN)
                                .SetColumns(q => q.CARTON_SN == CurPkg.Item.Package.SN)
                                .Where(q => q.WORK_ORDER == pkg.WORK_ORDER && q.SN == pkg.SN)
                                .Where(q => q.WORK_ORDER == pkg.WORK_ORDER && q.ID == pkg.WIP_ID)
                                .ExecuteCommand();
                            //包装信息保存到生产过程记录
                            db.Updateable<MES_WIP_HIS>()
                                .SetColumns(q => q.TRAY_SN == CurPkg.Item.Package.SN)
                                .SetColumns(q => q.INNER_SN == q.CARTON_SN)
                                .SetColumns(q => q.CARTON_SN == CurPkg.Item.Package.SN)
                                .Where(q => q.WORK_ORDER == pkg.WORK_ORDER && q.ID == pkg.WIP_ID && q.NODE_ID == pkg.NODE_ID)
                                .ExecuteCommand();
                            //包装信息保存到生产行为记录
                            db.Updateable<MES_WIP_ACT>()
                                .SetColumns(q => q.TRAY_SN == CurPkg.Item.Package.SN)
                                .SetColumns(q => q.INNER_SN == q.CARTON_SN)
                                .SetColumns(q => q.CARTON_SN == CurPkg.Item.Package.SN)
                                .Where(q => q.WORK_ORDER == pkg.WORK_ORDER && q.ID == pkg.WIP_ID && q.NODE_ID == pkg.NODE_ID && q.ACT_ID == NodeAct.ID)
                                .ExecuteCommand();
                            //包装信息保存到工单条码明细表
                            db.Updateable<BIZ_MES_WO_SN>()
                                .SetColumns(q => q.TRAY_SN == CurPkg.Item.Package.SN)
                                .SetColumns(q => q.OUTER_SN == CurPkg.Item.Package.SN)
                                .Where(q => q.WORK_ORDER == pkg.WORK_ORDER && q.SN == pkg.SN)
                                .Where(q => q.WORK_ORDER == pkg.WORK_ORDER && q.WIP_ID == pkg.WIP_ID)
                                .ExecuteCommand();
                        }
                    }
@@ -913,13 +928,27 @@
                                    .SetColumns(q => q.TRAY_SN == CurPkg.Item.Package.SN)
                                    .SetColumns(q => q.INNER_SN == q.CARTON_SN)
                                    .SetColumns(q => q.CARTON_SN == CurPkg.Item.Package.SN)
                                    .Where(q => q.WORK_ORDER == pkg.WORK_ORDER && q.SN == pkg.SN)
                                    .Where(q => q.WORK_ORDER == pkg.WORK_ORDER && q.ID == pkg.WIP_ID)
                                    .ExecuteCommand();
                                //包装信息保存到工单条码明细表
                                db.Updateable<BIZ_MES_WO_SN>()
                                //包装信息保存到生产过程记录
                                db.Updateable<MES_WIP_HIS>()
                                    .SetColumns(q => q.TRAY_SN == CurPkg.Item.Package.SN)
                                    .SetColumns(q => q.INNER_SN == q.CARTON_SN)
                                    .SetColumns(q => q.CARTON_SN == CurPkg.Item.Package.SN)
                                    .Where(q => q.WORK_ORDER == pkg.WORK_ORDER && q.ID == pkg.WIP_ID && q.NODE_ID == pkg.NODE_ID)
                                    .ExecuteCommand();
                                //包装信息保存到生产行为记录
                                db.Updateable<MES_WIP_ACT>()
                                    .SetColumns(q => q.TRAY_SN == CurPkg.Item.Package.SN)
                                    .SetColumns(q => q.INNER_SN == q.CARTON_SN)
                                    .SetColumns(q => q.CARTON_SN == CurPkg.Item.Package.SN)
                                    .Where(q => q.WORK_ORDER == pkg.WORK_ORDER && q.ID == pkg.WIP_ID && q.NODE_ID == pkg.NODE_ID && q.ACT_ID == NodeAct.ID)
                                    .ExecuteCommand();
                                //包装信息保存到工单条码明细表
                                db.Updateable<BIZ_MES_WO_SN>()
                                    .SetColumns(q => q.TRAY_SN == CurPkg.Item.Package.SN)
                                    .SetColumns(q => q.OUTER_SN == CurPkg.Item.Package.SN)
                                    .Where(q => q.WORK_ORDER == pkg.WORK_ORDER && q.SN == pkg.SN)
                                    .Where(q => q.WORK_ORDER == pkg.WORK_ORDER && q.WIP_ID == pkg.WIP_ID)
                                    .ExecuteCommand();
                            }
                        }
Tiger.Business.MES/WorkAction/YadaWoReport.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,215 @@
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 YadaWoReport : IYadaWoReport
    {
        #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
        private MES_WIP_PKG CurPkg;
        #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
            CurPkg = Biz.Db.Queryable<MES_WIP_PKG>().Where(q => q.SN == CurPosition.CurSN && q.AUTH_ORG == CurPosition.WorkBatch.WO.AUTH_ORG).First() ?? new()
            {
                AUTH_ORG = CurPosition.WorkBatch.WO.AUTH_ORG,
                AUTH_PROD = CurPosition.CurLine.LINE_CODE,
                SN = CurPosition.CurSN,
                PKG_TYPE = CurPosition.WorkBatch.WO.ItemInfo?.UNIT,
                ITEM_CODE = CurPosition.CurWipSNs.First().ITEM_CODE,
                QTY = CurPosition.CurWipSNs.Sum(q => q.QTY),
                UNIT = CurPosition.WorkBatch.WO.ItemInfo?.UNIT,
                WORK_ORDER = CurPosition.CurWipSNs.First().WORK_ORDER,
                BATCH_NO = CurPosition.CurWipSNs.First().BATCH_NO,
                ROT_CODE = CurPosition.CurWipSNs.First().ROT_CODE,
                NODE_ID = CurPosition.CurWipSNs.First().NODE_ID,
                NODE_NAME = CurPosition.CurWipSNs.First().NODE_NAME,
                FTY_CODE = CurPosition.CurWipSNs.First().FTY_CODE,
                WS_CODE = CurPosition.CurWipSNs.First().WS_CODE,
                LINE_CODE = CurPosition.CurWipSNs.First().LINE_CODE,
                POST_CODE = CurPosition.CurWipSNs.First().POST_CODE,
                OPER_CODE = CurPosition.CurWipSNs.First().OPER_CODE,
                SEGMENT = CurPosition.CurWipSNs.First().SEGMENT,
            };
            CurStep.Message = Biz.L("等待称重数据");
            CurStep.Status = StepStatus.Normal;
        }
        /// <summary>
        /// èŽ·å–è¡Œä¸ºå¼€å§‹çš„æç¤ºä¿¡æ¯
        /// </summary>
        /// <returns></returns>
        public Locale GetBeginMsg()
        {
            var msg = new Locale("MES.WorkAction.Weighing.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());
            action.LocaleMsg = GetBeginMsg();
            //如果返回成功则认为当前行为可以开始执行,否则返回失败
            CurStep.Message = Biz.L("称重开始");
            CurStep.Status = StepStatus.Normal;
            action.IsSuccessed = true;
            action.Data.ShortMsg = new("称重开始", ShortMessage.Types.Success);
            return action;
        }
        /// <summary>
        /// å·¥åºè¡Œä¸ºæäº¤æ•°æ®
        /// </summary>
        /// <returns></returns>
        public ApiAction<SubmitOutput> Submit(SubmitInput input)
        {
            var action = new ApiAction<SubmitOutput>(new SubmitOutput());
            action = SaveWeightInfo(input, action);
            //上料数据保存失败
            if (!action.IsSuccessed)
            {
                //如果行为设置为出错需要重置工序操作
                if (NodeAct.NEED_RESET == "Y")
                {
                    CurPosition.ResetNode();
                }
            }
            else
            {
                action = End(input);
            }
            return action;
        }
        public ApiAction<SubmitOutput> SaveWeightInfo(SubmitInput input, ApiAction<SubmitOutput> action)
        {
            try
            {
                var wInput = input?.Data?.JsonToObject<WeightInfo>();
                CurPkg.WEIGHT = wInput.Weight;
                CurPkg.WEIGHT_UNIT = wInput.Unit;
            }
            catch (System.Exception ex)
            {
                CurStep.Message = Biz.L("称重异常");
                CurStep.Status = StepStatus.Error;
                action.Data.ShortMsg = new("称重异常", ShortMessage.Types.Error);
                action.CatchExceptionWithLog(ex, $"称重行为:条码[{CurPosition.CurSN}]称重数据[{input?.Data?.ToString()}]保存异常");
                action.LocaleMsg = new("MES.WorkAction.Weighing.SaveWeightInfoException", CurPosition.CurSN, input?.Data.ToString());
            }
            return action;
        }
        /// <summary>
        /// ç»“束执行工序行为
        /// </summary>
        /// <returns></returns>
        public ApiAction<SubmitOutput> End(SubmitInput input)
        {
            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,
                    WIP_ID = wipSn.ID,
                    HIS_ID = CurPosition.CurWipSNHiss.First(q => q.SN == wipSn.SN).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_RESULT = "Y",
                    ELAPSED_TIME = CurStep.GetElapsedTime().TotalMilliseconds.ToInt64(),
                    TRACE_INFO = $"条码[{CurPosition.CurSN}]称重数据[{CurPkg.WEIGHT} {CurPkg.WEIGHT_UNIT}]保存成功",
                };
                wipActs.Add(wipAct);
            }
            //创建变量克隆对象用于传入DBSubmitAction中保存当前需要暂存的数据值
            var _wipActs = wipActs.Clone();
            var _CurPkg = CurPkg.Clone();
            //保存数据
            CurStep.DBSubmitAction = () =>
            {
                var db = CurPosition.GetCommitDB();
                db.Storageable(_wipActs, CurPosition.UserCode).ExecuteCommand();
                db.Storageable(_CurPkg, CurPosition.UserCode).ExecuteCommand();
            };
            IsFinished = true;
            CurStep.Message = Biz.L("称重完成");
            CurStep.Status = StepStatus.Finished;
            action.Data.ShortMsg = new("称重完成", ShortMessage.Types.Success);
            //action.LocaleMsg = new($"条码[{CurPosition.CurSN}]称重数据[{CurPkg.WEIGHT} {CurPkg.WEIGHT_UNIT}]保存成功");
            action.LocaleMsg = new("MES.WorkAction.Weighing.SaveSuccess", CurPosition.CurSN, CurPkg.WEIGHT, CurPkg.WEIGHT_UNIT);
            return action;
        }
        #endregion Functions
    }
}
Tiger.IBusiness.MES/WorkAction/IYadaWoReport.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,12 @@
using Newtonsoft.Json;
using Rhea.Common;
using System;
using Tiger.Model;
namespace Tiger.IBusiness.MES.WorkAction
{
    public interface IYadaWoReport : IWorkAction
    {
    }
}