refactor: 用户分页接口优化,添加创建时间范围查询参数
This commit is contained in:
32
src/main/java/com/youlai/system/common/util/DateUtils.java
Normal file
32
src/main/java/com/youlai/system/common/util/DateUtils.java
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
|
||||||
|
package com.youlai.system.common.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日期工具类
|
||||||
|
*
|
||||||
|
* @author haoxr
|
||||||
|
* @since 2.4.2
|
||||||
|
*/
|
||||||
|
public class DateUtils {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化日期范围
|
||||||
|
*
|
||||||
|
* @param createTimeRange
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<String> formatDateRange(List<String> createTimeRange) {
|
||||||
|
if (CollectionUtil.isNotEmpty(createTimeRange) && createTimeRange.size() == 2) {
|
||||||
|
createTimeRange.set(0, createTimeRange.get(0) + " 00:00:00");
|
||||||
|
createTimeRange.set(1, createTimeRange.get(1) + " 23:59:59");
|
||||||
|
return createTimeRange;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,9 +25,9 @@ public interface UserConverter {
|
|||||||
@Mappings({
|
@Mappings({
|
||||||
@Mapping(target = "genderLabel", expression = "java(com.youlai.system.common.base.IBaseEnum.getLabelByValue(bo.getGender(), com.youlai.system.common.enums.GenderEnum.class))")
|
@Mapping(target = "genderLabel", expression = "java(com.youlai.system.common.base.IBaseEnum.getLabelByValue(bo.getGender(), com.youlai.system.common.enums.GenderEnum.class))")
|
||||||
})
|
})
|
||||||
UserPageVO bo2Vo(UserBO bo);
|
UserPageVO toPageVo(UserBO bo);
|
||||||
|
|
||||||
Page<UserPageVO> bo2Vo(Page<UserBO> bo);
|
Page<UserPageVO> toPageVo(Page<UserBO> bo);
|
||||||
|
|
||||||
UserForm bo2Form(UserFormBO bo);
|
UserForm bo2Form(UserFormBO bo);
|
||||||
|
|
||||||
|
|||||||
@@ -4,13 +4,15 @@ import com.youlai.system.common.base.BasePageQuery;
|
|||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户分页查询对象
|
* 用户分页查询对象
|
||||||
*
|
*
|
||||||
* @author haoxr
|
* @author haoxr
|
||||||
* @since 2022/1/14
|
* @since 2022/1/14
|
||||||
*/
|
*/
|
||||||
@Schema
|
@Schema(description ="用户分页查询对象")
|
||||||
@Data
|
@Data
|
||||||
public class UserPageQuery extends BasePageQuery {
|
public class UserPageQuery extends BasePageQuery {
|
||||||
|
|
||||||
@@ -23,4 +25,7 @@ public class UserPageQuery extends BasePageQuery {
|
|||||||
@Schema(description="部门ID")
|
@Schema(description="部门ID")
|
||||||
private Long deptId;
|
private Long deptId;
|
||||||
|
|
||||||
|
@Schema(description="创建时间范围")
|
||||||
|
private List<String> createTimeRange;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.youlai.system.common.constant.SecurityConstants;
|
import com.youlai.system.common.constant.SecurityConstants;
|
||||||
import com.youlai.system.common.constant.SystemConstants;
|
import com.youlai.system.common.constant.SystemConstants;
|
||||||
|
import com.youlai.system.common.util.DateUtils;
|
||||||
import com.youlai.system.converter.UserConverter;
|
import com.youlai.system.converter.UserConverter;
|
||||||
import com.youlai.system.common.util.SecurityUtils;
|
import com.youlai.system.common.util.SecurityUtils;
|
||||||
import com.youlai.system.mapper.SysUserMapper;
|
import com.youlai.system.mapper.SysUserMapper;
|
||||||
@@ -73,13 +74,15 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||||||
int pageSize = queryParams.getPageSize();
|
int pageSize = queryParams.getPageSize();
|
||||||
Page<UserBO> page = new Page<>(pageNum, pageSize);
|
Page<UserBO> page = new Page<>(pageNum, pageSize);
|
||||||
|
|
||||||
|
// 时间范围参数处理
|
||||||
|
List<String> createTimeRange = DateUtils.formatDateRange(queryParams.getCreateTimeRange());
|
||||||
|
queryParams.setCreateTimeRange(createTimeRange);
|
||||||
|
|
||||||
// 查询数据
|
// 查询数据
|
||||||
Page<UserBO> userBoPage = this.baseMapper.getUserPage(page, queryParams);
|
Page<UserBO> userPage = this.baseMapper.getUserPage(page, queryParams);
|
||||||
|
|
||||||
// 实体转换
|
// 实体转换
|
||||||
Page<UserPageVO> userVoPage = userConverter.bo2Vo(userBoPage);
|
return userConverter.toPageVo(userPage);
|
||||||
|
|
||||||
return userVoPage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -37,6 +37,17 @@
|
|||||||
<if test='queryParams.deptId!=null'>
|
<if test='queryParams.deptId!=null'>
|
||||||
AND concat(',',concat(d.tree_path,',',d.id),',') like concat('%,',#{queryParams.deptId},',%')
|
AND concat(',',concat(d.tree_path,',',d.id),',') like concat('%,',#{queryParams.deptId},',%')
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
|
<if test="queryParams.createTimeRange != null and queryParams.createTimeRange.size() == 2 ">
|
||||||
|
<if test="queryParams.createTimeRange[0] != null and queryParams.createTimeRange[0].trim() neq ''">
|
||||||
|
AND u.create_time >= #{queryParams.createTimeRange[0]}
|
||||||
|
</if>
|
||||||
|
<if test="queryParams.createTimeRange[1] != null and queryParams.createTimeRange[1].trim() neq ''">
|
||||||
|
AND u.create_time <= #{queryParams.createTimeRange[1]}
|
||||||
|
</if>
|
||||||
|
</if>
|
||||||
|
|
||||||
|
|
||||||
</where>
|
</where>
|
||||||
GROUP BY u.id
|
GROUP BY u.id
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
Reference in New Issue
Block a user