lrf402788946 4 년 전
부모
커밋
d822c63e64
4개의 변경된 파일42개의 추가작업 그리고 10개의 파일을 삭제
  1. 1 0
      app/model/notice.js
  2. 6 1
      app/service/bedroom.js
  3. 34 8
      app/service/lesson.js
  4. 1 1
      app/service/notice.js

+ 1 - 0
app/model/notice.js

@@ -18,6 +18,7 @@ const NoticeSchema = {
   classid: { type: String, required: false, maxLength: 200 }, // 班级id
   noticeid: { type: String, required: true, maxLength: 200 }, // 通知人id
   content: { type: String, required: true }, // 通知内容
+  type: { type: String, required: false, maxLength: 200, default: '0' }, // 状态,0-培训自定义通知;1-日历通知;2-班主任计划通知;3-学校计划通知;4-课表通知;5-分寝通知
   notified: { type: [ notifiedInfo ], select: true }, // 被通知信息
 };
 

+ 6 - 1
app/service/bedroom.js

@@ -16,6 +16,7 @@ class BedroomService extends CrudService {
     this.cmodel = this.ctx.model.Class;
     this.umodel = this.ctx.model.User;
     this.ctmodel = this.ctx.model.Classtype;
+    this.nmodel = this.ctx.model.Notice;
 
   }
 
@@ -122,6 +123,9 @@ class BedroomService extends CrudService {
     }
     // 取得当前批次的所有班级
     const classes = await this.cmodel.find({ batchid });
+    const detail = '班级学生名单与寝室安排已确认,请及时查收';
+    const nres = await this.nmodel.create({ planyearid: trainplan.planyearid, planid: trainplanid, termid, noticeid: 'system', content: detail, type: '5' });
+
     for (const _class of classes) {
       // 取得每个班级的班主任id
       const headteacherid = _class.headteacherid;
@@ -130,9 +134,10 @@ class BedroomService extends CrudService {
         const openid = headteacher.openid;
         const remark = '感谢您的使用';
         const date = await this.ctx.service.util.updatedate();
-        const detail = '班级学生名单与寝室安排已确认,请及时查收';
         this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark, _class.id);
+        nres.notified.push({ notifiedid: headteacher.uid, username: headteacher.name });
       }
+      await nres.save();
 
     }
   }

+ 34 - 8
app/service/lesson.js

@@ -20,6 +20,7 @@ class LessonService extends CrudService {
     this.schmodel = this.ctx.model.School;
     this.headteamodel = this.ctx.model.Headteacher;
     this.umodel = this.ctx.model.User;
+    this.nmodel = this.ctx.model.Notice;
   }
 
   // 自动排课私有方法
@@ -292,6 +293,7 @@ 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 } } });
@@ -300,29 +302,50 @@ 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({
+        planyearid: planRes.planyearid,
+        planid: planRes._id,
+        termid,
+        classid,
+        noticeid: 'system',
+        type: '4',
+        content: `欢迎参加由吉林省高等学校毕业生就业指导中心举办的"双困生培训会"第${termnum}期`,
+      });
       const { headteacherid, lyteacherid } = classInfo;
       const headteacher = await this.headteamodel.findById(headteacherid);
-      if (headteacher) await this.toSendMsg(headteacher, 'headteacher', termnum);
+      if (headteacher) {
+        const r = await this.toSendMsg(headteacher, 'headteacher', termnum, nres._id);
+        if (r)nres.notified.push(r);
+      }
       // 礼仪教师和班主任不是一个人时查礼仪教师是班主任还是任课教师,然后发消息
       if (lyteacherid !== headteacherid) {
         let lyTeacher = await this.headteamodel.findById(lyteacherid);
-        if (lyTeacher) await this.toSendMsg(lyTeacher, 'headteacher', termnum);
-        else {
+        if (lyTeacher) {
+          const r = await this.toSendMsg(lyTeacher, 'headteacher', termnum);
+          if (r)nres.notified.push(r);
+        } else {
           lyTeacher = await this.teamodel.findById(lyteacherid);
-          if (lyTeacher) await this.toSendMsg(lyTeacher, 'teacher', termnum);
+          if (lyTeacher) {
+            const r = await this.toSendMsg(lyTeacher, 'teacher', termnum);
+            if (r) nres.notified.push(r);
+          }
         }
       }
       // 获取所有任课教师ids
       const teacherList = _.compact(_.uniq(lessons.map(i => i.teaid)));
       if (teacherList) {
         for (const tea of teacherList) {
-          await this.toSendMsg(tea, 'teacher', termnum);
+          const r = await this.toSendMsg(tea, 'teacher', termnum);
+          if (r) nres.notified.push(r);
         }
       }
+      nres.save();
     }
   }
 
-  async toSendMsg(teacherInfo, type, term) {
+  async toSendMsg(teacherInfo, type, term, nresid) {
+    let person = null;
     if (teacherInfo) {
       let email;
       if (type === 'headteacher') {
@@ -345,19 +368,22 @@ class LessonService extends CrudService {
       if (teacherUser) {
         const { openid } = teacherUser;
         if (openid) {
+          const tourl = this.ctx.app.config.baseUrl + '/trainnotice/?userid=' + teacherUser.uid + '&noticeid=' + nresid;
           // TODO 推送
           await this.ctx.service.weixin.sendTemplateDesign(
             this.ctx.app.config.REVIEW_TEMPLATE_ID,
             openid,
-            '您有一个新的通知',
+            '您有一个新的通知,请点击信息,确认您已收到信息!',
             '您有新的安排',
-            `欢迎参加由吉林省高等学校毕业生就业指导中心举办的“双困生培训会”第${term}期`,
+            `欢迎参加由吉林省高等学校毕业生就业指导中心举办的"双困生培训会"第${term}期`,
             '感谢您的使用',
             'http://www.baidu.com'
           );
+          person = { notifiedid: teacherUser.uid, username: teacherUser.name };
         }
       }
     }
+    return person;
   }
 
 }

+ 1 - 1
app/service/notice.js

@@ -29,7 +29,7 @@ class NoticeService extends CrudService {
     assert(noticeid, '通知人id为必填项');
     assert(content, '通知内容为必填项');
     // type:0=>所有人;1=>学生;2=>教师;3=>班主任 TODO:缺少个人发信息
-    const res = await this.model.create(data);
+    const res = await this.model.create({ ...data, type: '0' });
     let range = 'term';
     let personList = [];
     if (classid) range = 'class';