博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mongoose联表查询与一般查询合并
阅读量:4310 次
发布时间:2019-06-06

本文共 4770 字,大约阅读时间需要 15 分钟。

var query=model.$.find({});     size=size/2;     query.skip((parseInt(page) - 1) * size);     query.limit(parseInt(size));         //只针对管理类任务     query.where({pm_type:'0'});         //根据任务名进行查询     if(condition.name && condition.name !==''){
query.where('pm_name',new RegExp(condition.name)); //选择开始时间年度为下拉列表默认值,当用户不设置值时,该字符串被传到这里,故需要处理掉 }if(condition.year && condition.year !==''&&condition.year!=='选择开始时间年度'){
query.where('pm_begin_date',new RegExp(condition.year)); //当前用户为发送者或者为接受者 }if(condition.current_id&&condition.current_id!==''){
query.where({$or: [ { pm_receivePerson: { $elemMatch: { id: condition.current_id } } }, { 'pm_sendPersonID': condition.current_id}]}); //根据任务状态不同进行查询 }if(condition.status&&condition.status!==''){
query.where('pm_status').equals(condition.status); //对查询数据进行排序 }if(sortItem.sort!==undefined&&sortItem.sort!==null&&sortItem.sort!==''&&sortItem.order!==undefined&&sortItem.order!==null&&sortItem.order!==''){
var so={}; so[sortItem.sort]=sortItem.order; query.sort(so); } //计算分页数据 query.exec(function(err,rsForMan){
if(err){
cb(utils.returnMsg(false, '1000', '根据姓名查询出现异常。', null, err)); }else{
//计算数据总数,不限制也不跳过的。保证查询条件与上一致,只需要计算总的数据数量。 var queryForLength=model.$.find({}); queryForLength.where({pm_type:'0'}); if(condition.name && condition.name !==''){
queryForLength.where('pm_name',new RegExp(condition.name)); //选择开始时间年度为下拉列表默认值,当用户不设置值时,该字符串被传到这里,故需要处理掉 }if(condition.year && condition.year !==''&&condition.year!=='选择开始时间年度'){
queryForLength.where('pm_begin_date',new RegExp(condition.year)); //当前用户为发送者或者为接受者 }if(condition.current_id&&condition.current_id!==''){
queryForLength.where({$or: [ { pm_receivePerson: { $elemMatch: { id: condition.current_id } } }, { 'pm_sendPersonID': condition.current_id}]}); }if(condition.status&&condition.status!==''){
queryForLength.where('pm_status').equals(condition.status); } queryForLength.exec(function(err,resultForManLen){
if(err){
cb(utils.returnMsg(false, '1000', '根据姓名查询出现异常。', null, err)); }else {
var queryN=model.$user_pm_statusModel.find({}); queryN.populate('pm_id'); queryN.skip((parseInt(page) - 1) * size); queryN.limit(parseInt(size)); queryN.where({status:condition.status,user_id:condition.current_id}); if(sortItem.sort!==undefined&&sortItem.sort!==null&&sortItem.sort!==''&&sortItem.order!==undefined&&sortItem.order!==null&&sortItem.order!==''){
var so={}; so[sortItem.sort]=sortItem.order; queryN.sort(so); } if(condition.name && condition.name !==''){
queryN.where('pm_id.pm_name',new RegExp(condition.name)); //选择开始时间年度为下拉列表默认值,当用户不设置值时,该字符串被传到这里,故需要处理掉 }if(condition.year && condition.year !==''&&condition.year!=='选择开始时间年度'){
queryN.where('pm_id.pm_begin_date',new RegExp(condition.year)); //当前用户为发送者或者为接受者 } //计算分页数据 queryN.exec(function(err,rsForNot){
if(err){
cb(utils.returnMsg(false, '1000', '根据姓名查询出现异常。', null, err)); }else{
//计算数据总数 model.$user_pm_statusModel.find({status:condition.status,user_id:condition.current_id}).populate('pm_id').exec(function(err,resultForNotLen){
if(err){
cb(utils.returnMsg(false, '1000', '根据姓名查询出现异常。', null, err)); }else {
//合并数据 for(var i in rsForNot){
rsForMan.push(rsForNot[i].pm_id); } cb(utils.returnMsg4EasyuiPaging(true, '0000', '根据姓名查询成功。', rsForMan, resultForNotLen.length+resultForManLen.length)); } }); } }); } }); } });

转载于:https://www.cnblogs.com/Ysera-Dreamer/p/7442601.html

你可能感兴趣的文章
session和cookie区别与联系
查看>>
PHP 实现笛卡尔积
查看>>
Laravel中的$loop
查看>>
CentOS7 重置root密码
查看>>
Centos安装Python3
查看>>
PHP批量插入
查看>>
laravel连接sql server 2008
查看>>
Laravel 操作redis的各种数据类型
查看>>
Laravel框架学习笔记之任务调度(定时任务)
查看>>
laravel 定时任务秒级执行
查看>>
浅析 Laravel 官方文档推荐的 Nginx 配置
查看>>
Swagger在Laravel项目中的使用
查看>>
Laravel 的生命周期
查看>>
CentOS Docker 安装
查看>>
Nginx
查看>>
Navicat远程连接云主机数据库
查看>>
Nginx配置文件nginx.conf中文详解(总结)
查看>>
Mysql出现Table 'performance_schema.session_status' doesn't exist
查看>>
MySQL innert join、left join、right join等理解
查看>>
vivado模块封装ip/edf
查看>>