mirror of
https://github.com/YMFE/yapi.git
synced 2025-02-23 13:59:28 +08:00
65 lines
1.5 KiB
JavaScript
65 lines
1.5 KiB
JavaScript
/**
|
|
* Created by gxl.gao on 2017/10/24.
|
|
*/
|
|
const yapi = require('yapi.js');
|
|
const baseModel = require('models/base.js');
|
|
|
|
class statisMockModel extends baseModel {
|
|
getName() {
|
|
return 'statis_mock';
|
|
}
|
|
|
|
getSchema() {
|
|
return {
|
|
interface_id: { type: Number, required: true },
|
|
project_id: { type: Number, required: true },
|
|
group_id: { type: Number, required: true },
|
|
time: Number, //'时间戳'
|
|
ip: String,
|
|
date: String
|
|
};
|
|
}
|
|
|
|
save(data) {
|
|
let m = new this.model(data);
|
|
return m.save();
|
|
}
|
|
|
|
getTotalCount() {
|
|
return this.model.count({});
|
|
}
|
|
|
|
getDayCount(timeInterval) {
|
|
let end = timeInterval[1];
|
|
let start = timeInterval[0];
|
|
return this.model.aggregate([
|
|
{
|
|
$match: {
|
|
date: { $gt: start, $lte: end }
|
|
}
|
|
},
|
|
{
|
|
$group: {
|
|
_id: '$date', //$region is the column name in collection
|
|
count: { $sum: 1 }
|
|
}
|
|
},
|
|
{
|
|
$sort: { _id: 1 }
|
|
}
|
|
]);
|
|
}
|
|
|
|
list() {
|
|
return this.model.find({}).select('date').exec();
|
|
}
|
|
|
|
up(id, data) {
|
|
data.up_time = yapi.commons.time();
|
|
return this.model.update({
|
|
_id: id
|
|
}, data, { runValidators: true });
|
|
}
|
|
}
|
|
|
|
module.exports = statisMockModel; |