vehicleDrivingController2.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. 'use strict';
  2. const Controller = require('egg').Controller;
  3. // 车辆行驶数据分析模块
  4. class VehicleDrivingController2 extends Controller {
  5. constructor(ctx) {
  6. super(ctx);
  7. // 特殊的入参校验可以重写在这,默认可以使用commonRule
  8. this.createRule = {
  9. level: [ 'province', 'city' ], // 查询等级:省份,城市
  10. startTime: { type: 'number', min: 0 }, // 开始时间的时间戳 包含
  11. endTime: { type: 'number', min: 0 }, // 结束时间的时间戳 不包含(客户端处理结束时间 下一日 ,下一月第一日 ,下一年第一日)
  12. };
  13. }
  14. // 驾驶行为 基础
  15. async index() {
  16. const { ctx, service } = this;
  17. // 校验参数 组装参数
  18. const payload = ctx.validate();
  19. // // 调用 Service 进行业务处理
  20. const data = await service.drivingBehaviorInfoService2.index(payload, this.ctx.params.id);
  21. // // 设置响应内容和响应状态码
  22. ctx.success({ data });
  23. }
  24. // 驾驶行为 月年
  25. async mixMY() {
  26. const { ctx, service } = this;
  27. // 校验参数 组装参数
  28. const payload = ctx.validate();
  29. // // 调用 Service 进行业务处理
  30. let key = this.ctx.params.id;
  31. switch (payload.type) {
  32. case '1':
  33. key += 'Month';
  34. break;
  35. case '2':
  36. key += 'Year';
  37. break;
  38. default:
  39. break;
  40. }
  41. const data = await service.drivingBehaviorInfoService2.mixMY(payload, key);
  42. // // 设置响应内容和响应状态码
  43. ctx.success({ data });
  44. }
  45. // 驾驶行为 不同车速下耗电量
  46. async avgSpeedPower() {
  47. const { ctx, service } = this;
  48. // 校验参数 组装参数
  49. const payload = ctx.validate();
  50. // // 调用 Service 进行业务处理
  51. const data = await service.drivingBehaviorInfoService2.avg(payload, 'avgSpeedPower');
  52. // // 设置响应内容和响应状态码
  53. ctx.success({ data });
  54. }
  55. // 驾驶行为 油耗
  56. async avgOil() {
  57. const { ctx, service } = this;
  58. // 校验参数 组装参数
  59. const payload = ctx.validate(this.createRule);
  60. // 调用 Service 进行业务处理
  61. const data = await service.drivingBehaviorInfoService2.avgOil(payload);
  62. // // // 设置响应内容和响应状态码
  63. ctx.success({ data });
  64. }
  65. // 驾驶行为 充电模式
  66. async chargeType() {
  67. const { ctx, service } = this;
  68. // 校验参数 组装参数
  69. const payload = ctx.validate();
  70. // // 调用 Service 进行业务处理
  71. const data = await service.drivingBehaviorInfoService2.sum(payload, 'chargeType');
  72. // // 设置响应内容和响应状态码
  73. ctx.success({ data });
  74. }
  75. // 驾驶行为 平均量
  76. async count() {
  77. const { ctx, service } = this;
  78. // 校验参数 组装参数
  79. const payload = ctx.validate();
  80. // // 调用 Service 进行业务处理
  81. const data = await service.drivingBehaviorInfoService2.count(payload, this.ctx.params.id);
  82. // // 设置响应内容和响应状态码
  83. ctx.success({ data });
  84. }
  85. }
  86. module.exports = VehicleDrivingController2;