|
|
|
|
using AutoMapper;
|
|
|
|
|
using Entity.Api.Req;
|
|
|
|
|
using Entity.DbModel.Station;
|
|
|
|
|
using Entity.Dto;
|
|
|
|
|
using HybirdFrameworkCore.Entity;
|
|
|
|
|
using Magicodes.ExporterAndImporter.Excel;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.Extensions.Localization;
|
|
|
|
|
using Repository.Station;
|
|
|
|
|
using Service.Station;
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
var language = Request.Headers["Accept-Language"].ToString().ToLower();
|
|
|
|
|
|
|
|
|
|
List<EquipAlarmRecord> equipAlarmRecords = await equipAlarmRecordService.QueryAsync();
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
IMapper mapper = config.CreateMapper();
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
var language = Request.Headers["Accept-Language"].ToString().ToLower();
|
|
|
|
|
|
|
|
|
|
List<EquipAlarmProcessRecord> equipAlarmProcessRecords = await ProcessRecordRepository.QueryAsync();
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
IMapper mapper = config.CreateMapper();
|
|
|
|
|
|
|
|
|
|
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" };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|