|
@@ -227,6 +227,55 @@ class VisitService extends Service {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ async sevendayNum(data,user) {
|
|
|
+ const { model } = this.ctx;
|
|
|
+ const level = user.dept.level;
|
|
|
+ const match = {};
|
|
|
+ match.time = { $gte: data.yestday} ;
|
|
|
+ // admin的dept 存在冲突,所以它不需要结合
|
|
|
+ if (user.role._id != this.app.config.defaultAdminRoleId) {
|
|
|
+ match['dept'+level]= user.dept._id;
|
|
|
+ }
|
|
|
+
|
|
|
+ const res = await model.VisitModel.aggregate([
|
|
|
+ { $project: { time: { $dateToString: { format: '%Y-%m-%d', date: '$visitTime' } },_id:1,dept1:1,dept2:1,dept3:1,dept4:1,dept5:1} },
|
|
|
+ { $match: match},
|
|
|
+ { $group:{ _id: '$time', value : {$sum : 1}}},
|
|
|
+ { $project:{ label:'$_id',value:1,_id:0} },
|
|
|
+ { $sort:{ label: 1 } }
|
|
|
+ ]);
|
|
|
+
|
|
|
+
|
|
|
+ let morenArr = [];
|
|
|
+ for(let i=0;i<7;i++){
|
|
|
+ let yestday = new Date();
|
|
|
+ yestday.setTime(yestday.getTime()-24*60*60*1000*i);
|
|
|
+ let month = yestday.getMonth()+1;
|
|
|
+ if (month < 10) month = "0" + month;
|
|
|
+ let day = yestday.getDate();
|
|
|
+ if (day < 10) day = "0" + day;
|
|
|
+ let ysday = yestday.getFullYear()+"-" + month + "-" + day;
|
|
|
+ let vote = {};
|
|
|
+ vote.label = ysday;
|
|
|
+ vote.value = 0;
|
|
|
+ morenArr.push(vote)
|
|
|
+ }
|
|
|
+
|
|
|
+ if(res.length > 0){
|
|
|
+ for(let j = 0; j<morenArr.length ; j++){
|
|
|
+ let mlabel = morenArr[j].label;
|
|
|
+ for(let k = 0; k<res.length; k++){
|
|
|
+ let clabel = res[k].label;
|
|
|
+ if(mlabel == clabel){
|
|
|
+ morenArr[j].value = res[k].value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return morenArr;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
module.exports = VisitService;
|