Quellcode durchsuchen

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

liuyu vor 4 Jahren
Ursprung
Commit
25605144ad

+ 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 });
   }
 }
 

+ 5 - 0
app/controller/uploadtask.js

@@ -13,6 +13,11 @@ class UploadtaskController extends Controller {
     this.service = this.ctx.service.uploadtask;
   }
 
+  async index() {
+    const res = await this.service.query(this.ctx.query);
+    this.ctx.ok({ ...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

+ 42 - 0
app/service/class.js

@@ -18,6 +18,7 @@ class ClassService extends CrudService {
     this.gmodel = this.ctx.model.Group;
     this.heamodel = this.ctx.model.Headteacher;
     this.teamodel = this.ctx.model.Teacher;
+    this.locamodel = this.ctx.model.Location;
   }
 
   async divide(data) {
@@ -166,6 +167,26 @@ class ClassService extends CrudService {
         }
       }
     }
+    if (classInfo.yclocationid) {
+      classInfo.yclocation = (await this.locamodel.findById(classInfo.yclocationid)).name;
+    }
+    if (classInfo.kzjhlocationid) {
+      classInfo.kzjhlocation = (await this.locamodel.findById(classInfo.kzjhlocationid)).name;
+    }
+    if (classInfo.kbyslocationid) {
+      classInfo.kbyslocation = (await this.locamodel.findById(classInfo.kbyslocationid)).name;
+    }
+    if (classInfo.jslocationid) {
+      classInfo.jslocation = (await this.locamodel.findById(classInfo.jslocationid)).name;
+    }
+    if (classInfo.headteacherid) {
+      classInfo.headteacher = (await this.heamodel.findById(classInfo.headteacherid)).name;
+    }
+    if (classInfo.lyteacherid) {
+      let res = await this.teamodel.findById(classInfo.lyteacherid);
+      if (!res) res = await this.heamodel.findById(classInfo.lyteacherid);
+      if (res)classInfo.lyteacher = res.name;
+    }
     return classInfo;
   }
 
@@ -181,7 +202,18 @@ class ClassService extends CrudService {
     const classes = _.cloneDeep(JSON.parse(JSON.stringify(_classes)));
     // 学生信息
     const students = await this.stumodel.find({ classid });
+    // 所有用户信息
+    const users = await this.umodel.find();
     if (students) {
+      for (const stu of students) {
+        const user = users.find(item => item.uid === stu.id);
+        if (user && user.openid) {
+          const _stu = _.cloneDeep(JSON.parse(JSON.stringify(stu)));
+          _stu.hasuserinfo = '1';
+          _.remove(students, stu);
+          students.push(_stu);
+        }
+      }
       classes.students = students;
     }
     // 班主任信息
@@ -211,6 +243,16 @@ class ClassService extends CrudService {
     teachers.push(lyteacher);
     teachers.push(headteacher);
     teachers = _.uniq(_.compact(teachers));
+    for (const tea of teachers) {
+      const user = users.find(item => item.uid === tea.id);
+      console.log(user);
+      if (user && user.openid) {
+        const _tea = _.cloneDeep(JSON.parse(JSON.stringify(tea)));
+        _tea.hasuserinfo = '1';
+        _.remove(teachers, tea);
+        teachers.push(_tea);
+      }
+    }
     classes.teachers = teachers;
     return classes;
   }

+ 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({ id: elm.classid });
+          data.push(cla);
+        }
+      }
+    }
+    return data;
+  }
+
   async uplessones(data) {
     for (const _data of data) {
       await this.model.findByIdAndUpdate(_data.id, _data);

+ 9 - 12
app/service/notice.js

@@ -66,9 +66,7 @@ class NoticeService extends CrudService {
       const elm = [];
       for (const notified of notice.notified) {
         const _notified = _.cloneDeep(JSON.parse(JSON.stringify(notified)));
-        const user = await this.umodel.findOne({ uid: _notified.notifiedid });
-        const userinfo = await this.findUserInfo(user);
-        console.log({ ...JSON.parse(JSON.stringify(userinfo)), ..._notified });
+        const userinfo = await this.findUserInfo(_notified.notifiedid);
         elm.push({ ...JSON.parse(JSON.stringify(userinfo)), ..._notified });
       }
       res.push({ noticeid, content, meta, notified: elm });
@@ -76,19 +74,18 @@ class NoticeService extends CrudService {
     return { data: res, total };
   }
 
-  async findUserInfo(user) {
+  async findUserInfo(userid) {
     let userinfo;
-    if (user.type === '1') {
-      userinfo = await this.heamodel.findById(user.uid);
-    } else if (user.type === '2') {
-      userinfo = await this.schmodel.findById(user.uid);
-    } else if (user.type === '3') {
-      userinfo = await this.teamodel.findById(user.uid);
+    userinfo = await this.heamodel.findById(userid);
+    if (!userinfo) {
+      userinfo = await this.schmodel.findById(userid);
+    } if (!userinfo) {
+      userinfo = await this.teamodel.findById(userid);
       if (userinfo) {
         delete userinfo.status;
       }
-    } else if (user.type === '4') {
-      userinfo = await this.stumodel.findById(user.uid);
+    } if (!userinfo) {
+      userinfo = await this.stumodel.findById(userid);
     }
     return userinfo;
   }

+ 14 - 0
app/service/uploadtask.js

@@ -11,6 +11,20 @@ class UploadtaskService extends CrudService {
   constructor(ctx) {
     super(ctx, 'uploadtask');
     this.model = this.ctx.model.Uploadtask;
+    this.stumodel = this.ctx.model.Student;
+  }
+
+  async query({ skip, limit, ...info }) {
+    const total = await this.model.count(info);
+    const res = await this.model.find(info).skip(Number(skip)).limit(Number(limit));
+    const data = [];
+    for (const elm of res) {
+      const _elm = _.cloneDeep(JSON.parse(JSON.stringify(elm)));
+      const stu = await this.stumodel.findById(_elm.studentid);
+      _elm.stuname = stu.name;
+      data.push(_elm);
+    }
+    return { data, total };
   }
 
 }