2016-01-11 06:23:13 +08:00
|
|
|
|
using System;
|
2015-11-10 00:43:05 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-01-12 05:16:29 +08:00
|
|
|
|
using MongoDB.Bson;
|
|
|
|
|
using MongoDB.Driver;
|
2015-11-10 00:43:05 +08:00
|
|
|
|
|
2016-08-20 05:10:55 +08:00
|
|
|
|
namespace BuildFeed.Model
|
2015-11-10 00:43:05 +08:00
|
|
|
|
{
|
2017-02-24 04:53:49 +08:00
|
|
|
|
public partial class BuildRepository
|
|
|
|
|
{
|
|
|
|
|
public async Task<int[]> SelectAllYears(int limit = -1, int skip = 0)
|
|
|
|
|
{
|
2018-02-07 06:16:37 +08:00
|
|
|
|
var query =
|
2017-02-24 04:53:49 +08:00
|
|
|
|
_buildCollection.Aggregate()
|
|
|
|
|
.Match(Builders<Build>.Filter.Ne(b => b.BuildTime, null))
|
|
|
|
|
.Group(new BsonDocument("_id", new BsonDocument("$year", $"${nameof(Build.BuildTime)}")))
|
|
|
|
|
.Sort(new BsonDocument("_id", -1))
|
|
|
|
|
.Skip(skip);
|
|
|
|
|
|
|
|
|
|
if (limit > 0)
|
|
|
|
|
{
|
|
|
|
|
query = query.Limit(limit);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-07 06:16:37 +08:00
|
|
|
|
var grouping = await query.ToListAsync();
|
2017-02-24 04:53:49 +08:00
|
|
|
|
|
|
|
|
|
return (from g in grouping
|
2018-02-07 06:16:37 +08:00
|
|
|
|
where !g["_id"].IsBsonNull
|
|
|
|
|
select g["_id"].AsInt32).ToArray();
|
2017-02-24 04:53:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<long> SelectAllYearsCount()
|
|
|
|
|
{
|
2018-02-07 06:16:37 +08:00
|
|
|
|
var query = await _buildCollection.Aggregate()
|
|
|
|
|
.Match(Builders<Build>.Filter.Ne(b => b.BuildTime, null))
|
|
|
|
|
.Group(new BsonDocument("_id", new BsonDocument("$year", $"${nameof(Build.BuildTime)}")))
|
|
|
|
|
.ToListAsync();
|
2017-02-24 04:53:49 +08:00
|
|
|
|
|
|
|
|
|
return query.Count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<List<Build>> SelectYear(int year, int limit = -1, int skip = 0)
|
|
|
|
|
{
|
2018-02-07 06:16:37 +08:00
|
|
|
|
var query =
|
|
|
|
|
_buildCollection.Find(Builders<Build>.Filter.And(
|
|
|
|
|
Builders<Build>.Filter.Gte(b => b.BuildTime,
|
|
|
|
|
new DateTime(year, 1, 1, 0, 0, 0, DateTimeKind.Utc)),
|
|
|
|
|
Builders<Build>.Filter.Lte(b => b.BuildTime,
|
|
|
|
|
new DateTime(year, 12, 31, 23, 59, 59, DateTimeKind.Utc))))
|
|
|
|
|
.Sort(sortByCompileDate)
|
|
|
|
|
.Skip(skip);
|
2017-02-24 04:53:49 +08:00
|
|
|
|
|
|
|
|
|
if (limit > 0)
|
|
|
|
|
{
|
|
|
|
|
query = query.Limit(limit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return await query.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-07 06:16:37 +08:00
|
|
|
|
public async Task<long> SelectYearCount(int year) => await
|
2018-10-06 19:35:03 +08:00
|
|
|
|
_buildCollection.CountDocumentsAsync(Builders<Build>.Filter.And(
|
2018-02-07 06:16:37 +08:00
|
|
|
|
Builders<Build>.Filter.Gte(b => b.BuildTime, new DateTime(year, 1, 1, 0, 0, 0, DateTimeKind.Utc)),
|
|
|
|
|
Builders<Build>.Filter.Lte(b => b.BuildTime,
|
|
|
|
|
new DateTime(year, 12, 31, 23, 59, 59, DateTimeKind.Utc))));
|
2017-02-24 04:53:49 +08:00
|
|
|
|
}
|
2015-11-10 00:43:05 +08:00
|
|
|
|
}
|