carNumberController.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. 'use strict';
  2. const Controller = require('egg').Controller;
  3. // 车辆数量统计分析管理
  4. class CarNumberController 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. type: [ '1', '2' ], // 类型分为 0日 1月 2年
  12. };
  13. }
  14. // 实销车辆统计分析 实销车辆百分比统计分析 入网车辆总数统计分析
  15. async index() {
  16. const { ctx, service } = this;
  17. // 校验参数 组装参数
  18. const payload = ctx.validate();
  19. // 调用 Service 进行业务处理
  20. if (ctx.isDev()) {
  21. const data = ctx.getDataAdd(payload, { count: item => parseFloat((item.saledCount * 100 / item.count).toFixed(0)),
  22. value: [ 'saledCount', 'count' ] });
  23. ctx.success({ data });
  24. } else {
  25. const data = await service.tVehicleRecordService2.index(payload);
  26. // 设置响应内容和响应状态码
  27. ctx.success({ data });
  28. }
  29. }
  30. // 在线车辆分布统计分析
  31. async online() {
  32. const { ctx, service } = this;
  33. // 校验参数 组装参数
  34. const payload = ctx.validate();
  35. // 调用 Service 进行业务处理
  36. if (ctx.isDev()) {
  37. const data = ctx.getData(payload);
  38. ctx.success({ data });
  39. } else {
  40. const data = await service.tVehicleRecordService2.online(payload);
  41. // 设置响应内容和响应状态码
  42. ctx.success({ data });
  43. }
  44. }
  45. // 活跃车辆
  46. async active() {
  47. const { ctx, service } = this;
  48. // 校验参数 组装参数
  49. const payload = ctx.validate(this.createRule);
  50. // 调用 Service 进行业务处理
  51. if (ctx.isDev()) {
  52. const data = ctx.getDataAdd(payload, { count: item => item.count - item.activeCount,
  53. value: [ 'activeCount', 'count' ] });
  54. ctx.success({ data });
  55. } else {
  56. const data = await service.tVehicleRecordService2.active(payload);
  57. // 设置响应内容和响应状态码
  58. ctx.success({ data });
  59. }
  60. }
  61. // 车辆上报分类信息统计
  62. async report() {
  63. const { ctx, service } = this;
  64. // 校验参数 组装参数
  65. const payload = ctx.validate();
  66. // 调用 Service 进行业务处理
  67. if (ctx.isDev()) {
  68. const data = ctx.getData(payload, { count: item => item.vhl_val_cnt + item.alarm_cnt + item.failure_cnt,
  69. value: [ 'vhl_val_cnt', 'alarm_cnt', 'failure_cnt' ],
  70. });
  71. ctx.success({ data });
  72. } else {
  73. const data = await service.tVehicleReportInfoService.index(payload);
  74. // 设置响应内容和响应状态码
  75. ctx.success({ data });
  76. }
  77. }
  78. async onlineCount() {
  79. const { ctx, service } = this;
  80. // 调用 Service 进行业务处理
  81. if (ctx.isDev()) {
  82. const data = ctx.getOnlineCount();
  83. ctx.success({ data });
  84. } else {
  85. const data = await service.tVehicleOnlineInfoService.onlineCount();
  86. // 设置响应内容和响应状态码
  87. ctx.success({ data });
  88. }
  89. }
  90. async saledCity() {
  91. const { ctx, service } = this;
  92. // 校验参数 组装参数
  93. const payload = ctx.validate({});
  94. // 调用 Service 进行业务处理
  95. if (ctx.isDev()) {
  96. const data = ctx.getSaledCity(payload);
  97. ctx.success({ data });
  98. } else {
  99. const data = await service.tVehicleRecordService2.saledCity(payload);
  100. // 设置响应内容和响应状态码
  101. ctx.success({ data });
  102. }
  103. }
  104. async activeExt() {
  105. const { ctx, service } = this;
  106. // 校验参数 组装参数
  107. const payload = ctx.validate({});
  108. // 调用 Service 进行业务处理
  109. if (ctx.isDev()) {
  110. const data = ctx.getActiveExt(payload);
  111. ctx.success({ data });
  112. } else {
  113. const data = await service.tVehicleRecordService2.activeExt(payload);
  114. // 设置响应内容和响应状态码
  115. ctx.success({ data });
  116. }
  117. }
  118. }
  119. module.exports = CarNumberController;