From 800a881cec2b5e652e0a85b0897ecb64c6a8a71a Mon Sep 17 00:00:00 2001 From: Ben Lin <maobin001@msn.com> Date: 星期三, 17 七月 2024 15:41:18 +0800 Subject: [PATCH] U9C接口更新 --- Tiger.Business/MES/Biz.Route.cs | 188 +++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 166 insertions(+), 22 deletions(-) diff --git a/Tiger.Business/MES/Biz.Route.cs b/Tiger.Business/MES/Biz.Route.cs index ad36fd3..c36570e 100644 --- a/Tiger.Business/MES/Biz.Route.cs +++ b/Tiger.Business/MES/Biz.Route.cs @@ -10,7 +10,6 @@ using System.Linq; using Newtonsoft.Json; using Tiger.IBusiness; -using static Tiger.Business.Biz; using Microsoft.AspNetCore.Http; namespace Tiger.Business @@ -48,22 +47,34 @@ /// <summary> /// 鑾峰彇宸ヨ壓璺嚎鍥惧舰鏁版嵁 /// </summary> - /// <param name="routerCode"></param> + /// <param name="routerId"></param> /// <returns></returns> - public async Task<ApiAction<RouteData>> GetRouteData(string routerCode) + public async Task<ApiAction<RouteData>> GetRouteData(string routerId) { var res = new ApiAction<RouteData>(); RouteData rotData = new RouteData(); try { + if (string.IsNullOrEmpty(routerId)) + { + res.IsSuccessed = false; + res.LocaleMsg = new($"浼犲叆鐨勫伐鑹鸿矾绾縄D涓虹┖锛屼笉鑳芥煡鎵惧伐鑹鸿矾绾匡紒"); + return res; + } //宸ヨ壓璺嚎 var route = await Db.Queryable<MES_ROUTE>() - .WhereIF(!string.IsNullOrEmpty(routerCode), x => x.ROT_CODE.Equals(routerCode)) + .WhereIF(!string.IsNullOrEmpty(routerId), x => x.ID.Equals(routerId) || x.ROT_CODE == routerId) .OrderBy(x => x.CREATE_TIME).FirstAsync(); rotData.route = route; + if (route == null) + { + res.IsSuccessed = false; + res.LocaleMsg = new($"涓嶈兘鏌ユ壘鍒板伐鑹鸿矾绾匡紒"); + return res; + } //鑺傜偣 var nodes = await Db.Queryable<MES_ROUTE_NODE>() - .WhereIF(!string.IsNullOrEmpty(routerCode), x => x.ROT_CODE.Equals(routerCode)) + .WhereIF(!string.IsNullOrEmpty(route.ID), x => x.ROT_ID.Equals(route.ID)) .ToListAsync(); foreach (var node in nodes) { @@ -84,9 +95,31 @@ } rotData.nodes = nodes; + var acts = await Db.Queryable<MES_ROUTE_NODE_ACT>() + .WhereIF(!string.IsNullOrEmpty(route.ID), x => x.ROT_ID.Equals(route.ID)) + .ToListAsync(); + foreach (var act in acts) + { + act.node = new() + { + id = act.ID, + type = act.GPH_TYPE, + x = act.GPH_X, + y = act.GPH_Y, + properties = act.GPH_PROP, + text = new() + { + x = act.GPH_X, + y = act.GPH_Y, + value = act.GPH_TEXT + } + }; + } + rotData.acts = acts; + //杈� var edges = await Db.Queryable<MES_ROUTE_EDGE>() - .WhereIF(!string.IsNullOrEmpty(routerCode), x => x.ROT_CODE.Equals(routerCode)) + .WhereIF(!string.IsNullOrEmpty(route.ID), x => x.ROT_ID.Equals(route.ID)) .ToListAsync(); foreach (var edge in edges) { @@ -144,15 +177,15 @@ var dbTran = db.UseTran(() => { var y = db.Storageable(routeEdge) - .WhereColumns(t => new { t.EDGE_CODE, t.GHOST_ROW }) + .WhereColumns(t => new { t.ID, t.GHOST_ROW }) .ToStorage(); y.AsInsertable.ExecuteCommand(); - y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); + y.AsUpdateable.ExecuteCommand(); }); if (!dbTran.IsSuccess) { result.IsSuccessed = false; - result.Message = $"淇濆瓨杈规暟鎹紓甯�"; + result.LocaleMsg = new($"淇濆瓨杈规暟鎹紓甯�"); } } catch (Exception ex) @@ -176,15 +209,15 @@ var dbTran = db.UseTran(() => { var y = db.Storageable(routeNode) - .WhereColumns(t => new { t.NODE_CODE, t.GHOST_ROW }) + .WhereColumns(t => new { t.ID, t.GHOST_ROW }) .ToStorage(); y.AsInsertable.ExecuteCommand(); - y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); + y.AsUpdateable.ExecuteCommand(); }); if (!dbTran.IsSuccess) { result.IsSuccessed = false; - result.Message = $"淇濆瓨鑺傜偣鏁版嵁寮傚父"; + result.LocaleMsg = new($"淇濆瓨鑺傜偣鏁版嵁寮傚父"); } } catch (Exception ex) @@ -195,11 +228,11 @@ } /// <summary> - /// 淇濆瓨 + /// 淇濆瓨琛屼负 /// </summary> - /// <param name="router"></param> + /// <param name="routeAct"></param> /// <returns></returns> - public async Task<ApiAction> SaveRoute(MES_ROUTE router) + public async Task<ApiAction> SaveActs(List<MES_ROUTE_NODE_ACT> routeAct) { var result = new ApiAction(); try @@ -207,7 +240,46 @@ var db = Db; var dbTran = db.UseTran(() => { - var y = db.Storageable(router) + var y = db.Storageable(routeAct) + .WhereColumns(t => new { t.ID, t.GHOST_ROW }) + .ToStorage(); + y.AsInsertable.ExecuteCommand(); + y.AsUpdateable.ExecuteCommand(); + }); + if (!dbTran.IsSuccess) + { + result.IsSuccessed = false; + result.LocaleMsg = new($"淇濆瓨琛屼负鏁版嵁寮傚父"); + } + } + catch (Exception ex) + { + result.CatchExceptionWithLog(ex, "淇濆瓨琛屼负鏁版嵁寮傚父"); + } + return await Task.FromResult(result); + } + + /// <summary> + /// 淇濆瓨 + /// </summary> + /// <param name="route"></param> + /// <returns></returns> + public async Task<ApiAction> SaveRoute(MES_ROUTE route) + { + var result = new ApiAction(); + try + { + var _route = Db.Queryable<MES_ROUTE>().Where(x=>x.ROT_CODE == route.ROT_CODE).First(); + if (_route!=null && Db.Queryable<MES_ROUTE_NODE>().Where(x=>x.ROT_ID == _route.ID).Any()) + { + result.IsSuccessed = false; + result.LocaleMsg = new($"宸ヨ壓璺嚎宸茬粡鏈夎璁¤褰曪紝涓嶈兘淇濆瓨锛�"); + return result; + } + var db = Db; + var dbTran = db.UseTran(() => + { + var y = db.Storageable(route) .WhereColumns(t => new { t.ROT_CODE, t.GHOST_ROW }) .ToStorage(); y.AsInsertable.ExecuteCommand(); @@ -236,11 +308,6 @@ 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(() => { @@ -252,11 +319,26 @@ y.AsInsertable.ExecuteCommand(); y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); } + db.Deleteable<MES_ROUTE_NODE>(false).Where(x => x.ROT_ID == routeData.route.ID).ExecuteCommand(); + db.Deleteable<MES_ROUTE_EDGE>(false).Where(x => x.ROT_ID == routeData.route.ID).ExecuteCommand(); + db.Deleteable<MES_ROUTE_NODE_ACT>(false).Where(x=>x.ROT_ID == routeData.route.ID).ExecuteCommand(); + if (routeData.nodes != null) + { + db.Insertable(routeData.nodes).ExecuteCommand(); + } + if (routeData.edges != null) + { + db.Insertable(routeData.edges).ExecuteCommand(); + } + if (routeData.acts != null) + { + db.Insertable(routeData.acts).ExecuteCommand(); + } }); if (!dbTran.IsSuccess) { result.IsSuccessed = false; - result.Message = $"淇濆瓨宸ヨ壓璺嚎鍥惧舰鏁版嵁寮傚父"; + result.LocaleMsg = new($"淇濆瓨宸ヨ壓璺嚎鍥惧舰鏁版嵁寮傚父"); } } catch (Exception ex) @@ -265,6 +347,68 @@ } return await Task.FromResult(result); } + + /// <summary> + /// 鍒犻櫎宸ヨ壓璺嚎 + /// </summary> + /// <param name="routeId"></param> + /// <returns></returns> + public async Task<ApiAction> DeleteRoute(string routeId) { + var result = new ApiAction(); + try + { + //鏌ヨ鏄惁宸茬粡鏈夊伐鍗曞湪鐢ㄦ垨鑰呮湁缁戝畾浜у搧 + + var db = Db; + var dbTran = db.UseTran(() => + { + db.Deleteable<MES_ROUTE_NODE>(false).Where(x => x.ROT_ID == routeId).ExecuteCommand(); + db.Deleteable<MES_ROUTE_EDGE>(false).Where(x => x.ROT_ID == routeId).ExecuteCommand(); + db.Deleteable<MES_ROUTE_NODE_ACT>(false).Where(x => x.ROT_ID == routeId).ExecuteCommand(); + db.Deleteable<MES_ROUTE>().Where(x => x.ID == routeId).ExecuteCommand(); + }); + if (!dbTran.IsSuccess) + { + result.IsSuccessed = false; + result.LocaleMsg = new($"鍒犻櫎宸ヨ壓璺嚎寮傚父"); + } + } + catch (Exception ex) + { + result.CatchExceptionWithLog(ex, "鍒犻櫎宸ヨ壓璺嚎寮傚父"); + } + return await Task.FromResult(result); + } + + /// <summary> + /// 淇濆瓨鑺傜偣宀椾綅璧勬簮 + /// </summary> + /// <param name="nodePost"></param> + /// <returns></returns> + public async Task<ApiAction> SaveRouteNodePost(List<MES_ROUTE_NODE_POST> nodePost) { + var result = new ApiAction(); + try + { + var db = Db; + var dbTran = db.UseTran(() => + { + var y = db.Storageable(nodePost) + .ToStorage(); + y.AsInsertable.ExecuteCommand(); + y.AsUpdateable.ExecuteCommand(); + }); + if (!dbTran.IsSuccess) + { + result.IsSuccessed = false; + result.LocaleMsg = new($"淇濆瓨鑺傜偣宀椾綅璧勬簮鏁版嵁寮傚父"); + } + } + catch (Exception ex) + { + result.CatchExceptionWithLog(ex, "淇濆瓨鑺傜偣宀椾綅璧勬簮鏁版嵁寮傚父"); + } + return await Task.FromResult(result); + } } } } -- Gitblit v1.9.3