Forráskód Böngészése

状态机接口 初步业务整理

z332406259 4 éve
szülő
commit
a9df07dc78

+ 4 - 0
app/controller/carController.js

@@ -18,11 +18,15 @@ class CarController extends Controller {
       // 分为2种   driving_safety_score驾驶得分(默认)  energyConservationScore节能得分
     };
     this.createIndexRule = {
+      pageNumber: { type: 'number', required: false },
+      pageSize: { type: 'number', required: false },
       startTime: { type: 'number', min: 0 }, // 开始时间的时间戳  包含
       endTime: { type: 'number', min: 0 }, // 结束时间的时间戳  不包含(客户端处理结束时间  下一日 ,下一月第一日 ,下一年第一日)
       vin: { type: 'string' }, // 车辆vin
     };
     this.createVinRule = {
+      startTime: { type: 'number', min: 0, required: false }, // 开始时间的时间戳  包含
+      endTime: { type: 'number', min: 0, required: false }, // 结束时间的时间戳  不包含(客户端处理结束时间  下一日 ,下一月第一日 ,下一年第一日)
       vin: { type: 'string' }, // 车辆vin
     };
   }

+ 5 - 5
app/controller/carStatusCloudController.js

@@ -21,7 +21,7 @@ class CarStatusCloudController extends Controller {
     // 校验参数 组装参数
     const payload = ctx.validate(this.createRule);
     // // 调用 Service 进行业务处理
-    const data = payload;
+    const data = service.tFsmHitoryService.danger(payload);
     // // 设置响应内容和响应状态码
     ctx.success({ data });
   }
@@ -31,7 +31,7 @@ class CarStatusCloudController extends Controller {
     // 校验参数 组装参数
     const payload = ctx.validate(this.createRule);
     // // 调用 Service 进行业务处理
-    const data = payload;
+    const data = service.tFsmHitoryService.normal(payload);
     // // 设置响应内容和响应状态码
     ctx.success({ data });
   }
@@ -41,7 +41,7 @@ class CarStatusCloudController extends Controller {
     // 校验参数 组装参数
     const payload = ctx.validate(this.createRule);
     // // 调用 Service 进行业务处理
-    const data = payload;
+    const data = service.tFsmHitoryService.fault(payload);
     // // 设置响应内容和响应状态码
     ctx.success({ data });
   }
@@ -51,7 +51,7 @@ class CarStatusCloudController extends Controller {
     // 校验参数 组装参数
     const payload = ctx.validate(this.createRule);
     // // 调用 Service 进行业务处理
-    const data = payload;
+    const data = service.tFsmHitoryService.intelligence(payload);
     // // 设置响应内容和响应状态码
     ctx.success({ data });
   }
@@ -61,7 +61,7 @@ class CarStatusCloudController extends Controller {
     // 校验参数 组装参数
     const payload = ctx.validate(this.createRule);
     // // 调用 Service 进行业务处理
-    const data = payload;
+    const data = service.tFsmHitoryService.intelligenceMix(payload);
     // // 设置响应内容和响应状态码
     ctx.success({ data });
   }

+ 1 - 1
app/schedule/updateData.js

@@ -22,7 +22,7 @@ class UpdateData extends Subscription {
     // const result = await this.app.getHistoryModel('2006').find({}).limit(10);
     // this.app.logger.info(result);
     // await this.doTask();
-    await this.roundTask();
+    // await this.roundTask();
     await this.endTask();
   }
 

+ 44 - 6
app/service/TVehicleOnlineInfoService.js

@@ -34,18 +34,56 @@ class TVehicleOnlineInfoService extends Service {
     return result;
   }
 
-  // TODO 获取当前车需要的所有数据
+
   async liveStatus({ vin }) {
     const { ctx, service } = this;
-    const result = await service.redisService.hget(vin);
-    return result;
+    const online_status = await service.redisService.hget(vin, 'ONLINE_STATUS');
+    const running_status = await service.redisService.hget(vin, 'RUNNING_STATUS');
+    const network_status = await service.redisService.hget(vin, 'NETWORK_STATUS');
+    const failure_status = await service.redisService.hget(vin, 'FAILURE_STATUS');
+    const electric_status = await service.redisService.hget(vin, 'ELECTRIC_STATUS');
+    const dsm_status = await service.redisService.hget(vin, 'ANALYSIS_DSM_STATUS');
+    const speeding_status = await service.redisService.hget(vin, 'ANALYSIS_SPEEDING_STATUS');
+    const un_tie_sb_status = await service.redisService.hget(vin, 'ANALYSIS_UN_TIE_SB_STATUS');
+    const leave_sw_status = await service.redisService.hget(vin, 'ANALYSIS_LEAVE_SW_STATUS');
+    const acceleration_status = await service.redisService.hget(vin, 'ANALYSIS_ACCELERATION_STATUS');
+    const decelerate_status = await service.redisService.hget(vin, 'ANALYSIS_DECELERATE_STATUS');
+    const turn_status = await service.redisService.hget(vin, 'ANALYSIS_TURN_STATUS');
+    const clu_status = await service.redisService.hget(vin, 'ANALYSIS_CLU_STATUS');
+    const safety_air_bag_status = await service.redisService.hget(vin, 'ANALYSIS_SAFETY_AIR_BAG_STATUS');
+    const lka_status = await service.redisService.hget(vin, 'ANALYSIS_LKA_STATUS');
+    const ldw_status = await service.redisService.hget(vin, 'ANALYSIS_LDW_STATUS');
+    const bsd_status = await service.redisService.hget(vin, 'ANALYSIS_BSD_STATUS');
+    const fcw_status = await service.redisService.hget(vin, 'ANALYSIS_FCW_STATUS');
+    const fault_status = await service.redisService.hget(vin, 'ANALYSIS_FAULT_STATUS');
+
+
+    const v_parking = await service.redisService.hget(vin, '_S0210');// 第一个数值 [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ]
+    const acc = await service.redisService.hget(vin, '_S0508');
+    let idriving_status = 0;
+    const v_dict = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ];
+    if ((acc && acc.length > 0) || (v_parking && v_parking.length > 0 && v_dict.indexOf(v_parking[1])!=-1) ){
+      idriving_status = 1;
+    }
+    const traffic = await service.redisService.hget(vin, '_S0558');// 第二个数值 0:无效;1:严重拥堵;2:中度拥堵;3:轻度拥堵;4:畅通拥堵;5:高速行驶
+    const event = await service.redisService.hget(vin, 'EVENT0818');
+    // 取event里_S0100 - _S0169 的对应值  0基本是正常,具体看文档
+    return { online_status, running_status, network_status, failure_status, electric_status, dsm_status, speeding_status,
+      un_tie_sb_status, leave_sw_status, acceleration_status, decelerate_status, turn_status, clu_status, safety_air_bag_status,
+      lka_status, ldw_status, bsd_status, fcw_status, fault_status, idriving_status, traffic, event };
   }
 
-  // TODO 获取当前车 历史轨迹
   async travel({ vin, startTime, endTime }) {
     const { ctx } = this;
-    // const result = await ctx.model.RedisSerive.hget(vin);
-    // return result;
+    const agg = [
+      { $match: { ...ctx.helper.getTimeRangMatch(startTime,
+        endTime, 'timeStamp'), vin, _S0000: { $exists: true } } },
+      { $project: {
+        longitude: { $arrayElemAt: [ '$_S0000', 1 ] },
+        latitude: { $arrayElemAt: [ '$_S0000', 2 ] },
+      } },
+    ];
+    return await this.app.getHistoryModel('2006').aggregate(agg);
   }
 
 

+ 1 - 0
app/service/carService.js

@@ -67,6 +67,7 @@ class CarService extends Service {
     const agg = [
       { $match: { start_time: { $gte: startTime, $lt: endTime }, vin } },
       { $unwind: '$mileage_list' },
+      { $replaceRoot: { newRoot: '$mileage_list' } },
       ...ctx.helper.getPageMongo(pageNumber, pageSize),
     ];
     const list = await ctx.model.DrivingBehaviorInfoModel.aggregate(agg);

+ 4 - 4
app/service/iviBehaviorRecordService.js

@@ -122,16 +122,16 @@ class IviBehaviorRecordService extends Service {
     const iviBehavior = await this.group(timeRangData);
     iviBehavior.forEach(item => {
       switch (item._id) {
-        case 20020000:
+        case 20020001:
           musicTotal = item.count;
           break;
-        case 20010000:
+        case 20010001:
           fwTotal = item.count;
           break;
-        case 20050000:
+        case 20050001:
           newsTotal = item.count;
           break;
-        case 20030000:
+        case 20030001:
           videoTotal = item.count;
           break;
         default:

+ 3 - 2
app/service/redisService.js

@@ -5,10 +5,11 @@ const Service = require('egg').Service;
 // redis服务
 class RedisService extends Service {
 
-  async hget() {
+  async hget(vin, filed) {
     let data;
     if (this.app.redis) {
-      data = await this.app.redis.hget('faw:iov:fsm:broker:TEST0000000076257', 'SERIES_CODE');
+      // data = await this.app.redis.hget('faw:iov:fsm:broker:TEST0000000076257', 'SERIES_CODE');
+      data = await this.app.redis.hget(`faw:iov:fsm:broker:${vin}`, filed);
     }
     return data;
   }

+ 26 - 0
app/service/tFsmHitoryService.js

@@ -5,6 +5,32 @@ const Service = require('egg').Service;
 // 状态机历史数据服务
 class TFsmHitoryService extends Service {
 
+  async danger() {
+    const { ctx } = this;
+    return [];
+  }
+
+  async normal() {
+    const { ctx } = this;
+    return [];
+  }
+
+  async fault() {
+    const { ctx } = this;
+    return [];
+  }
+
+  async intelligence() {
+    const { ctx } = this;
+    return [];
+  }
+
+  async intelligenceMix() {
+    const { ctx } = this;
+    return [];
+  }
+
+
   async statistics({ timeRangData, initData, isForceUpdate }) {
     const { ctx } = this;
     const hasData = await ctx.service.statisticsService.saveBefore(ctx.model.Local.TFsmHitoryModel,