|
@@ -18,7 +18,8 @@ class LessonService extends CrudService {
|
|
|
this.teamodel = this.ctx.model.Teacher;
|
|
|
this.stumodel = this.ctx.model.Student;
|
|
|
this.schmodel = this.ctx.model.School;
|
|
|
-
|
|
|
+ this.headteamodel = this.ctx.model.Headteacher;
|
|
|
+ this.umodel = this.ctx.model.User;
|
|
|
}
|
|
|
|
|
|
// 自动排课私有方法
|
|
@@ -53,7 +54,10 @@ class LessonService extends CrudService {
|
|
|
if (!lessonmode_) {
|
|
|
lessonmode_ = _lessonmode[0];
|
|
|
if (!lessonmode_) {
|
|
|
- throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '课程模板信息不存在');
|
|
|
+ throw new BusinessError(
|
|
|
+ ErrorCode.DATA_NOT_EXIST,
|
|
|
+ '课程模板信息不存在'
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
// 取得模板内容并转化成json
|
|
@@ -117,7 +121,9 @@ class LessonService extends CrudService {
|
|
|
// 自动排教师,按照分数的综合成绩排序,上报时间,安排教师
|
|
|
async autoteacher(subid, teachids) {
|
|
|
// 按照上报时间取得所有老师,进行正序排列
|
|
|
- const teachers = await this.teamodel.find({ subid, status: '4' }).sort({ zlscore: '-1', msscore: '-1', xsscore: '-1' });
|
|
|
+ const teachers = await this.teamodel
|
|
|
+ .find({ subid, status: '4' })
|
|
|
+ .sort({ zlscore: '-1', msscore: '-1', xsscore: '-1' });
|
|
|
for (const teaid of teachids) {
|
|
|
_.remove(teachers, item => item.id === teaid);
|
|
|
}
|
|
@@ -276,6 +282,85 @@ class LessonService extends CrudService {
|
|
|
await this.model.findByIdAndUpdate(_data.id, _data);
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 修改课表的状态,并发送信息
|
|
|
+ * @param {Array} ids 要修改的课表
|
|
|
+ */
|
|
|
+ async check({ ids }) {
|
|
|
+ // 1,修改课表状态; TODO 2,拿到所有的班级,获取所有人员;3,然后发送信息
|
|
|
+ const list = await this.model.find({ _id: { $in: ids } });
|
|
|
+ const res = await this.model.updateMany({ _id: { $in: ids } }, { status: '1' });
|
|
|
+ // 循环课表
|
|
|
+ for (const lessonInfo of list) {
|
|
|
+ // 获取期数
|
|
|
+ const { termid, classid, lessons } = lessonInfo;
|
|
|
+ const planRes = await this.tmodel.findOne({ termnum: { $elemMatch: { _id: termid } } });
|
|
|
+ if (!planRes) continue;
|
|
|
+ const term = planRes.termnum.find(f => ObjectId(termid).equals(f._id));
|
|
|
+ if (!term) continue;
|
|
|
+ const { term: termnum } = term;
|
|
|
+ const classInfo = await this.clamodel.findById(classid);
|
|
|
+ const { headteacherid, lyteacherid } = classInfo;
|
|
|
+ const headteacher = await this.headteamodel.findById(headteacherid);
|
|
|
+ if (headteacher) await this.toSendMsg(headteacher, 'headteacher', termnum);
|
|
|
+ // 礼仪教师和班主任不是一个人时查礼仪教师是班主任还是任课教师,然后发消息
|
|
|
+ if (lyteacherid !== headteacherid) {
|
|
|
+ let lyTeacher = await this.headteamodel.findById(lyteacherid);
|
|
|
+ if (lyTeacher) await this.toSendMsg(lyTeacher, 'headteacher', termnum);
|
|
|
+ else {
|
|
|
+ lyTeacher = await this.teamodel.findById(lyteacherid);
|
|
|
+ if (lyTeacher) await this.toSendMsg(lyTeacher, 'teacher', termnum);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 获取所有任课教师ids
|
|
|
+ const teacherList = _.compact(_.uniq(lessons.map(i => i.teaid)));
|
|
|
+ if (teacherList) {
|
|
|
+ for (const tea of teacherList) {
|
|
|
+ await this.toSendMsg(tea, 'teacher', termnum);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async toSendMsg(teacherInfo, type, term) {
|
|
|
+ if (teacherInfo) {
|
|
|
+ let email;
|
|
|
+ if (type === 'headteacher') {
|
|
|
+ const { qq } = teacherInfo;
|
|
|
+ if (qq) email = `${qq}@qq.com`;
|
|
|
+ } else {
|
|
|
+ email = teacherInfo.email;
|
|
|
+ }
|
|
|
+ // 发邮件
|
|
|
+ if (email) {
|
|
|
+ const subject = '吉林省高等学校毕业生就业指导中心通知';
|
|
|
+ const text = teacherInfo.name + `您好!\n欢迎参加由吉林省高等学校毕业生就业指导中心举办的“双困生培训会”第${term}期,请您尽快登陆双困生培训系统查看您的安排`;
|
|
|
+ this.ctx.service.util.sendMail(email, subject, text);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 获取openid,推送
|
|
|
+ console.log(teacherInfo);
|
|
|
+ const teacherUser = await this.umodel.findOne({ uid: teacherInfo._id });
|
|
|
+ console.log(teacherUser);
|
|
|
+ if (teacherUser) {
|
|
|
+ const { openid } = teacherUser;
|
|
|
+ if (openid) {
|
|
|
+ // TODO 推送
|
|
|
+ await this.ctx.service.weixin.sendTemplateDesign(
|
|
|
+ this.ctx.app.config.REVIEW_TEMPLATE_ID,
|
|
|
+ openid,
|
|
|
+ '您有一个新的通知',
|
|
|
+ '您有新的安排',
|
|
|
+ 'null',
|
|
|
+ '感谢您的使用',
|
|
|
+ 'http://www.baidu.com'
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
module.exports = LessonService;
|