using AutoMapper;
using Entity.Ammeter;
using Entity.Api.Resp;
using Entity.Dto.Req;
using HybirdFrameworkCore.Entity;
using Microsoft.AspNetCore.Mvc;
using Service.Ammeter;
using Service.Station;
using SqlSugar;
namespace WebStarter.Controllers.Ammeter
{
///
/// 查询电表信息
///
[ApiController]
[Route("api/[controller]")]
public class AmmeterController : ControllerBase
{
private EmeterDayEnergyService _emeterDayEnergyService;
private EmeterHourEnergyService _emeterHourEnergyService;
private EmeterMinutesEnergyService _emeterMinutesEnergyService;
private EmeterMinutesEnergyChangeService _emeterMinutesEnergyChangeService;
private EquipInfoService _equipInfoService;
///
/// 直流电
///
private EmeterEnergyService _emeterEnergyService;
private EmeterEnergyChangeService _emeterEnergyChangeService;
///
/// 查询电表信息
///
///
///
///
///
///
public AmmeterController(EmeterDayEnergyService emeterDayEnergyService, EmeterHourEnergyService emeterHourEnergyService,
EmeterMinutesEnergyService emeterMinutesEnergyService, EmeterMinutesEnergyChangeService emeterMinutesEnergyChangeService,
EquipInfoService equipInfoService,
EmeterEnergyService emeterEnergyService,
EmeterEnergyChangeService emeterEnergyChangeService)
{
_emeterDayEnergyService = emeterDayEnergyService;
_emeterHourEnergyService = emeterHourEnergyService;
_emeterMinutesEnergyService = emeterMinutesEnergyService;
_emeterMinutesEnergyChangeService = emeterMinutesEnergyChangeService;
_equipInfoService = equipInfoService;
_emeterEnergyService = emeterEnergyService;
_emeterEnergyChangeService = emeterEnergyChangeService;
}
///
/// 七天电表用量
///
///
///
[HttpGet("SevenDaysElectrical")]
public async Task> SevenDaysElectrical()
{
EmeterEnergyResp resp = new EmeterEnergyResp();
// 获取直流和交流表数据
List sevenDaysElectrical = await _emeterEnergyService.SevenDaysElectrical();
List emeterEnergyChanges = await _emeterEnergyChangeService.SevenDaysElectrical();
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap().ReverseMap();
cfg.CreateMap().ReverseMap();
});
IMapper mapper = config.CreateMapper();
List emeterEnergyList = mapper.Map>(sevenDaysElectrical);
List sevenEmeterResps = mapper.Map>(emeterEnergyChanges);
resp.emeterEnergy = emeterEnergyList;
resp.emeterEnergyChange = sevenEmeterResps;
return Result.Success(resp,"成功");
}
#region 统计分析/电能表累计值信息
///
/// 直流电能表累计值
///
///
[HttpGet("GetAllElectricalData")]
public async Task>> GetAllElectricalData()
{
// 直流表数据
return Result>.Success(await _emeterEnergyService.GetAllElectricalData(),"成功");
}
///
/// 交流电能表累计值
///
///
[HttpGet("GetAllEmeterEnergyChange")]
public async Task>> GetAllEmeterEnergyChange()
{
// 交流表数据
return Result>.Success(await _emeterEnergyChangeService.GetAllElectricalData(),"成功");
}
///
/// 直流电能表小时统计
///
///
[HttpGet("GetTodayHourlyEnergy")]
public async Task>> GetTodayHourlyElectricalData()
{
// 直流表数据
return Result>.Success(await _emeterEnergyService.GetTodayHourlyElectricalData(),"成功");
}
///
/// 交流电能表小时统计
///
///
[HttpGet("GetTodayHourlyEnergyChange")]
public async Task>> GetTodayHourlyElectricalChangeData()
{
// 交流表数据
return Result>.Success(await _emeterEnergyChangeService.GetTodayHourlyElectricalData(),"成功");
}
///
/// 统计分析/电能表累计值信息
///
[HttpGet("TEgEmeterTotalEnergyValue/{Code}")]
public async Task>> GetNewEmeterMinutesEnergy(string Code)
{
var query = @"
SELECT t1.*
FROM
(
SELECT code, MAX(time) AS latest_time
FROM emeter_minutes_energy
WHERE code = @Code
GROUP BY code
) AS latest_records
JOIN emeter_minutes_energy t1
ON latest_records.code = t1.code
AND latest_records.latest_time = t1.time;";
var parameters = new List
{
new SugarParameter("@Code", Code)
};
var result = await Task.Run(() => _emeterMinutesEnergyService.SqlQuery(query, parameters));
return Result>.Success(result);
}
///
/// 删除电能表累计值信息
///
[HttpGet("delete/TEgEmeterTotalEnergyValue/{id}")]
public Result DeleteOneEmeterMinutesEnergy(long id)
{
return Result.Success(_emeterMinutesEnergyService.DeleteById(id));
}
///
/// 删除电能表累计值信息
///
[HttpPost("TEgEmeterTotalEnergyValue/BatchDelete")]
public Result DeleteMoreEmeterMinutesEnergy(int[] ids)
{
return Result.Success(_emeterMinutesEnergyService.DeleteByIds(ids));
}
#endregion
#region 统计分析/电能表变化值信息
///
/// 统计分析/电能表变化值信息
///
[HttpPost("TEgEmeterRealEnergyValue")]
public async Task>> GetEmeterMinutesEnergyChange([FromBody] PageAmmeterReq queryPageModel)
{
return Result>.Success(await _emeterMinutesEnergyChangeService.Page(queryPageModel));
}
///
/// 删除电能表变化值信息
///
[HttpGet("TEgEmeterRealEnergyValue/{id}")]
public Result DeleteEmeterMinutesEnergyChange(long id)
{
return Result.Success(_emeterMinutesEnergyChangeService.DeleteById(id));
}
///
/// 批量删除电能表变化值信息
///
[HttpPost("TEgEmeterRealEnergyValue/BatchDelete")]
public Result DeleteEmeterMinutesEnergyChange(int[] ids)
{
return Result.Success(_emeterMinutesEnergyChangeService.DeleteByIds(ids));
}
#endregion
#region 统计分析/电能表小时能耗值
///
/// 统计分析/电能表小时能耗值
///
[HttpPost("TEgEmeterHourEnergyValue")]
public async Task>> GetEmeterHourEnergy([FromBody] PageAmmeterReq queryPageModel)
{
return await _emeterHourEnergyService.Page(queryPageModel);
}
///
/// 删除电能表小时能耗值
///
[HttpGet("TEgEmeterHourEnergyValue/{id}")]
public Result DeleteEmeterHourEnergy(long id)
{
return Result.Success(_emeterHourEnergyService.DeleteById(id));
}
///
/// 批量删除电能表小时能耗值
///
[HttpPost("TEgEmeterHourEnergyValue/BatchDelete")]
public Result DeleteListEmeterHourEnergy(int[] ids)
{
return Result.Success(_emeterHourEnergyService.DeleteByIds(ids));
}
#endregion
#region 统计分析/电能表每天能耗值
///
/// 统计分析/电能表每天能耗值
///
[HttpPost("TEgEmeterDayEnergyValue")]
public async Task>> GetEmeterDayEnergy([FromBody] PageAmmeterReq queryPageModel)
{
return Result>.Success(await _emeterDayEnergyService.Page(queryPageModel));
}
///
/// 删除电能表每天能耗值
///
[HttpGet("TEgEmeterDayEnergyValue/{id}")]
public Result DeleteEmeterDayEnergy(long id)
{
return Result.Success(_emeterDayEnergyService.DeleteById(id));
}
///
/// 批量删除电能表每天能耗值
///
[HttpPost("TEgEmeterDayEnergyValue/BatchDelete")]
public Result DeleteListEmeterDayEnergy(int[] ids)
{
return Result.Success(_emeterDayEnergyService.DeleteByIds(ids));
}
#endregion
#region 统计分析/换电站分时用电统计信息
//TODO::
//小时计算总能耗值,小时计算充电能耗值,小时计算换电能耗值,小时计算其他能耗值,开始时间,结束时间
#endregion
#region 统计分析/换电站每天用电统计信息
//TODO::
//每天计算总能耗值,每天计算充电能耗值,每天计算换电能耗值,每天计算其他能耗值,开始时间,结束时间
#endregion
#region 电能监控/交流电能监控
///
/// 电能监控/交流电能监控
///
[HttpGet("ElecMeterParam/GetElecMeterParamValue")]
public Result> GetElecMeterParamValue()
{
var EquipInfo = _equipInfoService.QueryListByClause(i => i.TypeCode == 0);
List strings = new List();
foreach (var kvp in EquipInfo)
{
strings.Add(kvp.Code);
}
//TODO::过滤,确保编码相同只出现一次
return Result>.Success(_emeterMinutesEnergyService.QueryListByClause(i => strings.Contains(i.Code)).ToList());
}
#endregion
#region 电能监控/直流电能监控
///
/// 电能监控/直流电能监控
///
[HttpGet("ManualSwap/GetDcCurrentInfo")]
public Result> GetDcCurrentInfo()
{
var EquipInfo = _equipInfoService.QueryListByClause(i => i.TypeCode == 1);
List strings = new List();
foreach (var kvp in EquipInfo)
{
strings.Add(kvp.Code);
}
//TODO::过滤,确保编码相同只出现一次
return Result>.Success(_emeterMinutesEnergyService.QueryListByClause(i => strings.Contains(i.Code)).ToList());
}
#endregion
}
}