2024-08-21 16:50:14 +08:00
|
|
|
|
using Abp.Application.Services;
|
|
|
|
|
using Abp.Authorization;
|
|
|
|
|
using Abp.Domain.Repositories;
|
|
|
|
|
using Abp.Domain.Uow;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using YunDa.ISAS.Application.Core.SwaggerHelper;
|
|
|
|
|
using YunDa.ISAS.DataTransferObject;
|
|
|
|
|
using YunDa.ISAS.DataTransferObject.SecondaryElectricalEquipmentInfoDto.ProtectDeviceDto;
|
|
|
|
|
using YunDa.ISAS.Entities.DataMonitoring;
|
|
|
|
|
using YunDa.ISAS.Entities.GeneralInformation;
|
|
|
|
|
using YunDa.ISAS.Entities.MySQL.DataMonitoring;
|
|
|
|
|
using YunDa.ISMS.BASE.Entities.Models;
|
|
|
|
|
|
|
|
|
|
namespace YunDa.ISAS.Application.GeneralInformation
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 二次设备信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Description("二次设备信息")]
|
|
|
|
|
public class SecondaryElectricalEquipmentInfoAppService : ApplicationService
|
|
|
|
|
{
|
|
|
|
|
private readonly IRepository<ImDeviceDatum, string> _imDeviceDatumRepository;
|
|
|
|
|
private readonly IRepository<ImProtectDevice, string> _imProtectDeviceRepository;
|
|
|
|
|
private readonly IRepository<ImDeviceYc, string> _imDeviceYcRepository;
|
|
|
|
|
private readonly IRepository<ImDeviceYx, string> _imDeviceYxRepository;
|
|
|
|
|
|
|
|
|
|
private readonly IRepository<DMAlarmCategory, Guid> _dmalarmCategoryRepository;
|
|
|
|
|
|
|
|
|
|
private readonly IRepository<EquipmentInfo, Guid> _equipmentInfoRepository;
|
|
|
|
|
private readonly IRepository<TelemeteringConfiguration, Guid> _telemeteringConfigurationRepository;
|
|
|
|
|
private readonly IRepository<TelesignalisationConfiguration, Guid> _telesignalisationConfigurationRepository;
|
|
|
|
|
private readonly IUnitOfWorkManager _unitOfWorkManager;
|
|
|
|
|
|
|
|
|
|
public SecondaryElectricalEquipmentInfoAppService(
|
|
|
|
|
IRepository<ImDeviceDatum, string> imDeviceDatumRepository,
|
|
|
|
|
IRepository<ImProtectDevice, string> imProtectDeviceRepository,
|
|
|
|
|
IRepository<EquipmentInfo, Guid> equipmentInfoRepository,
|
|
|
|
|
IRepository<TelemeteringConfiguration, Guid> telemeteringConfigurationRepository,
|
|
|
|
|
IRepository<TelesignalisationConfiguration, Guid> telesignalisationConfigurationRepository,
|
|
|
|
|
IRepository<DMAlarmCategory, Guid> dmalarmCategoryRepository,
|
|
|
|
|
IRepository<ImDeviceYc, string> imDeviceYcRepository,
|
|
|
|
|
IRepository<ImDeviceYx, string> imDeviceYxRepository,
|
|
|
|
|
IUnitOfWorkManager unitOfWorkManager
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
_imDeviceDatumRepository = imDeviceDatumRepository;
|
|
|
|
|
_imProtectDeviceRepository = imProtectDeviceRepository;
|
|
|
|
|
_equipmentInfoRepository = equipmentInfoRepository;
|
|
|
|
|
_telemeteringConfigurationRepository = telemeteringConfigurationRepository;
|
|
|
|
|
_telesignalisationConfigurationRepository = telesignalisationConfigurationRepository;
|
|
|
|
|
_unitOfWorkManager = unitOfWorkManager;
|
|
|
|
|
_imDeviceYcRepository = imDeviceYcRepository;
|
|
|
|
|
_imDeviceYxRepository = imDeviceYxRepository;
|
|
|
|
|
_dmalarmCategoryRepository = dmalarmCategoryRepository;
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[AbpAllowAnonymous]
|
|
|
|
|
[ShowApi]
|
|
|
|
|
public RequestEasyResult Test()
|
|
|
|
|
{
|
|
|
|
|
RequestEasyResult rst = new RequestEasyResult();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var repo = _imProtectDeviceRepository.GetAllIncluding(t=>t.StatCodeNavigation);
|
|
|
|
|
foreach (var item in repo)
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine(item.DeviceName+" " + item.Id);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
rst.Flag = true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
rst.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return rst;
|
|
|
|
|
}
|
2024-09-20 09:59:25 +08:00
|
|
|
|
|
|
|
|
|
static int index = 0;
|
2024-08-21 16:50:14 +08:00
|
|
|
|
[HttpGet]
|
|
|
|
|
[AbpAllowAnonymous]
|
|
|
|
|
[ShowApi]
|
|
|
|
|
[UnitOfWork(isTransactional: false)]
|
|
|
|
|
public RequestEasyResult MergerDeviceData()
|
|
|
|
|
{
|
|
|
|
|
RequestEasyResult rst = new RequestEasyResult();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
List<ImDeviceDatum> deviceDatas = new List<ImDeviceDatum>();
|
|
|
|
|
List<ImDeviceYc> ImDeviceYcs = new List<ImDeviceYc>();
|
|
|
|
|
List<ImDeviceYx> ImDeviceYxs = new List<ImDeviceYx>();
|
|
|
|
|
using (var unitOfWork = _unitOfWorkManager.Begin())
|
|
|
|
|
{
|
|
|
|
|
deviceDatas = _imDeviceDatumRepository.GetAllIncluding(t => t.Device).ToList();
|
|
|
|
|
ImDeviceYcs = _imDeviceYcRepository.GetAll().ToList();
|
|
|
|
|
ImDeviceYxs = _imDeviceYxRepository.GetAll().ToList();
|
|
|
|
|
unitOfWork.Complete();
|
|
|
|
|
}
|
|
|
|
|
List<DMAlarmCategory> dmalarmCategories = new List<DMAlarmCategory>();
|
|
|
|
|
List<EquipmentInfo> equipments = new List<EquipmentInfo>();
|
|
|
|
|
|
|
|
|
|
using (var unitOfWork = _unitOfWorkManager.Begin())
|
|
|
|
|
{
|
|
|
|
|
equipments = _equipmentInfoRepository.GetAll().ToList();
|
|
|
|
|
dmalarmCategories = _dmalarmCategoryRepository.GetAll().ToList();
|
|
|
|
|
unitOfWork.Complete();
|
|
|
|
|
}
|
|
|
|
|
using (var unitOfWork = _unitOfWorkManager.Begin())
|
|
|
|
|
{
|
|
|
|
|
foreach (var equipment in equipments)
|
|
|
|
|
{
|
2024-09-20 09:59:25 +08:00
|
|
|
|
foreach (var deviceData in deviceDatas.Skip(index*10000).Take(10000))
|
2024-08-21 16:50:14 +08:00
|
|
|
|
{
|
|
|
|
|
if (equipment.Name == deviceData.Device.DeviceName)
|
|
|
|
|
{
|
2024-09-20 09:59:25 +08:00
|
|
|
|
if (deviceData.DataType == "YC")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var isExist = _telemeteringConfigurationRepository.GetAllIncluding().FirstOrDefault(t => t.EquipmentInfoId == equipment.Id && t.Name == deviceData.DataName);
|
|
|
|
|
if (isExist == null)
|
|
|
|
|
{
|
|
|
|
|
var yc = ImDeviceYcs.FirstOrDefault(t => t.Id == deviceData.Id);
|
|
|
|
|
TelemeteringConfiguration entity = new TelemeteringConfiguration()
|
|
|
|
|
{
|
|
|
|
|
DataSourceCategory = DataSourceCategoryEnum.Zongzi,
|
|
|
|
|
Coefficient = (float)yc?.Cof,
|
|
|
|
|
CPUSector = 0,
|
|
|
|
|
CreationTime = DateTime.Now,
|
|
|
|
|
CreatorUserId = Guid.Parse("08d89123-c503-4fbc-835b-c6b0c8a53096"),
|
|
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
_telemeteringConfigurationRepository.Insert(entity);
|
2024-08-21 16:50:14 +08:00
|
|
|
|
|
2024-09-20 09:59:25 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2024-08-21 16:50:14 +08:00
|
|
|
|
if (deviceData.DataType == "YX")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var isExist = _telesignalisationConfigurationRepository.GetAllIncluding().FirstOrDefault(t => t.EquipmentInfoId == equipment.Id && t.Name == deviceData.DataName);
|
|
|
|
|
if (isExist == null)
|
|
|
|
|
{
|
|
|
|
|
var yx = ImDeviceYxs.FirstOrDefault(t => t.Id == deviceData.Id);
|
|
|
|
|
string pattern = @"\d+";
|
|
|
|
|
|
|
|
|
|
Regex regex = new Regex(pattern);
|
|
|
|
|
MatchCollection matches = regex.Matches(yx.AlertLevel);
|
|
|
|
|
var firstmatch = matches.FirstOrDefault();
|
|
|
|
|
var defaultdma = dmalarmCategories.FirstOrDefault();
|
|
|
|
|
if (firstmatch != null)
|
|
|
|
|
{
|
|
|
|
|
defaultdma = dmalarmCategories.FirstOrDefault(t => t.Level == int.Parse(firstmatch.Value));
|
|
|
|
|
}
|
|
|
|
|
TelesignalisationConfiguration entity = new TelesignalisationConfiguration()
|
|
|
|
|
{
|
|
|
|
|
DataSourceCategory = DataSourceCategoryEnum.Zongzi,
|
|
|
|
|
CPUSector = 0,
|
|
|
|
|
CreationTime = DateTime.Now,
|
|
|
|
|
CreatorUserId = Guid.Parse("08d89123-c503-4fbc-835b-c6b0c8a53096"),
|
|
|
|
|
DispatcherAddress = deviceData.InfoAddr,
|
|
|
|
|
DeviceAddress = 1,
|
|
|
|
|
InfoCPUSector = 0,
|
|
|
|
|
IsSelfCheckingValue = false,
|
|
|
|
|
EquipmentInfoId = equipment.Id,
|
|
|
|
|
EquipmentTypeId = equipment.EquipmentTypeId,
|
|
|
|
|
YesContent = yx?.SwOnStr == null ? "" : yx.SwOnStr,
|
|
|
|
|
NoContent = yx?.SwOffStr==null?"": yx.SwOffStr,
|
|
|
|
|
UnsurenessContent = yx?.SwUncertStr == null ? "" : yx.SwUncertStr,
|
|
|
|
|
DMAlarmCategoryId = defaultdma?.Id,
|
|
|
|
|
IsActive = true,
|
|
|
|
|
IsSave = true,
|
|
|
|
|
Name = deviceData.DataName,
|
|
|
|
|
IsVisible = true,
|
|
|
|
|
SeqNo = 0,
|
|
|
|
|
TransformerSubstationId = equipment.TransformerSubstationId,
|
|
|
|
|
IsVirtualDevice = false,
|
2024-09-20 09:59:25 +08:00
|
|
|
|
ismsbaseYXId = deviceData.Id
|
2024-08-21 16:50:14 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_telesignalisationConfigurationRepository.Insert(entity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unitOfWork.Complete();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
rst.Flag = true;
|
2024-09-20 09:59:25 +08:00
|
|
|
|
rst.Message = $"成功插入{index * 10000}到{(index+1) * 10000}";
|
|
|
|
|
index++;
|
2024-08-21 16:50:14 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw ex;
|
|
|
|
|
}
|
|
|
|
|
return rst;
|
|
|
|
|
}
|
2024-09-20 09:59:25 +08:00
|
|
|
|
|
2024-08-21 16:50:14 +08:00
|
|
|
|
//[HttpGet]
|
|
|
|
|
//[AbpAllowAnonymous]
|
|
|
|
|
//[ShowApi]
|
|
|
|
|
//public RequestResult<List<ProtectDeviceOutput>> FindProtectDevicesData(string stationName)
|
|
|
|
|
//{
|
|
|
|
|
// RequestResult<List<ProtectDeviceOutput>> rst = new();
|
|
|
|
|
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// var repo = _imProtectDeviceRepository.GetAllIncluding();
|
|
|
|
|
// rst.ResultData =ObjectMapper.Map<List<ProtectDeviceOutput>>(repo);
|
|
|
|
|
// rst.Flag = true;
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// rst.Flag = false;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// return rst;
|
|
|
|
|
//}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[AbpAllowAnonymous]
|
|
|
|
|
[ShowApi]
|
|
|
|
|
public RequestResult<List<ProtectDeviceOutput>> FindDevicesData(string devName)
|
|
|
|
|
{
|
|
|
|
|
RequestResult<List<ProtectDeviceOutput>> rst = new();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//var repo = _imDeviceDatumRepository.GetAllIncluding(t=>t.Device).Where(t=>t.Device.DeviceName == protectDevName);
|
|
|
|
|
rst.Flag = true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
rst.Flag = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rst;
|
|
|
|
|
}
|
2024-08-22 14:18:13 +08:00
|
|
|
|
|
|
|
|
|
|
2024-08-21 16:50:14 +08:00
|
|
|
|
}
|
|
|
|
|
}
|