From c267f7c90b46efa192bd3d790691118e521510c8 Mon Sep 17 00:00:00 2001 From: Ben Lin <maobin001@msn.com> Date: 星期六, 08 三月 2025 17:11:55 +0800 Subject: [PATCH] 雅达-新增收货单处理和行审核功能 --- Tiger.Business/MES/Biz.Route.cs | 309 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 299 insertions(+), 10 deletions(-) diff --git a/Tiger.Business/MES/Biz.Route.cs b/Tiger.Business/MES/Biz.Route.cs index cd069f1..24cc730 100644 --- a/Tiger.Business/MES/Biz.Route.cs +++ b/Tiger.Business/MES/Biz.Route.cs @@ -14,6 +14,7 @@ using Tiger.Model.Entitys.WMS.DTOS; using static Tiger.Model.BIZ_MES_WO; using Tiger.Model.Entitys.MES.Position; +using System.Security.Cryptography; namespace Tiger.Business { @@ -273,20 +274,26 @@ 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) { @@ -311,6 +318,63 @@ 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(() => { @@ -321,6 +385,11 @@ .ToStorage(); 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(); @@ -336,6 +405,17 @@ 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) @@ -362,6 +442,12 @@ try { //鏌ヨ鏄惁宸茬粡鏈夊伐鍗曞湪鐢ㄦ垨鑰呮湁缁戝畾浜у搧 + if (Biz.Db.Queryable<MES_PROD_OPER>().Any(q=>q.ROT_ID == routeId)) + { + result.IsSuccessed = false; + result.LocaleMsg = new($"宸ヨ壓璺嚎宸茬粡缁戝畾浜嗕骇鍝侊紝涓嶈兘鍒犻櫎宸ヨ壓璺嚎"); + return result; + } var db = Db; var dbTran = db.UseTran(() => @@ -428,12 +514,12 @@ { var expable = Expressionable.Create<MES_PROD_ACTION>(); var expableOper = Expressionable.Create<MES_PROD_OPER>(); - if (!string.IsNullOrEmpty(input.rotId)) + if (!input.rotId.IsNullOrEmpty()) { expable.And(x => x.ROT_ID == input.rotId); expableOper.And(x => x.ROT_ID == input.rotId); } - else if (!string.IsNullOrEmpty(input.rotCode)) + else if (!input.rotCode.IsNullOrEmpty()) { var item = await Db.Queryable<MES_ROUTE>().Where(x => x.ROT_CODE == input.rotCode).FirstAsync(); if (item != null) @@ -442,18 +528,32 @@ expableOper.And(x => x.ROT_ID == item.ID); } } - if (!string.IsNullOrEmpty(input.prodCode)) + if (!input.prodCode.IsNullOrEmpty()) { - expable.And(x => x.PROD_CODE == input.prodCode); + expable.And(x => x.PROD_CODE == input.prodCode ); expableOper.And(x => x.PROD_CODE == input.prodCode); } + if (!input.custCode.IsNullOrEmpty()) + { + expable.And(x => x.CUST_CODE == input.custCode); + expableOper.And(x => x.CUST_CODE == input.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 (!input.prodCode.IsNullOrEmpty()) + { + db.Deleteable<MES_PROD_ACTION>().Where(exp).ExecuteCommand(); + db.Deleteable<MES_PROD_OPER>().Where(expOper).ExecuteCommand(); + } + if (input.prodCode.IsNullOrEmpty() && !input.custCode.IsNullOrEmpty()) + { + db.Updateable<MES_PROD_ACTION>().SetColumns(x => x.CUST_CODE == "").Where(exp).ExecuteCommand(); + db.Updateable<MES_PROD_OPER>().SetColumns(x => x.CUST_CODE == "").Where(expOper).ExecuteCommand(); + } }); if (!dbTran.IsSuccess) { @@ -552,6 +652,42 @@ 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; } @@ -699,6 +835,65 @@ 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(() => { @@ -710,6 +905,8 @@ // 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(); @@ -724,6 +921,14 @@ 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) @@ -770,6 +975,90 @@ 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; + } + + /// <summary> + /// 娣诲姞宸ュ崟宸ヨ壓璺嚎 + /// </summary> + /// <param name="input"></param> + /// <returns></returns> + public async Task<ApiAction> ProdRouteToWo(WoRotInput input) + { + var result = new ApiAction(); + try + { + //淇濆瓨鍓嶅垽鏂� + if (Db.Queryable<BIZ_MES_WO>().Any(x => x.ORDER_NO == input.wo && x.STATUS > STATUSs.Init.GetValue() && x.STATUS < STATUSs.Closed.GetValue())) { + + result.IsSuccessed = false; + result.LocaleMsg = new($"宸ュ崟[{input.wo}]鐘舵�佷笉鏄垵濮嬪寲鎴栬�呭畬鎴愶紝涓嶅彲浠ヤ慨鏀瑰伐鑹鸿矾绾匡紒"); + return result; + } + + var wo = await Db.Queryable<BIZ_MES_WO>().Where(x => x.ORDER_NO == input.wo).FirstAsync(); + wo.ROUTE_STATUS = ROUTE_STATUSs.Finish.GetValue(); + + SugarParameter[] pars = Biz.Db.Ado.GetParameters(new { ROT_ID = input.rotId, WO = input.wo, ERR_CODE = 0, ERR_MSG = "" }); + pars[2].Direction = System.Data.ParameterDirection.Output; + pars[3].Direction = System.Data.ParameterDirection.Output; + Biz.Db.Ado.UseStoredProcedure().ExecuteCommand("SP_MES_PROD2WO", pars); + result.Data = pars[2].Value; + result.IsSuccessed = pars[2].Value.ToInt32() == 0 ? true : false; + result.LocaleMsg = new(pars[3].Value.ToString()); + + var db = Db; + var dbTran = db.UseTran(() => + { + db.Updateable(wo, input.userId).UpdateColumns(x => new { x.ROUTE_STATUS, x.UPDATE_USER, x.UPDATE_TIME }).ExecuteCommand(); + }); + if (!dbTran.IsSuccess) + { + result.IsSuccessed = false; + result.LocaleMsg = new($"娣诲姞宸ュ崟宸ヨ壓璺嚎寮傚父"); + } + } + catch (Exception ex) + { + result.CatchExceptionWithLog(ex, "娣诲姞宸ュ崟宸ヨ壓璺嚎寮傚父"); + } + return result; + } } //endClass Route } //endClass Biz } -- Gitblit v1.9.3