Browse Source

classinfo

reloaded 4 years ago
parent
commit
d785aba838
3 changed files with 45 additions and 0 deletions
  1. 5 0
      app/controller/class.js
  2. 1 0
      app/router.js
  3. 39 0
      app/service/class.js

+ 5 - 0
app/controller/class.js

@@ -40,6 +40,11 @@ class ClassController extends Controller {
     const res = await this.service.upclasses(this.ctx.request.body);
     this.ctx.ok({ msg: 'ok', data: res });
   }
+
+  async classinfo() {
+    const res = await this.service.classinfo(this.ctx.params);
+    this.ctx.ok({ msg: 'ok', data: res });
+  }
 }
 
 module.exports = CrudController(ClassController, meta);

+ 1 - 0
app/router.js

@@ -59,6 +59,7 @@ module.exports = app => {
   router.post('bedroom', '/api/train/bedroom/ibeacon', controller.bedroom.ibeacon);
 
   // 班级表设置路由
+  router.get('class', '/api/train/class/classinfo/:id', controller.class.classinfo);
   router.post('class', '/api/train/class/upclasses', controller.class.upclasses);
   router.post('class', '/api/train/class/notice', controller.class.notice);
   router.resources('class', '/api/train/class', controller.class); // index、create、show、destroy

+ 39 - 0
app/service/class.js

@@ -16,6 +16,8 @@ class ClassService extends CrudService {
     this.umodel = this.ctx.model.User;
     this.tmodel = this.ctx.model.Trainplan;
     this.gmodel = this.ctx.model.Group;
+    this.heamodel = this.ctx.model.Headteacher;
+    this.teamodel = this.ctx.model.Teacher;
   }
 
   async divide(data) {
@@ -172,6 +174,43 @@ class ClassService extends CrudService {
       await this.model.findByIdAndUpdate(_data.id, _data);
     }
   }
+
+  async classinfo({ id: classid }) {
+    const _classes = await this.model.findById(classid);
+    // 班级信息
+    const classes = _.cloneDeep(JSON.parse(JSON.stringify(_classes)));
+    // 学生信息
+    const students = await this.stumodel.find({ classid });
+    if (students) {
+      classes.students = students;
+    }
+    // 班主任信息
+    if (classes.headteacherid) {
+      const headteacher = await this.heamodel.findById(classes.headteacherid);
+      classes.headteacher = headteacher;
+    }
+    // 礼仪课老师信息
+    if (classes.lyteacherid) {
+      let lyteacher = await this.heamodel.findById(classes.lyteacherid);
+      if (!lyteacher) {
+        lyteacher = await this.teamodel.findById(classes.lyteacherid);
+      }
+      classes.lyteacher = lyteacher;
+    }
+    // 教课老师信息
+    const teachers = [];
+    const lessones = await this.lessmodel.findOne({ classid });
+    if (lessones) {
+      for (const lesson of lessones.lessons) {
+        if (lesson.teaid) {
+          const teacher = await this.teamodel.findById(lesson.teaid);
+          teachers.push(teacher);
+        }
+      }
+    }
+    classes.teachers = teachers;
+    return classes;
+  }
 }
 
 module.exports = ClassService;