| | |
| | | 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 |
| | | { |
| | |
| | | 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(() => |
| | |
| | | { |
| | | 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) |
| | |
| | | expableOper.And(x => x.ROT_ID == item.ID); |
| | | } |
| | | } |
| | | |
| | | expable.And(x => x.PROD_CODE == input.prodCode && x.CUST_CODE == input.custCode); |
| | | expableOper.And(x => x.PROD_CODE == input.prodCode && x.CUST_CODE == input.custCode); |
| | | if (!input.prodCode.IsNullOrEmpty()) |
| | | { |
| | | 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) |
| | | { |
| | |
| | | } |
| | | 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 |
| | | } |