From 4651b8084dff20870148cc9f9c521d777a78ffb5 Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期三, 24 七月 2024 00:12:14 +0800
Subject: [PATCH] 删除工艺路线绑定

---
 Tiger.Business/MES/Biz.Route.cs                           |  142 +++++++++++++++++++++++++++++++++++
 Tiger.Business.MES/iERP/U9C_MES.cs                        |    4 
 Tiger.IBusiness/MES/IRoute.cs                             |    2 
 Tiger.Model.Net/Entitys/MES/ParameterEntity/RouteInput.cs |   24 ++++++
 Tiger.Api/Controllers/MES/MESController.Route.cs          |   42 ++++++++++
 Tiger.Model.Net/Tiger.Model.Net.csproj                    |    1 
 6 files changed, 214 insertions(+), 1 deletions(-)

diff --git a/Tiger.Api/Controllers/MES/MESController.Route.cs b/Tiger.Api/Controllers/MES/MESController.Route.cs
index 1b0f289..55edb33 100644
--- a/Tiger.Api/Controllers/MES/MESController.Route.cs
+++ b/Tiger.Api/Controllers/MES/MESController.Route.cs
@@ -139,6 +139,48 @@
         }
 
         /// <summary>
+        /// 鍒犻櫎浜у搧缁戝畾鐨勫伐鑹鸿矾绾�
+        /// </summary>
+        /// <param name="action"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [Route("api/[controller]/[action]")]
+        public async Task<IActionResult> DeleteProdRoute([FromBody] ApiAction<DelProdRotInput> action)
+        {
+            ApiAction response = new();
+            try
+            {
+                response = response.GetResponse(await DI.Resolve<IRoute>().DeleteProdRoute(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> DeleteWoRoute([FromBody] ApiAction<DelWoRotInput> action)
+        {
+            ApiAction response = new();
+            try
+            {
+                response = response.GetResponse(await DI.Resolve<IRoute>().DeleteWoRoute(action.Data));
+            }
+            catch (System.Exception ex)
+            {
+                response = response.GetResponse().CatchExceptionWithLog(ex);
+            }
+            return Ok(response);
+        }
+
+        /// <summary>
         /// 鑾峰彇宸ヨ壓璺嚎鏍戝舰缁撴瀯
         /// </summary>
         /// <param name="prodCode"></param>
diff --git a/Tiger.Business.MES/iERP/U9C_MES.cs b/Tiger.Business.MES/iERP/U9C_MES.cs
index 7614f96..ead57d8 100644
--- a/Tiger.Business.MES/iERP/U9C_MES.cs
+++ b/Tiger.Business.MES/iERP/U9C_MES.cs
@@ -123,13 +123,15 @@
                 if (di != null)
                 {
                     var orgId = di["Org"] == null ? "" : di["Org"].ToString();
+                    var itemId = di["ItemMaster"] == null ? "" : di["ItemMaster"].ToString();
+                    var basItem = Biz.Db.Queryable <BAS_ITEM>().Where(x=>x.ID == itemId).First();
                     BIZ_MES_WO woItem = new()
                     {
                         ORDER_NO = di["DocNo"] == null ? "" : di["DocNo"].ToString(),
                         ORDER_TYPE = di["DocTypeCode"] == null ? 0 : di["DocTypeCode"].ToInt32(),
                         PLAN_QTY = di["ProductQty"] == null ? 0 : di["ProductQty"].ToInt32(),
                         CUST_CODE = di["CustomerCode"] == null ? "" : di["CustomerCode"].ToString(),
-                        ITEM_CODE = di["ItemMaster"] == null ? "" : di["ItemMaster"].ToString(),
+                        ITEM_CODE = basItem != null? basItem.ITEM_CODE: "",
                         CREATE_TIME = di["CreatedOn"].ToDateTime(),
                         UPDATE_TIME = di["ModifiedOn"].ToDateTime(),
                         PLAN_START_TIME = di["CheckDate"].ToDateTime(),
diff --git a/Tiger.Business/MES/Biz.Route.cs b/Tiger.Business/MES/Biz.Route.cs
index c36570e..56fe66c 100644
--- a/Tiger.Business/MES/Biz.Route.cs
+++ b/Tiger.Business/MES/Biz.Route.cs
@@ -11,6 +11,8 @@
 using Newtonsoft.Json;
 using Tiger.IBusiness;
 using Microsoft.AspNetCore.Http;
+using Tiger.Model.Entitys.WMS.DTOS;
+using static Tiger.Model.BIZ_MES_WO;
 
 namespace Tiger.Business
 {
@@ -409,6 +411,146 @@
                 }
                 return await Task.FromResult(result);
             }
+
+            /// <summary>
+            /// 鍒犻櫎浜у搧缁戝畾鐨勫伐鑹鸿矾绾�
+            /// </summary>
+            /// <param name="input"></param>
+            /// <returns></returns>
+            /// <exception cref="NotImplementedException"></exception>
+            public async Task<ApiAction> DeleteProdRoute(DelProdRotInput input)
+            {
+                var result = new ApiAction();
+                try
+                {
+                    var expable = Expressionable.Create<MES_PROD_ACTION>();
+                    var expableOper = Expressionable.Create<MES_PROD_OPER>();
+                    if (!string.IsNullOrEmpty(input.rotId))
+                    {
+                        expable.And(x => x.ROT_ID == input.rotId);
+                        expableOper.And(x => x.ROT_ID == input.rotId);
+                    }
+                    else if (!string.IsNullOrEmpty(input.rotCode))
+                    {
+                        var item = await Db.Queryable<MES_ROUTE>().Where(x => x.ROT_CODE == input.rotCode).FirstAsync();
+                        if (item != null)
+                        {
+                            expable.And(x => x.ROT_ID == item.ID);
+                            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);
+                    }
+                    var exp = expable.ToExpression();
+                    var expOper = expableOper.ToExpression();
+                    var db = Db;
+                    var dbTran = db.UseTran(() =>
+                    {
+                        db.Deleteable<MES_PROD_ACTION>().Where(exp).ExecuteCommand();
+                        db.Deleteable<MES_PROD_OPER>().Where(expOper).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> DeleteWoRoute(DelWoRotInput input)
+            {
+                var result = new ApiAction();
+                try
+                {
+                    var bizMesWo = await Db.Queryable<BIZ_MES_WO>().Where(x=> x.ORDER_NO == input.wo).FirstAsync();
+                    if (bizMesWo != null && bizMesWo.STATUS > (int)STATUSs.Imported && bizMesWo.STATUS < (int)STATUSs.Closed)
+                    {
+                        result.IsSuccessed = false;
+                        result.LocaleMsg = new($"宸ュ崟鐘舵�佷负[{EnumHelper.GetDesc(EnumHelper.GetEnum<STATUSs>(bizMesWo.STATUS))}]锛屼笉鑳藉垹闄ゅ伐鑹鸿矾绾�");
+                        return result;
+                    }
+                    var expableNode = Expressionable.Create<MES_WO_NODE>();
+                    var expableEdge = Expressionable.Create<MES_WO_EDGE>();
+                    var expableAct = Expressionable.Create<MES_WO_NODE_ACT>();
+                    var expable = Expressionable.Create<MES_WO_ACTION>();
+                    var expableOper = Expressionable.Create<MES_WO_OPER>();
+                    var _rotId = input.rotId;
+                    if (!string.IsNullOrEmpty(input.rotId))
+                    {
+                        expable.And(x => x.ROT_ID == input.rotId);
+                        expableOper.And(x => x.ROT_ID == input.rotId);
+                        expableNode.And(x => x.ROT_ID == input.rotId);
+                        expableEdge.And(x => x.ROT_ID == input.rotId);
+                        expableAct.And(x => x.ROT_ID == input.rotId);
+                    }
+                    else if (!string.IsNullOrEmpty(input.rotCode))
+                    {
+                        var item = await Db.Queryable<MES_ROUTE>().Where(x => x.ROT_CODE == input.rotCode).FirstAsync();
+                        if (item != null)
+                        {
+                            _rotId = item.ID;
+                            expable.And(x => x.ROT_ID == item.ID);
+                            expableOper.And(x => x.ROT_ID == item.ID);
+                            expableNode.And(x => x.ROT_ID == item.ID);
+                            expableEdge.And(x => x.ROT_ID == item.ID);
+                            expableAct.And(x => x.ROT_ID == item.ID);
+                        }
+                    }
+                    //濡傛灉闄や簡鍒犻櫎鐨勫綋鍓嶅伐鑹鸿矾绾夸笉瀛樺湪鍏朵粬缁戝畾鐨勫伐鑹鸿矾绾匡紝鍒欐洿鏂扮姸鎬�
+                    if (bizMesWo != null && !Db.Queryable<MES_WO_NODE>().Where(x => x.WORK_ORDER == input.wo && x.ROT_ID != _rotId).Any()) {
+                        bizMesWo.ROUTE_STATUS = (int)ROUTE_STATUSs.WaitSet;
+                        bizMesWo.STATUS = (int)STATUSs.Init;
+                        bizMesWo.ROUTE_CODE = "";
+                    }
+                    if (!string.IsNullOrEmpty(input.wo))
+                    {
+                        expable.And(x => x.WORK_ORDER == input.wo);
+                        expableOper.And(x => x.WORK_ORDER == input.wo);
+                        expableNode.And(x => x.WORK_ORDER == input.wo);
+                        expableEdge.And(x => x.WORK_ORDER == input.wo);
+                        expableAct.And(x => x.WORK_ORDER == input.wo);
+                    }
+                    var exp = expable.ToExpression();
+                    var expOper = expableOper.ToExpression();
+                    var expNode = expableNode.ToExpression();
+                    var expEdge = expableEdge.ToExpression();
+                    var expAct = expableAct.ToExpression();
+                    var db = Db;
+                    var dbTran = db.UseTran(() =>
+                    {
+                        db.Deleteable<MES_WO_ACTION>().Where(exp).ExecuteCommand();
+                        db.Deleteable<MES_WO_OPER>().Where(expOper).ExecuteCommand();
+                        db.Deleteable<MES_WO_NODE>().Where(expNode).ExecuteCommand();
+                        db.Deleteable<MES_WO_EDGE>().Where(expEdge).ExecuteCommand();
+                        db.Deleteable<MES_WO_NODE_ACT>().Where(expAct).ExecuteCommand();
+                        db.Updateable(bizMesWo).ExecuteCommand();
+                    });
+                    if (!dbTran.IsSuccess)
+                    {
+                        result.IsSuccessed = false;
+                        result.LocaleMsg = new($"鍒犻櫎宸ヨ壓璺嚎寮傚父");
+                    }
+                }
+                catch (Exception ex)
+                {
+                    result.CatchExceptionWithLog(ex, "鍒犻櫎宸ヨ壓璺嚎寮傚父");
+                }
+                return result;
+            }
         }
     }
 }
diff --git a/Tiger.IBusiness/MES/IRoute.cs b/Tiger.IBusiness/MES/IRoute.cs
index ebeb884..cc95ac5 100644
--- a/Tiger.IBusiness/MES/IRoute.cs
+++ b/Tiger.IBusiness/MES/IRoute.cs
@@ -20,5 +20,7 @@
         public Task<ApiAction<RouteData>> GetRouteData(string routeCode);
         public Task<ApiAction> DeleteRoute(string routeId);
         public Task<ApiAction> SaveRouteNodePost(List<MES_ROUTE_NODE_POST> nodePost);
+        public Task<ApiAction> DeleteProdRoute(DelProdRotInput input);
+        public Task<ApiAction> DeleteWoRoute(DelWoRotInput input);
     }
 }
diff --git a/Tiger.Model.Net/Entitys/MES/ParameterEntity/RouteInput.cs b/Tiger.Model.Net/Entitys/MES/ParameterEntity/RouteInput.cs
new file mode 100644
index 0000000..87f6620
--- /dev/null
+++ b/Tiger.Model.Net/Entitys/MES/ParameterEntity/RouteInput.cs
@@ -0,0 +1,24 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tiger.Model
+{
+    public class RouteInput
+    {
+        public string rotId { get; set; }
+        public string rotCode { get; set; }
+    }
+
+    public class DelProdRotInput : RouteInput
+    {
+        public string prodCode { get; set; }
+    }
+
+    public class DelWoRotInput : RouteInput
+    {
+        public string wo { get; set; }
+    }
+}
diff --git a/Tiger.Model.Net/Tiger.Model.Net.csproj b/Tiger.Model.Net/Tiger.Model.Net.csproj
index 296c265..07ff413 100644
--- a/Tiger.Model.Net/Tiger.Model.Net.csproj
+++ b/Tiger.Model.Net/Tiger.Model.Net.csproj
@@ -148,6 +148,7 @@
     <Compile Include="Entitys\MES\ParameterEntity\SmtLoadingReturn.cs" />
     <Compile Include="Entitys\MES\ParameterEntity\SmtLoadingInput.cs" />
     <Compile Include="Entitys\MES\ParameterEntity\PositionParameter.cs" />
+    <Compile Include="Entitys\MES\ParameterEntity\RouteInput.cs" />
     <Compile Include="Entitys\MES\ParameterEntity\U9C_MES_Input.cs" />
     <Compile Include="Entitys\MES\R_Wip_Tracking_T.cs" />
     <Compile Include="Entitys\MES\SMT_FEEDER.cs" />

--
Gitblit v1.9.3