From b4bd82fdbace031a81ab40963c8344d5eaa4a772 Mon Sep 17 00:00:00 2001
From: Rodney Chen <rodney.chen@hotmail.com>
Date: 星期三, 21 八月 2024 17:19:44 +0800
Subject: [PATCH] 增加雅达三码合一行为,用于厂内条码绑定并打印客户条码

---
 Tiger.Business.MES/WorkAction/ThreeInOne.cs   |  251 ++++++++++++++++++++++++++++++++++++++++++++++++++
 Tiger.IBusiness/MES/WorkAction/IThreeInOne.cs |   12 ++
 Tiger.Api/Language.db                         |    0 
 Tiger.Business.MES/Transaction/PackingNode.cs |    2 
 Tiger.Business.MES/Transaction/Position.cs    |   13 +
 Tiger.Business/MES/Biz.WorkBatch.cs           |    2 
 6 files changed, 274 insertions(+), 6 deletions(-)

diff --git a/Tiger.Api/Language.db b/Tiger.Api/Language.db
index a3fef0a..b309d15 100644
--- a/Tiger.Api/Language.db
+++ b/Tiger.Api/Language.db
Binary files differ
diff --git a/Tiger.Business.MES/Transaction/PackingNode.cs b/Tiger.Business.MES/Transaction/PackingNode.cs
index 387b079..ec5a96b 100644
--- a/Tiger.Business.MES/Transaction/PackingNode.cs
+++ b/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;
                                 }
diff --git a/Tiger.Business.MES/Transaction/Position.cs b/Tiger.Business.MES/Transaction/Position.cs
index d4b8184..a932e37 100644
--- a/Tiger.Business.MES/Transaction/Position.cs
+++ b/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)
diff --git a/Tiger.Business.MES/WorkAction/ThreeInOne.cs b/Tiger.Business.MES/WorkAction/ThreeInOne.cs
new file mode 100644
index 0000000..c0d6e5c
--- /dev/null
+++ b/Tiger.Business.MES/WorkAction/ThreeInOne.cs
@@ -0,0 +1,251 @@
+锘縰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 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
+    }
+}
diff --git a/Tiger.Business/MES/Biz.WorkBatch.cs b/Tiger.Business/MES/Biz.WorkBatch.cs
index ab6068f..e22c66b 100644
--- a/Tiger.Business/MES/Biz.WorkBatch.cs
+++ b/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;
diff --git a/Tiger.IBusiness/MES/WorkAction/IThreeInOne.cs b/Tiger.IBusiness/MES/WorkAction/IThreeInOne.cs
new file mode 100644
index 0000000..ceb7137
--- /dev/null
+++ b/Tiger.IBusiness/MES/WorkAction/IThreeInOne.cs
@@ -0,0 +1,12 @@
+锘縰sing Newtonsoft.Json;
+using Rhea.Common;
+using System;
+using Tiger.Model;
+
+namespace Tiger.IBusiness.MES.WorkAction
+{
+    public interface IThreeInOne : IWorkAction
+    {
+
+    }
+}

--
Gitblit v1.9.3