From faf6facde340188539a94c93002684b4c8477b26 Mon Sep 17 00:00:00 2001
From: Rodney Chen <rodney.chen@hotmail.com>
Date: 星期二, 30 七月 2024 09:03:46 +0800
Subject: [PATCH] Merge branch 'master' of http://47.115.28.255:8110/r/TigerClouds-Tech/Server/TigerApi6_2024

---
 Tiger.Model.Net/Entitys/MES/ParameterEntity/BizMesWoBatchParameter - 复制.cs |    0 
 Tiger.Model.Net/Tiger.Model.Net.csproj                                     |    3 
 Tiger.IBusiness/MES/LabelTemplate/ILabelTemplate.cs                        |   20 ++++
 Tiger.Api/Controllers/MES/MESController.BAS_LABEL_TEMP.cs                  |   55 +++++++++++
 Tiger.Model.Net/Entitys/MES/ParameterEntity/BasLabelTempParameter.cs       |   15 +++
 Tiger.Business.MES/LabelTemplate/BAS_LABEL_TEMP.cs                         |  169 +++++++++++++++++++++++++++++++++
 6 files changed, 261 insertions(+), 1 deletions(-)

diff --git a/Tiger.Api/Controllers/MES/MESController.BAS_LABEL_TEMP.cs b/Tiger.Api/Controllers/MES/MESController.BAS_LABEL_TEMP.cs
new file mode 100644
index 0000000..d99018b
--- /dev/null
+++ b/Tiger.Api/Controllers/MES/MESController.BAS_LABEL_TEMP.cs
@@ -0,0 +1,55 @@
+锘縰sing Microsoft.AspNetCore.Mvc;
+using Rhea.Common;
+using System.Threading.Tasks;
+using Tiger.IBusiness;
+using Tiger.Model;
+using Tiger.Model.Entitys.MES.BasLabelTemp;
+
+namespace Tiger.Api.Controllers.MES
+{
+    public partial class MESController : ControllerBase
+    {
+
+        /// <summary>
+        /// 淇濆瓨鏍囩妯℃澘
+        /// </summary>
+        /// <param name="action"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [Route("api/[controller]/[action]")]
+        public async Task<IActionResult> SaveLabelTemplate([FromBody] ApiAction<BasLabelTempInput> action)
+        {
+            ApiAction response = new();
+            try
+            {
+                response = response.GetResponse(await DI.Resolve<ILabelTemplate>().SaveLabelTemplate(action.Data));
+            }
+            catch (System.Exception ex)
+            {
+                response = response.GetResponse().CatchExceptionWithLog(ex);
+            }
+            return Ok(response);
+        }
+
+        /// <summary>
+        /// 鍒犻櫎鏍囩妯℃澘
+        /// </summary>
+        /// <param name="action"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [Route("api/[controller]/[action]")]
+        public async Task<IActionResult> DeleteLabelTemplate([FromBody] ApiAction action)
+        {
+            ApiAction response = new();
+            try
+            {
+                response = response.GetResponse(await DI.Resolve<ILabelTemplate>().DeleteLabelTemplate(action.Data?.ToString()));
+            }
+            catch (System.Exception ex)
+            {
+                response = response.GetResponse().CatchExceptionWithLog(ex);
+            }
+            return Ok(response);
+        }
+    }
+}
diff --git a/Tiger.Business.MES/LabelTemplate/BAS_LABEL_TEMP.cs b/Tiger.Business.MES/LabelTemplate/BAS_LABEL_TEMP.cs
new file mode 100644
index 0000000..20e8339
--- /dev/null
+++ b/Tiger.Business.MES/LabelTemplate/BAS_LABEL_TEMP.cs
@@ -0,0 +1,169 @@
+锘縰sing Tiger.Model;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq.Expressions;
+using System.Text;
+using System.Threading.Tasks;
+using Rhea.Common;
+using System.Net;
+using System.Linq;
+using Newtonsoft.Json;
+using Tiger.IBusiness;
+using Microsoft.AspNetCore.Http;
+using Tiger.Model.Entitys.MES.BasLabelTemp;
+using System.Security.Cryptography;
+
+namespace Tiger.Business.MES
+{
+    public partial class BasLabelTemp : ILabelTemplate
+    {
+        public async Task<ApiAction> DeleteLabelTemplate(string Id)
+        {
+            var result = new ApiAction();
+            try
+            {
+                var _label = await Biz.Db.Queryable<BAS_LABEL_TEMP>().Where(x => x.ID == Id).FirstAsync();
+                if (_label == null)
+                {
+                    result.IsSuccessed = false;
+                    result.LocaleMsg = new($"鏍囩妯℃澘涓嶅瓨鍦紝涓嶈兘鍒犻櫎锛�");
+                    return result;
+                }
+                if (Biz.Db.Queryable<MES_PROD_ACTION>().Any(x => x.LABEL_CODE == _label.LABEL_CODE))
+                {
+                    result.IsSuccessed = false;
+                    result.LocaleMsg = new($"鏍囩妯℃澘宸茬粡缁戝畾鍒拌涓猴紝涓嶈兘鍒犻櫎锛�");
+                    return result;
+                }
+                if (Biz.Db.Queryable<MES_WO_ACTION>().Any(x => x.LABEL_CODE == _label.LABEL_CODE))
+                {
+                    result.IsSuccessed = false;
+                    result.LocaleMsg = new($"鏍囩妯℃澘宸茬粡缁戝畾鍒拌涓猴紝涓嶈兘鍒犻櫎锛�");
+                    return result;
+                }
+                var db = Biz.Db;
+                var dbTran = db.UseTran(() =>
+                {
+                    db.Deleteable<BAS_LABEL_TEMP>().Where(x => x.ID == Id).ExecuteCommand();
+                });
+                if (!dbTran.IsSuccess)
+                {
+                    result.IsSuccessed = false;
+                    result.LocaleMsg = new($"鍒犻櫎鏍囩妯℃澘寮傚父");
+                }
+            }
+            catch (Exception ex)
+            {
+                result.CatchExceptionWithLog(ex, "鍒犻櫎鏍囩妯℃澘寮傚父");
+            }
+            return result;
+        }
+
+        /// <summary>
+        /// 淇濆瓨鏍囩妯℃澘
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        /// <exception cref="NotImplementedException"></exception>
+        public async Task<ApiAction> SaveLabelTemplate(BasLabelTempInput input)
+        {
+            var result = new ApiAction();
+            try
+            {
+                BAS_LABEL_TEMP? prodTemp = null;
+                BAS_LABEL_TEMP? prodCustTemp = null;
+                //濡傛灉浼犲叆鐨勬爣绛惧鎴风紪鐮佷笉涓虹┖
+                if (!input.Label.CUST_CODE.IsNullOrEmpty())
+                {
+                    //濡傛灉鏌ヤ笉鍒版爣绛惧苟涓斿鎴风紪鐮佷笉涓虹┖
+                    if (!Biz.Db.Queryable<BAS_LABEL_TEMP>().Any(x => x.LABEL_CODE == input.Label.LABEL_CODE))
+                    {
+                        prodCustTemp = input.Label;
+                        prodTemp = input.Label.Clone();
+                        prodTemp.CUST_CODE = "";
+                        prodTemp.LABEL_CODE = $"{input.Label.LABEL_CODE}_{DateTime.Now.ToString("yyyyMMddhhmmss")}";
+                    }
+                    else
+                    {
+                        prodCustTemp = input.Label;
+                        prodCustTemp.LABEL_CODE = $"{input.Label.LABEL_CODE}_{DateTime.Now.ToString("yyyyMMddhhmmss")}";
+                    }
+                }
+                else
+                {
+                    //濡傛灉瀹㈡埛缂栫爜涓虹┖
+                    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))
+                    {
+                        prodTemp.LABEL_CODE = $"{input.Label.LABEL_CODE}_{DateTime.Now.ToString("yyyyMMddhhmmss")}";
+                    }
+                }
+                var db = Biz.Db;
+                var dbTran = db.UseTran(() =>
+                {
+                    if (prodTemp != null)
+                    {
+                        var x = db.Storageable(prodTemp)
+                           .WhereColumns(t => new { t.LABEL_CODE, t.PROD_CODE, t.CUST_CODE, t.GHOST_ROW })
+                           .ToStorage();
+                        x.AsInsertable.ExecuteCommand();
+                        x.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
+                    }
+                    if (prodCustTemp != null)
+                    {
+                        var y = db.Storageable(prodCustTemp)
+                           .WhereColumns(t => new { t.LABEL_CODE, t.PROD_CODE, t.CUST_CODE, t.GHOST_ROW })
+                           .ToStorage();
+                        y.AsInsertable.ExecuteCommand();
+                        y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
+                    }
+                    var temp = db.Queryable<BAS_LABEL_TEMP>().Where(x =>
+                    x.LABEL_CODE == input.Label.LABEL_CODE &&
+                    x.PROD_CODE == input.Label.PROD_CODE &&
+                    x.CUST_CODE == input.Label.CUST_CODE).First();
+                    if (input.LabelVars != null && input.LabelVars.Count > 0)
+                    {
+                        if (temp != null && temp.ID != input.LabelVars[0].LABEL_ID)
+                        {
+                            foreach (var item in input.LabelVars)
+                            {
+                                item.LABEL_ID = temp.ID;
+                            }
+                        }
+                        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)
+                    {
+                        if (temp != null && temp.ID != input.LabelVarWos[0].LABEL_ID)
+                        {
+                            foreach (var item in input.LabelVarWos)
+                            {
+                                item.LABEL_ID = temp.ID;
+                            }
+                        }
+                        var o = db.Storageable(input.LabelVarWos)
+                           .WhereColumns(t => new { t.LABEL_ID, 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);
+        }
+    }
+}
diff --git a/Tiger.IBusiness/MES/LabelTemplate/ILabelTemplate.cs b/Tiger.IBusiness/MES/LabelTemplate/ILabelTemplate.cs
new file mode 100644
index 0000000..8a1bc35
--- /dev/null
+++ b/Tiger.IBusiness/MES/LabelTemplate/ILabelTemplate.cs
@@ -0,0 +1,20 @@
+锘縰sing Rhea.Common;
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tiger.Model;
+using Tiger.Model.Entitys.MES.BasLabelTemp;
+using Tiger.Model.Entitys.MES.BizMesWo;
+using Tiger.Model.Entitys.MES.BizMesWoBatch;
+
+namespace Tiger.IBusiness
+{
+    public interface ILabelTemplate
+    {
+        public Task<ApiAction> SaveLabelTemplate(BasLabelTempInput input);
+        public Task<ApiAction> DeleteLabelTemplate(string Id);
+    }
+}
diff --git a/Tiger.Model.Net/Entitys/MES/ParameterEntity/BasLabelTempParameter.cs b/Tiger.Model.Net/Entitys/MES/ParameterEntity/BasLabelTempParameter.cs
new file mode 100644
index 0000000..68f96c0
--- /dev/null
+++ b/Tiger.Model.Net/Entitys/MES/ParameterEntity/BasLabelTempParameter.cs
@@ -0,0 +1,15 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tiger.Model.Entitys.MES.BasLabelTemp
+{
+    public class BasLabelTempInput
+    {
+        public BAS_LABEL_TEMP Label { get; set; }
+        public List<BAS_LABEL_VAR> LabelVars { get; set; }
+        public List<BAS_LABEL_VAR_WO> LabelVarWos { get; set; }
+    }
+}
diff --git a/Tiger.Model.Net/Entitys/MES/ParameterEntity/BizMesWoBatchParameter.cs "b/Tiger.Model.Net/Entitys/MES/ParameterEntity/BizMesWoBatchParameter - \345\244\215\345\210\266.cs"
similarity index 100%
rename from Tiger.Model.Net/Entitys/MES/ParameterEntity/BizMesWoBatchParameter.cs
rename to "Tiger.Model.Net/Entitys/MES/ParameterEntity/BizMesWoBatchParameter - \345\244\215\345\210\266.cs"
diff --git a/Tiger.Model.Net/Tiger.Model.Net.csproj b/Tiger.Model.Net/Tiger.Model.Net.csproj
index d86ea8e..548788c 100644
--- a/Tiger.Model.Net/Tiger.Model.Net.csproj
+++ b/Tiger.Model.Net/Tiger.Model.Net.csproj
@@ -151,8 +151,9 @@
     <Compile Include="Entitys\MES\MES_WO_NODE_POST.cs" />
     <Compile Include="Entitys\MES\MES_WO_OPER.cs" />
     <Compile Include="Entitys\MES\node.cs" />
+    <Compile Include="Entitys\MES\ParameterEntity\BizMesWoBatchParameter - 澶嶅埗.cs" />
     <Compile Include="Entitys\MES\ParameterEntity\BizMesWoParameter.cs" />
-    <Compile Include="Entitys\MES\ParameterEntity\BizMesWoBatchParameter.cs" />
+    <Compile Include="Entitys\MES\ParameterEntity\BasLabelTempParameter.cs" />
     <Compile Include="Entitys\MES\ParameterEntity\SmtLoadingReturn.cs" />
     <Compile Include="Entitys\MES\ParameterEntity\SmtLoadingInput.cs" />
     <Compile Include="Entitys\MES\ParameterEntity\PositionParameter.cs" />

--
Gitblit v1.9.3