namespace Yw.Application
|
{
|
/// <summary>
|
/// HealthQuotaEvaluationHandOnline
|
/// </summary>
|
[Route("Health/Quota/Evaluation/Online/Logic")]
|
[ApiDescriptionSettings("Health", Name = "指标在线评价(业务)", Order = 900)]
|
public class HealthQuotaEvaluationHandOnline_LogicController : IDynamicApiController
|
{
|
|
/// <summary>
|
/// 通过 EquipmentID 获取
|
/// </summary>
|
[Route("GetByEquipmentID@V1.0")]
|
[HttpGet]
|
public List<MonitorPointOnlineLogicDto> GetByEquipmentID([FromQuery][Required] EquipmentIDInput input)
|
{
|
var equipmentId = input.EquipmentID;
|
|
#region 获取所有设备
|
|
var serviceEquipment = new Service.Equipment();
|
var allEquipmentList = serviceEquipment.GetChildAndSelfByID(equipmentId);
|
if (allEquipmentList == null || allEquipmentList.Count < 1)
|
{
|
throw Oops.Oh(ErrorCodes.D001, $"EquipmentID:{equipmentId}");
|
}
|
|
#endregion
|
|
#region 获取设备测点映射
|
|
var allEquipmentIds = allEquipmentList.Select(x => x.ID).Distinct().ToList();
|
var serviceMonitorMapping = new Service.EquipmentMonitorMapping();
|
var allMonitorMappingList = serviceMonitorMapping.GetByEquipmentIds(allEquipmentIds);
|
if (allMonitorMappingList == null || allMonitorMappingList.Count < 1)
|
{
|
return default;
|
}
|
|
#endregion
|
|
#region 获取所有测点
|
|
var allMonitorIds = allMonitorMappingList.Select(x => x.MonitorPointID).Distinct().ToList();
|
var serviceMonitor = new Service.MonitorPoint();
|
var allMonitorList = serviceMonitor.GetExSignalWithSignalTypeByIds(allMonitorIds);
|
if (allMonitorList == null || allMonitorList.Count < 1)
|
{
|
return default;
|
}
|
|
#endregion
|
|
#region 获取所有测点组
|
|
var allGroupIds = allMonitorList.Select(x => x.GroupID).Distinct().ToList();
|
var serviceMonitorGroup = new Service.MonitorPointGroup();
|
var allGroupList = serviceMonitorGroup.GetByIds(allGroupIds);
|
if (allGroupList == null || allGroupList.Count < 1)
|
{
|
return default;
|
}
|
|
#endregion
|
|
#region 获取所有绑定
|
|
var allSignalIds = allMonitorList.SelectMany(x => x.SignalList.Select(t => t.ID)).ToList();
|
var allBindingList = new Service.HealthQuotaEvaluationModelBinding().GetValidBySignalIds(allSignalIds);
|
if (allBindingList == null || allBindingList.Count < 1)
|
{
|
return default;
|
}
|
|
#endregion
|
|
#region 获取所有绑定模型
|
|
var allModelIds = allBindingList.Select(x => x.ModelID).Distinct().ToList();
|
var allModelList = new Yw.Service.HealthQuotaEvaluationModel().GetByIds(allModelIds);
|
if (allModelList == null || allModelList.Count < 1)
|
{
|
return default;
|
}
|
|
#endregion
|
|
#region 遍历构造
|
|
var serviceMonitorRecord = new Lazy<Service.MonitorRecord>(() => new Service.MonitorRecord());
|
var serviceEvaluateRecord = new Lazy<Service.HealthQuotaEvaluationRecord>(() => new Service.HealthQuotaEvaluationRecord());
|
var vmList = new List<MonitorPointOnlineLogicDto>();
|
foreach (var group in allGroupList)
|
{
|
var monitorList = allMonitorList.Where(x => x.GroupID == group.ID).OrderBy(x => x.SortCode).ToList();
|
if (monitorList == null || monitorList.Count < 1)
|
continue;
|
foreach (var monitor in monitorList)
|
{
|
var vm = new MonitorPointOnlineLogicDto(monitor);
|
foreach (var signal in monitor.SignalList)
|
{
|
var binding = allBindingList.Find(x => x.SignalID == signal.ID);
|
if (binding != null)
|
{
|
var model = allModelList.Find(x => x.ID == binding.ModelID);
|
if (model != null)
|
{
|
if (model.Way == eEvaluateWay.Hand)
|
{
|
var lastRecord = serviceMonitorRecord.Value.GetLastRecord(signal.ID);
|
if (lastRecord != null)
|
{
|
var lastEvaluateRecord = serviceEvaluateRecord.Value.GetLastRecord(signal.ID);
|
var vmSignal = new SignalOnlineLogicDto(signal, lastRecord, model, lastEvaluateRecord);
|
vm.SignalList.Add(vmSignal);
|
}
|
}
|
}
|
}
|
}
|
if (vm.SignalList.Count > 0)
|
{
|
vmList.Add(vm);
|
}
|
}
|
}
|
|
return vmList;
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
}
|