noticeController.js 3.1 KB

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