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.

208 lines
7.8 KiB

using AutoMapper;
using Entity.Ammeter;
using Entity.Api.Resp;
6 months ago
using HybirdFrameworkCore.Entity;
using Microsoft.AspNetCore.Mvc;
using Service.Ammeter;
using Service.Station;
6 months ago
namespace WebStarter.Controllers.Ammeter
{
/// <summary>
/// 查询电表信息
/// </summary>
6 months ago
[ApiController]
[Route("api/[controller]")]
public class AmmeterController : ControllerBase
6 months ago
{
private EmeterDayEnergyService _emeterDayEnergyService;
private EmeterHourEnergyService _emeterHourEnergyService;
private EmeterMinutesEnergyService _emeterMinutesEnergyService;
private EquipInfoService _equipInfoService;
/// <summary>
/// 直流电
/// </summary>
private EmeterEnergyService _emeterEnergyService;
private EmeterEnergyChangeService _emeterEnergyChangeService;
/// <summary>
/// 查询电表信息
/// </summary>
/// <param name="emeterDayEnergyService"></param>
/// <param name="emeterHourEnergyService"></param>
/// <param name="emeterMinutesEnergyService"></param>
/// <param name="emeterMinutesEnergyChangeService"></param>
/// <param name="equipInfoService"></param>
public AmmeterController(EmeterDayEnergyService emeterDayEnergyService,
EmeterHourEnergyService emeterHourEnergyService,
EmeterMinutesEnergyService emeterMinutesEnergyService,
EquipInfoService equipInfoService,
EmeterEnergyService emeterEnergyService,
EmeterEnergyChangeService emeterEnergyChangeService)
6 months ago
{
_emeterDayEnergyService = emeterDayEnergyService;
_emeterHourEnergyService = emeterHourEnergyService;
_emeterMinutesEnergyService = emeterMinutesEnergyService;
_equipInfoService = equipInfoService;
_emeterEnergyService = emeterEnergyService;
_emeterEnergyChangeService = emeterEnergyChangeService;
6 months ago
}
/// <summary>
/// 七天电表用量
/// </summary>
/// <param name="Code"></param>
/// <returns></returns>
[HttpGet("SevenDaysElectrical")]
public async Task<Result<EmeterEnergyResp>> SevenDaysElectrical()
{
// 获取直流和交流表数据
List<EmeterEnergy> sevenDaysElectrical = await _emeterEnergyService.SevenDaysElectrical();
List<EmeterEnergyChange> emeterEnergyChanges = await _emeterEnergyChangeService.SevenDaysElectrical();
EmeterEnergyResp resp = new EmeterEnergyResp();
5 months ago
ChargeAssignment(sevenDaysElectrical, emeterEnergyChanges, resp);
6 months ago
return Result<EmeterEnergyResp>.Success(resp, "成功");
}
/// <summary>
5 months ago
/// 30天累计能耗
/// </summary>
/// <returns></returns>
[HttpGet("GetAllElectricalData")]
5 months ago
public async Task<Result<EmeterEnergyResp>> GetAllElectricalData()
{
5 months ago
List<EmeterEnergy> emeterEnergy = await _emeterEnergyService.GetAllElectricalData();
List<EmeterEnergyChange> emeterEnergyChanges = await _emeterEnergyChangeService.GetAllElectricalData();
5 months ago
EmeterEnergyResp resp = new EmeterEnergyResp();
ChargeAssignment(emeterEnergy, emeterEnergyChanges, resp);
return Result<EmeterEnergyResp>.Success(resp, "成功");
}
5 months ago
/// <summary>
5 months ago
/// 最近一天电表数据
/// </summary>
/// <returns></returns>
5 months ago
[HttpGet("GetLastDayMeterData")]
public async Task<Result<EmeterEnergyResp>> GetLastDayMeterData()
{
5 months ago
// 获取最近一天直流和交流表数据
List<EmeterEnergy> daysElectrical = await _emeterEnergyService.GetTodayHourlyElectricalData();
List<EmeterEnergyChange> daysElectricalChange =
await _emeterEnergyChangeService.GetTodayHourlyElectricalData();
5 months ago
EmeterEnergyResp resp = new EmeterEnergyResp();
ChargeAssignment(daysElectrical, daysElectricalChange, resp);
return Result<EmeterEnergyResp>.Success(resp, "成功");
}
/// <summary>
/// 直流电能表小时统计
/// </summary>
/// <returns></returns>
[HttpGet("GetTodayHourlyEnergy")]
public async Task<Result<List<EmeterEnergy>>> GetTodayHourlyElectricalData()
{
// 直流表数据
return Result<List<EmeterEnergy>>.Success(await _emeterEnergyService.GetTodayHourlyElectricalData(), "成功");
}
/// <summary>
/// 交流电能表小时统计
/// </summary>
/// <returns></returns>
[HttpGet("GetTodayHourlyEnergyChange")]
public async Task<Result<List<EmeterEnergyChange>>> GetTodayHourlyElectricalChangeData()
{
// 交流表数据
return Result<List<EmeterEnergyChange>>.Success(
await _emeterEnergyChangeService.GetTodayHourlyElectricalData(), "成功");
}
/// <summary>
/// 最近一小时电表数据
/// </summary>
/// <returns></returns>
[HttpGet("GetTodayMinutelyElectricalData")]
public async Task<Result<EmeterEnergyResp>> GetTodayMinutelyElectricalData()
{
// 获取最近一个小时直流和交流表数据
5 months ago
List<EmeterEnergy> minutesElectrical = await _emeterEnergyService.GetTodayMinutelyElectricalData();
List<EmeterEnergyChange> minutesElectricalChange =
await _emeterEnergyChangeService.GetTodayMinutelyElectricalData();
EmeterEnergyResp resp = new EmeterEnergyResp();
5 months ago
ChargeAssignment(minutesElectrical, minutesElectricalChange, resp);
return Result<EmeterEnergyResp>.Success(resp, "成功");
}
/// <summary>
/// 获取直流交流电表实时数据
/// </summary>
/// <returns></returns>
[HttpGet("GetEnergyMeterRealTime")]
5 months ago
public async Task<Result<EmeterEnergyResp>> GetEnergyMeterRealTime(string endTime)
{
5 months ago
// 不传值时查实时
if (!DateTime.TryParse(endTime, out DateTime parsedEndTime))
{
parsedEndTime = DateTime.Now;
}
5 months ago
endTime = parsedEndTime.ToString("yyyy-MM-dd HH:mm:ss");
// 获取实时直流和交流表数据
5 months ago
List<EmeterEnergy> minutesElectrical = await _emeterEnergyService.GetEnergyMeterRealTime(endTime);
List<EmeterEnergyChange> minutesElectricalChange =
await _emeterEnergyChangeService.GetEnergyMeterRealTime(endTime);
EmeterEnergyResp resp = new EmeterEnergyResp();
ChargeAssignment(minutesElectrical, minutesElectricalChange, resp);
5 months ago
return Result<EmeterEnergyResp>.Success(resp, "成功");
5 months ago
}
private static void ChargeAssignment(List<EmeterEnergy> emeterEnergy,
List<EmeterEnergyChange> emeterEnergyChanges, EmeterEnergyResp resp)
5 months ago
{
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<EmeterResp, EmeterEnergy>().ReverseMap();
cfg.CreateMap<EmeterResp, EmeterEnergyChange>().ReverseMap();
});
IMapper mapper = config.CreateMapper();
5 months ago
List<EmeterResp> EnergyList = mapper.Map<List<EmeterResp>>(emeterEnergy);
// 类型赋值直流
EnergyList?.ForEach(emeterResp => emeterResp.Type = 0);
5 months ago
List<EmeterResp> EnergyChangeList = mapper.Map<List<EmeterResp>>(emeterEnergyChanges);
// 类型赋值交流
EnergyChangeList?.ForEach(emeterResp => emeterResp.Type = 1);
resp.emeterEnergy = EnergyList.OrderBy(i => i.Code).ToList();
resp.emeterEnergyChange = EnergyChangeList.OrderBy(i => i.Code).ToList();
}
6 months ago
}
}