Merge branch 'main' of http://27.154.35.18:7053/yuxingheng/009_DI-Elec
This commit is contained in:
commit
716a1e3524
@ -533,131 +533,140 @@ namespace Learun.Application.TwoDevelopment.ZZDT_EC
|
||||
ValueInGroup = false
|
||||
})
|
||||
.ToList();
|
||||
// ====== [1] 提前建索引,避免循环里反复Where ======
|
||||
|
||||
// AllPropsOfEng 索引: (EngineDataID, PropertyID) -> 属性对象
|
||||
var allPropsDict = AllPropsOfEng
|
||||
.GroupBy(x => (x.EngineDataID, x.PropertyID))
|
||||
.ToDictionary(g => g.Key, g => g.First());
|
||||
|
||||
// quaryNeedCheckPropertiesDependency 索引: (EngineDataID, PropertyID) -> Dependency对象
|
||||
var depDict = quaryNeedCheckPropertiesDependency
|
||||
.GroupBy(x => (x.EngineDataID, x.PropertyID))
|
||||
.ToDictionary(g => g.Key, g => g.First());
|
||||
|
||||
// 索引: (PropertyID, ObjectTypeID) -> Dependency对象 (用于 RequireIf)
|
||||
var depByPropObjDict = quaryNeedCheckPropertiesDependency
|
||||
.GroupBy(x => (x.PropertyID, x.ObjectTypeID))
|
||||
.ToDictionary(g => g.Key, g => g.First());
|
||||
|
||||
// 索引: (PropertyGID, EngineDataID) -> List<Dependency> (用于 RequireMutually)
|
||||
var depByGroupDict = quaryNeedCheckPropertiesDependency
|
||||
.GroupBy(x => (x.PropertyGID, x.EngineDataID))
|
||||
.ToDictionary(g => g.Key, g => g.ToList());
|
||||
|
||||
foreach (var checkproperty in quaryNeedCheckPropertiesDependency)
|
||||
{
|
||||
//先看前置属性必填的情况
|
||||
// ----------------- RequireIfRequired -----------------
|
||||
if (checkproperty.dependency_type == dependency_type.RequireIfRequired
|
||||
&& !string.IsNullOrEmpty(checkproperty.trigger_property_id))
|
||||
{
|
||||
//获得关联对象是否必填
|
||||
var depObjIsNotRequired = quaryNeedCheckPropertiesDependency
|
||||
.Where(x => x.EngineDataID == checkproperty.EngineDataID
|
||||
&& x.PropertyID == checkproperty.trigger_property_id)
|
||||
.Select(x => x.IsRequired)
|
||||
.FirstOrDefault();
|
||||
//如果关联对象是必填的,那么就需要检查属性本身的值是不是空或者0
|
||||
if (depObjIsNotRequired == 1 && checkproperty.IsRequired == 1)//前置属性即时更新版必填的话,自己的即时更新版也必填,不然本身自己也显示不到EXCEL里面
|
||||
if (depDict.TryGetValue((checkproperty.EngineDataID, checkproperty.trigger_property_id), out var depObj)
|
||||
&& depObj.IsRequired == 1 && checkproperty.IsRequired == 1)
|
||||
{
|
||||
var PropertyValue = AllPropsOfEng
|
||||
.FirstOrDefault(x =>
|
||||
x.EngineDataID == checkproperty.EngineDataID &&
|
||||
x.PropertyID == checkproperty.PropertyID)
|
||||
?.PropertyValue;
|
||||
//foreach (var property in AllPropsOfEng.Where(x=>x.EngineDataID.Equals(checkproperty.EngineDataID)))
|
||||
//{
|
||||
//判断当前属性的值是不是为空、为NULL还是为0,如果是的话,报错
|
||||
if (string.IsNullOrEmpty(PropertyValue) || PropertyValue == "0")
|
||||
if (allPropsDict.TryGetValue((checkproperty.EngineDataID, checkproperty.PropertyID), out var prop))
|
||||
{
|
||||
errText = $"图面有对象【{checkproperty.TagNumber}】,其前置属性设置了必填,所以属性【{checkproperty.PropertyName}】本身也必须填值,不然不能检入,请执行“属性检查”功能对图纸进行属性检查。";
|
||||
return res = false;
|
||||
var value = prop.PropertyValue;
|
||||
if (string.IsNullOrEmpty(value) || value == "0")
|
||||
{
|
||||
errText = $"图面有对象【{checkproperty.TagNumber}】,其前置属性设置了必填,所以属性【{checkproperty.PropertyName}】本身也必须填值,不然不能检入,请执行“属性检查”功能对图纸进行属性检查。";
|
||||
return res = false;
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
||||
//前置属性符合某种条件时
|
||||
// ----------------- RequireIf -----------------
|
||||
if (checkproperty.dependency_type == dependency_type.RequireIf
|
||||
&& !string.IsNullOrEmpty(checkproperty.trigger_property_id)
|
||||
&& !string.IsNullOrEmpty(checkproperty.trigger_operator)
|
||||
&& !string.IsNullOrEmpty(checkproperty.trigger_value))
|
||||
{
|
||||
var triggerOperator = checkproperty.trigger_operator;
|
||||
var triggerValue = checkproperty.trigger_value;
|
||||
var triggerPropertyId = checkproperty.trigger_property_id;
|
||||
//先从该对象的属性列表里面找前置条件的那个属性,如果没有找到,证明前置属性为NULL,就是空,那么也就不用继续考虑本身是不是为空了
|
||||
if (AllPropsOfEng.Where(x => x.EngineDataID == checkproperty.EngineDataID).Select(x => x.PropertyID).Contains(triggerPropertyId))
|
||||
|
||||
// 如果前置属性在 AllProps 里面找不到,就直接跳过
|
||||
if (allPropsDict.ContainsKey((checkproperty.EngineDataID, triggerPropertyId)))
|
||||
{
|
||||
//找到上级的Isrequired值
|
||||
var upObjectIsRequired = quaryNeedCheckPropertiesDependency.Where(x => x.PropertyID.Equals(triggerPropertyId) && x.ObjectTypeID.Equals(checkproperty.ObjectTypeID)).Select(x => x.IsRequired).FirstOrDefault();
|
||||
//当前属性的IsRequired和上级的IsRequired都是即时更新版必填时才可以去做检入时检查
|
||||
if (upObjectIsRequired == 1 && checkproperty.IsRequired == 1)
|
||||
if (depByPropObjDict.TryGetValue((triggerPropertyId, checkproperty.ObjectTypeID), out var upObj)
|
||||
&& upObj.IsRequired == 1 && checkproperty.IsRequired == 1)
|
||||
{
|
||||
var PropertyValue = AllPropsOfEng
|
||||
.FirstOrDefault(x =>
|
||||
x.EngineDataID == checkproperty.EngineDataID &&
|
||||
x.PropertyID == checkproperty.PropertyID)
|
||||
?.PropertyValue;
|
||||
//进入循环了,证明能找到前置属性
|
||||
//foreach (var property in AllPropsOfEng)
|
||||
//{
|
||||
//先判断当前属性值是不是空或者0,不是的话也就不用去进一步判断了,如果是空或者0,则去看她的前置属性
|
||||
if (string.IsNullOrEmpty(PropertyValue) || PropertyValue == "0")
|
||||
// 当前属性值
|
||||
string propertyValue = allPropsDict.TryGetValue((checkproperty.EngineDataID, checkproperty.PropertyID), out var prop)
|
||||
? prop.PropertyValue : null;
|
||||
|
||||
if (string.IsNullOrEmpty(propertyValue) || propertyValue == "0")
|
||||
{
|
||||
//取当前属性的上级联动属性值
|
||||
var upPropertyValue = AllPropsOfEng?.Where(x =>
|
||||
x?.EngineDataID != null
|
||||
&& x.PropertyID != null
|
||||
&& x.EngineDataID.Equals(checkproperty?.EngineDataID)
|
||||
&& x.PropertyID.Equals(triggerPropertyId)).FirstOrDefault();
|
||||
if (upPropertyValue == null)
|
||||
// 找上级属性值
|
||||
if (!allPropsDict.TryGetValue((checkproperty.EngineDataID, triggerPropertyId), out var upProp))
|
||||
{
|
||||
errText = $"图面对象【{checkproperty.TagNumber}】,其属性【{checkproperty.PropertyName}】的前置属性【{triggerPropertyId}】找不到。请管理员确认。";
|
||||
return res = false;
|
||||
}
|
||||
//如果上级属性值符合条件,那么同时根据上面的判断,当前属性值不是空就是0,那么需要报错
|
||||
if ((triggerOperator == "=" && upPropertyValue.PropertyValue.ToUpper().Equals(triggerValue.ToUpper())) ||
|
||||
(triggerOperator == ">" && double.Parse(upPropertyValue.PropertyValue) > double.Parse(triggerValue)) ||
|
||||
(triggerOperator == "<" && double.Parse(upPropertyValue.PropertyValue) < double.Parse(triggerValue)) ||
|
||||
(triggerOperator == "!=" && !upPropertyValue.PropertyValue.ToUpper().Equals(triggerValue.ToUpper())))
|
||||
|
||||
// 判断触发条件
|
||||
bool conditionMet = false;
|
||||
var triggerValue = checkproperty.trigger_value;
|
||||
var triggerOperator = checkproperty.trigger_operator;
|
||||
|
||||
switch (triggerOperator)
|
||||
{
|
||||
errText = $"图面有对象【{checkproperty.TagNumber}】,其前置属性【{upPropertyValue.PropertyName}】符合{triggerOperator}条件,所以属性本身【{checkproperty.PropertyName}】必须填值,不然不能检入,请执行“属性检查”功能对图纸进行属性检查。";
|
||||
case "=":
|
||||
conditionMet = upProp.PropertyValue?.Equals(triggerValue, StringComparison.OrdinalIgnoreCase) == true;
|
||||
break;
|
||||
case "!=":
|
||||
conditionMet = !upProp.PropertyValue?.Equals(triggerValue, StringComparison.OrdinalIgnoreCase) == true;
|
||||
break;
|
||||
case ">":
|
||||
if (double.TryParse(upProp.PropertyValue, out var upVal) &&
|
||||
double.TryParse(triggerValue, out var trgVal))
|
||||
conditionMet = upVal > trgVal;
|
||||
break;
|
||||
case "<":
|
||||
if (double.TryParse(upProp.PropertyValue, out var upVal2) &&
|
||||
double.TryParse(triggerValue, out var trgVal2))
|
||||
conditionMet = upVal2 < trgVal2;
|
||||
break;
|
||||
}
|
||||
|
||||
if (conditionMet)
|
||||
{
|
||||
errText = $"图面有对象【{checkproperty.TagNumber}】,其前置属性【{upProp.PropertyName}】符合{triggerOperator}条件,所以属性本身【{checkproperty.PropertyName}】必须填值,不然不能检入,请执行“属性检查”功能对图纸进行属性检查。";
|
||||
return res = false;
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
//最后看组内互斥,检入的话只检查即时更新版的
|
||||
// ----------------- RequireMutually -----------------
|
||||
if (checkproperty.dependency_type == dependency_type.RequireMutually
|
||||
&& checkproperty.ValueInGroup == false
|
||||
&& checkproperty.IsRequired == 1)
|
||||
{
|
||||
var PgID = string.Empty;
|
||||
//如果ec_enginedata_propety里面没有必填属性要求的这个属性,就代表没有保存,认为是没有填值,为空
|
||||
if (AllPropsOfEng.Where(x => x.EngineDataID == checkproperty.EngineDataID).Select(x => x.PropertyID).Contains(checkproperty.PropertyID))
|
||||
if (allPropsDict.TryGetValue((checkproperty.EngineDataID, checkproperty.PropertyID), out var prop))
|
||||
{
|
||||
var PropertyValue = AllPropsOfEng
|
||||
.FirstOrDefault(x =>
|
||||
x.EngineDataID == checkproperty.EngineDataID &&
|
||||
x.PropertyID == checkproperty.PropertyID)
|
||||
?.PropertyValue;
|
||||
//foreach (var property in AllPropsOfEng)
|
||||
//{
|
||||
//如果ec_enginedata_propety里面的EngineDataID等于需要检查对象的EngineDataID,且属性ID也能对上,也属于同一group,且属性值为空或者NULL,则认为没有填写
|
||||
if (!string.IsNullOrEmpty(PropertyValue) && PropertyValue != "0")
|
||||
var value = prop.PropertyValue;
|
||||
if (!string.IsNullOrEmpty(value) && value != "0")
|
||||
{
|
||||
PgID = checkproperty.PropertyGID;//获得有属性值的属性组ID
|
||||
//break;
|
||||
}
|
||||
//}
|
||||
if (!string.IsNullOrEmpty(PgID))
|
||||
{
|
||||
foreach (var propertyvalue in quaryNeedCheckPropertiesDependency
|
||||
.Where(x => x.PropertyGID == PgID
|
||||
&& x.EngineDataID == checkproperty.EngineDataID
|
||||
&& x.dependency_type == dependency_type.RequireMutually))
|
||||
// 有属性值 → 找到组
|
||||
var groupKey = (checkproperty.PropertyGID, checkproperty.EngineDataID);
|
||||
if (depByGroupDict.TryGetValue(groupKey, out var groupList))
|
||||
{
|
||||
//把这个对象上只要属于这个检查组的ValueInGroup都打上标记,代表检查组里面至少有一个属性是有值的
|
||||
propertyvalue.ValueInGroup = true;
|
||||
foreach (var dep in groupList)
|
||||
{
|
||||
dep.ValueInGroup = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var lstValueGroup = quaryNeedCheckPropertiesDependency.Where(x => x.dependency_type == dependency_type.RequireMutually && x.IsRequired == 1).Select(x => new { x.ValueInGroup, x.EngineDataID }).Distinct().ToList();
|
||||
// ====== [3] 组内互斥最后检查 ======
|
||||
var lstValueGroup = quaryNeedCheckPropertiesDependency
|
||||
.Where(x => x.dependency_type == dependency_type.RequireMutually && x.IsRequired == 1)
|
||||
.Select(x => new { x.ValueInGroup, x.EngineDataID })
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
foreach (var item in lstValueGroup)
|
||||
{
|
||||
if (item.ValueInGroup == false)
|
||||
@ -834,6 +843,7 @@ namespace Learun.Application.TwoDevelopment.ZZDT_EC
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//没有依赖对象但要必填的循环
|
||||
foreach (var checkproperty in quaryNeedCheckProperties)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user