liuyu hace 4 años
padre
commit
1413efbf38
Se han modificado 1 ficheros con 10 adiciones y 6 borrados
  1. 10 6
      app/service/lesson.js

+ 10 - 6
app/service/lesson.js

@@ -25,6 +25,9 @@ class LessonService extends CrudService {
       throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '全年计划信息不存在');
     }
     const terms = res.termnum;
+    const _lessonmode = await this.lmodel.find();
+    // 取得模板内容并转化成json
+    const lessonmode = JSON.parse(_lessonmode.lessons);
     // 循环取得所有期
     for (const elm of terms) {
       // 根据期id清空课程表
@@ -43,19 +46,20 @@ class LessonService extends CrudService {
         // 循环班级
         for (const cla of _classs) {
           // 取得课程模板信息
-          const _lessonmode = await this.lmodel.findOne({ type: cla.type });
-          if (!_lessonmode) {
-            throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '课程模板信息不存在');
+          let lessonmode_ = _.find(lessonmode, { type: cla.type });
+          if (!lessonmode_) {
+            lessonmode_ = _lessonmode[0];
+            if (!lessonmode_) {
+              throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '课程模板信息不存在');
+            }
           }
-          // 取得模板内容并转化成json
-          const lessonmode = JSON.parse(_lessonmode.lessons);
           // 记录天数
           let i = 1;
           // 循环天数
           const newlesson = [];
           for (const day of sedays) {
             // 循环课程模板,将模板信息排入班级课程表中
-            for (const lessm of lessonmode) {
+            for (const lessm of lessonmode_) {
               // 循环插入模板信息
               if (lessm['day' + i] !== '--') {
                 let _subid = '';