|
@@ -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;
|