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.

312 lines
14 KiB

using System.Linq.Expressions;
using AutoMapper;
using Common.Const;
6 months ago
using Entity.Api.Req;
using Entity.DbModel.Station;
using Entity.Dto;
using Furion.LinqBuilder;
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;
using SqlSugar;
6 months ago
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([FromBody] QueryAlarmReq req)
{
4 months ago
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];
}
}
4 months ago
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" };
}
}
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([FromBody] QueryAlarmReq req)
{
4 months ago
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);
}
4 months ago
// 执行查询
List<EquipAlarmProcessRecord> equipAlarmProcessRecords = await ProcessRecordRepository.QueryListByClauseAsync(
predicate,
it => it.CreatedTime,
OrderByType.Desc
);
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();
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" };
}
}
6 months ago
}