|
@@ -8,12 +8,13 @@ const moment = require('moment');
|
|
|
const { CrudService } = require('naf-framework-mongoose/lib/service');
|
|
|
const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
|
|
|
|
-class ApplyService extends CrudService {
|
|
|
+class CountService extends CrudService {
|
|
|
constructor(ctx) {
|
|
|
super(ctx, 'count');
|
|
|
this.smodel = this.ctx.model.Student;
|
|
|
this.tmodel = this.ctx.model.Trainplan;
|
|
|
this.lmodel = this.ctx.model.Leave;
|
|
|
+ this.schmodel = this.ctx.model.School;
|
|
|
}
|
|
|
|
|
|
// 查询
|
|
@@ -70,6 +71,48 @@ class ApplyService extends CrudService {
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
+ // 按学校id统计查询
|
|
|
+ async countschstu({ id }) {
|
|
|
+ console.log(id);
|
|
|
+ // 取得当前年份计划信息
|
|
|
+ console.log(moment().format('YYYY'));
|
|
|
+ const plan = await this.tmodel.findOne({ year: moment().format('YYYY') });
|
|
|
+ if (!plan) {
|
|
|
+ throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '当前全年计划不存在');
|
|
|
+ }
|
|
|
+ // 根据计划取得当前年份下计划学校培训学生人数
|
|
|
+ const school = await this.schmodel.findOne({ code: id });
|
|
|
+ if (!school) {
|
|
|
+ throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '学校信息不存在');
|
|
|
+ }
|
|
|
+ const data = {};
|
|
|
+ data.planstu = school.number;
|
|
|
+ // 根据学校id取得学校上报的学生数
|
|
|
+ const schstus = await this.smodel.find({ planid: plan.id, schid: id });
|
|
|
+ data.schstu = schstus.length;
|
|
|
+ // 取得已培训的学生数
|
|
|
+ const trainstu = schstus.filter(item => item.openid);
|
|
|
+ data.trainstu = trainstu.length;
|
|
|
+ // 取得内未培训的学生数
|
|
|
+ const notrainstu = schstus.filter(item => !item.openid);
|
|
|
+ data.notrainstu = notrainstu.length;
|
|
|
+ // 取得学生请假数和退出数
|
|
|
+ const levelstus = [];
|
|
|
+ // 循环取得所有请假和退出的学生信息
|
|
|
+ for (const elm of trainstu) {
|
|
|
+ const level = await this.lmodel.findOne({ studentid: elm.id, status: '1' });
|
|
|
+ if (level) {
|
|
|
+ levelstus.push(level);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 筛选出请假数和退出数
|
|
|
+ const levelqj = levelstus.filter(item => item.type === '0');
|
|
|
+ const levelexit = levelstus.filter(item => item.type === '1');
|
|
|
+ data.levelqj = levelqj.length;
|
|
|
+ data.levelexit = levelexit.length;
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-module.exports = ApplyService;
|
|
|
+module.exports = CountService;
|