当前位置:网站首页>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);
边栏推荐
- Photoshop批量给不同的图片添加不同的编号
- A complete tutorial for getting started with redis: understanding and using APIs
- Redis démarrer le tutoriel complet: Pipeline
- [OpenGL] note 29 anti aliasing (MSAA)
- The caching feature of docker image and dockerfile
- Redis入门完整教程:Redis Shell
- The initial arrangement of particles in SPH (solved by two pictures)
- heatmap. JS picture hotspot heat map plug-in
- A complete tutorial for getting started with redis: getting to know redis for the first time
- Editplus-- usage -- shortcut key / configuration / background color / font size
猜你喜欢
Phpcms paid reading function Alipay payment
Talk about Middleware
CTF競賽題解之stm32逆向入門
C语言快速解决反转链表
Set up a website with a sense of ceremony, and post it to 1/2 of the public network through the intranet
Redis入门完整教程:哈希说明
The caching feature of docker image and dockerfile
P2181 diagonal and p1030 [noip2001 popularization group] arrange in order
A complete tutorial for getting started with redis: getting to know redis for the first time
一次edu证书站的挖掘
随机推荐
【js】-【排序-相关】-笔记
Insert sort, select sort, bubble sort
C语言快速解决反转链表
HMS core machine learning service
Summary of wechat applet display style knowledge points
小程序vant tab组件解决文字过多显示不全的问题
为什么信息图会帮助你的SEO
Explanation of bitwise operators
字体设计符号组合多功能微信小程序源码
Network namespace
【二叉树】节点与其祖先之间的最大差值
Compare two vis in LabVIEW
OSEK标准ISO_17356汇总介绍
图片懒加载的原理
云服务器设置ssh密钥登录
List related knowledge points to be sorted out
Ffmpeg quick clip
可观测|时序数据降采样在Prometheus实践复盘
Advantages of Alibaba cloud international CDN
[odx Studio Edit pdx] - 0.2 - Comment comparer deux fichiers pdx / odx