| | |
| | | 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 |
| | | { |
| | |
| | | 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); |
| | | } |
| | | 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 result = new ApiAction(); |
| | | try |
| | | { |
| | | var item = await Biz.Db.Queryable<BAS_ITEM>().ByAuth(input.options).Where(x=>x.ITEM_CODE == input.prodCode).FirstAsync(); |
| | | 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: ""; |
| | | item.DEFAULT_ROUTE = input.isDefault ? input.rotCode : ""; |
| | | var db = Db; |
| | | var dbTran = db.UseTran(() => |
| | | { |
| | | db.Updateable(item).UpdateColumns(q=> new { q.DEFAULT_ROUTE}).ExecuteCommand(); |
| | | db.Updateable(item).UpdateColumns(q => new { q.DEFAULT_ROUTE }).ExecuteCommand(); |
| | | }); |
| | | if (!dbTran.IsSuccess) |
| | | { |
| | |
| | | { |
| | | db.Insertable(routeData.acts).ExecuteCommand(); |
| | | } |
| | | if (operList.Count>0) |
| | | if (operList.Count > 0) |
| | | { |
| | | db.Insertable(operList).ExecuteCommand(); |
| | | } |
| | |
| | | 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 |
| | | } |