添加了WrapperUtils
parent
2b3a72d78b
commit
07beec4039
|
@ -30,11 +30,12 @@ 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))
|
||||
//.lambda()
|
||||
//.between(params.get("projectStartTimeStart")!=null,Project::getProjectStartTime,)
|
||||
);
|
||||
.allEq(WrapperUtils.getMapWithoutTime(params))
|
||||
//.lambda()
|
||||
//.between(params.get("projectStartTimeStart")!=null,Project::getProjectStartTime,)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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 {
|
||||
|
||||
/**
|
||||
* 用提供的paramMap构造一个QueryWrapper
|
||||
* <p>
|
||||
* - 一般的参数会与直接使用{@link QueryWrapper#allEq(Map, boolean)}相同
|
||||
* <p>
|
||||
* - 对于时间类({@link LocalDateTime}或{@link LocalDate}或{@link LocalTime}),
|
||||
* 会按照key的后缀处理,若为Start则处理为column >= key,End则处理为column <= key
|
||||
*
|
||||
* @param null2IsNull 若为真,将value为null的值在SQL中生成为IS NULL;否则值为null的参数不会在SQL中生成
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从参数map中获取去掉了value为时间类的entry的map
|
||||
* <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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue