You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
6.4 KiB

using AutoMapper;
6 months ago
using Entity.Api.Req;
using Entity.DbModel.Station;
using Entity.Dto;
6 months ago
using HybirdFrameworkCore.Entity;
using Magicodes.ExporterAndImporter.Excel;
6 months ago
using Microsoft.AspNetCore.Mvc;
4 months ago
using Microsoft.Extensions.Localization;
using Repository.Station;
6 months ago
using Service.Station;
namespace WebStarter.Controllers;
/// <summary>
/// 换电设备报警
/// </summary>
[ApiController]
[Route("api/[controller]")]
public class EquipAlarmRecordController : ControllerBase
{
private readonly EquipAlarmRecordService equipAlarmRecordService;
public readonly EquipAlarmProcessRecordRepository ProcessRecordRepository;
4 months ago
private readonly IStringLocalizer<EquipAlarmRecordController> _localizer;
6 months ago
public EquipAlarmRecordController(IStringLocalizer<EquipAlarmRecordController> localizer,EquipAlarmProcessRecordRepository equipAlarmProcessRecordRepository,EquipAlarmRecordService equipAlarmRecordService)
6 months ago
{
ProcessRecordRepository = equipAlarmProcessRecordRepository;
4 months ago
_localizer = localizer;
6 months ago
this.equipAlarmRecordService = equipAlarmRecordService;
}
/// <summary>
/// 查询未处理报警列表
/// </summary>
/// <param name="typeCode">设备类型:-1-查询全部0-充电机1-电表2-水冷机3-plc<</param>
/// <param name="equipCode">设备编码</param>
/// <returns></returns>
[HttpPost("QueryEquipAlarmPage")]
6 months ago
public Result<PageResult<EquipAlarmRecord>> QueryEquipAlarmPage([FromBody] QueryAlarmReq req)
{
4 months ago
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;
6 months ago
}
/// <summary>
/// 导出未处理报警
/// </summary>
/// <returns></returns>
[HttpPost]
[Route("ExportEquipAlarmRecord")]
public async Task<IActionResult> ExportEquipAlarmRecord()
{
4 months ago
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];
}
}
4 months ago
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" };
}
}
6 months ago
/// <summary>
/// 查询已处理报警列表
/// </summary>
/// <param name="typeCode">设备类型:-1-查询全部0-充电机1-电表2-水冷机3-plc</param>
/// <param name="equipCode">设备编码</param>
/// <returns></returns>
[HttpPost("QueryEquipAlarmProcessPage")]
6 months ago
public Result<PageResult<EquipAlarmProcessRecord>> QueryEquipAlarmProcessPage([FromBody] QueryAlarmReq req)
{
4 months ago
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;
6 months ago
}
/// <summary>
/// 导出已处理报警
/// </summary>
/// <returns></returns>
[HttpPost]
[Route("ExportEquipAlarmProcessRecord")]
public async Task<IActionResult> ExportEquipAlarmProcessRecord()
{
4 months ago
var language = Request.Headers["Accept-Language"].ToString().ToLower();
List<EquipAlarmProcessRecord> equipAlarmProcessRecords = await ProcessRecordRepository.QueryAsync();
4 months ago
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" };
}
}
6 months ago
}