增加导出,电表统计优化

zw
tq 5 months ago
parent 7e2dd76bf3
commit ccbe64bcce

@ -35,5 +35,12 @@ public class EmeterEnergy
[SugarColumn(ColumnName = "upload_flag")]
public virtual string UploadFlag { get; set; }
/// <summary>
/// 统计sql小时接收
/// </summary>
[SugarColumn(IsIgnore = true)] public virtual string Hour { get; set; }
/// <summary>
/// 统计sql分钟接收
/// </summary>
[SugarColumn(IsIgnore = true)] public virtual string Minute { get; set; }
}

@ -36,4 +36,8 @@ public class EmeterEnergyChange
public virtual int UploadFlag { get; set; }
[SugarColumn(IsIgnore = true)] public virtual string Hour { get; set; }
/// <summary>
/// 统计sql分钟接收
/// </summary>
[SugarColumn(IsIgnore = true)] public virtual string Minute { get; set; }
}

@ -13,5 +13,14 @@ public class EmeterResp
public float Value { get; set; }
public DateTime UploadTime { get; set; }
/// <summary>
/// 小时时间
/// </summary>
public string Hour { get; set; }
/// <summary>
///分钟时间
/// </summary>
public string Minute { get; set; }
}

@ -0,0 +1,64 @@
using Magicodes.ExporterAndImporter.Core;
using Magicodes.ExporterAndImporter.Excel;
namespace Entity.Dto;
[ExcelExporter(Name = "已处理报警日志", TableStyle = OfficeOpenXml.Table.TableStyles.None, AutoFitAllColumn = true)]
public class EquipAlarmProcessRecordDto
{
/// <summary>
/// Desc:设备类型编码
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "设备类型编码", IsBold = true)]
public int EquipTypeCode { get; set; }
/// <summary>
/// Desc:设备编码
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "设备编码", IsBold = true)]
public string EquipCode { get; set; }
/// <summary>
/// Desc:报警编码
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "报警编码", IsBold = true)]
public string ErrorCode { get; set; }
/// <summary>
/// Desc:报警等级
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "报警等级", IsBold = true)]
public string ErrorLevel { get; set; }
/// <summary>
/// Desc:报警描述
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "报警描述", IsBold = true)]
public string ErrorMsg { get; set; }
/// <summary>
/// Desc:处理方法
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "处理方法", IsBold = true)]
public string ProcessMethod { get; set; }
/// <summary>
/// Desc:处理时间
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "处理时间", IsBold = true,Width = 30, Format = "yyyy-MM-dd HH:mm:ss", AutoCenterColumn = true)]
public DateTime? ProcessTime { get; set; }
}

@ -0,0 +1,56 @@
using Magicodes.ExporterAndImporter.Core;
using Magicodes.ExporterAndImporter.Excel;
namespace Entity.Dto;
[ExcelExporter(Name = "未处理报警日志", TableStyle = OfficeOpenXml.Table.TableStyles.None, AutoFitAllColumn = true)]
public class EquipAlarmRecordDto
{
/// <summary>
/// Desc:设备类型编码
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "设备类型编码", IsBold = true)]
public int EquipTypeCode { get; set; }
/// <summary>
/// Desc:设备编码
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "设备编码", IsBold = true)]
public string EquipCode { get; set; }
/// <summary>
/// Desc:报警编码
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "报警编码", IsBold = true)]
public string ErrorCode { get; set; }
/// <summary>
/// Desc:报警等级
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "报警等级", IsBold = true)]
public string ErrorLevel { get; set; }
/// <summary>
/// Desc:报警描述
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "报警描述", IsBold = true)]
public string ErrorMsg { get; set; }
/// <summary>
/// Desc:处理方法
/// Default:
/// Nullable:True
/// </summary>
[ExporterHeader(DisplayName = "处理方法", IsBold = true)]
public string ProcessMethod { get; set; }
}

@ -0,0 +1,100 @@
using Magicodes.ExporterAndImporter.Core;
using Magicodes.ExporterAndImporter.Excel;
namespace Entity.Dto;
[ExcelExporter(Name = "换电站日运行统计结果", TableStyle = OfficeOpenXml.Table.TableStyles.None, AutoFitAllColumn = true)]
public class ExchangeStationDayRunDto
{
/// <summary>
/// 平均充电时长
/// </summary>
[ExporterHeader(DisplayName = "平均充电时长", IsBold = true)]
public string AvgChgTime { get; set; }
/// <summary>
/// 平均换电时长
/// </summary>
[ExporterHeader(DisplayName = "平均换电时长", IsBold = true)]
public string AvgRepTime { get; set; }
/// <summary>
/// 换电日期
/// </summary>
[ExporterHeader(DisplayName = "换电日期", IsBold = true,Width = 30, Format = "yyyy-MM-dd HH:mm:ss", AutoCenterColumn = true)]
public string SwapDate { get; set; }
/// <summary>
/// 首次换电时间
/// </summary>
[ExporterHeader(DisplayName = "首次换电时间", IsBold = true,Width = 30, Format = "yyyy-MM-dd HH:mm:ss", AutoCenterColumn = true)]
public string FristSwapTime { get; set; }
/// <summary>
/// 结束换电时间
/// </summary>
[ExporterHeader(DisplayName = "结束换电时间", IsBold = true,Width = 30, Format = "yyyy-MM-dd HH:mm:ss", AutoCenterColumn = true)]
public string StopTime { get; set; }
/// <summary>
/// 运行开始时间
/// </summary>
[ExporterHeader(DisplayName = "运行开始时间", IsBold = true,Width = 30, Format = "yyyy-MM-dd HH:mm:ss", AutoCenterColumn = true)]
public string RunStartTime { get; set; }
/// <summary>
/// 运行结束时间
/// </summary>
[ExporterHeader(DisplayName = "运行结束时间", IsBold = true,Width = 30, Format = "yyyy-MM-dd HH:mm:ss", AutoCenterColumn = true)]
public string RunEndTime { get; set; }
/// <summary>
/// 充电总次数
/// </summary>
[ExporterHeader(DisplayName = "充电总次数", IsBold = true)]
public int ChgCount { get; set; }
/// <summary>
/// 运营状态1营业状态 2暂停营业状态 3设备维护状态 4歇业状态
/// </summary>
[ExporterHeader(DisplayName = "运营状态", IsBold = true)]
public string OperationalStatus
{
get
{
return State switch
{
1 => "营业状态",
2 => "暂停营业状态",
3 => "设备维护状态",
4 => "歇业状态",
_ => "未知"
};
}
}
/// <summary>
/// 运营状态
/// </summary>
[ExporterHeader(IsIgnore = true)]
public int State { get; set; }
/// <summary>
/// 换电总次数
/// </summary>
[ExporterHeader(DisplayName = "换电总次数", IsBold = true)]
public int ToltalSwapCount { get; set; }
/// <summary>
/// 换电总时长
/// </summary>
[ExporterHeader(DisplayName = "换电总时长", IsBold = true)]
public float ToltalSwapAllTime { get; set; }
/// <summary>
/// 站运行总时长
/// </summary>
[ExporterHeader(DisplayName = "站运行总时长", IsBold = true)]
public float ToltalTimeCount { get; set; }
}

@ -23,7 +23,8 @@ public class EmeterEnergyChangeService : BaseServices<EmeterEnergyChange>
`code`,
DATE(`upload_time`) AS `UploadTime`,
MAX(`value`) AS `MaxValue`,
MIN(`value`) AS `MinValue`
MIN(`value`) AS `MinValue`,
COUNT(*) AS `Count`
FROM
`emeter_energy_change`
WHERE
@ -34,25 +35,36 @@ public class EmeterEnergyChangeService : BaseServices<EmeterEnergyChange>
SELECT
`code`,
`UploadTime`,
`MaxValue`,
`MinValue`,
`Count`,
LAG(`MaxValue`) OVER (PARTITION BY `code` ORDER BY `UploadTime`) AS `PreviousMaxValue`
FROM
daily_max_min
)
), daily_consumption AS (
SELECT
d.`code`,
d.`UploadTime`,
CASE
WHEN d.`MaxValue` = d.`MinValue` THEN COALESCE(d.`MaxValue` - p.`PreviousMaxValue`, d.`MaxValue`)
WHEN d.`Count` = 1 THEN d.`MaxValue` - d.`PreviousMaxValue`
ELSE d.`MaxValue` - d.`MinValue`
END AS `Value`
END AS `DailyValue`
FROM
daily_max_min d
LEFT JOIN
previous_day_max p ON d.`code` = p.`code` AND d.`UploadTime` = p.`UploadTime`
previous_day_max d
WHERE
d.`UploadTime` >= NOW() - INTERVAL 7 DAY
)
SELECT
`UploadTime`,
SUM(`DailyValue`) AS `Value`
FROM
daily_consumption
GROUP BY
`UploadTime`
ORDER BY
d.`code`, d.`UploadTime`;
`UploadTime`;
";
List<EmeterEnergyChange> emeterEnergies = await _emeterEnergyChangeRep.SqlQueryable(sql);
@ -117,4 +129,51 @@ public class EmeterEnergyChangeService : BaseServices<EmeterEnergyChange>
List<EmeterEnergyChange> emeterEnergies = await _emeterEnergyChangeRep.SqlQueryable(sql);
return emeterEnergies;
}
/// <summary>
/// 根据分钟统计电量
/// </summary>
/// <returns></returns>
public async Task<List<EmeterEnergyChange>> GetTodayMinutelyElectricalData()
{
string sql = @"
WITH minute_max_min AS (
SELECT
`code`,
DATE_FORMAT(`upload_time`, '%Y-%m-%d %H:%i:00') AS `Minute`,
MAX(`value`) AS `MaxValue`,
MIN(`value`) AS `MinValue`,
COUNT(*) AS `record_count`
FROM
`emeter_energy_change`
WHERE
`upload_time` >= NOW() - INTERVAL 1 HOUR
GROUP BY
`code`, DATE_FORMAT(`upload_time`, '%Y-%m-%d %H:%i:00')
), previous_minute_max AS (
SELECT
`code`,
`Minute`,
LAG(`MaxValue`) OVER (PARTITION BY `code` ORDER BY `Minute`) AS `PreviousMaxValue`
FROM
`minute_max_min`
)
SELECT
m.`code`,
m.`Minute`,
CASE
WHEN p.`PreviousMaxValue` IS NULL THEN 0
WHEN m.`record_count` > 1 THEN m.`MaxValue` - m.`MinValue`
ELSE m.`MaxValue` - p.`PreviousMaxValue`
END AS `Value`
FROM
`minute_max_min` m
LEFT JOIN
`previous_minute_max` p ON m.`code` = p.`code` AND m.`Minute` = p.`Minute`
ORDER BY
m.`code`, m.`Minute`;";
List<EmeterEnergyChange> emeterEnergies = await _emeterEnergyChangeRep.SqlQueryable(sql);
return emeterEnergies;
}
}

@ -27,7 +27,8 @@ public class EmeterEnergyService : BaseServices<EmeterEnergy>
`code`,
DATE(`upload_time`) AS `UploadTime`,
MAX(`value`) AS `MaxValue`,
MIN(`value`) AS `MinValue`
MIN(`value`) AS `MinValue`,
COUNT(*) AS `Count`
FROM
`emeter_energy`
WHERE
@ -38,25 +39,36 @@ public class EmeterEnergyService : BaseServices<EmeterEnergy>
SELECT
`code`,
`UploadTime`,
`MaxValue`,
`MinValue`,
`Count`,
LAG(`MaxValue`) OVER (PARTITION BY `code` ORDER BY `UploadTime`) AS `PreviousMaxValue`
FROM
daily_max_min
)
), daily_consumption AS (
SELECT
d.`code`,
d.`UploadTime`,
CASE
WHEN d.`MaxValue` = d.`MinValue` THEN COALESCE(d.`MaxValue` - p.`PreviousMaxValue`, d.`MaxValue`)
WHEN d.`Count` = 1 THEN d.`MaxValue` - d.`PreviousMaxValue`
ELSE d.`MaxValue` - d.`MinValue`
END AS `Value`
END AS `DailyValue`
FROM
daily_max_min d
LEFT JOIN
previous_day_max p ON d.`code` = p.`code` AND d.`UploadTime` = p.`UploadTime`
previous_day_max d
WHERE
d.`UploadTime` >= NOW() - INTERVAL 7 DAY
)
SELECT
`UploadTime`,
SUM(`DailyValue`) AS `Value`
FROM
daily_consumption
GROUP BY
`UploadTime`
ORDER BY
d.`code`, d.`UploadTime`;
`UploadTime`;
";
List<EmeterEnergy> emeterEnergies = await this.BaseDal.SqlQueryable(sql);
return emeterEnergies;
@ -130,4 +142,51 @@ public class EmeterEnergyService : BaseServices<EmeterEnergy>
List<EmeterEnergy> emeterEnergies = await this.BaseDal.SqlQueryable(sql);
return emeterEnergies;
}
/// <summary>
/// 根据分钟统计电量
/// </summary>
/// <returns></returns>
public async Task<List<EmeterEnergy>> GetTodayMinutelyElectricalData()
{
string sql = @"
WITH minute_max_min AS (
SELECT
`code`,
DATE_FORMAT(`upload_time`, '%Y-%m-%d %H:%i:00') AS `Minute`,
MAX(`value`) AS `MaxValue`,
MIN(`value`) AS `MinValue`,
COUNT(*) AS `record_count`
FROM
`emeter_energy`
WHERE
`upload_time` >= NOW() - INTERVAL 1 HOUR
GROUP BY
`code`, DATE_FORMAT(`upload_time`, '%Y-%m-%d %H:%i:00')
), previous_minute_max AS (
SELECT
`code`,
`Minute`,
LAG(`MaxValue`) OVER (PARTITION BY `code` ORDER BY `Minute`) AS `PreviousMaxValue`
FROM
`minute_max_min`
)
SELECT
m.`code`,
m.`Minute`,
CASE
WHEN p.`PreviousMaxValue` IS NULL THEN 0
WHEN m.`record_count` > 1 THEN m.`MaxValue` - m.`MinValue`
ELSE m.`MaxValue` - p.`PreviousMaxValue`
END AS `Value`
FROM
`minute_max_min` m
LEFT JOIN
`previous_minute_max` p ON m.`code` = p.`code` AND m.`Minute` = p.`Minute`
ORDER BY
m.`code`, m.`Minute`;";
List<EmeterEnergy> emeterEnergies = await this.BaseDal.SqlQueryable(sql);
return emeterEnergies;
}
}

@ -1,8 +1,12 @@
using AutoMapper;
using Entity.Api.Req;
using Entity.DbModel.Station;
using Entity.Dto;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Entity;
using HybirdFrameworkCore.Utils;
using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.Mvc;
using Repository.Station;
namespace Service.Station;
@ -42,6 +46,31 @@ public class EquipAlarmRecordService : BaseServices<EquipAlarmRecord>
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" };
}
/// <summary>
/// 查询已处理报警列表
/// </summary>
@ -68,4 +97,29 @@ public class EquipAlarmRecordService : BaseServices<EquipAlarmRecord>
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" };
}
}

@ -12,6 +12,10 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using Entity.Dto;
using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.Mvc;
namespace Service.Station
{
@ -54,5 +58,31 @@ namespace Service.Station
return await _exStationDayRunResultRepository.DeleteByIdsAsync(ids);
}
/// <summary>
/// 导出换电站日运行统计结果 🔖
/// </summary>
/// <returns></returns>
public async Task<IActionResult> ExportExchangeStationDayRunResult()
{
List<ExchangeStationDayRunResult> exchangeStationDayRunResults = await _exStationDayRunResultRepository.QueryAsync();
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<ExchangeStationDayRunDto, ExchangeStationDayRunResult>().ReverseMap();
});
IMapper mapper = config.CreateMapper();
List<ExchangeStationDayRunDto> logExList = mapper.Map<List<ExchangeStationDayRunDto>>(exchangeStationDayRunResults);
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" };
}
}
}

@ -58,11 +58,12 @@ namespace WebStarter.Controllers.Ammeter
[HttpGet("SevenDaysElectrical")]
public async Task<Result<EmeterEnergyResp>> SevenDaysElectrical()
{
EmeterEnergyResp resp = new EmeterEnergyResp();
// 获取直流和交流表数据
List<EmeterEnergy> sevenDaysElectrical = await _emeterEnergyService.SevenDaysElectrical();
List<EmeterEnergyChange> emeterEnergyChanges = await _emeterEnergyChangeService.SevenDaysElectrical();
EmeterEnergyResp resp = new EmeterEnergyResp();
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<EmeterResp, EmeterEnergy>().ReverseMap();
@ -125,7 +126,34 @@ namespace WebStarter.Controllers.Ammeter
return Result<List<EmeterEnergyChange>>.Success(await _emeterEnergyChangeService.GetTodayHourlyElectricalData(),"成功");
}
/// <summary>
/// 最近一小时电表数据
/// </summary>
/// <returns></returns>
[HttpGet("GetTodayMinutelyElectricalData")]
public async Task<Result<EmeterEnergyResp>> GetTodayMinutelyElectricalData()
{
// 获取最近一个小时直流和交流表数据
List<EmeterEnergy> sevenDaysElectrical = await _emeterEnergyService.GetTodayMinutelyElectricalData();
List<EmeterEnergyChange> emeterEnergyChanges = await _emeterEnergyChangeService.GetTodayMinutelyElectricalData();
EmeterEnergyResp resp = new EmeterEnergyResp();
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<EmeterResp, EmeterEnergy>().ReverseMap();
cfg.CreateMap<EmeterResp, EmeterEnergyChange>().ReverseMap();
});
IMapper mapper = config.CreateMapper();
List<EmeterResp> emeterEnergyList = mapper.Map<List<EmeterResp>>(sevenDaysElectrical);
List<EmeterResp> sevenEmeterResps = mapper.Map<List<EmeterResp>>(emeterEnergyChanges);
resp.emeterEnergy = emeterEnergyList;
resp.emeterEnergyChange = sevenEmeterResps;
return Result<EmeterEnergyResp>.Success(resp,"成功");
}
/// <summary>
/// 统计分析/电能表累计值信息

@ -32,6 +32,20 @@ public class EquipAlarmRecordController : ControllerBase
return equipAlarmRecordService.QueryEquipAlarmPage(req);
}
/// <summary>
/// 导出未处理报警
/// </summary>
/// <returns></returns>
[HttpPost]
[Route("ExportEquipAlarmRecord")]
public async Task<IActionResult> ExportEquipAlarmRecord()
{
return await equipAlarmRecordService.ExportEquipAlarmRecord();
}
/// <summary>
/// 查询已处理报警列表
/// </summary>
@ -43,4 +57,15 @@ public class EquipAlarmRecordController : ControllerBase
{
return equipAlarmRecordService.QueryEquipAlarmProcessPage(req);
}
/// <summary>
/// 导出已处理报警
/// </summary>
/// <returns></returns>
[HttpPost]
[Route("ExportEquipAlarmProcessRecord")]
public async Task<IActionResult> ExportEquipAlarmProcessRecord()
{
return await equipAlarmRecordService.ExportEquipAlarmProcessRecord();
}
}

@ -31,6 +31,19 @@ namespace WebStarter.Controllers
return Result<PageResult<ExchangeStationDayRunResult>>.Success(await _exStationDayRunResultService.ExStationDaySwapRunRes(queryPageModel));
}
/// <summary>
/// 导出换电站日运行统计结果
/// </summary>
/// <returns></returns>
[HttpPost]
[Route("ExportExchangeStationDayRunResult")]
public async Task<IActionResult> ExportExchangeStationDayRunResult()
{
return await _exStationDayRunResultService.ExportExchangeStationDayRunResult();
}
/// <summary>
/// 删除换电站日运行统计结果
/// </summary>

Loading…
Cancel
Save