From 925079c1cd09cbc5bc2ec6f66d07875e0f982716 Mon Sep 17 00:00:00 2001
From: Rodney Chen <rodney.chen@hotmail.com>
Date: 星期四, 10 十月 2024 09:43:18 +0800
Subject: [PATCH] 优化提示

---
 Tiger.Business/MES/Biz.Route.cs |   88 +++++++++++++++++++++++++++++++++++++-------
 1 files changed, 74 insertions(+), 14 deletions(-)

diff --git a/Tiger.Business/MES/Biz.Route.cs b/Tiger.Business/MES/Biz.Route.cs
index fdf3e3f..8243cd7 100644
--- a/Tiger.Business/MES/Biz.Route.cs
+++ b/Tiger.Business/MES/Biz.Route.cs
@@ -273,20 +273,26 @@
                 try
                 {
                     var _route = Db.Queryable<MES_ROUTE>().Where(x => x.ROT_CODE == route.ROT_CODE).First();
-                    if (_route != null && Db.Queryable<MES_ROUTE_NODE>().Where(x => x.ROT_ID == _route.ID).Any())
+                    //if (_route != null && Db.Queryable<MES_ROUTE_NODE>().Where(x => x.ROT_ID == _route.ID).Any())
+                    //{
+                    //    result.IsSuccessed = false;
+                    //    result.LocaleMsg = new($"宸ヨ壓璺嚎宸茬粡鏈夎璁¤褰曪紝涓嶈兘淇濆瓨锛�");
+                    //    return result;
+                    //}
+                    if (_route != null && Db.Queryable<MES_PROD_OPER>().Where(x => x.ROT_ID == _route.ID).Any())
                     {
                         result.IsSuccessed = false;
-                        result.LocaleMsg = new($"宸ヨ壓璺嚎宸茬粡鏈夎璁¤褰曪紝涓嶈兘淇濆瓨锛�");
+                        result.LocaleMsg = new($"宸ヨ壓璺嚎宸茬粡鏈夌粦瀹氳褰曪紝涓嶈兘淇濆瓨锛�");
                         return result;
                     }
                     var db = Db;
                     var dbTran = db.UseTran(() =>
                     {
                         var y = db.Storageable(route)
-                           .WhereColumns(t => new { t.ROT_CODE, t.GHOST_ROW })
+                           //.WhereColumns(t => new { t.ROT_CODE, t.GHOST_ROW })
                            .ToStorage();
                         y.AsInsertable.ExecuteCommand();
-                        y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
+                        y.AsUpdateable.ExecuteCommand();
                     });
                     if (!dbTran.IsSuccess)
                     {
@@ -333,6 +339,9 @@
                                 ALLOW_DFT_IN = "N",
                                 IS_INPUT = "N",
                                 IS_OUTPUT = "N",
+                                AUTH_ORG = node.AUTH_ORG,
+                                AUTH_PROD = node.AUTH_PROD,
+                                AUTH_WH = node.AUTH_WH,
                             });
                         }
                     }
@@ -340,7 +349,7 @@
                     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))
+                        if (!Db.Queryable<MES_PROD_ACTION>().Any(q => q.ACT_ID == act.ID && q.ROT_ID == routeData.route.ID))
                         {
                             actList.Add(new()
                             {
@@ -359,6 +368,9 @@
                                 PKG_CODE = "",
                                 IS_ACTIVE = "Y",
                                 SETUP_FINISH = "N",
+                                AUTH_ORG = act.AUTH_ORG,
+                                AUTH_PROD = act.AUTH_PROD,
+                                AUTH_WH = act.AUTH_WH,
                             });
                         }
                     }
@@ -373,8 +385,11 @@
                             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(actIds, x.ACT_ID)).ExecuteCommand();
+                        if (!routeData.route.PROD_CODE.IsNullOrEmpty())
+                        {
+                            db.Deleteable<MES_PROD_OPER>().Where(x => x.ROT_ID == routeData.route.ID && x.PROD_CODE == routeData.route.PROD_CODE && !SqlFunc.ContainsArray(nodeIds, x.NODE_ID)).ExecuteCommand();
+                            db.Deleteable<MES_PROD_ACTION>().Where(x => x.ROT_ID == routeData.route.ID && 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();
@@ -390,13 +405,16 @@
                         {
                             db.Insertable(routeData.acts).ExecuteCommand();
                         }
-                        if (operList.Count > 0)
+                        if (!routeData.route.PROD_CODE.IsNullOrEmpty())
                         {
-                            db.Insertable(operList).ExecuteCommand();
-                        }
-                        if (actList.Count > 0)
-                        {
-                            db.Insertable(actList).ExecuteCommand();
+                            if (operList.Count > 0)
+                            {
+                                db.Insertable(operList).ExecuteCommand();
+                            }
+                            if (actList.Count > 0)
+                            {
+                                db.Insertable(actList).ExecuteCommand();
+                            }
                         }
                     });
                     if (!dbTran.IsSuccess)
@@ -617,6 +635,42 @@
                 return result;
             }
 
+            /// <summary>
+            /// 淇濆瓨榛樿宸ヨ壓璺嚎鍒颁骇鍝�
+            /// </summary>
+            /// <param name="input"></param>
+            /// <returns></returns>
+            public async Task<ApiAction> SetDefaultRoute(ProdRotInput input)
+            {
+                var result = new ApiAction();
+                try
+                {
+                    var item = await Biz.Db.Queryable<BAS_ITEM>().ByAuth(input.options).Where(x=>x.ITEM_CODE == input.prodCode).FirstAsync();
+                    if (item == null)
+                    {
+                        result.IsSuccessed = false;
+                        result.LocaleMsg = new($"浜у搧[{input.prodCode}]涓嶅瓨鍦紒");
+                        return result;
+                    }
+                    item.DEFAULT_ROUTE = input.isDefault? input.rotCode: "";
+                    var db = Db;
+                    var dbTran = db.UseTran(() =>
+                    {
+                        db.Updateable(item).UpdateColumns(q=> new { q.DEFAULT_ROUTE}).ExecuteCommand();
+                    });
+                    if (!dbTran.IsSuccess)
+                    {
+                        result.IsSuccessed = false;
+                        result.LocaleMsg = new($"淇濆瓨榛樿宸ヨ壓璺嚎鍒颁骇鍝佸紓甯�");
+                    }
+                }
+                catch (Exception ex)
+                {
+                    result.CatchExceptionWithLog(ex, "淇濆瓨榛樿宸ヨ壓璺嚎鍒颁骇鍝佸紓甯�");
+                }
+                return result;
+            }
+
             #region 宸ュ崟宸ヨ壓璺嚎鐩稿叧
 
 
@@ -783,6 +837,9 @@
                                 ALLOW_DFT_IN = "N",
                                 IS_INPUT = "N",
                                 IS_OUTPUT = "N",
+                                AUTH_ORG = node.AUTH_ORG,
+                                AUTH_PROD = node.AUTH_PROD,
+                                AUTH_WH = node.AUTH_WH,
                             });
                         }
                     }
@@ -790,7 +847,7 @@
                     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))
+                        if (!Db.Queryable<MES_WO_ACTION>().Any(q => q.ACT_ID == act.ID))
                         {
                             actList.Add(new()
                             {
@@ -810,6 +867,9 @@
                                 PKG_CODE = "",
                                 IS_ACTIVE = "Y",
                                 SETUP_FINISH = "N",
+                                AUTH_ORG = act.AUTH_ORG,
+                                AUTH_PROD = act.AUTH_PROD,
+                                AUTH_WH = act.AUTH_WH,
                             });
                         }
                     }

--
Gitblit v1.9.3