feat 餐饮主页接口
This commit is contained in:
@@ -12,6 +12,7 @@ using Kurisu.Core.DataAccess.Entity;
|
||||
using Kurisu.Core.User.Abstractions;
|
||||
using Kurisu.SqlSugar.Extensions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
|
||||
@@ -565,7 +566,7 @@ public class BalanceService : IBalanceService
|
||||
.Where(x =>x.Status == CanteenBusinessPlaceStatusEnumType.Opened)
|
||||
.ToListAsync();
|
||||
|
||||
var time = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
|
||||
//所有消费数据
|
||||
var bs = await _dbContext.Queryable<BalanceRecordEntity>()
|
||||
.Where(x => x.Type == BalanceRecordTypeEnumType.Out)
|
||||
@@ -573,13 +574,8 @@ public class BalanceService : IBalanceService
|
||||
//可消费人数
|
||||
var consumerable = bs.Select(x => x.UserCode).Distinct().Count();
|
||||
|
||||
//当日消费数据
|
||||
var monthbs = bs
|
||||
.Where(x => x.CostDateTime.ToString("yyyy-MM-dd") == time);
|
||||
//当日消费额
|
||||
var monthlySpending = monthbs.Sum(x => x.Amount);
|
||||
//当日消费人数
|
||||
var monthlyCount = monthbs.Select(x => x.UserCode).Distinct().Count();
|
||||
var dailyNumber = SameDay(bs,"");
|
||||
|
||||
|
||||
//消费走势
|
||||
var months = await GetConsumptionTrendsAsync(ConsumptionTrendEnumType.Month);
|
||||
@@ -591,15 +587,98 @@ public class BalanceService : IBalanceService
|
||||
OffNumber = offCount.Count,
|
||||
PlaceNumber = places.Count,
|
||||
ConsumerableNumber = consumerable,
|
||||
DailyNumber = monthlyCount != 0 ? Math.Abs((int)Math.Ceiling(monthlySpending / monthlyCount)) : 0,
|
||||
DailyNumber = dailyNumber,
|
||||
Days = days,
|
||||
Months = months
|
||||
};
|
||||
return res;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取单日消费数据
|
||||
/// </summary>
|
||||
/// <param name="bs"></param>
|
||||
/// <param name="userCode"></param>
|
||||
/// <returns></returns>
|
||||
private int SameDay(List<BalanceRecordEntity> bs,string userCode)
|
||||
{
|
||||
var time = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
var b = userCode.IsEmpty();
|
||||
//当日消费数据
|
||||
var monthbs = bs
|
||||
.Where(x => x.CostDateTime.ToString("yyyy-MM-dd") == time)
|
||||
.WhereIF(!userCode.IsEmpty(),x => x.UserCode == userCode);
|
||||
//当日消费额
|
||||
var monthlySpending = monthbs.Sum(x => x.Amount);
|
||||
//当日消费人数
|
||||
var monthlyCount = monthbs.Select(x => x.UserCode).Distinct().Count();
|
||||
var dailyNumber = monthlyCount != 0 ? Math.Abs((int)Math.Ceiling(monthlySpending / monthlyCount)) : 0;
|
||||
return dailyNumber;
|
||||
}
|
||||
|
||||
public async Task<Pagination<SpendingDetailResponse>> GetSpendingDetailsAsync(SpendingDetailRequest request)
|
||||
{
|
||||
var brs = await _dbContext
|
||||
.Queryable<BalanceRecordEntity>()
|
||||
.Where(x => x.Type == BalanceRecordTypeEnumType.Out)
|
||||
.ToListAsync();
|
||||
var codes = brs.Select(x => x.UserCode).ToList().Distinct().ToList();
|
||||
|
||||
var lst = new List<SpendingDetailResponse>();
|
||||
foreach (var code in codes)
|
||||
{
|
||||
var br = brs.Where(x => x.UserCode == code).FirstOrDefault();
|
||||
var res = br.Adapt<SpendingDetailResponse>();
|
||||
lst.Add(res);
|
||||
}
|
||||
|
||||
// 分页操作
|
||||
var startIndex = (request.PageIndex - 1) * request.PageSize;
|
||||
var pagedData = lst.Skip(startIndex).Take(request.PageSize).ToList();
|
||||
|
||||
var pagination = new Pagination<SpendingDetailResponse>
|
||||
{
|
||||
PageIndex = request.PageIndex,
|
||||
PageSize = request.PageSize,
|
||||
Total = lst.Count, // 使用原始列表的总数进行分页
|
||||
Data = pagedData
|
||||
};
|
||||
|
||||
return pagination;
|
||||
}
|
||||
|
||||
public async Task<Pagination<AverageDailyResponse>> AverageDailyAsync(AverageDailyRequest request)
|
||||
{
|
||||
//所有消费数据
|
||||
var brs = await _dbContext.Queryable<BalanceRecordEntity>()
|
||||
.Where(x => x.Type == BalanceRecordTypeEnumType.Out)
|
||||
.ToListAsync();
|
||||
var codes = brs.Select(x => x.UserCode).ToList().Distinct().ToList();
|
||||
|
||||
var lst = new List<AverageDailyResponse>();
|
||||
foreach (var code in codes)
|
||||
{
|
||||
var br = brs.Where(x => x.UserCode == code).FirstOrDefault();
|
||||
var res = br.Adapt<AverageDailyResponse>();
|
||||
var dailyNumber = SameDay(brs,code);
|
||||
res.AverageAmount = dailyNumber;
|
||||
lst.Add(res);
|
||||
}
|
||||
|
||||
// 分页操作
|
||||
var startIndex = (request.PageIndex - 1) * request.PageSize;
|
||||
var pagedData = lst.Skip(startIndex).Take(request.PageSize).ToList();
|
||||
|
||||
var pagination = new Pagination<AverageDailyResponse>
|
||||
{
|
||||
PageIndex = request.PageIndex,
|
||||
PageSize = request.PageSize,
|
||||
Total = lst.Count, // 使用原始列表的总数进行分页
|
||||
Data = pagedData
|
||||
};
|
||||
|
||||
return pagination;
|
||||
}
|
||||
|
||||
public async Task<Pagination<DevicePageResponse>> GetConsumeDeviceAsync(GetConsumeDeviceRequest request)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user