fix error

This commit is contained in:
chiu 2020-03-04 11:06:36 +08:00
parent bae6f2cf17
commit 89c065b047
1 changed files with 8 additions and 1 deletions

View File

@ -72,6 +72,9 @@ class Site
mount_uploader :favicon, ImageUploader
mount_uploader :mobile_icon, ImageUploader
Impression.class_eval{
def self.create_date_for_group(date)
{'_id'=>{'year'=>date.year,'month'=>date.month,'day'=>date.day},'count'=>0}
end
def self.group_by(field,day_limit,start_day=Date.today,format = 'day')
limit_ele = self.desc(:id).where({ created_at: { "$lt" => start_day-(day_limit-2).days }}).first || self.first
key_op = [['year','$year'],['month', '$month'], ['day', '$dayOfMonth']]
@ -84,7 +87,11 @@ class Site
{"$group" => {"_id" => group_id_fields,"count" => {"$sum" => 1}}},
{"$sort" => {"_id"=>-1}}
]
collection.aggregate(pipeline)
tmp = collection.aggregate(pipeline)
if tmp.count < day_limit
tmp.concat(Array.new(day_limit-tmp.count).map.with_index.map{|v,i| create_date_for_group(start_day+i.days)})
end
tmp
end
}
after_initialize do