using Tiger.Model;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq.Expressions;
|
using System.Text;
|
using System.Threading.Tasks;
|
using Rhea.Common;
|
using System.Net;
|
using System.Linq;
|
using Newtonsoft.Json;
|
using Tiger.IBusiness;
|
using static Tiger.Business.Biz;
|
using Microsoft.AspNetCore.Http;
|
|
namespace Tiger.Business
|
{
|
public partial class Biz
|
{
|
/// <summary>
|
/// 工艺路线
|
/// </summary>
|
public partial class Route : IRoute
|
{
|
/// <summary>
|
/// 获取工艺路线
|
/// </summary>
|
/// <param name="routerCode"></param>
|
/// <returns></returns>
|
public async Task<ApiAction<List<MES_ROUTE>>> GetRoute(string routerCode)
|
{
|
var res = new ApiAction<List<MES_ROUTE>>();
|
List<MES_ROUTE> list = new List<MES_ROUTE>();
|
try
|
{
|
list = await Db.Queryable<MES_ROUTE>()
|
.WhereIF(!string.IsNullOrEmpty(routerCode), x => x.ROT_CODE.Equals(routerCode))
|
.OrderBy(x => x.CREATE_TIME).ToListAsync();
|
}
|
catch (Exception ex)
|
{
|
res.CatchExceptionWithLog(ex, "查询异常");
|
}
|
res.Data = list;
|
return res;
|
}
|
|
/// <summary>
|
/// 获取工艺路线图形数据
|
/// </summary>
|
/// <param name="routerCode"></param>
|
/// <returns></returns>
|
public async Task<ApiAction<RouteData>> GetRouteData(string routerCode)
|
{
|
var res = new ApiAction<RouteData>();
|
RouteData rotData = new RouteData();
|
try
|
{
|
//工艺路线
|
var route = await Db.Queryable<MES_ROUTE>()
|
.WhereIF(!string.IsNullOrEmpty(routerCode), x => x.ROT_CODE.Equals(routerCode))
|
.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))
|
.ToListAsync();
|
foreach (var node in nodes)
|
{
|
node.node = new()
|
{
|
id = node.ID,
|
type = node.GPH_TYPE,
|
x = node.GPH_X,
|
y = node.GPH_Y,
|
properties = node.GPH_PROP,
|
text = new()
|
{
|
x = node.GPH_X,
|
y = node.GPH_Y,
|
value = node.GPH_TEXT
|
}
|
};
|
}
|
rotData.nodes = nodes;
|
|
//边
|
var edges = await Db.Queryable<MES_ROUTE_EDGE>()
|
.WhereIF(!string.IsNullOrEmpty(routerCode), x => x.ROT_CODE.Equals(routerCode))
|
.ToListAsync();
|
foreach (var edge in edges)
|
{
|
edge.edge = new()
|
{
|
id = edge.ID,
|
type = edge.GPH_TYPE,
|
sourceNodeId = edge.SRC_NODE,
|
targetNodeId = edge.TGT_NODE,
|
properties = edge.GPH_PROP,
|
startPoint = new()
|
{
|
x = edge.GPH_SRC_X,
|
y = edge.GPH_SRC_Y,
|
},
|
endPoint = new()
|
{
|
x = edge.GPH_TGT_X,
|
y = edge.GPH_TGT_Y,
|
},
|
pointsList = new()
|
{
|
new(){
|
x = edge.GPH_SRC_X,
|
y = edge.GPH_SRC_Y,
|
},
|
new(){
|
x = edge.GPH_TGT_X,
|
y = edge.GPH_TGT_Y,
|
}
|
}
|
};
|
}
|
rotData.edges = edges;
|
}
|
catch (Exception ex)
|
{
|
res.CatchExceptionWithLog(ex, "查询异常");
|
}
|
res.Data = rotData;
|
return res;
|
}
|
|
/// <summary>
|
/// 保存边数据
|
/// </summary>
|
/// <param name="routeEdge"></param>
|
/// <returns></returns>
|
public async Task<ApiAction> SaveEdges(List<MES_ROUTE_EDGE> routeEdge)
|
{
|
var result = new ApiAction();
|
try
|
{
|
var db = Db;
|
var dbTran = db.UseTran(() =>
|
{
|
var y = db.Storageable(routeEdge)
|
.WhereColumns(t => new { t.EDGE_CODE, t.GHOST_ROW })
|
.ToStorage();
|
y.AsInsertable.ExecuteCommand();
|
y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
|
});
|
if (!dbTran.IsSuccess)
|
{
|
result.IsSuccessed = false;
|
result.Message = $"保存边数据异常";
|
}
|
}
|
catch (Exception ex)
|
{
|
result.CatchExceptionWithLog(ex, "保存边数据异常");
|
}
|
return await Task.FromResult(result);
|
}
|
|
/// <summary>
|
/// 保存节点数据
|
/// </summary>
|
/// <param name="routeNode"></param>
|
/// <returns></returns>
|
public async Task<ApiAction> SaveNodes(List<MES_ROUTE_NODE> routeNode)
|
{
|
var result = new ApiAction();
|
try
|
{
|
var db = Db;
|
var dbTran = db.UseTran(() =>
|
{
|
var y = db.Storageable(routeNode)
|
.WhereColumns(t => new { t.NODE_CODE, t.GHOST_ROW })
|
.ToStorage();
|
y.AsInsertable.ExecuteCommand();
|
y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
|
});
|
if (!dbTran.IsSuccess)
|
{
|
result.IsSuccessed = false;
|
result.Message = $"保存节点数据异常";
|
}
|
}
|
catch (Exception ex)
|
{
|
result.CatchExceptionWithLog(ex, "保存节点数据异常");
|
}
|
return await Task.FromResult(result);
|
}
|
|
/// <summary>
|
/// 保存
|
/// </summary>
|
/// <param name="router"></param>
|
/// <returns></returns>
|
public async Task<ApiAction> SaveRoute(MES_ROUTE router)
|
{
|
var result = new ApiAction();
|
try
|
{
|
var db = Db;
|
var dbTran = db.UseTran(() =>
|
{
|
var y = db.Storageable(router)
|
.WhereColumns(t => new { t.ROT_CODE, t.GHOST_ROW })
|
.ToStorage();
|
y.AsInsertable.ExecuteCommand();
|
y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
|
});
|
if (!dbTran.IsSuccess)
|
{
|
result.IsSuccessed = false;
|
result.Message = $"保存工艺路线异常";
|
}
|
}
|
catch (Exception ex)
|
{
|
result.CatchExceptionWithLog(ex, "保存工艺路线异常");
|
}
|
return await Task.FromResult(result);
|
}
|
|
/// <summary>
|
/// 保存工艺路线图形数据
|
/// </summary>
|
/// <param name="routeData"></param>
|
/// <returns></returns>
|
public async Task<ApiAction> SaveRouteData(RouteData routeData)
|
{
|
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(() =>
|
{
|
if (routeData.route != null)
|
{
|
var y = db.Storageable(routeData.route)
|
.WhereColumns(t => new { t.ROT_CODE, t.GHOST_ROW })
|
.ToStorage();
|
y.AsInsertable.ExecuteCommand();
|
y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
|
}
|
});
|
if (!dbTran.IsSuccess)
|
{
|
result.IsSuccessed = false;
|
result.Message = $"保存工艺路线图形数据异常";
|
}
|
}
|
catch (Exception ex)
|
{
|
result.CatchExceptionWithLog(ex, "保存工艺路线图形数据异常");
|
}
|
return await Task.FromResult(result);
|
}
|
}
|
}
|
}
|