服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-05-30 7e25ed322740ed337296a990bac67e95bc250ac0
Tiger.Business/MES/Biz.Route.cs
@@ -10,7 +10,6 @@
using System.Linq;
using Newtonsoft.Json;
using Tiger.IBusiness;
using static Tiger.Business.Biz;
using Microsoft.AspNetCore.Http;
namespace Tiger.Business
@@ -48,22 +47,28 @@
            /// <summary>
            /// 获取工艺路线图形数据
            /// </summary>
            /// <param name="routerCode"></param>
            /// <param name="routerId"></param>
            /// <returns></returns>
            public async Task<ApiAction<RouteData>> GetRouteData(string routerCode)
            public async Task<ApiAction<RouteData>> GetRouteData(string routerId)
            {
                var res = new ApiAction<RouteData>();
                RouteData rotData = new RouteData();
                try
                {
                    if (string.IsNullOrEmpty(routerId))
                    {
                        res.IsSuccessed = false;
                        res.LocaleMsg = new($"传入的工艺路线ID为空,不能查找工艺路线!");
                        return res;
                    }
                    //工艺路线
                    var route = await Db.Queryable<MES_ROUTE>()
                        .WhereIF(!string.IsNullOrEmpty(routerCode), x => x.ROT_CODE.Equals(routerCode))
                        .WhereIF(!string.IsNullOrEmpty(routerId), x => x.ID.Equals(routerId))
                        .OrderBy(x => x.CREATE_TIME).FirstAsync();
                    rotData.route = route;
                    //节点
                    var nodes = await Db.Queryable<MES_ROUTE_NODE>()
                        .WhereIF(!string.IsNullOrEmpty(routerCode), x => x.ROT_CODE.Equals(routerCode))
                        .WhereIF(!string.IsNullOrEmpty(routerId), x => x.ROT_ID.Equals(routerId))
                        .ToListAsync();
                    foreach (var node in nodes)
                    {
@@ -84,9 +89,31 @@
                    }
                    rotData.nodes = nodes;
                    var acts = await Db.Queryable<MES_ROUTE_NODE_ACT>()
                        .WhereIF(!string.IsNullOrEmpty(routerId), x => x.ROT_ID.Equals(routerId))
                        .ToListAsync();
                    foreach (var act in acts)
                    {
                        act.node = new()
                        {
                            id = act.ID,
                            type = act.GPH_TYPE,
                            x = act.GPH_X,
                            y = act.GPH_Y,
                            properties = act.GPH_PROP,
                            text = new()
                            {
                                x = act.GPH_X,
                                y = act.GPH_Y,
                                value = act.GPH_TEXT
                            }
                        };
                    }
                    rotData.acts = acts;
                    //边
                    var edges = await Db.Queryable<MES_ROUTE_EDGE>()
                        .WhereIF(!string.IsNullOrEmpty(routerCode), x => x.ROT_CODE.Equals(routerCode))
                        .WhereIF(!string.IsNullOrEmpty(routerId), x => x.ROT_ID.Equals(routerId))
                        .ToListAsync();
                    foreach (var edge in edges)
                    {
@@ -144,15 +171,15 @@
                    var dbTran = db.UseTran(() =>
                    {
                        var y = db.Storageable(routeEdge)
                           .WhereColumns(t => new { t.EDGE_CODE, t.GHOST_ROW })
                           .WhereColumns(t => new { t.ID, t.GHOST_ROW })
                           .ToStorage();
                        y.AsInsertable.ExecuteCommand();
                        y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
                        y.AsUpdateable.ExecuteCommand();
                    });
                    if (!dbTran.IsSuccess)
                    {
                        result.IsSuccessed = false;
                        result.Message = $"保存边数据异常";
                        result.LocaleMsg = new($"保存边数据异常");
                    }
                }
                catch (Exception ex)
@@ -176,15 +203,15 @@
                    var dbTran = db.UseTran(() =>
                    {
                        var y = db.Storageable(routeNode)
                           .WhereColumns(t => new { t.NODE_CODE, t.GHOST_ROW })
                           .WhereColumns(t => new { t.ID, t.GHOST_ROW })
                           .ToStorage();
                        y.AsInsertable.ExecuteCommand();
                        y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
                        y.AsUpdateable.ExecuteCommand();
                    });
                    if (!dbTran.IsSuccess)
                    {
                        result.IsSuccessed = false;
                        result.Message = $"保存节点数据异常";
                        result.LocaleMsg = new($"保存节点数据异常");
                    }
                }
                catch (Exception ex)
@@ -195,11 +222,11 @@
            }
            /// <summary>
            /// 保存
            /// 保存行为
            /// </summary>
            /// <param name="router"></param>
            /// <param name="routeAct"></param>
            /// <returns></returns>
            public async Task<ApiAction> SaveRoute(MES_ROUTE router)
            public async Task<ApiAction> SaveActs(List<MES_ROUTE_NODE_ACT> routeAct)
            {
                var result = new ApiAction();
                try
@@ -207,7 +234,46 @@
                    var db = Db;
                    var dbTran = db.UseTran(() =>
                    {
                        var y = db.Storageable(router)
                        var y = db.Storageable(routeAct)
                           .WhereColumns(t => new { t.ID, t.GHOST_ROW })
                           .ToStorage();
                        y.AsInsertable.ExecuteCommand();
                        y.AsUpdateable.ExecuteCommand();
                    });
                    if (!dbTran.IsSuccess)
                    {
                        result.IsSuccessed = false;
                        result.LocaleMsg = new($"保存行为数据异常");
                    }
                }
                catch (Exception ex)
                {
                    result.CatchExceptionWithLog(ex, "保存行为数据异常");
                }
                return await Task.FromResult(result);
            }
            /// <summary>
            /// 保存
            /// </summary>
            /// <param name="route"></param>
            /// <returns></returns>
            public async Task<ApiAction> SaveRoute(MES_ROUTE route)
            {
                var result = new ApiAction();
                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())
                    {
                        result.IsSuccessed = false;
                        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 })
                           .ToStorage();
                        y.AsInsertable.ExecuteCommand();
@@ -236,11 +302,6 @@
                var result = new ApiAction();
                try
                {
                    var actionNode = await SaveNodes(routeData.nodes);
                    if (!actionNode.IsSuccessed) { return actionNode; }
                    var actionEdge = await SaveEdges(routeData.edges);
                    if (!actionEdge.IsSuccessed) { return actionEdge; }
                    var db = Db;
                    var dbTran = db.UseTran(() =>
                    {
@@ -252,11 +313,26 @@
                            y.AsInsertable.ExecuteCommand();
                            y.AsUpdateable.IgnoreColumns(x => x.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();
                        if (routeData.nodes != null)
                        {
                            db.Insertable(routeData.nodes).ExecuteCommand();
                        }
                        if (routeData.edges != null)
                        {
                            db.Insertable(routeData.edges).ExecuteCommand();
                        }
                        if (routeData.acts != null)
                        {
                            db.Insertable(routeData.acts).ExecuteCommand();
                        }
                    });
                    if (!dbTran.IsSuccess)
                    {
                        result.IsSuccessed = false;
                        result.Message = $"保存工艺路线图形数据异常";
                        result.LocaleMsg = new($"保存工艺路线图形数据异常");
                    }
                }
                catch (Exception ex)
@@ -265,6 +341,38 @@
                }
                return await Task.FromResult(result);
            }
            /// <summary>
            /// 删除工艺路线
            /// </summary>
            /// <param name="routeId"></param>
            /// <returns></returns>
            public async Task<ApiAction> DeleteRoute(string routeId) {
                var result = new ApiAction();
                try
                {
                    //查询是否已经有工单在用或者有绑定产品
                    var db = Db;
                    var dbTran = db.UseTran(() =>
                    {
                        db.Deleteable<MES_ROUTE_NODE>(false).Where(x => x.ROT_ID == routeId).ExecuteCommand();
                        db.Deleteable<MES_ROUTE_EDGE>(false).Where(x => x.ROT_ID == routeId).ExecuteCommand();
                        db.Deleteable<MES_ROUTE_NODE_ACT>(false).Where(x => x.ROT_ID == routeId).ExecuteCommand();
                        db.Deleteable<MES_ROUTE>().Where(x => x.ID == routeId).ExecuteCommand();
                    });
                    if (!dbTran.IsSuccess)
                    {
                        result.IsSuccessed = false;
                        result.LocaleMsg = new($"删除工艺路线异常");
                    }
                }
                catch (Exception ex)
                {
                    result.CatchExceptionWithLog(ex, "删除工艺路线异常");
                }
                return await Task.FromResult(result);
            }
        }
    }
}