From cc3df152b3d12c03ae14489bcca3ab8a11db7931 Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期六, 27 四月 2024 16:33:12 +0800
Subject: [PATCH] 工艺路线

---
 Tiger.IBusiness/MES/IRouter.cs                   |   21 ++
 Tiger.Api/appsettings.json                       |    2 
 Tiger.Api/Controllers/MES/MESController.Route.cs |   95 ++++++++++
 Tiger.Business/MES/Biz.Router.cs                 |  270 ++++++++++++++++++++++++++++++
 Tiger.Api/Controllers/MES/MESController.cs       |    9 +
 Tiger.Business/Tiger.Business.csproj             |    1 
 Tiger.Model.Net/Tiger.Model.Net.csproj           |    2 
 Tiger.Model.Net/Entitys/MES/MES_ROUTE_EDGE.cs    |   26 +-
 Tiger.Model.Net/Entitys/MES/node.cs              |   23 ++
 Tiger.Api/Tiger.Api.csproj                       |    1 
 Tiger.Model.Net/Entitys/MES/edge.cs              |   26 ++
 Tiger.Model.Net/Entitys/MES/MES_ROUTE.cs         |    7 
 Tiger.Model.Net/Entitys/MES/MES_ROUTE_NODE.cs    |   26 +-
 13 files changed, 486 insertions(+), 23 deletions(-)

diff --git a/Tiger.Api/Controllers/MES/MESController.Route.cs b/Tiger.Api/Controllers/MES/MESController.Route.cs
new file mode 100644
index 0000000..39ba694
--- /dev/null
+++ b/Tiger.Api/Controllers/MES/MESController.Route.cs
@@ -0,0 +1,95 @@
+锘縰sing Microsoft.AspNetCore.Mvc;
+using Rhea.Common;
+using System.Threading.Tasks;
+using Tiger.IBusiness;
+using Tiger.Model;
+
+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> GetRouter([FromBody] ApiAction action)
+        {
+            ApiAction response = new();
+            try
+            {
+                response = response.GetResponse(await DI.Resolve<IRouter>().GetRouter(action.Data?.ToString()));
+            }
+            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> GetRouterData([FromBody] ApiAction action)
+        {
+            ApiAction response = new();
+            try
+            {
+                response = response.GetResponse(await DI.Resolve<IRouter>().GetRouterData(action.Data?.ToString()));
+            }
+            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> SaveRouterData([FromBody] ApiAction<RouterData> action)
+        {
+            ApiAction response = new();
+            try
+            {
+                response = response.GetResponse(await DI.Resolve<IRouter>().SaveRouterData(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> SaveRouter([FromBody] ApiAction<MES_ROUTE> action)
+        {
+            ApiAction response = new();
+            try
+            {
+                response = response.GetResponse(await DI.Resolve<IRouter>().SaveRouter(action.Data));
+            }
+            catch (System.Exception ex)
+            {
+                response = response.GetResponse().CatchExceptionWithLog(ex);
+            }
+            return Ok(response);
+        }
+    }
+}
diff --git a/Tiger.Api/Controllers/MES/MESController.cs b/Tiger.Api/Controllers/MES/MESController.cs
new file mode 100644
index 0000000..db55130
--- /dev/null
+++ b/Tiger.Api/Controllers/MES/MESController.cs
@@ -0,0 +1,9 @@
+锘縰sing Microsoft.AspNetCore.Mvc;
+
+namespace Tiger.Api.Controllers.MES
+{
+    public partial class MESController : ControllerBase
+    {
+
+    }
+}
diff --git a/Tiger.Api/Tiger.Api.csproj b/Tiger.Api/Tiger.Api.csproj
index 3330fc0..715d944 100644
--- a/Tiger.Api/Tiger.Api.csproj
+++ b/Tiger.Api/Tiger.Api.csproj
@@ -78,7 +78,6 @@
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Controllers\EMS\" />
-    <Folder Include="Controllers\MES\" />
     <Folder Include="Controllers\QMS\" />
   </ItemGroup>
   <ItemGroup>
diff --git a/Tiger.Api/appsettings.json b/Tiger.Api/appsettings.json
index d8783e1..662ecc3 100644
--- a/Tiger.Api/appsettings.json
+++ b/Tiger.Api/appsettings.json
@@ -18,7 +18,7 @@
       "http://*:9530", //PDA
       "http://*:9531", //鐪嬫澘
       "http://*:9532", //渚涘簲鍟�
-      "http://*:9533" //渚涘簲鍟�
+      "http://*:9533" //
     ]
   },
   "Upgrade": {
diff --git a/Tiger.Business/MES/Biz.Router.cs b/Tiger.Business/MES/Biz.Router.cs
new file mode 100644
index 0000000..ff482aa
--- /dev/null
+++ b/Tiger.Business/MES/Biz.Router.cs
@@ -0,0 +1,270 @@
+锘縰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 static Tiger.Business.Biz;
+using Microsoft.AspNetCore.Http;
+
+namespace Tiger.Business
+{
+    public partial class Biz
+    {
+        /// <summary>
+        /// 宸ヨ壓璺嚎
+        /// </summary>
+        public partial class Router : IRouter
+        {
+            /// <summary>
+            /// 鑾峰彇宸ヨ壓璺嚎
+            /// </summary>
+            /// <param name="routerCode"></param>
+            /// <returns></returns>
+            public async Task<ApiAction<List<MES_ROUTE>>> GetRouter(string routerCode)
+            {
+                var res = new ApiAction<List<MES_ROUTE>>();
+                List<MES_ROUTE> list = new List<MES_ROUTE>();
+                try
+                {
+                    list = await Db.Queryable<MES_ROUTE>()
+                        .WhereIF(!string.IsNullOrEmpty(routerCode), x => x.ROT_CODE.Equals(routerCode))
+                        .OrderBy(x => x.CREATE_TIME).ToListAsync();
+                }
+                catch (Exception ex)
+                {
+                    res.CatchExceptionWithLog(ex, "鏌ヨ寮傚父");
+                }
+                res.Data = list;
+                return res;
+            }
+
+            /// <summary>
+            /// 鑾峰彇宸ヨ壓璺嚎鍥惧舰鏁版嵁
+            /// </summary>
+            /// <param name="routerCode"></param>
+            /// <returns></returns>
+            public async Task<ApiAction<RouterData>> GetRouterData(string routerCode)
+            {
+                var res = new ApiAction<RouterData>();
+                RouterData rotData = new RouterData();
+                try
+                {
+                    //宸ヨ壓璺嚎
+                    var route = await Db.Queryable<MES_ROUTE>()
+                        .WhereIF(!string.IsNullOrEmpty(routerCode), x => x.ROT_CODE.Equals(routerCode))
+                        .OrderBy(x => x.CREATE_TIME).FirstAsync();
+                    rotData.route = route;
+                    //鑺傜偣
+                    var nodes = await Db.Queryable<MES_ROUTE_NODE>()
+                        .WhereIF(!string.IsNullOrEmpty(routerCode), x => x.ROT_CODE.Equals(routerCode))
+                        .ToListAsync();
+                    foreach (var node in nodes)
+                    {
+                        node.node = new()
+                        {
+                            id = node.ID,
+                            type = node.GPH_TYPE,
+                            x = node.GPH_X,
+                            y = node.GPH_Y,
+                            properties = node.GPH_PROP,
+                            text = new()
+                            {
+                                x = node.GPH_X,
+                                y = node.GPH_Y,
+                                value = node.GPH_TEXT
+                            }
+                        };
+                    }
+                    rotData.nodes = nodes;
+
+                    //杈�
+                    var edges = await Db.Queryable<MES_ROUTE_EDGE>()
+                        .WhereIF(!string.IsNullOrEmpty(routerCode), x => x.ROT_CODE.Equals(routerCode))
+                        .ToListAsync();
+                    foreach (var edge in edges)
+                    {
+                        edge.edge = new()
+                        {
+                            id = edge.ID,
+                            type = edge.GPH_TYPE,
+                            sourceNodeId = edge.SRC_NODE,
+                            targetNodeId = edge.TGT_NODE,
+                            properties = edge.GPH_PROP,
+                            startPoint = new()
+                            {
+                                x = edge.GPH_SRC_X,
+                                y = edge.GPH_SRC_Y,
+                            },
+                            endPoint = new()
+                            {
+                                x = edge.GPH_TGT_X,
+                                y = edge.GPH_TGT_Y,
+                            },
+                            pointsList = new()
+                            {
+                                new(){
+                                    x = edge.GPH_SRC_X,
+                                    y = edge.GPH_SRC_Y,
+                                },
+                                new(){
+                                    x = edge.GPH_TGT_X,
+                                    y = edge.GPH_TGT_Y,
+                                }
+                            }
+                        };
+                    }
+                    rotData.edges = edges;
+                }
+                catch (Exception ex)
+                {
+                    res.CatchExceptionWithLog(ex, "鏌ヨ寮傚父");
+                }
+                res.Data = rotData;
+                return res;
+            }
+
+            /// <summary>
+            /// 淇濆瓨杈规暟鎹�
+            /// </summary>
+            /// <param name="routeEdge"></param>
+            /// <returns></returns>
+            public async Task<ApiAction> SaveEdges(List<MES_ROUTE_EDGE> routeEdge)
+            {
+                var result = new ApiAction();
+                try
+                {
+                    var db = Db;
+                    var dbTran = db.UseTran(() =>
+                    {
+                        var y = db.Storageable(routeEdge)
+                           .WhereColumns(t => new { t.EDGE_CODE, t.GHOST_ROW })
+                           .ToStorage();
+                        y.AsInsertable.ExecuteCommand();
+                        y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
+                    });
+                    if (!dbTran.IsSuccess)
+                    {
+                        result.IsSuccessed = false;
+                        result.Message = $"淇濆瓨杈规暟鎹紓甯�";
+                    }
+                }
+                catch (Exception ex)
+                {
+                    result.CatchExceptionWithLog(ex, "淇濆瓨杈规暟鎹紓甯�");
+                }
+                return await Task.FromResult(result);
+            }
+
+            /// <summary>
+            /// 淇濆瓨鑺傜偣鏁版嵁
+            /// </summary>
+            /// <param name="routeNode"></param>
+            /// <returns></returns>
+            public async Task<ApiAction> SaveNodes(List<MES_ROUTE_NODE> routeNode)
+            {
+                var result = new ApiAction();
+                try
+                {
+                    var db = Db;
+                    var dbTran = db.UseTran(() =>
+                    {
+                        var y = db.Storageable(routeNode)
+                           .WhereColumns(t => new { t.NODE_CODE, t.GHOST_ROW })
+                           .ToStorage();
+                        y.AsInsertable.ExecuteCommand();
+                        y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
+                    });
+                    if (!dbTran.IsSuccess)
+                    {
+                        result.IsSuccessed = false;
+                        result.Message = $"淇濆瓨鑺傜偣鏁版嵁寮傚父";
+                    }
+                }
+                catch (Exception ex)
+                {
+                    result.CatchExceptionWithLog(ex, "淇濆瓨鑺傜偣鏁版嵁寮傚父");
+                }
+                return await Task.FromResult(result);
+            }
+
+            /// <summary>
+            /// 淇濆瓨
+            /// </summary>
+            /// <param name="router"></param>
+            /// <returns></returns>
+            public async Task<ApiAction> SaveRouter(MES_ROUTE router)
+            {
+                var result = new ApiAction();
+                try
+                {
+                    var db = Db;
+                    var dbTran = db.UseTran(() =>
+                    {
+                        var y = db.Storageable(router)
+                           .WhereColumns(t => new { t.ROT_CODE, t.GHOST_ROW })
+                           .ToStorage();
+                        y.AsInsertable.ExecuteCommand();
+                        y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
+                    });
+                    if (!dbTran.IsSuccess)
+                    {
+                        result.IsSuccessed = false;
+                        result.Message = $"淇濆瓨宸ヨ壓璺嚎寮傚父";
+                    }
+                }
+                catch (Exception ex)
+                {
+                    result.CatchExceptionWithLog(ex, "淇濆瓨宸ヨ壓璺嚎寮傚父");
+                }
+                return await Task.FromResult(result);
+            }
+
+            /// <summary>
+            /// 淇濆瓨宸ヨ壓璺嚎鍥惧舰鏁版嵁
+            /// </summary>
+            /// <param name="routeData"></param>
+            /// <returns></returns>
+            public async Task<ApiAction> SaveRouterData(RouterData routeData)
+            {
+                var result = new ApiAction();
+                try
+                {
+                    var actionNode = await SaveNodes(routeData.nodes);
+                    if (!actionNode.IsSuccessed) { return actionNode; }
+                    var actionEdge = await SaveEdges(routeData.edges);
+                    if (!actionEdge.IsSuccessed) { return actionEdge; }
+
+                    var db = Db;
+                    var dbTran = db.UseTran(() =>
+                    {
+                        if (routeData.route != null)
+                        {
+                            var y = db.Storageable(routeData.route)
+                               .WhereColumns(t => new { t.ROT_CODE, t.GHOST_ROW })
+                               .ToStorage();
+                            y.AsInsertable.ExecuteCommand();
+                            y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
+                        }
+                    });
+                    if (!dbTran.IsSuccess)
+                    {
+                        result.IsSuccessed = false;
+                        result.Message = $"淇濆瓨宸ヨ壓璺嚎鍥惧舰鏁版嵁寮傚父";
+                    }
+                }
+                catch (Exception ex)
+                {
+                    result.CatchExceptionWithLog(ex, "淇濆瓨宸ヨ壓璺嚎鍥惧舰鏁版嵁寮傚父");
+                }
+                return await Task.FromResult(result);
+            }
+        }
+    }
+}
diff --git a/Tiger.Business/Tiger.Business.csproj b/Tiger.Business/Tiger.Business.csproj
index 4fdf554..dc5de90 100644
--- a/Tiger.Business/Tiger.Business.csproj
+++ b/Tiger.Business/Tiger.Business.csproj
@@ -124,7 +124,6 @@
     <Folder Include="Language\Monitors\" />
     <Folder Include="Language\QMS\" />
     <Folder Include="Language\TSK\" />
-    <Folder Include="MES\" />
     <Folder Include="QMS\" />
     <Folder Include="RTest\" />
   </ItemGroup>
diff --git a/Tiger.IBusiness/MES/IRouter.cs b/Tiger.IBusiness/MES/IRouter.cs
new file mode 100644
index 0000000..ac64cca
--- /dev/null
+++ b/Tiger.IBusiness/MES/IRouter.cs
@@ -0,0 +1,21 @@
+锘縰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;
+
+namespace Tiger.IBusiness
+{
+    public interface IRouter
+    {
+        public Task<ApiAction> SaveRouter(MES_ROUTE router);
+        public Task<ApiAction> SaveNodes(List<MES_ROUTE_NODE> routeNode);
+        public Task<ApiAction> SaveEdges(List<MES_ROUTE_EDGE> routeEdge);
+        public Task<ApiAction> SaveRouterData(RouterData routeData);
+        public Task<ApiAction<List<MES_ROUTE>>> GetRouter(string routerCode);
+        public Task<ApiAction<RouterData>> GetRouterData(string routerCode);
+    }
+}
diff --git a/Tiger.Model.Net/Entitys/MES/MES_ROUTE.cs b/Tiger.Model.Net/Entitys/MES/MES_ROUTE.cs
index 77a4820..aa80961 100644
--- a/Tiger.Model.Net/Entitys/MES/MES_ROUTE.cs
+++ b/Tiger.Model.Net/Entitys/MES/MES_ROUTE.cs
@@ -72,4 +72,11 @@
 		#endregion
 
 	}//endClass
+
+    public class RouterData
+	{
+		public MES_ROUTE route { get; set; }
+		public List<MES_ROUTE_NODE> nodes { get; set; }
+        public List<MES_ROUTE_EDGE> edges { get; set; }
+    }
 }
\ No newline at end of file
diff --git a/Tiger.Model.Net/Entitys/MES/MES_ROUTE_EDGE.cs b/Tiger.Model.Net/Entitys/MES/MES_ROUTE_EDGE.cs
index d98e23b..66ef73d 100644
--- a/Tiger.Model.Net/Entitys/MES/MES_ROUTE_EDGE.cs
+++ b/Tiger.Model.Net/Entitys/MES/MES_ROUTE_EDGE.cs
@@ -74,17 +74,23 @@
 		/// 备注
 		/// </summary>
 		public string REMARK { get; set; }
-		#endregion
+        #endregion
 
-		#region 虚拟属性
-		/*例子
+        #region 虚拟属性
+        /*例子
 		[SugarColumn(IsIgnore = true)]
 		public string FieldName { get; set; }
 		*/
-		#endregion
 
-		#region 枚举变量
-		/*例子
+        /// <summary>
+        /// 边
+        /// </summary>
+        [SugarColumn(IsIgnore = true)]
+        public edge edge { get; set; }
+        #endregion
+
+        #region 枚举变量
+        /*例子
 		public enum FieldNames
 		{
 			[Description("枚举描述0")]
@@ -93,11 +99,11 @@
 			Enum1,
 		}
 		*/
-		#endregion
+        #endregion
 
-		#region 公共方法
+        #region 公共方法
 
-		#endregion
+        #endregion
 
-	}//endClass
+    }//endClass
 }
\ No newline at end of file
diff --git a/Tiger.Model.Net/Entitys/MES/MES_ROUTE_NODE.cs b/Tiger.Model.Net/Entitys/MES/MES_ROUTE_NODE.cs
index fc918b5..3bb11ba 100644
--- a/Tiger.Model.Net/Entitys/MES/MES_ROUTE_NODE.cs
+++ b/Tiger.Model.Net/Entitys/MES/MES_ROUTE_NODE.cs
@@ -78,17 +78,23 @@
 		/// 备注
 		/// </summary>
 		public string REMARK { get; set; }
-		#endregion
+        #endregion
 
-		#region 虚拟属性
-		/*例子
+        #region 虚拟属性
+        /*例子
 		[SugarColumn(IsIgnore = true)]
 		public string FieldName { get; set; }
 		*/
-		#endregion
 
-		#region 枚举变量
-		/*例子
+		/// <summary>
+		/// 节点
+		/// </summary>
+        [SugarColumn(IsIgnore = true)]
+        public node node { get; set; }
+        #endregion
+
+        #region 枚举变量
+        /*例子
 		public enum FieldNames
 		{
 			[Description("枚举描述0")]
@@ -97,11 +103,11 @@
 			Enum1,
 		}
 		*/
-		#endregion
+        #endregion
 
-		#region 公共方法
+        #region 公共方法
 
-		#endregion
+        #endregion
 
-	}//endClass
+    }//endClass
 }
\ No newline at end of file
diff --git a/Tiger.Model.Net/Entitys/MES/edge.cs b/Tiger.Model.Net/Entitys/MES/edge.cs
new file mode 100644
index 0000000..d8846f8
--- /dev/null
+++ b/Tiger.Model.Net/Entitys/MES/edge.cs
@@ -0,0 +1,26 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tiger.Model
+{
+    public class edge
+    {
+        public string id { get; set; }
+        public string type { get; set; }
+        public string sourceNodeId { get; set; }
+        public string targetNodeId { get; set; }
+        public point startPoint { get; set; }
+        public point endPoint { get; set; }
+        public string properties { get; set; }
+        public List<point> pointsList { get; set; }
+    }
+
+    public class point
+    {
+        public decimal x { get; set; }
+        public decimal y { get; set; }
+    }
+}
diff --git a/Tiger.Model.Net/Entitys/MES/node.cs b/Tiger.Model.Net/Entitys/MES/node.cs
new file mode 100644
index 0000000..cf11ef7
--- /dev/null
+++ b/Tiger.Model.Net/Entitys/MES/node.cs
@@ -0,0 +1,23 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tiger.Model
+{
+    public class node
+    {
+        public string id { get; set; }
+        public string type { get; set; }
+        public decimal x { get; set; }
+        public decimal y { get; set; }
+        public string properties { get; set; }
+        public nodeText text { get; set; }
+    }
+
+    public class nodeText: point
+    {
+        public string value { get; set; }
+    }
+}
diff --git a/Tiger.Model.Net/Tiger.Model.Net.csproj b/Tiger.Model.Net/Tiger.Model.Net.csproj
index e574063..c485ec0 100644
--- a/Tiger.Model.Net/Tiger.Model.Net.csproj
+++ b/Tiger.Model.Net/Tiger.Model.Net.csproj
@@ -89,6 +89,8 @@
     <Compile Include="Entitys\DigitalTwin\Sharetronic\ShelfApiResult.cs" />
     <Compile Include="Entitys\MES\C_Stock_Info_t.cs" />
     <Compile Include="Entitys\MES\C_Stock_Pallet_T.cs" />
+    <Compile Include="Entitys\MES\edge.cs" />
+    <Compile Include="Entitys\MES\node.cs" />
     <Compile Include="Entitys\MES\R_Wip_Tracking_T.cs" />
     <Compile Include="Entitys\SYS\LOG_CS_LOGIN.cs" />
     <Compile Include="Entitys\SYS\LOG_PDA_LOGIN.cs" />

--
Gitblit v1.9.3