12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- 'use strict';
- const Service = require('../service/baseService');
- class UrgencyService extends Service {
- tag() {
- return this.ctx.model.UrgencyModel;
- }
- // 分页查询
- async listForPage(data) {
- const { model } = this.ctx;
- const page = data.page;
- const rows = Number.parseInt(data.rows) || this.app.config.defaultPageSize;
- delete data.page;
- delete data.rows;
- const where = {};
- if (data.dept1) {
- where.dept1 = data.dept1;// 省
- }
- if (data.dept2) {
- where.dept2 = data.dept2; // 市
- }
- if (data.dept3) {
- where.dept3 = data.dept3; // 区
- }
- if (data.dept4) {
- where.dept4 = data.dept4; // 乡
- }
- if (data.dept5) {
- where.dept5 = data.dept5; // 社区
- }
- if (data.userName) {
- const result = await model.SysUserModel.find({ loginName: { $regex: data.userName } });
- if (result.length > 0) {
- where.userid = result[0]._id;
- } else {
- return '';
- }
- }
- if (data.managerName) {
- const result = await model.SysUserModel.find({ loginName: { $regex: data.managerName } });
- if (result.length > 0) {
- where.managerid = result[0]._id;
- } else {
- return '';
- }
- }
- if (data.oldName) {
- where.oldName = data.oldName;
- }
- if (data.status) {
- where.status = '' + data.status;
- }
- if (data.startTime && data.endTime) {
- where.createTime = { $gte: new Date(data.startTime + ' 00:00:00'), $lt: new Date(data.endTime + ' 23:59:59') };
- }
- this.ctx.logger.info('条件', where);
- const pop = [
- {
- path: 'dept1',
- select: 'name',
- },
- {
- path: 'dept2',
- select: 'name',
- },
- {
- path: 'dept3',
- select: 'name',
- },
- {
- path: 'dept4',
- select: 'name',
- },
- {
- path: 'dept5',
- select: 'name',
- },
- {
- path: 'visitId',
- },
- ];
- const total = await model.UrgencyModel.find(where).populate(pop).countDocuments();
- const result = await model.UrgencyModel.find(where).populate(pop).skip((page - 1) * rows)
- .limit(rows)
- .sort({ time: -1 });
- return {
- count: total,
- list: result,
- };
- }
- }
- module.exports = UrgencyService;
|