123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- 'use strict';
- const Service = require('../service/baseService');
- const sm4 = require('../util/sm4').sma4;
- 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 = this.app.mongoose.Types.ObjectId(data.dept1);// 省
- }
- if (data.dept2) {
- where.dept2 = this.app.mongoose.Types.ObjectId(data.dept2); // 市
- }
- if (data.dept3) {
- where.dept3 = this.app.mongoose.Types.ObjectId(data.dept3); // 区
- }
- if (data.dept4) {
- where.dept4 = this.app.mongoose.Types.ObjectId(data.dept4); // 乡
- }
- if (data.dept5) {
- where.dept5 = this.app.mongoose.Types.ObjectId(data.dept5); // 社区
- }
- if (data.userName) {
- const result = await model.SysUserModel.find({ loginName: { $regex: data.userName } }); // TODO 数据加密处理-CH 这里不用加,因为这个前端传的是loginName
- 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 = sm4.encrypt_ECB(data.oldName); // TODO 数据加密处理-CH
- }
- 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',
- },
- {
- path: 'userid',
- select: 'loginName userName',
- },
- {
- path: 'managerid',
- select: 'loginName userName',
- },
- ];
- 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({ createTime: -1 });
- return {
- count: total,
- list: result,
- };
- }
- async urgencyFirst(data) {
- const { model } = this.ctx;
- const infodata = data;
- if (infodata.dept4) {
- infodata.status = 2;
- } else {
- infodata.status = 1;
- }
- const total = await model.InfoModel.find(infodata).countDocuments();
- data.status = '0';
- const JJtotal = await model.UrgencyModel.find(data).countDocuments();
- return {
- count: total,
- jjcount: JJtotal,
- };
- }
- }
- module.exports = UrgencyService;
|