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="routerId"></param>
|
/// <returns></returns>
|
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(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(routerId), x => x.ROT_ID.Equals(routerId))
|
.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 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(routerId), x => x.ROT_ID.Equals(routerId))
|
.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.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="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.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="routeAct"></param>
|
/// <returns></returns>
|
public async Task<ApiAction> SaveActs(List<MES_ROUTE_NODE_ACT> routeAct)
|
{
|
var result = new ApiAction();
|
try
|
{
|
var db = Db;
|
var dbTran = db.UseTran(() =>
|
{
|
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();
|
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 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();
|
}
|
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.LocaleMsg = new($"保存工艺路线图形数据异常");
|
}
|
}
|
catch (Exception ex)
|
{
|
result.CatchExceptionWithLog(ex, "保存工艺路线图形数据异常");
|
}
|
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);
|
}
|
}
|
}
|
}
|