|
@@ -17,17 +17,24 @@ class NoticeService extends CrudService {
|
|
|
this.schmodel = this.ctx.model.School;
|
|
|
this.heamodel = this.ctx.model.Headteacher;
|
|
|
this.teamodel = this.ctx.model.Teacher;
|
|
|
+ this.lmodel = this.ctx.model.Lesson;
|
|
|
+ this.clsmodel = this.ctx.model.Class;
|
|
|
}
|
|
|
|
|
|
async create(data) {
|
|
|
- const { planyearid, planid, termid, classid, noticeid, content, notified } = data;
|
|
|
+ const { planyearid, planid, termid, classid, noticeid, content, notified, type } = data;
|
|
|
assert(planyearid, '年度计划id为必填项');
|
|
|
assert(planid, '计划id为必填项');
|
|
|
assert(noticeid, '通知人id为必填项');
|
|
|
assert(content, '通知内容为必填项');
|
|
|
const res = await this.model.create(data);
|
|
|
if (res) {
|
|
|
- for (const elm of res.notified) {
|
|
|
+ // 判断班级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;
|
|
@@ -44,6 +51,102 @@ class NoticeService extends CrudService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 取得要通知的人
|
|
|
+ async getnotified(termid, classid, type) {
|
|
|
+ const notified_ = [];
|
|
|
+ if (classid) {
|
|
|
+ if (type === '1') {
|
|
|
+ const students = await this.stumodel.find({ classid });
|
|
|
+ for (const stu of students) {
|
|
|
+ const newdata = { notifiedid: stu.id, username: stu.name };
|
|
|
+ notified_.push(newdata);
|
|
|
+ }
|
|
|
+ } else if (type === '2') {
|
|
|
+ const lesson = await this.lmodel.findOne({ classid });
|
|
|
+ for (const elm of lesson.lessons) {
|
|
|
+ const newdata = { notifiedid: elm.teaid, username: elm.teaname };
|
|
|
+ notified_.push(newdata);
|
|
|
+ }
|
|
|
+ } else if (type === '3') {
|
|
|
+ const class_ = await this.clsmodel.findById(classid);
|
|
|
+ if (class_) {
|
|
|
+ const htea = await this.heamodel.findById(class_.headteacherid);
|
|
|
+ if (htea) {
|
|
|
+ const newdata = { notifiedid: htea.id, username: htea.name };
|
|
|
+ notified_.push(newdata);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (type === '0') {
|
|
|
+ const students = await this.stumodel.find({ classid });
|
|
|
+ for (const stu of students) {
|
|
|
+ const newdata = { notifiedid: stu.id, username: stu.name };
|
|
|
+ notified_.push(newdata);
|
|
|
+ }
|
|
|
+ const lesson = await this.lmodel.findOne({ classid });
|
|
|
+ for (const elm of lesson.lessons) {
|
|
|
+ const newdata = { notifiedid: elm.teaid, username: elm.teaname };
|
|
|
+ notified_.push(newdata);
|
|
|
+ }
|
|
|
+ const class_ = await this.clsmodel.findById(classid);
|
|
|
+ if (class_) {
|
|
|
+ const htea = await this.heamodel.findById(class_.headteacherid);
|
|
|
+ if (htea) {
|
|
|
+ const newdata = { notifiedid: htea.id, username: htea.name };
|
|
|
+ notified_.push(newdata);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 没输入班级的时候
|
|
|
+ if (type === '1') {
|
|
|
+ const students = await this.stumodel.find({ termid });
|
|
|
+ for (const stu of students) {
|
|
|
+ const newdata = { notifiedid: stu.id, username: stu.name };
|
|
|
+ notified_.push(newdata);
|
|
|
+ }
|
|
|
+ } else if (type === '2') {
|
|
|
+ const lessons = await this.lmodel.find({ termid });
|
|
|
+ for (const les of lessons) {
|
|
|
+ for (const elm of les.lessons) {
|
|
|
+ const newdata = { notifiedid: elm.teaid, username: elm.teaname };
|
|
|
+ notified_.push(newdata);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (type === '3') {
|
|
|
+ const class_ = await this.clsmodel.find({ termid });
|
|
|
+ for (const cla of class_) {
|
|
|
+ const htea = await this.heamodel.findById(cla.headteacherid);
|
|
|
+ if (htea) {
|
|
|
+ const newdata = { notifiedid: htea.id, username: htea.name };
|
|
|
+ notified_.push(newdata);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (type === '0') {
|
|
|
+ const students = await this.stumodel.find({ termid });
|
|
|
+ for (const stu of students) {
|
|
|
+ const newdata = { notifiedid: stu.id, username: stu.name };
|
|
|
+ notified_.push(newdata);
|
|
|
+ }
|
|
|
+ const lessons = await this.lmodel.find({ termid });
|
|
|
+ for (const les of lessons) {
|
|
|
+ for (const elm of les.lessons) {
|
|
|
+ const newdata = { notifiedid: elm.teaid, username: elm.teaname };
|
|
|
+ notified_.push(newdata);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const class_ = await this.clsmodel.find({ termid });
|
|
|
+ for (const cla of class_) {
|
|
|
+ const htea = await this.heamodel.findById(cla.headteacherid);
|
|
|
+ if (htea) {
|
|
|
+ const newdata = { notifiedid: htea.id, username: htea.name };
|
|
|
+ notified_.push(newdata);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return notified_;
|
|
|
+ }
|
|
|
+
|
|
|
async look(data) {
|
|
|
const { noticeid, uid } = data;
|
|
|
const notice = await this.model.findById(noticeid);
|