fix 移除无用代码
This commit is contained in:
@@ -9,6 +9,7 @@ using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Sys.Api;
|
||||
using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||
using Kurisu.AspNetCore.CustomClass;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
@@ -187,10 +188,9 @@ public class BalanceService : IBalanceService
|
||||
.LeftJoin<DepartmentEntity>((record, department) => record.DepartmentNo == department.No)
|
||||
.LeftJoin<BusinessPlaceEntity>((record, department, bPlace) => record.BusinessPlaceCode == bPlace.Code)
|
||||
.LeftJoin<GainfoEntity>((record, department, bPlace, gainfo) => record.UserNo == gainfo.No)
|
||||
.Where((record) => record.Type == BalanceRecordTypeEnumType.Out && record.Status == BalanceRecordStatusEnumType.Valid)
|
||||
.Where(record => record.Type == BalanceRecordTypeEnumType.Out && record.Status == BalanceRecordStatusEnumType.Valid)
|
||||
.Where(record => myCodes.Contains(record.BusinessPlaceCode))
|
||||
.WhereIF(request.SearchDateTimePeriod?.Start.HasValue == true, record => record.CostDate >= request.SearchDateTimePeriod.Start)
|
||||
.WhereIF(request.SearchDateTimePeriod?.End.HasValue == true, record => record.CostDate <= request.SearchDateTimePeriod.End)
|
||||
.WhereIF(request.SearchDateTimePeriod.HasValue(), record => record.CostDate >= request.SearchDateTimePeriod.Start && record.CostDate <= request.SearchDateTimePeriod.End)
|
||||
.WhereIF(request.ShiftType.HasValue, record => record.ShiftType == request.ShiftType)
|
||||
.WhereIF(request.Search.IsPresent(), record => record.UserCode == request.Search || record.Name == request.Search);
|
||||
|
||||
@@ -348,157 +348,59 @@ public class BalanceService : IBalanceService
|
||||
.Where(x => x.Status == CanteenBusinessPlaceStatusEnumType.Opened)
|
||||
.ToListAsync();
|
||||
|
||||
|
||||
//所有消费数据
|
||||
var bs = await _dbContext.Queryable<BalanceRecordEntity>()
|
||||
.Where(x => x.Type == BalanceRecordTypeEnumType.Out)
|
||||
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
|
||||
.ToListAsync();
|
||||
|
||||
//可消费人数
|
||||
var consumerable = bs.Select(x => x.UserCode).Distinct().Count();
|
||||
|
||||
var dailyNumber = SameDay(bs, "");
|
||||
|
||||
var consumerable = bs.DistinctBy(x => x.UserCode).Count();
|
||||
|
||||
//消费走势
|
||||
var months = await GetConsumptionTrendsAsync(ConsumptionTrendEnumType.Month);
|
||||
var days = await GetConsumptionTrendsAsync(ConsumptionTrendEnumType.Day);
|
||||
var months = await GetConsumptionTrendsAsync(1);
|
||||
var days = await GetConsumptionTrendsAsync(2);
|
||||
|
||||
var res = new ConsumeNumberResponse
|
||||
return new ConsumeNumberResponse
|
||||
{
|
||||
Total = devices.Count,
|
||||
OffNumber = offCount.Count,
|
||||
PlaceNumber = places.Count,
|
||||
ConsumerableNumber = consumerable,
|
||||
DailyNumber = dailyNumber,
|
||||
DailyNumber = 0,
|
||||
Days = days,
|
||||
Months = months
|
||||
};
|
||||
return res;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取单日消费数据
|
||||
/// </summary>
|
||||
/// <param name="bs"></param>
|
||||
/// <param name="userCode"></param>
|
||||
/// <returns></returns>
|
||||
private static 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
|
||||
return 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;
|
||||
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
|
||||
.Select<SpendingDetailResponse>()
|
||||
.Distinct()
|
||||
.ToPageListAsync(request);
|
||||
}
|
||||
|
||||
public async Task<Pagination<AverageDailyResponse>> AverageDailyAsync(AverageDailyRequest request)
|
||||
{
|
||||
//所有消费数据
|
||||
var brs = await _dbContext.Queryable<BalanceRecordEntity>()
|
||||
return 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.FirstOrDefault(x => x.UserCode == code);
|
||||
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)
|
||||
{
|
||||
if (request.IsOff)
|
||||
{
|
||||
//消费机离线设备
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>()
|
||||
.Where(x => x.Type == DeviceTypeEnumType.Meal)
|
||||
.ToListAsync();
|
||||
|
||||
var offs = await GetOfflineDevicesCount(devices);
|
||||
var offUniqueNos = offs.Select(x => x.UniqueNo).ToList();
|
||||
|
||||
var offpage = await _dbContext.Queryable<DeviceEntity>()
|
||||
.LeftJoin<DeviceTemplateEntity>((d, dt) => d.TemplateCode == dt.Code)
|
||||
.Where(d => offUniqueNos.Contains(d.UniqueNo))
|
||||
.Select((d, dt) => new DevicePageResponse
|
||||
{
|
||||
FuncsStr = d.Funcs.ToString(),
|
||||
Brand = dt.Brand,
|
||||
Type = d.Type,
|
||||
}, true)
|
||||
.ToPageListAsync(request);
|
||||
return offpage;
|
||||
}
|
||||
|
||||
//消费机总数
|
||||
var page = await _dbContext.Queryable<DeviceEntity>()
|
||||
.LeftJoin<DeviceTemplateEntity>((d, dt) => d.TemplateCode == dt.Code)
|
||||
.Where(d => d.Type == DeviceTypeEnumType.Meal)
|
||||
.Select((d, dt) => new DevicePageResponse
|
||||
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
|
||||
.GroupBy(x => new
|
||||
{
|
||||
FuncsStr = d.Funcs.ToString(),
|
||||
Brand = dt.Brand,
|
||||
Type = d.Type,
|
||||
}, true)
|
||||
x.UserNo, x.Name, x.UserCode, x.CostDate
|
||||
})
|
||||
.Select(x => new AverageDailyResponse
|
||||
{
|
||||
UserNo = x.UserNo,
|
||||
Name = x.Name,
|
||||
UserCode = x.UserCode,
|
||||
AverageAmount = SqlFunc.AggregateSum(SqlFunc.Abs(x.Amount)) / SqlFunc.AggregateDistinctCount(x.CostDate)
|
||||
})
|
||||
.ToPageListAsync(request);
|
||||
return page;
|
||||
}
|
||||
|
||||
public async Task HainingImportAsync(BalanceHainingImportRequest request)
|
||||
@@ -772,7 +674,7 @@ public class BalanceService : IBalanceService
|
||||
return list;
|
||||
}
|
||||
|
||||
private async Task<List<ConsumptionTrendResponse>> GetConsumptionTrendsAsync(ConsumptionTrendEnumType type)
|
||||
private async Task<List<ConsumptionTrendResponse>> GetConsumptionTrendsAsync(int type)
|
||||
{
|
||||
var bs = await _dbContext.Queryable<BalanceRecordEntity>()
|
||||
.Where(x => x.Type == BalanceRecordTypeEnumType.Out)
|
||||
@@ -781,7 +683,7 @@ public class BalanceService : IBalanceService
|
||||
var totalAmount = Math.Round(Math.Abs(bs.Sum(x => x.Amount)), 2);
|
||||
|
||||
var list = new List<ConsumptionTrendResponse>();
|
||||
if (type == ConsumptionTrendEnumType.Month)
|
||||
if (type == 1)
|
||||
{
|
||||
//月与总额对比
|
||||
var months = GetMonthsOfYear();
|
||||
|
||||
Reference in New Issue
Block a user