瀏覽代碼

LOG日志

wq 4 年之前
父節點
當前提交
180902e32b
共有 1 個文件被更改,包括 20 次插入0 次删除
  1. 20 0
      app/service/sysLogService.js

+ 20 - 0
app/service/sysLogService.js

@@ -37,6 +37,10 @@ class SysLogService extends Service {
     if (data.state) {
       where.state = data.state;
     }
+    if (data.startTime && data.endTime) {
+      where.time = { $gte: data.startTime + ' 00:00:00', $lt: data.endTime + ' 23:59:59' };
+    }
+
 
     this.ctx.logger.info('条件', where);
 
@@ -63,6 +67,21 @@ class SysLogService extends Service {
         select: 'name',
       },
     ];
+
+    const nowday = new Date();
+    const finalday = nowday.getFullYear()+"-"+(nowday.getMonth()+1)+"-"+nowday.getDate();
+    const match ={};
+    match.time = { $gte: finalday+ ' 00:00:00', $lt: finalday + ' 23:59:59'};
+    const nowdaytotal = await model.SysLogModel.aggregate([
+      { $project: {time: { $dateToString: { format: "%Y-%m-%d %H:%M:%S", date: "$time" } },_id:1}},
+      { $match : match },
+      { $group: { _id: '$_id' } },
+      { $count:'total'}
+    ]);
+    let nowdaynum = 0
+    if(nowdaytotal.length>0){
+      nowdaynum = nowdaytotal[0].total
+    }
     const total = await model.SysLogModel.find(where).populate(pop).countDocuments();
     const result = await model.SysLogModel.find(where).populate(pop).skip((page - 1) * rows)
       .limit(rows)
@@ -70,6 +89,7 @@ class SysLogService extends Service {
     return {
       count: total,
       list: result,
+      nowdaytotal:nowdaynum,
     };
   }