| | |
| | | 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()) |
| | | //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) |
| | | { |
| | |
| | | y.AsInsertable.ExecuteCommand(); |
| | | y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); |
| | | } |
| | | db.Deleteable<MES_PROD_OPER>().Where(x => x.PROD_CODE == routeData.route.PROD_CODE && !SqlFunc.ContainsArray(nodeIds, x.NODE_ID)).ExecuteCommand(); |
| | | db.Deleteable<MES_PROD_ACTION>().Where(x => x.PROD_CODE == routeData.route.PROD_CODE && !SqlFunc.ContainsArray(actIds, x.ACT_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.Insertable(routeData.acts).ExecuteCommand(); |
| | | } |
| | | if (operList.Count > 0) |
| | | if (!routeData.route.PROD_CODE.IsNullOrEmpty()) |
| | | { |
| | | db.Insertable(operList).ExecuteCommand(); |
| | | } |
| | | if (actList.Count > 0) |
| | | { |
| | | db.Insertable(actList).ExecuteCommand(); |
| | | if (operList.Count > 0) |
| | | { |
| | | db.Insertable(operList).ExecuteCommand(); |
| | | } |
| | | if (actList.Count > 0) |
| | | { |
| | | db.Insertable(actList).ExecuteCommand(); |
| | | } |
| | | } |
| | | }); |
| | | if (!dbTran.IsSuccess) |
| | |
| | | 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 工单工艺路线相关 |
| | | |
| | | |