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
{
///
/// 工艺路线
///
public partial class Router : IRouter
{
///
/// 获取工艺路线
///
///
///
public async Task>> GetRouter(string routerCode)
{
var res = new ApiAction>();
List list = new List();
try
{
list = await Db.Queryable()
.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;
}
///
/// 获取工艺路线图形数据
///
///
///
public async Task> GetRouterData(string routerCode)
{
var res = new ApiAction();
RouterData rotData = new RouterData();
try
{
//工艺路线
var route = await Db.Queryable()
.WhereIF(!string.IsNullOrEmpty(routerCode), x => x.ROT_CODE.Equals(routerCode))
.OrderBy(x => x.CREATE_TIME).FirstAsync();
rotData.route = route;
//节点
var nodes = await Db.Queryable()
.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()
.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;
}
///
/// 保存边数据
///
///
///
public async Task SaveEdges(List 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);
}
///
/// 保存节点数据
///
///
///
public async Task SaveNodes(List 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);
}
///
/// 保存
///
///
///
public async Task SaveRouter(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);
}
///
/// 保存工艺路线图形数据
///
///
///
public async Task SaveRouterData(RouterData 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);
}
}
}
}