msgCenterController.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 'use strict';
  2. const Controller = require('egg').Controller;
  3. // 消息中心统计分析管理
  4. class MsgCenterController extends Controller {
  5. constructor(ctx) {
  6. super(ctx);
  7. // 特殊的入参校验可以重写在这,默认可以使用commonRule
  8. this.createRule = {
  9. msgType: { type: 'number', required: false },
  10. startTime: { type: 'number', min: 0 }, // 开始时间的时间戳 包含
  11. endTime: { type: 'number', min: 0 }, // 结束时间的时间戳 不包含(客户端处理结束时间 下一日 ,下一月第一日 ,下一年第一日)
  12. type: [ '0', '1', '2' ], // 类型分为 0日 1月 2年
  13. };
  14. }
  15. // 消息渠道统计
  16. async channel() {
  17. const { ctx, service } = this;
  18. // 校验参数 组装参数
  19. const payload = ctx.validate();
  20. // 调用 Service 进行业务处理
  21. if (ctx.isDev()) {
  22. const data = ctx.getData(payload, {
  23. value: [ 'colorTotal', 'grayTotal' ],
  24. });
  25. ctx.success({ data });
  26. } else {
  27. const data = await service.msgCenterRecordService2.channel(payload);
  28. // 设置响应内容和响应状态码
  29. ctx.success({ data });
  30. }
  31. }
  32. // 消息查看率统计
  33. async read() {
  34. const { ctx, service } = this;
  35. // 校验参数 组装参数
  36. const payload = ctx.validate(this.createRule);
  37. // 调用 Service 进行业务处理
  38. if (ctx.isDev()) {
  39. const data = ctx.getDataAdd(payload, {
  40. value: [ 'readCount', 'total' ],
  41. });
  42. ctx.success({ data });
  43. } else {
  44. const data = await service.msgCenterRecordService2.read(payload);
  45. // 设置响应内容和响应状态码
  46. ctx.success({ data });
  47. }
  48. }
  49. // 消息抵达率统计
  50. async over() {
  51. const { ctx, service } = this;
  52. // 校验参数 组装参数
  53. const payload = ctx.validate();
  54. // 调用 Service 进行业务处理
  55. if (ctx.isDev()) {
  56. const data = ctx.getData(payload, {
  57. value: [ 'readTotal', 'unReadTotal' ],
  58. });
  59. ctx.success({ data });
  60. } else {
  61. const data = await service.msgCenterRecordService2.over(payload);
  62. // 设置响应内容和响应状态码
  63. ctx.success({ data });
  64. }
  65. }
  66. }
  67. module.exports = MsgCenterController;