userDrivingController2.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. 'use strict';
  2. const Controller = require('egg').Controller;
  3. // 用户出行信息行为统计分析模块
  4. class UserDrivingController2 extends Controller {
  5. constructor(ctx) {
  6. super(ctx);
  7. // 特殊的入参校验可以重写在这,默认可以使用commonRule
  8. this.createRule = {
  9. startTime: { type: 'number', min: 0 }, // 开始时间的时间戳 包含
  10. endTime: { type: 'number', min: 0 }, // 结束时间的时间戳 不包含(客户端处理结束时间 下一日 ,下一月第一日 ,下一年第一日)
  11. };
  12. }
  13. // 驾驶行为 基础
  14. async index() {
  15. const { ctx, service } = this;
  16. // 校验参数 组装参数
  17. const payload = ctx.validate();
  18. // // 调用 Service 进行业务处理
  19. const data = await service.drivingBehaviorInfoService2.index(payload, this.ctx.params.id);
  20. // // 设置响应内容和响应状态码
  21. ctx.success({ data });
  22. }
  23. // 驾驶行为 月年
  24. async mixMY() {
  25. const { ctx, service } = this;
  26. // 校验参数 组装参数
  27. const payload = ctx.validate();
  28. // // 调用 Service 进行业务处理
  29. let key = this.ctx.params.id;
  30. switch (payload.type) {
  31. case '1':
  32. key += 'Month';
  33. break;
  34. case '2':
  35. key += 'Year';
  36. break;
  37. default:
  38. break;
  39. }
  40. const data = await service.drivingBehaviorInfoService2.mixMY(payload, key);
  41. // // 设置响应内容和响应状态码
  42. ctx.success({ data });
  43. }
  44. // 驾驶行为 出行时间+疲劳驾驶
  45. async mileageStartTimeAndDsm() {
  46. const { ctx, service } = this;
  47. // 校验参数 组装参数
  48. const payload = ctx.validate();
  49. // // 调用 Service 进行业务处理
  50. const data = await service.drivingBehaviorInfoService2.mileageStartTimeAndDsm(payload);
  51. // // 设置响应内容和响应状态码
  52. ctx.success({ data });
  53. }
  54. // 驾驶行为 分组 时间区分 工作日 周末
  55. async date() {
  56. const { ctx, service } = this;
  57. // 校验参数 组装参数
  58. const payload = ctx.validate();
  59. // // 调用 Service 进行业务处理
  60. const data = await service.drivingBehaviorInfoService2.date(payload, this.ctx.params.id);
  61. // // 设置响应内容和响应状态码
  62. ctx.success({ data });
  63. }
  64. // 驾驶行为 日累加
  65. async count2() {
  66. const { ctx, service } = this;
  67. // 校验参数 组装参数
  68. const payload = ctx.validate();
  69. // // 调用 Service 进行业务处理
  70. const data = await service.drivingBehaviorInfoService2.count2(payload, this.ctx.params.id);
  71. // // 设置响应内容和响应状态码
  72. ctx.success({ data });
  73. }
  74. // 驾驶行为 一段时间总和
  75. async sum() {
  76. const { ctx, service } = this;
  77. // 校验参数 组装参数
  78. const payload = ctx.validate(this.createRule);
  79. // 调用 Service 进行业务处理
  80. const data = await service.drivingBehaviorInfoService2.sum(payload, this.ctx.params.id);
  81. // // // 设置响应内容和响应状态码
  82. ctx.success({ data });
  83. }
  84. // 驾驶行为 额外
  85. async ext() {
  86. const { ctx, service } = this;
  87. // 调用 Service 进行业务处理
  88. const data = await service.drivingBehaviorInfoService2.ext();
  89. // // // 设置响应内容和响应状态码
  90. ctx.success({ data });
  91. }
  92. }
  93. module.exports = UserDrivingController2;