userDrivingController2.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. async index() {
  14. const { ctx, service } = this;
  15. // 校验参数 组装参数
  16. const payload = ctx.validate();
  17. // // 调用 Service 进行业务处理
  18. if (ctx.isDev()) {
  19. const data = ctx.getMix(payload, this.ctx.params.id);
  20. ctx.success({ data });
  21. } else {
  22. const data = await service.drivingBehaviorInfoService2.index(payload, this.ctx.params.id);
  23. // // 设置响应内容和响应状态码
  24. ctx.success({ data });
  25. }
  26. }
  27. async mileageStartTimeAndDsm() {
  28. const { ctx, service } = this;
  29. // 校验参数 组装参数
  30. const payload = ctx.validate();
  31. // // 调用 Service 进行业务处理
  32. if (ctx.isDev()) {
  33. const data = ctx.getMix2(payload);
  34. ctx.success({ data });
  35. } else {
  36. const data = await service.drivingBehaviorInfoService2.mileageStartTimeAndDsm(payload);
  37. // // 设置响应内容和响应状态码
  38. ctx.success({ data });
  39. }
  40. }
  41. async date() {
  42. const { ctx, service } = this;
  43. // 校验参数 组装参数
  44. const payload = ctx.validate();
  45. // // 调用 Service 进行业务处理
  46. if (ctx.isDev()) {
  47. const data = ctx.getMix3(payload, this.ctx.params.id);
  48. ctx.success({ data });
  49. } else {
  50. const data = await service.drivingBehaviorInfoService2.date(payload, this.ctx.params.id);
  51. // // 设置响应内容和响应状态码
  52. ctx.success({ data });
  53. }
  54. }
  55. async count2() {
  56. const { ctx, service } = this;
  57. // 校验参数 组装参数
  58. const payload = ctx.validate();
  59. // // 调用 Service 进行业务处理
  60. if (ctx.isDev()) {
  61. const data = ctx.getData(payload);
  62. ctx.success({ data });
  63. } else {
  64. const data = await service.drivingBehaviorInfoService2.count2(payload, this.ctx.params.id);
  65. // // 设置响应内容和响应状态码
  66. ctx.success({ data });
  67. }
  68. }
  69. async sum() {
  70. const { ctx, service } = this;
  71. // 校验参数 组装参数
  72. const payload = ctx.validate(this.createRule);
  73. // 调用 Service 进行业务处理
  74. if (ctx.isDev()) {
  75. const kv = {
  76. continuousDrive: {
  77. 0: '0-1',
  78. 1: '1-2',
  79. 2: '2-3',
  80. 3: '3-4',
  81. 4: '4以上',
  82. },
  83. driveStyle: { 稳健型: '稳健型', 一般型: '一般型', 激进型: '激进型' },
  84. drivingSafetyScore: {
  85. 0: '60分以下',
  86. 60: '74-60分',
  87. 80: '89-75分',
  88. 90: '100-90分',
  89. },
  90. energyConservationScore: {
  91. 0: '60分以下',
  92. 60: '74-60分',
  93. 80: '89-75分',
  94. 90: '100-90分',
  95. },
  96. mileageAvg: {
  97. 0: '0-10',
  98. 10: '10-20',
  99. 20: '20-30',
  100. 30: '30-40',
  101. 40: '40-50',
  102. 50: '50-60',
  103. 60: '60-70',
  104. 70: '70-80',
  105. 80: '80-90',
  106. 90: '90-100',
  107. 100: '100-110',
  108. 110: '110-120',
  109. },
  110. };
  111. const data = ctx.getSum(kv[this.ctx.params.id]);
  112. ctx.success({ data });
  113. } else {
  114. const data = await service.drivingBehaviorInfoService2.sum(payload, this.ctx.params.id);
  115. // // // 设置响应内容和响应状态码
  116. ctx.success({ data });
  117. }
  118. }
  119. }
  120. module.exports = UserDrivingController2;