123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- 'use strict';
- const Service = require('egg').Service;
- // 其他 业务 转接服务
- class OtherService extends Service {
- async chargingCycle({ vin, startTime, endTime, pageSize = 10, endId }) {
- const { ctx } = this;
- const cond = {};
- if (endId) {
- cond.endId = endId;
- }
- let result;
- let data;
- try {
- result = await ctx.curl(
- this.app.config.chargingCycleApi,
- {
- // 必须指定 method
- method: 'POST',
- // 通过 contentType 告诉 HttpClient 以 JSON 格式发送
- contentType: 'json',
- data: {
- // vin: 'ICARTEST2019EV601',
- vin,
- pageSize,
- beginTime: ctx.helper.formatTime2(startTime),
- endTime: ctx.helper.formatTime2(endTime),
- ...cond,
- },
- // 明确告诉 HttpClient 以 JSON 格式处理返回的响应 body
- dataType: 'json',
- });
- } catch (e) {
- throw new Error(e.message || '');
- }
- if (result.status == 200) {
- if (result.data.code == 200) {
- data = result.data.data;
- } else {
- throw new Error(result.data.msg || '');
- }
- } else {
- throw new Error(result.status + ':' + (result.data.message || ''));
- }
- return data;
- }
- async rbac({ token }) {
- const { ctx } = this;
- let result;
- let data;
- try {
- result = await ctx.curl(`${this.app.config.rbacApi}?token=${token}`, { dataType: 'json' });
- } catch (e) {
- throw new Error(e.message || '');
- }
- if (result.status == 200) {
- if (result.data.retCode == 200) {
- data = result.data.responseData.permission;
- } else {
- throw new Error(result.data.responseData || '');
- }
- } else {
- throw new Error(result.status + ' ' + (result.data.message || ''));
- }
- return data;
- }
- async travel({ vin, startTime, endTime, pageSize = 10000, endId }) {
- const { ctx } = this;
- const cond = {};
- if (endId) {
- cond.endId = endId;
- }
- let result;
- let data;
- try {
- result = await ctx.curl(
- this.app.config.travelApi,
- {
- // 必须指定 method
- method: 'POST',
- // 通过 contentType 告诉 HttpClient 以 JSON 格式发送
- contentType: 'json',
- data: {
- // vin: 'ICARTEST2019EV601',
- vin,
- pageSize,
- beginTime: ctx.helper.formatTime2(startTime),
- endTime: ctx.helper.formatTime2(endTime),
- ...cond,
- },
- // 明确告诉 HttpClient 以 JSON 格式处理返回的响应 body
- dataType: 'json',
- });
- } catch (e) {
- throw new Error(e.message || '');
- }
- if (result.status == 200) {
- if (result.data.code == 200) {
- data = result.data.data;
- } else {
- throw new Error(result.data.msg || '');
- }
- } else {
- throw new Error(result.status + ':' + (result.data.message || ''));
- }
- return data;
- }
- }
- module.exports = OtherService;
- // id:主键
- // vin:VIN号
- // createTime:创建时间
- // series:车系
- // startTime:充电开始时间
- // endTime:充电结束时间
- // cycleStartTime:周期开始时间
- // cycleEndTime:周期结束时间
- // startElectricity:充电开始时剩余电量(百分比值)
- // endElectricity:充电结束时剩余电量(百分比值)
- // voltage:充电电压
- // current:充电电流
- // temperature:充电环境温度
- // chargeDuration:充电时长(毫秒)
- // connectTime:满电后充电枪连接时长(毫秒)
- // driveDuration:行驶时长(毫秒)
- // mileage:行驶里程(km)
- // mileageCnt:行程数
- // avgPowerConsumption:平均电耗
- // avgSpeed:平均行驶速度(km/h)
- // airDuration:空调使用时长
- // airAvgDegrees:空调温度
- // outAvgDegrees:外部环境温度
- // differenceDegrees:平均温差(车外温度-空调温度)
- // accelerationCnt:急加速次数
- // accelerationDuration:急加速持续时长(秒)
- // decelerateCnt:急减速次数
- // decelerateDuration:急减速持续时长(秒)
- // turnCnt:急转弯次数
- // turnDuration:急转弯持续时长(秒)
- // speedingCnt:超速次数
- // speedingDuration:超速时长(秒)
- // unTieSbStatus:未系安全带状态 0-否 1-是
- // unTieSbDuration:未系安全带持续时间(秒)
- // dsmStatus:疲劳驾驶状态 0-否 1-是
- // dsmDuration:疲劳驾驶持续时长(秒)
- // faultStatus:故障行驶状态 0-否 1-是
- // faultDuration:故障行驶持续时长(秒)
- // leaveSwCnt:双手离开方向盘次数
- // totalScore:总得分
- // saProportion:平稳加速里程占比
- // sdProportion:平稳减速里程占比
- // steadyProportion:稳定车速里程占比
|