lrf402788946 4 lat temu
rodzic
commit
6f249edd4e
1 zmienionych plików z 45 dodań i 16 usunięć
  1. 45 16
      app/service/lesson.js

+ 45 - 16
app/service/lesson.js

@@ -293,7 +293,6 @@ class LessonService extends CrudService {
     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 } } });
@@ -302,33 +301,59 @@ class LessonService extends CrudService {
       if (!term) continue;
       const { term: termnum } = term;
       const classInfo = await this.clamodel.findById(classid);
-      // TODO创建信息,获取数据
-      const nres = await this.nmodel.create({
+      // 先查找信息,如果有,不需要创建,修改创建信息,获取数据
+      const content = `欢迎参加由吉林省高等学校毕业生就业指导中心举办的"双困生培训会"第${termnum}期`;
+      let is_update = false;
+      let nres = await this.nmodel.findOne({
         planyearid: planRes.planyearid,
         planid: planRes._id,
         termid,
         classid,
         noticeid: 'system',
         type: '4',
-        content: `欢迎参加由吉林省高等学校毕业生就业指导中心举办的"双困生培训会"第${termnum}期`,
       });
+      if (nres) is_update = true;
+      if (!is_update) {
+        nres = await this.nmodel.create({
+          planyearid: planRes.planyearid,
+          planid: planRes._id,
+          termid,
+          classid,
+          noticeid: 'system',
+          type: '4',
+          content,
+        });
+      }
+
       const { headteacherid, lyteacherid } = classInfo;
       const headteacher = await this.headteamodel.findById(headteacherid);
       if (headteacher) {
-        const r = await this.toSendMsg(headteacher, 'headteacher', termnum, nres._id);
-        if (r)nres.notified.push(r);
+        const r = await this.toSendMsg(headteacher, 'headteacher', termnum, nres._id, content);
+        if (r && is_update) nres.notified.push(r);
+        else if (r && !is_update) {
+          const dr = nres.notified.find(f => f.notifiedid === r.notifiedid);
+          if (!dr) nres.notified.push(r);
+        }
       }
       // 礼仪教师和班主任不是一个人时查礼仪教师是班主任还是任课教师,然后发消息
       if (lyteacherid !== headteacherid) {
         let lyTeacher = await this.headteamodel.findById(lyteacherid);
         if (lyTeacher) {
-          const r = await this.toSendMsg(lyTeacher, 'headteacher', termnum);
-          if (r)nres.notified.push(r);
+          const r = await this.toSendMsg(lyTeacher, 'headteacher', termnum, nres._id, content);
+          if (r && is_update) nres.notified.push(r);
+          else if (r && !is_update) {
+            const dr = nres.notified.find(f => f.notifiedid === r.notifiedid);
+            if (!dr) nres.notified.push(r);
+          }
         } else {
           lyTeacher = await this.teamodel.findById(lyteacherid);
           if (lyTeacher) {
-            const r = await this.toSendMsg(lyTeacher, 'teacher', termnum);
-            if (r) nres.notified.push(r);
+            const r = await this.toSendMsg(lyTeacher, 'teacher', termnum, nres._id, content);
+            if (r && is_update) nres.notified.push(r);
+            else if (r && !is_update) {
+              const dr = nres.notified.find(f => f.notifiedid === r.notifiedid);
+              if (!dr) nres.notified.push(r);
+            }
           }
         }
       }
@@ -336,15 +361,19 @@ class LessonService extends CrudService {
       const teacherList = _.compact(_.uniq(lessons.map(i => i.teaid)));
       if (teacherList) {
         for (const tea of teacherList) {
-          const r = await this.toSendMsg(tea, 'teacher', termnum);
-          if (r) nres.notified.push(r);
+          const r = await this.toSendMsg(tea, 'teacher', termnum, nres._id, content);
+          if (r && is_update) nres.notified.push(r);
+          else if (r && !is_update) {
+            const dr = nres.notified.find(f => f.notifiedid === r.notifiedid);
+            if (!dr) nres.notified.push(r);
+          }
         }
       }
       nres.save();
     }
   }
 
-  async toSendMsg(teacherInfo, type, term, nresid) {
+  async toSendMsg(teacherInfo, type, term, nresid, content) {
     let person = null;
     if (teacherInfo) {
       let email;
@@ -358,7 +387,7 @@ class LessonService extends CrudService {
       if (email) {
         console.error(`${teacherInfo.name}-email:${email}`);
         const subject = '吉林省高等学校毕业生就业指导中心通知';
-        const text = teacherInfo.name + `您好!\n欢迎参加由吉林省高等学校毕业生就业指导中心举办的“双困生培训会”第${term}期,请您尽快登陆双困生培训系统查看您的安排`;
+        const text = teacherInfo.name + `${content},请您尽快登陆双困生培训系统查看您的安排`;
         this.ctx.service.util.sendMail(email, subject, text);
       }
 
@@ -375,9 +404,9 @@ class LessonService extends CrudService {
             openid,
             '您有一个新的通知,请点击信息,确认您已收到信息!',
             '您有新的安排',
-            `欢迎参加由吉林省高等学校毕业生就业指导中心举办的"双困生培训会"第${term}期`,
+            content,
             '感谢您的使用',
-            'http://www.baidu.com'
+            tourl
           );
           person = { notifiedid: teacherUser.uid, username: teacherUser.name };
         }