浏览代码

LOG日志

wq 4 年之前
父节点
当前提交
f92ec83b1e
共有 4 个文件被更改,包括 93 次插入1 次删除
  1. 1 1
      app/controller/infoController.js
  2. 41 0
      app/controller/visitController.js
  3. 2 0
      app/router/logic.js
  4. 49 0
      app/service/visitService.js

+ 1 - 1
app/controller/infoController.js

@@ -599,7 +599,7 @@ async yestdayNum() {
   let month = yestday.getMonth()+1;
   let month = yestday.getMonth()+1;
   if (month < 10) month = "0" + month;
   if (month < 10) month = "0" + month;
   let day = yestday.getDate();
   let day = yestday.getDate();
-  if (month < 10) day = "0" + day;
+  if (day < 10) day = "0" + day;
   let ysday = yestday.getFullYear()+"-" + month + "-" + day;
   let ysday = yestday.getFullYear()+"-" + month + "-" + day;
   ctx.query.yestday = ysday;
   ctx.query.yestday = ysday;
   const result = await service.infoService.yestdayNum(query,user);
   const result = await service.infoService.yestdayNum(query,user);

+ 41 - 0
app/controller/visitController.js

@@ -901,6 +901,47 @@ class VisitController extends Controller {
       ctx.error('身份证不存在');
       ctx.error('身份证不存在');
     }
     }
   }
   }
+
+  // 首页近7日探访数据数据
+  async sevendayNum() {
+    const { ctx, service } = this;
+    const query = ctx.query;
+    const user = ctx.user;
+    // const level = user.dept.level;
+    // 判断当前的dept权限  和传入的5级权限   不能超过当前人dept
+    if (!ctx.query.dept1) {
+      delete ctx.query.dept1;
+    }
+    if (!ctx.query.dept2) {
+      delete ctx.query.dept2;
+    }
+    if (!ctx.query.dept3) {
+      delete ctx.query.dept3;
+    }
+    if (!ctx.query.dept4) {
+      delete ctx.query.dept4;
+    }
+    if (!ctx.query.dept5) {
+      delete ctx.query.dept5;
+    }
+    delete ctx.query.deptId;
+    // // admin的dept 存在冲突,所以它不需要结合
+    // if (user.role._id != this.app.config.defaultAdminRoleId) {
+    //   ctx.query['dept' + level] = user.dept._id;
+    // }
+
+    let yestday = new Date();
+    yestday.setTime(yestday.getTime()-24*60*60*1000*6);
+    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;
+    ctx.query.startday = ysday;
+    const result = await service.visitService.sevendayNum(query,user);
+    ctx.success(result);
+
+  }
 }
 }
 
 
 module.exports = VisitController;
 module.exports = VisitController;

+ 2 - 0
app/router/logic.js

@@ -36,6 +36,8 @@ module.exports = app => {
   router.get('/visit/list', controller.visitController.list);
   router.get('/visit/list', controller.visitController.list);
   router.get('/visit/listForPage', controller.visitController.listForPageWithDept);
   router.get('/visit/listForPage', controller.visitController.listForPageWithDept);
   router.get('/visit/exportExcelByVisit', controller.visitController.exportExcelByVisit);
   router.get('/visit/exportExcelByVisit', controller.visitController.exportExcelByVisit);
+  router.get('/visit/sevendayNum', controller.visitController.sevendayNum);
+
 
 
 
 
   //   积分管理
   //   积分管理

+ 49 - 0
app/service/visitService.js

@@ -227,6 +227,55 @@ class VisitService extends Service {
     return result;
     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;
 module.exports = VisitService;