vehicleDrivingController2.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. async index() {
  15. const { ctx, service } = this;
  16. // 校验参数 组装参数
  17. const payload = ctx.validate();
  18. // // 调用 Service 进行业务处理
  19. if (ctx.isDev()) {
  20. const data = ctx.getMix(payload, this.ctx.params.id);
  21. ctx.success({ data });
  22. } else {
  23. const data = await service.drivingBehaviorInfoService2.index(payload, this.ctx.params.id);
  24. // // 设置响应内容和响应状态码
  25. ctx.success({data});
  26. }
  27. }
  28. async avgSpeedPower() {
  29. const { ctx, service } = this;
  30. // 校验参数 组装参数
  31. const payload = ctx.validate();
  32. // // 调用 Service 进行业务处理
  33. if (ctx.isDev()) {
  34. const data = ctx.getMix(payload, 'avgSpeedPower');
  35. ctx.success({ data });
  36. } else {
  37. const data = await service.drivingBehaviorInfoService2.avg(payload, 'avgSpeedPower');
  38. // // 设置响应内容和响应状态码
  39. ctx.success({data});
  40. }
  41. }
  42. async avgOil() {
  43. const { ctx, service } = this;
  44. // 校验参数 组装参数
  45. const payload = ctx.validate(this.createRule);
  46. // 调用 Service 进行业务处理
  47. if (ctx.isDev()) {
  48. const data = ctx.getLevel(payload);
  49. ctx.success({ data });
  50. } else {
  51. const data = await service.drivingBehaviorInfoService2.avgOil(payload);
  52. // // // 设置响应内容和响应状态码
  53. ctx.success({data});
  54. }
  55. }
  56. async chargeType() {
  57. const { ctx, service } = this;
  58. // 校验参数 组装参数
  59. const payload = ctx.validate();
  60. // // 调用 Service 进行业务处理、
  61. if (ctx.isDev()) {
  62. const data = ctx.getSum({
  63. 1: '32A交流充电',
  64. 2: '16A交流充电',
  65. 3: '10A交流充电',
  66. 4: '直流充电',
  67. 5: '63A交流充电',
  68. });
  69. ctx.success({ data });
  70. } else {
  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. if (ctx.isDev()) {
  82. const data = ctx.getData(payload);
  83. ctx.success({ data });
  84. } else {
  85. const data = await service.drivingBehaviorInfoService2.count(payload, this.ctx.params.id);
  86. // // 设置响应内容和响应状态码
  87. ctx.success({data});
  88. }
  89. }
  90. }
  91. module.exports = VehicleDrivingController2;