|
@@ -25,32 +25,102 @@ class NoticeService extends CrudService {
|
|
|
const { planyearid, planid, termid, classid, noticeid, content, notified, type } = data;
|
|
|
assert(planyearid, '年度计划id为必填项');
|
|
|
assert(planid, '计划id为必填项');
|
|
|
+ assert(termid, '期id为必填项');
|
|
|
assert(noticeid, '通知人id为必填项');
|
|
|
assert(content, '通知内容为必填项');
|
|
|
+ // type:0=>所有人;1=>学生;2=>教师;3=>班主任 TODO:缺少个人发信息
|
|
|
const res = await this.model.create(data);
|
|
|
- if (res) {
|
|
|
- // 判断班级id是否为空
|
|
|
- // 不为空时被通知人:当前期,班下的学生,教师,班主任,并使用type判断
|
|
|
- const notified_ = await this.getnotified(termid, classid, type);
|
|
|
- res.notified = notified_;
|
|
|
- await res.save();
|
|
|
- for (const elm of notified_) {
|
|
|
- const user = await this.umodel.findOne({ uid: elm.notifiedid });
|
|
|
- if (!user) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (user.openid) {
|
|
|
- const openid = user.openid;
|
|
|
- const remark = '感谢您的使用';
|
|
|
- const date = await this.ctx.service.util.updatedate();
|
|
|
- const detail = '尊敬的' + user.name + ',您有一个新的通知,请及时查收';
|
|
|
- const tourl = this.ctx.app.config.baseUrl + '/mobiledirtea/messageInfo/index?uid=' + user.uid + '¬iceid=' + res.id;
|
|
|
- this.ctx.service.weixin.sendTemplateDesign(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark, tourl);
|
|
|
- }
|
|
|
- }
|
|
|
+ let range = 'term';
|
|
|
+ let personList = [];
|
|
|
+ if (classid) range = 'class';
|
|
|
+ if (range === 'term') {
|
|
|
+ if (type === '0') {
|
|
|
+ const sList = await this.getRangeStudent({ termid });
|
|
|
+ const tList = await this.getRangeTeacher({ termid });
|
|
|
+ const hList = await this.getRangeClasses({ termid });
|
|
|
+ personList = [ ...sList, ...tList, ...hList ];
|
|
|
+ } else if (type === '1') personList = await this.getRangeStudent({ termid });
|
|
|
+ else if (type === '2')personList = await this.getRangeTeacher({ termid });
|
|
|
+ else if (type === '3')personList = await this.getRangeClasses({ termid });
|
|
|
+ } else if (range === 'class') {
|
|
|
+ if (type === '0') {
|
|
|
+ const sList = await this.getRangeStudent({ classid });
|
|
|
+ const tList = await this.getRangeTeacher({ classid });
|
|
|
+ const hList = await this.getRangeClasses({ id: classid });
|
|
|
+ personList = [ ...sList, ...tList, ...hList ];
|
|
|
+ } else if (type === '1') personList = await this.getRangeStudent({ classid });
|
|
|
+ else if (type === '2') personList = await this.getRangeTeacher({ classid });
|
|
|
+ else if (type === '3') personList = await this.getRangeClasses({ id: classid });
|
|
|
}
|
|
|
+ // 获取所有人后发送信息
|
|
|
+ const userList = await this.umodel.find({ uid: { $in: personList } });
|
|
|
+ for (const user of userList) {
|
|
|
+ // 1,判断有没有openid;2有openid的发送消息,添加记录
|
|
|
+ if (!_.get(user, 'openid')) continue;
|
|
|
+ const openid = _.get(user, 'openid');
|
|
|
+ const remark = '感谢您的使用';
|
|
|
+ const date = await this.ctx.service.util.updatedate();
|
|
|
+ const detail = '尊敬的' + user.name + ',您有一个新的通知,请及时查收';
|
|
|
+ const tourl = this.ctx.app.config.baseUrl + '/mobiledirtea/messageInfo/index?uid=' + user.uid + '¬iceid=' + res.id;
|
|
|
+ this.ctx.service.weixin.sendTemplateDesign(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark, tourl);
|
|
|
+ const notified = _.get(res, 'notified', []);
|
|
|
+ notified.push({ notifiedid: user._id, username: user.name });
|
|
|
+ res.notified = notified;
|
|
|
+ }
|
|
|
+ res.save();
|
|
|
+ // if (res) {
|
|
|
+ // // 判断班级id是否为空
|
|
|
+ // // 不为空时被通知人:当前期,班下的学生,教师,班主任,并使用type判断
|
|
|
+ // const notified_ = await this.getnotified(termid, classid, type);
|
|
|
+ // res.notified = notified_;
|
|
|
+ // await res.save();
|
|
|
+ // for (const elm of notified_) {
|
|
|
+ // const user = await this.umodel.findOne({ uid: elm.notifiedid });
|
|
|
+ // if (!user) {
|
|
|
+ // continue;
|
|
|
+ // }
|
|
|
+ // if (user.openid) {
|
|
|
+ // const openid = user.openid;
|
|
|
+ // const remark = '感谢您的使用';
|
|
|
+ // const date = await this.ctx.service.util.updatedate();
|
|
|
+ // const detail = '尊敬的' + user.name + ',您有一个新的通知,请及时查收';
|
|
|
+ // const tourl = this.ctx.app.config.baseUrl + '/mobiledirtea/messageInfo/index?uid=' + user.uid + '¬iceid=' + res.id;
|
|
|
+ // this.ctx.service.weixin.sendTemplateDesign(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark, tourl);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据条件返回学生列表
|
|
|
+ * @param {Object} condition 查询学生的条件
|
|
|
+ */
|
|
|
+ async getRangeStudent(condition) {
|
|
|
+ const res = await this.stumodel.find(condition);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 根据条件返回教师列表
|
|
|
+ * @param {Object} condition 查询教师的条件
|
|
|
+ */
|
|
|
+ async getRangeTeacher(condition) {
|
|
|
+ // teamodel;lmodel
|
|
|
+ const lessonList = await this.lmodel.find(condition);
|
|
|
+ const teacherList = _.compact(_.uniq(lessonList.map(i => i.lessons).flat().map(i => i.teaid)));
|
|
|
+ return teacherList;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据条件返回班主任+礼仪教师列表
|
|
|
+ * @param {Object} condition 查询班主任+礼仪教师条件
|
|
|
+ */
|
|
|
+ async getRangeClasses(condition) {
|
|
|
+ const classesList = await this.clsmodel.find(condition);
|
|
|
+ const resList = classesList.map(i => i.headteacherid).concat(classesList.map(i => i.lyteacherid));
|
|
|
+ return resList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
// 取得要通知的人
|
|
|
async getnotified(termid, classid, type) {
|
|
|
const notified_ = [];
|