|
@@ -46,17 +46,21 @@ class NoticeService extends CrudService {
|
|
|
if (type === '0') {
|
|
|
const sList = await this.getRangeStudent({ classid });
|
|
|
const tList = await this.getRangeTeacher({ classid });
|
|
|
- const hList = await this.getRangeClasses({ id: 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 });
|
|
|
}
|
|
|
- console.group('发送人列表');
|
|
|
- console.table(personList);
|
|
|
- console.groupEnd();
|
|
|
+ personList = personList.map(i => i._id);
|
|
|
+ // console.group('发送人列表');
|
|
|
+ // console.table(userList);
|
|
|
+ // console.groupEnd();
|
|
|
+ // console.log(personList);
|
|
|
// 获取所有人后发送信息
|
|
|
const userList = await this.umodel.find({ uid: { $in: personList } });
|
|
|
+ console.log(userList);
|
|
|
+
|
|
|
for (const user of userList) {
|
|
|
// 1,判断有没有openid;2有openid的发送消息,添加记录
|
|
|
if (!_.get(user, 'openid')) continue;
|
|
@@ -99,7 +103,8 @@ class NoticeService extends CrudService {
|
|
|
* @param {Object} condition 查询学生的条件
|
|
|
*/
|
|
|
async getRangeStudent(condition) {
|
|
|
- const res = await this.stumodel.find(condition);
|
|
|
+ const res = await this.stumodel.find({ ...condition, openid: { $exists: true } });
|
|
|
+ console.log(res);
|
|
|
return res;
|
|
|
}
|
|
|
/**
|
|
@@ -110,16 +115,32 @@ class NoticeService extends CrudService {
|
|
|
// 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;
|
|
|
+ const teaInfoList = await this.teamodel.find({ _id: { $in: teacherList } });
|
|
|
+ return teaInfoList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据条件返回班主任+礼仪教师列表
|
|
|
* @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));
|
|
|
+ async getRangeClasses({ _id, termid }) {
|
|
|
+ let resList = [];
|
|
|
+ if (_.id) {
|
|
|
+ const cla = await this.clsmodel.findOne(_id);
|
|
|
+ if (cla) resList.push(cla.headteacherid, cla.lyteacherid);
|
|
|
+ } else {
|
|
|
+ const classesList = await this.clsmodel.find(termid);
|
|
|
+ if (classesList) {
|
|
|
+ for (const cla of classesList) {
|
|
|
+ resList.push(cla.headteacherid, cla.lyteacherid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ resList = _.compact(_.uniq(resList));
|
|
|
+ const headteaList = await this.heamodel.find({ _id: { $in: resList } });
|
|
|
+ resList = resList.filter(f => !headteaList.find(hf => ObjectId(f).equals(hf._id)));
|
|
|
+ const teaList = await this.teamodel.find({ _id: { $in: resList } });
|
|
|
+ resList = [ ...headteaList, ...teaList ];
|
|
|
return resList;
|
|
|
}
|
|
|
|