|
|
@ -192,4 +192,184 @@ public class ChargeOrderService : BaseServices<ChargeOrder>
|
|
|
|
|
|
|
|
|
|
|
|
return QueryListByClause(predicate);
|
|
|
|
return QueryListByClause(predicate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<ChargeCountResp>> GetElectricityConsumptionByTime(ChargeCountReq req)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
List<ChargeCountResp> list = await GetElectricityConsumption(req, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
list = list.OrderBy(x => x.Time).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<PageResult<ChargeCountResp>> GetElectricityConsumptionByChargerNo(ChargeCountReq req)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
List<ChargeCountResp> resp = await GetElectricityConsumption(req, true);
|
|
|
|
|
|
|
|
resp = resp.OrderBy(x => x.Time).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int skip = (req.PageNum - 1) * req.PageSize;
|
|
|
|
|
|
|
|
int take = req.PageSize;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ChargeCountResp> respList = resp.Skip(skip).Take(take).ToList();
|
|
|
|
|
|
|
|
PageResult<ChargeCountResp> result = new PageResult<ChargeCountResp>();
|
|
|
|
|
|
|
|
result.PageNum = req.PageNum;
|
|
|
|
|
|
|
|
result.PageSize = req.PageSize;
|
|
|
|
|
|
|
|
result.Rows = respList;
|
|
|
|
|
|
|
|
result.ToTal = resp.Count;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<ChargeCountResp>> GetElectricityConsumption(ChargeCountReq req,
|
|
|
|
|
|
|
|
bool groupByChargerNo = false)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 设置时间范围
|
|
|
|
|
|
|
|
SetTime(req);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Expression<Func<ChargeOrder, bool>> predicate = x => x.EndTime >= req.StartTime && x.EndTime <= req.EndTime;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(req.ChargerNo))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Expression<Func<ChargeOrder, bool>> condition2Expr = u => u.ChargerNo == req.ChargerNo;
|
|
|
|
|
|
|
|
predicate = Expression.Lambda<Func<ChargeOrder, bool>>(
|
|
|
|
|
|
|
|
Expression.AndAlso(predicate.Body, condition2Expr.Body),
|
|
|
|
|
|
|
|
predicate.Parameters[0]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ChargeOrder> chargeOrders = await QueryListByClauseAsync(predicate);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ChargeCountResp> result = new List<ChargeCountResp>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (req.TimeType == 1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 按小时分组统计
|
|
|
|
|
|
|
|
if (groupByChargerNo)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 按 ChargerNo 和小时分组
|
|
|
|
|
|
|
|
result = chargeOrders
|
|
|
|
|
|
|
|
.Where(order => order.EndTime.HasValue && !string.IsNullOrEmpty(order.ChargerNo))
|
|
|
|
|
|
|
|
.GroupBy(order => new { order.ChargerNo, Hour = order.EndTime.Value.Hour })
|
|
|
|
|
|
|
|
.Select(group => new ChargeCountResp
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ChargerNo = group.Key.ChargerNo,
|
|
|
|
|
|
|
|
Time = group.Key.Hour.ToString("00") + ":00",
|
|
|
|
|
|
|
|
ChargeCount = group.Sum(order => order.ElecCount ?? 0)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 仅按小时分组
|
|
|
|
|
|
|
|
result = chargeOrders
|
|
|
|
|
|
|
|
.Where(order => order.EndTime.HasValue)
|
|
|
|
|
|
|
|
.GroupBy(order => order.EndTime.Value.Hour)
|
|
|
|
|
|
|
|
.Select(group => new ChargeCountResp
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Time = group.Key.ToString("00") + ":00",
|
|
|
|
|
|
|
|
ChargeCount = group.Sum(order => order.ElecCount ?? 0)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (req.TimeType == 2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 按天分组统计
|
|
|
|
|
|
|
|
if (groupByChargerNo)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 按 ChargerNo 和日期分组
|
|
|
|
|
|
|
|
result = chargeOrders
|
|
|
|
|
|
|
|
.Where(order => order.EndTime.HasValue && !string.IsNullOrEmpty(order.ChargerNo))
|
|
|
|
|
|
|
|
.GroupBy(order => new { order.ChargerNo, Date = order.EndTime.Value.Date })
|
|
|
|
|
|
|
|
.Select(group => new ChargeCountResp
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ChargerNo = group.Key.ChargerNo,
|
|
|
|
|
|
|
|
Time = group.Key.Date.ToString("yyyy-MM-dd"),
|
|
|
|
|
|
|
|
ChargeCount = group.Sum(order => order.ElecCount ?? 0)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 仅按日期分组
|
|
|
|
|
|
|
|
result = chargeOrders
|
|
|
|
|
|
|
|
.Where(order => order.EndTime.HasValue)
|
|
|
|
|
|
|
|
.GroupBy(order => order.EndTime.Value.Date)
|
|
|
|
|
|
|
|
.Select(group => new ChargeCountResp
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Time = group.Key.ToString("yyyy-MM-dd"),
|
|
|
|
|
|
|
|
ChargeCount = group.Sum(order => order.ElecCount ?? 0)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (req.TimeType == 3)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 按月分组统计
|
|
|
|
|
|
|
|
if (groupByChargerNo)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 按 ChargerNo、年和月分组
|
|
|
|
|
|
|
|
result = chargeOrders
|
|
|
|
|
|
|
|
.Where(order => order.EndTime.HasValue && !string.IsNullOrEmpty(order.ChargerNo))
|
|
|
|
|
|
|
|
.GroupBy(order => new { order.ChargerNo, order.EndTime.Value.Year, order.EndTime.Value.Month })
|
|
|
|
|
|
|
|
.Select(group => new ChargeCountResp
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ChargerNo = group.Key.ChargerNo,
|
|
|
|
|
|
|
|
Time = group.Key.Year + "-" + group.Key.Month.ToString("00"),
|
|
|
|
|
|
|
|
ChargeCount = group.Sum(order => order.ElecCount ?? 0)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 仅按年和月分组
|
|
|
|
|
|
|
|
result = chargeOrders
|
|
|
|
|
|
|
|
.Where(order => order.EndTime.HasValue)
|
|
|
|
|
|
|
|
.GroupBy(order => new { order.EndTime.Value.Year, order.EndTime.Value.Month })
|
|
|
|
|
|
|
|
.Select(group => new ChargeCountResp
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Time = group.Key.Year + "-" + group.Key.Month.ToString("00"),
|
|
|
|
|
|
|
|
ChargeCount = group.Sum(order => order.ElecCount ?? 0)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void SetTime(ChargeCountReq req)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (req.StartTime.HasValue && req.EndTime.HasValue)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return ;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (req.TimeType < 1 || req.TimeType > 3)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 时间类型传值错误
|
|
|
|
|
|
|
|
throw new ArgumentException("时间类型传值错误");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req.TimeType == 1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 今天的开始时间
|
|
|
|
|
|
|
|
req.StartTime = DateTime.Today;
|
|
|
|
|
|
|
|
// 今天的结束时间
|
|
|
|
|
|
|
|
req.EndTime = DateTime.Today.AddDays(1).AddSeconds(-1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (req.TimeType == 2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 本月的开始时间
|
|
|
|
|
|
|
|
req.StartTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
|
|
|
|
|
|
|
|
// 本月的结束时间 下个月减1秒
|
|
|
|
|
|
|
|
req.EndTime = req.StartTime.Value.AddMonths(1).AddSeconds(-1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (req.TimeType == 3)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 今年的开始时间
|
|
|
|
|
|
|
|
req.StartTime = new DateTime(DateTime.Now.Year, 1, 1);
|
|
|
|
|
|
|
|
// 今年的结束时间 明年减1秒
|
|
|
|
|
|
|
|
req.EndTime = req.StartTime.Value.AddYears(1).AddSeconds(-1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|