639 lines
29 KiB
C#
639 lines
29 KiB
C#
![]() |
using Abp.Auditing;
|
|||
|
using Abp.Authorization;
|
|||
|
using Abp.Collections.Extensions;
|
|||
|
using Abp.Domain.Repositories;
|
|||
|
using Abp.Domain.Uow;
|
|||
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
using MongoDB.Driver.Linq;
|
|||
|
using Newtonsoft.Json;
|
|||
|
using NPOI.SS.Formula.Functions;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Linq.Dynamic.Core;
|
|||
|
using System.Linq.Expressions;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Xml.Serialization;
|
|||
|
using ToolLibrary.LogHelper;
|
|||
|
using YunDa.ISAS.Application.Core;
|
|||
|
using YunDa.ISAS.Application.Core.Session;
|
|||
|
using YunDa.ISAS.Application.Core.SwaggerHelper;
|
|||
|
using YunDa.ISAS.DataTransferObject;
|
|||
|
using YunDa.ISAS.DataTransferObject.CommonDto;
|
|||
|
using YunDa.ISAS.DataTransferObject.GeneralInformation.EquipmentInfoDto.SearchCondition;
|
|||
|
using YunDa.ISAS.Entities.GeneralInformation;
|
|||
|
using YunDa.ISMS.BASE.Entities.Models;
|
|||
|
using YunDa.SOMS.DataTransferObject.GeneralInformation.ProtectionDeviceInfoDto;
|
|||
|
using YunDa.SOMS.DataTransferObject.GeneralInformation.ProtectionDeviceInfoDto.HistoryData;
|
|||
|
using YunDa.SOMS.DataTransferObject.GeneralInformation.ProtectionDeviceInfoDto.SearchCondition;
|
|||
|
using YunDa.SOMS.Entities.GeneralInformation;
|
|||
|
using static Google.Protobuf.Reflection.ExtensionRangeOptions.Types;
|
|||
|
|
|||
|
namespace YunDa.ISAS.Application.GeneralInformation
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 保护装置履历信息管理类
|
|||
|
/// </summary>
|
|||
|
public class ProtectionDeviceAppService : ISASAppServiceBase,IProtectionDeviceAppService
|
|||
|
{
|
|||
|
private readonly IRepository<EquipmentInfo, Guid> _equipmentInfoRepository;
|
|||
|
private readonly IRepository<ProtectionDeviceInfo, Guid> _protectionDeviceInfoRepository;
|
|||
|
private readonly IRepository<ProtectionDeviceHistory, Guid> _protectionDeviceHistoryRepository;
|
|||
|
private readonly IRepository<SecondaryCircuitProtectionDevice, Guid> _secondaryCircuitProtectionDeviceRepository;
|
|||
|
|
|||
|
|
|||
|
private readonly IRepository<BoardCardInfo, Guid> _boardCardInfoRepository;
|
|||
|
private readonly IRepository<BoardCardHistory, Guid> _boardCardHistoryRepository;
|
|||
|
private readonly IRepository<ImProtectDevice,string> _imProtectDeviceRepository;
|
|||
|
private readonly IUnitOfWorkManager _unitOfWorkManager;
|
|||
|
|
|||
|
public ProtectionDeviceAppService(
|
|||
|
IRepository<ProtectionDeviceInfo, Guid> protectionDeviceInfoRepository,
|
|||
|
IUnitOfWorkManager unitOfWorkManager,
|
|||
|
IRepository<ImProtectDevice, string> imProtectDeviceRepository,
|
|||
|
IRepository<EquipmentInfo, Guid> equipmentInfoRepository,
|
|||
|
IRepository<SecondaryCircuitProtectionDevice, Guid> secondaryCircuitProtectionDeviceRepository
|
|||
|
,
|
|||
|
IRepository<BoardCardInfo, Guid> boardCardInfoRepository,
|
|||
|
IRepository<BoardCardHistory, Guid> boardCardHistoryRepository,
|
|||
|
IRepository<ProtectionDeviceHistory, Guid> protectionDeviceHistoryRepository,
|
|||
|
ISessionAppService sessionAppService
|
|||
|
) :
|
|||
|
base(sessionAppService)
|
|||
|
{
|
|||
|
_unitOfWorkManager = unitOfWorkManager;
|
|||
|
_equipmentInfoRepository = equipmentInfoRepository;
|
|||
|
_imProtectDeviceRepository = imProtectDeviceRepository;
|
|||
|
_protectionDeviceInfoRepository = protectionDeviceInfoRepository;
|
|||
|
_protectionDeviceHistoryRepository = protectionDeviceHistoryRepository;
|
|||
|
_boardCardInfoRepository = boardCardInfoRepository;
|
|||
|
_boardCardHistoryRepository = boardCardHistoryRepository;
|
|||
|
_secondaryCircuitProtectionDeviceRepository = secondaryCircuitProtectionDeviceRepository;
|
|||
|
|
|||
|
}
|
|||
|
public async Task<RequestResult<ProtectionDeviceInfoViewOutput>> CreateOrUpdateAsync(EditProtectionDeviceInfoInput input)
|
|||
|
{
|
|||
|
RequestResult<ProtectionDeviceInfoViewOutput> rst = new RequestResult<ProtectionDeviceInfoViewOutput>();
|
|||
|
try
|
|||
|
{
|
|||
|
if (input.Id.HasValue)
|
|||
|
{
|
|||
|
var entity = _protectionDeviceInfoRepository.GetAllIncluding(t=>t.EquipmentInfo).FirstOrDefault(t => t.Id == input.Id);
|
|||
|
if (entity != null)
|
|||
|
{
|
|||
|
entity.LastModificationTime = DateTime.Now;
|
|||
|
entity.LastModifierUserId = base.GetCurrentUser().Id;
|
|||
|
entity.SeqNo = input.SeqNo;
|
|||
|
// 逐字段赋值
|
|||
|
entity.Name = input.Name;
|
|||
|
entity.Specification = input.Specification;
|
|||
|
entity.DeviceAddress = input.DeviceAddress;
|
|||
|
entity.BaselineBoardVersion = input.BaselineBoardVersion;
|
|||
|
entity.HardwareVersion = input.HardwareVersion;
|
|||
|
entity.IsActive = input.IsActive;
|
|||
|
// 设备信息赋值
|
|||
|
if (entity.EquipmentInfo != null)
|
|||
|
{
|
|||
|
entity.EquipmentInfo.ManufacturerInfoId = input.ManufacturerInfoId;
|
|||
|
entity.EquipmentInfo.Name = input.Name;
|
|||
|
entity.EquipmentInfo.InstallationDate = input.InstallationDate;
|
|||
|
entity.EquipmentInfo.ProductionDate = input.ProductionDate;
|
|||
|
entity.EquipmentInfo.FactorySerialNumber = input.FactorySerialNumber;
|
|||
|
entity.EquipmentInfo.VerificationPerson = input.VerificationPerson;
|
|||
|
entity.EquipmentInfo.VerificationDate = input.VerificationDate;
|
|||
|
entity.EquipmentInfo.VerificationRecords = input.VerificationRecords;
|
|||
|
entity.EquipmentInfo.ManufacturerInfoId = input.ManufacturerInfoId;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
var entity = new ProtectionDeviceInfo();
|
|||
|
entity.CreatorUserId = base.GetCurrentUser().Id;
|
|||
|
entity.CreationTime = DateTime.Now;
|
|||
|
// 逐字段赋值
|
|||
|
entity.SeqNo = input.SeqNo;
|
|||
|
entity.Name = input.Name;
|
|||
|
entity.Specification = input.Specification;
|
|||
|
entity.DeviceAddress = input.DeviceAddress;
|
|||
|
entity.BaselineBoardVersion = input.BaselineBoardVersion;
|
|||
|
entity.HardwareVersion = input.HardwareVersion;
|
|||
|
entity.IsActive = input.IsActive;
|
|||
|
|
|||
|
entity.EquipmentInfo = new EquipmentInfo();
|
|||
|
entity.EquipmentInfo.ManufacturerInfoId = input.ManufacturerInfoId;
|
|||
|
entity.EquipmentInfo.SeqNo = input.SeqNo;
|
|||
|
entity.EquipmentInfo.Name = input.Name;
|
|||
|
entity.EquipmentInfo.InstallationDate = input.InstallationDate;
|
|||
|
entity.EquipmentInfo.ProductionDate = input.ProductionDate;
|
|||
|
entity.EquipmentInfo.FactorySerialNumber = input.FactorySerialNumber;
|
|||
|
entity.EquipmentInfo.VerificationPerson = input.VerificationPerson;
|
|||
|
entity.EquipmentInfo.VerificationDate = input.VerificationDate;
|
|||
|
entity.EquipmentInfo.VerificationRecords = input.VerificationRecords;
|
|||
|
entity.EquipmentInfo.ManufacturerInfoId = input.ManufacturerInfoId;
|
|||
|
var equipmentInfoId =await _equipmentInfoRepository.InsertAndGetIdAsync(entity.EquipmentInfo);
|
|||
|
entity.EquipmentInfoId = equipmentInfoId;
|
|||
|
await _protectionDeviceInfoRepository.InsertAsync(entity);
|
|||
|
}
|
|||
|
rst.Flag = true;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
rst.Message = ex.Message;
|
|||
|
rst.Flag = false;
|
|||
|
Log4Helper.Error(this.GetType(), "线路管理服务", ex);
|
|||
|
}
|
|||
|
|
|||
|
return rst;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 扫码枪输入设备信息
|
|||
|
/// </summary>
|
|||
|
/// <param name="input"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[ShowApi]
|
|||
|
[AbpAllowAnonymous]
|
|||
|
[HttpPost]
|
|||
|
public RequestEasyResult ScanDeviceQRCode(EditProtectionQrCodeDeviceInfoInput input)
|
|||
|
{
|
|||
|
RequestEasyResult rst = new RequestEasyResult();
|
|||
|
try
|
|||
|
{
|
|||
|
|
|||
|
var repo = _protectionDeviceInfoRepository.GetAllIncluding(t => t.EquipmentInfo,t=>t.ProtectionDeviceType).ToList();
|
|||
|
|
|||
|
var protectionDevice = repo.FirstOrDefault(t => t.Name.Contains(input.Name));
|
|||
|
if (protectionDevice != null)
|
|||
|
{
|
|||
|
//当出厂编号不一致进行履历更新
|
|||
|
if (protectionDevice.EquipmentInfo.FactorySerialNumber != input.SerialNumber)
|
|||
|
{
|
|||
|
var json = JsonConvert.SerializeObject(protectionDevice);
|
|||
|
var protectionDeviceHistory = _protectionDeviceHistoryRepository.GetAll().Where(t => t.ProtectionDeviceInfoId == protectionDevice.Id).ToList();
|
|||
|
var deviceHistory = new ProtectionDeviceHistory
|
|||
|
{
|
|||
|
ContentJson = json,
|
|||
|
CreationTime = DateTime.Now,
|
|||
|
CreatorUserId = base.GetCurrentUser().Id,
|
|||
|
Name = protectionDevice.Name,
|
|||
|
RecodeDate = DateTime.Now,
|
|||
|
ProtectionDeviceInfoId = protectionDevice.Id,
|
|||
|
SeqNo = protectionDeviceHistory.Count > 0 ? protectionDeviceHistory.Max(t => t.SeqNo) : 1
|
|||
|
};
|
|||
|
protectionDevice.Specification = input.Specification;
|
|||
|
protectionDevice.EquipmentInfo.FactorySerialNumber = input.SerialNumber;
|
|||
|
protectionDevice.EquipmentInfo.ProductionDate = input.ProductionDate;
|
|||
|
protectionDevice.EquipmentInfo.VerificationDate = input.VerificationDate;
|
|||
|
protectionDevice.EquipmentInfo.VerificationPerson = input.VerificationPerson;
|
|||
|
protectionDevice.EquipmentInfo.VerificationRecords = input.VerificationRecords;
|
|||
|
var newjson = JsonConvert.SerializeObject(protectionDevice);
|
|||
|
deviceHistory.ContentNewJson = newjson;
|
|||
|
_protectionDeviceHistoryRepository.Insert(deviceHistory);
|
|||
|
|
|||
|
}
|
|||
|
rst.Flag = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
rst.Message = "未找到对应装置";
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
throw;
|
|||
|
}
|
|||
|
|
|||
|
return rst;
|
|||
|
}
|
|||
|
|
|||
|
public async Task<RequestEasyResult> DeleteByIdAsync(Guid id)
|
|||
|
{
|
|||
|
RequestEasyResult rst = new RequestEasyResult();
|
|||
|
return rst;
|
|||
|
}
|
|||
|
|
|||
|
public async Task<RequestEasyResult> DeleteByIdsAsync(List<Guid> ids)
|
|||
|
{
|
|||
|
RequestEasyResult rst = new RequestEasyResult();
|
|||
|
return rst;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 查询保护装置信息
|
|||
|
/// </summary>
|
|||
|
/// <param name="searchCondition"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[ShowApi]
|
|||
|
[AbpAllowAnonymous]
|
|||
|
[DisableAuditing]
|
|||
|
[HttpPost]
|
|||
|
public RequestPageResult<ProtectionDeviceInfoViewOutput> FindDatas(PageSearchCondition<ProtectionDeviceInfoSearchConditionInput> searchCondition)
|
|||
|
{
|
|||
|
RequestPageResult<ProtectionDeviceInfoViewOutput> rst = new RequestPageResult<ProtectionDeviceInfoViewOutput>();
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
var repo = _protectionDeviceInfoRepository.GetAllIncluding(t => t.EquipmentInfo)
|
|||
|
.WhereIf(searchCondition.SearchCondition.IsOnlyActive.HasValue, t => t.IsActive)
|
|||
|
.WhereIf(searchCondition.SearchCondition.Id.HasValue, t => t.Id == searchCondition.SearchCondition.Id.Value)
|
|||
|
.WhereIf(searchCondition.SearchCondition.TransformerSubstationId.HasValue, t => t.Id == searchCondition.SearchCondition.TransformerSubstationId.Value).ToList();
|
|||
|
List<ProtectionDeviceInfoViewOutput> datas = default;
|
|||
|
if (!string.IsNullOrWhiteSpace( searchCondition.SearchCondition.Name))
|
|||
|
{
|
|||
|
repo = repo.Where(t => t.Name.Contains(searchCondition.SearchCondition.Name)).ToList();
|
|||
|
}
|
|||
|
rst.TotalCount = repo.Count();
|
|||
|
if (repo.Count()>0)
|
|||
|
{
|
|||
|
rst.PageSize = searchCondition.PageSize;
|
|||
|
rst.PageIndex = searchCondition.PageIndex;
|
|||
|
if ( searchCondition.PageSize>0)
|
|||
|
{
|
|||
|
var dataTemps = repo.Skip((searchCondition.PageIndex-1)* searchCondition.PageSize).Take(searchCondition.PageSize);
|
|||
|
datas = ObjectMapper.Map<List<ProtectionDeviceInfoViewOutput>>(dataTemps);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
datas = ObjectMapper.Map<List<ProtectionDeviceInfoViewOutput>>(repo);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
rst.ResultData= datas;
|
|||
|
rst.Flag = true;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
rst.Message = ex.Message;
|
|||
|
rst.Flag = false;
|
|||
|
Log4Helper.Error(this.GetType(), "保护装置信息管理服务", ex);
|
|||
|
}
|
|||
|
|
|||
|
return rst;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 查询保护装置信息
|
|||
|
/// </summary>
|
|||
|
/// <param name="searchCondition"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[ShowApi]
|
|||
|
[AbpAllowAnonymous]
|
|||
|
[DisableAuditing]
|
|||
|
[HttpPost]
|
|||
|
public RequestPageResult<ProtectionDeviceInfoViewOutput> FindDatasByCircuit(PageSearchCondition<ProtectionDeviceInfoSearchConditionInput> searchCondition)
|
|||
|
{
|
|||
|
RequestPageResult<ProtectionDeviceInfoViewOutput> rst = new RequestPageResult<ProtectionDeviceInfoViewOutput>();
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
var repo = _secondaryCircuitProtectionDeviceRepository.GetAllIncluding(t => t.ProtectionDevice)
|
|||
|
.Where(t=>t.SecondaryCircuitId == searchCondition.SearchCondition.SecondaryCircuitId).ToList();
|
|||
|
List<ProtectionDeviceInfoViewOutput> datas = default;
|
|||
|
|
|||
|
rst.TotalCount = repo.Count();
|
|||
|
if (repo.Count() > 0)
|
|||
|
{
|
|||
|
rst.PageSize = searchCondition.PageSize;
|
|||
|
rst.PageIndex = searchCondition.PageIndex;
|
|||
|
if (searchCondition.PageSize > 0)
|
|||
|
{
|
|||
|
var dataTemps = repo.Skip((searchCondition.PageIndex - 1) * searchCondition.PageSize).Take(searchCondition.PageSize);
|
|||
|
datas = ObjectMapper.Map<List<ProtectionDeviceInfoViewOutput>>(dataTemps.Select(t=>t.ProtectionDevice));
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
datas = ObjectMapper.Map<List<ProtectionDeviceInfoViewOutput>>(repo);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
rst.ResultData = datas;
|
|||
|
rst.Flag = true;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
rst.Message = ex.Message;
|
|||
|
rst.Flag = false;
|
|||
|
Log4Helper.Error(this.GetType(), "保护装置信息管理服务", ex);
|
|||
|
}
|
|||
|
|
|||
|
return rst;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 查询保护装置信息
|
|||
|
/// </summary>
|
|||
|
/// <param name="equipmentInfoId"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[ShowApi]
|
|||
|
[AbpAllowAnonymous]
|
|||
|
[DisableAuditing]
|
|||
|
[HttpGet]
|
|||
|
public RequestResult<ProtectionDeviceInfoViewOutput> FindDataByEquipmentInfoId(Guid? equipmentInfoId)
|
|||
|
{
|
|||
|
RequestResult<ProtectionDeviceInfoViewOutput> rst = new RequestResult<ProtectionDeviceInfoViewOutput>();
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
var entity = _protectionDeviceInfoRepository.GetAllIncluding(t => t.EquipmentInfo)
|
|||
|
.FirstOrDefault(t => t.EquipmentInfoId == equipmentInfoId);
|
|||
|
if (entity!=null)
|
|||
|
{
|
|||
|
rst.ResultData = ObjectMapper.Map<ProtectionDeviceInfoViewOutput>(entity);
|
|||
|
rst.Flag = true;
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
rst.Message = ex.Message;
|
|||
|
rst.Flag = false;
|
|||
|
Log4Helper.Error(this.GetType(), "保护装置信息管理服务", ex);
|
|||
|
}
|
|||
|
|
|||
|
return rst;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 查询历史保护装置信息
|
|||
|
/// </summary>
|
|||
|
/// <param name="equipmentInfoId"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[ShowApi]
|
|||
|
[AbpAllowAnonymous]
|
|||
|
[DisableAuditing]
|
|||
|
[HttpGet]
|
|||
|
public RequestResult<List<ProtectionDeviceHistoryOutput>> FindHistoryDataByEquipmentInfoId(Guid? equipmentInfoId)
|
|||
|
{
|
|||
|
RequestResult<List<ProtectionDeviceHistoryOutput>> rst = new RequestResult<List<ProtectionDeviceHistoryOutput>>();
|
|||
|
try
|
|||
|
{
|
|||
|
List<ProtectionDeviceHistoryOutput> historys = new List<ProtectionDeviceHistoryOutput>();
|
|||
|
var protectionDevice = _protectionDeviceInfoRepository.GetAllIncluding(t => t.EquipmentInfo)
|
|||
|
.FirstOrDefault(t => t.EquipmentInfoId == equipmentInfoId);
|
|||
|
if (protectionDevice != null)
|
|||
|
{
|
|||
|
var entitys = _protectionDeviceHistoryRepository.GetAll().Where(t => t.ProtectionDeviceInfoId == protectionDevice.Id);
|
|||
|
foreach (var entity in entitys)
|
|||
|
{
|
|||
|
ProtectionDeviceInfo protectionDevice1= JsonConvert.DeserializeObject<ProtectionDeviceInfo>(entity.ContentJson);
|
|||
|
ProtectionDeviceInfo protectionDevice2 = JsonConvert.DeserializeObject<ProtectionDeviceInfo>(entity.ContentNewJson);
|
|||
|
ProtectionDeviceHistoryOutput historyOutput = new ProtectionDeviceHistoryOutput
|
|||
|
{
|
|||
|
SeqNo = entity.SeqNo,
|
|||
|
RecodeDate = entity.RecodeDate,
|
|||
|
PostUpdate = new ProtectionDeviceHistoryViewOutput
|
|||
|
{
|
|||
|
BaselineBoardVersion = protectionDevice1.BaselineBoardVersion,
|
|||
|
FactorySerialNumber = protectionDevice1.EquipmentInfo.FactorySerialNumber,
|
|||
|
ProductionDate = protectionDevice1.EquipmentInfo.ProductionDate,
|
|||
|
HardwareVersion = protectionDevice1.HardwareVersion,
|
|||
|
Specification = protectionDevice1.Specification,
|
|||
|
VerificationDate = protectionDevice1.EquipmentInfo.VerificationDate,
|
|||
|
VerificationPerson = protectionDevice1.EquipmentInfo.VerificationPerson,
|
|||
|
VerificationRecords = protectionDevice1.EquipmentInfo.VerificationRecords,
|
|||
|
},
|
|||
|
PrioUpdate = new ProtectionDeviceHistoryViewOutput
|
|||
|
{
|
|||
|
BaselineBoardVersion = protectionDevice2.BaselineBoardVersion,
|
|||
|
FactorySerialNumber = protectionDevice2.EquipmentInfo.FactorySerialNumber,
|
|||
|
ProductionDate = protectionDevice2.EquipmentInfo.ProductionDate,
|
|||
|
HardwareVersion = protectionDevice2.HardwareVersion,
|
|||
|
Specification = protectionDevice2.Specification,
|
|||
|
VerificationDate = protectionDevice2.EquipmentInfo.VerificationDate,
|
|||
|
VerificationPerson = protectionDevice2.EquipmentInfo.VerificationPerson,
|
|||
|
VerificationRecords = protectionDevice2.EquipmentInfo.VerificationRecords,
|
|||
|
},
|
|||
|
};
|
|||
|
historys.Add(historyOutput);
|
|||
|
|
|||
|
}
|
|||
|
rst.Flag = true;
|
|||
|
rst.ResultData = historys;
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
rst.Message = ex.Message;
|
|||
|
rst.Flag = false;
|
|||
|
Log4Helper.Error(this.GetType(), "保护装置信息管理服务", ex);
|
|||
|
}
|
|||
|
|
|||
|
return rst;
|
|||
|
}
|
|||
|
public RequestResult<string> GetProtectionDeviceQRcode(Guid id)
|
|||
|
{
|
|||
|
RequestResult<string> rst = new RequestResult<string>();
|
|||
|
return rst;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 获取保护装置列表
|
|||
|
/// </summary>
|
|||
|
/// <param name="stationId"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpGet]
|
|||
|
[ShowApi]
|
|||
|
[AbpAllowAnonymous]
|
|||
|
[DisableAuditing]
|
|||
|
public RequestResult<List<SelectModelOutput>> FindProtectionDeviceForSelect(Guid stationId)
|
|||
|
{
|
|||
|
var rst = new RequestResult<List<SelectModelOutput>> { Flag = false };
|
|||
|
try
|
|||
|
{
|
|||
|
var datas = _protectionDeviceInfoRepository.GetAllIncluding()
|
|||
|
.Where(e => e.IsActive)
|
|||
|
.Where(t=>t.TransformerSubstationId == stationId)
|
|||
|
.OrderBy(x=>x.SeqNo).ThenBy(x => x.Name);
|
|||
|
|
|||
|
rst.ResultData = datas.Select(item => new SelectModelOutput
|
|||
|
{
|
|||
|
Value = item.Id.ToString().ToLower(),
|
|||
|
Key = item.Id,
|
|||
|
Text = item.Name
|
|||
|
}).ToList();
|
|||
|
|
|||
|
rst.Flag = true;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
rst.Message = ex.Message;
|
|||
|
rst.Flag = false;
|
|||
|
Log4Helper.Error(this.GetType(), "获取保护装置列表", ex);
|
|||
|
}
|
|||
|
|
|||
|
return rst;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 从综自后台数据库迁移数据到运维数据库中(保护装置数据)
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
[ShowApi]
|
|||
|
[AbpAllowAnonymous]
|
|||
|
[HttpGet]
|
|||
|
[UnitOfWork(isTransactional: false)]
|
|||
|
public RequestEasyResult MigreteDataFromISMS()
|
|||
|
{
|
|||
|
RequestEasyResult rst = new RequestEasyResult();
|
|||
|
try
|
|||
|
{
|
|||
|
List<EquipmentInfo> equipments = default;
|
|||
|
Dictionary<string,ImProtectDevice> imProtectDevices = default;
|
|||
|
Dictionary<string, ProtectionDeviceInfo> porotectionDeviceInfos = default;
|
|||
|
using (var unitOfWork = _unitOfWorkManager.Begin())
|
|||
|
{
|
|||
|
equipments = _equipmentInfoRepository.GetAllIncluding().ToList();
|
|||
|
_protectionDeviceInfoRepository.GetAllIncluding().ToDictionary(t=>t.Name);
|
|||
|
unitOfWork.Complete();
|
|||
|
}
|
|||
|
using (var unitOfWork = _unitOfWorkManager.Begin())
|
|||
|
{
|
|||
|
imProtectDevices = _imProtectDeviceRepository.GetAllIncluding().ToDictionary(t=>t.DeviceName);
|
|||
|
unitOfWork.Complete();
|
|||
|
|
|||
|
}
|
|||
|
int count = 0;
|
|||
|
using (var unitOfWork = _unitOfWorkManager.Begin())
|
|||
|
{
|
|||
|
foreach (var equipment in equipments)
|
|||
|
{
|
|||
|
if (imProtectDevices.ContainsKey(equipment.Name))
|
|||
|
{
|
|||
|
if (porotectionDeviceInfos.ContainsKey(equipment.Name))
|
|||
|
{
|
|||
|
continue;
|
|||
|
}
|
|||
|
count++;
|
|||
|
var imProtectDevice = imProtectDevices[equipment.Name];
|
|||
|
ProtectionDeviceInfo protectionDeviceInfo = new ProtectionDeviceInfo()
|
|||
|
{
|
|||
|
CanSwitchDZZone = imProtectDevice.CanSwDzzone == 1 ? true : false,
|
|||
|
CreationTime = DateTime.Now,
|
|||
|
CreatorUserId = null,
|
|||
|
SupportsDualCurrent = imProtectDevice.SupportVersion,
|
|||
|
BayName = imProtectDevice.BayName,
|
|||
|
DeviceAddress = imProtectDevice.DeviceAddr,
|
|||
|
DeviceState = imProtectDevice.DeviceState,
|
|||
|
EndOfDKJL = imProtectDevice.EndOfDkjl,
|
|||
|
EquipmentInfoId = equipment.Id,
|
|||
|
IsActive = true,
|
|||
|
ISMS_DeviceId = imProtectDevice.Id,
|
|||
|
Name = equipment.Name,
|
|||
|
ProtectionDeviceGatewayId = null,
|
|||
|
ProtectionDeviceTypeId = null,
|
|||
|
TransformerSubstationId = equipment.TransformerSubstationId.Value,
|
|||
|
};
|
|||
|
_protectionDeviceInfoRepository.Insert(protectionDeviceInfo);
|
|||
|
}
|
|||
|
}
|
|||
|
unitOfWork.Complete();
|
|||
|
}
|
|||
|
rst.Flag= true;
|
|||
|
rst.Message = $"共完成{count}信息迁移";
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
rst.Message = ex.Message;
|
|||
|
rst.Flag = false;
|
|||
|
Log4Helper.Error(this.GetType(), "线路管理服务", ex);
|
|||
|
}
|
|||
|
|
|||
|
return rst;
|
|||
|
}
|
|||
|
#if DEBUG
|
|||
|
/// <summary>
|
|||
|
/// 填充出厂编号
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
[ShowApi]
|
|||
|
[AbpAllowAnonymous]
|
|||
|
[HttpGet]
|
|||
|
public RequestEasyResult UpdateProtetionInfoForTest()
|
|||
|
{
|
|||
|
RequestEasyResult rst = new RequestEasyResult();
|
|||
|
try
|
|||
|
{
|
|||
|
var datas = _protectionDeviceInfoRepository.GetAllIncluding(t => t.EquipmentInfo);
|
|||
|
Random random = new Random();
|
|||
|
foreach (var data in datas) {
|
|||
|
|
|||
|
data.BaselineBoardVersion = "v1.100.001";
|
|||
|
data.Specification = "110V 1A";
|
|||
|
data.EquipmentInfo.FactorySerialNumber = "210"+ random.Next(100000, 1000000).ToString();
|
|||
|
// 设置出厂时间为当前日期的前一天(您可以根据需求调整时间)
|
|||
|
data.EquipmentInfo.ProductionDate = DateTime.Now.AddDays(-100);
|
|||
|
// 设置检验人员
|
|||
|
data.EquipmentInfo.VerificationPerson = "贺严玲"; // 请替换为实际人员名称
|
|||
|
// 设置检验日期为当前日期
|
|||
|
data.EquipmentInfo.VerificationDate = DateTime.Now.AddDays(0).ToString("yyyy-MM-dd"); // 日期格式为 "yyyy-MM-dd"
|
|||
|
// 设置检验记录内容
|
|||
|
data.EquipmentInfo.VerificationRecords = "检验装置外观及功能,均符合要求";
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
|
|||
|
throw;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
return rst;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 填充出厂编号
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
[ShowApi]
|
|||
|
[AbpAllowAnonymous]
|
|||
|
[HttpGet]
|
|||
|
public async Task<RequestEasyResult> UpdateProtetionInfoForHistoryTest()
|
|||
|
{
|
|||
|
RequestEasyResult rst = new RequestEasyResult();
|
|||
|
try
|
|||
|
{
|
|||
|
List<ProtectionDeviceInfo> datas;
|
|||
|
using (var unitOfWork = _unitOfWorkManager.Begin())
|
|||
|
{
|
|||
|
datas = _protectionDeviceInfoRepository.GetAllIncluding(t => t.EquipmentInfo).ToList();
|
|||
|
await unitOfWork.CompleteAsync();
|
|||
|
}
|
|||
|
Random random = new Random();
|
|||
|
for (int i = 0; i < 3; i++)
|
|||
|
{
|
|||
|
foreach (var data in datas)
|
|||
|
{
|
|||
|
EditProtectionQrCodeDeviceInfoInput deviceInfo = new EditProtectionQrCodeDeviceInfoInput
|
|||
|
{
|
|||
|
Name = data.Name, // 示例装置名称
|
|||
|
SerialNumber = "210" + random.Next(100000, 1000000).ToString(), // 出厂编号设为 "210" 开头 + 6 位随机数
|
|||
|
ProductionDate = new DateTime(2023, 5, 15), // 示例生产日期
|
|||
|
VerificationPerson = "贺严玲", // 示例检验人员
|
|||
|
VerificationDate = DateTime.Now.AddDays(-100+i).ToString("yyyy-MM-dd"), // 检验日期设为当前日期
|
|||
|
VerificationRecords = "检验装置外观及功能,均符合要求" // 示例检验记录
|
|||
|
};
|
|||
|
using (var unitOfWork = _unitOfWorkManager.Begin())
|
|||
|
{
|
|||
|
ScanDeviceQRCode(deviceInfo);
|
|||
|
await unitOfWork.CompleteAsync();
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
|
|||
|
throw;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
return rst;
|
|||
|
}
|
|||
|
|
|||
|
#endif
|
|||
|
|
|||
|
}
|
|||
|
}
|