浏览代码

修改实销用户的数据来源

z332406259 4 年之前
父节点
当前提交
d550e2a490

+ 13 - 10
app/controller/carController.js

@@ -8,27 +8,31 @@ class CarController extends Controller {
   constructor(ctx) {
     super(ctx);
     this.createRule = {
-      pageNumber: { type: 'number', required: false },
-      pageSize: { type: 'number', required: false },
-      startTime: { type: 'number', min: 0, required: false }, // 开始时间的时间戳  包含
-      endTime: { type: 'number', min: 0, required: false }, // 结束时间的时间戳  不包含(客户端处理结束时间  下一日 ,下一月第一日 ,下一年第一日)
+      pageNumber: { type: 'number', min: 0, required: false },
+      pageSize: { type: 'number', min: 0, required: false },
+      startTime: { type: 'number', min: 0 }, // 开始时间的时间戳  包含
+      endTime: { type: 'number', min: 0 }, // 结束时间的时间戳  不包含(客户端处理结束时间  下一日 ,下一月第一日 ,下一年第一日)
 
       mode: { type: 'string', required: false }, // 分为4种  0代表0-60  1代表60-75  2代表75-90  3代表90-100
       modeKey: { type: 'string', required: false },
       // 分为2种   driving_safety_score驾驶得分(默认)  energyConservationScore节能得分
     };
     this.createIndexRule = {
-      pageNumber: { type: 'number', required: false },
-      pageSize: { type: 'number', required: false },
+      pageNumber: { type: 'number', min: 0, required: false },
+      pageSize: { type: 'number', min: 0, 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 }, // 结束时间的时间戳  不包含(客户端处理结束时间  下一日 ,下一月第一日 ,下一年第一日)
+      startTime: { type: 'number', min: 0 }, // 开始时间的时间戳  包含
+      endTime: { type: 'number', min: 0 }, // 结束时间的时间戳  不包含(客户端处理结束时间  下一日 ,下一月第一日 ,下一年第一日)
       vin: { type: 'string' }, // 车辆vin
     };
+    this.createListRule = {
+      pageNumber: { type: 'number', min: 0, required: false },
+      pageSize: { type: 'number', min: 0, required: false },
+    };
   }
 
   //  单车  用户驾驶评分分布/节能驾驶评分分布 列表
@@ -48,8 +52,7 @@ class CarController extends Controller {
     const { ctx, service } = this;
 
     // 校验参数 组装参数
-    const payload = ctx.validate({ pageNumber: { type: 'number', required: false },
-      pageSize: { type: 'number', required: false } });
+    const payload = ctx.validate(this.createListRule);
     // 调用 Service 进行业务处理
     const data = await service.carService.list(payload);
     // 设置响应内容和响应状态码

+ 4 - 4
app/controller/carHeatController.js

@@ -18,10 +18,10 @@ class CarHeatController extends Controller {
 
     this.createTravelRule = {
       vin: { type: 'string' }, // 车辆vin
-      pageNumber: { type: 'number', required: false },
-      pageSize: { type: 'number', required: false },
-      startTime: { type: 'number', min: 0, required: false }, // 开始时间的时间戳  包含
-      endTime: { type: 'number', min: 0, required: false }, // 结束时间的时间戳  不包含(客户端处理结束时间  下一日 ,下一月第一日 ,下一年第一日)
+      pageNumber: { type: 'number', min: 0, required: false },
+      pageSize: { type: 'number', min: 0, required: false },
+      startTime: { type: 'number', min: 0 }, // 开始时间的时间戳  包含
+      endTime: { type: 'number', min: 0 }, // 结束时间的时间戳  不包含(客户端处理结束时间  下一日 ,下一月第一日 ,下一年第一日)
     };
   }
 

+ 3 - 6
app/controller/home.js

@@ -6,8 +6,8 @@ class HomeController extends Controller {
   constructor(ctx) {
     super(ctx);
     this.createRule = {
-      startTime: { type: 'number', min: 0 }, // 开始时间的时间戳  包含
-      endTime: { type: 'number', min: 0 }, // 结束时间的时间戳  不包含(客户端处理结束时间  下一日 ,下一月第一日 ,下一年第一日)
+      startTime: { type: 'number', min: 0, required: false }, // 开始时间的时间戳  包含
+      endTime: { type: 'number', min: 0, required: false }, // 结束时间的时间戳  不包含(客户端处理结束时间  下一日 ,下一月第一日 ,下一年第一日)
     };
 
   }
@@ -18,10 +18,7 @@ class HomeController extends Controller {
 
   async task() {
     const { ctx, service } = this;
-    const payload = ctx.validate({
-      startTime: { type: 'number', min: 0, required: false },
-      endTime: { type: 'number', min: 0, required: false },
-    });
+    const payload = ctx.validate(this.createRule);
     await service.statisticsService.task(payload);
     ctx.body = 'complete';
   }

+ 5 - 4
app/controller/userInfoController.js

@@ -10,16 +10,17 @@ class UserInfoController extends Controller {
     this.createRule = {
       user_id: { type: 'string' },
     };
+    this.createListRule = {
+      pageNumber: { type: 'number', min: 0, required: false },
+      pageSize: { type: 'number', min: 0, required: false },
+    };
   }
 
   // 用户基础信息查询
   async list() {
     const { ctx, service } = this;
 
-    const payload = ctx.validate({
-      pageNumber: { type: 'number', required: false },
-      pageSize: { type: 'number', required: false },
-    });
+    const payload = ctx.validate(this.createListRule);
 
     const data = await service.userInfoService.list(payload);
     // // 设置响应内容和响应状态码

+ 26 - 25
app/extend/helper.js

@@ -1,6 +1,8 @@
 'use strict';
 const moment = require('moment');
 
+exports.chargingCycleApi =
+    'http://10.120.28.6:60080/test/fawiovconditionquery/iov/analysis/driving-behavior/charging-cycle';
 // 实销用户id
 exports.saledRoleId = 90;// '90'
 // 远控行为ID
@@ -183,7 +185,6 @@ exports.getLocationMongo = () => {
 };
 
 
-
 // 获取年龄和性别分组语句  (之前的前置语句或者结果必须存在 元素属性: id_card,gender)
 exports.getAggAndSexMongo = () => {
   return [
@@ -489,17 +490,17 @@ exports.getAppActiveCond = ({ startTime, endTime }) => {
     { $match: { ...this.getTimeRangMatch(startTime, endTime, 'login_time'), login_state: 1 } },
     { $sort: { login_time: 1 } },
     { $group: {
-        _id: '$user_Id',
-        login_count: { $sum: 1 },
-        provice_name: { $first: '$provice_name' }, city_name: { $first: '$city_name' },
-      } },
+      _id: '$user_Id',
+      login_count: { $sum: 1 },
+      provice_name: { $first: '$provice_name' }, city_name: { $first: '$city_name' },
+    } },
     { $lookup: { from: 't_sync_county', localField: 'provice_name', foreignField: 'province_name', as: 'area' } },
     { $project: {
-        login_count: 1,
-        area_name: { $arrayElemAt: [ '$area.area_name', 0 ] },
-        provice_name: '$provice_name',
-        city_name: '$city_name',
-      } },
+      login_count: 1,
+      area_name: { $arrayElemAt: [ '$area.area_name', 0 ] },
+      provice_name: '$provice_name',
+      city_name: '$city_name',
+    } },
     { $lookup:
           {
             from: 'app_behavior_record',
@@ -514,10 +515,10 @@ exports.getAppActiveCond = ({ startTime, endTime }) => {
     },
     { $unwind: { path: '$behaviors', preserveNullAndEmptyArrays: true } },
     { $group: {
-        _id: '$_id', login_count: { $first: '$login_count' },
-        use_duration: { $sum: { $cond: [ '$behaviors.use_duration', '$behaviors.use_duration', 0 ] } },
-        area_name: { $first: '$area_name' }, provice_name: { $first: '$provice_name' }, city_name: { $first: '$city_name' },
-      } },
+      _id: '$_id', login_count: { $first: '$login_count' },
+      use_duration: { $sum: { $cond: [ '$behaviors.use_duration', '$behaviors.use_duration', 0 ] } },
+      area_name: { $first: '$area_name' }, provice_name: { $first: '$provice_name' }, city_name: { $first: '$city_name' },
+    } },
     { $match: { $or: [{ use_duration: { $gt: 30 * 60 * 1000 } }, { login_count: { $gte: 3 } }] } },
   ];
 };
@@ -527,24 +528,24 @@ exports.getAppActiveCond = ({ startTime, endTime }) => {
 exports.getCarActiveCond = ({ startTime, endTime }) => {
   return [
     { $lookup: {
-        from: 'driving_behavior_info',
-        let: { vin: '$vin' },
-        pipeline: [{ $match: { $expr: { $and:
+      from: 'driving_behavior_info',
+      let: { vin: '$vin' },
+      pipeline: [{ $match: { $expr: { $and:
                   [
                     { $eq: [ '$vin', '$$vin' ] },
                     { $gte: [ '$start_time', this.getMonthTop(startTime) ] },
                     { $lt: [ '$start_time', endTime ] },
                   ] } } }], as: 'drive',
-      } },
+    } },
     { $unwind: { path: '$drive', preserveNullAndEmptyArrays: true } },
     { $group: {
-        _id: '$vin',
-        mileage: { $sum: { $cond: [ '$drive.mileage', { $toDouble: '$drive.mileage' }, 0 ] } },
-        pro_code: { $first: '$pro_code' }, city_code: { $first: '$city_code' },
-        is_saled_car: { $first: '$is_saled_car' }, sale_date: { $first: '$sale_date' },
-        user_id: { $first: '$user_id' },
-        series_code: { $first: '$series_code' }, model_code: { $first: '$model_code' },
-      } },
+      _id: '$vin',
+      mileage: { $sum: { $cond: [ '$drive.mileage', { $toDouble: '$drive.mileage' }, 0 ] } },
+      pro_code: { $first: '$pro_code' }, city_code: { $first: '$city_code' },
+      is_saled_car: { $first: '$is_saled_car' }, sale_date: { $first: '$sale_date' },
+      user_id: { $first: '$user_id' },
+      series_code: { $first: '$series_code' }, model_code: { $first: '$model_code' },
+    } },
   ];
 };
 

+ 2 - 2
app/schedule/updateData.js

@@ -9,7 +9,7 @@ class UpdateData extends Subscription {
       // interval: '24h', // 1 分钟间隔
       cron: '0 30 3 * * ? ', // 每天凌晨3点
       type: 'worker', //  all 指定所有的都需要执行  worker 其中一个
-      // immediate: true,
+      immediate: true,
       cronOptions: {
         tz: 'Asia/Shanghai',
       },
@@ -19,7 +19,7 @@ class UpdateData extends Subscription {
   // subscribe 是真正定时任务执行时被运行的函数
   async subscribe() {
     await this.beforeTask();
-    await this.service.statisticsService.task();
+    await this.service.statisticsService.task({});
     await this.endTask();
   }
 

+ 1 - 1
app/service/chargingCycleService.js

@@ -30,7 +30,7 @@ class ChargingCycleService extends Service {
       cond.endId = endId;
     }
     const result = await ctx.curl(
-      'http://10.120.28.6:60080/test/fawiovconditionquery/iov/analysis/driving-behavior/charging-cycle',
+      ctx.helper.chargingCycleApi,
       {
       // 必须指定 method
         method: 'POST',

+ 14 - 14
app/service/statisticsService.js

@@ -50,21 +50,21 @@ class StatisticsService extends Service {
     while (satrtMoment.valueOf() < endTime) {
       const startTime = satrtMoment.valueOf();
       const eTime = satrtMoment.add(1, 'days').valueOf();
-      await this.ctx.service.tRbacUserService.statistics(this.createBaseData(startTime, eTime));
+      // await this.ctx.service.tRbacUserService.statistics(this.createBaseData(startTime, eTime));//重新处理
       await this.ctx.service.tRegisterInfoService.statistics(this.createBaseData(startTime, eTime));
-      await this.ctx.service.onlineUserService2.statistics(this.createBaseData(startTime, eTime));
-      await this.ctx.service.drivingBehaviorInfoService2.statistics(this.createBaseData(startTime, eTime));
-      await this.ctx.service.statsBaseInfoService2.statistics(this.createBaseData(startTime, eTime));
-      await this.ctx.service.tVehicleRecordService2.statistics(this.createBaseData(startTime, eTime));
-      await this.ctx.service.tVehicleReportInfoService.statistics(this.createBaseData(startTime, eTime));
-
-      await this.ctx.service.appBehaviorRecordService.statistics(this.createBaseData(startTime, eTime));
-      await this.ctx.service.appExceptionRecordService.statistics(this.createBaseData(startTime, eTime));
-      await this.ctx.service.appFeedbackRecordService.statistics(this.createBaseData(startTime, eTime));
-      await this.ctx.service.iviBehaviorRecordService.statistics(this.createBaseData(startTime, eTime));
-      await this.ctx.service.msgQueryRecordService.statistics(this.createBaseData(startTime, eTime));
-      await this.ctx.service.msgCenterRecordService2.statistics(this.createBaseData(startTime, eTime));
-      await this.ctx.service.tBoxAutoTestService.statistics(this.createBaseData(startTime, eTime));
+      // await this.ctx.service.onlineUserService2.statistics(this.createBaseData(startTime, eTime));//重新处理
+      // await this.ctx.service.drivingBehaviorInfoService2.statistics(this.createBaseData(startTime, eTime));//重新处理
+      // await this.ctx.service.statsBaseInfoService2.statistics(this.createBaseData(startTime, eTime));//重新处理
+      // await this.ctx.service.tVehicleRecordService2.statistics(this.createBaseData(startTime, eTime));//重新处理
+      // await this.ctx.service.tVehicleReportInfoService.statistics(this.createBaseData(startTime, eTime));//重新处理
+      //
+      // await this.ctx.service.appBehaviorRecordService.statistics(this.createBaseData(startTime, eTime));
+      // await this.ctx.service.appExceptionRecordService.statistics(this.createBaseData(startTime, eTime));
+      // await this.ctx.service.appFeedbackRecordService.statistics(this.createBaseData(startTime, eTime));
+      // await this.ctx.service.iviBehaviorRecordService.statistics(this.createBaseData(startTime, eTime));//重新处理
+      // await this.ctx.service.msgQueryRecordService.statistics(this.createBaseData(startTime, eTime));
+      // await this.ctx.service.msgCenterRecordService2.statistics(this.createBaseData(startTime, eTime));
+      // await this.ctx.service.tBoxAutoTestService.statistics(this.createBaseData(startTime, eTime));//重新处理
     }
   }
 

+ 11 - 8
app/service/tRbacUserService.js

@@ -48,18 +48,12 @@ 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);
@@ -67,9 +61,18 @@ class TRbacUserService extends Service {
     const activeIviTotal = await this.activeIviTotal(timeRangData);
     const activeIviSexAndAgeTotal = await this.activeIviSex2Age(timeRangData);
 
+    // 目前的所有性别年龄统计 和这下面的5个 算法-算车主都是算最终态
     const saledTotal = await this.total({ role_id: ctx.helper.saledRoleId });
     const saledAppTotal = await this.total({ user_orgin: 'APP', role_id: ctx.helper.saledRoleId });
     const saledIviTotal = await this.total({ user_orgin: 'IVI', role_id: ctx.helper.saledRoleId });
+    const newAppSaledTotal = await this.total({
+      create_date: { $gte: timeRangData.startTime, $lt: timeRangData.endTime }, user_orgin: 'APP',
+      role_id: ctx.helper.saledRoleId,
+    });
+    const newIviSaledTotal = await this.total({
+      create_date: { $gte: timeRangData.startTime, $lt: timeRangData.endTime }, user_orgin: 'IVI',
+      role_id: ctx.helper.saledRoleId,
+    });
     initData.end_time = new Date();
     await ctx.service.statisticsService.save(ctx.model.Local.TRbacUserModel,
       { ...initData, total, sexAndAgeTotal,

+ 19 - 1
app/service/tRegisterInfoService.js

@@ -84,7 +84,9 @@ class TRegisterInfoService extends Service {
     initData.start_time = new Date();
     const total = await this.count(ctx.helper.getTimeRangMatch(timeRangData.startTime,
       timeRangData.endTime, 'update_time'));
-    const saledTotal = await this.count({ update_time: { $lt: timeRangData.endTime } });
+    const saledTotal = await this.saledCount(timeRangData);
+
+
     initData.end_time = new Date();
 
     await ctx.service.statisticsService.save(ctx.model.Local.TRegisterInfoModel,
@@ -96,6 +98,22 @@ class TRegisterInfoService extends Service {
     const { ctx } = this;
     return await ctx.model.TRegisterInfoModel.find(cond).countDocuments();
   }
+
+  async saledCount({ endTime }) {
+    const { ctx } = this;
+    const agg = [
+      { $match: { is_saled_car: 1, user_id: { $ne: null }, sale_date: { $lt: endTime } } },
+      { $group: {
+        _id: '$user_id',
+      } },
+      { $count: 'count' },
+    ];
+    const result = await ctx.model.TVehicleRecordModel.aggregate(agg);
+    if (result && result.length > 0) {
+      return result[0].count;
+    }
+    return 0;
+  }
 }
 
 module.exports = TRegisterInfoService;