diff --git a/src/YunDa.Application/YunDa.ISAS.Application/GeneralInformation/EquipmentInfo/EquipmentInfoExAppService.cs b/src/YunDa.Application/YunDa.ISAS.Application/GeneralInformation/EquipmentInfo/EquipmentInfoExAppService.cs index 425aada..9354e3e 100644 --- a/src/YunDa.Application/YunDa.ISAS.Application/GeneralInformation/EquipmentInfo/EquipmentInfoExAppService.cs +++ b/src/YunDa.Application/YunDa.ISAS.Application/GeneralInformation/EquipmentInfo/EquipmentInfoExAppService.cs @@ -610,84 +610,6 @@ namespace YunDa.ISAS.Application.GeneralInformation } } - /// - /// 获取遥信数据 - /// - /// 所亭名称 - /// - [HttpGet, AbpAllowAnonymous] - [ShowApi] - [DisableAuditing] - public async Task>> GetYXData(string stationName) - { - string rediskey = "telesignalisationModelList"; - - RequestResult> rst = new RequestResult>(); - try - { - var data = await _telesignalisationModelListRedis.HashSetGetAllAsync(rediskey); - if (data != null && data.Count > 0) - { - rst.ResultData = data.Select(t => new IEC104YXOutput - { - YXValue = t.ResultValue, - DateTime = t.ResultTime, - ISMSYXId = t.ismsbaseYXId, - Name = t.Name, - }).ToList(); - } - - rst.Flag = true; - } - catch (Exception ex) - { - Log4Helper.Error(this.GetType(), "", ex); - rst.Message = ex.Message; - } - return rst; - } - /// - /// 获取遥测数据 - /// - /// 所亭名称 - /// - [HttpGet, AbpAllowAnonymous] - [ShowApi] - [DisableAuditing] - public async Task>> GetYCData(string stationName) - { - string rediskey = "telemeteringModelList"; - - RequestResult> rst = new RequestResult>(); - try - { - var data = await _telemeteringModelListRedis.HashSetGetAllAsync(rediskey); - if (data != null && data.Count > 0) - { - rst.ResultData = data.Select(t => new IEC104YCOutput - { - YCValue = t.ResultValue, - DateTime = t.ResultTime, - ISMSYCId = t.ismsbaseYCId, - Name = t.Name, - }).ToList(); - } - //else - //{ - // InitYXList(); - //} - rst.Flag = true; - - } - catch (Exception ex) - { - Log4Helper.Error(this.GetType(), "", ex); - rst.Message = ex.Message; - } - - return rst; - } - } } diff --git a/src/YunDa.Application/YunDa.ISAS.Application/GeneralInformation/EquipmentInfo/SecondaryElectricalEquipmentInfoAppService.cs b/src/YunDa.Application/YunDa.ISAS.Application/GeneralInformation/EquipmentInfo/SecondaryElectricalEquipmentInfoAppService.cs index 53711ba..c6818ce 100644 --- a/src/YunDa.Application/YunDa.ISAS.Application/GeneralInformation/EquipmentInfo/SecondaryElectricalEquipmentInfoAppService.cs +++ b/src/YunDa.Application/YunDa.ISAS.Application/GeneralInformation/EquipmentInfo/SecondaryElectricalEquipmentInfoAppService.cs @@ -111,7 +111,6 @@ namespace YunDa.ISAS.Application.GeneralInformation deviceDatas = _imDeviceDatumRepository.GetAllIncluding(t => t.Device).ToList(); ImDeviceYcs = _imDeviceYcRepository.GetAll().ToList(); ImDeviceYxs = _imDeviceYxRepository.GetAll().ToList(); - unitOfWork.Complete(); } using (var unitOfWork = _unitOfWorkManager.Begin()) @@ -120,6 +119,7 @@ namespace YunDa.ISAS.Application.GeneralInformation dmalarmCategories = _dmalarmCategoryRepository.GetAll().ToList(); unitOfWork.Complete(); } + // 将设备数据和设备映射到字典中 var equipmentDict = equipments.ToDictionary(e => e.Name); var telemeteringConfigIds = new HashSet(_telemeteringConfigurationRepository.GetAll().Select(t => t.ismsbaseYCId)); @@ -135,95 +135,176 @@ namespace YunDa.ISAS.Application.GeneralInformation continue; // 未匹配到设备,跳过 } - if (deviceData.DataType == "YC" && !telemeteringConfigIds.Contains(deviceData.Id)) + if (deviceData.DataType == "YC") { var yc = ImDeviceYcs.FirstOrDefault(t => t.Id == deviceData.Id); - if (yc != null) + if (telemeteringConfigIds.Contains(deviceData.Id)) { - telemeteringConfigurations.Add(new TelemeteringConfiguration + // 更新已有的 Telemetering 配置 + var existingTelemeteringConfig = _telemeteringConfigurationRepository + .FirstOrDefault(t => t.ismsbaseYCId == deviceData.Id); + if (existingTelemeteringConfig != null) { - DataSourceCategory = DataSourceCategoryEnum.Zongzi, - Coefficient = (float)yc.Cof, - CPUSector = 0, - CreationTime = DateTime.Now, - CreatorUserId = default, - DeviceAddress = 1, - DecimalDigits = (int)yc.Precise, - DispatcherAddress = deviceData.InfoAddr, - InfoCPUSector = 0, - IsSelfCheckingValue = false, - EquipmentInfoId = equipment.Id, - EquipmentTypeId = equipment.EquipmentTypeId, - IsActive = true, - IsSave = true, - Name = deviceData.DataName, - IsVisible = true, - SeqNo = 0, - TransformerSubstationId = equipment.TransformerSubstationId, - Unit = yc.Unit, - IsVirtualDevice = false, - IsEnvironmentTemp = false, - ismsbaseYCId = deviceData.Id - }); - telemeteringConfigIds.Add(deviceData.Id); // 添加到已存在集合中 + existingTelemeteringConfig.Coefficient = (float)yc.Cof; + existingTelemeteringConfig.DecimalDigits = (int)yc.Precise; + existingTelemeteringConfig.Name = deviceData.DataName; + existingTelemeteringConfig.Unit = yc.Unit; + existingTelemeteringConfig.IsSelfCheckingValue = false; // 假设这是需要更新的字段 + existingTelemeteringConfig.EquipmentInfoId = equipment.Id; // 更新设备信息ID + existingTelemeteringConfig.EquipmentTypeId = equipment.EquipmentTypeId; // 更新设备类型ID + existingTelemeteringConfig.TransformerSubstationId = equipment.TransformerSubstationId; // 更新变电站ID + existingTelemeteringConfig.IsVirtualDevice = false; // 假设这是需要更新的字段 + existingTelemeteringConfig.IsEnvironmentTemp = false; // 假设这是需要更新的字段 + existingTelemeteringConfig.InfoAddress = deviceData.InfoAddr; // 更新信息地址 + existingTelemeteringConfig.DispatcherAddress = deviceData.InfoAddr; // 更新调度器地址 + existingTelemeteringConfig.IsActive = true; // 更新是否激活 + existingTelemeteringConfig.IsSave = true; // 更新是否保存 + existingTelemeteringConfig.IsVisible = true; // 更新是否可见 + existingTelemeteringConfig.SeqNo = 0; // 假设这是需要更新的字段 + existingTelemeteringConfig.CPUSector = 0; ; // 更新CPU扇区 + existingTelemeteringConfig.InfoCPUSector = deviceData.CpuIndex; ; // 更新信息CPU扇区 + existingTelemeteringConfig.CreatorUserId = default; // 更新创建用户ID(如果需要) + existingTelemeteringConfig.LastModificationTime = DateTime.Now; // 更新创建时间 + // 这里可以添加更多的更新字段 + // 保存到数据库 + _telemeteringConfigurationRepository.Update(existingTelemeteringConfig); + } + } + else + { + if (yc != null) + { + telemeteringConfigurations.Add(new TelemeteringConfiguration + { + DataSourceCategory = DataSourceCategoryEnum.Zongzi, + Coefficient = (float)yc.Cof, + CPUSector = 0, + CreationTime = DateTime.Now, + CreatorUserId = default, + DeviceAddress = 1, + DecimalDigits = (int)yc.Precise, + DispatcherAddress = deviceData.InfoAddr, + InfoAddress = deviceData.InfoAddr, + InfoCPUSector = 0, + IsSelfCheckingValue = false, + EquipmentInfoId = equipment.Id, + EquipmentTypeId = equipment.EquipmentTypeId, + IsActive = true, + IsSave = true, + Name = deviceData.DataName, + IsVisible = true, + SeqNo = 0, + TransformerSubstationId = equipment.TransformerSubstationId, + Unit = yc.Unit, + IsVirtualDevice = false, + IsEnvironmentTemp = false, + ismsbaseYCId = deviceData.Id + }); + telemeteringConfigIds.Add(deviceData.Id); // 添加到已存在集合中 + } } } - else if (deviceData.DataType == "YX" && !telesignalisationConfigIds.Contains(deviceData.Id)) + else if (deviceData.DataType == "YX") { var yx = ImDeviceYxs.FirstOrDefault(t => t.Id == deviceData.Id); - if (yx != null) + if (telesignalisationConfigIds.Contains(deviceData.Id)) { - string levelStr = Regex.Match(yx.AlertLevel, @"\d+")?.Value; - if (string.IsNullOrWhiteSpace(levelStr)) + // 更新已有的 Telesignalisation 配置 + var existingTelesignalisationConfig = _telesignalisationConfigurationRepository + .FirstOrDefault(t => t.ismsbaseYXId == deviceData.Id); + if (existingTelesignalisationConfig != null) { - levelStr = "4"; - } - var defaultDma = dmalarmCategories.FirstOrDefault(t => t.Level == int.Parse(levelStr)); + // 处理 AlertLevel 字段 + string levelStr = Regex.Match(yx.AlertLevel, @"\d+")?.Value; + if (string.IsNullOrWhiteSpace(levelStr)) + { + levelStr = "4"; // 默认值 + } + var defaultDma = dmalarmCategories.FirstOrDefault(t => t.Level == int.Parse(levelStr)); - telesignalisationConfigurations.Add(new TelesignalisationConfiguration + // 更新 Telesignalisation 配置的各个字段 + existingTelesignalisationConfig.YesContent = yx.SwOnStr ?? ""; // 如果为空,设置为默认值 + existingTelesignalisationConfig.NoContent = yx.SwOffStr ?? ""; // 如果为空,设置为默认值 + existingTelesignalisationConfig.UnsurenessContent = yx.SwUncertStr ?? "不定"; // 如果为空,设置为默认值 + existingTelesignalisationConfig.DMAlarmCategoryId = defaultDma?.Id; // 更新报警分类ID + existingTelesignalisationConfig.Name = deviceData.DataName; // 更新名称 + existingTelesignalisationConfig.InfoAddress = deviceData.InfoAddr; // 更新信息地址 + existingTelesignalisationConfig.DispatcherAddress = deviceData.InfoAddr; // 更新调度器地址 + existingTelesignalisationConfig.EquipmentInfoId = equipment.Id; // 更新设备信息ID + existingTelesignalisationConfig.EquipmentTypeId = equipment.EquipmentTypeId; // 更新设备类型ID + existingTelesignalisationConfig.TransformerSubstationId = equipment.TransformerSubstationId; // 更新变电站ID + existingTelesignalisationConfig.IsActive = true; // 更新是否激活 + existingTelesignalisationConfig.IsSave = true; // 更新是否保存 + existingTelesignalisationConfig.IsVisible = true; // 更新是否可见 + existingTelesignalisationConfig.SeqNo = 0; // 假设需要设置序号 + existingTelesignalisationConfig.CPUSector = 0; // 更新CPU扇区 + existingTelesignalisationConfig.InfoCPUSector = deviceData.CpuIndex; // 更新信息CPU扇区 + existingTelesignalisationConfig.IsVirtualDevice = false; // 更新虚拟设备标志 + existingTelesignalisationConfig.CreatorUserId = default; // 更新创建用户ID + existingTelesignalisationConfig.LastModificationTime = DateTime.Now; // 更新创建时间 + + // 这里可以继续添加其他字段更新的代码 + + // 保存到数据库 + _telesignalisationConfigurationRepository.Update(existingTelesignalisationConfig); + } + } + else + { + if (yx != null) { - DataSourceCategory = DataSourceCategoryEnum.Zongzi, - CPUSector = 0, - CreationTime = DateTime.Now, - CreatorUserId = default, - DispatcherAddress = deviceData.InfoAddr, - DeviceAddress = 1, - InfoCPUSector = 0, - IsSelfCheckingValue = false, - EquipmentInfoId = equipment.Id, - EquipmentTypeId = equipment.EquipmentTypeId, - YesContent = yx.SwOnStr ?? "", - NoContent = yx.SwOffStr ?? "", - UnsurenessContent = yx.SwUncertStr ?? "", - DMAlarmCategoryId = defaultDma?.Id, - IsActive = true, - IsSave = true, - Name = deviceData.DataName, - IsVisible = true, - SeqNo = 0, - TransformerSubstationId = equipment.TransformerSubstationId, - IsVirtualDevice = false, - ismsbaseYXId = deviceData.Id - }); - telesignalisationConfigIds.Add(deviceData.Id); // 添加到已存在集合中 + string levelStr = Regex.Match(yx.AlertLevel, @"\d+")?.Value; + if (string.IsNullOrWhiteSpace(levelStr)) + { + levelStr = "4"; + } + var defaultDma = dmalarmCategories.FirstOrDefault(t => t.Level == int.Parse(levelStr)); + + telesignalisationConfigurations.Add(new TelesignalisationConfiguration + { + DataSourceCategory = DataSourceCategoryEnum.Zongzi, + CPUSector = 0, + CreationTime = DateTime.Now, + CreatorUserId = default, + DispatcherAddress = deviceData.InfoAddr, + InfoAddress = deviceData.InfoAddr, + DeviceAddress = 1, + InfoCPUSector = 0, + IsSelfCheckingValue = false, + EquipmentInfoId = equipment.Id, + EquipmentTypeId = equipment.EquipmentTypeId, + YesContent = yx.SwOnStr ?? "", + NoContent = yx.SwOffStr ?? "", + UnsurenessContent = yx.SwUncertStr ?? "", + DMAlarmCategoryId = defaultDma?.Id, + IsActive = true, + IsSave = true, + Name = deviceData.DataName, + IsVisible = true, + SeqNo = 0, + TransformerSubstationId = equipment.TransformerSubstationId, + IsVirtualDevice = false, + ismsbaseYXId = deviceData.Id + }); + telesignalisationConfigIds.Add(deviceData.Id); // 添加到已存在集合中 + } } } } - // 批量插入 + // 批量插入或更新数据库 using (var unitOfWork = _unitOfWorkManager.Begin()) { if (telemeteringConfigurations.Any()) - await _telemeteringConfigurationRepository.InsertRangeAsync(telemeteringConfigurations); - + await _telemeteringConfigurationRepository.InsertRangeAsync(telemeteringConfigurations); if (telesignalisationConfigurations.Any()) await _telesignalisationConfigurationRepository.InsertRangeAsync(telesignalisationConfigurations); - unitOfWork.Complete(); + // 完成数据库操作 + await unitOfWork.CompleteAsync(); } rst.Flag = true; - rst.Message = "批量插入成功!"; } catch (Exception ex) { @@ -235,6 +316,7 @@ namespace YunDa.ISAS.Application.GeneralInformation } + //[HttpGet] //[AbpAllowAnonymous] //[ShowApi] diff --git a/src/YunDa.Application/YunDa.ISAS.Application/GeneralInformation/ProtectionDevice/ProtectionDeviceAppService.cs b/src/YunDa.Application/YunDa.ISAS.Application/GeneralInformation/ProtectionDevice/ProtectionDeviceAppService.cs index 692405b..fc92334 100644 --- a/src/YunDa.Application/YunDa.ISAS.Application/GeneralInformation/ProtectionDevice/ProtectionDeviceAppService.cs +++ b/src/YunDa.Application/YunDa.ISAS.Application/GeneralInformation/ProtectionDevice/ProtectionDeviceAppService.cs @@ -872,6 +872,7 @@ namespace YunDa.ISAS.Application.GeneralInformation } else { + porotectionDeviceInfos[item].ISMS_DeviceId = imProtectDevice.Id; porotectionDeviceInfos[item].DeviceAddress = imProtectDevice.DeviceAddr; } } diff --git a/src/YunDa.Application/YunDa.ISAS.Application/YunDa.ISAS.Application.xml b/src/YunDa.Application/YunDa.ISAS.Application/YunDa.ISAS.Application.xml index c4122b0..792428f 100644 --- a/src/YunDa.Application/YunDa.ISAS.Application/YunDa.ISAS.Application.xml +++ b/src/YunDa.Application/YunDa.ISAS.Application/YunDa.ISAS.Application.xml @@ -3601,7 +3601,7 @@ - 从综自后台数据库迁移数据到运维数据库中(保护装置数据) + 从综自后台数据库迁移数据到运维数据库中(保护装置网关数据) @@ -3681,6 +3681,13 @@ + + + 查询保护装置在线情况 + + + + 查询定值信息