当前位置:网站首页>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);
边栏推荐
- How can enterprises cross the digital divide? In cloud native 2.0
- Redis入門完整教程:Pipeline
- 智力考验看成语猜古诗句微信小程序源码
- ETCD数据库源码分析——处理Entry记录简要流程
- MySQL数据库备份与恢复--mysqldump命令
- [machine learning] handwritten digit recognition
- UML图记忆技巧
- Redis getting started complete tutorial: Geo
- Wechat official account solves the cache problem of entering from the customized menu
- Redis入门完整教程:慢查询分析
猜你喜欢
P2181 diagonal and p1030 [noip2001 popularization group] arrange in order
Compare two vis in LabVIEW
[OpenGL] note 29 anti aliasing (MSAA)
Redis: redis configuration file related configuration and redis persistence
Redis introduction complete tutorial: Collection details
Redis入门完整教程:事务与Lua
LabVIEW中比较两个VI
Tweenmax emoticon button JS special effect
One of the commonly used technical indicators, reading boll Bollinger line indicators
The difference between debug and release
随机推荐
[OpenGL] note 29 anti aliasing (MSAA)
Basic knowledge of database
A complete tutorial for getting started with redis: getting to know redis for the first time
CTF競賽題解之stm32逆向入門
Servlet服务器端和客户端中文输出乱码问题
刷题指南-public
Redis getting started complete tutorial: publish and subscribe
Redis introduction complete tutorial: slow query analysis
[graph theory] topological sorting
The small program vant tab component solves the problem of too much text and incomplete display
CTF competition problem solution STM32 reverse introduction
A complete tutorial for getting started with redis: redis shell
Redis getting started complete tutorial: hash description
Redis:Redis的事务
Phpcms paid reading function Alipay payment
PS style JS webpage graffiti board plug-in
Basic use and upgrade of Android native database
Header file duplicate definition problem solving "c1014 error“
可观测|时序数据降采样在Prometheus实践复盘
Compare two vis in LabVIEW