|
@@ -9,6 +9,57 @@ class NoticeService extends CrudService {
|
|
|
constructor(ctx) {
|
|
|
super(ctx, 'notice');
|
|
|
this.model = this.ctx.model.Notice;
|
|
|
+ this.http = this.ctx.service.util.httpUtil;
|
|
|
+ this.basePrefix = this.app.config.httpPrefix.base;
|
|
|
+ }
|
|
|
+
|
|
|
+ async create(body = {}) {
|
|
|
+ const code = _.get(body, 'code');
|
|
|
+ const type = _.get(body, 'receive_type');
|
|
|
+ if (type === '0') {
|
|
|
+ const p1List = await this.findByAdmin(code);
|
|
|
+ const p2List = await this.findPersonal(code);
|
|
|
+ const p3List = await this.findByOrg(code);
|
|
|
+ body.receive = _.uniqBy([ ...p1List, ...p2List, ...p3List ], 'user_id');
|
|
|
+ } else if (type === '1') {
|
|
|
+ const pList = await this.findByAdmin(code);
|
|
|
+ body.receive = pList;
|
|
|
+ } else if (type === '3') {
|
|
|
+ const pList = await this.findPersonal(code);
|
|
|
+ body.receive = pList;
|
|
|
+ }
|
|
|
+ const res = await this.model.create(body);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ async findByAdmin(code) {
|
|
|
+ const res = await this.http.cget(`${this.basePrefix}/admin`, { code });
|
|
|
+ if (!res) return [];
|
|
|
+ const receive = [];
|
|
|
+ for (const r of res) {
|
|
|
+ const pr = await this.http.cget(`${this.basePrefix}/admin`, { role: '2', pid: r._id });
|
|
|
+ const list = pr.map(i => ({ user_id: i._id, name: i.name }));
|
|
|
+ receive.push(...list);
|
|
|
+ }
|
|
|
+ return receive;
|
|
|
+ }
|
|
|
+
|
|
|
+ async findPersonal(code) {
|
|
|
+ const res = await this.http.cget(`${this.basePrefix}/personal`, { code });
|
|
|
+ if (res) return res.map(i => ({ user_id: i._id, name: i.name }));
|
|
|
+ }
|
|
|
+
|
|
|
+ async findByOrg(code) {
|
|
|
+ const res = await this.http.cget(`${this.basePrefix}/admin`, { code, role: '2' });
|
|
|
+ const list = [];
|
|
|
+ for (const r of res) {
|
|
|
+ list.push({ user_id: r._id, name: r.name });
|
|
|
+ const orgCode = _.get(r, 'code');
|
|
|
+ const pList = await this.findPersonal(orgCode);
|
|
|
+ list.push(...pList);
|
|
|
+
|
|
|
+ }
|
|
|
+ return list;
|
|
|
}
|
|
|
}
|
|
|
|