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.

126 lines
4.5 KiB

using AutoMapper;
7 months ago
using Entity.Api.Req;
using Entity.DbModel.Station;
using Entity.Dto;
7 months ago
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Entity;
using HybirdFrameworkCore.Utils;
using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.Mvc;
7 months ago
using Repository.Station;
namespace Service.Station;
[Scope]
public class EquipAlarmRecordService : BaseServices<EquipAlarmRecord>
{
public EquipAlarmProcessRecordRepository ProcessRecordRepository { get; set; }
public EquipAlarmRecordService(EquipAlarmRecordRepository dal)
{
BaseDal = dal;
}
/// <summary>
/// 查询未处理报警列表
/// </summary>
/// <param name="typeCode">设备类型:-1-查询全部0-充电机1-电表2-水冷机3-plc<</param>
/// <param name="equipCode">设备编码</param>
/// <returns></returns>
public Result<PageResult<EquipAlarmRecord>> QueryEquipAlarmPage(QueryAlarmReq req)
{
int totalCount = 0;
int reqTypeCode = req.TypeCode;
var equipCode = req.EquipCode;
List<EquipAlarmRecord> list = BaseDal.Queryable().WhereIF(reqTypeCode != -1, it => it.EquipTypeCode == reqTypeCode)
.WhereIF(ObjUtils.IsNotNullOrWhiteSpace(equipCode), it => it.EquipCode == equipCode)
.ToPageList(req.PageNum, req.PageSize, ref totalCount);
PageResult<EquipAlarmRecord> result = new PageResult<EquipAlarmRecord>()
{
PageNum = req.PageNum,
PageSize = req.PageSize,
ToTal = totalCount,
Rows = list
};
return Result<PageResult<EquipAlarmRecord>>.Success(result);
}
/// <summary>
/// 导出未处理报警日志 🔖
/// </summary>
/// <returns></returns>
public async Task<IActionResult> ExportEquipAlarmRecord()
{
List<EquipAlarmRecord> equipAlarmRecords = await BaseDal.QueryAsync();
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<EquipAlarmRecordDto, EquipAlarmRecord>().ReverseMap();
});
IMapper mapper = config.CreateMapper();
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" };
}
7 months ago
/// <summary>
/// 查询已处理报警列表
/// </summary>
/// <param name="typeCode">设备类型:-1-查询全部0-充电机1-电表2-水冷机3-plc</param>
/// <param name="equipCode">设备编码</param>
/// <returns></returns>
public Result<PageResult<EquipAlarmProcessRecord>> QueryEquipAlarmProcessPage(QueryAlarmReq req)
{
int totalCount = 0;
int reqTypeCode = req.TypeCode;
var equipCode = req.EquipCode;
List<EquipAlarmProcessRecord> list = ProcessRecordRepository.Queryable().WhereIF(reqTypeCode != -1, it => it.EquipTypeCode == reqTypeCode)
.WhereIF(ObjUtils.IsNotNullOrWhiteSpace(equipCode), it => it.EquipCode == equipCode)
.ToPageList(req.PageNum, req.PageSize, ref totalCount);
PageResult<EquipAlarmProcessRecord> result = new PageResult<EquipAlarmProcessRecord>()
{
PageNum = req.PageNum,
PageSize = req.PageSize,
ToTal = totalCount,
Rows = list
};
return Result<PageResult<EquipAlarmProcessRecord>>.Success(result);
}
/// <summary>
/// 导出已处理报警日志 🔖
/// </summary>
/// <returns></returns>
public async Task<IActionResult> ExportEquipAlarmProcessRecord()
{
List<EquipAlarmProcessRecord> equipAlarmProcessRecords = await ProcessRecordRepository.QueryAsync();
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<EquipAlarmProcessRecordDto, EquipAlarmProcessRecord>().ReverseMap();
});
IMapper mapper = config.CreateMapper();
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" };
}
7 months ago
}