appFeedbackRecordService.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict';
  2. const Service = require('egg').Service;
  3. class AppFeedbackRecordService extends Service {
  4. async feedback(cond) {
  5. const { ctx } = this;
  6. const agg = ctx.helper.getCommonAggSum({ ...cond, value: 'total' });
  7. return await ctx.model.Local.AppFeedbackRecordModel.aggregateFix(agg);
  8. }
  9. async statistics({ timeRangData, initData, isForceUpdate }) {
  10. const { ctx } = this;
  11. const hasData = await ctx.service.statisticsService.saveBefore(ctx.model.Local.AppFeedbackRecordModel,
  12. { ...initData });
  13. if (hasData && !isForceUpdate) {
  14. return;
  15. }
  16. initData.start_time = new Date();
  17. const obj = await this.total(timeRangData);
  18. ctx.logger.info('任务进行total');
  19. const total = obj.total || 0;
  20. await ctx.service.statisticsService.save(ctx.model.Local.AppFeedbackRecordModel,
  21. { ...initData, total }, isForceUpdate);
  22. }
  23. async total({ startTime, endTime }) {
  24. const { ctx } = this;
  25. const agg = [
  26. { $match: ctx.helper.getTimeRangMatch(startTime, endTime, 'create_time') },
  27. { $group: {
  28. _id: null,
  29. total: { $sum: '$count' },
  30. },
  31. },
  32. ];
  33. return await ctx.model.AppFeedbackRecordModel.aggregateNGroup(agg);
  34. }
  35. }
  36. module.exports = AppFeedbackRecordService;