Exemple #1
0
 /// <summary>
 /// 获取今天的出刀列表
 /// </summary>
 /// <returns>
 /// <para>出刀表</para>
 /// <para><see langword="null"/> 数据库错误</para>
 /// </returns>
 public List <GuildBattle> GetTodayAttacks(long?uid = null)
 {
     try
     {
         using var dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         if (uid == null)
         {
             //查询所有人的出刀表
             return(dbClient.Queryable <GuildBattle>()
                    .AS(BattleTableName)
                    .Where(i => i.Time >= BotUtils.GetPcrUpdateStamp())
                    .OrderBy(i => i.Aid)
                    .ToList());
         }
         else
         {
             //查询单独成员的出刀表
             return(dbClient.Queryable <GuildBattle>()
                    .AS(BattleTableName)
                    .Where(i => i.Time >= BotUtils.GetPcrUpdateStamp() && i.Uid == uid)
                    .OrderBy(i => i.Aid)
                    .ToList());
         }
     }
     catch (Exception e)
     {
         Log.Error("Database error", Log.ErrorLogBuilder(e));
         return(null);
     }
 }
Exemple #2
0
 /// <summary>
 /// 查询今日余刀
 /// 用于查刀和催刀
 /// </summary>
 /// <returns>余刀表</returns>
 public Dictionary <long, int> GetTodayAtkCount()
 {
     try
     {
         using var dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         return(dbClient.Queryable <GuildBattle>()
                .AS(BattleTableName)
                .Where(attack => attack.Time > BotUtils.GetPcrUpdateStamp() &&
                       attack.Attack != AttackType.Compensate &&
                       attack.Attack != AttackType.CompensateKill)
                .GroupBy(member => member.Uid)
                .Select(member => new
         {
             member.Uid,
             times = SqlFunc.AggregateCount(member.Uid)
         })
                .ToList()
                .ToDictionary(member => member.Uid,
                              member => member.times));
     }
     catch (Exception e)
     {
         Log.Error("Database error", Log.ErrorLogBuilder(e));
         return(null);
     }
 }
Exemple #3
0
 /// <summary>
 /// 获取今日的总出刀数量
 /// </summary>
 /// <returns>
 /// <para>今日出刀数</para>
 /// <para><see langword="-1"/> 数据库错误</para>
 /// </returns>
 public int GetTodayAttackCount()
 {
     try
     {
         using var dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         //出刀数
         return(dbClient.Queryable <GuildBattle>()
                .AS(BattleTableName)
                //今天5点之后出刀的
                .Where(i => i.Time >= BotUtils.GetPcrUpdateStamp() &&
                       i.Attack != AttackType.Compensate && i.Attack != AttackType.CompensateKill)
                //筛选出刀总数
                .Count());
     }
     catch (Exception e)
     {
         Log.Error("Database error", Log.ErrorLogBuilder(e));
         return(-1);
     }
 }