当前位置:网站首页>Mongodb usage
Mongodb usage
2022-06-11 11:17:00 【Grade III code farmer 666】
1. rely on
<!-- SpringBoot MongoDB -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
2.mongoDB Pagination
@ApiOperation(value = " Query alert records and analyze photo information by page ", notes = "", httpMethod = "GET")
@RequestMapping(method = RequestMethod.GET, value = "/analysisSearchAll")
public Response<Page<AnalysisAlarm>> analysisSearchAll(@ApiIgnore Pager<AnalysisAlarm> pager, String deviceType, String startTime,
String endTime, String deviceId) {
Page<AnalysisAlarm> analysisAlarms = service.analysisSearchAll(pager, deviceType, startTime, endTime, deviceId);
return Response.put(analysisAlarms);
}
3. Pagination impl Realization
@Override
public Page<AnalysisAlarm> analysisSearchAll(Pager<AnalysisAlarm> pager, String deviceType, String startTime, String endTime,
String deviceId) {
Query query = new Query();
Sort sort = Sort.by(Direction.DESC, "create_time");
PageRequest pageable = PageRequest.of(pager.getPageNum() - 1, pager.getPageSize(), sort);
// Paging condition query : Time , equipment id, Alert type
if(StringUtil.isNotEmpty(startTime) && StringUtil.isNotEmpty(endTime)){
query.addCriteria(Criteria.where("create_time").gte(DateUtils.parseDate(startTime)).lte(DateUtils.parseDate(endTime)));
}
if (StringUtils.isNotBlank(deviceId)) {
query.addCriteria(Criteria.where("deviceID").is(deviceId));
}
if (StringUtils.isNotBlank(deviceType)) {
query.addCriteria(Criteria.where("warningType").is(deviceType));
}
query.addCriteria(Criteria.where("data_status").is(1));
// Total number of queries
long total = mongoTemplate.count(query, AnalysisAlarm.class);
// Paging query
List<AnalysisAlarm> analysisAlarmList = mongoTemplate.find(query.with(pageable), AnalysisAlarm.class);
// Set the result set , total
Page<AnalysisAlarm> analysisAlarmPage = new PageImpl(analysisAlarmList, pageable, total);
return analysisAlarmPage;
}
4. Delete
@Override
public int deleteBatch(List<String> ids) {
ids.forEach(d->{
Query query = new Query(Criteria.where("_id").is(d));
AnalysisAlarm one = mongoTemplate.findOne(query, AnalysisAlarm.class);
if (ObjectUtils.isEmpty(one)){
throw new BusinessException(" This collection has been deleted ");
}
Update update = new Update();
update.set("data_status",0);
mongoTemplate.updateFirst(query, update, AnalysisAlarm.class);
});
return 1;
}
5. details
@Override
public List<AnalysisAlarm> elavatorAction(String deviceId) {
Query query = new Query();
// Paging condition query : Time , equipment id, Alert type
if (StringUtils.isNotBlank(deviceId)) {
query.addCriteria(Criteria.where("deviceID").is(deviceId));
}
query.addCriteria(Criteria.where("data_status").is(1));
// adopt deviceId Inquire about
// find It's an array
List<AnalysisAlarm> analysisAlarms = mongoTemplate.find(query, AnalysisAlarm.class);
return analysisAlarms;
}
边栏推荐
- Jerry's acquisition of ble OTA dual backup upgrade (can only be used for chips above 4mbits) [article]
- AcWing 1944. Record keeping (hash, STL)
- Droid-slam: depth vision slam for monocular and binocular rgbd cameras
- MWC 2022 lights up the future, and everything serves
- Split data - horizontal split and vertical split
- What is the best annuity insurance product in 2022?
- AI security and Privacy Forum issue 11 - stable learning: finding common ground between causal reasoning and machine learning
- How to form a good habit? By perseverance? By determination? None of them!
- 使用Yolov3训练自己制作数据集,快速上手
- Xiao P weekly Vol.08
猜你喜欢

Why does a ddrx power supply design require a VTT power supply

Using domestic MCU (national technology n32g031f8s7) to realize pwm+dma control ws2812

Remote monitoring project offline log specification

CAP理论听起来很高大上,其实很简单

木瓜移动CFO刘凡 释放数字时代女性创新力量

企业微信小程序避坑指南,欢迎补充。。。

使用Yolov5训练好模型调用电脑自带摄像头时出现问题:TypeError: argument of type “int‘ is not iterable的解决方法

How programmers do sidelines

Display of receiving address list 【 project mall 】

Writing the program into the microcontroller can control the forward and reverse rotation of the motor more conveniently and quickly
随机推荐
Problems encountered when using nailing intranet to penetrate and upload PHP projects
nft数字藏品app系统搭建
杰理之获取 BLE 出现电压检测、ADC 检测不准【篇】
距离度量 —— 欧式距离(Euclidean Distance)
小 P 周刊 Vol.08
Shi Yigong: I was not interested in research until I graduated from my doctor's degree! I'm confused about the future, and I don't know what to do in the future
使用Labelimg制作VOC数据集或yolo数据集的入门方法
Typeerror: argument of type "Int 'is not Iterable
Content-Type: multipart/form-data; boundary=${bound}
Common construction and capacity operation of string class
使用Yolov3训练自己制作数据集,快速上手
The application of the spingboot+quartrz production environment supports distributed, custom corn, reflective execution of multiple tasks
沒有財富就不能自由嗎?
Leetcode (Sword finger offer) - 10- ii Frog jumping on steps
Split data - horizontal split and vertical split
数字藏品系统app源码
Vscode——vscode 多窗口名字配置成项目名字
数字藏品系统源码搭建
Source code construction of digital collection system
[DBSCAN] DBSCAN instance