Browse Source

更新额外数据 文档

z332406259 4 years ago
parent
commit
0d83f1ce9a

+ 1 - 0
app/extend/helper.js

@@ -92,6 +92,7 @@ exports.energyConservationScoreProject = {
 
 // 格式化时间
 exports.formatTime = time => moment(time).format('YYYY-MM-DD HH:mm:ss');
+exports.formatTime2 = time => moment(time).format('YYYY-MM-DD HH:mm:ss.SSS');
 // 获取昨日0:0:0
 exports.yesterday = () => moment().subtract(1, 'days').set('hour', 0)
   .set('minute', 0)

+ 3 - 0
app/model/local/tRbacUserModel.js

@@ -84,6 +84,9 @@ module.exports = app => {
       },
     ],
 
+    newAppSaledTotal: { type: Number }, // 新增app实销,
+    newIviSaledTotal: { type: Number }, // 新增ivi实销
+
   });
 
   return conn.model('TRbacUser', TRbacUserSchema, 'lc_t_rbac_user');

+ 2 - 2
app/router/br05_carNumber.js

@@ -14,9 +14,9 @@ module.exports = app => {
 
   // 实销城市排名
   router.get('/report/carNumber/saledCity', controller.carNumberController.saledCity);
-  // 当前在线车辆数量
+  // 当前在线车辆数量,离线车辆数量
   router.get('/report/carNumber/onlineCount', controller.carNumberController.onlineCount);
-  // 活跃车辆 扩展数据
+  // 扩展数据
   router.get('/report/carNumber/activeExt', controller.carNumberController.activeExt);
 
 };

+ 2 - 7
app/service/TVehicleOnlineInfoService.js

@@ -19,15 +19,10 @@ class TVehicleOnlineInfoService extends Service {
     const result = await ctx.model.TVehicleOnlineInfoModel.find(
       { online_status: 1 })
       .countDocuments();
-    return { count: result };
-  }
-
-  async offlineCount() {
-    const { ctx } = this;
-    const result = await ctx.model.TVehicleOnlineInfoModel.find(
+    const offlineCount = await ctx.model.TVehicleOnlineInfoModel.find(
       { online_status: 0 })
       .countDocuments();
-    return { count: result };
+    return { count: result, offlineCount };
   }
 
   async offline() {

+ 18 - 6
app/service/carService.js

@@ -62,15 +62,27 @@ class CarService extends Service {
     return { list, total };
   }
 
-  // TODO 单次行程列表
-  async listWithTravel() {
-
+  async listWithTravel({ vin, startTime, endTime, pageNumber = 1, pageSize = 10 }) {
+    const { ctx, service } = this;
+    const agg = [
+      { $match: { vin, start_time: { $gte: startTime, $lt: endTime } } },
+      { $unwind: '$mileage_list' },
+      ...ctx.helper.getPageMongo(pageNumber, pageSize),
+    ];
+    const list = await ctx.model.DrivingBehaviorInfoModel.aggregate(agg);
+    const result = await ctx.model.DrivingBehaviorInfoModel.aggregate(
+      [ ...agg, { $count: 'total' }]);
+    let total = 0;
+    if (result && result.length > 0) {
+      total = result[0].total;
+    }
+    return { list, total };
   }
 
-  // TODO 单次充电周期列表
-  async listWithCharging() {
+  // TODO 单次充电周期列表 需明确这段时间的充电周期条数
+  async listWithCharging(param) {
     const { ctx, service } = this;
-    return await service.chargingCycleService.index();
+    return await service.chargingCycleService.index(param);
   }
 
   async indexTrip({ vin, startTime, endTime }) {

+ 22 - 14
app/service/chargingCycleService.js

@@ -23,22 +23,30 @@ class ChargingCycleService extends Service {
   // 	"endId":"xxxx"
   // }
   // 此处endId为上一次查询最后一条记录的ID
-  async index() {
+  async index({ vin, startTime, endTime, pageNumber, pageSize = 10, endId }) {
     const { ctx } = this;
-    const result = await ctx.curl('http://10.120.28.6:60080/test/fawiovconditionquery/iov/analysis/driving-behavior/charging-cycle', {
+    const cond = {};
+    if (endId) {
+      cond.endId = endId;
+    }
+    const result = await ctx.curl(
+      'http://10.120.28.6:60080/test/fawiovconditionquery/iov/analysis/driving-behavior/charging-cycle',
+      {
       // 必须指定 method
-      method: 'POST',
-      // 通过 contentType 告诉 HttpClient 以 JSON 格式发送
-      contentType: 'json',
-      data: {
-        vin: 'ICARTEST2019EV601',
-        pageSize: 10,
-        beginTime: '2020-06-10 00:00:00.000',
-        endTime: '2020-06-10 00:01:03.000',
-      },
-      // 明确告诉 HttpClient 以 JSON 格式处理返回的响应 body
-      dataType: 'json',
-    });
+        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',
+      });
     return result.data;
   }
 

+ 16 - 16
app/service/onlineUserService2.js

@@ -187,26 +187,26 @@ class OnlineUserService2 extends Service {
     if (al && al.length > 0) {
       appLocation = al[0].areas;
     }
-    // const anl = await this.appNewLocation(timeRangData);
-    // if (anl && anl.length > 0) {
-    //   appNewLocation = anl[0].areas;
-    // }
-    // const aal = await this.appActiveLocation(timeRangData);
-    // if (aal && aal.length > 0) {
-    //   appActiveLocation = aal[0].areas;
-    // }
+    const anl = await this.appNewLocation(timeRangData);
+    if (anl && anl.length > 0) {
+      appNewLocation = anl[0].areas;
+    }
+    const aal = await this.appActiveLocation(timeRangData);
+    if (aal && aal.length > 0) {
+      appActiveLocation = aal[0].areas;
+    }
     const il = await this.iviLocation(timeRangData);
     if (il && il.length > 0) {
       iviLocation = il[0].areas;
     }
-    // const inl = await this.iviNewLocation(timeRangData);
-    // if (inl && inl.length > 0) {
-    //   iviNewLocation = inl[0].areas;
-    // }
-    // const ial = await this.iviActiveLocation(timeRangData);
-    // if (ial && ial.length > 0) {
-    //   iviActiveLocation = ial[0].areas;
-    // }
+    const inl = await this.iviNewLocation(timeRangData);
+    if (inl && inl.length > 0) {
+      iviNewLocation = inl[0].areas;
+    }
+    const ial = await this.iviActiveLocation(timeRangData);
+    if (ial && ial.length > 0) {
+      iviActiveLocation = ial[0].areas;
+    }
     initData.end_time = new Date();
 
     await ctx.service.statisticsService.save(ctx.model.Local.OnlineUserModel,

+ 10 - 2
app/service/tRbacUserService.js

@@ -48,15 +48,22 @@ class TRbacUserService extends Service {
       create_date: { $lt: timeRangData.endTime }, user_orgin: 'IVI' });
     const newAppTotal = await this.total({
       create_date: { $gte: timeRangData.startTime, $lt: timeRangData.endTime }, user_orgin: 'APP' });
+    const newAppSaledTotal = await this.total({
+      create_date: { $gte: timeRangData.startTime, $lt: timeRangData.endTime }, user_orgin: 'APP',
+      role_id: ctx.helper.saledRoleId,
+    });
     const newAppSexAndAgeTotal = await this.sex2Age({
       create_date: { $gte: timeRangData.startTime, $lt: timeRangData.endTime }, user_orgin: 'APP' });
     const newIviTotal = await this.total({
       create_date: { $gte: timeRangData.startTime, $lt: timeRangData.endTime }, user_orgin: 'IVI' });
+    const newIviSaledTotal = await this.total({
+      create_date: { $gte: timeRangData.startTime, $lt: timeRangData.endTime }, user_orgin: 'IVI',
+      role_id: ctx.helper.saledRoleId,
+    });
     const newIviSexAndAgeTotal = await this.sex2Age({
       create_date: { $gte: timeRangData.startTime, $lt: timeRangData.endTime }, user_orgin: 'IVI' });
     const activeAppTotal = await this.activeAppTotal(timeRangData);
-    const activeAppSexAndAgeTotal = [];
-    // const activeAppSexAndAgeTotal = await this.activeAppSex2Age(timeRangData);
+    const activeAppSexAndAgeTotal = await this.activeAppSex2Age(timeRangData);
     const activeIviTotal = await this.activeIviTotal(timeRangData);
     const activeIviSexAndAgeTotal = await this.activeIviSex2Age(timeRangData);
     initData.end_time = new Date();
@@ -68,6 +75,7 @@ class TRbacUserService extends Service {
         iviTotal, iviSexAndAgeTotal,
         newIviTotal, newIviSexAndAgeTotal,
         activeIviTotal, activeIviSexAndAgeTotal,
+        newAppSaledTotal, newIviSaledTotal,
       }, isForceUpdate);
   }
 

+ 15 - 11
app/service/tRegisterInfoService.js

@@ -41,26 +41,30 @@ class TRegisterInfoService extends Service {
       { user_orgin: 'APP', role_id: ctx.helper.saledRoleId }).countDocuments();
     const saledIviTotal = await ctx.model.TRbacUserModel.find(
       { user_orgin: 'IVI', role_id: ctx.helper.saledRoleId }).countDocuments();
-    // const user = await ctx.model.Local.TRbacUserModel.find({}, { appTotal: 1, newAppTotal: 1, activeAppTotal: 1,
-    //   iviTotal: 1, newIviTotal: 1, activeIviTotal: 1 }).sort({ create_date: -1 });
+    const user = await ctx.model.Local.TRbacUserModel.find({}, { appTotal: 1, newAppTotal: 1, activeAppTotal: 1,
+      iviTotal: 1, newIviTotal: 1, activeIviTotal: 1, newAppSaledTotal: 1, newIviSaledTotal: 1 }).sort({ create_date: -1 });
     let appTotal = 0;
     let newAppTotal = 0;
     let activeAppTotal = 0;
     let iviTotal = 0;
     let newIviTotal = 0;
     let activeIviTotal = 0;
-    // if (user) {
-    //   appTotal = user.appTotal;
-    //   newAppTotal = user.newAppTotal;
-    //   activeAppTotal = user.activeAppTotal;
-    //   iviTotal = user.iviTotal;
-    //   newIviTotal = user.newIviTotal;
-    //   activeIviTotal = user.activeIviTotal;
-    // }
+    let newAppSaledTotal = 0;
+    let newIviSaledTotal = 0;
+    if (user) {
+      appTotal = user.appTotal;
+      newAppTotal = user.newAppTotal;
+      activeAppTotal = user.activeAppTotal;
+      iviTotal = user.iviTotal;
+      newIviTotal = user.newIviTotal;
+      activeIviTotal = user.activeIviTotal;
+      newAppSaledTotal = user.newAppSaledTotal;
+      newIviSaledTotal = user.newIviSaledTotal;
+    }
     return { maxDay, maxMonth, saledTotal, saledAppTotal, saledIviTotal,
       appTotal, newAppTotal, activeAppTotal,
       iviTotal, newIviTotal, activeIviTotal,
-
+      newAppSaledTotal, newIviSaledTotal,
     };
 
   }

+ 11 - 12
app/service/tVehicleRecordService2.js

@@ -299,15 +299,15 @@ class TVehicleRecordService2 extends Service {
 
   async activeCount(timeRangData) {
     const { ctx } = this;
-    // const onlineAgg = [
-    //   { $match: { ...ctx.helper.getTimeRangMatch(ctx.helper.getMonthTop(timeRangData.startTime), timeRangData.endTime,
-    //     'online_time') } },
-    //   { $group: {
-    //     _id: '$vin',
-    //     login_count: { $sum: 1 },
-    //   } },
-    //   { $match: { login_count: { $gt: 3 } } },
-    // ];
+    const onlineAgg = [
+      { $match: { ...ctx.helper.getTimeRangMatch(ctx.helper.getMonthTop(timeRangData.startTime), timeRangData.endTime,
+        'online_time') } },
+      { $group: {
+        _id: '$vin',
+        login_count: { $sum: 1 },
+      } },
+      { $match: { login_count: { $gt: 3 } } },
+    ];
     const driveAgg = [
       { $match: ctx.helper.getTimeRangMatch(ctx.helper.getMonthTop(timeRangData.startTime), timeRangData.endTime,
         'start_time') },
@@ -315,8 +315,7 @@ class TVehicleRecordService2 extends Service {
         mileage: { $sum: { $cond: [ '$mileage', { $toDouble: '$mileage' }, 0 ] } } } },
       { $match: { mileage: { $gt: 50 } } },
     ];
-    const result1 = [];
-    // const result1 = await ctx.model.TBoxOnlineModel.aggregate(onlineAgg);
+    const result1 = await ctx.model.TBoxOnlineModel.aggregate(onlineAgg);
     const result2 = await ctx.model.DrivingBehaviorInfoModel.aggregate(driveAgg);
     const unionArray = ctx.helper.unionArray(result1.map(item => item._id), result2.map(item => item._id));
 
@@ -324,7 +323,7 @@ class TVehicleRecordService2 extends Service {
       { $match: { vin: { $in: unionArray } } },
       { $group: { _id: { series_code: '$series_code', model_code: '$model_code' },
         count: { $sum: 1 },
-        // activeCount: { $sum: { $cond: [{ $in: [ '$vin', unionArray ] }, 1, 0 ] } },
+        activeCount: { $sum: { $cond: [{ $in: [ '$vin', unionArray ] }, 1, 0 ] } },
       } },
     ];
     return await ctx.model.TVehicleRecordModel.aggregate(agg);