noticeController.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. 'use strict';
  2. const Controller = require('../extend/baseController');
  3. class NoticeController extends Controller {
  4. tag() {
  5. return this.ctx.service.noticeService;
  6. }
  7. async listForPage() {
  8. const { ctx } = this;
  9. ctx.query.userid = ctx.user._id;
  10. ctx.query.sort = { createTime: -1 };
  11. if (!ctx.query.searchtitle) {
  12. delete ctx.query.searchtitle;
  13. }else{
  14. ctx.query.title = ctx.query.searchtitle;
  15. ctx.query.title ={$regex: ctx.query.searchtitle}
  16. delete ctx.query.searchtitle;
  17. }
  18. const result = await this.tag().listForPage(ctx.query);
  19. ctx.success(result);
  20. }
  21. // 已读接口
  22. async listForApplets() {
  23. const { ctx, service } = this;
  24. const user = ctx.user;
  25. const query = {};
  26. query.userid = user._id;
  27. const applist = await service.readNoticeService.appList(query);
  28. let finallist;
  29. if (user) {
  30. 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 });
  31. // const list2 = await service.noticeService.listForApplets({ deptId:user.dept2._id,_id:{$in:applist}},{title:1,createTime:1});
  32. // const list3 = await service.noticeService.listForApplets({ deptId:user.dept3._id,_id:{$in:applist}},{title:1,createTime:1});
  33. // finallist = list1.concat(list2).concat(list3);
  34. finallist = list;
  35. }
  36. ctx.success(finallist);
  37. }
  38. // 未读
  39. async listForAppletsNoread() {
  40. const { ctx, service } = this;
  41. const user = ctx.user;
  42. const query = {};
  43. query.userid = user._id;
  44. const applist = await service.readNoticeService.appList(query);
  45. let finallist;
  46. if (user) {
  47. 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 });
  48. // const list2 = await service.noticeService.listForApplets({ deptId:user.dept2._id,_id:{$nin:applist}},{title:1,createTime:1});
  49. // const list3 = await service.noticeService.listForApplets({ deptId:user.dept3._id,_id:{$nin:applist}},{title:1,createTime:1});
  50. // finallist = list1.concat(list2).concat(list3);
  51. finallist = list;
  52. }
  53. ctx.success(finallist);
  54. }
  55. async listForAppletsFirst() {
  56. const { ctx, service } = this;
  57. const user = ctx.user;
  58. let finallist;
  59. if (user) {
  60. const list = await service.noticeService.listForAppletsFirst({$or:[{deptId:user.dept1._id},{deptId:user.dept2._id},{deptId:user.dept3._id}]},{title:1,createTime:1});
  61. finallist = list
  62. }
  63. if(finallist.length>0){
  64. ctx.success(finallist[0]);
  65. }else{
  66. ctx.success([]);
  67. }
  68. }
  69. }
  70. module.exports = NoticeController;