liuyu hace 4 años
padre
commit
f3e881bb5f
Se han modificado 1 ficheros con 36 adiciones y 6 borrados
  1. 36 6
      app/service/class.js

+ 36 - 6
app/service/class.js

@@ -164,14 +164,44 @@ class ClassService extends CrudService {
   // 根据传入的学生列表和班级id更新学生信息
   async studentupclass({ id }, data) {
     assert(id, '班级id为必填项');
-    // 循环学生id
-    for (const stuid of data) {
-      const student = await this.stumodel.findById(stuid);
-      if (student) {
-        student.classid = id;
-        await student.save();
+    // 根据全年计划表id查出对应的全年计划详细信息
+    const trainplan = await this.model.findOne({ 'termnum.batchnum.class._id': ObjectId(id) });
+    if (!trainplan) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '全年计划信息不存在');
+    }
+    // 取得计划期批次信息
+    let termid = '';
+    let batchid = '';
+    let classname = '';
+    for (const term of trainplan.termnum) {
+      for (const batch of term.batchnum) {
+        const class_ = await batch.class.id(id);
+        if (class_) {
+          termid = term.id;
+          batchid = batch.id;
+          classname = class_.name;
+          break;
+        }
+      }
+    }
+    let classid_ = '';
+    if (classname) {
+      const cla_ = await this.clamodel.findOne({ termid, batchid, name: classname });
+      if (cla_) {
+        classid_ = cla_.id;
+      }
+    }
+    if (classid_) {
+      // 循环学生id
+      for (const stuid of data) {
+        const student = await this.stumodel.findById(stuid);
+        if (student) {
+          student.classid = classid_;
+          await student.save();
+        }
       }
     }
+
   }
 
   async notice(data) {