12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- '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 StudentService extends CrudService {
- constructor(ctx) {
- super(ctx, 'student');
- this.model = this.ctx.model.Student;
- }
- // 查询
- async seek({ termid, skip, limit }) {
- const students = await this.model.find({ termid, classid: null });
- const data = await this.model.find({ termid, classid: null }).skip(Number(skip)).limit(Number(limit));
- const total = await students.length;
- const result = { total, data };
- return result;
- }
- async findbedroom({ batchid }) {
- const students = await this.model.find({ batchid });
- const bedroomList = new Set();
- for (const student of students) {
- bedroomList.add(student.bedroom);
- }
- const result = [];
- let studentList = [];
- for (const bedroom of bedroomList) {
- const newstudents = await this.model.find({ bedroom });
- for (const newstudent of newstudents) {
- studentList.push(newstudent.name);
- }
- result.push({ bedroom, studentList });
- studentList = [];
- }
- return result;
- }
- }
- module.exports = StudentService;
|