lrf402788946 4 anos atrás
pai
commit
468160d149
1 arquivos alterados com 25 adições e 64 exclusões
  1. 25 64
      app/service/lesson.js

+ 25 - 64
app/service/lesson.js

@@ -319,13 +319,17 @@ class LessonService extends CrudService {
       // 班主任信息
       let data = await this.getHeadTeacherMsg(classInfo);
       // 礼仪教师信息
-      const lydata = await this.getLyTeacherMsg(classInfo);
+      let lydata = await this.getLyTeacherMsg(classInfo);
       // 整理信息
       data = { ...data, ...defaults, termid, classid, planyearid, planid };
       const dirIsBefore = moment().isBefore(classInfo.startdate);
       if (dirIsBefore) {
         noticeList.push(data);
-        if (lydata) noticeList.push(lydata);
+        if (lydata) {
+          lydata = { ...lydata, ...defaults, termid, classid, planyearid, planid };
+          console.log(lydata);
+          noticeList.push(lydata);
+        }
       }
       const { lessons } = l;
       let have_teacherLesson = lessons.filter(f => f.teaid);
@@ -459,36 +463,38 @@ class LessonService extends CrudService {
 
 
   async toSendMsg(noticeList) {
-    console.log(noticeList);
     for (const notice of noticeList) {
       // 先找信息notice,然后查看有没有这个人的信息,有就发送,没有就添加,再发送
       // 课表通知,1个班的信息放一起,按班级来看
       const { planyearid, planid, termid, classid, noticeid, type, ncontent, content, username, notifiedid, email, openid } = notice;
       // await this.nmodel.deleteMany({ termid, planid, classid, type });
-      // 排除重复,没有的填进对应的班级中
       let nres = await this.nmodel.findOne({ termid, planid, classid, type });
-      if (!nres) {
+      if (openid) {
+        // 排除重复,没有的填进对应的班级中
+        if (!nres) {
         // 组织数据,存起来
-        const notified = [{ content, username, notifiedid }];
-        const nobj = { planyearid, planid, termid, classid, noticeid, type, content: ncontent, notified };
-        await this.nmodel.create(nobj);
-        nres = await this.nmodel.findOne({ termid, planid, classid, type });
-      } else {
+          const notified = [{ content, username, notifiedid }];
+          const nobj = { planyearid, planid, termid, classid, noticeid, type, content: ncontent, notified };
+          await this.nmodel.create(nobj);
+          nres = await this.nmodel.findOne({ termid, planid, classid, type });
+        } else {
         // 有该班的通知,然后查看是否有这个人,没有,加进去,有这个人,不管
-        if (nres.notified && _.isArray(nres.notified)) {
-          const r = nres.notified.find(f => f.notifiedid === notifiedid);
-          // 没有人,加进去,保存
-          if (!r) {
-            nres.notified.push({ content, username, notifiedid });
-            await nres.save();
-          } else {
+          if (nres.notified && _.isArray(nres.notified)) {
+            const r = nres.notified.find(f => f.notifiedid === notifiedid);
+            // 没有人,加进去,保存
+            if (!r) {
+              nres.notified.push({ content, username, notifiedid });
+              await nres.save();
+            } else {
             // 有这个人,需要查这个人是否接收到信息,接收到信息,就不需要再次发送了
-            const { status } = r;
-            if (status !== '0') continue;
+              const { status } = r;
+              if (status !== '0') continue;
+            }
           }
         }
       }
 
+
       // 邮件
       if (email) {
         const subject = '吉林省高等学校毕业生就业指导中心通知';
@@ -507,52 +513,7 @@ class LessonService extends CrudService {
           tourl
         );
       }
-
-
     }
-
-
-    // const r = alreadyList.find(f => ObjectId(f.notifiedid).equals(teacherInfo._id));
-    // if (r) return;
-    // let person = null;
-    // if (teacherInfo) {
-    //   let email;
-    //   if (type === 'headteacher') {
-    //     const { qq } = teacherInfo;
-    //     if (qq) email = `${qq}@qq.com`;
-    //   } else {
-    //     email = teacherInfo.email;
-    //   }
-    //   // 发邮件
-    //   if (email) {
-    //     // console.error(`${teacherInfo.name}-email:${email}`);
-    //     const subject = '吉林省高等学校毕业生就业指导中心通知';
-    //     const text = teacherInfo.name + `${content},请您尽快登陆双困生培训系统查看您的安排,系统邮件,请勿回复!`;
-    //     this.ctx.service.util.sendMail('2938260457@qq.com', subject, text); // email
-    //   }
-
-
-    //   // 获取openid,推送
-    //   const teacherUser = await this.umodel.findOne({ uid: teacherInfo._id });
-    //   if (teacherUser) {
-    //     const { openid } = teacherUser;
-    //     if (openid) {
-    //       const tourl = this.ctx.app.config.baseUrl + '/msgconfirm/?userid=' + teacherUser.uid + '&noticeid=' + nresid;
-    //       // TODO 推送
-    //       await this.ctx.service.weixin.sendTemplateDesign(
-    //         this.ctx.app.config.REVIEW_TEMPLATE_ID,
-    //         'ocPqjswkUejZHq2ANriNrFFC7A3I',
-    //         '您有一个新的通知,请点击信息,确认您已收到信息!(若已确认,则无需理会)',
-    //         '您有新的安排',
-    //         content,
-    //         '感谢您的使用',
-    //         tourl
-    //       );
-    //       person = { notifiedid: teacherUser.uid, username: teacherUser.name };
-    //     }
-    //   }
-    // }
-    // return person;
   }
 
   // 新排课,从计划中拿出来对应的课表