当前位置:网站首页>MP进阶操作: 时间操作, sql,querywapper,lambdaQueryWapper(条件构造器)快速筛选 枚举类
MP进阶操作: 时间操作, sql,querywapper,lambdaQueryWapper(条件构造器)快速筛选 枚举类
2022-07-04 22:35:00 【pingzhuyan】
目录
2. sql语句 :TIMESTAMPDIFF()的 方法 使用
查询当前时间的30分钟之前(过期30分钟)和60分钟后(快到期60分钟)
1. 时间筛选的原方法:
获取 开始时间-> 结束时间
一个月, 一年 都需要计算
queryWapper.ge(timeStatus, "update_date", appointEntity.getStartTime())//大于开始时间
.le(timeStatus, "update_date", appointEntity.getEndTime())//小于等于结束时间2. sql语句 :TIMESTAMPDIFF()的 方法 使用
查询当前时间的30分钟之前(过期30分钟)和60分钟后(快到期60分钟)
select id from 表
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. 整合条件构造器(时间)
3.1 写一个枚举类(时间)
package com.aisce.common.enums;
public enum DataTimeTypeEnum {
/**
* 近一周
*/
ONE_WEEK(1, "近一周"),
/**
* 近一个月
*/
ONE_MONTH(2, "近一个月"),
/**
* 近三个月
*/
THREE_MONTH(3, "近三个月"),
/**
* 近一年
*/
ONE_YEAR(4, "近一年"),
/**
* 所有
*/
ALL(5, "所有"),
/**
* 自定义
*/
CUSTOMIZE(6, "自定义")
;
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 写一个类 需要这三个属性
/**
* 时间类型
*/
@TableField(exist = false )
private Integer TimeType ;
/**
* 开始时间
*/
@TableField(exist = false )
private Date startTime;
/**
* 结束时间
*/
@TableField(exist = false )
private Date endTime;3.3 条件构造器写法
/**
* lambdaQuery 终极写法 时间规划
* @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 代码中使用方式
(可能有更好的使用方式 寻找中)
DataBaseDTO dto = new DataBaseDTO();
dto.setTimeType(1);
LambdaQueryWrapper<*> LambdaQueryWrapper = buildQueryWrapper(dto);
LambdaQueryWrapper.eq(*::getCompanyId,user.getCompanyId());
//先获取全部数据
List<*> RecordList = baseMapper.selectList(LambdaQueryWrapper);边栏推荐
- Three stage operations in the attack and defense drill of the blue team
- Attack and defense world misc advanced area Hong
- 攻防世界 MISC 进阶区 can_has_stdio?
- NFT insider 64: e-commerce giant eBay submitted an NFT related trademark application, and KPMG will invest $30million in Web3 and metauniverse
- 攻防世界 MISC 高手进阶区 001 normal_png
- Redis getting started complete tutorial: Geo
- 啃下大骨头——排序(二)
- Redis入门完整教程:事务与Lua
- Redis入门完整教程:发布订阅
- MySQL Architecture - user rights and management
猜你喜欢

【室友用一局王者荣耀的时间学会了用BI报表数据处理】

Redis getting started complete tutorial: Key Management

攻防世界 MISC 进阶区 can_has_stdio?

堆排序代码详解

Wake up day, how do I step by step towards the road of software testing
![[Jianzhi offer] 6-10 questions](/img/73/5974068008bcdc9a70b3f5f57f1eb0.png)
[Jianzhi offer] 6-10 questions

Redis introduction complete tutorial: List explanation
![[sword finger offer] questions 1-5](/img/54/b70d5290978e842939db99645c6ada.png)
[sword finger offer] questions 1-5

The new version judges the code of PC and mobile terminal, the mobile terminal jumps to the mobile terminal, and the PC jumps to the latest valid code of PC terminal

10 schemes to ensure interface data security
随机推荐
串口数据帧
Hit the core in the advanced area of misc in the attack and defense world
Serial port data frame
攻防世界 misc 高手进阶区 a_good_idea
新版判断PC和手机端代码,手机端跳转手机端,PC跳转PC端最新有效代码
Attack and defense world misc advanced area can_ has_ stdio?
[graph theory] topological sorting
EditPlus--用法--快捷键/配置/背景色/字体大小
Analog rocker controlled steering gear
[roommate learned to use Bi report data processing in the time of King glory in one game]
Sword finger offer 67 Convert a string to an integer
共创软硬件协同生态:Graphcore IPU与百度飞桨的“联合提交”亮相MLPerf
Redis入门完整教程:慢查询分析
Wake up day, how do I step by step towards the road of software testing
Redis入门完整教程:初识Redis
A complete tutorial for getting started with redis: redis usage scenarios
Analysis of the self increasing and self decreasing of C language function parameters
Lost in the lock world of MySQL
Redis入门完整教程:HyperLogLog
vim编辑器知识总结