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 | 287 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 261 insertions(+), 26 deletions(-) diff --git a/Tiger.Business/MES/Biz.Route.cs b/Tiger.Business/MES/Biz.Route.cs index 77ab922..56fe66c 100644 --- a/Tiger.Business/MES/Biz.Route.cs +++ b/Tiger.Business/MES/Biz.Route.cs @@ -10,8 +10,9 @@ using System.Linq; using Newtonsoft.Json; using Tiger.IBusiness; -using static Tiger.Business.Biz; using Microsoft.AspNetCore.Http; +using Tiger.Model.Entitys.WMS.DTOS; +using static Tiger.Model.BIZ_MES_WO; namespace Tiger.Business { @@ -56,14 +57,26 @@ 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(routerId), x => x.ROT_CODE.Equals(routerId)) + .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(routerId), x => x.ROT_ID.Equals(routerId)) + .WhereIF(!string.IsNullOrEmpty(route.ID), x => x.ROT_ID.Equals(route.ID)) .ToListAsync(); foreach (var node in nodes) { @@ -84,9 +97,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(routerId), x => x.ROT_ID.Equals(routerId)) + .WhereIF(!string.IsNullOrEmpty(route.ID), x => x.ROT_ID.Equals(route.ID)) .ToListAsync(); foreach (var edge in edges) { @@ -152,7 +187,7 @@ if (!dbTran.IsSuccess) { result.IsSuccessed = false; - result.Message = $"淇濆瓨杈规暟鎹紓甯�"; + result.LocaleMsg = new($"淇濆瓨杈规暟鎹紓甯�"); } } catch (Exception ex) @@ -184,7 +219,7 @@ if (!dbTran.IsSuccess) { result.IsSuccessed = false; - result.Message = $"淇濆瓨鑺傜偣鏁版嵁寮傚父"; + result.LocaleMsg = new($"淇濆瓨鑺傜偣鏁版嵁寮傚父"); } } catch (Exception ex) @@ -216,7 +251,7 @@ if (!dbTran.IsSuccess) { result.IsSuccessed = false; - result.Message = $"淇濆瓨琛屼负鏁版嵁寮傚父"; + result.LocaleMsg = new($"淇濆瓨琛屼负鏁版嵁寮傚父"); } } catch (Exception ex) @@ -229,17 +264,24 @@ /// <summary> /// 淇濆瓨 /// </summary> - /// <param name="router"></param> + /// <param name="route"></param> /// <returns></returns> - public async Task<ApiAction> SaveRoute(MES_ROUTE router) + 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(router) + var y = db.Storageable(route) .WhereColumns(t => new { t.ROT_CODE, t.GHOST_ROW }) .ToStorage(); y.AsInsertable.ExecuteCommand(); @@ -279,35 +321,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) { - var y = db.Storageable(routeData.nodes) - .WhereColumns(t => new { t.ID, t.GHOST_ROW }) - .ToStorage(); - y.AsInsertable.ExecuteCommand(); - y.AsUpdateable.ExecuteCommand(); + db.Insertable(routeData.nodes).ExecuteCommand(); } if (routeData.edges != null) { - var y = db.Storageable(routeData.edges) - .WhereColumns(t => new { t.ID, t.GHOST_ROW }) - .ToStorage(); - y.AsInsertable.ExecuteCommand(); - y.AsUpdateable.ExecuteCommand(); + db.Insertable(routeData.edges).ExecuteCommand(); } if (routeData.acts != null) { - var y = db.Storageable(routeData.acts) - .WhereColumns(t => new { t.ID, t.GHOST_ROW }) - .ToStorage(); - y.AsInsertable.ExecuteCommand(); - y.AsUpdateable.ExecuteCommand(); + db.Insertable(routeData.acts).ExecuteCommand(); } }); if (!dbTran.IsSuccess) { result.IsSuccessed = false; - result.Message = $"淇濆瓨宸ヨ壓璺嚎鍥惧舰鏁版嵁寮傚父"; + result.LocaleMsg = new($"淇濆瓨宸ヨ壓璺嚎鍥惧舰鏁版嵁寮傚父"); } } catch (Exception ex) @@ -316,6 +349,208 @@ } 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); + } + + /// <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; + } } } } -- Gitblit v1.9.3