liuyu %!s(int64=4) %!d(string=hai) anos
pai
achega
e516b72f78
Modificáronse 1 ficheiros con 21 adicións e 8 borrados
  1. 21 8
      app/service/class.js

+ 21 - 8
app/service/class.js

@@ -41,8 +41,10 @@ class ClassService extends CrudService {
     for (const _class of newclass) {
       // 取得班级人数
       const stunum = _class.number;
+      // 取出相同类型的学生
+      const studentids = await this.getstutype(_students, _class.type);
       // 取出班级人数下的学生id
-      const beforestu = _.take(_students, stunum);
+      const beforestu = _.take(studentids, stunum);
       // 将取出的数据调用更新学生的班级信息方法
       await this.studentup(_class.id, _class.type, _class.batchid, beforestu);
       // 将班级自动分为组
@@ -52,6 +54,18 @@ class ClassService extends CrudService {
     }
   }
 
+  // 取得同样类型的学生
+  async getstutype(_students, type) {
+    const data = [];
+    for (const stuid of _students) {
+      const student = await this.stumodel.findById(stuid);
+      if (student && student.type === type) {
+        data.push(stuid);
+      }
+    }
+    return data;
+  }
+
   // 自动生成班级私有方法
   async autoclass(planid, termid) {
     // 删除所有计划下的班级
@@ -62,13 +76,12 @@ class ClassService extends CrudService {
       throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '全年计划信息不存在');
     }
     // 循环出所有班级进行添加操作
-    for (const term of res.termnum) {
-      for (const batch of term.batchnum) {
-        const classs = await batch.class;
-        for (const cla of classs) {
-          const newdata = { name: cla.name, number: cla.number, batchid: batch.id, termid: term.id, planid: res.id, type: cla.type, headteacherid: cla.headteacherid };
-          await this.model.create(newdata);
-        }
+    const term = await res.termnum.id(termid);
+    for (const batch of term.batchnum) {
+      const classs = await batch.class;
+      for (const cla of classs) {
+        const newdata = { name: cla.name, number: cla.number, batchid: batch.id, termid: term.id, planid: res.id, type: cla.type, headteacherid: cla.headteacherid };
+        await this.model.create(newdata);
       }
     }
   }