1052 lines
41 KiB
C#
1052 lines
41 KiB
C#
using DocumentFormat.OpenXml.Drawing.Spreadsheet;
|
||
using Learun.Application.Organization;
|
||
using Learun.Application.TwoDevelopment.ZZDT_EC;
|
||
using Learun.Application.TwoDevelopment.ZZDT_EC.Frame;
|
||
using Learun.Cache.Base;
|
||
using Learun.Cache.Factory;
|
||
using Learun.Loger;
|
||
using Learun.Util;
|
||
using Learun.Util.SqlSugar;
|
||
using log4net.Config;
|
||
using Microsoft.Practices.ObjectBuilder2;
|
||
using Newtonsoft.Json;
|
||
using Org.BouncyCastle.Bcpg.OpenPgp;
|
||
using Pipelines.Sockets.Unofficial.Arenas;
|
||
using SqlSugar;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data.Entity.Infrastructure;
|
||
using System.Diagnostics;
|
||
using System.Linq;
|
||
using System.Web.Http;
|
||
using static Learun.Application.TwoDevelopment.ZZDT_EC.IO_WorkFlowService;
|
||
|
||
namespace Learun.Application.Web.AppApi
|
||
{
|
||
/// <summary>
|
||
/// IO模块(By YuXH)
|
||
/// </summary>
|
||
[HandlerApiLogin(FilterMode.Ignore)]
|
||
public class IOModuleApiController : WebApiControllerBase
|
||
{
|
||
#region 模块对象
|
||
private ec_CableBLL ec_CableBLL = new ec_CableBLL();
|
||
|
||
private ec_PanelBLL ec_PanelBLL = new ec_PanelBLL();
|
||
private ec_PanelStripBLL ec_PanelStripBLL = new ec_PanelStripBLL();
|
||
private ec_PanelStripTermBLL ec_PanelStripTermBLL = new ec_PanelStripTermBLL();
|
||
private ec_PanelChannelBLL ec_PanelChannelBLL = new ec_PanelChannelBLL();
|
||
#endregion
|
||
|
||
#region 信号相关
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 找到某一个预分配箱子 附近的某一个箱子
|
||
/// <param name="frameLists"/>
|
||
/// <param name="allPanel"/>
|
||
/// <param name="IOTypeOnCable">Digital,4-20mA,10v,pt100,pulse</param>
|
||
/// <param name="PreAssignPanelID"/>
|
||
/// </summary>
|
||
|
||
private ec_PanelEntity FindPanelNearby(List<FrameBll.FrameList> frameLists, List<ec_PanelEntity> allPanel, List<ec_enginedata_propertyEntity> allPanelProps
|
||
, string IOTypeOnCable)
|
||
{
|
||
//当前预分配的箱子的位置
|
||
var AssignPanelX = allPanelProps.FirstOrDefault(x => x.PropertyName == GlobalObject.propName_Frame)?.PropertyValue;
|
||
AssignPanelX = AssignPanelX.Split(new string[] { GlobalObject.enum_separator }, StringSplitOptions.None)[0];//插件端对于下拉列表 都是 name || nameEN
|
||
var AssignPanelXValue = frameLists.FirstOrDefault(X => X.Num == AssignPanelX)?.Value;
|
||
if (AssignPanelXValue < 400)//null也没事
|
||
{
|
||
// 小于400,我几乎可以认为此时肋位号用的是m这个单位。因为如果用的是mm,400mm的肋位号似乎也太小了。
|
||
AssignPanelXValue = 1000 * AssignPanelXValue; // 转成mm
|
||
}
|
||
var AssignPanelXOff = allPanelProps.FirstOrDefault(x => x.PropertyName == GlobalObject.propName_FrameOff)?.PropertyValue;
|
||
|
||
var AssignPanelY = allPanelProps.FirstOrDefault(x => x.PropertyName == GlobalObject.propName_YOff)?.PropertyValue;
|
||
|
||
foreach (var panel in allPanel)
|
||
{
|
||
//拿到每一个的xy属性
|
||
//然后和预分配箱子进行对比
|
||
//这也太耗时了把
|
||
}
|
||
//然后排序一次
|
||
|
||
//根据电缆上的信号,去找匹配的排序第一位(已经按照距离排序过)的箱子
|
||
switch (IOTypeOnCable.ToUpper())
|
||
{
|
||
case "DIGITAL":
|
||
//其他就近箱子的 allowIOTypes里有DI DO
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// IO分配主界面查询,查询所有的位置 - 采集箱 - 模块 - 通道
|
||
/// </summary>
|
||
/// <param name="projectId"></param>
|
||
/// <returns></returns>
|
||
public IHttpActionResult GetPanelTree(string projectId)
|
||
{
|
||
|
||
//2023 05 22,从用户所在的role的lr base authorize里去查
|
||
//UserInfo userInfo = LoginUserInfo.Get();
|
||
//UserRelationIBLL userRelationIBLL = new UserRelationBLL();
|
||
//var roles = userRelationIBLL.GetObjectIds(userInfo.userId, 1, projectId);
|
||
var stopWatch = new Stopwatch();
|
||
var Locations = GetLocList(projectId);
|
||
if (Locations == null)
|
||
{
|
||
return Fail("系统设置中找不到“系统柜位置”这一项内容。联系管理员");
|
||
}
|
||
var ec_PanelStripTermService = new ec_PanelStripTermBLL();
|
||
var ec_WireTerminalService = new ec_WireTerminalService();
|
||
var ec_Wire_GroupService = new ec_Wire_GroupBLL();
|
||
stopWatch.Start();
|
||
var Panels = ec_PanelBLL.GetList("{ProjectId:\"" + projectId + "\"}").OrderBy(x => x.TagNumber).ToList();
|
||
stopWatch.Stop();
|
||
this.Logger.Info($"Panel查询 {stopWatch.ElapsedMilliseconds}" + "\r\n");
|
||
stopWatch.Start();
|
||
var Strips = ec_PanelStripBLL.GetList("{ProjectId:\"" + projectId + "\"}").OrderBy(x => x.Panel_Strip_Seq).OrderBy(x => x.StripName);
|
||
stopWatch.Stop();
|
||
this.Logger.Info($"Strip查询 {stopWatch.ElapsedMilliseconds}" + "\r\n");
|
||
stopWatch.Start();
|
||
var Channels = ec_PanelChannelBLL.GetList("{ProjectId:\"" + projectId + "\"}");
|
||
stopWatch.Stop();
|
||
this.Logger.Info($"Channel查询 {stopWatch.ElapsedMilliseconds}" + "\r\n");
|
||
stopWatch.Start();
|
||
var AllTerms = ec_PanelStripTermService.GetList("{ProjectId:\"" + projectId + "\"}");
|
||
stopWatch.Stop();
|
||
this.Logger.Info($"Term查询 {stopWatch.ElapsedMilliseconds}" + "\r\n");
|
||
stopWatch.Start();
|
||
var AllWTs = ec_WireTerminalService.GetList("{ProjectId:\"" + projectId + "\"}", true);
|
||
stopWatch.Stop();
|
||
this.Logger.Info($"WireTerminal查询 {stopWatch.ElapsedMilliseconds}" + "\r\n");
|
||
stopWatch.Start();
|
||
var AllSignals = ec_Wire_GroupService.GetList("{ProjectId:\"" + projectId + "\"}", true);
|
||
stopWatch.Stop();
|
||
this.Logger.Info($"Signals查询 {stopWatch.ElapsedMilliseconds}" + "\r\n");
|
||
stopWatch.Start();
|
||
List<TreeModel> treeList = new List<TreeModel>();
|
||
foreach (var Loc in Locations)
|
||
{
|
||
TreeModel nodeCatalogue = new TreeModel();
|
||
nodeCatalogue.id = Loc.DataItemDetailID;
|
||
nodeCatalogue.text = Loc.DataItemName;
|
||
nodeCatalogue.value = Loc.DataItemName;
|
||
nodeCatalogue.nodeType = "0";
|
||
nodeCatalogue.showcheck = false;
|
||
nodeCatalogue.checkstate = 0;
|
||
nodeCatalogue.isexpand = false;
|
||
nodeCatalogue.parentId = Loc.UpDataItemDetailID;
|
||
nodeCatalogue.NodeExtData = Loc;
|
||
treeList.Add(nodeCatalogue);
|
||
|
||
var listPanel = Panels.Where(x => x.Panel_Loc_ID == Loc.DataItemDetailID && x.systempanel == GlobalEnum.specialType.系统柜.ToString()).ToList();
|
||
if (listPanel != null && listPanel.Count > 0)
|
||
{
|
||
foreach (var Panel in listPanel)
|
||
{
|
||
TreeModel nodeFile = new TreeModel();
|
||
nodeFile.id = Panel.PanelID;
|
||
nodeFile.text = Panel.TagNumber;
|
||
nodeFile.value = Panel.EngineerDataID;
|
||
nodeFile.nodeType = "1";
|
||
nodeFile.showcheck = false;
|
||
nodeFile.checkstate = 0;
|
||
nodeFile.isexpand = false;
|
||
nodeFile.parentId = Panel.Panel_Loc_ID; //后面会根据变为tree
|
||
nodeFile.NodeExtData = Panel;
|
||
|
||
//判断下是不是有效的类型
|
||
|
||
treeList.Add(nodeFile);
|
||
|
||
var StripsInPanel = Strips.Where(x => x.PanelID == Panel.PanelID).ToList();
|
||
if (StripsInPanel != null && StripsInPanel.Count > 0)
|
||
{
|
||
//StripsInPanel = StripsInPanel.OrderBy(x => x.Panel_Strip_Seq).ToList();
|
||
foreach (var Strip in StripsInPanel)
|
||
{
|
||
#region 带上汇总信息
|
||
var ChannelsInStrip = Channels.Where(x => x.StripID == Strip.StripID).ToList();//("{ProjectId:\"" + projectId + "\",StripID:\"" + Strip.StripID + "\",PanelID:\"" + Strip.PanelID + "\"}");
|
||
//Strip.Channels = ChannelsInStrip.ToList();
|
||
foreach (var Channel in ChannelsInStrip)
|
||
{
|
||
var Terms = AllTerms.Where(x => x.StripID == Strip.StripID && x.ChannelID == Channel.ChannelID).ToList();//ec_PanelStripTermService.GetList("{ProjectId:\"" + projectId + "\",StripID:\"" + Strip.StripID + "\",ChannelID:\"" + Channel.ChannelID + "\"}");
|
||
//wire termianl
|
||
var conns = AllWTs.Where(x => Terms.Select(y => y.TermID).ToList().Contains(x.TermID)).ToList(); //.GetList(("{ProjectId:\"" + projectId + "\",PanelID:\"" + Strip.PanelID + "\",StripID:\"" + Strip.StripID + "\"}"));
|
||
bool bUsed = false;
|
||
|
||
if (conns != null && conns.Count() > 0)
|
||
{
|
||
bUsed = true;
|
||
|
||
}
|
||
//foreach (ec_PanelStripTermEntity term in Terms)
|
||
//{
|
||
// var conn = conns.FirstOrDefault(x => x.TermID == term.TermID);
|
||
// if (conn != null)
|
||
// {
|
||
// bUsed = true;
|
||
// break;
|
||
// }
|
||
|
||
//}
|
||
if (bUsed)
|
||
{
|
||
//wire group
|
||
var signal = AllSignals.FirstOrDefault(x => x.ChannelID == Channel.ChannelID);//.GetList("{ProjectId:\"" + projectId + "\",StripID:\"" + Strip.StripID + "\",ChannelID:\"" + Channel.ChannelID + "\"}").FirstOrDefault();
|
||
if (signal != null)
|
||
{
|
||
Strip.ChannelsUsed += 1;
|
||
}
|
||
else
|
||
{
|
||
Strip.ChannelsUsedNoSignal += 1;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Strip.ChannelsSpared += 1;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
TreeModel nodeStrip = new TreeModel();
|
||
nodeStrip.id = Strip.StripID;
|
||
nodeStrip.text = Strip.StripName;
|
||
nodeStrip.value = Strip.Panel_Strip_Seq;
|
||
nodeStrip.nodeType = "1";
|
||
nodeStrip.showcheck = false;
|
||
nodeStrip.checkstate = 0;
|
||
nodeStrip.isexpand = false;
|
||
nodeStrip.parentId = Strip.PanelID;
|
||
nodeStrip.NodeExtData = Strip;
|
||
|
||
treeList.Add(nodeStrip);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
stopWatch.Stop();
|
||
this.Logger.Info($"循环位置耗时 {stopWatch.ElapsedMilliseconds}" + "\r\n");
|
||
return Success(treeList.ToTree());
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据ID拿。只查询ec panel表本身
|
||
/// </summary>
|
||
/// <param name="PanelID"></param>
|
||
/// <param name="projId"></param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
public IHttpActionResult GetPanel(string PanelID, string projId)
|
||
{
|
||
var res = ec_PanelBLL.GetEntity(projId, PanelID);
|
||
return Success(res);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据EngineerDataID拿。包括set wire,以及from to信息
|
||
/// </summary>
|
||
/// <param name="EngineerDataID"></param>
|
||
/// <param name="projId"></param>
|
||
/// <param name="OnlySelf"></param>
|
||
/// <param name="PreAssign"></param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
public IHttpActionResult GetCableByEngID(string EngineerDataID, string projId, bool OnlySelf = false, bool PreAssign = false)
|
||
{
|
||
if (PreAssign)
|
||
{
|
||
var res = ec_CableBLL.GetCablePreAssign(projId, EngineerDataID);
|
||
return Success(res);
|
||
}
|
||
else
|
||
{
|
||
var res = ec_CableBLL.GetCableByEngID(projId, EngineerDataID, OnlySelf);
|
||
return Success(res);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// 自动分配通道(点表信号自动分配)。
|
||
///
|
||
/// </summary>
|
||
/// <param name="projId"></param>
|
||
/// <param name="AcceptNearbyPanel"></param>
|
||
/// <param name="CableIds">需要分配的电缆cableid,不是enginedataId,逗号分开</param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public IHttpActionResult AutoAssignCable2Channel_step1(string projId, bool AcceptNearbyPanel, [FromBody] List<string> CableIds)
|
||
{
|
||
#region 数据准备
|
||
var frameBll = new FrameBll();
|
||
var allFrames = frameBll.GetFrameList(projId);
|
||
var cbll = new ec_CableBLL();
|
||
var panelTable = ProjectSugar.TableName<ec_PanelEntity>(projId);
|
||
var stripTable = ProjectSugar.TableName<ec_PanelStripEntity>(projId);
|
||
var tagTable = ProjectSugar.TableName<ec_enginedataEntity>(projId);
|
||
var propTable = ProjectSugar.TableName<ec_enginedata_propertyEntity>(projId);
|
||
var typeTable = ProjectSugar.TableName<ec_objecttypeEntity>(projId);
|
||
#endregion
|
||
|
||
#region 先要知道有哪些待分配的信号 端子排
|
||
if (CableIds == null || CableIds.Count == 0)
|
||
{
|
||
return Success("OK");
|
||
}
|
||
var cablesNeedAssigned = cbll.GetCablesPreAssign(projId, CableIds, true);
|
||
cablesNeedAssigned = cablesNeedAssigned.Where(x => CableIds.Contains(x.CableID)).ToList();
|
||
#endregion
|
||
//涉及到哪些箱子
|
||
var allPanel = SqlSugarHelper.Db.Queryable<ec_PanelEntity>().AS(panelTable).
|
||
InnerJoin<ec_enginedataEntity>((a, b) => a.EngineerDataID == b.EngineDataID).AS<ec_enginedataEntity>(tagTable).
|
||
InnerJoin<ec_objecttypeEntity>((a, b, c) => b.ObjectTypeID == c.ObjectTypeID).AS<ec_objecttypeEntity>(typeTable).
|
||
Where((a, b, c) => c.specialType == GlobalEnum.specialType.系统柜).
|
||
ToList();//这里要过滤一下,根据object type里的specialType,而不是所有的panel
|
||
|
||
var allPanelProp = SqlSugarHelper.Db.Queryable<ec_enginedata_propertyEntity>().AS(propTable)
|
||
.Where(x => allPanel.Select(xx => xx.EngineerDataID).Contains(x.EngineDataID))
|
||
.ToList().GroupBy(x => x.EngineDataID).ToDictionary(x => x.Key, x => x.ToList());
|
||
var panelsNeed = allPanel.Where(x => cablesNeedAssigned.Select(xx => xx.PanelID).Contains(x.PanelID)).ToList();//用户指定的预分配的箱子
|
||
|
||
var stripsNeed = SqlSugarHelper.Db.Queryable<ec_PanelStripEntity>().AS(stripTable).
|
||
Where(x => panelsNeed.Select(xx => xx.PanelID).Contains(x.PanelID)).
|
||
ToList();
|
||
#region 1.1判断(信号预分配选择的采集箱可能并没有该电缆需要的信号类型)
|
||
var cablesNotMatchIO = cablesNeedAssigned.Where(x => x.IOTypesNotMatchedList.Count > 0).ToList(); // GetCablesPreAssign 查询时已经处理过io是否匹配了
|
||
if (cablesNotMatchIO != null && cablesNotMatchIO.Count > 0)
|
||
{
|
||
if (AcceptNearbyPanel)//允许进行
|
||
{
|
||
//有不匹配的,但是用户允许继续
|
||
//在之后的自动分配过程中会自动寻找匹配的采集箱,原则上从就近的开始找,如果没有匹配的采集箱,则提示“未找到具有XX类型的采集箱,请新增后再次分配,是否取消自动分配进程?”
|
||
bool nearbyFound = false;
|
||
foreach (var cable in cablesNotMatchIO)
|
||
{
|
||
var nearPanel = FindPanelNearby(allFrames, allPanel, allPanelProp[cable.ToPanel.EngineerDataID], cable.PreAssignIOType);
|
||
if (nearPanel == null)
|
||
{
|
||
nearbyFound = false;
|
||
return Fail($"在附近未找到具有{cable.PreAssignIOType}类型的采集箱,请新增后再次分配,是否取消自动分配进程?");
|
||
}
|
||
else
|
||
{
|
||
nearbyFound = true;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
}
|
||
else
|
||
{
|
||
//不继续自动分配,中断进程,等添加完正确的模块后再继续自动分配
|
||
var cableNamesNotMatched = string.Join(",", cablesNotMatchIO.Select(x => x.TagNumber).ToList());
|
||
var panelIOMissing = new List<string>();
|
||
foreach (ec_CableEntity cableNotMatchIO in cablesNotMatchIO)
|
||
{
|
||
panelIOMissing.Add(cableNotMatchIO.PanelID + "缺失IO: " + string.Join(",", cableNotMatchIO.IOTypesNotMatchedList));
|
||
}
|
||
return Fail($"预分配结果中,以下电缆【{cableNamesNotMatched}】的IO类型和其预分配采集箱的IO类型无法匹配。等添加完正确的模块后再继续自动分配。\r\n" +
|
||
$"需要添加的正确模块有:{string.Join(",", panelIOMissing)}");
|
||
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//没有不匹配的,可以继续进行
|
||
|
||
}
|
||
//必要的数据存入redis,以便后续步骤使用
|
||
ICache redisObj = CacheFactory.CaChe();
|
||
redisObj.Remove("IOModule_AutoAssign2Ch_" + projId, CacheId.IOModule_AutoAssign2Ch);
|
||
redisObj.Write<List<ec_CableEntity>>("IOModule_AutoAssign2Ch_" + projId, cablesNeedAssigned, CacheId.IOModule_AutoAssign2Ch);
|
||
|
||
return Success("OK");
|
||
#endregion
|
||
|
||
|
||
|
||
|
||
}
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="projId"></param>
|
||
/// <returns></returns>
|
||
public IHttpActionResult AutoAssignCable2Channel_step2(string projId)
|
||
{
|
||
ICache redisObj = CacheFactory.CaChe();
|
||
var cablesNeedAssigned = redisObj.Read<List<ec_CableEntity>>("IOModule_AutoAssign2Ch_" + projId, CacheId.IOModule_AutoAssign2Ch);
|
||
|
||
//#region 1.2
|
||
#region 先分组 1.2.2
|
||
cablesNeedAssigned = cablesNeedAssigned.OrderBy(x => new { x.PanelID, x.PreAssignIOType, x.System }).ToList();
|
||
//var curPanel = new ec_PanelEntity();
|
||
//curPanel = panelsNeed.FirstOrDefault(x => x.PanelID == cablesNeedAssigned[0].PanelID);//先定位到第一个电缆所在的箱子
|
||
//curPanel.strips = stripsNeed.Where(x => x.PanelID == curPanel.PanelID).ToList();
|
||
//var curStrip = new ec_PanelStripEntity();
|
||
#endregion
|
||
//for (var i = 0; i < cablesNeedAssigned.Count; i++)
|
||
//{
|
||
|
||
// #region 是否有端子排 1.2.1
|
||
// if (curPanel.PanelID != cablesNeedAssigned[i].PanelID)
|
||
// {
|
||
// curPanel = panelsNeed.FirstOrDefault(x => x.PanelID == cablesNeedAssigned[0].PanelID);//切换箱子
|
||
// curPanel.strips = stripsNeed.Where(x => x.PanelID == curPanel.PanelID).ToList();
|
||
// }
|
||
// foreach (var set in cablesNeedAssigned[i].Sets)
|
||
// {
|
||
// var availableStrips = curPanel.strips.Where(x => x.IO_TYPE.ToUpper() == set.IOType.ToString().ToUpper()).ToList();
|
||
|
||
// if (availableStrips != null && availableStrips.Count > 0)
|
||
// {
|
||
// //已经存在端子排
|
||
// }
|
||
// else
|
||
// {
|
||
// //没有端子排,根据信号数里自动新建端子排,通道数里根据端子io模板的默认值获得
|
||
// //?????????????????????????????????
|
||
// }
|
||
// }
|
||
// //可能要换一下循环主体,评估下是按照cable循环好,还是按strip循环好
|
||
// #endregion
|
||
|
||
//}
|
||
//#endregion
|
||
return Success("自动关联完成");
|
||
|
||
|
||
}
|
||
/// <summary>
|
||
/// 把电缆分配到空余的模块的通道上。
|
||
/// </summary>
|
||
/// <param name="projId"></param>
|
||
/// <param name="execute"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public IHttpActionResult AssignCable2Channel(string projId, bool execute = false)
|
||
{
|
||
var asyncContent = Request.Content.ReadAsStringAsync().Result;
|
||
var cableIds = asyncContent.ToObject<List<string>>();
|
||
return Success("res");
|
||
}
|
||
/// <summary>
|
||
/// 查询所有需要预分配的电缆
|
||
/// </summary>
|
||
/// <param name="projId"></param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
public IHttpActionResult GetCablePreAssignPreview(string projId)
|
||
{
|
||
var bll = new ec_CableBLL();
|
||
var res = bll.GetCablesPreAssign(projId, null);
|
||
|
||
return Success(res);
|
||
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询所有的电缆
|
||
/// </summary>
|
||
/// <param name="projId"></param>
|
||
/// <param name="homerun">true或false</param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
public IHttpActionResult GetCables(string projId, bool homerun = true)
|
||
{
|
||
var res = ec_CableBLL.GetCables(projId, homerun);//这有个问题 如果一开始不知道要关联到那个通道 就不会有ec cable出来
|
||
|
||
return Success(res);
|
||
}
|
||
/// <summary>
|
||
/// PanelStrip参考库
|
||
/// </summary>
|
||
/// <param name="projId"></param>
|
||
/// <param name="OnlySelf">false时,带上下面的通道和端子。true时,就是返回端子排自己</param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
public IHttpActionResult GetPanelStrips(string projId, bool OnlySelf = false)
|
||
{
|
||
var res = ec_PanelStripBLL.GetList("{ProjectId:\"" + projId + "\",OnlySelf:\"" + OnlySelf + "\"}");
|
||
return Success(res);
|
||
}
|
||
/// <summary>
|
||
/// 在IO分配界面,从左侧目录树中选择一个“端子排”后,进行查询
|
||
/// </summary>
|
||
/// <param name="StripID"></param>
|
||
/// <param name="projId"></param>
|
||
/// <param name="OnlySelf">false时,带上下面的通道和端子。true时,就是返回端子排自己</param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
public IHttpActionResult GetPanelStrip(string StripID, string projId, bool OnlySelf = false, bool HaveChannel = true)
|
||
{
|
||
var res = ec_PanelStripBLL.GetEntity(projId, StripID, OnlySelf, HaveChannel);
|
||
return Success(res);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 新增或者修改。
|
||
/// 新建相当于强行,因为正常流程是和engineerdata一起新建出来的。
|
||
/// 改的话,只是改location和端子排数量这些。常规属性依旧通过objectTypeAPI去做
|
||
/// </summary>
|
||
/// <param name="entity"></param>
|
||
/// <param name="projId"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
[HandlerApiLogin(FilterMode.Enforce)]
|
||
public IHttpActionResult SavePanel(ec_PanelEntity entity, string projId)
|
||
{
|
||
|
||
try
|
||
{
|
||
ec_PanelBLL.SaveEntity(projId, entity.PanelID, entity);
|
||
return Success("OK");
|
||
}
|
||
catch (System.Exception E)
|
||
{
|
||
return Fail(E.Message);
|
||
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// SaveConnections 专用
|
||
/// </summary>
|
||
private class Connections
|
||
{
|
||
public string ID { get; set; }
|
||
public List<ec_WireTerminalEntity> Conns { get; set; }
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 处理 接线关系,同时对cableset和wire的个别属性进行修改
|
||
/// </summary>
|
||
/// <param name="projId"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
[HandlerApiLogin(FilterMode.Enforce)]
|
||
public IHttpActionResult SaveConnections(string projId)
|
||
{
|
||
|
||
try
|
||
{
|
||
var asyncContent = Request.Content.ReadAsStringAsync().Result;
|
||
var entity = asyncContent.ToObject<Connections>();
|
||
var res = entity.Conns;
|
||
new ec_WireTerminalBLL().SaveConnections(projId, ref res);
|
||
return Success(res);
|
||
}
|
||
catch (System.Exception E)
|
||
{
|
||
return Fail(E.Message);
|
||
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="projId"></param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
public IHttpActionResult GetConnections(string projId, string ID)
|
||
{
|
||
|
||
try
|
||
{
|
||
var res = new ec_WireTerminalService().GetEntity(projId, ID);
|
||
return Success(res);
|
||
}
|
||
catch (System.Exception E)
|
||
{
|
||
return Fail(E.Message);
|
||
|
||
}
|
||
}
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="entity"></param>
|
||
/// <param name="projId"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
[HandlerApiLogin(FilterMode.Enforce)]
|
||
public IHttpActionResult SaveCable(ec_CableEntity entity, string projId)
|
||
{
|
||
|
||
try
|
||
{
|
||
if (!string.IsNullOrEmpty(entity.CableID))
|
||
{
|
||
ec_CableBLL.SaveEntity(projId, entity.CableID, entity);
|
||
}
|
||
|
||
return Success("OK");
|
||
}
|
||
catch (System.Exception E)
|
||
{
|
||
return Fail(E.Message);
|
||
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 通过预设模式,批量创建端子排 通道 端子
|
||
/// </summary>
|
||
/// <param name="entity"></param>
|
||
/// <param name="projId"></param>
|
||
[HttpPost]
|
||
[HandlerApiLogin(FilterMode.Enforce)]
|
||
public IHttpActionResult CreatePanelStripByProfile(string projId)
|
||
{
|
||
try
|
||
{
|
||
var asyncContent = Request.Content.ReadAsStringAsync().Result;
|
||
var entity = asyncContent.ToObject<ec_PanelStripEntity>();
|
||
string NewID = "";
|
||
ec_PanelStripBLL.SaveEntity(projId, "", entity, out NewID);
|
||
|
||
var res = ec_PanelStripBLL.GetEntity(projId, NewID);
|
||
return Success(res);
|
||
}
|
||
catch (System.Exception e)
|
||
{
|
||
return Fail(e.Message);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
///// <summary>
|
||
///// 通过预设模式,批量创建端子排 端子(不需要了,因为预设模式只有对IO有通道的那边才有用)
|
||
///// </summary>
|
||
///// <param name="entity"></param>
|
||
///// <param name="projId"></param>
|
||
//[HttpPost]
|
||
//[HandlerApiLogin(FilterMode.Enforce)]
|
||
//public IHttpActionResult CreatePanelStripByProfileNoChannel(string projId, ec_PanelStripEntity entity)
|
||
//{
|
||
// try
|
||
// {
|
||
// string NewID = "";
|
||
// ec_PanelStripBLL.SaveEntity(projId, "", entity, out NewID, false);
|
||
|
||
// var res = ec_PanelStripBLL.GetEntity(projId, NewID);
|
||
// return Success(res);
|
||
// }
|
||
// catch (System.Exception e)
|
||
// {
|
||
// return Fail(e.Message);
|
||
// }
|
||
|
||
|
||
//}
|
||
|
||
/// <summary>
|
||
/// GetCableByEngID先去判断这个cable是否已经有了IO Module这边的记录
|
||
/// 电缆-端子连接,从图面上选择一个电缆对象
|
||
/// </summary>
|
||
/// <param name="projId"></param>
|
||
[HttpPost]
|
||
[HandlerApiLogin(FilterMode.Enforce)]
|
||
public IHttpActionResult CreateCableByProfile(string projId)
|
||
{
|
||
try
|
||
{
|
||
var asyncContent = Request.Content.ReadAsStringAsync().Result;
|
||
var entity = asyncContent.ToObject<ec_CableEntity>();
|
||
|
||
ec_CableBLL.SaveEntity(projId, entity.CableID, entity);
|
||
|
||
var res = ec_CableBLL.GetCableByEngID(projId, entity.EngineerDataID);
|
||
return Success(res);
|
||
}
|
||
catch (System.Exception e)
|
||
{
|
||
return Fail(e.Message);
|
||
}
|
||
|
||
|
||
}
|
||
/// <summary>
|
||
/// 批量保存电缆的set wire 名字等
|
||
/// </summary>
|
||
/// <param name="projId"></param>
|
||
[HttpPost]
|
||
[HandlerApiLogin(FilterMode.Enforce)]
|
||
public IHttpActionResult SaveCables(string projId)
|
||
{
|
||
try
|
||
{
|
||
var asyncContent = Request.Content.ReadAsStringAsync().Result;
|
||
var entitys = asyncContent.ToObject<List<ec_CableEntity>>();
|
||
foreach (var entity in entitys)
|
||
{
|
||
ec_CableBLL.SaveEntity(projId, entity.CableID, entity);
|
||
|
||
}
|
||
|
||
return Success(entitys);
|
||
}
|
||
catch (System.Exception e)
|
||
{
|
||
return Fail(e.Message);
|
||
}
|
||
|
||
|
||
}
|
||
/// <summary>
|
||
/// 创建、修改 端子排和端子(一般是为非监测设备的端子排)
|
||
/// </summary>
|
||
/// <param name="entity"></param>
|
||
/// <param name="projId"></param>
|
||
[HttpPost]
|
||
[HandlerApiLogin(FilterMode.Enforce)]
|
||
public IHttpActionResult SavePanelStripNoChannel(string projId, ec_PanelStripEntity entity)
|
||
{
|
||
try
|
||
{
|
||
string NewID = "";
|
||
ec_PanelStripBLL.SaveEntity(projId, entity.StripID, entity, out NewID, false);
|
||
|
||
var res = ec_PanelStripBLL.GetEntity(projId, NewID, false, false);
|
||
return Success(res);
|
||
}
|
||
catch (System.Exception e)
|
||
{
|
||
return Fail(e.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// 保存端子排 通道 端子的信息(不管信号和接线关系)。
|
||
/// 迁移通道也是这里。
|
||
/// </summary>
|
||
/// <param name="entity"></param>
|
||
/// <param name="projId"></param>
|
||
[HttpPost]
|
||
[HandlerApiLogin(FilterMode.Enforce)]
|
||
public IHttpActionResult SavePanelStrip(string projId, ec_PanelStripEntity entity)
|
||
{
|
||
XmlConfigurator.Configure();
|
||
var log = log4net.LogManager.GetLogger("Debug"); //参数就是config里logger节点的名字
|
||
try
|
||
{
|
||
//var asyncContent = Request.Content.ReadAsStringAsync().Result;
|
||
//var entity = asyncContent.ToObject<ec_PanelStripEntity>();
|
||
ec_PanelStripBLL.SaveEntity(projId, entity.StripID, entity, out string NewID);
|
||
var res = ec_PanelStripBLL.GetEntity(projId, NewID);
|
||
return Success(res);
|
||
}
|
||
catch (System.Exception e)
|
||
{
|
||
log.Debug($"★★★{DateTime.Now.ToString()}★★★{e}★★★");
|
||
return Fail(e.Message);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="entity"></param>
|
||
/// <param name="projId"></param>
|
||
[HttpPost]
|
||
[HandlerApiLogin(FilterMode.Enforce)]
|
||
public IHttpActionResult SavePanelStripTerm(ec_PanelStripTermEntity entity, string projId)
|
||
{
|
||
|
||
try
|
||
{
|
||
ec_PanelStripTermBLL.SaveEntity(projId, entity.TermID, entity);
|
||
return Success("OK");
|
||
}
|
||
catch (System.Exception e)
|
||
{
|
||
return Fail(e.Message);
|
||
}
|
||
}
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="entity"></param>
|
||
/// <param name="projId"></param>
|
||
[HttpPost]
|
||
[HandlerApiLogin(FilterMode.Enforce)]
|
||
public IHttpActionResult SavePanelChannel(ec_PanelChannelEntity entity, string projId)
|
||
{
|
||
|
||
|
||
try
|
||
{
|
||
var newId = ec_PanelChannelBLL.SaveEntity(projId, entity.ChannelID, entity);
|
||
foreach (var term in entity.Terms)
|
||
{
|
||
ec_PanelStripTermBLL.SaveEntity(projId, term.TermID, term);
|
||
}
|
||
var res = ec_PanelChannelBLL.GetEntity(projId, newId);
|
||
return Success(res);
|
||
}
|
||
catch (System.Exception e)
|
||
{
|
||
return Fail(e.Message);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 调端子排所属Panel
|
||
/// </summary>
|
||
/// <param name="StripID">端子排ID</param>
|
||
/// <param name="PanelID">PanelID</param>
|
||
/// <param name="ProjectId">项目ID</param>
|
||
[HttpPost]
|
||
[HandlerApiLogin(FilterMode.Enforce)]
|
||
public IHttpActionResult SwitchPanelStrip(string StripID, string PanelID, string ProjectId)
|
||
{
|
||
try
|
||
{
|
||
ec_PanelStripBLL.SwitchPanelStrip(StripID, PanelID, ProjectId);
|
||
return Success("OK");
|
||
}
|
||
catch (System.Exception e)
|
||
{
|
||
return Fail(e.Message);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 调换电缆的from/to信息
|
||
/// </summary>
|
||
/// <param name="CableID">Cable的工程ID</param>
|
||
/// <param name="ProjectId">项目ID</param>
|
||
[HttpPost]
|
||
[HandlerApiLogin(FilterMode.Enforce)]
|
||
public IHttpActionResult SwitchCableFromTo(string ProjectId)
|
||
{
|
||
try
|
||
{
|
||
var asyncContent = Request.Content.ReadAsStringAsync().Result;
|
||
var entityCol = asyncContent.ToObject<List<string>>();
|
||
|
||
var res = new ec_enginedata_relService().SwitchCableFromTo(entityCol, ProjectId);
|
||
if (res)
|
||
{
|
||
return Success("OK");
|
||
}
|
||
else
|
||
{
|
||
return Fail("From/To 交换出现问题。");
|
||
}
|
||
}
|
||
catch (System.Exception e)
|
||
{
|
||
return Fail(e.Message);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 比如 移动通道时,进行保存
|
||
/// </summary>
|
||
/// <param name="entity"></param>
|
||
/// <param name="projId"></param>
|
||
/// <returns></returns>
|
||
[Obsolete]
|
||
[HttpPost]
|
||
[HandlerApiLogin(FilterMode.Enforce)]
|
||
public IHttpActionResult SavePanelChannels(List<ec_PanelChannelEntity> entitys, string projId)
|
||
{
|
||
|
||
|
||
try
|
||
{
|
||
foreach (var entity in entitys)
|
||
{
|
||
var newId = ec_PanelChannelBLL.SaveEntity(projId, entity.ChannelID, entity);
|
||
foreach (var term in entity.Terms)
|
||
{
|
||
ec_PanelStripTermBLL.SaveEntity(projId, term.TermID, term);
|
||
}
|
||
}
|
||
|
||
|
||
return Success("OK");
|
||
}
|
||
catch (System.Exception e)
|
||
{
|
||
return Fail(e.Message);
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 根据某个数据字典的编号来。默认有个id=1的枚举
|
||
/// </summary>
|
||
/// <param name="ProjectId"></param>
|
||
/// <returns></returns>
|
||
private List<ec_dataitemdetailEntity> GetLocList(string ProjectId)
|
||
{
|
||
var ec_dataitemBLL = new ec_dataitemBLL();
|
||
var settings = new ec_projectSettingsBLL();
|
||
|
||
var ListFlg = settings.GetEntity(GlobalObject.projSetting_enumlist_IORackPosition, ProjectId);
|
||
|
||
if (ListFlg != null)
|
||
{
|
||
List<ec_dataitemdetailEntity> frameLists = new List<ec_dataitemdetailEntity>();
|
||
frameLists.Add(new ec_dataitemdetailEntity() { DataItemName = "默认", DataItemCode = "默认", DataItemDetailID = "1", UpDataItemDetailID = "", DataItemID = "" }); //{ Name = "默认", Desc = "默认", Id = "1", ParentID = "" });
|
||
var ListName = ec_dataitemBLL.GetList("{ProjectId:\"" + ProjectId + "\",keyword:\"" + ListFlg.SettingValue + "\"}").FirstOrDefault();
|
||
if (ListName == null)
|
||
{
|
||
return null;
|
||
}
|
||
else
|
||
{
|
||
frameLists[0].DataItemID = ListName.DataItemID;
|
||
}
|
||
var res = ec_dataitemBLL.GetDetailList(ListFlg.SettingValue, "", ProjectId, false); //区域
|
||
foreach (var item in res)
|
||
{
|
||
|
||
//frameLists.Add(new ec_dataitemdetailEntity()
|
||
//{
|
||
// Name = item.DataItemName,
|
||
// ParentID = item.UpDataItemDetailID,
|
||
// Desc = item.DataItemCode,
|
||
// Id = item.DataItemDetailID,
|
||
// DataItemId = item.DataItemID
|
||
//});
|
||
frameLists.Add(item);
|
||
}
|
||
|
||
|
||
return frameLists;
|
||
}
|
||
else
|
||
{
|
||
return null;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 位置。缺省都放到“默认”下
|
||
/// </summary>
|
||
/// <param name="ProjectId"></param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
public IHttpActionResult GetLocationList(string ProjectId)
|
||
{
|
||
var RES = GetLocList(ProjectId);
|
||
|
||
if (RES != null)
|
||
{
|
||
return Success(RES);
|
||
}
|
||
else
|
||
{
|
||
return Fail("未找到合适的数据字典,可以当做位置");
|
||
}
|
||
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据id来删除
|
||
/// </summary>
|
||
/// <param name="keyValue"></param>
|
||
/// <param name="ProjectId"></param>
|
||
[HttpPost]
|
||
[HandlerApiLogin(FilterMode.Enforce)]
|
||
public IHttpActionResult DeletePanel(string PanelID, string ProjectId)
|
||
{
|
||
new ec_enginedataBLL().DeleteEntity(PanelID, ProjectId);
|
||
return Success("删除成功!");
|
||
}
|
||
/// <summary>
|
||
/// 根据id来删除
|
||
/// </summary>
|
||
/// <param name="CableID"></param>
|
||
/// <param name="ProjectId"></param>
|
||
[HttpPost]
|
||
[HandlerApiLogin(FilterMode.Enforce)]
|
||
public IHttpActionResult DeleteCableProfile(string CableID, string ProjectId)
|
||
{
|
||
ec_CableBLL.DeleteEntity(ProjectId, CableID);
|
||
return Success("OK");
|
||
}
|
||
/// <summary>
|
||
/// 根据id来删除
|
||
/// </summary>
|
||
/// <param name="keyValue"></param>
|
||
/// <param name="ProjectId"></param>
|
||
[HttpPost]
|
||
[HandlerApiLogin(FilterMode.Enforce)]
|
||
public IHttpActionResult DeletePanelStrip(string StripID, string ProjectId)
|
||
{
|
||
ec_PanelStripBLL.DeleteEntity(ProjectId, StripID);
|
||
return Success("删除成功!");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据id来删除
|
||
/// </summary>
|
||
/// <param name="ChannelID"></param>
|
||
/// <param name="ProjectId"></param>
|
||
[HttpPost]
|
||
[HandlerApiLogin(FilterMode.Enforce)]
|
||
public IHttpActionResult DeletePanelChannel(string ChannelID, string ProjectId)
|
||
{
|
||
ec_PanelChannelBLL.DeleteEntity(ProjectId, ChannelID);
|
||
return Success("OK");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
//public class Panel_Location
|
||
//{
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
//public string ParentID { get; set; }
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
//public string Id { set; get; }
|
||
/// <summary>
|
||
/// 所在数据字典的ID
|
||
/// </summary>
|
||
// public string DataItemId { set; get; }
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
//public string Name { get; set; }
|
||
|
||
/// <summary>
|
||
/// 数据字典里的code
|
||
/// </summary>
|
||
//public string Desc { get; set; }
|
||
//}
|
||
|
||
|
||
} |