12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- 'use strict';
- const Service = require('egg').Service;
- class AppFeedbackRecordService extends Service {
- async feedback(cond) {
- const { ctx } = this;
- const agg = ctx.helper.getCommonAggSum({ ...cond, value: 'total' });
- return await ctx.model.Local.AppFeedbackRecordModel.aggregateFix(agg);
- }
- async statistics({ timeRangData, initData, isForceUpdate }) {
- const { ctx } = this;
- const hasData = await ctx.service.statisticsService.saveBefore(ctx.model.Local.AppFeedbackRecordModel,
- { ...initData });
- if (hasData && !isForceUpdate) {
- return;
- }
- initData.start_time = new Date();
- const obj = await this.total(timeRangData);
- ctx.logger.info('任务进行total');
- const total = obj.total || 0;
- await ctx.service.statisticsService.save(ctx.model.Local.AppFeedbackRecordModel,
- { ...initData, total }, isForceUpdate);
- }
- async total({ startTime, endTime }) {
- const { ctx } = this;
- const agg = [
- { $match: ctx.helper.getTimeRangMatch(startTime, endTime, 'create_time') },
- { $group: {
- _id: null,
- total: { $sum: '$count' },
- },
- },
- ];
- return await ctx.model.AppFeedbackRecordModel.aggregateNGroup(agg);
- }
- }
- module.exports = AppFeedbackRecordService;
|