소스 검색

加入按计划id教师id查询班级信息

liuyu 4 년 전
부모
커밋
39590ec816
3개의 변경된 파일46개의 추가작업 그리고 0개의 파일을 삭제
  1. 6 0
      app/controller/lesson.js
  2. 1 0
      app/router.js
  3. 39 0
      app/service/lesson.js

+ 6 - 0
app/controller/lesson.js

@@ -19,6 +19,12 @@ class LessonController extends Controller {
     this.ctx.ok({ res });
   }
 
+  // 根据计划id与教师id查出班级和课程信息
+  async classbyteaid() {
+    const data = await this.service.classbyteaid(this.ctx.request.query);
+    this.ctx.ok({ data });
+  }
+
 }
 
 module.exports = CrudController(LessonController, meta);

+ 1 - 0
app/router.js

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

+ 39 - 0
app/service/lesson.js

@@ -135,6 +135,45 @@ class LessonService extends CrudService {
     }
   }
 
+  // 根据计划id、教师id查询所有班级信息
+  async classbyteaid({ 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 });
+      const batchs = await term.batchnum;
+      for (const elm of lessons) {
+        const newdata = {};
+        const batch = await batchs.id(elm.batchid);
+        newdata.planid = planid;
+        newdata.title = plan.title;
+        newdata.termid = elm.termid;
+        newdata.term = term.term;
+        newdata.batchid = elm.batchid;
+        newdata.batch = batch.batch;
+        newdata.classid = elm.classid;
+        if (elm.classid) {
+          const cla = await this.clamodel.findById(elm.classid);
+          if (cla) {
+            newdata.classname = cla.name;
+          }
+        }
+        const _lessons = elm.lessons.filter(item => item.teaid === teaid);
+        newdata.lessons = _lessons;
+        data.push(newdata);
+      }
+    }
+    return data;
+  }
+
 }
 
 module.exports = LessonService;