服务端的TigerApi 框架,基于.NET6 2024 版本
YangYuGang
2025-04-07 7f75d4c1a1a3bd348042eb0fec8480f5df9cd1d2
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
{
@@ -387,8 +388,8 @@
                        }
                        if (!routeData.route.PROD_CODE.IsNullOrEmpty())
                        {
                            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();
                            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();
@@ -441,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(() =>
@@ -507,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)
@@ -521,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)
                    {
@@ -631,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;
            }
@@ -865,7 +922,7 @@
                        {
                            db.Insertable(routeData.acts).ExecuteCommand();
                        }
                        if (operList.Count>0)
                        if (operList.Count > 0)
                        {
                            db.Insertable(operList).ExecuteCommand();
                        }
@@ -918,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
}