123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- 'use strict';
- const Controller = require('../extend/baseController');
- class NoticeController extends Controller {
- tag() {
- return this.ctx.service.noticeService;
- }
- // 我发布的通知
- async listForPage() {
- const { ctx, service } = this;
- const user = ctx.user;
- const pop = [
- {
- path: 'userid',
- select: 'loginName userName',
- // select: 'loginName',
- },
- ];
- if (user.role._id != this.app.config.defaultAdminRoleId) {
- ctx.query.userid = ctx.user._id; // 不是admin的情况
- if (ctx.query.status == 1) { // 不是admin情况选择 我发布的通知
- delete ctx.query.status;
- ctx.query.sort = { createTime: -1 };
- if (!ctx.query.searchtitle) {
- delete ctx.query.searchtitle;
- } else {
- ctx.query.title = ctx.query.searchtitle;
- ctx.query.title = { $regex: ctx.query.searchtitle };
- delete ctx.query.searchtitle;
- }
- this.ctx.logger.info(ctx.query);
- const result0 = await this.tag().listForPage(ctx.query, pop);
- ctx.success(result0);
- } else { // 不是admin情况下选择 发布给我的通知
- const result1 = await service.noticeService.pcListForPage(ctx.query, user);
- ctx.success(result1);
- }
- } else { // 是admin情况下只能看 所有通知
- delete ctx.query.userid;
- delete ctx.query.status;
- ctx.query.sort = { createTime: -1 };
- if (!ctx.query.searchtitle) {
- delete ctx.query.searchtitle;
- } else {
- ctx.query.title = ctx.query.searchtitle;
- ctx.query.title = { $regex: ctx.query.searchtitle };
- delete ctx.query.searchtitle;
- }
- const result2 = await this.tag().listForPage(ctx.query, pop);
- ctx.success(result2);
- }
- }
- // PC端发给我的通知
- async pcListForPage() {
- const { ctx, service } = this;
- const user = ctx.user;
- const result = await service.noticeService.pcListForPage(ctx.query, user);
- ctx.success(result);
- }
- // 已读接口
- async listForApplets() {
- const { ctx, service } = this;
- const user = ctx.user;
- const query = {};
- query.userid = user._id;
- const applist = await service.readNoticeService.appList(query);
- let finallist;
- if (user) {
- const list = await service.noticeService.listForApplets({ $or: [{ deptId: user.dept1._id }, { deptId: user.dept2._id }, { deptId: user.dept3._id }], _id: { $in: applist } }, { title: 1, content: 1, createTime: 1 });
- // const list2 = await service.noticeService.listForApplets({ deptId:user.dept2._id,_id:{$in:applist}},{title:1,createTime:1});
- // const list3 = await service.noticeService.listForApplets({ deptId:user.dept3._id,_id:{$in:applist}},{title:1,createTime:1});
- // finallist = list1.concat(list2).concat(list3);
- finallist = list;
- }
- ctx.success(finallist);
- }
- // 未读
- async listForAppletsNoread() {
- const { ctx, service } = this;
- const user = ctx.user;
- const query = {};
- query.userid = user._id;
- const applist = await service.readNoticeService.appList(query);
- let finallist;
- if (user) {
- const list = await service.noticeService.listForApplets({ $or: [{ deptId: user.dept1._id }, { deptId: user.dept2._id }, { deptId: user.dept3._id }], _id: { $nin: applist } }, { title: 1, content: 1, createTime: 1 });
- // const list2 = await service.noticeService.listForApplets({ deptId:user.dept2._id,_id:{$nin:applist}},{title:1,createTime:1});
- // const list3 = await service.noticeService.listForApplets({ deptId:user.dept3._id,_id:{$nin:applist}},{title:1,createTime:1});
- // finallist = list1.concat(list2).concat(list3);
- finallist = list;
- }
- ctx.success(finallist);
- }
- async listForAppletsFirst() {
- const { ctx, service } = this;
- const user = ctx.user;
- let finallist;
- if (user) {
- const list = await service.noticeService.listForAppletsFirst({ $or: [{ deptId: user.dept1._id }, { deptId: user.dept2._id }, { deptId: user.dept3._id }] }, { title: 1, createTime: 1 });
- finallist = list;
- }
- if (finallist.length > 0) {
- ctx.success(finallist[0]);
- } else {
- ctx.success([]);
- }
- }
- }
- module.exports = NoticeController;
|