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.
56 lines
2.2 KiB
56 lines
2.2 KiB
using Build_God_Api.DB;
|
|
using SqlSugar;
|
|
|
|
namespace Build_God_Api.Services
|
|
{
|
|
public interface IStatisticsService
|
|
{
|
|
Task<StatisticsSummary> GetSummary();
|
|
}
|
|
|
|
public class StatisticsSummary
|
|
{
|
|
public int EquipmentCount { get; set; }
|
|
public int LevelCount { get; set; }
|
|
public int ProfessionCount { get; set; }
|
|
public int PillCount { get; set; }
|
|
public int MissionCount { get; set; }
|
|
public Dictionary<int, int> EquipmentByRarity { get; set; } = new();
|
|
public Dictionary<int, int> MissionByDifficulty { get; set; } = new();
|
|
}
|
|
|
|
public class StatisticsService(ISqlSugarClient db) : IStatisticsService
|
|
{
|
|
private readonly ISqlSugarClient db = db;
|
|
|
|
public async Task<StatisticsSummary> GetSummary()
|
|
{
|
|
var equipmentCount = await db.Queryable<EquipmentTemplate>().CountAsync();
|
|
var levelCount = await db.Queryable<Level>().CountAsync();
|
|
var professionCount = await db.Queryable<Profession>().CountAsync();
|
|
var pillCount = await db.Queryable<Pill>().CountAsync();
|
|
var missionCount = await db.Queryable<Mission>().CountAsync();
|
|
|
|
var equipmentByRarity = await db.Queryable<EquipmentTemplate>()
|
|
.GroupBy(x => x.Rarity)
|
|
.Select(x => new { Rarity = x.Rarity, Count = SqlFunc.AggregateCount(x.Id) })
|
|
.ToListAsync();
|
|
|
|
var missionByDifficulty = await db.Queryable<Mission>()
|
|
.GroupBy(x => x.Difficulty)
|
|
.Select(x => new { Difficulty = x.Difficulty, Count = SqlFunc.AggregateCount(x.Id) })
|
|
.ToListAsync();
|
|
|
|
return new StatisticsSummary
|
|
{
|
|
EquipmentCount = equipmentCount,
|
|
LevelCount = levelCount,
|
|
ProfessionCount = professionCount,
|
|
PillCount = pillCount,
|
|
MissionCount = missionCount,
|
|
EquipmentByRarity = equipmentByRarity.ToDictionary(x => (int)x.Rarity, x => x.Count),
|
|
MissionByDifficulty = missionByDifficulty.ToDictionary(x => (int)x.Difficulty, x => x.Count)
|
|
};
|
|
}
|
|
}
|
|
}
|
|
|