reloaded 4 years ago
parent
commit
e703f94d68
3 changed files with 35 additions and 1 deletions
  1. 7 1
      app/controller/lesson.js
  2. 1 0
      app/router.js
  3. 27 0
      app/service/lesson.js

+ 7 - 1
app/controller/lesson.js

@@ -24,9 +24,15 @@ class LessonController extends Controller {
     this.ctx.ok({ data });
   }
 
+  // 根据计划id与教师id查出班级和课程信息
+  async teaclass() {
+    const data = await this.service.teaclass(this.ctx.request.query);
+    this.ctx.ok({ data });
+  }
+
   async uplessones() {
     const res = await this.service.uplessones(this.ctx.request.body);
-    this.ctx.ok({ msg: 'ok', data: res });
+    this.ctx.ok({ msg: "ok", data: res });
   }
 }
 

+ 1 - 0
app/router.js

@@ -89,6 +89,7 @@ module.exports = app => {
   router.post('festival', '/api/train/festival/update/:id', controller.festival.update);
 
   // 课程表设置路由
+  router.get('/api/train/lesson/teaclass', controller.lesson.teaclass);
   router.post('lesson', '/api/train/lesson/uplessones', controller.lesson.uplessones);
   router.get('/api/train/lesson/classbyteaid', controller.lesson.classbyteaid); // 根据计划id与教师id查询班级信息
   router.resources('lesson', '/api/train/lesson', controller.lesson); // index、create、show、destroy

+ 27 - 0
app/service/lesson.js

@@ -194,6 +194,33 @@ class LessonService extends CrudService {
     return data;
   }
 
+  // 根据计划id、教师id查询所有班级信息
+  async teaclass({ planid, teaid }) {
+    // 取得传入的计划id与教师id
+    // 根据计划id取得所有期
+    const plan = await this.tmodel.findById(planid);
+    if (!plan) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '全年计划信息不存在');
+    }
+    const terms = await plan.termnum;
+    // 循环取得所有期信息
+    const data = [];
+    for (const term of terms) {
+      // 根据期id与教师id查出课程班级信息
+      const lessons = await this.model.find({
+        termid: term.id,
+        'lessons.teaid': teaid,
+      });
+      for (const elm of lessons) {
+        if (elm.classid) {
+          const cla = await this.ctx.service.class.fetch(elm.classid);
+          data.push(cla);
+        }
+      }
+    }
+    return data;
+  }
+
   async uplessones(data) {
     for (const _data of data) {
       await this.model.findByIdAndUpdate(_data.id, _data);