| | |
| | | using Newtonsoft.Json; |
| | | using Tiger.IBusiness; |
| | | using Microsoft.AspNetCore.Http; |
| | | using Tiger.Model.Entitys.WMS.DTOS; |
| | | using static Tiger.Model.BIZ_MES_WO; |
| | | using Tiger.Model.Entitys.MES.Position; |
| | | |
| | | namespace Tiger.Business |
| | | { |
| | |
| | | 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()) |
| | | 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; |
| | | //} |
| | | if (_route != null && Db.Queryable<MES_PROD_OPER>().Where(x => x.ROT_ID == _route.ID).Any()) |
| | | { |
| | | result.IsSuccessed = false; |
| | | result.LocaleMsg = new($"工艺路线已经有设计记录,不能保存!"); |
| | | 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 }) |
| | | //.WhereColumns(t => new { t.ROT_CODE, t.GHOST_ROW }) |
| | | .ToStorage(); |
| | | y.AsInsertable.ExecuteCommand(); |
| | | y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); |
| | | y.AsUpdateable.ExecuteCommand(); |
| | | }); |
| | | if (!dbTran.IsSuccess) |
| | | { |
| | |
| | | var result = new ApiAction(); |
| | | try |
| | | { |
| | | var nodeIds = routeData.nodes.Select(x => x.ID).ToList(); |
| | | var actIds = routeData.acts.Select(x => x.ID).ToList(); |
| | | //如果工序节点ID没在产品工序里就新增 |
| | | List<MES_PROD_OPER> operList = new List<MES_PROD_OPER>(); |
| | | foreach (var node in routeData.nodes) |
| | | { |
| | | if (!Db.Queryable<MES_PROD_OPER>().Any(q => q.NODE_ID == node.ID && q.ROT_ID == routeData.route.ID)) |
| | | { |
| | | operList.Add(new() |
| | | { |
| | | PROD_CODE = routeData.route.PROD_CODE, |
| | | CUST_CODE = routeData.route.CUST_CODE, |
| | | NODE_ID = node.ID, |
| | | NODE_NAME = node.NODE_NAME, |
| | | ROT_ID = node.ROT_ID, |
| | | OPER_CODE = node.OPER_CODE, |
| | | IS_ACTIVE = "Y", |
| | | CAN_SKIP = "N", |
| | | IS_CALC_FPY = "N", |
| | | ALLOW_DFT_IN = "N", |
| | | IS_INPUT = "N", |
| | | IS_OUTPUT = "N", |
| | | AUTH_ORG = node.AUTH_ORG, |
| | | AUTH_PROD = node.AUTH_PROD, |
| | | AUTH_WH = node.AUTH_WH, |
| | | }); |
| | | } |
| | | } |
| | | //如果行为节点ID没在产品行为里就新增 |
| | | List<MES_PROD_ACTION> actList = new List<MES_PROD_ACTION>(); |
| | | foreach (var act in routeData.acts) |
| | | { |
| | | if (!Db.Queryable<MES_PROD_ACTION>().Any(q => q.ACT_ID == act.ID && q.ROT_ID == routeData.route.ID)) |
| | | { |
| | | actList.Add(new() |
| | | { |
| | | PROD_CODE = routeData.route.PROD_CODE, |
| | | CUST_CODE = routeData.route.CUST_CODE, |
| | | NODE_ID = act.NODE_ID, |
| | | ACT_ID = act.ID, |
| | | ACT_TYPE = act.ACT_TYPE, |
| | | ROT_ID = act.ROT_ID, |
| | | ACT_CODE = act.ACT_CODE, |
| | | RULE_CODE = "", |
| | | ITEM_CODE = "", |
| | | TEST_CODE = "", |
| | | SAPL_CODE = "", |
| | | LABEL_CODE = "", |
| | | PKG_CODE = "", |
| | | IS_ACTIVE = "Y", |
| | | SETUP_FINISH = "N", |
| | | AUTH_ORG = act.AUTH_ORG, |
| | | AUTH_PROD = act.AUTH_PROD, |
| | | AUTH_WH = act.AUTH_WH, |
| | | }); |
| | | } |
| | | } |
| | | var db = Db; |
| | | var dbTran = db.UseTran(() => |
| | | { |
| | |
| | | y.AsInsertable.ExecuteCommand(); |
| | | y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); |
| | | } |
| | | if (!routeData.route.PROD_CODE.IsNullOrEmpty()) |
| | | { |
| | | db.Deleteable<MES_PROD_OPER>().Where(x => x.ROT_ID == routeData.route.ID && x.PROD_CODE == routeData.route.PROD_CODE && !SqlFunc.ContainsArray(nodeIds, x.NODE_ID)).ExecuteCommand(); |
| | | db.Deleteable<MES_PROD_ACTION>().Where(x => x.ROT_ID == routeData.route.ID && x.PROD_CODE == routeData.route.PROD_CODE && !SqlFunc.ContainsArray(actIds, x.ACT_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(); |
| | | 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.acts != null) |
| | | { |
| | | db.Insertable(routeData.acts).ExecuteCommand(); |
| | | } |
| | | if (!routeData.route.PROD_CODE.IsNullOrEmpty()) |
| | | { |
| | | if (operList.Count > 0) |
| | | { |
| | | db.Insertable(operList).ExecuteCommand(); |
| | | } |
| | | if (actList.Count > 0) |
| | | { |
| | | db.Insertable(actList).ExecuteCommand(); |
| | | } |
| | | } |
| | | }); |
| | | if (!dbTran.IsSuccess) |
| | |
| | | /// </summary> |
| | | /// <param name="routeId"></param> |
| | | /// <returns></returns> |
| | | public async Task<ApiAction> DeleteRoute(string routeId) { |
| | | public async Task<ApiAction> DeleteRoute(string routeId) |
| | | { |
| | | var result = new ApiAction(); |
| | | try |
| | | { |
| | |
| | | /// </summary> |
| | | /// <param name="nodePost"></param> |
| | | /// <returns></returns> |
| | | public async Task<ApiAction> SaveRouteNodePost(List<MES_ROUTE_NODE_POST> nodePost) { |
| | | public async Task<ApiAction> SaveRouteNodePost(List<MES_ROUTE_NODE_POST> nodePost) |
| | | { |
| | | var result = new ApiAction(); |
| | | try |
| | | { |
| | |
| | | } |
| | | 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); |
| | | } |
| | | } |
| | | string _custCode = input.custCode ?? ""; |
| | | expable.And(x => x.PROD_CODE == input.prodCode && (x.CUST_CODE == _custCode)); |
| | | expableOper.And(x => x.PROD_CODE == input.prodCode && x.CUST_CODE == _custCode); |
| | | |
| | | 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; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 保存默认工艺路线到产品 |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public async Task<ApiAction> SetDefaultRoute(ProdRotInput input) |
| | | { |
| | | var result = new ApiAction(); |
| | | try |
| | | { |
| | | var item = await Biz.Db.Queryable<BAS_ITEM>().ByAuth(input.options).Where(x => x.ITEM_CODE == input.prodCode).FirstAsync(); |
| | | if (item == null) |
| | | { |
| | | result.IsSuccessed = false; |
| | | result.LocaleMsg = new($"产品[{input.prodCode}]不存在!"); |
| | | return result; |
| | | } |
| | | item.DEFAULT_ROUTE = input.isDefault ? input.rotCode : ""; |
| | | var db = Db; |
| | | var dbTran = db.UseTran(() => |
| | | { |
| | | db.Updateable(item).UpdateColumns(q => new { q.DEFAULT_ROUTE }).ExecuteCommand(); |
| | | }); |
| | | if (!dbTran.IsSuccess) |
| | | { |
| | | result.IsSuccessed = false; |
| | | result.LocaleMsg = new($"保存默认工艺路线到产品异常"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | result.CatchExceptionWithLog(ex, "保存默认工艺路线到产品异常"); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | #region 工单工艺路线相关 |
| | | |
| | | |
| | | /// <summary> |
| | | /// 获取工单工艺路线图形数据 |
| | | /// </summary> |
| | | /// <param name="workorder"></param> |
| | | /// <returns></returns> |
| | | public async Task<ApiAction<WoRouteData>> GetWoRouteData(string workorder) |
| | | { |
| | | var res = new ApiAction<WoRouteData>(); |
| | | WoRouteData rotData = new WoRouteData(); |
| | | try |
| | | { |
| | | if (string.IsNullOrEmpty(workorder)) |
| | | { |
| | | res.IsSuccessed = false; |
| | | res.LocaleMsg = new($"传入的工艺路线ID为空,不能查找工艺路线!"); |
| | | return res; |
| | | } |
| | | //工艺路线 |
| | | var route = await Db.Queryable<BIZ_MES_WO, MES_ROUTE>((q, s) => new JoinQueryInfos(JoinType.Inner, q.ROUTE_CODE == s.ROT_CODE)) |
| | | .Where((q, s) => q.ID.Equals(workorder) || q.ORDER_NO == workorder).Select((q, s) => new MES_ROUTE |
| | | { |
| | | ID = s.ID, |
| | | ROT_CODE = s.ROT_CODE, |
| | | ROT_NAME = s.ROT_NAME, |
| | | ROT_TYPE = s.ROT_TYPE, |
| | | ROT_VER = s.ROT_VER, |
| | | IS_ACTIVE = s.IS_ACTIVE, |
| | | REMARK = s.REMARK, |
| | | WORK_ORDER = q.ORDER_NO, |
| | | PROD_CODE = q.ITEM_CODE, |
| | | CUST_CODE = q.CUST_CODE, |
| | | }).FirstAsync(); |
| | | rotData.route = route; |
| | | if (route == null) |
| | | { |
| | | res.IsSuccessed = false; |
| | | res.LocaleMsg = new($"不能查找到工单工艺路线!"); |
| | | return res; |
| | | } |
| | | //节点 |
| | | var nodes = await Db.Queryable<MES_WO_NODE>() |
| | | .WhereIF(!string.IsNullOrEmpty(route.ID), x => x.WORK_ORDER.Equals(route.WORK_ORDER)) |
| | | .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 acts = await Db.Queryable<MES_WO_NODE_ACT>() |
| | | .WhereIF(!string.IsNullOrEmpty(route.ID), x => x.WORK_ORDER.Equals(route.WORK_ORDER)) |
| | | .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_WO_EDGE>() |
| | | .WhereIF(!string.IsNullOrEmpty(route.ID), x => x.WORK_ORDER.Equals(route.WORK_ORDER)) |
| | | .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="routeData"></param> |
| | | /// <returns></returns> |
| | | public async Task<ApiAction> SaveWoRouteData(WoRouteData routeData) |
| | | { |
| | | var result = new ApiAction(); |
| | | try |
| | | { |
| | | var nodeIds = routeData.nodes.Select(x => x.ID).ToList(); |
| | | var actIds = routeData.acts.Select(x => x.ID).ToList(); |
| | | //如果工序节点ID没在工单工序里就新增 |
| | | List<MES_WO_OPER> operList = new List<MES_WO_OPER>(); |
| | | foreach (var node in routeData.nodes) |
| | | { |
| | | if (!Db.Queryable<MES_WO_OPER>().Any(q => q.NODE_ID == node.ID)) |
| | | { |
| | | operList.Add(new() |
| | | { |
| | | WORK_ORDER = node.WORK_ORDER, |
| | | PROD_CODE = node.PROD_CODE, |
| | | CUST_CODE = node.CUST_CODE, |
| | | NODE_ID = node.ID, |
| | | NODE_NAME = node.NODE_NAME, |
| | | ROT_ID = node.ROT_ID, |
| | | OPER_CODE = node.OPER_CODE, |
| | | IS_ACTIVE = "Y", |
| | | CAN_SKIP = "N", |
| | | IS_CALC_FPY = "N", |
| | | ALLOW_DFT_IN = "N", |
| | | IS_INPUT = "N", |
| | | IS_OUTPUT = "N", |
| | | AUTH_ORG = node.AUTH_ORG, |
| | | AUTH_PROD = node.AUTH_PROD, |
| | | AUTH_WH = node.AUTH_WH, |
| | | }); |
| | | } |
| | | } |
| | | //如果行为节点ID没在工单行为里就新增 |
| | | List<MES_WO_ACTION> actList = new List<MES_WO_ACTION>(); |
| | | foreach (var act in routeData.acts) |
| | | { |
| | | if (!Db.Queryable<MES_WO_ACTION>().Any(q => q.ACT_ID == act.ID)) |
| | | { |
| | | actList.Add(new() |
| | | { |
| | | WORK_ORDER = act.WORK_ORDER, |
| | | PROD_CODE = act.PROD_CODE, |
| | | CUST_CODE = act.CUST_CODE, |
| | | NODE_ID = act.NODE_ID, |
| | | ACT_ID = act.ID, |
| | | ACT_TYPE = act.ACT_TYPE, |
| | | ROT_ID = act.ROT_ID, |
| | | ACT_CODE = act.ACT_CODE, |
| | | RULE_CODE = "", |
| | | ITEM_CODE = "", |
| | | TEST_CODE = "", |
| | | SAPL_CODE = "", |
| | | LABEL_CODE = "", |
| | | PKG_CODE = "", |
| | | IS_ACTIVE = "Y", |
| | | SETUP_FINISH = "N", |
| | | AUTH_ORG = act.AUTH_ORG, |
| | | AUTH_PROD = act.AUTH_PROD, |
| | | AUTH_WH = act.AUTH_WH, |
| | | }); |
| | | } |
| | | } |
| | | 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(); |
| | | //} |
| | | db.Deleteable<MES_WO_OPER>().Where(x => x.WORK_ORDER == routeData.route.WORK_ORDER && !SqlFunc.ContainsArray(nodeIds, x.NODE_ID)).ExecuteCommand(); |
| | | db.Deleteable<MES_WO_ACTION>().Where(x => x.WORK_ORDER == routeData.route.WORK_ORDER && !SqlFunc.ContainsArray(actIds, x.ACT_ID)).ExecuteCommand(); |
| | | db.Deleteable<MES_WO_NODE>(false).Where(x => x.WORK_ORDER == routeData.route.WORK_ORDER).ExecuteCommand(); |
| | | db.Deleteable<MES_WO_EDGE>(false).Where(x => x.WORK_ORDER == routeData.route.WORK_ORDER).ExecuteCommand(); |
| | | db.Deleteable<MES_WO_NODE_ACT>(false).Where(x => x.WORK_ORDER == routeData.route.WORK_ORDER).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 (operList.Count > 0) |
| | | { |
| | | db.Insertable(operList).ExecuteCommand(); |
| | | } |
| | | if (actList.Count > 0) |
| | | { |
| | | db.Insertable(actList).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> SaveWoRouteNodePost(List<MES_WO_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); |
| | | } |
| | | #endregion |
| | | /// <summary> |
| | | /// 获取工艺路线树形结构 |
| | | /// </summary> |
| | | /// <param name="prodCode"></param> |
| | | /// <param name="orgCode"></param> |
| | | /// <returns></returns> |
| | | public async Task<List<V_MES_ROUTE_PTREE>> GetRoutePTree(string prodCode, string orgCode) |
| | | { |
| | | var result = new List<V_MES_ROUTE_PTREE>(); |
| | | try |
| | | { |
| | | |
| | | SugarParameter[] pars = Biz.Db.Ado.GetParameters(new { PROD_CODE = prodCode, ORG_CODE = orgCode }); |
| | | result = Biz.Db.Ado.UseStoredProcedure().SqlQuery<V_MES_ROUTE_PTREE>("SP_MES_GET_ROUTE_PTREE", pars);//返回List |
| | | var item = await Db.Queryable<BAS_ITEM>().Where(q => q.ITEM_CODE == prodCode).FirstAsync(); |
| | | if (item != null && !item.DEFAULT_ROUTE.IsNullOrEmpty()) |
| | | { |
| | | var pid = result.Where(q => q.code == $"DefaultRoute_{orgCode}_{prodCode}").Select(q => q.tid).FirstOrDefault(); |
| | | result.ForEach(d => |
| | | { |
| | | if (d.pid == pid && d.code == item.DEFAULT_ROUTE) |
| | | { |
| | | d.isDefault = true; |
| | | } |
| | | else |
| | | { |
| | | d.isDefault = false; |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Logger.Default.Error(ex, "保存默认工艺路线到产品异常"); |
| | | } |
| | | return result; |
| | | } |
| | | } //endClass Route |
| | | } //endClass Biz |
| | | } |