|
@@ -4,6 +4,7 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
const _ = require('lodash');
|
|
const _ = require('lodash');
|
|
const assert = require('assert');
|
|
const assert = require('assert');
|
|
const moment = require('moment');
|
|
const moment = require('moment');
|
|
|
|
+const { ObjectId } = require('mongoose').Types;
|
|
|
|
|
|
//
|
|
//
|
|
class StatisticsService extends CrudService {
|
|
class StatisticsService extends CrudService {
|
|
@@ -19,16 +20,31 @@ class StatisticsService extends CrudService {
|
|
// 查出这个学校下面的教练
|
|
// 查出这个学校下面的教练
|
|
const rList = await this.rcsModel.find({ school_id }).populate('coach_id', 'name');
|
|
const rList = await this.rcsModel.find({ school_id }).populate('coach_id', 'name');
|
|
const coachList = rList.map(i => i.coach_id);
|
|
const coachList = rList.map(i => i.coach_id);
|
|
|
|
+ console.log(coachList);
|
|
const lcList = await this.lessonCoachModel.find({ school_id }, { coach_id: 1, is_sign: 1 });
|
|
const lcList = await this.lessonCoachModel.find({ school_id }, { coach_id: 1, is_sign: 1 });
|
|
const midList = _.groupBy(lcList, 'coach_id');
|
|
const midList = _.groupBy(lcList, 'coach_id');
|
|
|
|
+ const arr = [];
|
|
for (const coach_id in midList) {
|
|
for (const coach_id in midList) {
|
|
const l = midList[coach_id];
|
|
const l = midList[coach_id];
|
|
midList[coach_id] = _.groupBy(l, 'is_sign');
|
|
midList[coach_id] = _.groupBy(l, 'is_sign');
|
|
for (const is_sign in midList[coach_id]) {
|
|
for (const is_sign in midList[coach_id]) {
|
|
midList[coach_id][is_sign] = midList[coach_id][is_sign].length;
|
|
midList[coach_id][is_sign] = midList[coach_id][is_sign].length;
|
|
}
|
|
}
|
|
|
|
+ const coach = coachList.find(f => ObjectId(f._id).equals(coach_id));
|
|
|
|
+ const obj = { coach: coach.name };
|
|
|
|
+ const csList = midList[coach_id];
|
|
|
|
+ let total = 0;
|
|
|
|
+ let is_signed = 0;
|
|
|
|
+ for (const is_sign in csList) {
|
|
|
|
+ const d = csList[is_sign];
|
|
|
|
+ if (is_sign === '1') is_signed = d;
|
|
|
|
+ total += d;
|
|
|
|
+ }
|
|
|
|
+ console.log(is_signed, total);
|
|
|
|
+ obj.value = `${_.floor(_.divide(is_signed, total) * 100)}%`;
|
|
|
|
+ arr.push(obj);
|
|
}
|
|
}
|
|
- console.log(midList);
|
|
|
|
|
|
+ return arr;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|