441 lines
20 KiB
C#
441 lines
20 KiB
C#
|
using Learun.Application.TwoDevelopment.ZZDT_EC;
|
|||
|
using Learun.Util;
|
|||
|
using Learun.Util.SqlSugar;
|
|||
|
using NPOI.SS.Formula.PTG;
|
|||
|
using NPOI.Util.Collections;
|
|||
|
using Pipelines.Sockets.Unofficial.Arenas;
|
|||
|
using System;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Runtime;
|
|||
|
using System.Web;
|
|||
|
using System.Web.Http;
|
|||
|
using System.Windows.Controls;
|
|||
|
|
|||
|
namespace Learun.Application.Web.AppApi
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 绘制布置图相关的(By YuXH)
|
|||
|
/// </summary>
|
|||
|
[HandlerApiLogin(FilterMode.Ignore)]
|
|||
|
public class PlotLayoutApiController : WebApiControllerBase
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 查找一个图上的所有基点
|
|||
|
/// </summary>
|
|||
|
/// <param name="keyProp">所属系统 甲板号 区域 的其中一个</param>
|
|||
|
/// <param name="keyOperator"></param>
|
|||
|
/// <param name="keyValue"></param>
|
|||
|
/// <param name="ProjectId"></param>
|
|||
|
/// <param name="drawingId"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpGet]
|
|||
|
public IHttpActionResult GetBasePointByDwg(string keyProp, string keyOperator, string keyValue, string ProjectId = "c151f5d4-cbe1-4522-945c-501b1ad990d5", string drawingId = "277d883d-e271-45e4-990b-926585321fa8")
|
|||
|
{
|
|||
|
var typeTbName = ProjectSugar.TableName<ec_objecttypeEntity>(ProjectId);
|
|||
|
var pixelTbName = ProjectSugar.TableName<ec_enginedata_pixelEntity>(ProjectId);
|
|||
|
var tagTbName = ProjectSugar.TableName<ec_enginedataEntity>(ProjectId);
|
|||
|
var propTbName = ProjectSugar.TableName<ec_enginedata_propertyEntity>(ProjectId);
|
|||
|
var listTbName = ProjectSugar.TableName<ec_dataitemEntity>(ProjectId);
|
|||
|
var detailTbName = ProjectSugar.TableName<ec_dataitemdetailEntity>(ProjectId);
|
|||
|
var typeFilterTbName = ProjectSugar.TableName<ec_objTypeLayoutFilter>(ProjectId);
|
|||
|
var typeFilterPTbName = ProjectSugar.TableName<ec_objTypeLayoutFilterP>(ProjectId);
|
|||
|
|
|||
|
var allFilter = SqlSugarHelper.Db.Queryable<ec_objTypeLayoutFilter>().AS(typeFilterTbName).ToList();
|
|||
|
|
|||
|
var allFilterP = SqlSugarHelper.Db.Queryable<ec_objTypeLayoutFilterP>().AS(typeFilterPTbName).ToList();
|
|||
|
|
|||
|
var allType = SqlSugarHelper.Db.Queryable<ec_objecttypeEntity>().AS(typeTbName).ToList();
|
|||
|
var pointType = allType.First(x => x.ObjectTypeName == GlobalObject.objectType_Base);
|
|||
|
if (pointType == null)
|
|||
|
{
|
|||
|
return Fail("找不到基点这个对象类型。");
|
|||
|
}
|
|||
|
#region frame
|
|||
|
List<FrameList> frameLists = new List<FrameList>();
|
|||
|
frameLists.Add(new FrameList()
|
|||
|
{ Num = "", Value = 0 });
|
|||
|
var settings = new ec_projectSettingsBLL();
|
|||
|
var ec_dataitemBLL = new ec_dataitemBLL();
|
|||
|
|
|||
|
var FrameListFlg = settings.GetEntity(GlobalObject.projSetting_enumlist_Frame, ProjectId);
|
|||
|
|
|||
|
if (FrameListFlg != null)
|
|||
|
{
|
|||
|
|
|||
|
var FrameDetail = ec_dataitemBLL.GetDetailList(FrameListFlg.SettingValue, "", ProjectId, false);
|
|||
|
if (FrameDetail == null)
|
|||
|
{
|
|||
|
return Fail("项目数据字典中,没有找到【肋位号】的下拉项中。");// 或者 无法从数据字典中找到对应的那个下拉
|
|||
|
}
|
|||
|
foreach (var item in FrameDetail)
|
|||
|
{
|
|||
|
double value;
|
|||
|
if (double.TryParse(item.DataItemCode, out value))
|
|||
|
{
|
|||
|
frameLists.Add(new FrameList() { Num = item.DataItemName, Value = value });
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
frameLists = frameLists.OrderBy(t => t.Value).ToList();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return Fail("项目设置中(projectSettings表),没有找到【肋位号】的设置项。");// 或者 无法从数据字典中找到对应的那个下拉
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
var pointsOnDwg = SqlSugarHelper.Db.Queryable<ec_enginedata_pixelEntity>().AS(pixelTbName).
|
|||
|
Where(x => x.DrawingFileID == drawingId).ToList();
|
|||
|
var pointTags = SqlSugarHelper.Db.Queryable<ec_enginedataEntity>().AS(tagTbName).
|
|||
|
Where(x => pointsOnDwg.Select(y => y.EngineDataID).Distinct().Contains(x.EngineDataID)
|
|||
|
&& x.ObjectTypeID == pointType.ObjectTypeID).ToList();
|
|||
|
var propAll = SqlSugarHelper.Db.Queryable<ec_enginedata_propertyEntity>().AS(propTbName).ToList();
|
|||
|
//Where(x => x.PropertyName == GlobalObject.propName_Frame
|
|||
|
//|| x.PropertyName == GlobalObject.propName_FrameOff
|
|||
|
//|| x.PropertyName == GlobalObject.propName_YOff
|
|||
|
//|| x.PropertyName == GlobalObject.propName_System
|
|||
|
//|| x.PropertyName == "甲板号"
|
|||
|
//|| x.PropertyName == "区域").ToList();
|
|||
|
List<layoutTagInfoBrief> res = new List<layoutTagInfoBrief>();
|
|||
|
foreach (var pointTag in pointTags)
|
|||
|
{
|
|||
|
var tagProps = propAll.FindAll(x => x.EngineDataID == pointTag.EngineDataID);
|
|||
|
var Prop_Frame = tagProps.FirstOrDefault(x => x.PropertyName == GlobalObject.propName_Frame)?.PropertyValue;
|
|||
|
Prop_Frame = Prop_Frame.Split(new string[] { "||" }, StringSplitOptions.None)[0];//插件端对于下拉列表 都是 name || nameEN
|
|||
|
var Prop_FrameOff = tagProps.FirstOrDefault(x => x.PropertyName == GlobalObject.propName_FrameOff)?.PropertyValue;
|
|||
|
var Prop_YOff = tagProps.FirstOrDefault(x => x.PropertyName == GlobalObject.propName_YOff)?.PropertyValue;
|
|||
|
var DECK = tagProps.FirstOrDefault(x => x.PropertyName == "甲板号")?.PropertyValue;
|
|||
|
var AREA = tagProps.FirstOrDefault(x => x.PropertyName == "区域")?.PropertyValue;
|
|||
|
var layoutTag = new layoutTagInfoBrief()
|
|||
|
{
|
|||
|
EngineDataID = pointTag.EngineDataID,
|
|||
|
FileId = "",
|
|||
|
PixelOnDwg = pointsOnDwg.FirstOrDefault(x => x.EngineDataID == pointTag.EngineDataID)?.PixelCode,
|
|||
|
TagNumber = pointTag.TagNumber,
|
|||
|
X = frameLists.FirstOrDefault(X => X.Num == Prop_Frame).Value,
|
|||
|
XOff = Prop_FrameOff,
|
|||
|
YOff = Prop_YOff,
|
|||
|
deck = DECK,
|
|||
|
area = AREA
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
res.Add(layoutTag);
|
|||
|
}
|
|||
|
// 找出area和deck列组合重复的行
|
|||
|
var duplicateGroups = res
|
|||
|
.GroupBy(r => new { r.area, r.deck })
|
|||
|
.Where(g => g.Count() > 1)
|
|||
|
.ToList();
|
|||
|
if (duplicateGroups.Any())
|
|||
|
{
|
|||
|
return Fail("该图纸上有区域和甲板信息重复的基点存在。");
|
|||
|
}
|
|||
|
|
|||
|
//这里要考虑下拉列表 带 ||的问题
|
|||
|
var matchedTagIds = propAll.Where(x => x.PropertyName == keyProp
|
|||
|
&& (x.PropertyValue == keyValue || x.PropertyValue.StartsWith(keyValue + "||"))).
|
|||
|
Select(X => X.EngineDataID).Distinct().ToList();
|
|||
|
|
|||
|
//有效范围的设备
|
|||
|
var matchedTags = SqlSugarHelper.Db.Queryable<ec_enginedataEntity>().AS(tagTbName).
|
|||
|
InnerJoin<ec_objecttypeEntity>((a, b) => a.ObjectTypeID == b.ObjectTypeID).AS<ec_objecttypeEntity>(typeTbName).
|
|||
|
Where(a => matchedTagIds.Contains(a.EngineDataID)
|
|||
|
&& a.ObjectTypeID != pointType.ObjectTypeID)
|
|||
|
.Select((a, b) => new { a.EngineDataID, a.TagNumber, a.ObjectTypeID, b.DefaultLayoutLibFileID })
|
|||
|
.ToList();
|
|||
|
|
|||
|
//有效范围的设备的所有属性
|
|||
|
var EquipPropAll = propAll.Where(x => matchedTags.Select(y => y.EngineDataID).Contains(x.EngineDataID)).ToList();
|
|||
|
foreach (var basePoint in res)
|
|||
|
{
|
|||
|
#region 每个基点关联的设备
|
|||
|
//甲板 区域都和基点一致的设备
|
|||
|
var DeckMatchedTagIds = EquipPropAll.Where(x => x.PropertyName == "甲板号" && x.PropertyValue == basePoint.deck).Select(X => X.EngineDataID).ToList();
|
|||
|
var AreaMatchedTagIds = EquipPropAll.Where(x => x.PropertyName == "区域" && x.PropertyValue == basePoint.area).Select(X => X.EngineDataID).ToList();
|
|||
|
|
|||
|
var matchPointTagIds = DeckMatchedTagIds.Intersect(AreaMatchedTagIds).ToList();
|
|||
|
|
|||
|
foreach (var matchPointTagId in matchPointTagIds)
|
|||
|
{
|
|||
|
var tagProps = EquipPropAll.Where(x => x.EngineDataID == matchPointTagId).ToList();
|
|||
|
var Prop_Frame = tagProps.FirstOrDefault(x => x.PropertyName == GlobalObject.propName_Frame)?.PropertyValue;
|
|||
|
Prop_Frame = Prop_Frame.Split(new string[] { "||" }, StringSplitOptions.None)[0];//插件端对于下拉列表 都是 name || nameEN
|
|||
|
var Prop_FrameOff = tagProps.FirstOrDefault(x => x.PropertyName == GlobalObject.propName_FrameOff)?.PropertyValue;
|
|||
|
var Prop_YOff = tagProps.FirstOrDefault(x => x.PropertyName == GlobalObject.propName_YOff)?.PropertyValue;
|
|||
|
|
|||
|
var tagInfo = matchedTags.FirstOrDefault(X => X.EngineDataID == matchPointTagId);
|
|||
|
|
|||
|
#region 判断是否满足特定条件
|
|||
|
var fileId = tagInfo.DefaultLayoutLibFileID;
|
|||
|
var matched = false;
|
|||
|
foreach (var filter in allFilter.Where(x => x.ObjectTypeId == tagInfo.ObjectTypeID))
|
|||
|
{
|
|||
|
if (matched)
|
|||
|
{
|
|||
|
//有一个满足就可以了
|
|||
|
break;
|
|||
|
}
|
|||
|
var filterOp = filter.Operator;//and or
|
|||
|
var filterPs = allFilterP.Where(x => x.FilterID == filter.SP_ID).ToList();
|
|||
|
|
|||
|
foreach (var filterP in filterPs)
|
|||
|
{
|
|||
|
var prop = tagProps.FirstOrDefault(x => x.PropertyName == filterP.PropertyName);
|
|||
|
if (prop != null)
|
|||
|
{
|
|||
|
if (prop.PropertyValue.ToUpper() == filterP.Value.ToUpper())
|
|||
|
{
|
|||
|
if (filterOp.ToUpper() == "OR")
|
|||
|
{
|
|||
|
//一个满足即可
|
|||
|
matched = true;
|
|||
|
fileId = filter.LayoutLibFileID;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (filterOp.ToUpper() == "AND")
|
|||
|
{
|
|||
|
//一个不满足都不满足
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//压根没这个属性,认为不符合
|
|||
|
if (filterOp.ToUpper() == "AND")
|
|||
|
{
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//能走到这里说明满足这个
|
|||
|
matched = true;
|
|||
|
fileId = tagInfo.DefaultLayoutLibFileID;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
var layoutTagInfo = new layoutTagInfoBrief()
|
|||
|
{
|
|||
|
EngineDataID = matchPointTagId,
|
|||
|
FileId = fileId, //2个优先级
|
|||
|
PixelOnDwg = "",
|
|||
|
TagNumber = tagInfo.TagNumber,
|
|||
|
X = frameLists.FirstOrDefault(X => X.Num == Prop_Frame).Value,
|
|||
|
XOff = Prop_FrameOff,
|
|||
|
YOff = Prop_YOff,
|
|||
|
deck = basePoint.deck,
|
|||
|
area = basePoint.area
|
|||
|
};
|
|||
|
basePoint.Tags.Add(layoutTagInfo);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return Success(res);
|
|||
|
}
|
|||
|
///// <summary>
|
|||
|
///// 拿项目的所属系统。所属系统是一个特定的数据字典。至于哪个作为所属系统,则从settingAPI里查询
|
|||
|
///// </summary>
|
|||
|
///// <param name="ProjectId"></param>
|
|||
|
///// <returns>返回TreeModel</returns>
|
|||
|
//[HttpGet]
|
|||
|
//public IHttpActionResult GetSystemList(string ProjectId)
|
|||
|
//{
|
|||
|
// var ec_propertyBLL = new ec_propertyBLL();
|
|||
|
// var ec_dataitemBLL = new ec_dataitemBLL();
|
|||
|
// var settings = new ec_projectSettingsBLL();
|
|||
|
// List<TreeModel> treeList = new List<TreeModel>();
|
|||
|
// var FrameListFlg = settings.GetEntity("所属系统", ProjectId);//???感觉不需要啊
|
|||
|
|
|||
|
// if (FrameListFlg != null)
|
|||
|
// {
|
|||
|
// //从setting找属性
|
|||
|
// var property = ec_propertyBLL.GetList("{PropertyName:\"" + FrameListFlg.SettingValue + "\",ProjectId:\"" + ProjectId + "\"}").FirstOrDefault();
|
|||
|
// if (property != null)
|
|||
|
// {
|
|||
|
// //从属性去找数据字典
|
|||
|
// var res = ec_dataitemBLL.GetDetailList(property.EnumData, "", ProjectId, false);
|
|||
|
// foreach (var item in res)
|
|||
|
// {
|
|||
|
// TreeModel node = new TreeModel();
|
|||
|
// node.id = item.DataItemDetailID;
|
|||
|
// node.text = item.DataItemName + "," + item.DataItemCode; //名字 + 编码 20230512;
|
|||
|
// node.value = item.DataItemCode;
|
|||
|
// node.showcheck = false;
|
|||
|
// node.checkstate = 0;
|
|||
|
// node.isexpand = true;
|
|||
|
// node.parentId = item.UpDataItemDetailID == null ? "0" : item.UpDataItemDetailID;
|
|||
|
// treeList.Add(node);
|
|||
|
|
|||
|
|
|||
|
// }
|
|||
|
// treeList = treeList.ToTree();
|
|||
|
// return Success(treeList);
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// return Fail($"属性中(property表),没有找到【{FrameListFlg.SettingValue}】的属性。");
|
|||
|
// }
|
|||
|
|
|||
|
|
|||
|
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// return Fail("项目设置中(projectSettings表),没有找到【所属系统】的设置项。");
|
|||
|
// }
|
|||
|
|
|||
|
//}
|
|||
|
/// <summary>
|
|||
|
/// 根据选中的所属系统,返回位号id,fileid和md5
|
|||
|
/// </summary>
|
|||
|
/// <param name="ProjectId"></param>
|
|||
|
/// <param name="DataItemNames">数据字典里的枚举值,以逗号分开,不需要带引号</param>
|
|||
|
/// <returns>返回List<treeModel>,id是对象id,text是fileId,value是MD5</treeModel></returns>
|
|||
|
[HttpGet]
|
|||
|
[Obsolete]
|
|||
|
public IHttpActionResult GetLibraryFileBySelectedSystem(string ProjectId, string DataItemNames)
|
|||
|
{
|
|||
|
var res = new ec_library_fileService().GetFileOnSystemDwgByTagId(ProjectId, DataItemNames);
|
|||
|
return Success(res);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 拿项目的肋位号。肋位号是一个特定的数据字典。至于哪个作为肋位号,则从settingAPI里查询
|
|||
|
/// </summary>
|
|||
|
/// <param name="ProjectId"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpGet]
|
|||
|
public IHttpActionResult GetFrameList(string ProjectId)
|
|||
|
{
|
|||
|
var ec_dataitemBLL = new ec_dataitemBLL();
|
|||
|
var settings = new ec_projectSettingsBLL();
|
|||
|
|
|||
|
var FrameListFlg = settings.GetEntity(GlobalObject.projSetting_enumlist_Frame, ProjectId);
|
|||
|
|
|||
|
if (FrameListFlg != null)
|
|||
|
{
|
|||
|
List<FrameList> frameLists = new List<FrameList>();
|
|||
|
|
|||
|
|
|||
|
var res = ec_dataitemBLL.GetDetailList(FrameListFlg.SettingValue, "", ProjectId, false);
|
|||
|
if (res == null)
|
|||
|
{
|
|||
|
return Fail("项目设置中(projectSettings表),没有找到【肋位号】的设置项中,对应的那个下拉。");// 或者 无法从数据字典中找到对应的那个下拉
|
|||
|
}
|
|||
|
foreach (var item in res)
|
|||
|
{
|
|||
|
double value;
|
|||
|
if (double.TryParse(item.DataItemCode, out value))
|
|||
|
{
|
|||
|
frameLists.Add(new FrameList() { Num = item.DataItemName, Value = value });
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
frameLists = frameLists.OrderBy(t => t.Value).ToList();
|
|||
|
return Success(frameLists);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return Fail("项目设置中(projectSettings表),没有找到【肋位号】的设置项。");// 或者 无法从数据字典中找到对应的那个下拉
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 根据ObjectTypeID,查绘制布置图时的图例
|
|||
|
/// </summary>
|
|||
|
/// <param name="ProjectId"></param>
|
|||
|
/// <param name="objectTypeID"></param>
|
|||
|
/// <returns>返回一个LibraryFileID属性的json对象</returns>
|
|||
|
[HttpGet]
|
|||
|
public IHttpActionResult GetLibraryFileByType(string ProjectId, string objectTypeID)
|
|||
|
{
|
|||
|
//DefaultLayoutLibFileID
|
|||
|
|
|||
|
var res = new ec_objecttypeBLL().GetEntity(objectTypeID, ProjectId);
|
|||
|
if (res == null)
|
|||
|
{
|
|||
|
return Fail("无效的ObjectTypeID");
|
|||
|
}
|
|||
|
if (string.IsNullOrEmpty(res.DefaultLayoutLibFileID))
|
|||
|
{
|
|||
|
return Success("0");
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
var fileObj = new ec_library_fileBLL().GetEntity(res.DefaultLayoutLibFileID, ProjectId);
|
|||
|
if (fileObj != null)
|
|||
|
{
|
|||
|
return Success(("{LibraryFileID:\"" + res.DefaultLayoutLibFileID + "\"}").ToJObject());
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return Success("0");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 查绘制布置图时的图例。
|
|||
|
/// </summary>
|
|||
|
/// <param name="ProjectId"></param>
|
|||
|
/// <returns>返回所有有DefaultLayoutLibFileID的对象类型集合</returns>
|
|||
|
[HttpGet]
|
|||
|
public IHttpActionResult GetLibraryFileAll(string ProjectId)
|
|||
|
{
|
|||
|
//获取当前项目的所有对象类型数据
|
|||
|
var allObjectData = new ec_objecttypeBLL().GetList("{ProjectId:\"" + ProjectId + "\"}").ToList();
|
|||
|
List<ec_objecttypeEntity> resAll = new List<ec_objecttypeEntity>();
|
|||
|
var fileBlll = new ec_library_fileBLL();
|
|||
|
foreach (var res in allObjectData)
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(res.DefaultLayoutLibFileID))
|
|||
|
{
|
|||
|
continue;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
var fileObj = fileBlll.GetEntity(res.DefaultLayoutLibFileID, ProjectId);
|
|||
|
if (fileObj != null)
|
|||
|
{
|
|||
|
resAll.Add(res);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
continue;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return Success(resAll);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 肋位号
|
|||
|
/// </summary>
|
|||
|
public class FrameList
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 号
|
|||
|
/// </summary>
|
|||
|
public string Num { get; set; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 值。单位是m
|
|||
|
/// </summary>
|
|||
|
public double Value { get; set; }
|
|||
|
}
|
|||
|
|
|||
|
}
|