Просмотр исходного кода

Merge branch 'master' of http://git.cc-lotus.info/new_train/service-center

liuyu 4 лет назад
Родитель
Сommit
48413b4f16
3 измененных файлов с 48 добавлено и 0 удалено
  1. 5 0
      app/controller/class.js
  2. 1 0
      app/router.js
  3. 42 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

+ 42 - 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,46 @@ 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;
+    }
+    // 班主任信息
+    let headteacher;
+    if (classes.headteacherid) {
+      headteacher = await this.heamodel.findById(classes.headteacherid);
+    }
+    // 礼仪课老师信息
+    let lyteacher;
+    if (classes.lyteacherid) {
+      lyteacher = await this.heamodel.findById(classes.lyteacherid);
+      if (!lyteacher) {
+        lyteacher = await this.teamodel.findById(classes.lyteacherid);
+      }
+    }
+    // 教课老师信息
+    let 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);
+        }
+      }
+    }
+    teachers.push(lyteacher);
+    teachers.push(headteacher);
+    teachers = _.uniq(_.compact(teachers));
+    classes.teachers = teachers;
+    return classes;
+  }
 }
 
 module.exports = ClassService;