|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
using Common.Const;
|
|
|
|
|
using Entity.Api.Req;
|
|
|
|
|
using Entity.DbModel.Station;
|
|
|
|
|
using Entity.Dto;
|
|
|
|
|
using Furion.LinqBuilder;
|
|
|
|
|
using HybirdFrameworkCore.Entity;
|
|
|
|
|
using Magicodes.ExporterAndImporter.Excel;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.Extensions.Localization;
|
|
|
|
|
using Repository.Station;
|
|
|
|
|
using Service.Station;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
|
|
|
|
namespace WebStarter.Controllers;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 换电设备报警
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
public class EquipAlarmRecordController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly EquipAlarmRecordService equipAlarmRecordService;
|
|
|
|
|
public readonly EquipAlarmProcessRecordRepository ProcessRecordRepository;
|
|
|
|
|
private readonly IStringLocalizer<EquipAlarmRecordController> _localizer;
|
|
|
|
|
|
|
|
|
|
public EquipAlarmRecordController(IStringLocalizer<EquipAlarmRecordController> localizer,EquipAlarmProcessRecordRepository equipAlarmProcessRecordRepository,EquipAlarmRecordService equipAlarmRecordService)
|
|
|
|
|
{
|
|
|
|
|
ProcessRecordRepository = equipAlarmProcessRecordRepository;
|
|
|
|
|
_localizer = localizer;
|
|
|
|
|
this.equipAlarmRecordService = equipAlarmRecordService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询未处理报警列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="typeCode">设备类型:-1-查询全部;0-充电机;1-电表;2-水冷机;3-plc<</param>
|
|
|
|
|
/// <param name="equipCode">设备编码</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("QueryEquipAlarmPage")]
|
|
|
|
|
public Result<PageResult<EquipAlarmRecord>> QueryEquipAlarmPage([FromBody] QueryAlarmReq req)
|
|
|
|
|
{
|
|
|
|
|
Result<PageResult<EquipAlarmRecord>> result = equipAlarmRecordService.QueryEquipAlarmPage(req);
|
|
|
|
|
if (result.Data.Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var recordAlarm in result.Data.Rows)
|
|
|
|
|
{
|
|
|
|
|
recordAlarm.ErrorMsg = _localizer[recordAlarm.ErrorMsg];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 导出未处理报警
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[Route("ExportEquipAlarmRecord")]
|
|
|
|
|
public async Task<IActionResult> ExportEquipAlarmRecord([FromBody] QueryAlarmReq req)
|
|
|
|
|
{
|
|
|
|
|
var language = Request.Headers["Accept-Language"].ToString().ToLower();
|
|
|
|
|
|
|
|
|
|
// 创建查询条件的表达式
|
|
|
|
|
Expression<Func<EquipAlarmRecord, bool>> predicate = it => true;
|
|
|
|
|
|
|
|
|
|
// 动态添加查询条件
|
|
|
|
|
if (req.TypeCode != -1)
|
|
|
|
|
{
|
|
|
|
|
predicate = predicate.And(it => it.EquipTypeCode == req.TypeCode);
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(req.EquipCode))
|
|
|
|
|
{
|
|
|
|
|
predicate = predicate.And(it => it.EquipCode == req.EquipCode);
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(req.ErrorLevel))
|
|
|
|
|
{
|
|
|
|
|
predicate = predicate.And(it => it.ErrorLevel == req.ErrorLevel);
|
|
|
|
|
}
|
|
|
|
|
if (req.StartTime.HasValue && req.ProcessTime.HasValue)
|
|
|
|
|
{
|
|
|
|
|
predicate = predicate.And(it => it.StartTime >= req.StartTime && it.StartTime <= req.ProcessTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 执行查询
|
|
|
|
|
List<EquipAlarmRecord> equipAlarmRecords = await equipAlarmRecordService.QueryListByClauseAsync(
|
|
|
|
|
predicate,
|
|
|
|
|
it => it.CreatedTime,
|
|
|
|
|
OrderByType.Desc
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (equipAlarmRecords.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var recordAlarm in equipAlarmRecords)
|
|
|
|
|
{
|
|
|
|
|
recordAlarm.ErrorMsg = _localizer[recordAlarm.ErrorMsg];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var config = new MapperConfiguration(cfg =>
|
|
|
|
|
{
|
|
|
|
|
cfg.CreateMap<EquipAlarmRecordDto, EquipAlarmRecord>().ReverseMap();
|
|
|
|
|
cfg.CreateMap<EquipAlarmRecordDto2, EquipAlarmRecord>().ReverseMap();
|
|
|
|
|
cfg.CreateMap<PlcEquipAlarmRecordDto, EquipAlarmRecord>().ReverseMap();
|
|
|
|
|
cfg.CreateMap<PlcEquipAlarmRecordDto2, EquipAlarmRecord>().ReverseMap();
|
|
|
|
|
cfg.CreateMap<ChargeEquipAlarmRecordDto, EquipAlarmRecord>().ReverseMap();
|
|
|
|
|
cfg.CreateMap<ChargeEquipAlarmRecordDto2, EquipAlarmRecord>().ReverseMap();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
IMapper mapper = config.CreateMapper();
|
|
|
|
|
|
|
|
|
|
if (req.TypeCode==(int)EquipmentType.Plc)
|
|
|
|
|
{
|
|
|
|
|
if (language == "en")
|
|
|
|
|
{
|
|
|
|
|
List<PlcEquipAlarmRecordDto2> logExList2 = mapper.Map<List<PlcEquipAlarmRecordDto2>>(equipAlarmRecords);
|
|
|
|
|
IExcelExporter excelExporter = new ExcelExporter();
|
|
|
|
|
var res = await excelExporter.ExportAsByteArray(logExList2);
|
|
|
|
|
return new FileStreamResult(new MemoryStream(res), "application/octet-stream")
|
|
|
|
|
{ FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "_Unhandled_Alarm_Logs.xlsx" };
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
List<PlcEquipAlarmRecordDto> logExList = mapper.Map<List<PlcEquipAlarmRecordDto>>(equipAlarmRecords);
|
|
|
|
|
IExcelExporter excelExporter = new ExcelExporter();
|
|
|
|
|
var res = await excelExporter.ExportAsByteArray(logExList);
|
|
|
|
|
return new FileStreamResult(new MemoryStream(res), "application/octet-stream")
|
|
|
|
|
{ FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "未处理报警日志.xlsx" };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (req.TypeCode==(int)EquipmentType.Charger)
|
|
|
|
|
{
|
|
|
|
|
if (language == "en")
|
|
|
|
|
{
|
|
|
|
|
List<ChargeEquipAlarmRecordDto2> logExList2 = mapper.Map<List<ChargeEquipAlarmRecordDto2>>(equipAlarmRecords);
|
|
|
|
|
IExcelExporter excelExporter = new ExcelExporter();
|
|
|
|
|
var res = await excelExporter.ExportAsByteArray(logExList2);
|
|
|
|
|
return new FileStreamResult(new MemoryStream(res), "application/octet-stream")
|
|
|
|
|
{ FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "_Unhandled_Alarm_Logs.xlsx" };
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
List<ChargeEquipAlarmRecordDto> logExList = mapper.Map<List<ChargeEquipAlarmRecordDto>>(equipAlarmRecords);
|
|
|
|
|
IExcelExporter excelExporter = new ExcelExporter();
|
|
|
|
|
var res = await excelExporter.ExportAsByteArray(logExList);
|
|
|
|
|
return new FileStreamResult(new MemoryStream(res), "application/octet-stream")
|
|
|
|
|
{ FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "未处理报警日志.xlsx" };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (language == "en")
|
|
|
|
|
{
|
|
|
|
|
List<EquipAlarmRecordDto2> logExList2 = mapper.Map<List<EquipAlarmRecordDto2>>(equipAlarmRecords);
|
|
|
|
|
IExcelExporter excelExporter = new ExcelExporter();
|
|
|
|
|
var res = await excelExporter.ExportAsByteArray(logExList2);
|
|
|
|
|
return new FileStreamResult(new MemoryStream(res), "application/octet-stream")
|
|
|
|
|
{ FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "_Unhandled_Alarm_Logs.xlsx" };
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
List<EquipAlarmRecordDto> logExList = mapper.Map<List<EquipAlarmRecordDto>>(equipAlarmRecords);
|
|
|
|
|
IExcelExporter excelExporter = new ExcelExporter();
|
|
|
|
|
var res = await excelExporter.ExportAsByteArray(logExList);
|
|
|
|
|
return new FileStreamResult(new MemoryStream(res), "application/octet-stream")
|
|
|
|
|
{ FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "未处理报警日志.xlsx" };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询已处理报警列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="typeCode">设备类型:-1-查询全部;0-充电机;1-电表;2-水冷机;3-plc</param>
|
|
|
|
|
/// <param name="equipCode">设备编码</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("QueryEquipAlarmProcessPage")]
|
|
|
|
|
public Result<PageResult<EquipAlarmProcessRecord>> QueryEquipAlarmProcessPage([FromBody] QueryAlarmReq req)
|
|
|
|
|
{
|
|
|
|
|
Result<PageResult<EquipAlarmProcessRecord>> result = equipAlarmRecordService.QueryEquipAlarmProcessPage(req);
|
|
|
|
|
|
|
|
|
|
if (result.Data.Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var recordAlarm in result.Data.Rows)
|
|
|
|
|
{
|
|
|
|
|
recordAlarm.ErrorMsg = _localizer[recordAlarm.ErrorMsg];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 导出已处理报警
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[Route("ExportEquipAlarmProcessRecord")]
|
|
|
|
|
public async Task<IActionResult> ExportEquipAlarmProcessRecord([FromBody] QueryAlarmReq req)
|
|
|
|
|
{
|
|
|
|
|
var language = Request.Headers["Accept-Language"].ToString().ToLower();
|
|
|
|
|
|
|
|
|
|
// 创建查询条件的表达式
|
|
|
|
|
Expression<Func<EquipAlarmProcessRecord, bool>> predicate = it => true;
|
|
|
|
|
|
|
|
|
|
// 动态添加查询条件
|
|
|
|
|
if (req.TypeCode != -1)
|
|
|
|
|
{
|
|
|
|
|
predicate = predicate.And(it => it.EquipTypeCode == req.TypeCode);
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(req.EquipCode))
|
|
|
|
|
{
|
|
|
|
|
predicate = predicate.And(it => it.EquipCode == req.EquipCode);
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(req.ErrorLevel))
|
|
|
|
|
{
|
|
|
|
|
predicate = predicate.And(it => it.ErrorLevel == req.ErrorLevel);
|
|
|
|
|
}
|
|
|
|
|
if (req.StartTime.HasValue && req.ProcessTime.HasValue)
|
|
|
|
|
{
|
|
|
|
|
predicate = predicate.And(it => it.StartTime >= req.StartTime && it.ProcessTime <= req.ProcessTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 执行查询
|
|
|
|
|
List<EquipAlarmProcessRecord> equipAlarmProcessRecords = await ProcessRecordRepository.QueryListByClauseAsync(
|
|
|
|
|
predicate,
|
|
|
|
|
it => it.CreatedTime,
|
|
|
|
|
OrderByType.Desc
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (equipAlarmProcessRecords.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var recordAlarm in equipAlarmProcessRecords)
|
|
|
|
|
{
|
|
|
|
|
recordAlarm.ErrorMsg = _localizer[recordAlarm.ErrorMsg];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var config = new MapperConfiguration(cfg =>
|
|
|
|
|
{
|
|
|
|
|
cfg.CreateMap<EquipAlarmProcessRecordDto, EquipAlarmProcessRecord>().ReverseMap();
|
|
|
|
|
cfg.CreateMap<EquipAlarmProcessRecordDto2, EquipAlarmProcessRecord>().ReverseMap();
|
|
|
|
|
cfg.CreateMap<PlcEquipAlarmProcessRecordDto, EquipAlarmProcessRecord>().ReverseMap();
|
|
|
|
|
cfg.CreateMap<PlcEquipAlarmProcessRecordDto2, EquipAlarmProcessRecord>().ReverseMap();
|
|
|
|
|
cfg.CreateMap<ChargeEquipAlarmProcessRecordDto, EquipAlarmProcessRecord>().ReverseMap();
|
|
|
|
|
cfg.CreateMap<ChargeEquipAlarmProcessRecordDto2, EquipAlarmProcessRecord>().ReverseMap();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
IMapper mapper = config.CreateMapper();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (req.TypeCode==(int)EquipmentType.Plc)
|
|
|
|
|
{
|
|
|
|
|
if (language == "en")
|
|
|
|
|
{
|
|
|
|
|
List<PlcEquipAlarmProcessRecordDto2> logExList2 = mapper.Map<List<PlcEquipAlarmProcessRecordDto2>>(equipAlarmProcessRecords);
|
|
|
|
|
IExcelExporter excelExporter = new ExcelExporter();
|
|
|
|
|
var res = await excelExporter.ExportAsByteArray(logExList2);
|
|
|
|
|
return new FileStreamResult(new MemoryStream(res), "application/octet-stream")
|
|
|
|
|
{ FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "_Processed_Alarm_Logs.xlsx" };
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
List<PlcEquipAlarmProcessRecordDto> logExList = mapper.Map<List<PlcEquipAlarmProcessRecordDto>>(equipAlarmProcessRecords);
|
|
|
|
|
IExcelExporter excelExporter = new ExcelExporter();
|
|
|
|
|
var res = await excelExporter.ExportAsByteArray(logExList);
|
|
|
|
|
return new FileStreamResult(new MemoryStream(res), "application/octet-stream")
|
|
|
|
|
{ FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "已处理报警日志.xlsx" };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (req.TypeCode==(int)EquipmentType.Charger)
|
|
|
|
|
{
|
|
|
|
|
if (language == "en")
|
|
|
|
|
{
|
|
|
|
|
List<ChargeEquipAlarmProcessRecordDto2> logExList2 = mapper.Map<List<ChargeEquipAlarmProcessRecordDto2>>(equipAlarmProcessRecords);
|
|
|
|
|
IExcelExporter excelExporter = new ExcelExporter();
|
|
|
|
|
var res = await excelExporter.ExportAsByteArray(logExList2);
|
|
|
|
|
return new FileStreamResult(new MemoryStream(res), "application/octet-stream")
|
|
|
|
|
{ FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "_Processed_Alarm_Logs.xlsx" };
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
List<ChargeEquipAlarmProcessRecordDto> logExList = mapper.Map<List<ChargeEquipAlarmProcessRecordDto>>(equipAlarmProcessRecords);
|
|
|
|
|
IExcelExporter excelExporter = new ExcelExporter();
|
|
|
|
|
var res = await excelExporter.ExportAsByteArray(logExList);
|
|
|
|
|
return new FileStreamResult(new MemoryStream(res), "application/octet-stream")
|
|
|
|
|
{ FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "已处理报警日志.xlsx" };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (language == "en")
|
|
|
|
|
{
|
|
|
|
|
List<EquipAlarmProcessRecordDto2> logExList2 = mapper.Map<List<EquipAlarmProcessRecordDto2>>(equipAlarmProcessRecords);
|
|
|
|
|
IExcelExporter excelExporter = new ExcelExporter();
|
|
|
|
|
var res = await excelExporter.ExportAsByteArray(logExList2);
|
|
|
|
|
return new FileStreamResult(new MemoryStream(res), "application/octet-stream")
|
|
|
|
|
{ FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "_Processed_Alarm_Logs.xlsx" };
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
List<EquipAlarmProcessRecordDto> logExList = mapper.Map<List<EquipAlarmProcessRecordDto>>(equipAlarmProcessRecords);
|
|
|
|
|
IExcelExporter excelExporter = new ExcelExporter();
|
|
|
|
|
var res = await excelExporter.ExportAsByteArray(logExList);
|
|
|
|
|
return new FileStreamResult(new MemoryStream(res), "application/octet-stream")
|
|
|
|
|
{ FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "已处理报警日志.xlsx" };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|