添加了WrapperUtils

master
ArgonarioD 2022-06-30 14:26:45 +08:00
parent 2b3a72d78b
commit 07beec4039
2 changed files with 76 additions and 4 deletions

View File

@ -30,8 +30,9 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
Integer staffId = TokenUtils.getStaffId(token);
return baseMapper.findMyProject(new Page<>(pageCurrent, pageSize), staffId,
//TODO: 应该要改成调用WrapperUtils.allEqAndTimeIntervalQueryWrapper方法
Wrappers.<Project>query()
.allEq(WrapperUtils.getWrappedMapWithoutTime(params))
.allEq(WrapperUtils.getMapWithoutTime(params))
//.lambda()
//.between(params.get("projectStartTimeStart")!=null,Project::getProjectStartTime,)
);

View File

@ -0,0 +1,71 @@
package cn.edu.hfut.rmdjzz.projectmanagement.utils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.HashMap;
import java.util.Map;
/**
* @author
* @since 2022/6/30 11:50
*/
public class WrapperUtils {
/**
* paramMapQueryWrapper
* <p>
* - 使{@link QueryWrapper#allEq(Map, boolean)}
* <p>
* - {@link LocalDateTime}{@link LocalDate}{@link LocalTime}
* keyStartcolumn >= keyEndcolumn <= key
*
* @param null2IsNull valuenullSQLIS NULLnullSQL
*/
public static <T> QueryWrapper<T> allEqAndTimeIntervalQueryWrapper(Map<String, Object> paramMap, boolean null2IsNull) {
QueryWrapper<T> wrapper = new QueryWrapper<>();
paramMap.forEach((key, value) -> {
if (value == null) {
if (null2IsNull) {
wrapper.isNull(key);
}
return;
}
if (isTimeClass(value.getClass())) {
if (key.endsWith("Start")) {
wrapper.ge(key.substring(0, key.length() - 5), value);
} else if (key.endsWith("End")) {
wrapper.ge(key.substring(key.length() - 3), value);
}
return;
}
wrapper.eq(key, value);
});
return wrapper;
}
/**
* mapvalueentrymap
* <p>
* **使{@link WrapperUtils#allEqAndTimeIntervalQueryWrapper(Map, boolean)}**wrapper
*/
@Deprecated
public static Map<String, Object> getMapWithoutTime(Map<String, Object> map) {
Map<String, Object> result = new HashMap<>();
map.forEach((key, value) -> {
if (!isTimeClass(value.getClass())) {
result.put(key, value);
}
});
return result;
}
/**
* class{@link LocalDateTime}{@link LocalDate}{@link LocalTime}
*/
public static boolean isTimeClass(Class<?> clazz) {
return LocalDateTime.class.equals(clazz) || LocalDate.class.equals(clazz) || LocalTime.class.equals(clazz);
}
}