namespace IStation.Application { /// /// DmaAnaly /// [Route("SZJT/Dma/Analy/Logic")] [ApiDescriptionSettings("SZJT", Name = "Dma分析(Logic)", Order = 5000)] public class DmaAnaly_LogicController : IDynamicApiController { #region 地图 /// /// 获取分区地图列表 /// [Route("GetAreaMapList@V1.0")] [HttpGet] public List GetAreaMapList([FromQuery][Required] BelongOfKindInput input) { var allAreaList = new Yw.Service.DmaArea().GetByBelongTypeAndBelongID(input.BelongType, input.BelongID); if (allAreaList == null || allAreaList.Count < 1) { return default; } var allAreaIds = allAreaList.Select(x => x.ID).Distinct().ToList(); var allSiteList = new Yw.Service.DmaSite().GetByBelongTypeAndBelongID(input.BelongType, input.BelongID); if (allSiteList == null) { allSiteList = new List(); } var allSiteIds = allSiteList.Select(x => x.ID).Distinct().ToList(); var allMappingList = new Yw.Service.DmaSiteMapping().GetBySiteIds(allSiteIds); if (allMappingList == null) { allMappingList = new List(); } var serviceMapInfo = new Yw.Service.MapInfo(); var vm_list = new List(); foreach (var area in allAreaList) { var vm = new DmaAnalyAreaMapDto(area); vm_list.Add(vm); var area_map_info = serviceMapInfo.Get(Yw.DMA.DataType.DmaArea, area.ID, input.Kind, Yw.Map.Purpose.Location); if (area_map_info != null) { vm.Position = Yw.Model.Map.Polygon.ToModel(area_map_info.Position); } var mappingList = allMappingList.Where(x => x.AreaID == area.ID).ToList(); if (mappingList != null && mappingList.Count > 0) { vm.SiteList = new List(); foreach (var mapping in mappingList) { var site = allSiteList.Find(x => x.ID == mapping.SiteID); if (site == null) { continue; } var vm_site = new DmaAnalySiteMapDto(site, mapping); var site_map_info = serviceMapInfo.Get(Yw.DMA.DataType.DmaSite, site.ID, input.Kind, Yw.Map.Purpose.Location); if (site_map_info != null) { vm_site.Position = Yw.Model.Map.Marker.ToModel(site_map_info.Position); } vm.SiteList.Add(vm_site); } } } return vm_list; } #endregion #region 分区 /// /// 通过 ID 获取分区详细 /// [Route("GetAreaDetailByID@V1.0")] [HttpGet] public DmaAnalyAreaDetailDto GetAreaDetailByID([FromQuery][Required] IDInput input) { var model = new Yw.Service.DmaArea().GetByID(input.ID); if (model == null) { throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"ID:{input.ID} 数据不存在"); } var vm = new DmaAnalyAreaDetailDto(model); var allMappingList = new Yw.Service.DmaSiteMapping().GetByAreaID(input.ID); if (allMappingList != null && allMappingList.Count > 0) { var service_site_binding = new Yw.Service.DmaSiteBinding(); var service_equipment = new Lazy(() => new Yw.Service.Equipment()); var service_supplier = new Lazy(() => new Yw.Service.Supplier()); var allInMappingList = allMappingList.Where(x => x.Direction == Yw.DMA.eDirection.IN).ToList(); if (allInMappingList.Count > 0) { vm.InFlowMeterList = new List(); foreach (var mapping in allInMappingList) { var binding = service_site_binding.GetValidBySiteID(mapping.SiteID); if (binding != null) { var flowMeter = service_equipment.Value.GetByID(binding.MeterID); if (flowMeter != null) { var supplier = service_supplier.Value.GetByID(flowMeter.SupplierID); var vm_flow_meter = new DmaAnalyAreaDetailFlowMeterDto(flowMeter, supplier?.Name); vm.InFlowMeterList.Add(vm_flow_meter); } } } } var allOutMappingList = allMappingList.Where(x => x.Direction == Yw.DMA.eDirection.OUT).ToList(); if (allOutMappingList.Count > 0) { vm.OutFlowMeterList = new List(); foreach (var mapping in allOutMappingList) { var binding = service_site_binding.GetValidBySiteID(mapping.SiteID); if (binding != null) { var flowMeter = service_equipment.Value.GetByID(binding.MeterID); if (flowMeter != null) { var supplier = service_supplier.Value.GetByID(flowMeter.SupplierID); var vm_flow_meter = new DmaAnalyAreaDetailFlowMeterDto(flowMeter, supplier?.Name); vm.OutFlowMeterList.Add(vm_flow_meter); } } } } } return vm; } /// /// 获取分区日状态列表 /// [Route("GetAreaDayStatusList@V1.0")] [HttpGet] public List GetAreaDayStatusList([FromQuery][Required] QueryDmaAreaDayStatusListInput input) { var vmList = new List(); for (DateTime i = input.StartDay.Date; i <= input.EndDay.Date; i = i.AddDays(1)) { var vm = new DmaAnalyAreaDayStatusDto(); vm.Day = i; vm.InVol = RandomHelper.Random(4000, 5000); vm.OutVol = RandomHelper.Random(1000, 2000); vm.ReadVol = RandomHelper.Random(2000, 3000); vm.UseVol = vm.InVol - vm.OutVol; vm.LeakRate = null; vmList.Add(vm); } return vmList; } /// /// 获取分区月状态列表 /// [Route("GetAreaMonthStatusList@V1.0")] [HttpGet] public List GetAreaMonthStatusList([FromQuery][Required] QueryDmaAreaMonthStatusListInput input) { var vmList = new List(); for (int i = input.StartYear; i <= input.EndYear; i++) { var min = 1; if (i == input.StartYear) { min = input.StartMonth; } var max = 12; if (i == input.EndYear) { max = input.EndMonth; } for (int j = min; j <= max; j++) { var vm = new DmaAnalyAreaMonthStatusDto(); vm.Year = i; vm.Month = j; vm.InVol = RandomHelper.Random(4000, 5000); vm.OutVol = RandomHelper.Random(1000, 2000); vm.ReadVol = RandomHelper.Random(2000, 3000); vm.UseVol = vm.InVol - vm.OutVol; vm.LeakRate = null; vmList.Add(vm); } } return vmList; } #endregion #region 点位 /// /// 通过 ID 获取点位详细 /// [Route("GetSiteDetailByID@V1.0")] [HttpGet] public DmaAnalySiteDetailDto GetSiteDetailByID([FromQuery][Required] IDInput input) { var site = new Yw.Service.DmaSite().GetByID(input.ID); if (site == null) { throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"ID:{input.ID} 数据不存在"); } var vm = new DmaAnalySiteDetailDto(site); var binding = new Yw.Service.DmaSiteBinding().GetValidBySiteID(site.ID); if (binding != null) { var flowMeter = new Yw.Service.Equipment().GetByID(binding.MeterID); if (flowMeter != null) { var supplier = new Yw.Service.Supplier().GetByID(flowMeter.SupplierID); vm.FlowMeter = new DmaAnalySiteDetailFlowMeterDto(flowMeter, supplier?.Name); } } return vm; } /// /// 查询点位实时状态列表 /// [Route("GetSiteRealStatusList@V1.0")] [HttpGet] public List GetSiteRealStatusList([FromQuery][Required] QueryDmaSiteRealStatusListInput input) { var site = new Yw.Service.DmaSite().GetByID(input.ID); if (site == null) { throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"ID:{input.ID} 数据不存在"); } var binding = new Yw.Service.DmaSiteBinding().GetValidBySiteID(site.ID); if (binding == null) { return default; } var monitorMappingList = new Yw.Service.EquipmentMonitorMapping().GetByEquipmentID(binding.MeterID); if (monitorMappingList == null || monitorMappingList.Count < 1) { return default; } var monitorIds = monitorMappingList.Select(x => x.MonitorPointID).Distinct().ToList(); var monitorList = new Yw.Service.MonitorPoint().GetExSignalWithSignalTypeByIds(monitorIds); monitorList = monitorList?.Where(x => x.UseStatus == Yw.Model.eUseStatus.Enable).ToList(); monitorList = monitorList?.Where(x => x.CronType == Yw.Monitor.eCronType.Real).ToList(); if (monitorList == null || monitorList.Count < 1) { return default; } var service_monitor_record = new Lazy(() => new Yw.Service.MonitorRealRecord()); var vmList = new List(); var monitorQ = monitorList.Find(x => x.Flags.Contains(IStation.Flags.默认) && x.SignalList.Exists(t => t.SignalType.Code == Yw.Monitor.SignalType.瞬时流量)); if (monitorQ == null) { monitorQ = monitorList.Find(x => x.SignalList.Exists(t => t.SignalType.Code == Yw.Monitor.SignalType.瞬时流量)); } if (monitorQ != null) { var signalQ = monitorQ.SignalList.First(); var recordList = service_monitor_record.Value.GetLimitBySignalIDOfDayRange(signalQ.ID, input.StartDay, input.EndDay, 10000); vmList.Add(new DmaAnalySiteRealStatusDto(monitorQ, signalQ, recordList)); } var monitorQl = monitorList.Find(x => x.Flags.Contains(IStation.Flags.默认) && x.SignalList.Exists(t => t.SignalType.Code == Yw.Monitor.SignalType.累积流量)); if (monitorQl == null) { monitorQl = monitorList.Find(x => x.SignalList.Exists(t => t.SignalType.Code == Yw.Monitor.SignalType.累积流量)); } if (monitorQl != null) { var signalQl = monitorQl.SignalList.First(); var recordList = service_monitor_record.Value.GetLimitBySignalIDOfDayRange(signalQl.ID, input.StartDay, input.EndDay, 10000); vmList.Add(new DmaAnalySiteRealStatusDto(monitorQl, signalQl, recordList)); } return vmList; } /// /// 查询点位日状态列表 /// [Route("GetSiteDayStatusList@V1.0")] [HttpGet] public List GetSiteDayStatusList([FromQuery][Required] QueryDmaSiteDayStatusListInput input) { var vmList = new List(); for (DateTime i = input.StartDay.Date; i <= input.EndDay.Date; i = i.AddDays(1)) { var vm = new DmaAnalySiteDayStatusDto(); vm.Day = i; vm.Value = RandomHelper.Random(1000, 5000); if (vm.Value > 4000) { vm.Value = null; } vmList.Add(vm); } return vmList; } /// /// 查询点位月状态列表 /// [Route("GetSiteMonthStatusList@V1.0")] [HttpGet] public List GetSiteMonthStatusList([FromQuery][Required] QueryDmaSiteMonthStatusListInput input) { var vmList = new List(); for (int i = input.StartYear; i <= input.EndYear; i++) { var min = 1; if (i == input.StartYear) { min = input.StartMonth; } var max = 12; if (i == input.EndYear) { max = input.EndMonth; } for (int j = min; j <= max; j++) { var vm = new DmaAnalySiteMonthStatusDto(); vm.Year = i; vm.Month = j; vm.Value = RandomHelper.Random(1000, 5000); if (vm.Value > 4000) { vm.Value = null; } vmList.Add(vm); } } return vmList; } #endregion #region 流量计 /// /// 获取流量计列表 /// [Route("GetFlowMeterList@V1.0")] [HttpGet] public List GetFlowMeterList([FromQuery][Required] BelongInput input) { var catalogList = new Yw.Service.SysCatalog().GetChildAndSelfByCode(IStation.Catalog.FlowMeter); if (catalogList == null || catalogList.Count < 1) { throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, "流量计分类编码验证失败"); } var catalogIds = catalogList.Select(x => x.ID).Distinct().ToList(); var allMeterList = new Yw.Service.Equipment().GetByBelongTypeAndBelongID(input.BelongType, input.BelongID); allMeterList = allMeterList?.Where(x => catalogIds.Contains(x.CatalogID)).ToList(); if (allMeterList == null || allMeterList.Count < 1) { return default; } var service_supplier = new Yw.Service.Supplier(); var service_binding = new Yw.Service.DmaSiteBinding(); var service_mapping = new Lazy(() => new Yw.Service.DmaSiteMapping()); var service_area = new Lazy(() => new Yw.Service.DmaArea()); var service_monitor_mapping = new Yw.Service.EquipmentMonitorMapping(); var service_monitor = new Lazy(() => new Yw.Service.MonitorPoint()); var service_monitor_record = new Lazy(() => new Yw.Service.MonitorRealRecord()); var vmList = new List(); foreach (var meter in allMeterList) { var supplier = service_supplier.GetByID(meter.SupplierID); var vm = new DmaAnalyFlowMeterDto(meter, supplier?.Name); vmList.Add(vm); var binding = service_binding.GetValidByMeterID(meter.ID); if (binding != null) { var mapping_list = service_mapping.Value.GetBySiteID(binding.SiteID); if (mapping_list != null && mapping_list.Count > 0) { var mappingIn = mapping_list.Find(x => x.Direction == Yw.DMA.eDirection.IN); if (mappingIn != null) { vm.FlowIn = service_area.Value.GetByID(mappingIn.AreaID)?.Name; } var mappingOut = mapping_list.Find(x => x.Direction == Yw.DMA.eDirection.OUT); if (mappingOut != null) { vm.FlowOut = service_area.Value.GetByID(mappingOut.AreaID)?.Name; } } } var monitor_mapping_list = service_monitor_mapping.GetByEquipmentID(meter.ID); if (monitor_mapping_list != null && monitor_mapping_list.Count > 0) { var monitorIds = monitor_mapping_list.Select(x => x.MonitorPointID).Distinct().ToList(); var monitor_list = service_monitor.Value.GetExSignalWithSignalTypeByIds(monitorIds); monitor_list = monitor_list?.Where(x => x.UseStatus == Yw.Model.eUseStatus.Enable).ToList(); monitor_list = monitor_list?.Where(x => x.CronType == Yw.Monitor.eCronType.Real).ToList(); if (monitor_list != null && monitor_list.Count > 0) { vm.LastRecordList = new List(); var monitorQ = monitor_list.Find(x => x.Flags.Contains(IStation.Flags.默认) && x.SignalList.Exists(t => t.SignalType.Code == Yw.Monitor.SignalType.瞬时流量)); if (monitorQ == null) { monitorQ = monitor_list.Find(x => x.SignalList.Exists(t => t.SignalType.Code == Yw.Monitor.SignalType.瞬时流量)); } if (monitorQ != null) { var signalQ = monitorQ.SignalList.First(); var last_record = service_monitor_record.Value.GetLastRecord(signalQ.ID); if (last_record != null) { vm.LastRecordList.Add(new DmaAnalyFlowMeterLastRecordDto(monitorQ, signalQ, last_record)); } } var monitorQl = monitor_list.Find(x => x.Flags.Contains(IStation.Flags.默认) && x.SignalList.Exists(t => t.SignalType.Code == Yw.Monitor.SignalType.累积流量)); if (monitorQl == null) { monitorQl = monitor_list.Find(x => x.SignalList.Exists(t => t.SignalType.Code == Yw.Monitor.SignalType.累积流量)); } if (monitorQl != null) { var signalQl = monitorQl.SignalList.First(); var last_record = service_monitor_record.Value.GetLastRecord(signalQl.ID); if (last_record != null) { vm.LastRecordList.Add(new DmaAnalyFlowMeterLastRecordDto(monitorQl, signalQl, last_record)); } } } } } return vmList; } #endregion #region 压力计 /// /// 获取压力计列表 /// [Route("GetPressMeterList@V1.0")] [HttpGet] public List GetPressMeterList([FromQuery][Required] BelongInput input) { var catalogList = new Yw.Service.SysCatalog().GetChildAndSelfByCode(IStation.Catalog.PressMeter); if (catalogList == null || catalogList.Count < 1) { throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, "压力计分类编码验证失败"); } var catalogIds = catalogList.Select(x => x.ID).Distinct().ToList(); var allMeterList = new Yw.Service.Equipment().GetByBelongTypeAndBelongID(input.BelongType, input.BelongID); allMeterList = allMeterList?.Where(x => catalogIds.Contains(x.CatalogID)).ToList(); if (allMeterList == null || allMeterList.Count < 1) { return default; } var service_supplier = new Yw.Service.Supplier(); var service_monitor_mapping = new Yw.Service.EquipmentMonitorMapping(); var service_monitor = new Lazy(() => new Yw.Service.MonitorPoint()); var service_monitor_record = new Lazy(() => new Yw.Service.MonitorRealRecord()); var vmList = new List(); foreach (var meter in allMeterList) { var supplier = service_supplier.GetByID(meter.SupplierID); var vm = new DmaAnalyPressMeterDto(meter, supplier?.Name); vmList.Add(vm); var monitor_mapping_list = service_monitor_mapping.GetByEquipmentID(meter.ID); if (monitor_mapping_list != null && monitor_mapping_list.Count > 0) { var monitorIds = monitor_mapping_list.Select(x => x.MonitorPointID).Distinct().ToList(); var monitor_list = service_monitor.Value.GetExSignalWithSignalTypeByIds(monitorIds); monitor_list = monitor_list?.Where(x => x.UseStatus == Yw.Model.eUseStatus.Enable).ToList(); monitor_list = monitor_list?.Where(x => x.CronType == Yw.Monitor.eCronType.Real).ToList(); if (monitor_list != null && monitor_list.Count > 0) { vm.LastRecordList = new List(); var monitorPr = monitor_list.Find(x => x.Flags.Contains(IStation.Flags.默认) && x.SignalList.Exists(t => t.SignalType.Code == Yw.Monitor.SignalType.压力)); if (monitorPr == null) { monitorPr = monitor_list.Find(x => x.SignalList.Exists(t => t.SignalType.Code == Yw.Monitor.SignalType.压力)); } if (monitorPr != null) { var signalPr = monitorPr.SignalList.First(); var last_record = service_monitor_record.Value.GetLastRecord(signalPr.ID); if (last_record != null) { vm.LastRecordList.Add(new DmaAnalyPressMeterLastRecordDto(monitorPr, signalPr, last_record)); } } } } } return vmList; } #endregion } }