From 10f3247a8320da7e1e519c20b8014c65958301c2 Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期三, 31 七月 2024 23:17:05 +0800
Subject: [PATCH] 模板变量维护更新

---
 Tiger.Api/Controllers/Base/BaseController.cs              |    2 
 Tiger.Model.Net/Entitys/BAS/BAS_LABEL_VAR_WO.cs           |    5 ++
 Tiger.IBusiness/MES/LabelTemplate/ILabelTemplate.cs       |    1 
 Tiger.Api/Controllers/MES/MESController.BAS_LABEL_TEMP.cs |   23 +++++++++++
 Tiger.Business.MES/LabelTemplate/BAS_LABEL_TEMP.cs        |   63 +++++++++++++++++++++++++++----
 5 files changed, 85 insertions(+), 9 deletions(-)

diff --git a/Tiger.Api/Controllers/Base/BaseController.cs b/Tiger.Api/Controllers/Base/BaseController.cs
index c185bcb..7783881 100644
--- a/Tiger.Api/Controllers/Base/BaseController.cs
+++ b/Tiger.Api/Controllers/Base/BaseController.cs
@@ -562,7 +562,7 @@
         {
             if (file == null || file.Length == 0)
                 return BadRequest("No file uploaded.");
-            var folderName = entityName == "BAS_LABEL_TEMP" ? "upload/Template": "upload";
+            var folderName = entityName == "BAS_LABEL_TEMP" || entityName == "BAS_LABEL_VAR" ? "upload/Template": "upload";
             var path = Path.Combine($@"{BizConfig.Configuration["UploadAddress"]}", folderName, file.FileName);
 
             using (var stream = new FileStream(path, FileMode.Create))
diff --git a/Tiger.Api/Controllers/MES/MESController.BAS_LABEL_TEMP.cs b/Tiger.Api/Controllers/MES/MESController.BAS_LABEL_TEMP.cs
index d99018b..4e776dc 100644
--- a/Tiger.Api/Controllers/MES/MESController.BAS_LABEL_TEMP.cs
+++ b/Tiger.Api/Controllers/MES/MESController.BAS_LABEL_TEMP.cs
@@ -1,4 +1,5 @@
 锘縰sing Microsoft.AspNetCore.Mvc;
+using Newtonsoft.Json;
 using Rhea.Common;
 using System.Threading.Tasks;
 using Tiger.IBusiness;
@@ -32,6 +33,28 @@
         }
 
         /// <summary>
+        /// 淇濆瓨鏍囩妯℃澘鍙橀噺
+        /// </summary>
+        /// <param name="action"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [Route("api/[controller]/[action]")]
+        public async Task<IActionResult> SaveLabelTemplateVar([FromBody] ApiAction<BasLabelTempInput> action)
+        {
+            ApiAction response = new();
+            try
+            {
+
+                response = response.GetResponse(await DI.Resolve<ILabelTemplate>().SaveLabelTemplateVar(action.Data));
+            }
+            catch (System.Exception ex)
+            {
+                response = response.GetResponse().CatchExceptionWithLog(ex);
+            }
+            return Ok(response);
+        }
+
+        /// <summary>
         /// 鍒犻櫎鏍囩妯℃澘
         /// </summary>
         /// <param name="action"></param>
diff --git a/Tiger.Business.MES/LabelTemplate/BAS_LABEL_TEMP.cs b/Tiger.Business.MES/LabelTemplate/BAS_LABEL_TEMP.cs
index 438184f..919c5bc 100644
--- a/Tiger.Business.MES/LabelTemplate/BAS_LABEL_TEMP.cs
+++ b/Tiger.Business.MES/LabelTemplate/BAS_LABEL_TEMP.cs
@@ -47,6 +47,8 @@
                 var dbTran = db.UseTran(() =>
                 {
                     db.Deleteable<BAS_LABEL_TEMP>().Where(x => x.ID == Id).ExecuteCommand();
+                    db.Deleteable<BAS_LABEL_VAR>().Where(x => x.LABEL_ID == Id).ExecuteCommand();
+                    db.Deleteable<BAS_LABEL_VAR_WO>().Where(x => x.LABEL_ID == Id).ExecuteCommand();
                 });
                 if (!dbTran.IsSuccess)
                 {
@@ -74,11 +76,12 @@
             {
                 BAS_LABEL_TEMP? prodTemp = null;
                 BAS_LABEL_TEMP? prodCustTemp = null;
+                var ltemp = await Biz.Db.Queryable<BAS_LABEL_TEMP>().Where(x => x.LABEL_CODE == input.Label.LABEL_CODE).FirstAsync();
                 //濡傛灉浼犲叆鐨勬爣绛惧鎴风紪鐮佷笉涓虹┖
                 if (!input.Label.CUST_CODE.IsNullOrEmpty())
                 {
                     //濡傛灉鏌ヤ笉鍒版爣绛惧苟涓斿鎴风紪鐮佷笉涓虹┖
-                    if (!Biz.Db.Queryable<BAS_LABEL_TEMP>().Any(x => x.LABEL_CODE == input.Label.LABEL_CODE))
+                    if (ltemp == null)
                     {
                         prodCustTemp = input.Label;
                         prodTemp = input.Label.Clone();
@@ -88,11 +91,9 @@
                     else
                     {
                         prodCustTemp = input.Label;
-                        if (Biz.Db.Queryable<BAS_LABEL_TEMP>().Any(x =>
-                        x.LABEL_CODE == input.Label.LABEL_CODE && (
-                        (x.PROD_CODE != input.Label.PROD_CODE && x.CUST_CODE == input.Label.CUST_CODE) ||
-                        (x.PROD_CODE != input.Label.PROD_CODE && x.CUST_CODE != input.Label.CUST_CODE) ||
-                        (x.PROD_CODE == input.Label.PROD_CODE && x.CUST_CODE != input.Label.CUST_CODE))))
+                        if ((ltemp.PROD_CODE != input.Label.PROD_CODE && ltemp.CUST_CODE == input.Label.CUST_CODE) ||
+                            (ltemp.PROD_CODE != input.Label.PROD_CODE && ltemp.CUST_CODE != input.Label.CUST_CODE) ||
+                            (ltemp.PROD_CODE == input.Label.PROD_CODE && ltemp.CUST_CODE != input.Label.CUST_CODE))
                         {
                             prodCustTemp.LABEL_CODE = GenerateCodeName(input.Label.LABEL_CODE, "_L");
                         }
@@ -102,7 +103,7 @@
                 {
                     //濡傛灉瀹㈡埛缂栫爜涓虹┖
                     prodTemp = input.Label;
-                    if (Biz.Db.Queryable<BAS_LABEL_TEMP>().Any(x => x.LABEL_CODE == input.Label.LABEL_CODE && x.PROD_CODE != input.Label.PROD_CODE))
+                    if (ltemp != null && (ltemp.PROD_CODE.IsNullOrEmpty() || ltemp.PROD_CODE != input.Label.PROD_CODE))
                     {
                         prodTemp.LABEL_CODE = GenerateCodeName(input.Label.LABEL_CODE, "_L");
                     }
@@ -154,8 +155,9 @@
                                 item.LABEL_ID = temp.ID;
                             }
                         }
+                        db.Deleteable<BAS_LABEL_VAR_WO>(false).Where(x => x.LABEL_ID == input.LabelVarWos[0].LABEL_ID).ExecuteCommand();
                         var o = db.Storageable(input.LabelVarWos)
-                           .WhereColumns(t => new { t.LABEL_ID, t.VAR_NAME, t.GHOST_ROW })
+                           .WhereColumns(t => new { t.LABEL_ID, t.WORK_ORDER, t.VAR_NAME, t.GHOST_ROW })
                            .ToStorage();
                         o.AsInsertable.ExecuteCommand();
                         o.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
@@ -175,6 +177,51 @@
         }
 
         /// <summary>
+        /// 淇濆瓨鏍囩妯℃澘鍙橀噺
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        public async Task<ApiAction> SaveLabelTemplateVar(BasLabelTempInput input)
+        {
+            var result = new ApiAction();
+            try
+            {
+                var db = Biz.Db;
+                var dbTran = db.UseTran(() =>
+                {
+                    if (input.LabelVars != null && input.LabelVars.Count > 0)
+                    {
+                        db.Deleteable<BAS_LABEL_VAR>(false).Where(x => x.LABEL_ID == input.LabelVars[0].LABEL_ID).ExecuteCommand();
+                        var z = db.Storageable(input.LabelVars)
+                           .WhereColumns(t => new { t.LABEL_ID, t.VAR_NAME, t.GHOST_ROW })
+                           .ToStorage();
+                        z.AsInsertable.ExecuteCommand();
+                        z.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
+                    }
+                    if (input.LabelVarWos != null && input.LabelVarWos.Count > 0)
+                    {
+                        db.Deleteable<BAS_LABEL_VAR_WO>(false).Where(x => x.LABEL_ID == input.LabelVarWos[0].LABEL_ID).ExecuteCommand();
+                        var o = db.Storageable(input.LabelVarWos)
+                           .WhereColumns(t => new { t.LABEL_ID, t.WORK_ORDER, t.VAR_NAME, t.GHOST_ROW })
+                           .ToStorage();
+                        o.AsInsertable.ExecuteCommand();
+                        o.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
+                    }
+                });
+                if (!dbTran.IsSuccess)
+                {
+                    result.IsSuccessed = false;
+                    result.LocaleMsg = new($"淇濆瓨鏍囩鍙橀噺寮傚父锛�");
+                }
+            }
+            catch (Exception ex)
+            {
+                result.CatchExceptionWithLog(ex, "淇濆瓨鏍囩鍙橀噺寮傚父");
+            }
+            return await Task.FromResult(result);
+        }
+
+        /// <summary>
         /// 鏍规嵁鍒嗛殧绗︾敓鎴怌ode鍚�
         /// </summary>
         /// <param name="data"></param>
diff --git a/Tiger.IBusiness/MES/LabelTemplate/ILabelTemplate.cs b/Tiger.IBusiness/MES/LabelTemplate/ILabelTemplate.cs
index 8a1bc35..878484c 100644
--- a/Tiger.IBusiness/MES/LabelTemplate/ILabelTemplate.cs
+++ b/Tiger.IBusiness/MES/LabelTemplate/ILabelTemplate.cs
@@ -16,5 +16,6 @@
     {
         public Task<ApiAction> SaveLabelTemplate(BasLabelTempInput input);
         public Task<ApiAction> DeleteLabelTemplate(string Id);
+        public Task<ApiAction> SaveLabelTemplateVar(BasLabelTempInput input);
     }
 }
diff --git a/Tiger.Model.Net/Entitys/BAS/BAS_LABEL_VAR_WO.cs b/Tiger.Model.Net/Entitys/BAS/BAS_LABEL_VAR_WO.cs
index 7b7bc04..be15b28 100644
--- a/Tiger.Model.Net/Entitys/BAS/BAS_LABEL_VAR_WO.cs
+++ b/Tiger.Model.Net/Entitys/BAS/BAS_LABEL_VAR_WO.cs
@@ -64,6 +64,11 @@
         /// </summary>
         [DisplayName("产品编码")]
         public string PROD_CODE { get; set; }
+        /// <summary>
+        /// 默认值
+        /// </summary>
+        [DisplayName("默认值")]
+        public string DEFAULT_VALUE { get; set; }
         #endregion
 
         #region 虚拟属性

--
Gitblit v1.9.3