1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- 'use strict';
- const Controller = require('../extend/baseController');
- class NoticeController extends Controller {
- tag() {
- return this.ctx.service.noticeService;
- }
- async listForPage() {
- const { ctx } = this;
- ctx.query.userid = ctx.user._id;
- 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);
- }
- // 已读接口
- 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;
|