Browse Source

教师首页查询

lrf402788946 4 years ago
parent
commit
cd0a4ae6dd
3 changed files with 41 additions and 0 deletions
  1. 9 0
      app/controller/.lesson.js
  2. 3 0
      app/router.js
  3. 29 0
      app/service/lesson.js

+ 9 - 0
app/controller/.lesson.js

@@ -37,4 +37,13 @@ module.exports = {
     requestBody: ["ids", "classids"],
     service: "check",
   },
+  teaIndex: {
+    parameters: {
+      query: {
+        planid: "planid",
+        teaid: "teaid",
+      },
+    },
+    service: "teaIndex",
+  },
 };

+ 3 - 0
app/router.js

@@ -679,4 +679,7 @@ module.exports = app => {
   router.post('student', '/api/train/student/printcert', controller.student.printCert);
   // 日志
   router.get('/api/train/logs', controller.logs.index);
+
+  // 教师首页,根据计划id和教师id查教师的安排(已确定的,不是预课表)
+  router.get('/api/train/teaIndex', controller.lesson.teaIndex);
 };

+ 29 - 0
app/service/lesson.js

@@ -622,6 +622,35 @@ class LessonService extends CrudService {
     return obj;
   }
 
+  async teaIndex({ planid, teaid }) {
+    const trainplan = await this.tmodel.findById(planid);
+    if (!trainplan) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到指定年度计划');
+    const { termnum } = trainplan;
+    const termids = termnum.map(i => i._id);
+    let lessons = await this.model.find({ termid: termids, status: '1', lessons: { $elemMatch: { teaid } } });
+    if (lessons.length > 0)lessons = JSON.parse(JSON.stringify(lessons));
+    else return [];
+    const classids = lessons.map(i => i.classid);
+    // 找期,班级信息
+    const classes = await this.clamodel.find({ _id: classids });
+    let res = [];
+    for (const i of lessons) {
+      const { lessons: ls, classid, termid } = i;
+      let term,
+        cla;
+      const list = ls.filter(f => f.teaid === teaid);
+      const t = termnum.find(f => ObjectId(f._id).equals(termid));
+      if (t) term = t.term;
+      const c = classes.find(f => ObjectId(f._id).equals(classid));
+      if (c) cla = c.name;
+      for (const l of list) {
+        const { subname, date } = l;
+        res.push({ subname, date, term, class: cla });
+      }
+    }
+    res = _.uniqWith(res, _.isEqual);
+    return res;
+  }
 }
 
 module.exports = LessonService;