From 4a3788499301329d245b07bf2ba0213cf9fba540 Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期二, 13 八月 2024 21:03:29 +0800
Subject: [PATCH] 产品、工单绑定工艺路线更新

---
 Tiger.Business/MES/Biz.Route.cs |  126 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 126 insertions(+), 0 deletions(-)

diff --git a/Tiger.Business/MES/Biz.Route.cs b/Tiger.Business/MES/Biz.Route.cs
index cd069f1..c2da126 100644
--- a/Tiger.Business/MES/Biz.Route.cs
+++ b/Tiger.Business/MES/Biz.Route.cs
@@ -311,6 +311,57 @@
                 var result = new ApiAction();
                 try
                 {
+                    var nodeIds = routeData.nodes.Select(x => x.ID).ToList();
+                    var actIds = routeData.acts.Select(x => x.ID).ToList();
+                    //濡傛灉宸ュ簭鑺傜偣ID娌″湪浜у搧宸ュ簭閲屽氨鏂板
+                    List<MES_PROD_OPER> operList = new List<MES_PROD_OPER>();
+                    foreach (var node in routeData.nodes)
+                    {
+                        if (!Db.Queryable<MES_PROD_OPER>().Any(q => q.NODE_ID == node.ID && q.ROT_ID == routeData.route.ID))
+                        {
+                            operList.Add(new()
+                            {
+                                PROD_CODE = routeData.route.PROD_CODE,
+                                CUST_CODE = routeData.route.CUST_CODE,
+                                NODE_ID = node.ID,
+                                NODE_NAME = node.NODE_NAME,
+                                ROT_ID = node.ROT_ID,
+                                OPER_CODE = node.OPER_CODE,
+                                IS_ACTIVE = "Y",
+                                CAN_SKIP = "N",
+                                IS_CALC_FPY = "N",
+                                ALLOW_DFT_IN = "N",
+                                IS_INPUT = "N",
+                                IS_OUTPUT = "N",
+                            });
+                        }
+                    }
+                    //濡傛灉琛屼负鑺傜偣ID娌″湪浜у搧琛屼负閲屽氨鏂板
+                    List<MES_PROD_ACTION> actList = new List<MES_PROD_ACTION>();
+                    foreach (var act in routeData.acts)
+                    {
+                        if (!Db.Queryable<MES_PROD_ACTION>().Any(q => q.NODE_ID == act.ID && q.ROT_ID == routeData.route.ID))
+                        {
+                            actList.Add(new()
+                            {
+                                PROD_CODE = routeData.route.PROD_CODE,
+                                CUST_CODE = routeData.route.CUST_CODE,
+                                NODE_ID = act.NODE_ID,
+                                ACT_ID = act.ID,
+                                ACT_TYPE = act.ACT_TYPE,
+                                ROT_ID = act.ROT_ID,
+                                ACT_CODE = act.ACT_CODE,
+                                RULE_CODE = "",
+                                ITEM_CODE = "",
+                                TEST_CODE = "",
+                                SAPL_CODE = "",
+                                LABEL_CODE = "",
+                                PKG_CODE = "",
+                                IS_ACTIVE = "Y",
+                                SETUP_FINISH = "N",
+                            });
+                        }
+                    }
                     var db = Db;
                     var dbTran = db.UseTran(() =>
                     {
@@ -322,6 +373,9 @@
                             y.AsInsertable.ExecuteCommand();
                             y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
                         }
+                        db.Deleteable<MES_PROD_OPER>().Where(x => x.PROD_CODE == routeData.route.PROD_CODE && !SqlFunc.ContainsArray(nodeIds, x.NODE_ID)).ExecuteCommand();
+                        db.Deleteable<MES_PROD_ACTION>().Where(x => x.PROD_CODE == routeData.route.PROD_CODE && !SqlFunc.ContainsArray(nodeIds, x.NODE_ID)).ExecuteCommand();
+                        db.Deleteable<MES_PROD_ACTION>().Where(x => x.PROD_CODE == routeData.route.PROD_CODE && !SqlFunc.ContainsArray(actIds, x.ACT_ID)).ExecuteCommand();
                         db.Deleteable<MES_ROUTE_NODE>(false).Where(x => x.ROT_ID == routeData.route.ID).ExecuteCommand();
                         db.Deleteable<MES_ROUTE_EDGE>(false).Where(x => x.ROT_ID == routeData.route.ID).ExecuteCommand();
                         db.Deleteable<MES_ROUTE_NODE_ACT>(false).Where(x => x.ROT_ID == routeData.route.ID).ExecuteCommand();
@@ -336,6 +390,14 @@
                         if (routeData.acts != null)
                         {
                             db.Insertable(routeData.acts).ExecuteCommand();
+                        }
+                        if (operList.Count > 0)
+                        {
+                            db.Insertable(operList).ExecuteCommand();
+                        }
+                        if (actList.Count > 0)
+                        {
+                            db.Insertable(actList).ExecuteCommand();
                         }
                     });
                     if (!dbTran.IsSuccess)
@@ -699,6 +761,59 @@
                 var result = new ApiAction();
                 try
                 {
+                    var nodeIds = routeData.nodes.Select(x => x.ID).ToList();
+                    var actIds = routeData.acts.Select(x => x.ID).ToList();
+                    //濡傛灉宸ュ簭鑺傜偣ID娌″湪宸ュ崟宸ュ簭閲屽氨鏂板
+                    List<MES_WO_OPER> operList = new List<MES_WO_OPER>();
+                    foreach (var node in routeData.nodes)
+                    {
+                        if (!Db.Queryable<MES_WO_OPER>().Any(q => q.NODE_ID == node.ID))
+                        {
+                            operList.Add(new()
+                            {
+                                WORK_ORDER = node.WORK_ORDER,
+                                PROD_CODE = node.PROD_CODE,
+                                CUST_CODE = node.CUST_CODE,
+                                NODE_ID = node.ID,
+                                NODE_NAME = node.NODE_NAME,
+                                ROT_ID = node.ROT_ID,
+                                OPER_CODE = node.OPER_CODE,
+                                IS_ACTIVE = "Y",
+                                CAN_SKIP = "N",
+                                IS_CALC_FPY = "N",
+                                ALLOW_DFT_IN = "N",
+                                IS_INPUT = "N",
+                                IS_OUTPUT = "N",
+                            });
+                        }
+                    }
+                    //濡傛灉琛屼负鑺傜偣ID娌″湪宸ュ崟琛屼负閲屽氨鏂板
+                    List<MES_WO_ACTION> actList = new List<MES_WO_ACTION>();
+                    foreach (var act in routeData.acts)
+                    {
+                        if (!Db.Queryable<MES_WO_ACTION>().Any(q => q.NODE_ID == act.ID))
+                        {
+                            actList.Add(new()
+                            {
+                                WORK_ORDER = act.WORK_ORDER,
+                                PROD_CODE = act.PROD_CODE,
+                                CUST_CODE = act.CUST_CODE,
+                                NODE_ID = act.NODE_ID,
+                                ACT_ID = act.ID,
+                                ACT_TYPE = act.ACT_TYPE,
+                                ROT_ID = act.ROT_ID,
+                                ACT_CODE = act.ACT_CODE,
+                                RULE_CODE = "",
+                                ITEM_CODE = "",
+                                TEST_CODE = "",
+                                SAPL_CODE = "",
+                                LABEL_CODE = "",
+                                PKG_CODE = "",
+                                IS_ACTIVE = "Y",
+                                SETUP_FINISH = "N",
+                            });
+                        }
+                    }
                     var db = Db;
                     var dbTran = db.UseTran(() =>
                     {
@@ -710,6 +825,9 @@
                         //    y.AsInsertable.ExecuteCommand();
                         //    y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
                         //}
+                        db.Deleteable<MES_WO_OPER>().Where(x => x.WORK_ORDER == routeData.route.WORK_ORDER && !SqlFunc.ContainsArray(nodeIds, x.NODE_ID)).ExecuteCommand();
+                        db.Deleteable<MES_WO_ACTION>().Where(x => x.WORK_ORDER == routeData.route.WORK_ORDER && !SqlFunc.ContainsArray(nodeIds, x.NODE_ID)).ExecuteCommand();
+                        db.Deleteable<MES_WO_ACTION>().Where(x => x.WORK_ORDER == routeData.route.WORK_ORDER && !SqlFunc.ContainsArray(actIds, x.ACT_ID)).ExecuteCommand();
                         db.Deleteable<MES_WO_NODE>(false).Where(x => x.WORK_ORDER == routeData.route.WORK_ORDER).ExecuteCommand();
                         db.Deleteable<MES_WO_EDGE>(false).Where(x => x.WORK_ORDER == routeData.route.WORK_ORDER).ExecuteCommand();
                         db.Deleteable<MES_WO_NODE_ACT>(false).Where(x => x.WORK_ORDER == routeData.route.WORK_ORDER).ExecuteCommand();
@@ -725,6 +843,14 @@
                         {
                             db.Insertable(routeData.acts).ExecuteCommand();
                         }
+                        if (operList.Count>0)
+                        {
+                            db.Insertable(operList).ExecuteCommand();
+                        }
+                        if (actList.Count > 0)
+                        {
+                            db.Insertable(actList).ExecuteCommand();
+                        }
                     });
                     if (!dbTran.IsSuccess)
                     {

--
Gitblit v1.9.3