当前位置:网站首页>MP advanced operation: time operation, SQL, querywapper, lambdaquerywapper (condition constructor) quick filter enumeration class
MP advanced operation: time operation, SQL, querywapper, lambdaquerywapper (condition constructor) quick filter enumeration class
2022-07-04 23:15:00 【pingzhuyan】
Catalog
1. Original method of time screening :
2. sql sentence :TIMESTAMPDIFF() Of Method Use
3. Integrate condition constructors ( Time )
3.1 Write an enumeration class ( Time )
3.2 Write a class These three attributes are required
3.3 Condition constructor writing
1. Original method of time screening :
obtain Starting time -> End time
A month , A year All need calculation
queryWapper.ge(timeStatus, "update_date", appointEntity.getStartTime())// Greater than the start time
.le(timeStatus, "update_date", appointEntity.getEndTime())// Less than or equal to the end time
2. sql sentence :TIMESTAMPDIFF() Of Method Use
Query the current time 30 Minutes ago ( Be overdue 30 minute ) and 60 Minutes later ( Due soon 60 minute )
select id from surface
where (TIMESTAMPDIFF(MINUTE, #{nowTime}, ap_time) >0 and TIMESTAMPDIFF(MINUTE, #{nowTime}, ap_time) <= 60 )
or
(TIMESTAMPDIFF(MINUTE, ap_time, #{nowTime})>0 and TIMESTAMPDIFF(MINUTE, ap_time, #{nowTime}) <30)
3. Integrate condition constructors ( Time )
3.1 Write an enumeration class ( Time )
package com.aisce.common.enums;
public enum DataTimeTypeEnum {
/**
* Last week
*/
ONE_WEEK(1, " Last week "),
/**
* Nearly a month
*/
ONE_MONTH(2, " Nearly a month "),
/**
* Nearly three months
*/
THREE_MONTH(3, " Nearly three months "),
/**
* Nearly a year
*/
ONE_YEAR(4, " Nearly a year "),
/**
* all
*/
ALL(5, " all "),
/**
* Customize
*/
CUSTOMIZE(6, " Customize ")
;
private final int code;
private final String name;
DataTimeTypeEnum(int code, String info) {
this.code = code;
this.name = info;
}
public static String getValue(int code) {
DataTimeTypeEnum[] enums = values();
for (DataTimeTypeEnum item : enums) {
if (item.code == code) {
return item.getName();
}
}
return null;
}
public int getCode() {
return code;
}
public String getName() {
return name;
}
}
3.2 Write a class These three attributes are required
/**
* Time type
*/
@TableField(exist = false )
private Integer TimeType ;
/**
* Starting time
*/
@TableField(exist = false )
private Date startTime;
/**
* End time
*/
@TableField(exist = false )
private Date endTime;
3.3 Condition constructor writing
/**
* lambdaQuery Ultimate writing Time planning
* @param dto
* @param <T>
* @return
*/
private <T extends AixiBillRecord> LambdaQueryWrapper<T> buildQueryWrapper(DataBaseDTO dto){
Integer timeType = dto.getTimeType();
// Integer timeType = 3;
Date currentDate = new Date();
LambdaQueryWrapper<T> lqw = Wrappers.lambdaQuery();
lqw.ge(timeType == DataTimeTypeEnum.ONE_WEEK.getCode(), T::getCreateTime, DateUtil.offsetWeek(currentDate, -1));
lqw.ge(timeType == DataTimeTypeEnum.ONE_MONTH.getCode(), T::getCreateTime, DateUtil.offsetMonth(currentDate, -1));
lqw.ge(timeType == DataTimeTypeEnum.THREE_MONTH.getCode(), T::getCreateTime, DateUtil.offsetMonth(currentDate, -3));
lqw.ge(timeType == DataTimeTypeEnum.ONE_YEAR.getCode(), T::getCreateTime, DateUtil.offsetMonth(currentDate, -12));
lqw.ge(timeType == DataTimeTypeEnum.CUSTOMIZE.getCode(), T::getCreateTime, dto.getStartTime());
lqw.le(timeType == DataTimeTypeEnum.CUSTOMIZE.getCode(), T::getCreateTime, dto.getEndTime());
return lqw;
}
3.4 Use in code
( There may be a better way to use Searching )
DataBaseDTO dto = new DataBaseDTO();
dto.setTimeType(1);
LambdaQueryWrapper<*> LambdaQueryWrapper = buildQueryWrapper(dto);
LambdaQueryWrapper.eq(*::getCompanyId,user.getCompanyId());
// Get all the data first
List<*> RecordList = baseMapper.selectList(LambdaQueryWrapper);
边栏推荐
- Redis入门完整教程:键管理
- Galera cluster of MariaDB - dual active and dual active installation settings
- Redis introduction complete tutorial: client communication protocol
- Redis démarrer le tutoriel complet: Pipeline
- 实战模拟│JWT 登录认证
- 智力考验看成语猜古诗句微信小程序源码
- ffmpeg快速剪辑
- HMS core machine learning service
- A complete tutorial for getting started with redis: transactions and Lua
- Sword finger offer 68 - I. nearest common ancestor of binary search tree
猜你喜欢
Explanation of bitwise operators
The small program vant tab component solves the problem of too much text and incomplete display
智力考验看成语猜古诗句微信小程序源码
Redis getting started complete tutorial: hash description
【js】-【排序-相关】-笔记
A complete tutorial for getting started with redis: getting to know redis for the first time
Redis入门完整教程:列表讲解
Redis入门完整教程:集合详解
QT drawing network topology diagram (connecting database, recursive function, infinite drawing, dragging nodes)
Phpcms paid reading function Alipay payment
随机推荐
Redis入门完整教程:Bitmaps
Redis入門完整教程:Pipeline
Redis:Redis的事务
Actual combat simulation │ JWT login authentication
CTF competition problem solution STM32 reverse introduction
Pagoda 7.9.2 pagoda control panel bypasses mobile phone binding authentication bypasses official authentication
Ffmpeg quick clip
Object detection based on OpenCV haarcascades
Photoshop batch adds different numbers to different pictures
cout/cerr/clog的区别
Qt加法计算器(简单案例)
The solution to the lack of pcntl extension under MAMP, fatal error: call to undefined function pcntl_ signal()
【二叉树】节点与其祖先之间的最大差值
Excel 快捷键-随时补充
【ODX Studio编辑PDX】-0.2-如何对比Compare两个PDX/ODX文件
Redis入门完整教程:事务与Lua
Header file duplicate definition problem solving "c1014 error“
Tweenmax emoticon button JS special effect
微信公众号解决从自定义菜单进入的缓存问题
Basic knowledge of database