|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询电表信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
public class AmmeterController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private EmeterDayEnergyService _emeterDayEnergyService;
|
|
|
|
|
private EmeterHourEnergyService _emeterHourEnergyService;
|
|
|
|
|
private EmeterMinutesEnergyService _emeterMinutesEnergyService;
|
|
|
|
|
private EmeterMinutesEnergyChangeService _emeterMinutesEnergyChangeService;
|
|
|
|
|
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, EmeterMinutesEnergyChangeService emeterMinutesEnergyChangeService,
|
|
|
|
|
EquipInfoService equipInfoService,
|
|
|
|
|
EmeterEnergyService emeterEnergyService,
|
|
|
|
|
EmeterEnergyChangeService emeterEnergyChangeService)
|
|
|
|
|
{
|
|
|
|
|
_emeterDayEnergyService = emeterDayEnergyService;
|
|
|
|
|
_emeterHourEnergyService = emeterHourEnergyService;
|
|
|
|
|
_emeterMinutesEnergyService = emeterMinutesEnergyService;
|
|
|
|
|
_emeterMinutesEnergyChangeService = emeterMinutesEnergyChangeService;
|
|
|
|
|
_equipInfoService = equipInfoService;
|
|
|
|
|
_emeterEnergyService = emeterEnergyService;
|
|
|
|
|
_emeterEnergyChangeService = emeterEnergyChangeService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ChargeAssignment(sevenDaysElectrical, emeterEnergyChanges, resp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Result<EmeterEnergyResp>.Success(resp,"成功");
|
|
|
|
|
}
|
|
|
|
|
#region 统计分析/电能表累计值信息
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 30天累计能耗
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("GetAllElectricalData")]
|
|
|
|
|
public async Task<Result<EmeterEnergyResp>> GetAllElectricalData()
|
|
|
|
|
{
|
|
|
|
|
List<EmeterEnergy> emeterEnergy = await _emeterEnergyService.GetAllElectricalData();
|
|
|
|
|
List<EmeterEnergyChange> emeterEnergyChanges = await _emeterEnergyChangeService.GetAllElectricalData();
|
|
|
|
|
|
|
|
|
|
EmeterEnergyResp resp = new EmeterEnergyResp();
|
|
|
|
|
|
|
|
|
|
ChargeAssignment(emeterEnergy, emeterEnergyChanges, resp);
|
|
|
|
|
|
|
|
|
|
return Result<EmeterEnergyResp>.Success(resp,"成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 最近一天电表数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("GetLastDayMeterData")]
|
|
|
|
|
public async Task<Result<EmeterEnergyResp>> GetLastDayMeterData()
|
|
|
|
|
{
|
|
|
|
|
// 获取最近一天直流和交流表数据
|
|
|
|
|
List<EmeterEnergy> daysElectrical = await _emeterEnergyService.GetTodayHourlyElectricalData();
|
|
|
|
|
List<EmeterEnergyChange> daysElectricalChange = await _emeterEnergyChangeService.GetTodayHourlyElectricalData();
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
// 获取最近一个小时直流和交流表数据
|
|
|
|
|
List<EmeterEnergy> minutesElectrical = await _emeterEnergyService.GetTodayMinutelyElectricalData();
|
|
|
|
|
List<EmeterEnergyChange> minutesElectricalChange = await _emeterEnergyChangeService.GetTodayMinutelyElectricalData();
|
|
|
|
|
|
|
|
|
|
EmeterEnergyResp resp = new EmeterEnergyResp();
|
|
|
|
|
|
|
|
|
|
ChargeAssignment(minutesElectrical, minutesElectricalChange, resp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Result<EmeterEnergyResp>.Success(resp,"成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void ChargeAssignment(List<EmeterEnergy> emeterEnergy, List<EmeterEnergyChange> emeterEnergyChanges, EmeterEnergyResp resp)
|
|
|
|
|
{
|
|
|
|
|
var config = new MapperConfiguration(cfg =>
|
|
|
|
|
{
|
|
|
|
|
cfg.CreateMap<EmeterResp, EmeterEnergy>().ReverseMap();
|
|
|
|
|
cfg.CreateMap<EmeterResp, EmeterEnergyChange>().ReverseMap();
|
|
|
|
|
});
|
|
|
|
|
IMapper mapper = config.CreateMapper();
|
|
|
|
|
|
|
|
|
|
List<EmeterResp> EnergyList = mapper.Map<List<EmeterResp>>(emeterEnergy);
|
|
|
|
|
// 类型赋值直流
|
|
|
|
|
EnergyList?.ForEach(emeterResp => emeterResp.Type = 0);
|
|
|
|
|
|
|
|
|
|
List<EmeterResp> EnergyChangeList = mapper.Map<List<EmeterResp>>(emeterEnergyChanges);
|
|
|
|
|
// 类型赋值交流
|
|
|
|
|
EnergyChangeList?.ForEach(emeterResp => emeterResp.Type = 1);
|
|
|
|
|
|
|
|
|
|
resp.emeterEnergy = EnergyList;
|
|
|
|
|
resp.emeterEnergyChange = EnergyChangeList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 统计分析/电能表累计值信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet("TEgEmeterTotalEnergyValue/{Code}")]
|
|
|
|
|
public async Task<Result<List<EmeterMinutesEnergy>>> 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<SugarParameter>
|
|
|
|
|
{
|
|
|
|
|
new SugarParameter("@Code", Code)
|
|
|
|
|
};
|
|
|
|
|
var result = await Task.Run(() => _emeterMinutesEnergyService.SqlQuery(query, parameters));
|
|
|
|
|
|
|
|
|
|
return Result<List<EmeterMinutesEnergy>>.Success(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除电能表累计值信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet("delete/TEgEmeterTotalEnergyValue/{id}")]
|
|
|
|
|
public Result<bool> DeleteOneEmeterMinutesEnergy(long id)
|
|
|
|
|
{
|
|
|
|
|
return Result<bool>.Success(_emeterMinutesEnergyService.DeleteById(id));
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除电能表累计值信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost("TEgEmeterTotalEnergyValue/BatchDelete")]
|
|
|
|
|
public Result<bool> DeleteMoreEmeterMinutesEnergy(int[] ids)
|
|
|
|
|
{
|
|
|
|
|
return Result<bool>.Success(_emeterMinutesEnergyService.DeleteByIds(ids));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 统计分析/电能表变化值信息
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 统计分析/电能表变化值信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost("TEgEmeterRealEnergyValue")]
|
|
|
|
|
public async Task<Result<PageResult<EmeterMinutesEnergyChange>>> GetEmeterMinutesEnergyChange([FromBody] PageAmmeterReq queryPageModel)
|
|
|
|
|
{
|
|
|
|
|
return Result<PageResult<EmeterMinutesEnergyChange>>.Success(await _emeterMinutesEnergyChangeService.Page(queryPageModel));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除电能表变化值信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet("TEgEmeterRealEnergyValue/{id}")]
|
|
|
|
|
public Result<bool> DeleteEmeterMinutesEnergyChange(long id)
|
|
|
|
|
{
|
|
|
|
|
return Result<bool>.Success(_emeterMinutesEnergyChangeService.DeleteById(id));
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 批量删除电能表变化值信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost("TEgEmeterRealEnergyValue/BatchDelete")]
|
|
|
|
|
public Result<bool> DeleteEmeterMinutesEnergyChange(int[] ids)
|
|
|
|
|
{
|
|
|
|
|
return Result<bool>.Success(_emeterMinutesEnergyChangeService.DeleteByIds(ids));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 统计分析/电能表小时能耗值
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 统计分析/电能表小时能耗值
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost("TEgEmeterHourEnergyValue")]
|
|
|
|
|
public async Task<Result<PageResult<EmeterHourEnergy>>> GetEmeterHourEnergy([FromBody] PageAmmeterReq queryPageModel)
|
|
|
|
|
{
|
|
|
|
|
return await _emeterHourEnergyService.Page(queryPageModel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除电能表小时能耗值
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet("TEgEmeterHourEnergyValue/{id}")]
|
|
|
|
|
public Result<bool> DeleteEmeterHourEnergy(long id)
|
|
|
|
|
{
|
|
|
|
|
return Result<bool>.Success(_emeterHourEnergyService.DeleteById(id));
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 批量删除电能表小时能耗值
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost("TEgEmeterHourEnergyValue/BatchDelete")]
|
|
|
|
|
public Result<bool> DeleteListEmeterHourEnergy(int[] ids)
|
|
|
|
|
{
|
|
|
|
|
return Result<bool>.Success(_emeterHourEnergyService.DeleteByIds(ids));
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 统计分析/电能表每天能耗值
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 统计分析/电能表每天能耗值
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost("TEgEmeterDayEnergyValue")]
|
|
|
|
|
public async Task<Result<PageResult<EmeterDayEnergy>>> GetEmeterDayEnergy([FromBody] PageAmmeterReq queryPageModel)
|
|
|
|
|
{
|
|
|
|
|
return Result<PageResult<EmeterDayEnergy>>.Success(await _emeterDayEnergyService.Page(queryPageModel));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除电能表每天能耗值
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet("TEgEmeterDayEnergyValue/{id}")]
|
|
|
|
|
public Result<bool> DeleteEmeterDayEnergy(long id)
|
|
|
|
|
{
|
|
|
|
|
return Result<bool>.Success(_emeterDayEnergyService.DeleteById(id));
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 批量删除电能表每天能耗值
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost("TEgEmeterDayEnergyValue/BatchDelete")]
|
|
|
|
|
public Result<bool> DeleteListEmeterDayEnergy(int[] ids)
|
|
|
|
|
{
|
|
|
|
|
return Result<bool>.Success(_emeterDayEnergyService.DeleteByIds(ids));
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 统计分析/换电站分时用电统计信息
|
|
|
|
|
//TODO::
|
|
|
|
|
//小时计算总能耗值,小时计算充电能耗值,小时计算换电能耗值,小时计算其他能耗值,开始时间,结束时间
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 统计分析/换电站每天用电统计信息
|
|
|
|
|
//TODO::
|
|
|
|
|
//每天计算总能耗值,每天计算充电能耗值,每天计算换电能耗值,每天计算其他能耗值,开始时间,结束时间
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 电能监控/交流电能监控
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 电能监控/交流电能监控
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet("ElecMeterParam/GetElecMeterParamValue")]
|
|
|
|
|
public Result<List<EmeterMinutesEnergy>> GetElecMeterParamValue()
|
|
|
|
|
{
|
|
|
|
|
var EquipInfo = _equipInfoService.QueryListByClause(i => i.TypeCode == 0);
|
|
|
|
|
List<string> strings = new List<string>();
|
|
|
|
|
foreach (var kvp in EquipInfo)
|
|
|
|
|
{
|
|
|
|
|
strings.Add(kvp.Code);
|
|
|
|
|
}
|
|
|
|
|
//TODO::过滤,确保编码相同只出现一次
|
|
|
|
|
return Result<List<EmeterMinutesEnergy>>.Success(_emeterMinutesEnergyService.QueryListByClause(i => strings.Contains(i.Code)).ToList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 电能监控/直流电能监控
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 电能监控/直流电能监控
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet("ManualSwap/GetDcCurrentInfo")]
|
|
|
|
|
public Result<List<EmeterMinutesEnergy>> GetDcCurrentInfo()
|
|
|
|
|
{
|
|
|
|
|
var EquipInfo = _equipInfoService.QueryListByClause(i => i.TypeCode == 1);
|
|
|
|
|
List<string> strings = new List<string>();
|
|
|
|
|
foreach (var kvp in EquipInfo)
|
|
|
|
|
{
|
|
|
|
|
strings.Add(kvp.Code);
|
|
|
|
|
}
|
|
|
|
|
//TODO::过滤,确保编码相同只出现一次
|
|
|
|
|
return Result<List<EmeterMinutesEnergy>>.Success(_emeterMinutesEnergyService.QueryListByClause(i => strings.Contains(i.Code)).ToList());
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|