瀏覽代碼

新增确认班级所有信息后向班主任、教师、学生发送通知,新增分寝后向班主任发送学生寝室安排

reloaded 5 年之前
父節點
當前提交
2e6d61a6fa
共有 8 個文件被更改,包括 100 次插入28 次删除
  1. 9 9
      app/controller/.lesson.js
  2. 5 0
      app/controller/class.js
  3. 3 3
      app/model/lesson.js
  4. 1 0
      app/router.js
  5. 16 4
      app/service/bedroom.js
  6. 40 0
      app/service/class.js
  7. 3 3
      app/service/leave.js
  8. 23 9
      app/service/trainplan.js

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

@@ -1,9 +1,9 @@
 module.exports = {
   create: {
     requestBody: [
-      '!class',
-      '!term',
-      '!batch',
+      '!classid',
+      '!termid',
+      '!batchid',
       'lessons'
     ]
   },
@@ -14,9 +14,9 @@ module.exports = {
   update: {
     params: ['!id'],
     requestBody: [
-      'class',
-      'term',
-      'batch',
+      'classid',
+      'termid',
+      'batchid',
       'lessons'
     ]
   },
@@ -29,9 +29,9 @@ module.exports = {
   index: {
     parameters: {
       query: {
-        class :'class',
-        term:'term',
-        batch :'batch',
+        classid:'classid',
+        termid:'termid',
+        batchid:'batchid',
         lessons :'lessons'
       }
     },

+ 5 - 0
app/controller/class.js

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

+ 3 - 3
app/model/lesson.js

@@ -14,9 +14,9 @@ const lessonInfo = new Schema({
 
 // 课程表
 const LessonSchema = {
-  class: { type: String, required: true, maxLength: 500 }, // 班级
-  term: { type: String, required: true, maxLength: 500 }, // 期
-  batch: { type: String, required: true, maxLength: 500 }, // 批次
+  classid: { type: String, required: true, maxLength: 500 }, // 班级id
+  termid: { type: String, required: true, maxLength: 500 }, // 期id
+  batchid: { type: String, required: true, maxLength: 500 }, // 批次id
   lessons: { type: [ lessonInfo ], select: true }, // 课程信息
 };
 

+ 1 - 0
app/router.js

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

+ 16 - 4
app/service/bedroom.js

@@ -11,8 +11,11 @@ class BedroomService extends CrudService {
   constructor(ctx) {
     super(ctx, 'bedroom');
     this.model = this.ctx.model.Bedroom;
-    this.umodel = this.ctx.model.Student;
+    this.smodel = this.ctx.model.Student;
     this.tmodel = this.ctx.model.Trainplan;
+    this.cmodel = this.ctx.model.Class;
+    this.umodel = this.ctx.model.User;
+
   }
 
   // 一键分寝
@@ -80,20 +83,29 @@ class BedroomService extends CrudService {
         }
       }
     }
-
+    const classes = await this.cmodel.find({ batchid });
+    for (const _class of classes) {
+      const headteacherid = _class.headteacherid;
+      const headteacher = await this.umodel.findOne({ uid: headteacherid, type: '1' });
+      const openid = headteacher.openid;
+      const remark = '感谢您的使用';
+      const date = await this.ctx.service.util.updatedate();
+      const detail = '班级学生名单与寝室安排已确认,请及时查收';
+      this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark, _class.id);
+    }
   }
 
   // 取得符合条件的学生列表
   async getstudents(termid, batchid) {
     // 根据期id查找所有当期学生列表
-    const studentList = await this.umodel.find({ termid, batchid }).sort({ gender: -1 });
+    const studentList = await this.smodel.find({ termid, batchid }).sort({ gender: -1 });
     return studentList;
   }
 
   // 取得符合条件的学生列表
   async getbedroomstudents(termid, batchid, bedroomid) {
     // 根据期id查找所有当期学生列表
-    const studentList = await this.umodel.find({ termid, batchid, bedroomid });
+    const studentList = await this.smodel.find({ termid, batchid, bedroomid });
     return studentList;
   }
 }

+ 40 - 0
app/service/class.js

@@ -12,6 +12,9 @@ class ClassService extends CrudService {
     super(ctx, 'class');
     this.model = this.ctx.model.Class;
     this.stumodel = this.ctx.model.Student;
+    this.lessmodel = this.ctx.model.Lesson;
+    this.umodel = this.ctx.model.User;
+    this.tmodel = this.ctx.model.Trainplan;
   }
 
   async divide(data) {
@@ -56,6 +59,43 @@ class ClassService extends CrudService {
     }
 
   }
+
+  async notice(data) {
+    for (const classid of data.classids) {
+      const _class = await this.model.findById(classid);
+      const { headteacherid } = _class;
+      const lesson = await this.lessmodel.findOne({ classid });
+      const lessons = lesson.lessons;
+      const remark = '感谢您的使用';
+      const date = await this.ctx.service.util.updatedate();
+      const detail = '班级各项信息已确认,请注意查收';
+      // 遍历班级授课教师发送通知
+      for (const lessoninfo of lessons) {
+        const teaid = lessoninfo.teaid;
+        const _teacher = await this.umodel.findOne({ uid: teaid, type: '3' });
+        const teaopenid = _teacher.openid;
+        this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, teaopenid, '您有一个新的通知', detail, date, remark, classid);
+      }
+      // 给班主任发送通知
+      const _headteacher = await this.umodel.findOne({ uid: headteacherid, type: '1' });
+      const headteaopenid = _headteacher.openid;
+      this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, headteaopenid, '您有一个新的通知', detail, date, remark, classid);
+      // 根据班级的期id查询对应的培训计划
+      const trainplan = await this.tmodel.findOne({ 'termnum._id': _class.termid });
+      const term = await trainplan.termnum.id(_class.termid);
+      const batch = await term.batchnum.id(_class.batchid);
+      const startdate = batch.startdate;
+      const classname = _class.name;
+      // 给班级所有学生发送邮件通知
+      const students = await this.stumodel.find({ classid });
+      for (const student of students) {
+        const { email, name } = student;
+        const subject = '吉林省高等学校毕业生就业指导中心通知';
+        const text = name + '您好!\n欢迎参加由吉林省高等学校毕业生就业指导中心举办的“双困生培训会”。\n您所在的班级为:' + classname + '\n班级开课时间为:' + startdate;
+        this.ctx.service.util.sendMail(email, subject, text);
+      }
+    }
+  }
 }
 
 module.exports = ClassService;

+ 3 - 3
app/service/leave.js

@@ -21,7 +21,7 @@ class LeaveService extends CrudService {
     const studentid = data.studentid;
     const student = await this.smodel.findById(studentid);
     const schoolid = student.schoolid;
-    const user = await this.umodel.findOne({ uid: schoolid });
+    const user = await this.umodel.findOne({ uid: schoolid, type: '2' });
     const openid = user.openid;
     const date = await this.ctx.service.util.updatedate();
     const detail = student.name + '发起了请假请求,请及时处理';
@@ -48,7 +48,7 @@ class LeaveService extends CrudService {
     if (status) {
       const student = await this.smodel.findById(studentid);
       const remark = '感谢您的使用';
-      const stuuser = await this.umodel.findOne({ uid: studentid });
+      const stuuser = await this.umodel.findOne({ uid: studentid, type: '4' });
       if (status === '1') {
         let detail = student.name + '的请假申请已通过,请及时查收!';
         const users = await this.umodel.find({ type: '0' });
@@ -59,7 +59,7 @@ class LeaveService extends CrudService {
         }
         const _class = await this.cmodel.findById(student.classid);
         const headteacherid = _class.headteacherid;
-        const headuser = await this.umodel.findOne({ uid: headteacherid });
+        const headuser = await this.umodel.findOne({ uid: headteacherid, type: '1' });
         const openid = headuser.openid;
         const date = await this.ctx.service.util.updatedate();
         await this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);

+ 23 - 9
app/service/trainplan.js

@@ -39,25 +39,39 @@ class TrainplanService extends CrudService {
 
   async update({ id }, data) {
     const trainplan = await this.model.findById(id);
-    trainplan.year = data.year;
-    trainplan.title = data.title;
-    trainplan.termnum = data.termnum;
-    trainplan.festivals = data.festivals;
-    if (data.status === '1') {
+    const { year, title, termnum, festivals, status } = data;
+    if (year) {
+      trainplan.year = year;
+    }
+    if (title) {
+      trainplan.title = title;
+    }
+    if (termnum) {
+      trainplan.termnum = termnum;
+    }
+    if (festivals) {
+      trainplan.festivals = festivals;
+    }
+    // 如果培训计划状态改为发布
+    if (status === '1') {
+      // 查询所有入库的教师
       const teachers = await this.tmodel.find({ status: '4' });
       for (const teacher of teachers) {
-        const openid = teacher.openid;
-        const detail = data.title + '已发布,请注意查收!';
+        const teacherid = teacher._id;
+        const _teacher = await this.umodel.findOne({ uid: teacherid, type: '3' });
+        const openid = _teacher.openid;
+        const detail = trainplan.title + '已发布,请注意查收!';
         const moment = require('moment');
         let date = new Date();
         date = moment(date).format('YYYY-MM-DD HH:mm:ss');
         const remark = '感谢您的使用';
         this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
       }
+      // 查询所有学校用户
       const schools = await this.umodel.find({ type: '2' });
       for (const school of schools) {
         const openid = school.openid;
-        const detail = data.title + '已发布,请注意查收!';
+        const detail = trainplan.title + '已发布,请注意查收!';
         const moment = require('moment');
         let date = new Date();
         date = moment(date).format('YYYY-MM-DD HH:mm:ss');
@@ -65,7 +79,7 @@ class TrainplanService extends CrudService {
         this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
       }
     }
-
+    return await trainplan.save();
   }
 }
 module.exports = TrainplanService;