1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- 'use strict';
- const Service = require('../service/baseService');
- class NoticeService extends Service {
- tag() {
- return this.ctx.model.NoticeModel;
- }
- async listForApplets(data, pop) {
- const { model } = this.ctx;
- return await model.NoticeModel.find(data, pop).sort({ createTime: -1 });
- }
- async listForAppletsFirst(data, pop) {
- const { model } = this.ctx;
- return await model.NoticeModel.find(data, pop).sort({ createTime: -1 }).skip(0)
- .limit(1);
- }
- // PC端发给我的通知
- async pcListForPage(data, user) {
- const { model } = this.ctx;
- const page = data.page;
- const level = user.dept.level;
- const rows = Number.parseInt(data.rows) || this.app.config.defaultPageSize;
- delete data.page;
- delete data.rows;
- const where = {};
- if (data._id) {
- where._id = data._id;
- }
- if (!data.searchtitle) {
- delete data.searchtitle;
- } else {
- where.title = { $regex: data.searchtitle };
- delete data.searchtitle;
- }
- if (level == 1) {
- where.$or = [{ dept1: user.dept1._id }];
- where.userid = { $ne: user._id };
- } else if (level == 2) {
- where.$or = [{ deptId: user.dept1._id }, { deptId: user.dept2._id }];
- where.userid = { $ne: user._id };
- } else if (level >= 3) {
- where.$or = [{ deptId: user.dept1._id }, { deptId: user.dept2._id }, { deptId: user.dept3._id }];
- where.userid = { $ne: user._id };
- }
- const pop = [
- {
- path: 'userid',
- select: 'loginName userName',
- // select: 'loginName',
- },
- ];
- const total = await model.NoticeModel.find(where).countDocuments();
- const result = await model.NoticeModel.find(where).populate(pop).skip((page - 1) * rows)
- .limit(rows)
- .sort({ createTime: -1 });
- return {
- count: total,
- list: result,
- };
- }
- }
- module.exports = NoticeService;
|