'use strict'; const assert = require('assert'); const _ = require('lodash'); const { ObjectId } = require('mongoose').Types; const { CrudService } = require('naf-framework-mongoose/lib/service'); const { BusinessError, ErrorCode } = require('naf-core').Error; class TeaplanService extends CrudService { constructor(ctx) { super(ctx, 'teaplan'); this.model = this.ctx.model.Teaplan; this.hmodel = this.ctx.model.Headteacher; } async findteacher({ batchid }) { // 查询所有班主任信息 const headteachers = await this.hmodel.find(); const newheadteachers = []; // 遍历班主任信息 for (const headteacher of headteachers) { // 查询某班主任对应的班主任全年计划表 const teaplan = await this.model.findOne({ headteacherid: headteacher.id }); if (teaplan) { const nobatchids = teaplan.nobatchid; // 如果有对应的全年计划表并且该计划表中的不能上课的批次包含指定批次,则添加status='0'的标记 if (nobatchids.includes(batchid)) { newheadteachers.push({ ...JSON.parse(JSON.stringify(headteacher)), status: '0' }); } else { newheadteachers.push(headteacher); } } else { newheadteachers.push(headteacher); } } return newheadteachers; } } module.exports = TeaplanService;