otherService.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. 'use strict';
  2. const Service = require('egg').Service;
  3. // 其他 业务 转接服务
  4. class OtherService extends Service {
  5. async chargingCycle({ vin, startTime, endTime, pageSize = 10, endId }) {
  6. const { ctx } = this;
  7. const cond = {};
  8. if (endId) {
  9. cond.endId = endId;
  10. }
  11. let result;
  12. let data;
  13. try {
  14. result = await ctx.curl(
  15. this.app.config.chargingCycleApi,
  16. {
  17. // 必须指定 method
  18. method: 'POST',
  19. // 通过 contentType 告诉 HttpClient 以 JSON 格式发送
  20. contentType: 'json',
  21. data: {
  22. // vin: 'ICARTEST2019EV601',
  23. vin,
  24. pageSize,
  25. beginTime: ctx.helper.formatTime2(startTime),
  26. endTime: ctx.helper.formatTime2(endTime),
  27. ...cond,
  28. },
  29. // 明确告诉 HttpClient 以 JSON 格式处理返回的响应 body
  30. dataType: 'json',
  31. });
  32. } catch (e) {
  33. throw new Error(e.message || '');
  34. }
  35. if (result.status == 200) {
  36. if (result.data.code == 200) {
  37. data = result.data.data;
  38. } else {
  39. throw new Error(result.data.msg || '');
  40. }
  41. } else {
  42. throw new Error(result.status + ':' + (result.data.message || ''));
  43. }
  44. return data;
  45. }
  46. async rbac({ token }) {
  47. const { ctx } = this;
  48. let result;
  49. let data;
  50. try {
  51. result = await ctx.curl(`${this.app.config.rbacApi}?token=${token}`, { dataType: 'json' });
  52. } catch (e) {
  53. throw new Error(e.message || '');
  54. }
  55. if (result.status == 200) {
  56. if (result.data.retCode == 200) {
  57. data = result.data.responseData.permission;
  58. } else {
  59. throw new Error(result.data.responseData || '');
  60. }
  61. } else {
  62. throw new Error(result.status + ' ' + (result.data.message || ''));
  63. }
  64. return data;
  65. }
  66. async travel({ vin, startTime, endTime, pageSize = 10000, endId }) {
  67. const { ctx } = this;
  68. const cond = {};
  69. if (endId) {
  70. cond.endId = endId;
  71. }
  72. let result;
  73. let data;
  74. try {
  75. result = await ctx.curl(
  76. this.app.config.travelApi,
  77. {
  78. // 必须指定 method
  79. method: 'POST',
  80. // 通过 contentType 告诉 HttpClient 以 JSON 格式发送
  81. contentType: 'json',
  82. data: {
  83. // vin: 'ICARTEST2019EV601',
  84. vin,
  85. pageSize,
  86. beginTime: ctx.helper.formatTime2(startTime),
  87. endTime: ctx.helper.formatTime2(endTime),
  88. ...cond,
  89. },
  90. // 明确告诉 HttpClient 以 JSON 格式处理返回的响应 body
  91. dataType: 'json',
  92. });
  93. } catch (e) {
  94. throw new Error(e.message || '');
  95. }
  96. if (result.status == 200) {
  97. if (result.data.code == 200) {
  98. data = result.data.data;
  99. } else {
  100. throw new Error(result.data.msg || '');
  101. }
  102. } else {
  103. throw new Error(result.status + ':' + (result.data.message || ''));
  104. }
  105. return data;
  106. }
  107. }
  108. module.exports = OtherService;
  109. // id:主键
  110. // vin:VIN号
  111. // createTime:创建时间
  112. // series:车系
  113. // startTime:充电开始时间
  114. // endTime:充电结束时间
  115. // cycleStartTime:周期开始时间
  116. // cycleEndTime:周期结束时间
  117. // startElectricity:充电开始时剩余电量(百分比值)
  118. // endElectricity:充电结束时剩余电量(百分比值)
  119. // voltage:充电电压
  120. // current:充电电流
  121. // temperature:充电环境温度
  122. // chargeDuration:充电时长(毫秒)
  123. // connectTime:满电后充电枪连接时长(毫秒)
  124. // driveDuration:行驶时长(毫秒)
  125. // mileage:行驶里程(km)
  126. // mileageCnt:行程数
  127. // avgPowerConsumption:平均电耗
  128. // avgSpeed:平均行驶速度(km/h)
  129. // airDuration:空调使用时长
  130. // airAvgDegrees:空调温度
  131. // outAvgDegrees:外部环境温度
  132. // differenceDegrees:平均温差(车外温度-空调温度)
  133. // accelerationCnt:急加速次数
  134. // accelerationDuration:急加速持续时长(秒)
  135. // decelerateCnt:急减速次数
  136. // decelerateDuration:急减速持续时长(秒)
  137. // turnCnt:急转弯次数
  138. // turnDuration:急转弯持续时长(秒)
  139. // speedingCnt:超速次数
  140. // speedingDuration:超速时长(秒)
  141. // unTieSbStatus:未系安全带状态 0-否 1-是
  142. // unTieSbDuration:未系安全带持续时间(秒)
  143. // dsmStatus:疲劳驾驶状态 0-否 1-是
  144. // dsmDuration:疲劳驾驶持续时长(秒)
  145. // faultStatus:故障行驶状态 0-否 1-是
  146. // faultDuration:故障行驶持续时长(秒)
  147. // leaveSwCnt:双手离开方向盘次数
  148. // totalScore:总得分
  149. // saProportion:平稳加速里程占比
  150. // sdProportion:平稳减速里程占比
  151. // steadyProportion:稳定车速里程占比