Ver Fonte

临时提交

z332406259 há 4 anos atrás
pai
commit
f04edffa49

+ 1 - 4
app/controller/carNumberController.js

@@ -12,9 +12,6 @@ class CarNumberController extends Controller {
       endTime: { type: 'number', min: 0 }, // 结束时间的时间戳  不包含(客户端处理结束时间  下一日 ,下一月第一日 ,下一年第一日)
       type: [ '1', '2' ], // 类型分为   0日   1月   2年
     };
-    this.createSaledRule = {
-      saledTime: { type: 'number', min: 0, required: false },
-    };
   }
 
   // 实销车辆统计分析 实销车辆百分比统计分析 入网车辆总数统计分析
@@ -78,7 +75,7 @@ class CarNumberController extends Controller {
   async saledCity() {
     const { ctx, service } = this;
     // 校验参数 组装参数
-    const payload = ctx.validate(this.createSaledRule);
+    const payload = ctx.validate({});
 
     // 调用 Service 进行业务处理
     const data = await service.tVehicleRecordService2.saledCity(payload);

+ 1 - 1
app/extend/helper.js

@@ -278,7 +278,7 @@ exports.getAggAndSexMongo = () => {
               to: 'int',
               onError: { $add: [{ $year: { $toDate: new Date() } }, 1 ] } } },
           ] }, -1 ] },
-        boundaries: [ 0, 18, 25, 30, 35, 40, 200 ],
+        boundaries: [ 18, 25, 30, 35, 40, 200 ],
         default: 'Other',
         output: {
           mCount: { $sum: {

+ 2 - 2
app/schedule/updateData.js

@@ -7,7 +7,7 @@ class UpdateData extends Subscription {
   static get schedule() {
     return {
       // interval: '24h', // 1 分钟间隔
-      cron: '0 23 10 * * ? ', // 每天凌晨3点
+      cron: '0 30 3 * * ? ', // 每天凌晨3点
       // cron: '0 10 17 * * ? ', // 每天凌晨3点
       type: 'all', // 指定所有的 worker 都需要执行
       // immediate: true,
@@ -54,7 +54,7 @@ class UpdateData extends Subscription {
     this.isRunningTask = true;
 
     // 更新历史时间段数据 => 修改createBaseData的参数做循环请求即可
-    const satrtMoment = this.ctx.helper.momentDate('2020-05-01');
+    const satrtMoment = this.ctx.helper.momentDate('2020-01-01');
 
     // const satrtMoment = this.ctx.helper.momentDate('2020-06-01');
     // const endTime = this.ctx.helper.parse('2019-06-17');

+ 5 - 1
app/service/msgCenterRecordService2.js

@@ -55,7 +55,9 @@ class MsgCenterRecordService2 extends Service {
     }
     initData.start_time = new Date();
 
+    ctx.logger.info(`1`);
     const cResult = await this.channelGroup(timeRangData);
+    ctx.logger.info(`2`);
     const rResult = await this.readGroup(timeRangData);
     let colorTotal = 0;// 彩色数
     let grayTotal = 0;// 灰色数
@@ -88,7 +90,9 @@ class MsgCenterRecordService2 extends Service {
           break;
       }
     });
-    const msgType = await this.typeGroup(timeRangData);
+    ctx.logger.info(`3`);
+    // const msgType = await this.typeGroup(timeRangData);TODO 问题
+    const msgType = [];
     initData.end_time = new Date();
 
     await ctx.service.statisticsService.save(ctx.model.Local.MsgCenterRecordModel,

+ 28 - 16
app/service/onlineUserService2.js

@@ -150,12 +150,14 @@ class OnlineUserService2 extends Service {
     let pwdTotal = 0;
     let codeTotal = 0;
     let scanTotal = 0;
+    ctx.logger.info("1");
     const iviTotal = await this.iviTotal(timeRangData);
     let carTotal = 0;
     let commonTotal = 0;
     let guestTotal = 0;
     let successTotal = 0;
     let failTotal = 0;
+    ctx.logger.info("2");
     const modes = await this.modeGroup(timeRangData);
     modes.forEach(item => {
       switch (item._id) { // 1:人脸、2:声纹、3:密码、4:验证码、5:二维码
@@ -178,6 +180,7 @@ class OnlineUserService2 extends Service {
           break;
       }
     });
+    ctx.logger.info("3");
     const roles = await this.roleGroup(timeRangData);
     roles.forEach(item => {
       switch (item._id) {
@@ -194,6 +197,7 @@ class OnlineUserService2 extends Service {
           break;
       }
     });
+    ctx.logger.info("4");
     const status = await this.statusGroup(timeRangData);
     status.forEach(item => {
       switch (item._id) {
@@ -207,12 +211,14 @@ class OnlineUserService2 extends Service {
           break;
       }
     });
+    ctx.logger.info("5");
     const aResult = await this.appPlace(ctx.helper.getTimeRangMatch(
       timeRangData.startTime, timeRangData.endTime, 'login_time'));
     if (aResult && aResult.length > 0) {
       appTotal = aResult[0].count;
       appPlace = aResult[0].areas;
     }
+    ctx.logger.info("6");
     const tResult = await this.tBoxPlace(timeRangData);
     if (tResult && tResult.length > 0) {
       tBoxTotal = tResult[0].count;
@@ -226,30 +232,36 @@ class OnlineUserService2 extends Service {
     let iviLocation = [];
     let iviNewLocation = [];
     let iviActiveLocation = [];
+    ctx.logger.info("7");
     const al = await this.appPlace({ login_time: { $lt: timeRangData.endTime } });
     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;
-    }
+    ctx.logger.info("8");
+    // const anl = await this.appNewLocation(timeRangData);TODO 问题
+    // if (anl && anl.length > 0) {
+    //   appNewLocation = anl[0].areas;
+    // }
+    ctx.logger.info("9");
+    // const aal = await this.appActiveLocation(timeRangData);TODO 问题
+    // if (aal && aal.length > 0) {
+    //   appActiveLocation = aal[0].areas;
+    // }
+    ctx.logger.info("10");
     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;
-    }
+    ctx.logger.info("11");
+    // const inl = await this.iviNewLocation(timeRangData);TODO 问题
+    // if (inl && inl.length > 0) {
+    //   iviNewLocation = inl[0].areas;
+    // }
+    ctx.logger.info("12");
+    // const ial = await this.iviActiveLocation(timeRangData);TODO 问题
+    // if (ial && ial.length > 0) {
+    //   iviActiveLocation = ial[0].areas;
+    // }
     initData.end_time = new Date();
 
     await ctx.service.statisticsService.save(ctx.model.Local.OnlineUserModel,

+ 1 - 1
app/service/statisticsService.js

@@ -19,7 +19,7 @@ class StatisticsService extends Service {
   async save(model, data, isUpdate) {
     const { ctx } = this;
     const { dateString } = data;
-
+    ctx.logger.info(`执行本地${model.modelName}`);
     if (isUpdate) {
       const result = await model.findOne({ dateString });
       if (result) {

+ 19 - 3
app/service/tRbacUserService.js

@@ -35,28 +35,44 @@ class TRbacUserService extends Service {
     if (hasData && !isForceUpdate) {
       return;
     }
+    ctx.logger.info(`zzzz`);
     initData.start_time = new Date();
     const total = await this.total({ create_date: { $lt: timeRangData.endTime } });
+    ctx.logger.info(`1`);
     const sexAndAgeTotal = await this.sex2Age({ create_date: { $lt: timeRangData.endTime } });
+    ctx.logger.info(`2`);
     const appTotal = await this.total({ user_orgin: 'APP', create_date: { $lt: timeRangData.endTime } });
+    ctx.logger.info(`3`);
     const appSexAndAgeTotal = await this.sex2Age({ user_orgin: 'APP', create_date: { $lt: timeRangData.endTime } });
+    ctx.logger.info(`3`);
     const iviTotal = await this.total({ user_orgin: 'IVI', create_date: { $lt: timeRangData.endTime } });
+    ctx.logger.info(`4`);
     const iviSexAndAgeTotal = await this.sex2Age({ user_orgin: 'IVI', create_date: { $lt: timeRangData.endTime } });
+    ctx.logger.info(`5`);
     const newAppTotal = await this.total({ user_orgin: 'APP',
       create_date: { $gte: timeRangData.startTime, $lt: timeRangData.endTime } });
+    ctx.logger.info(`6`);
     const newAppSexAndAgeTotal = await this.sex2Age({ user_orgin: 'APP',
       create_date: { $gte: timeRangData.startTime, $lt: timeRangData.endTime } });
+    ctx.logger.info(`7`);
     const newIviTotal = await this.total({ user_orgin: 'IVI',
       create_date: { $gte: timeRangData.startTime, $lt: timeRangData.endTime } });
+    ctx.logger.info(`8`);
     const newIviSexAndAgeTotal = await this.sex2Age({ user_orgin: 'IVI',
       create_date: { $gte: timeRangData.startTime, $lt: timeRangData.endTime } });
-    const activeAppTotal = await this.activeAppTotal(timeRangData);
-    const activeAppSexAndAgeTotal = await this.activeAppSex2Age(timeRangData);
+    ctx.logger.info(`9`);
+    // const activeAppTotal = await this.activeAppTotal(timeRangData); TODO 问题
+    const activeAppTotal = 0;
+    ctx.logger.info(`10`);
+    // const activeAppSexAndAgeTotal = await this.activeAppSex2Age(timeRangData); TODO 问题
+    const activeAppSexAndAgeTotal = [];
+    ctx.logger.info("11");
     const activeIviTotal = await this.activeIviTotal(timeRangData);
+    ctx.logger.info(`12`);
     const activeIviSexAndAgeTotal = await this.activeIviSex2Age(timeRangData);
 
     initData.end_time = new Date();
-
+    ctx.logger.info(`ssss`);
     await ctx.service.statisticsService.save(ctx.model.Local.TRbacUserModel,
       { ...initData, total, sexAndAgeTotal,
         appTotal, appSexAndAgeTotal,

+ 25 - 26
app/service/tVehicleRecordService2.js

@@ -32,7 +32,7 @@ class TVehicleRecordService2 extends Service {
   // TODO 暂时即时查询
   async saled({ seriesCode, modelCode }) {
     const { ctx } = this;
-    const cond = [{ $match: { is_saled_car: 1, user_id: { $ne: null } } }];
+    const cond = [{ $match: { is_saled_car: 1, user_id: { $ne: null }, pro_code: { $exists: true } } }];
     if (seriesCode) {
       cond[0].$match.series_code = seriesCode;
     }
@@ -43,37 +43,36 @@ class TVehicleRecordService2 extends Service {
 
     const agg = [
       ...cond,
-      { $lookup: { from: 't_sync_province', localField: 'pro_code', foreignField: 'out_pro_code', as: 'pro' } },
+      { $group: { _id: '$pro_code', count: { $sum: 1 } } },
+      { $lookup: { from: 't_sync_province', localField: '_id', foreignField: 'out_pro_code', as: 'pro' } },
       { $unwind: '$pro' },
-      { $lookup: {
-        from: 't_sync_city',
-        let: { city_code: '$city_code', province_id: '$pro.province_id' },
-        pipeline: [{ $match: { $expr: { $and:
-                    [
-                      { $eq: [ '$out_city_code', '$$city_code' ] },
-                      { $eq: [ '$province_id', '$$province_id' ] },
-                    ] } } }], as: 'city',
-      } },
-      { $unwind: '$city' },
-      { $lookup: { from: 't_sync_county', localField: 'pro_code', foreignField: 'out_pro_code', as: 'area' } },
+      { $lookup: { from: 't_sync_county', localField: '_id', foreignField: 'out_pro_code', as: 'area' } },
       { $project: {
+        count: 1,
         area_code: { $arrayElemAt: [ '$area.area_code', 0 ] },
         area_name: { $arrayElemAt: [ '$area.area_name', 0 ] },
-        provice_code: '$pro_code',
+        provice_code: '$pro.out_pro_code',
         provice_name: '$pro.province_name',
-        city_code: '$city_code',
-        city_name: '$city.city_name',
       } },
-      ...ctx.helper.getLocationMongo(),
+      { $group: { _id: { area_code: '$area_code', area_name: '$area_name' },
+        provinces: { $push: { provice_code: '$provice_code', provice_name: '$provice_name',
+          count: '$count' } },
+        count: { $sum: '$count' } } },
+      { $group: { _id: null,
+        areas: { $push: { area_code: '$_id.area_code', area_name: '$_id.area_name',
+          provinces: '$provinces',
+          count: '$count' } },
+        count: { $sum: '$count' } } },
     ];
 
     return await ctx.model.TVehicleRecordModel.aggregate(agg);
   }
 
   // TODO 暂时即时查询
-  async saledCity({ seriesCode, modelCode, saledTime = this.ctx.helper.today() }) {
+  async saledCity({ seriesCode, modelCode }) {
     const { ctx } = this;
-    const cond = [{ $match: { is_saled_car: 1, user_id: { $ne: null }, sale_date: { $lt: saledTime } } }];
+    const cond = [{ $match: { is_saled_car: 1, user_id: { $ne: null },
+      pro_code: { $exists: true }, city_code: { $exists: true } } }];
     if (seriesCode) {
       cond[0].$match.series_code = seriesCode;
     }
@@ -243,13 +242,13 @@ class TVehicleRecordService2 extends Service {
       return;
     }
     initData.start_time = new Date();
-    const result = await this.group(timeRangData);
-    let car = [];
-    let total = 0;
-    if (result && result.length > 0) {
-      car = result[0].car;
-      total = result[0].total;
-    }
+    // const result = await this.group(timeRangData); TODO 问题
+    const car = [];
+    const total = 0;
+    // if (result && result.length > 0) {
+    //   car = result[0].car;
+    //   total = result[0].total;
+    // }
 
     // 实销城市 (按照时间 + 车型车系来取前三名)
 

+ 2 - 2
config/config.default.js

@@ -60,10 +60,10 @@ module.exports = appInfo => {
         },
       },
       etlLocalDB: {// 本地清洗后的数据库
-        url: 'mongodb://127.0.0.1/faw-etl-local', //
+        // url: 'mongodb://127.0.0.1/faw-etl-local', //
         // url: 'mongodb://faw-etl-local:faw-etl-local%40123@10.6.222.37:27017/faw-etl-local', // dev
         // url: 'mongodb://faw-etl-local:faw-etl-local%40123@10.112.16.11:27017/faw-etl-local', // sit
-        // url: 'mongodb://local3:local3%40123@uat.dbaas.private:27028/faw-etl-local3', // uat
+        url: 'mongodb://local3:local3%40123@uat.dbaas.private:27028/faw-etl-local3', // uat
         options: {
           useUnifiedTopology: true,
         },