diff --git a/Learun.Application.Web/AppApi/ObjectTypeApiController.cs b/Learun.Application.Web/AppApi/ObjectTypeApiController.cs
index c50e9ba2..69687a2e 100644
--- a/Learun.Application.Web/AppApi/ObjectTypeApiController.cs
+++ b/Learun.Application.Web/AppApi/ObjectTypeApiController.cs
@@ -373,7 +373,7 @@ namespace Learun.Application.Web.AppApi
///
/// 项目ID
/// 图纸文件ID
- /// 图元编号集合(用,连接)
+ /// 图元编号集合(用,连接)。正常就1个
/// 工况ID
///
[HttpGet]
@@ -552,7 +552,7 @@ namespace Learun.Application.Web.AppApi
{
TagProp.PropertyValue = CableConn.End1Tag;
}
- else if (TagProp.PropertyName ==GlobalObject.propName_To)
+ else if (TagProp.PropertyName == GlobalObject.propName_To)
{
TagProp.PropertyValue = CableConn.End2Tag;
}
@@ -591,44 +591,55 @@ namespace Learun.Application.Web.AppApi
var propTbName = ProjectSugar.TableName(projectId);
var allUser = SqlSugarHelper.Db.Queryable().ToList();
+ var userDict = allUser.ToDictionary(x => x.F_UserId, x => x.F_RealName);
var pixelAll = SqlSugarHelper.Db.Queryable().AS(pixelTbName).Where(x => x.DrawingFileID == drawingFileID && x.DeleteFlg != 1).ToList();
+ var pixelDictByTag = pixelAll.GroupBy(x => x.EngineDataID).ToDictionary(x => x.Key, x => x.ToList());
var pixelObjs = pixelAll.Where(x => pixelCodes.Split(',').ToList().Contains(x.PixelCode)).ToList();
var tagIds = pixelObjs.Select(x => x.EngineDataID).Distinct().ToList();
var tagAll = SqlSugarHelper.Db.Queryable().AS(tagTbName).OrderBy(x => x.TagNumber).ToList();
+ // 提前分组:按ObjectTypeID分组,并为每个组预生成字典(仅执行一次,O(m)时间)
+ var preGrouped = tagAll
+ .GroupBy(tag => tag.ObjectTypeID)
+ .ToDictionary(
+ group => group.Key, // 键:ObjectTypeID
+ group => group.ToDictionary( // 值:该组内的EngineDataID→TagNumber字典
+ item => item.EngineDataID,
+ item => item.TagNumber
+ )
+ );
var tagObjs = tagAll.Where(x => tagIds.Contains(x.EngineDataID)).ToList();
-
+ var tagDictByType = tagObjs.GroupBy(x => x.ObjectTypeID).ToDictionary(x => x.Key, x => x.ToList());
var typeIds = tagObjs.Select(x => x.ObjectTypeID).Distinct().ToList();
var typeAll = SqlSugarHelper.Db.Queryable().AS(typeTbName).ToList();
var typeObjs = typeAll.Where(x => typeIds.Contains(x.ObjectTypeID)).ToList();
var tagPropAll = SqlSugarHelper.Db.Queryable().AS(propTbName).Where(x => tagIds.Contains(x.EngineDataID)).ToList();
+ var tagPropDictByTag = tagPropAll.GroupBy(x => x.EngineDataID).ToDictionary(x => x.Key, x => x.ToList());
//所有类别的属性信息
var objectTypeProps2 = objectTypePBll.GetObjectTypePById(string.Join(",", typeIds), projectId, true);//最频繁的那个接口
-
+ var typePropDictByType = objectTypeProps2.GroupBy(x => x.ObjectTypeID).ToDictionary(g => g.Key, g => g.ToList());
try
{
foreach (var objectType in typeObjs)
{
//该类型下的属性信息
- objectType.props = objectTypeProps2.Where(x => x.ObjectTypeID == objectType.ObjectTypeID).ToList();
+ objectType.props = typePropDictByType[objectType.ObjectTypeID];// objectTypeProps2.Where(x => x.ObjectTypeID == objectType.ObjectTypeID).ToList();
//该类型下的位号基础信息
- objectType.tags = tagObjs.Where(x => x.ObjectTypeID == objectType.ObjectTypeID).ToList();
- foreach (var item in objectType.tags)
- {
- item.CreateUserName = allUser.FirstOrDefault(x => x.F_UserId == item.CreateUserID)?.F_RealName;
- }
+ objectType.tags = tagDictByType[objectType.ObjectTypeID]; // tagObjs.Where(x => x.ObjectTypeID == objectType.ObjectTypeID).ToList();
+
//每个位号的属性信息
foreach (var tag in objectType.tags)
{
+ tag.CreateUserName = userDict[tag.CreateUserID];// allUser.FirstOrDefault(x => x.F_UserId == item.CreateUserID)?.F_RealName;
- tag.EngineDataID = tag.EngineDataID;
- tag.EngineDataProperty = tagPropAll.Where(x => x.EngineDataID == tag.EngineDataID).ToList();
+ tag.EngineDataProperty = tagPropDictByTag[tag.EngineDataID];// tagPropAll.Where(x => x.EngineDataID == tag.EngineDataID).ToList();
tag.ObjectTypeName = objectType.ObjectTypeName;
+
if (objectType.ObjectTypeName.EndsWith("电缆"))
{
//电缆from to
- var CableConn = relBll.GetCableConn(tag.EngineDataID, projectId);
+ var CableConn = relBll.GetCableConn(tag.EngineDataID, projectId);//此时就根据rel里的id拿到了新的tagNumber
if (!tag.EngineDataProperty.Any(X => X.PropertyName == GlobalObject.propName_From))
{
@@ -640,7 +651,7 @@ namespace Learun.Application.Web.AppApi
};
newProp.Create();
- ec_enginedata_propertyBLL.InsertTagProp(projectId, tag.EngineDataID, newProp);
+ ec_enginedata_propertyBLL.InsertTagProp(projectId, tag.EngineDataID, newProp);//增加 起始设备
tag.EngineDataProperty.Add(newProp);
}
if (!tag.EngineDataProperty.Any(X => X.PropertyName == GlobalObject.propName_To))
@@ -653,7 +664,7 @@ namespace Learun.Application.Web.AppApi
};
newProp.Create();
- ec_enginedata_propertyBLL.InsertTagProp(projectId, tag.EngineDataID, newProp);
+ ec_enginedata_propertyBLL.InsertTagProp(projectId, tag.EngineDataID, newProp);////增加 终止设备
tag.EngineDataProperty.Add(newProp);
}
@@ -671,10 +682,10 @@ namespace Learun.Application.Web.AppApi
}
//查一下每个位号的图元信息
- tag.EngineDataPixel = pixelAll.Where(x => x.EngineDataID == tag.EngineDataID).ToList();
+ tag.EngineDataPixel = pixelDictByTag[tag.EngineDataID];// pixelAll.Where(x => x.EngineDataID == tag.EngineDataID).ToList();
}
//taglist
- objectType.tagsListDropDown = tagAll.Where(X => X.ObjectTypeID == objectType.ObjectTypeID).ToDictionary(x => x.EngineDataID, x => x.TagNumber);
+ objectType.tagsListDropDown = preGrouped[objectType.ObjectTypeID]; //tagAll.Where(X => X.ObjectTypeID == objectType.ObjectTypeID).ToDictionary(x => x.EngineDataID, x => x.TagNumber);
//该类型下的流水
if (objectType.IsSerialNumber == 1)
diff --git a/Learun.Application.Web/AppApi/RelApiController.cs b/Learun.Application.Web/AppApi/RelApiController.cs
index cd1f2e2c..40062252 100644
--- a/Learun.Application.Web/AppApi/RelApiController.cs
+++ b/Learun.Application.Web/AppApi/RelApiController.cs
@@ -77,7 +77,7 @@ namespace Learun.Application.Web.AppApi
relData.RelEngineData2ID
};
}
- ec_relDataBLL.SaveEntitys(ProjectId, relData.RelTypeID, relData.RelEngineData1ID, relData.End2IDs);
+ ec_relDataBLL.SaveEntitys(ProjectId, relData.RelTypeID, relData.RelEngineData1ID, relData.End2IDs,relData.OPCPixel);
}
@@ -487,7 +487,7 @@ namespace Learun.Application.Web.AppApi
}
}
-
+
relDataCol = relDataColNotOPC;
}
else
@@ -536,7 +536,7 @@ namespace Learun.Application.Web.AppApi
{
//根据句柄和图纸,先把工程id查出来先
//获取工程数据图元数据
- var EngineDataIDs = pixelServ.GetList("{\"ProjectId\":\"" + ProjectId + "\",\"PixelCode\":\"" + relData.TagPixelID + "\",\"DrawingFileID\":\"" + relData.DrawingID + "\"}",ProjectId).
+ var EngineDataIDs = pixelServ.GetList("{\"ProjectId\":\"" + ProjectId + "\",\"PixelCode\":\"" + relData.TagPixelID + "\",\"DrawingFileID\":\"" + relData.DrawingID + "\"}", ProjectId).
Select(x => x.EngineDataID).Distinct();
var CableIDs = pixelServ.GetList("{\"ProjectId\":\"" + ProjectId + "\",\"PixelCode\":\"" + relData.CablePixelID + "\",\"DrawingFileID\":\"" + relData.DrawingID + "\"}", ProjectId).
Select(x => x.EngineDataID).Distinct();
@@ -547,13 +547,13 @@ namespace Learun.Application.Web.AppApi
- if (relData.IsEnd1)
+ if (relData.IsEnd1)//电缆的起始端连接信息,设备在end1,电缆在end2
{
- ec_relDataBLL.SaveEntitys(ProjectId, RelTypeID, new List { TagID }, CableID, true);
+ ec_relDataBLL.SaveEntitys(ProjectId, RelTypeID, new List { TagID }, CableID, relData.TagPixelID, true);
}
else
{
- ec_relDataBLL.SaveEntitys(ProjectId, RelTypeID, CableID, new List { TagID }, true);
+ ec_relDataBLL.SaveEntitys(ProjectId, RelTypeID, CableID, new List { TagID }, relData.TagPixelID, true);
}
}
diff --git a/Learun.Application.Web/Areas/ZZDT_EC/Controllers/ec_enginedata_relController.cs b/Learun.Application.Web/Areas/ZZDT_EC/Controllers/ec_enginedata_relController.cs
index 3dee7536..d365cbc3 100644
--- a/Learun.Application.Web/Areas/ZZDT_EC/Controllers/ec_enginedata_relController.cs
+++ b/Learun.Application.Web/Areas/ZZDT_EC/Controllers/ec_enginedata_relController.cs
@@ -99,7 +99,7 @@ namespace Learun.Application.Web.Areas.ZZDT_EC.Controllers
public ActionResult SaveForm(string ProjectId, string RelTypeID, string RelEngineData1ID, string strEntity)
{
List relEngineData2IDs = strEntity.ToList();
- ec_enginedata_relIBLL.SaveEntitys(ProjectId, RelTypeID, RelEngineData1ID, relEngineData2IDs);
+ ec_enginedata_relIBLL.SaveEntitys(ProjectId, RelTypeID, RelEngineData1ID, relEngineData2IDs,"");
return Success("保存成功!");
}
#endregion
diff --git a/Learun.Application.Web/Areas/ZZDT_EC/Controllers/ec_report_fileController.cs b/Learun.Application.Web/Areas/ZZDT_EC/Controllers/ec_report_fileController.cs
index 16e0b0a4..d907b34f 100644
--- a/Learun.Application.Web/Areas/ZZDT_EC/Controllers/ec_report_fileController.cs
+++ b/Learun.Application.Web/Areas/ZZDT_EC/Controllers/ec_report_fileController.cs
@@ -1123,7 +1123,7 @@ namespace Learun.Application.Web.Areas.ZZDT_EC.Controllers
//电缆的from to是根据甲板号的order顺序来的,高优先级的就属于from
int? FromOrder = -1; int? ToOrder = -1;
#region From
- var cableFromId = relDatas?.FirstOrDefault(x => x?.RelEngineData2ID == cable?.EngineDataID && x?.RelEngDataObjType1?.Contains("OPC")==false)?.RelEngineData1ID;
+ var cableFromId = relDatas?.FirstOrDefault(x => x?.RelEngineData2ID == cable?.EngineDataID && x?.RelEngDataObjType1?.Contains(GlobalObject.objectType_OPC)==false)?.RelEngineData1ID;
if (!string.IsNullOrEmpty(cableFromId))
{
var cableFromObj = Equips.FirstOrDefault(x => x.EngineDataID == cableFromId);
@@ -1174,7 +1174,7 @@ namespace Learun.Application.Web.Areas.ZZDT_EC.Controllers
}
#endregion
#region To
- var cableEndId = relDatas?.FirstOrDefault(x => x?.RelEngineData1ID == cable?.EngineDataID && x?.RelEngDataObjType2?.Contains("OPC")==false)?.RelEngineData2ID;
+ var cableEndId = relDatas?.FirstOrDefault(x => x?.RelEngineData1ID == cable?.EngineDataID && x?.RelEngDataObjType2?.Contains(GlobalObject.objectType_OPC)==false)?.RelEngineData2ID;
if (!string.IsNullOrEmpty(cableEndId))
{
var cableEndObj = Equips.FirstOrDefault(x => x.EngineDataID == cableEndId);
@@ -1570,8 +1570,8 @@ namespace Learun.Application.Web.Areas.ZZDT_EC.Controllers
(eep, ee, eo, edf, edc, edp) => eep.EngineDataID == edp.EngineDataID
)
.LeftJoin(subQuery, (eep, ee, eo, edf, edc, edp,dde)=> edp.甲板号 == dde.DataItemName)
- .WhereIF(selectModel == 0, (eep, ee, eo, edf, edc, edp, dde) => !eo.FullPathCN.EndsWith("电缆") && !eo.FullPathCN.EndsWith("图框") && !eo.FullPathCN.EndsWith(GlobalObject.objectType_Base) && !eo.FullPathCN.EndsWith("OPC") && eep.DeleteFlg == 0)
- .WhereIF(selectModel == 1, (eep, ee, eo, edf, edc, edp, dde) => !eo.FullPathCN.EndsWith("电缆") && !eo.FullPathCN.EndsWith("图框") && !eo.FullPathCN.EndsWith(GlobalObject.objectType_Base) && !eo.FullPathCN.EndsWith("OPC") && dwgIdCos.Contains(eep.DrawingFileID) && eep.DeleteFlg == 0)
+ .WhereIF(selectModel == 0, (eep, ee, eo, edf, edc, edp, dde) => !eo.FullPathCN.EndsWith("电缆") && !eo.FullPathCN.EndsWith("图框") && !eo.FullPathCN.EndsWith(GlobalObject.objectType_Base) && !eo.FullPathCN.EndsWith(GlobalObject.objectType_OPC) && eep.DeleteFlg == 0)
+ .WhereIF(selectModel == 1, (eep, ee, eo, edf, edc, edp, dde) => !eo.FullPathCN.EndsWith("电缆") && !eo.FullPathCN.EndsWith("图框") && !eo.FullPathCN.EndsWith(GlobalObject.objectType_Base) && !eo.FullPathCN.EndsWith(GlobalObject.objectType_OPC) && dwgIdCos.Contains(eep.DrawingFileID) && eep.DeleteFlg == 0)
.GroupBy((eep, ee, eo, edf, edc, edp, dde) => new
{
edc.DrawingCatalogueNO,
diff --git a/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/ZZDT_EC/ec_enginedata/ec_enginedataBLL.cs b/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/ZZDT_EC/ec_enginedata/ec_enginedataBLL.cs
index 66983972..d06cfa16 100644
--- a/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/ZZDT_EC/ec_enginedata/ec_enginedataBLL.cs
+++ b/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/ZZDT_EC/ec_enginedata/ec_enginedataBLL.cs
@@ -131,7 +131,7 @@ namespace Learun.Application.TwoDevelopment.ZZDT_EC
Where(x => allTag.Select(y => y.ObjectTypeID).Contains(x.ObjectTypeID)
&& !x.FullPathCN.EndsWith("图框")
&& !x.FullPathCN.EndsWith(GlobalObject.objectType_Base)
- && !x.FullPathCN.EndsWith("OPC")).Distinct().ToList();
+ && !x.FullPathCN.EndsWith(GlobalObject.objectType_OPC)).Distinct().ToList();
var allPropDef = Db.Queryable().AS(propT).ToList();
//var allObjectTypeP = Db.Queryable().AS(objectTypeP_T).ToList();
var allObjectTypeP = new ec_objecttypepBLL().GetObjectTypePById("", projectId, true).ToList();
@@ -1816,10 +1816,29 @@ namespace Learun.Application.TwoDevelopment.ZZDT_EC
var relObj = Db.Queryable().AS(relTableName).First(x => x.RelType == "0");
if (relObj != null) {
var existCableConns = Db.Queryable().AS(reldataTableName).
- Where(x => x.RelTypeID == relObj.RelTypeID && (x.RelEngineData1ID == oldTagId || x.RelEngineData2ID == oldTagId)).ToList();
+ Where(x => x.RelTypeID == relObj.RelTypeID && x.OPCPixel == pixel.PixelCode && (x.RelEngineData1ID == oldTagId || x.RelEngineData2ID == oldTagId)).ToList();
//这里有问题。
//比如设备B在多个图上多有句柄P1 P2 P3,且这些句柄都关联了多个电缆C1 C2 C3,那么在rel表里就有3个B的记录
//这时如果进行提交,句柄P1的主体变为了设备BBB,那么B的所有句柄P1 P2 P3都变为BBB了,没有单独分离出来 C1 C2 C3中的某一个
+
+ //解决:在进行saveconnection,把设备的句柄存入
+
+ if (existCableConns != null)
+ {
+ //更新rel表
+ foreach (var existConn in existCableConns)
+ {
+ if (existConn.RelEngineData1ID == oldTagId)
+ {
+ existConn.RelEngineData1ID = newTagId;
+ }
+ else if (existConn.RelEngineData2ID == oldTagId)
+ {
+ existConn.RelEngineData2ID = newTagId;
+ }
+ }
+ //更新电缆属性里的 起始设备 和 终止设备
+ }
}
}
#endregion
@@ -2549,7 +2568,7 @@ namespace Learun.Application.TwoDevelopment.ZZDT_EC
// 筛选出“真实设备”,这里排除OPC、通讯器等中转对象
var deviceTags = endpointInfo
- .Where(x => !x.objectType.Contains("OPC"))
+ .Where(x => !x.objectType.Contains(GlobalObject.objectType_OPC))
.Select(x => x.tagNumber)
.Distinct()
.Take(2) // 只取前两个设备
diff --git a/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/ZZDT_EC/ec_enginedata_pixel/ec_enginedata_pixelBLL.cs b/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/ZZDT_EC/ec_enginedata_pixel/ec_enginedata_pixelBLL.cs
index 82fb05a1..1318106d 100644
--- a/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/ZZDT_EC/ec_enginedata_pixel/ec_enginedata_pixelBLL.cs
+++ b/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/ZZDT_EC/ec_enginedata_pixel/ec_enginedata_pixelBLL.cs
@@ -400,7 +400,7 @@ namespace Learun.Application.TwoDevelopment.ZZDT_EC
.LeftJoin((edp, ede) => edp.EngineDataID == ede.EngineDataID).AS(enginedataTableName)
.LeftJoin((edp, ede, eot) => ede.ObjectTypeID == eot.ObjectTypeID).AS(objectTypeTableName)
.Where((edp, ede, eot) => edp.DeleteFlg == 0 && edp.DrawingFileID == drawingFileID && pixelEntities.Select(y => y.PixelCode).Contains(edp.PixelCode)
- && !eot.FullPathCN.EndsWith("图框") && !eot.FullPathCN.EndsWith(GlobalObject.objectType_Base) && !eot.FullPathCN.EndsWith("OPC"))
+ && !eot.FullPathCN.EndsWith("图框") && !eot.FullPathCN.EndsWith(GlobalObject.objectType_Base) && !eot.FullPathCN.EndsWith(GlobalObject.objectType_OPC))
.Select((edp, ede, eot) => edp.EngineDataID)
.Distinct()
.ToList();
@@ -753,7 +753,7 @@ namespace Learun.Application.TwoDevelopment.ZZDT_EC
.LeftJoin((edp, ede) => edp.EngineDataID == ede.EngineDataID).AS(enginedataTableName)
.LeftJoin((edp, ede, eot) => ede.ObjectTypeID == eot.ObjectTypeID).AS(objectTypeTableName)
.Where((edp, ede, eot) => edp.DeleteFlg == 0 && edp.DrawingFileID == drawingFileID
- && !eot.FullPathCN.EndsWith("图框") && !eot.FullPathCN.EndsWith(GlobalObject.objectType_Base) && !eot.FullPathCN.EndsWith("OPC"))
+ && !eot.FullPathCN.EndsWith("图框") && !eot.FullPathCN.EndsWith(GlobalObject.objectType_Base) && !eot.FullPathCN.EndsWith(GlobalObject.objectType_OPC))
.Select((edp, ede, eot) => edp.EngineDataID)
.Distinct()
.ToList();
@@ -1212,7 +1212,7 @@ namespace Learun.Application.TwoDevelopment.ZZDT_EC
// 筛选出“真实设备”,这里排除OPC、通讯器等中转对象
var deviceTags = endpointInfo
- .Where(x => !x.objectType?.Contains("OPC") ?? false)
+ .Where(x => !x.objectType?.Contains(GlobalObject.objectType_OPC) ?? false)
.Select(x => x.tagNumber)
.Where(tag => !string.IsNullOrWhiteSpace(tag))
.Distinct()
diff --git a/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/ZZDT_EC/ec_enginedata_rel/ec_enginedata_relBLL.cs b/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/ZZDT_EC/ec_enginedata_rel/ec_enginedata_relBLL.cs
index a354c4ff..89f70779 100644
--- a/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/ZZDT_EC/ec_enginedata_rel/ec_enginedata_relBLL.cs
+++ b/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/ZZDT_EC/ec_enginedata_rel/ec_enginedata_relBLL.cs
@@ -13,7 +13,7 @@ using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
-using System.Threading.Tasks;
+using System.Threading.Tasks;
using static Learun.Application.TwoDevelopment.ZZDT_EC.ProjectSugar;
using static Learun.Util.SqlSugar.SqlSugarHelper;
@@ -1348,7 +1348,7 @@ Select((a, b, c) => new
//根据句柄和图纸,先把工程id查出来先
var drawingID = CablePixelID.DrawingID;
var pixelID = CablePixelID.CablePixelID;
- var EngineDataIDs = pixelServ.GetList("{\"ProjectId\":\"" + ProjectId + "\",\"PixelCode\":\"" + pixelID + "\",\"DrawingFileID\":\"" + drawingID + "\"}").
+ var EngineDataIDs = pixelServ.GetList("{\"ProjectId\":\"" + ProjectId + "\",\"PixelCode\":\"" + pixelID + "\",\"DrawingFileID\":\"" + drawingID + "\"}", ProjectId).
Select(x => x.EngineDataID).Distinct();
if (EngineDataIDs != null && EngineDataIDs.Count() == 1)
{
@@ -1395,7 +1395,19 @@ Select((a, b, c) => new
var End2 = new ec_enginedata_relEntity();
//查单一记录
var existRel = this.GetList("{ProjectId:\"" + ProjectId + "\",RelType:\"" + (int)enum_RelType.设备_电缆 + "\",RelEngineDataID:\"" + CableID + "\"}").ToList();
- if (existRel.Any(x => !string.IsNullOrEmpty(x.OPCPixel)))
+ //需要换判断了,现在所有东西都有存这个
+ var tagIds = existRel.Select(x => x.RelEngineData1ID).ToList();
+ tagIds.AddRange(existRel.Select(x => x.RelEngineData2ID).ToList());
+ tagIds = tagIds.Where(X => X != CableID).Distinct().ToList();
+
+ var tbName = ProjectSugar.TableName(ProjectId);
+ var typeTbName = ProjectSugar.TableName(ProjectId);
+ var tags = SqlSugarHelper.Db.Queryable().AS(tbName).
+ InnerJoin((t, t2) => t.ObjectTypeID == t2.ObjectTypeID).AS(typeTbName).
+ Where(t => tagIds.Contains(t.EngineDataID)).
+ Select((t, t2) => new { t.EngineDataID, t.TagNumber, t2.ObjectTypeName }).ToList();
+
+ if (tags.Any(x => x.ObjectTypeName == GlobalObject.objectType_OPC))
{
//OPC
var tb = ProjectSugar.TableName(ProjectId);
@@ -1420,6 +1432,7 @@ Select((a, b, c) => new
}
else
{
+ //正常情况
existRel = existRel.Where(X => X.RelEngineData1ID != opcId.EngineDataID && X.RelEngineData2ID != opcId.EngineDataID).ToList();//排除opc的,留下电缆的
}
}
@@ -1444,11 +1457,11 @@ Select((a, b, c) => new
}
- public class ec_enginedataEntity_2: ec_enginedataEntity
+ public class ec_enginedataEntity_2 : ec_enginedataEntity
{
}
- public class ec_objecttypeEntity_2: ec_objecttypeEntity
+ public class ec_objecttypeEntity_2 : ec_objecttypeEntity
{
}
@@ -1491,7 +1504,7 @@ Select((a, b, c) => new
.WhereIF(!string.IsNullOrEmpty(RelEngineData2ID), a => a.RelEngineData2ID == RelEngineData2ID)
.WhereIF(!string.IsNullOrEmpty(RelTypeName), (a, b) => b.RelTypeName == RelTypeName)
.WhereIF(!string.IsNullOrEmpty(RelType), (a, b) => b.RelType == RelType)
- .Select((a, b, t1,t2,o1,o2) => new ec_enginedata_relEntity
+ .Select((a, b, t1, t2, o1, o2) => new ec_enginedata_relEntity
{
EngineDataRelID = a.EngineDataRelID,
RelTypeID = a.RelTypeID,
@@ -1529,7 +1542,7 @@ Select((a, b, c) => new
// dataIds.Add(x.RelEngineData1ID);
// dataIds.Add(x.RelEngineData2ID);
//});
-
+
//dataIds.AddRange(list?.Select(x => x.RelEngineData1ID).Distinct());
//dataIds.AddRange(list?.Select(x => x.RelEngineData2ID).Distinct());
//dataIds = dataIds.Distinct().ToList();
@@ -1633,7 +1646,7 @@ Select((a, b, c) => new
/// 是否移除已有的,true的话,基本就是确保一对一的这种rel关系
///
///
- public void SaveEntitys(string ProjectId, string RelTypeID, string RelEngineData1ID, List relEngineData2IDs, bool NeedRemove = false)
+ public void SaveEntitys(string ProjectId, string RelTypeID, string RelEngineData1ID, List relEngineData2IDs, string tagPixelId, bool NeedRemove = false)
{
try
{
@@ -1688,7 +1701,7 @@ Select((a, b, c) => new
}
//engineDataRelDel = engineDataRel.Except(engineDataRelExcept).ToList();
List delEngineDataRelIDs = new List(); //engineDataRelDel.Select(x => x.EngineDataRelID).ToList();
- ec_enginedata_relService.SaveEntity(ProjectId, engineDataRelAdd, delEngineDataRelIDs);
+ ec_enginedata_relService.SaveEntity(ProjectId, engineDataRelAdd, delEngineDataRelIDs); //电缆在end1,进行最后的保存
}
catch (Exception ex)
{
@@ -1711,7 +1724,7 @@ Select((a, b, c) => new
///
/// 电缆ID,大概率
///
- public void SaveEntitys(string ProjectId, string RelTypeID, List RelEngineData1IDs, string relEngineData2ID, bool NeedRemove = false)
+ public void SaveEntitys(string ProjectId, string RelTypeID, List RelEngineData1IDs, string relEngineData2ID, string tagPixelId, bool NeedRemove = false)
{
try
{
@@ -1726,7 +1739,6 @@ Select((a, b, c) => new
foreach (var item in RelEngineData1IDs)
{
- //判断下是否为OPC
if (NeedRemove)
{
@@ -1759,6 +1771,7 @@ Select((a, b, c) => new
model.RelTypeID = RelTypeID;
model.RelEngineData1ID = item;
model.RelEngineData2ID = relEngineData2ID;
+ model.OPCPixel = tagPixelId;
engineDataRelAdd.Add(model);
continue;
}
@@ -1775,7 +1788,7 @@ Select((a, b, c) => new
}
//engineDataRelDel = engineDataRel.Except(engineDataRelExcept).ToList();
List delEngineDataRelIDs = new List(); //engineDataRelDel.Select(x => x.EngineDataRelID).ToList();
- ec_enginedata_relService.SaveEntity(ProjectId, engineDataRelAdd, delEngineDataRelIDs);
+ ec_enginedata_relService.SaveEntity(ProjectId, engineDataRelAdd, delEngineDataRelIDs);//电缆在end2,进行最后的保存
}
catch (Exception ex)
{
diff --git a/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/ZZDT_EC/ec_enginedata_rel/ec_enginedata_relIBLL.cs b/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/ZZDT_EC/ec_enginedata_rel/ec_enginedata_relIBLL.cs
index 93c80b9e..cff0f09a 100644
--- a/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/ZZDT_EC/ec_enginedata_rel/ec_enginedata_relIBLL.cs
+++ b/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/ZZDT_EC/ec_enginedata_rel/ec_enginedata_relIBLL.cs
@@ -35,10 +35,10 @@ namespace Learun.Application.TwoDevelopment.ZZDT_EC
/// 主键
///
///
- void SaveEntitys(string ProjectId, string RelTypeID, string RelEngineData1ID, List relEngineData2IDs, bool NeedRemove = false);
+ void SaveEntitys(string ProjectId, string RelTypeID, string RelEngineData1ID, List relEngineData2IDs, string tagPixeId, bool NeedRemove = false);
+
+ void SaveEntitys(string ProjectId, string RelTypeID, List RelEngineData1IDs, string relEngineData2ID, string tagPixeId, bool NeedRemove = false);
- void SaveEntitys(string ProjectId, string RelTypeID, List RelEngineData1IDs, string relEngineData2ID, bool NeedRemove = false);
-
#endregion
diff --git a/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/ZZDT_EC/ec_objecttypep/ec_objecttypepBLL.cs b/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/ZZDT_EC/ec_objecttypep/ec_objecttypepBLL.cs
index 7d0b4d92..5a035895 100644
--- a/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/ZZDT_EC/ec_objecttypep/ec_objecttypepBLL.cs
+++ b/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/ZZDT_EC/ec_objecttypep/ec_objecttypepBLL.cs
@@ -116,29 +116,54 @@ namespace Learun.Application.TwoDevelopment.ZZDT_EC
if (!string.IsNullOrEmpty(objectTypeID))
{
- RES = RES.Where(X => objectTypeID.Split(',').ToList().Contains(X.ObjectTypeID)).ToList();
+ RES = RES.Where(X => objectTypeID.Split(',').Contains(X.ObjectTypeID)).ToList();
}
var propBll = new ec_propertyBLL();
var allProp = propBll.GetListRedis(ProjectId);
+ // 提前构建Dictionary(键为PropertyID,值为对应的AllProp对象)
+ var allPropDict = allProp.ToDictionary(x => x.PropertyID);
var propGroupBll = new ec_propertygBLL();
var allGroup = propGroupBll.GetList("{ProjectId:\"" + ProjectId + "\"}");
+ var allGroupDict = allGroup.ToDictionary(x => x.PropertyGID);
var unitTypeBll = new ec_measuring_unittypeBLL();
var allUnitType = unitTypeBll.GetList("{ProjectId:\"" + ProjectId + "\"}");
+ var allUnitTypeDict = allUnitType.ToDictionary(x => x.MeasuringUnitTypeID);
var unitBll = new ec_measuring_unitBLL();
var allUnit = unitBll.GetListRedis(ProjectId);
+ var allUnitDict = allUnit.ToDictionary(x => x.MeasuringUnitID);
var detailBll = new ec_dataitemBLL();
var allDics = detailBll.GetList("{ProjectId:\"" + ProjectId + "\"}");
var allDetails = detailBll.GetDetailList("", "", ProjectId);
+ var detailsDictGrouped = allDetails.GroupBy(x => x.DataItemID).ToDictionary(g => g.Key, g => g.ToList());//按照DataItemID分组
//strSql.Append($" FROM ec_objecttypep_{ProjectEntity.ProjectIndex} t1 ");
if (isLoadExtraData)
{
foreach (var objectTypeProp in RES)
{
- var t2 = allProp.FirstOrDefault(x => x.PropertyID == objectTypeProp.PropertyID);
- if (t2 == null) { continue; }
- var t3 = allGroup.FirstOrDefault(x => x.PropertyGID == t2.PropertyGID);
- if (t3 == null) { continue; }
- ;
+ // 用TryGetValue快速查询(O(1)时间)
+ if (allPropDict.TryGetValue(objectTypeProp.PropertyID, out var t2))
+ {
+ // 找到匹配项,处理t2
+ }
+ else
+ {
+ // 未找到匹配项的处理逻辑
+ continue;
+ }
+ //var t2 = allProp.FirstOrDefault(x => x.PropertyID == objectTypeProp.PropertyID);
+ //if (t2 == null) { continue; }
+ if (allGroupDict.TryGetValue(t2.PropertyGID, out var t3))
+ {
+ // 找到匹配项,处理t2
+ }
+ else
+ {
+ // 未找到匹配项的处理逻辑
+ continue;
+ }
+ //var t3 = allGroup.FirstOrDefault(x => x.PropertyGID == t2.PropertyGID);
+ //if (t3 == null) { continue; }
+ //;
objectTypeProp.PropertyName = t2.PropertyName;
objectTypeProp.PropertyNameEN = t2.PropertyNameEN;
objectTypeProp.PropertyType = t2.PropertyType;
@@ -158,17 +183,26 @@ namespace Learun.Application.TwoDevelopment.ZZDT_EC
objectTypeProp.PropertyGroupName = t3.PropertyGroupName;
objectTypeProp.PropertyGID = t3.PropertyGID;
+ if (allUnitTypeDict.TryGetValue(t2.MeasuringUnitTypeID, out var t4))
+ {
+ // 找到匹配项,处理t2
+ objectTypeProp.MeasuringUnitTypeName = t4.MeasuringUnitTypeName;
- objectTypeProp.MeasuringUnitTypeName = allUnitType.FirstOrDefault(x => x.MeasuringUnitTypeID == t2.MeasuringUnitTypeID)?.MeasuringUnitTypeName;
- objectTypeProp.DefaultUnitName = allUnit.FirstOrDefault(x => x.MeasuringUnitID == t2.DefaultUnit)?.MeasuringUnitName;
+ }
+ if (allUnitDict.TryGetValue(t2.DefaultUnit, out var t5))
+ {
+ objectTypeProp.DefaultUnitName = t5.MeasuringUnitName;
+
+ }
if (!string.IsNullOrEmpty(t2.EnumData))
{
- var Dic = allDics.FirstOrDefault(X => t2.EnumData == X.DataItemName || t2.EnumData == X.DataItemCode);
+
+ var Dic = allDics.FirstOrDefault(X => t2.EnumData == X.DataItemName || t2.EnumData == X.DataItemCode);//不是按照id来找
if (Dic != null)
{
- foreach (var detail in allDetails.Where(x => x.DataItemID == Dic.DataItemID))
+ foreach (ec_dataitemdetailEntity detail in detailsDictGrouped[Dic.DataItemID])// allDetails.Where(x => x.DataItemID == Dic.DataItemID))
{
if (!string.IsNullOrEmpty(detail.DataItemNameEN) && Dic.ShowEN == 1)
{
@@ -215,16 +249,19 @@ namespace Learun.Application.TwoDevelopment.ZZDT_EC
{
var tObjectType = ProjectSugar.TableName(ProjectId);
var tobjTypeAll = SqlSugarHelper.Db.Queryable().AS(tObjectType).ToList();
+ var tobjTypeDict = tobjTypeAll.ToDictionary(x => x.ObjectTypeID);
foreach (var item in objectTypeID.Split(','))
{
- var pObjectType = RES.Where(x => x.ObjectTypeID == item).ToList();
- var tobjType = tobjTypeAll.First(x => x.ObjectTypeID == item);
+ var pObjectType = RES.Where(x => x.ObjectTypeID == item).ToList();//每种类型下的属性
+ var tobjType = tobjTypeDict[item];//每种类型的名字
+ // 提前提取所有PropertyName到HashSet(仅需一次遍历)
+ var propertyNames = new HashSet(pObjectType.Select(x => x.PropertyName));//每种类型下的属性的名字
if (tobjType.ObjectTypeName.EndsWith("电缆"))
{
- if (!pObjectType.Any(X => X.PropertyName == GlobalObject.propName_parallelCableCombineName))
+ if (!propertyNames.Any(X => X == GlobalObject.propName_parallelCableCombineName))
{
ec_objecttypepEntity UDF_01 = new ec_objecttypepEntity();
UDF_01.ObjectTypePID = Guid.NewGuid().ToString();
@@ -236,7 +273,7 @@ namespace Learun.Application.TwoDevelopment.ZZDT_EC
RES.Add(UDF_01);
}
- if (!pObjectType.Any(X => X.PropertyName == GlobalObject.propName_parallelCableList))
+ if (!propertyNames.Any(X => X == GlobalObject.propName_parallelCableList))
{
ec_objecttypepEntity UDF_02 = new ec_objecttypepEntity();
UDF_02.ObjectTypePID = Guid.NewGuid().ToString();