|
@@ -69,8 +69,9 @@ class TrainplanService extends CrudService {
|
|
|
if (trainplan.termnum) {
|
|
|
// trainplan.termnum =
|
|
|
trainplan.termnum = await this.termGetLesson(trainplan.termnum);
|
|
|
+ // 重新查看每个班级是否有课程
|
|
|
+ trainplan.termnum = this.setClassLesson(trainplan.termnum);
|
|
|
}
|
|
|
-
|
|
|
// 如果培训计划状态改为发布,发送培训计划信息,并自动生成班级
|
|
|
const res = await trainplan.save();
|
|
|
if (res) {
|
|
@@ -82,46 +83,47 @@ class TrainplanService extends CrudService {
|
|
|
// await this.autoclassname(res);
|
|
|
// 发送培训计划信息通知给相应人员
|
|
|
// 查询所有入库的教师
|
|
|
- const teachers = await this.tmodel.find({ status: '4' });
|
|
|
- for (const teacher of teachers) {
|
|
|
- const teacherid = teacher._id;
|
|
|
- const _teacher = await this.umodel.findOne({
|
|
|
- uid: teacherid,
|
|
|
- type: '3',
|
|
|
- });
|
|
|
- const openid = _teacher.openid;
|
|
|
- const detail = trainplan.title + '已发布,请注意查收!';
|
|
|
- const date = await this.ctx.service.util.updatedate();
|
|
|
- const remark = '感谢您的使用';
|
|
|
- if (openid) {
|
|
|
- this.ctx.service.weixin.sendTemplateMsg(
|
|
|
- this.ctx.app.config.REVIEW_TEMPLATE_ID,
|
|
|
- openid,
|
|
|
- '您有一个新的通知',
|
|
|
- detail,
|
|
|
- date,
|
|
|
- remark
|
|
|
- );
|
|
|
- }
|
|
|
- }
|
|
|
+ // 不需要给教师发信息
|
|
|
+ // const teachers = await this.tmodel.find({ status: '4' });
|
|
|
+ // for (const teacher of teachers) {
|
|
|
+ // const teacherid = teacher._id;
|
|
|
+ // const _teacher = await this.umodel.findOne({
|
|
|
+ // uid: teacherid,
|
|
|
+ // type: '3',
|
|
|
+ // });
|
|
|
+ // const openid = _teacher.openid;
|
|
|
+ // const detail = trainplan.title + '已发布,请注意查收!';
|
|
|
+ // const date = await this.ctx.service.util.updatedate();
|
|
|
+ // const remark = '感谢您的使用';
|
|
|
+ // if (openid) {
|
|
|
+ // 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 = trainplan.title + '已发布,请注意查收!';
|
|
|
- const date = await this.ctx.service.util.updatedate();
|
|
|
- const remark = '感谢您的使用';
|
|
|
- if (openid) {
|
|
|
- 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 = trainplan.title + '已发布,请注意查收!';
|
|
|
+ // const date = await this.ctx.service.util.updatedate();
|
|
|
+ // const remark = '感谢您的使用';
|
|
|
+ // if (openid) {
|
|
|
+ // this.ctx.service.weixin.sendTemplateMsg(
|
|
|
+ // this.ctx.app.config.REVIEW_TEMPLATE_ID,
|
|
|
+ // openid,
|
|
|
+ // '您有一个新的通知',
|
|
|
+ // detail,
|
|
|
+ // date,
|
|
|
+ // remark
|
|
|
+ // );
|
|
|
+ // }
|
|
|
+ // }
|
|
|
}
|
|
|
// 查哪个学校schtime表没有生成,就给生成了
|
|
|
const schoolList = await this.smodel.find();
|
|
@@ -195,6 +197,35 @@ class TrainplanService extends CrudService {
|
|
|
}
|
|
|
return termnum;
|
|
|
}
|
|
|
+ // 设置课表模板到班级上
|
|
|
+ setClassLesson(termnum) {
|
|
|
+ // 为班级设置lessons,有的就不设置了
|
|
|
+ for (const t of termnum) {
|
|
|
+ const { batchnum } = t;
|
|
|
+ if (!batchnum || !_.isArray(batchnum)) {
|
|
|
+ this.$message.error(`第${t.term}期的批次数据错误!`);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (const b of t.batchnum) {
|
|
|
+ const { class: cla, lessons: ltemplate } = b;
|
|
|
+ if (!cla) {
|
|
|
+ console.warn(`${t.term}期${b.batch}批次没有班级列表`);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (!ltemplate) {
|
|
|
+ console.warn(`${t.term}期${b.batch}批次没有课表`);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (const c of b.class) {
|
|
|
+ const { lessons } = c;
|
|
|
+ if (lessons) {
|
|
|
+ if (lessons.length <= 0) c.lessons = ltemplate;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return termnum;
|
|
|
+ }
|
|
|
|
|
|
// 自动生成班级私有方法
|
|
|
async autoclassNew(res) {
|