123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- 'use strict';
- const Controller = require('../extend/baseController');
- class NoticeController extends Controller {
- tag() {
- return this.ctx.service.noticeService;
- }
- //我发布的通知
- async listForPage() {
- const { ctx } = this;
- const user = ctx.user;
- if (user.role._id != this.app.config.defaultAdminRoleId) {
- ctx.query.userid = ctx.user._id;
- }else{
- delete ctx.query.userid;
- }
- 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 result = await this.tag().listForPage(ctx.query);
- ctx.success(result);
- }
- //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;
|