From 77771c41aa9f7f1f242c79b95fc2a8c82bd7c6c8 Mon Sep 17 00:00:00 2001
From: Rodney Chen <rodney.chen@hotmail.com>
Date: 星期三, 01 一月 2025 15:59:31 +0800
Subject: [PATCH] 增加更新条码数量行为

---
 Tiger.Business.MES/WorkAction/InputQty.cs                        |  265 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 Tiger.Api/Language.db                                            |    0 
 Tiger.Business.MES/WorkAction/Weighing.cs                        |    2 
 Tiger.Model.Net/Entitys/MES/MES_WO_NODE_ACT.cs                   |    2 
 Tiger.Model.Net/Entitys/MES/ParameterEntity/PositionParameter.cs |    8 +
 Tiger.IBusiness.MES/WorkAction/IInputQty.cs                      |   12 ++
 6 files changed, 286 insertions(+), 3 deletions(-)

diff --git a/Tiger.Api/Language.db b/Tiger.Api/Language.db
index 6d79cc3..31e59fc 100644
--- a/Tiger.Api/Language.db
+++ b/Tiger.Api/Language.db
Binary files differ
diff --git a/Tiger.Business.MES/WorkAction/InputQty.cs b/Tiger.Business.MES/WorkAction/InputQty.cs
new file mode 100644
index 0000000..0cb3940
--- /dev/null
+++ b/Tiger.Business.MES/WorkAction/InputQty.cs
@@ -0,0 +1,265 @@
+锘縰sing 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 InputQty : IInputQty
+    {
+        #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; }
+        public MES_WO_NODE_ACT NodeAct { get; set; }
+        public MES_WO_ACTION Setting { get; set; }
+        #endregion
+        public double NewQty { get; set; }
+        public double NewWoInputQty { get; set; }
+        public double NewBatchInputQty { 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 鍥哄畾鍐欐硶锛岀粰榛樿鍙橀噺璧嬪��
+            MainDB = position.MainDB;
+            CurStep = curStep;
+            CurPosition = position;
+            NodeAct = nodeAct;
+            Setting = setting;
+            #endregion
+
+            CurStep.Message = Biz.L("绛夊緟杈撳叆鏉$爜鏁伴噺");
+            CurStep.Status = StepStatus.Normal;
+        }
+
+        /// <summary>
+        /// 鑾峰彇琛屼负寮�濮嬬殑鎻愮ず淇℃伅
+        /// </summary>
+        /// <returns></returns>
+        public Locale GetBeginMsg()
+        {
+            //var msg = new Locale($"璇疯緭鍏ユ潯鐮乕{0}]鐨勬暟閲�");
+            var msg = new Locale("MES.WorkAction.InputQty.BeginMsg", 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 = SaveSnQty(input, action);
+            //涓婃枡鏁版嵁淇濆瓨澶辫触
+            if (!action.IsSuccessed)
+            {
+                //濡傛灉琛屼负璁剧疆涓哄嚭閿欓渶瑕侀噸缃伐搴忔搷浣�
+                if (NodeAct.NEED_RESET == "Y")
+                {
+                    CurPosition.ResetNode();
+                }
+            }
+            else
+            {
+                action = End(input);
+            }
+            return action;
+        }
+
+        public ApiAction<SubmitOutput> SaveSnQty(SubmitInput input, ApiAction<SubmitOutput> action)
+        {
+            try
+            {
+                NewQty = input?.Data?.ToInt32() ?? 0;
+                if (NewQty > 0)
+                {
+                    var newInput = CurPosition.CurWipSNs.Sum(q => NewQty);
+                    var woInput = CurPosition.WorkBatch.WoSNs.Where(q => q.WORK_ORDER == CurPosition.WorkBatch.WO.ORDER_NO && BIZ_MES_WO_SN.STATUSs.NotInput.GetValue() < q.STATUS && q.STATUS <= BIZ_MES_WO_SN.STATUSs.Finished.GetValue())
+                                                                                           .Where(q => !CurPosition.CurWipSNs.Any(sn => sn.ID == q.WIP_ID)).DistinctBy(q => q.WIP_ID).Sum(q => q.QTY);
+                    var batchInput = CurPosition.WorkBatch.WoSNs.Where(q => q.BATCH_NO == CurPosition.WorkBatch.Batch.BATCH_NO && BIZ_MES_WO_SN.STATUSs.NotInput.GetValue() < q.STATUS && q.STATUS <= BIZ_MES_WO_SN.STATUSs.Finished.GetValue())
+                                                                                               .Where(q => !CurPosition.CurWipSNs.Any(sn => sn.ID == q.WIP_ID)).DistinctBy(q => q.WIP_ID).Sum(q => q.QTY);
+                    
+                    //宸ュ崟鎵规鎶曞叆鏁伴噺鍑忓幓鎶ュ簾鏁伴噺濡傛灉澶т簬绛変簬璁″垝鏁伴噺锛屽垯涓嶅厑璁哥敓浜�
+                    if ((NewBatchInputQty = batchInput + newInput) > CurPosition.WorkBatch.Batch.PLAN_QTY)
+                    {
+                        CurStep.Message = Biz.L("閲嶆柊杈撳叆鏁伴噺");
+                        CurStep.Status = StepStatus.Error;
+                        action.IsSuccessed = false;
+                        action.Data.ShortMsg = new("閲嶆柊杈撳叆鏁伴噺", ShortMessage.Types.Error);
+                        //action.LocaleMsg = new($"鏉$爜鏇存柊鏁伴噺[{0}]鍚庯紝宸ュ崟鎵规[{1}]鎶曞叆鏁伴噺[{2}]瓒呭嚭璁″垝鏁伴噺[{3}]锛岃閲嶆柊杈撳叆姝g‘鐨勬暟閲�");
+                        action.LocaleMsg = new("MES.WorkAction.InputQty.BatchInputEnough", input.Data, CurPosition.WorkBatch.Batch.BATCH_NO, batchInput + newInput, CurPosition.WorkBatch.Batch.PLAN_QTY);
+                    }
+                    //宸ュ崟鎶曞叆鏁伴噺鍑忓幓鎶ュ簾鏁伴噺濡傛灉澶т簬绛変簬璁″垝鏁伴噺锛屽垯涓嶅厑璁哥敓浜�
+                    else if ((NewWoInputQty = woInput + newInput) > CurPosition.WorkBatch.WO.PLAN_QTY)
+                    {
+                        CurStep.Message = Biz.L("閲嶆柊杈撳叆鏁伴噺");
+                        CurStep.Status = StepStatus.Error;
+                        action.IsSuccessed = false;
+                        action.Data.ShortMsg = new("閲嶆柊杈撳叆鏁伴噺", ShortMessage.Types.Error);
+                        //action.LocaleMsg = new($"鏉$爜鏇存柊鏁伴噺[{0}]鍚庯紝宸ュ崟[{1}]鎶曞叆鏁伴噺[{2}]瓒呭嚭璁″垝鏁伴噺[{3}]锛岃閲嶆柊杈撳叆姝g‘鐨勬暟閲�");
+                        action.LocaleMsg = new("MES.WorkAction.InputQty.WoInputEnough", input.Data, CurPosition.WorkBatch.WO.ORDER_NO, woInput + newInput, CurPosition.WorkBatch.WO.PLAN_QTY);
+                    }
+                    else
+                    {
+                        action = End(input);
+                    }
+                }
+                else
+                {
+                    CurStep.Message = Biz.L("閲嶆柊杈撳叆鏁伴噺");
+                    CurStep.Status = StepStatus.Error;
+                    action.IsSuccessed = false;
+                    action.Data.ShortMsg = new("閲嶆柊杈撳叆鏁伴噺", ShortMessage.Types.Error);
+                    //action.LocaleMsg = new($"鏁伴噺[{0}]蹇呴』鏄ぇ浜�0鐨勬暣鏁帮紝璇烽噸鏂拌緭鍏ユ纭殑鏁伴噺");
+                    action.LocaleMsg = new("MES.WorkAction.InputQty.QtyError", input.Data);
+
+                }
+            }
+            catch (System.Exception ex)
+            {
+                CurStep.Message = Biz.L("鏇存柊鏁伴噺寮傚父");
+                CurStep.Status = StepStatus.Error;
+                action.Data.ShortMsg = new("鏇存柊鏁伴噺寮傚父", ShortMessage.Types.Error);
+                //action.CatchExceptionWithLog(ex, $"鏇存柊鏁伴噺琛屼负锛氭洿鏂版潯鐮乕{0}]鏁伴噺[{1}]寮傚父");
+                action.LocaleMsg = new("MES.WorkAction.InputQty.SaveQtyException", 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}]鏇存柊鏁伴噺涓篬{NewQty}]淇濆瓨鎴愬姛",
+                };
+                wipActs.Add(wipAct);
+            }
+
+            //鍒涘缓鍙橀噺鍏嬮殕瀵硅薄鐢ㄤ簬浼犲叆DBSubmitAction涓繚瀛樺綋鍓嶉渶瑕佹殏瀛樼殑鏁版嵁鍊�
+            var _wipActs = wipActs.Clone();
+            var wo = CurPosition.WorkBatch.WO.ORDER_NO;
+            var batch = CurPosition.WorkBatch.Batch.BATCH_NO;
+            var nodeID = NodeAct.NODE_ID;
+            var _wipIDs = CurPosition.CurWipSNs.Select(q => q.ID).ToList().Clone();
+            //淇濆瓨鏁版嵁
+            CurStep.DBSubmitAction = () =>
+            {
+                var db = CurPosition.GetCommitDB();
+                //鍦ㄥ埗鍝佷俊鎭〃
+                db.Updateable<MES_WIP_DATA>(CurPosition.UserCode)
+                    .SetColumns(q => q.QTY == NewQty)
+                    .Where(q => q.WORK_ORDER == wo && _wipIDs.Contains(q.ID))
+                    .ExecuteCommand();
+                //鐢熶骇杩囩▼璁板綍
+                db.Updateable<MES_WIP_HIS>(CurPosition.UserCode)
+                    .SetColumns(q => q.QTY == NewQty)
+                    .Where(q => q.WORK_ORDER == wo && q.NODE_ID == nodeID && _wipIDs.Contains(q.WIP_ID))
+                    .ExecuteCommand();
+                //宸ュ崟琛�
+                db.Updateable<BIZ_MES_WO>(CurPosition.UserCode)
+                    .SetColumns(q => q.INPUT_QTY == NewWoInputQty)
+                    .Where(q => q.ORDER_NO == wo)
+                    .ExecuteCommand();
+                //宸ュ崟鎵规琛�
+                db.Updateable<BIZ_MES_WO_BATCH>(CurPosition.UserCode)
+                    .SetColumns(q => q.INPUT_QTY == NewBatchInputQty)
+                    .Where(q => q.BATCH_NO == batch)
+                    .ExecuteCommand();
+                //宸ュ崟鏉$爜鏄庣粏琛�
+                db.Updateable<BIZ_MES_WO_SN>(CurPosition.UserCode)
+                    .SetColumns(q => q.QTY == NewQty)
+                    .Where(q => q.WORK_ORDER == wo && _wipIDs.Contains(q.WIP_ID))
+                    .ExecuteCommand();
+                db.Storageable(_wipActs, CurPosition.UserCode).ExecuteCommand();
+            };
+
+            IsFinished = true;
+            CurStep.Message = Biz.L("鏇存柊鏁伴噺鎴愬姛");
+            CurStep.Status = StepStatus.Finished;
+            action.Data.ShortMsg = new("鏇存柊鏁伴噺鎴愬姛", ShortMessage.Types.Success);
+            //action.LocaleMsg = new($"鏉$爜[{0}]鏇存柊鏁伴噺涓篬{1}]淇濆瓨鎴愬姛");
+            action.LocaleMsg = new("MES.WorkAction.InputQty.SaveSuccess", CurPosition.CurSN, NewQty);
+            return action;
+        }
+
+        #endregion Functions
+    }
+}
diff --git a/Tiger.Business.MES/WorkAction/Weighing.cs b/Tiger.Business.MES/WorkAction/Weighing.cs
index 354b4bb..e159648 100644
--- a/Tiger.Business.MES/WorkAction/Weighing.cs
+++ b/Tiger.Business.MES/WorkAction/Weighing.cs
@@ -134,7 +134,7 @@
                 CurStep.Message = Biz.L("绉伴噸寮傚父");
                 CurStep.Status = StepStatus.Error;
                 action.Data.ShortMsg = new("绉伴噸寮傚父", ShortMessage.Types.Error);
-                action.CatchExceptionWithLog(ex, $"绉伴噸琛屼负锛氭潯鐮乕{CurPosition.CurSN}]绉伴噸鏁版嵁[{input?.Data?.ToString()}]淇濆瓨寮傚父");
+                //action.CatchExceptionWithLog(ex, $"绉伴噸琛屼负锛氭潯鐮乕{0}]绉伴噸鏁版嵁[{1}]淇濆瓨寮傚父");
                 action.LocaleMsg = new("MES.WorkAction.Weighing.SaveWeightInfoException", CurPosition.CurSN, input?.Data.ToString());
             }
             return action;
diff --git a/Tiger.IBusiness.MES/WorkAction/IInputQty.cs b/Tiger.IBusiness.MES/WorkAction/IInputQty.cs
new file mode 100644
index 0000000..604c95a
--- /dev/null
+++ b/Tiger.IBusiness.MES/WorkAction/IInputQty.cs
@@ -0,0 +1,12 @@
+锘縰sing Newtonsoft.Json;
+using Rhea.Common;
+using System;
+using Tiger.Model;
+
+namespace Tiger.IBusiness.MES.WorkAction
+{
+    public interface IInputQty : IWorkAction
+    {
+
+    }
+}
diff --git a/Tiger.Model.Net/Entitys/MES/MES_WO_NODE_ACT.cs b/Tiger.Model.Net/Entitys/MES/MES_WO_NODE_ACT.cs
index 8f7b557..504bcc9 100644
--- a/Tiger.Model.Net/Entitys/MES/MES_WO_NODE_ACT.cs
+++ b/Tiger.Model.Net/Entitys/MES/MES_WO_NODE_ACT.cs
@@ -161,6 +161,8 @@
 		*/
         [Navigate(NavigateType.OneToOne, nameof(ACT_CODE), nameof(MES_CUSTOM_ACT.ACT_CODE), "GHOST_ROW = 0")]//涓�瀵逛竴 ClassAId鏄疢ES_WO_NODE_ACT绫婚噷闈㈢殑澶栭敭ID瀛楁
         public MES_CUSTOM_ACT Definition { get; set; } //娉ㄦ剰绂佹鎵嬪姩璧嬪�硷紝鍙兘鏄痭ull
+        [Navigate(NavigateType.OneToMany, nameof(MES_WO_ACT_VAR.ACT_ID), nameof(ID), "GHOST_ROW = 0")]//ClassA琛ㄤ腑鐨凪ES_WO_NODE_ACTId
+        public List<MES_WO_ACT_VAR> Variables { get; set; } //娉ㄦ剰绂佹鎵嬪姩璧嬪�硷紝鍙兘鏄痭ull
         #endregion
 
         #region 鏋氫妇鍙橀噺
diff --git a/Tiger.Model.Net/Entitys/MES/ParameterEntity/PositionParameter.cs b/Tiger.Model.Net/Entitys/MES/ParameterEntity/PositionParameter.cs
index d74c353..0d32bf9 100644
--- a/Tiger.Model.Net/Entitys/MES/ParameterEntity/PositionParameter.cs
+++ b/Tiger.Model.Net/Entitys/MES/ParameterEntity/PositionParameter.cs
@@ -46,9 +46,9 @@
         /// </summary>
         public string DFT_CODE { get; set; }
         /// <summary>
-        /// 褰撳墠鎿嶄綔闇�瑕佹彁浜ょ殑閫夐」
+        /// 褰撳墠鎿嶄綔鐨勮涓虹殑鍙橀噺瀛楀吀锛屽鏋滄槸涓嶆槸琛屼负锛屽惁鍒欑暀绌�
         /// </summary>
-        public Dictionary<string, string> Options { get; set; } = new Dictionary<string, string>();
+        public Dictionary<string, string> ActionDic { get; set; } = new Dictionary<string, string>();
         /// <summary>
         /// 褰撳墠鎿嶄綔闇�瑕佹彁浜ょ殑鏁版嵁
         /// </summary>
@@ -74,6 +74,10 @@
         /// </summary>
         public string ActionType { get; set; }
         /// <summary>
+        /// 褰撳墠鎿嶄綔鐨勮涓虹殑鍙橀噺瀛楀吀锛屽鏋滄槸涓嶆槸琛屼负锛屽惁鍒欑暀绌�
+        /// </summary>
+        public Dictionary<string, string> ActionDic { get; set; }
+        /// <summary>
         /// 涓嬩竴涓搷浣滅殑宸ユID
         /// </summary>
         public string NextStepID { get; set; }

--
Gitblit v1.9.3