From a592da60f0db0d4eb950a81a8530e965444be7b1 Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期三, 16 十月 2024 09:14:02 +0800
Subject: [PATCH] 工艺路线默认优化

---
 Tiger.Business/MES/Biz.Route.cs |   54 +++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 45 insertions(+), 9 deletions(-)

diff --git a/Tiger.Business/MES/Biz.Route.cs b/Tiger.Business/MES/Biz.Route.cs
index 8243cd7..2e6c16b 100644
--- a/Tiger.Business/MES/Biz.Route.cs
+++ b/Tiger.Business/MES/Biz.Route.cs
@@ -521,11 +521,10 @@
                             expableOper.And(x => x.ROT_ID == item.ID);
                         }
                     }
-                    if (!string.IsNullOrEmpty(input.prodCode))
-                    {
-                        expable.And(x => x.PROD_CODE == input.prodCode);
-                        expableOper.And(x => x.PROD_CODE == input.prodCode);
-                    }
+
+                    expable.And(x => x.PROD_CODE == input.prodCode && x.CUST_CODE == input.custCode);
+                    expableOper.And(x => x.PROD_CODE == input.prodCode && x.CUST_CODE == input.custCode);
+
                     var exp = expable.ToExpression();
                     var expOper = expableOper.ToExpression();
                     var db = Db;
@@ -645,18 +644,18 @@
                 var result = new ApiAction();
                 try
                 {
-                    var item = await Biz.Db.Queryable<BAS_ITEM>().ByAuth(input.options).Where(x=>x.ITEM_CODE == input.prodCode).FirstAsync();
+                    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: "";
+                    item.DEFAULT_ROUTE = input.isDefault ? input.rotCode : "";
                     var db = Db;
                     var dbTran = db.UseTran(() =>
                     {
-                        db.Updateable(item).UpdateColumns(q=> new { q.DEFAULT_ROUTE}).ExecuteCommand();
+                        db.Updateable(item).UpdateColumns(q => new { q.DEFAULT_ROUTE }).ExecuteCommand();
                     });
                     if (!dbTran.IsSuccess)
                     {
@@ -901,7 +900,7 @@
                         {
                             db.Insertable(routeData.acts).ExecuteCommand();
                         }
-                        if (operList.Count>0)
+                        if (operList.Count > 0)
                         {
                             db.Insertable(operList).ExecuteCommand();
                         }
@@ -954,6 +953,43 @@
                 return await Task.FromResult(result);
             }
             #endregion
+            /// <summary>
+            /// 鑾峰彇宸ヨ壓璺嚎鏍戝舰缁撴瀯
+            /// </summary>
+            /// <param name="prodCode"></param>
+            /// <param name="orgCode"></param>
+            /// <returns></returns>
+            public async Task<List<V_MES_ROUTE_PTREE>> GetRoutePTree(string prodCode, string orgCode)
+            {
+                var result = new List<V_MES_ROUTE_PTREE>();
+                try
+                {
+
+                    SugarParameter[] pars = Biz.Db.Ado.GetParameters(new { PROD_CODE = prodCode, ORG_CODE = orgCode });
+                    result = Biz.Db.Ado.UseStoredProcedure().SqlQuery<V_MES_ROUTE_PTREE>("SP_MES_GET_ROUTE_PTREE", pars);//杩斿洖List
+                    var item = await Db.Queryable<BAS_ITEM>().Where(q => q.ITEM_CODE == prodCode).FirstAsync();
+                    if (item != null && !item.DEFAULT_ROUTE.IsNullOrEmpty())
+                    {
+                        var pid = result.Where(q => q.code == $"DefaultRoute_{orgCode}_{prodCode}").Select(q => q.tid).FirstOrDefault();
+                        result.ForEach(d =>
+                        {
+                            if (d.pid == pid && d.code == item.DEFAULT_ROUTE)
+                            {
+                                d.isDefault = true;
+                            }
+                            else
+                            {
+                                d.isDefault = false;
+                            }
+                        });
+                    }
+                }
+                catch (Exception ex)
+                {
+                    Logger.Default.Error(ex, "淇濆瓨榛樿宸ヨ壓璺嚎鍒颁骇鍝佸紓甯�");
+                }
+                return result;
+            }
         } //endClass Route
     } //endClass Biz
 }

--
Gitblit v1.9.3