当前位置:网站首页>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 ;
边栏推荐
- Telecommuting: camping at home office gadgets | community essay solicitation
- 如何在物联网低代码平台中进行任务管理?
- Daily question 8-515 Find the maximum value in each tree row
- HarmonyOS.2
- 杰理之TIMER0 用默认的 PA13 来检测脉宽【篇】
- 2022 recurrent training question bank and answers for hoisting signal Rigger (special type of construction work)
- 杰理之可能出现有些芯片音乐播放速度快【篇】
- Kotlin asynchronous flow
- Kotlin keyword extension function
- 智源社区周刊#86:Gary Marcus谈大模型研究可借鉴的三个语言学因素;谷歌提出媲美Imgen的文生图模型Parti;OpenAI提出视频预训练模型VPT,可玩MC游戏
猜你喜欢
随机推荐
Simulated 100 questions and answers of fluorination process examination in 2022
Android kotlin Encyclopedia
快手实时数仓保障体系研发实践
Rasa 3.x 学习系列-非常荣幸成为 Rasa contributors 源码贡献者,和全世界的Rasa源码贡献者共建共享Rasa社区!
Detailed explanation of kotlin collaboration lanch
kotlin 协程 lanch 详解
Gatling performance test
The project manager needs to look at six characteristics to build a team
Kotlin shared mutable state and concurrency
钛星数安加入龙蜥社区,共同打造网络安全生态
HarmonyOS-3
English writing of Mathematics -- Basic Chinese and English vocabulary (common vocabulary of geometry and trigonometry)
Source code analysis handler interview classic
90%的项目经理都跳过的坑,你现在还在坑里吗?
2022煤矿瓦斯抽采操作证考试题及模拟考试
万用表测量电阻图解及使用注意事项
Kotlin coordination channel
国内首款开源MySQL HTAP数据库即将发布,三大看点提前告知
2022 coal mine gas drainage operation certificate examination questions and simulation examination
Explain kubernetes backup and recovery tools velero | learn more about carina series phase III









