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.

52 lines
1.7 KiB

using Entity.Ammeter;
using Entity.Dto.Req;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Entity;
using Repository.Ammeter;
using SqlSugar;
namespace Service.Ammeter
{
/// <summary>
///
/// </summary>
[Scope("SingleInstance")]
public class EmeterDayEnergyService : BaseServices<EmeterDayEnergy>
{
public EmeterDayEnergyService(EmeterDayEnergyRepository service)
{
this.BaseDal = service;
}
public async Task<PageResult<EmeterDayEnergy>> Page(PageAmmeterReq queryPageModel)
{
QueryPageModel queryPageModel1 = new QueryPageModel
{
PageNum = queryPageModel.PageNum,
PageSize = queryPageModel.PageSize,
};
if (!string.IsNullOrEmpty(queryPageModel.Code))
return PageResult<EmeterDayEnergy>.ConvertPage(this.BaseDal.QueryIPageByCause(queryPageModel1, u => u.Code == queryPageModel.Code));
else
return PageResult<EmeterDayEnergy>.ConvertPage(this.BaseDal.QueryIPageByCause(queryPageModel1, null));
}
/// <summary>
/// 七天电能统计
/// </summary>
/// <returns></returns>
public async Task<List<EmeterDayEnergy>> SevenDaysElectricalEnergy()
{
DateTime sevenDaysAgo = DateTime.Today.AddDays(-7);
List<EmeterDayEnergy> result = this.BaseDal.Queryable()
.Where(e => e.St >= sevenDaysAgo)
.GroupBy(e => e.Code)
.Select(e => new EmeterDayEnergy
{
Code = e.Code,
Value = SqlFunc.AggregateSum(e.Value)
}).ToList();
return result;
}
}
}