当前位置:网站首页>Record various sets of and or of mongotemplate once
Record various sets of and or of mongotemplate once
2022-06-24 13:59:00 【Humanoid bug maker 9527】
The requirement is to query the user's schedule information
Query the user's itinerary from the past seven days to the future ,
In other words, the data must meet the following conditions
1. Meeting time >= current time -7 God
2. user id= sender id, And the sender confirms the situation =0 perhaps =null
Or the user id= The receiver , And the sender confirms the situation =0 perhaps =null
The above two indicate that the user has not confirmed or denied the record , So show
3. The itinerary must be agreed
4. The itinerary must be unseen
5. Designated user
mysql General writing
select
*
from table
where
isConsent = 1
and
isMeet = 0
and
userId = xxxxxxxxx
and meetime > Current time minus 7 God
and
(
userId = recId and (recConfirm = 0 or recConfirm = null)
or
userId = senId and (senConfirm = 0 or recConfirm = null)
)
use mongoTemplate Writing
/** * Query all valid and UN cancelled meeting itineraries of the user , And in ascending order of meeting time ASC * * @param userId * @return */
@Override
public PageResult<Meeting> getMeetingSchedule(Integer page, Integer limit, Long userId) {
LocalDateTime min = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
Long sevenDaysAgo = AdTimeUtils.getMills(min.plusDays(-7));
// Create conditions
Criteria criteria = new Criteria();
// Enable or Operator , As long as one of them is satisfied, it is true Then hit
criteria.orOperator(
// Meet the conditions 1
Criteria.where("sendUserId").is(userId)
// Meet the conditions 1 Enable... When or Operator , As long as one of them is satisfied, it is true, Match the above where That is, the higher level true
.orOperator(
Criteria.where("senderConfirm").is(MeetingEnum.UN_MEET.getCode()),
Criteria.where("senderConfirm").is(null)
)
,
Criteria.where("recUserId").is(userId)
.orOperator(
Criteria.where("recipientConfirm").is(MeetingEnum.UN_MEET.getCode()),
Criteria.where("recipientConfirm").is(null)
)
);
// Enable and Operator , If all the conditions are met, it is selected
criteria.andOperator(
Criteria.where("isConsent").is(MeetingEnum.IS_CONSENT.getCode()),
Criteria.where("isMeet").is(MeetingEnum.UN_MEET.getCode()),
Criteria.where("meetTime").gte(sevenDaysAgo)
);
Query query = new Query(criteria);
query.skip((page - 1) * limit).limit(limit)
.with(Sort.by(Sort.Order.asc("meetTime")));
List<Meeting> meetings = mongoTemplate.find(query, Meeting.class);
if (CollUtil.isEmpty(meetings)) {
return new PageResult<>(
false,
CodeEnum.NO_SCHEDULE.getCode());
}
// This means that the required travel data has been found , Package return
return new PageResult<>(true, page, limit,
CodeEnum.SELECT_SUCCESS.getCode(), meetings);
}
orOperator as well as andOperator
Are equivalent to opening a and ( Judge ) When inside || perhaps && When satisfied, this is true, Then hit , The same is true for nested cases , If the whole is judged as true, But the upper layer has other nesting , Then add their judgment ;
边栏推荐
- 杰理之红外滤波【篇】
- Docker installation redis
- 快手实时数仓保障体系研发实践
- Rasa 3.x 学习系列-非常荣幸成为 Rasa contributors 源码贡献者,和全世界的Rasa源码贡献者共建共享Rasa社区!
- 【sdx62】WCN685X IPA不生效问题分析及解决方案
- 万用表的使用方法
- 远程办公之:在家露营办公小工具| 社区征文
- 2022起重信号司索工(建筑特殊工种)复训题库及答案
- 2022 recurrent training question bank and answers for hoisting signal Rigger (special type of construction work)
- 项目经理搭建团队,需要看6个特征
猜你喜欢

SAP Marketing Cloud 功能概述(四)
![Jerry's serial port receiving IO needs to set the digital function [chapter]](/img/04/48e7da42101a53827463d479952f67.png)
Jerry's serial port receiving IO needs to set the digital function [chapter]

万用表测量电阻图解及使用注意事项

One click to generate University, major and even admission probability. Is it so magical for AI to fill in volunteer cards?

遠程辦公之:在家露營辦公小工具| 社區征文

Research and development practice of Kwai real-time data warehouse support system

Eight major trends in the industrial Internet of things (iiot)
![Jerry's infrared filtering [chapter]](/img/6b/7c4b52d39a4c90f969674a5c21b2c7.png)
Jerry's infrared filtering [chapter]

#21Set经典案例
![[5g NR] 5g NR system architecture](/img/78/6db70c18887c7a3920843d1cb4bdf3.png)
[5g NR] 5g NR system architecture
随机推荐
钛星数安加入龙蜥社区,共同打造网络安全生态
杰理之在所有模式下打开喊话增加 mic 自动 mute【篇】
Seven challenges faced by data scientists and Solutions
每日一题day8-515. 在每个树行中找最大值
项目经理搭建团队,需要看6个特征
源碼解析 Handler 面試寶典
[5g NR] 5g NR system architecture
Activity lifecycle
English writing of Mathematics -- Basic Chinese and English vocabulary (common vocabulary of geometry and trigonometry)
Yyds dry goods counting solution sword finger offer: adjust the array order so that odd numbers precede even numbers (2)
Research and development practice of Kwai real-time data warehouse support system
[R language data science] (XIV): random variables and basic statistics
Source code analysis handler interview classic
HarmonyOS. two
在线文本实体抽取能力,助力应用解析海量文本数据
Daily question 8-515 Find the maximum value in each tree row
OpenHarmony 1
The research on the report "market insight into China's database security capabilities, 2022" was officially launched
Mysql题目篇
数学之英文写作——基本中英文词汇(几何与三角的常用词汇)