carHeatController.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. 'use strict';
  2. const Controller = require('egg').Controller;
  3. // 车辆热力分布
  4. class CarHeatController 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. this.createVinRule = {
  13. vin: { type: 'string' }, // 车辆vin
  14. longitude: { type: 'number' }, // 经度
  15. latitude: { type: 'number' }, // 纬度
  16. };
  17. this.createTravelRule = {
  18. vin: { type: 'string' }, // 车辆vin
  19. pageNumber: { type: 'number', min: 0, required: false },
  20. pageSize: { type: 'number', min: 0, required: false },
  21. startTime: { type: 'number', min: 0 }, // 开始时间的时间戳 包含
  22. endTime: { type: 'number', min: 0 }, // 结束时间的时间戳 不包含(客户端处理结束时间 下一日 ,下一月第一日 ,下一年第一日)
  23. };
  24. }
  25. // 实销车分布
  26. async saled() {
  27. const { ctx, service } = this;
  28. // 校验参数 组装参数
  29. const payload = ctx.validate({});
  30. // 调用 Service 进行业务处理
  31. if (ctx.isDev()) {
  32. const data = ctx.getSaled(payload);
  33. ctx.success({ data });
  34. } else {
  35. const data = await service.tVehicleRecordService2.saled(payload);
  36. // 设置响应内容和响应状态码
  37. ctx.success({ data });
  38. }
  39. }
  40. // 在线车分布
  41. async online() {
  42. const { ctx, service } = this;
  43. // 调用 Service 进行业务处理
  44. if (ctx.isDev()) {
  45. const data = ctx.getMapP();
  46. ctx.success({ data });
  47. } else {
  48. const data = await service.tVehicleOnlineInfoService.online();
  49. // 设置响应内容和响应状态码
  50. ctx.success({ data });
  51. }
  52. }
  53. // 离线车分布
  54. async offline() {
  55. const { ctx, service } = this;
  56. // 调用 Service 进行业务处理
  57. if (ctx.isDev()) {
  58. const data = ctx.getMapP();
  59. ctx.success({ data });
  60. } else {
  61. const data = await service.tVehicleOnlineInfoService.offline();
  62. // 设置响应内容和响应状态码
  63. ctx.success({ data });
  64. }
  65. }
  66. // 实时快照
  67. async liveStatus() {
  68. const { ctx, service } = this;
  69. // 校验参数 组装参数
  70. const payload = ctx.validate(this.createVinRule);
  71. // 调用 Service 进行业务处理
  72. if (ctx.isDev()) {
  73. const data = { address: '吉林省长春市南关区', online_status: '1', car: '下电,网络故障', behavior: '急加速',
  74. danger: '安全气囊弹出', idriving_status: '手动驾驶状态', traffic: '1', event: '发动机常见故障,电气系统常见故障' };
  75. ctx.success({ data });
  76. } else {
  77. const data = await service.tVehicleOnlineInfoService.liveStatus(payload);
  78. // 设置响应内容和响应状态码
  79. ctx.success({ data });
  80. }
  81. }
  82. // 历史轨迹
  83. async travel() {
  84. const { ctx, service } = this;
  85. // 校验参数 组装参数
  86. const payload = ctx.validate(this.createTravelRule);
  87. // 调用 Service 进行业务处理
  88. if (ctx.isDev()) {
  89. const data = ctx.getMapP(10);
  90. ctx.success({ data });
  91. } else {
  92. const data = await service.tVehicleOnlineInfoService.travel(payload);
  93. // 设置响应内容和响应状态码
  94. ctx.success({ data });
  95. }
  96. }
  97. // 活跃车分布
  98. async active() {
  99. const { ctx, service } = this;
  100. // 校验参数 组装参数
  101. const payload = ctx.validate(this.createRule);
  102. // 调用 Service 进行业务处理
  103. if (ctx.isDev()) {
  104. const data = ctx.getSaled(payload);
  105. ctx.success({ data });
  106. } else {
  107. const data = await service.tVehicleRecordService2.activeLocation(payload);
  108. // 设置响应内容和响应状态码
  109. ctx.success({ data });
  110. }
  111. }
  112. }
  113. module.exports = CarHeatController;