Skip to content

Commit

Permalink
perf: 优化用户及部门查询
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed May 29, 2024
1 parent 0285874 commit 448f9a0
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.ibatis.annotations.Select;
import top.continew.admin.common.config.mybatis.DataPermissionMapper;
import top.continew.admin.system.model.entity.UserDO;
import top.continew.admin.system.model.resp.UserDetailResp;
import top.continew.starter.data.mybatis.plus.datapermission.DataPermission;
import top.continew.starter.security.crypto.annotation.FieldEncrypt;

Expand All @@ -44,8 +45,8 @@ public interface UserMapper extends DataPermissionMapper<UserDO> {
* @return 分页列表信息
*/
@DataPermission("t1")
IPage<UserDO> selectUserPage(@Param("page") IPage<UserDO> page,
@Param(Constants.WRAPPER) QueryWrapper<UserDO> queryWrapper);
IPage<UserDetailResp> selectUserPage(@Param("page") IPage<UserDO> page,
@Param(Constants.WRAPPER) QueryWrapper<UserDO> queryWrapper);

/**
* 查询列表
Expand All @@ -54,7 +55,7 @@ IPage<UserDO> selectUserPage(@Param("page") IPage<UserDO> page,
* @return 列表信息
*/
@DataPermission("t1")
List<UserDO> selectUserList(@Param(Constants.WRAPPER) QueryWrapper<UserDO> queryWrapper);
List<UserDetailResp> selectUserList(@Param(Constants.WRAPPER) QueryWrapper<UserDO> queryWrapper);

/**
* 根据用户名查询
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@

package top.continew.admin.system.model.resp;

import cn.crane4j.annotation.AssembleMethod;
import cn.crane4j.annotation.ContainerMethod;
import cn.crane4j.annotation.Mapping;
import cn.crane4j.annotation.condition.ConditionOnExpression;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import top.continew.admin.common.enums.DisEnableStatusEnum;
import top.continew.admin.system.service.DeptService;
import top.continew.starter.extension.crud.annotation.TreeField;
import top.continew.starter.extension.crud.converter.ExcelBaseEnumConverter;
import top.continew.starter.extension.crud.model.resp.BaseDetailResp;
Expand Down Expand Up @@ -58,18 +53,9 @@ public class DeptResp extends BaseDetailResp {
* 上级部门 ID
*/
@Schema(description = "上级部门 ID", example = "2")
@ConditionOnExpression(value = "#target.parentId != 0")
@AssembleMethod(props = @Mapping(src = "name", ref = "parentName"), targetType = DeptService.class, method = @ContainerMethod(bindMethod = "get", resultType = DeptResp.class))
@ExcelProperty(value = "上级部门 ID", order = 3)
private Long parentId;

/**
* 上级部门
*/
@Schema(description = "上级部门", example = "天津总部")
@ExcelProperty(value = "上级部门", order = 4)
private String parentName;

/**
* 状态
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import cn.crane4j.annotation.AssembleMethod;
import cn.crane4j.annotation.ContainerMethod;
import cn.crane4j.annotation.Mapping;
import cn.crane4j.annotation.condition.ConditionOnExpression;
import cn.crane4j.core.executor.handler.ManyToManyAssembleOperationHandler;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
Expand All @@ -33,6 +34,7 @@
import top.continew.starter.extension.crud.converter.ExcelBaseEnumConverter;
import top.continew.starter.extension.crud.model.resp.BaseDetailResp;
import top.continew.starter.file.excel.converter.ExcelListConverter;
import top.continew.starter.security.crypto.annotation.FieldEncrypt;

import java.io.Serial;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -86,6 +88,7 @@ public class UserDetailResp extends BaseDetailResp {
* 部门 ID
*/
@Schema(description = "部门 ID", example = "5")
@ConditionOnExpression("#target.deptName == null")
@AssembleMethod(props = @Mapping(src = "name", ref = "deptName"), targetType = DeptService.class, method = @ContainerMethod(bindMethod = "get", resultType = DeptResp.class))
@ExcelProperty(value = "部门 ID", order = 6)
private Long deptId;
Expand Down Expand Up @@ -117,13 +120,15 @@ public class UserDetailResp extends BaseDetailResp {
*/
@Schema(description = "手机号码", example = "13811111111")
@ExcelProperty(value = "手机号码", order = 10)
@FieldEncrypt
private String phone;

/**
* 邮箱
*/
@Schema(description = "邮箱", example = "[email protected]")
@ExcelProperty(value = "邮箱", order = 11)
@FieldEncrypt
private String email;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@
package top.continew.admin.system.model.resp;

import cn.crane4j.annotation.Assemble;
import cn.crane4j.annotation.AssembleMethod;
import cn.crane4j.annotation.ContainerMethod;
import cn.crane4j.annotation.Mapping;
import cn.crane4j.core.executor.handler.ManyToManyAssembleOperationHandler;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import top.continew.admin.common.constant.ContainerConstants;
import top.continew.admin.common.enums.DisEnableStatusEnum;
import top.continew.admin.common.enums.GenderEnum;
import top.continew.admin.common.util.helper.LoginHelper;
import top.continew.admin.system.service.DeptService;
import top.continew.starter.extension.crud.model.resp.BaseDetailResp;
import top.continew.starter.security.mask.annotation.JsonMask;
import top.continew.starter.security.mask.enums.MaskType;
Expand Down Expand Up @@ -110,7 +106,6 @@ public class UserResp extends BaseDetailResp {
* 部门 ID
*/
@Schema(description = "部门 ID", example = "5")
@AssembleMethod(props = @Mapping(src = "name", ref = "deptName"), targetType = DeptService.class, method = @ContainerMethod(bindMethod = "get", resultType = DeptResp.class))
private Long deptId;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
@Override
public PageResp<UserResp> page(UserQuery query, PageQuery pageQuery) {
QueryWrapper<UserDO> queryWrapper = this.buildQueryWrapper(query);
IPage<UserDO> page = baseMapper.selectUserPage(pageQuery.toPage(), queryWrapper);
IPage<UserDetailResp> page = baseMapper.selectUserPage(pageQuery.toPage(), queryWrapper);
PageResp<UserResp> pageResp = PageResp.build(page, this.listClass);
pageResp.getList().forEach(this::fill);
return pageResp;
Expand Down Expand Up @@ -288,7 +288,7 @@ protected <E> List<E> list(UserQuery query, SortQuery sortQuery, Class<E> target
QueryWrapper<UserDO> queryWrapper = this.buildQueryWrapper(query);
// 设置排序
super.sort(queryWrapper, sortQuery);
List<UserDO> entityList = baseMapper.selectUserList(queryWrapper);
List<UserDetailResp> entityList = baseMapper.selectUserList(queryWrapper);
if (entityClass == targetClass) {
return (List<E>)entityList;
}
Expand All @@ -309,7 +309,7 @@ protected QueryWrapper<UserDO> buildQueryWrapper(UserQuery query) {
.eq(null != status, "t1.status", status)
.between(CollUtil.isNotEmpty(createTimeList), "t1.create_time", CollUtil.getFirst(createTimeList), CollUtil
.getLast(createTimeList))
.and(null != deptId, q -> {
.and(null != deptId && !SysConstants.SUPER_DEPT_ID.equals(deptId), q -> {
List<Long> deptIdList = deptService.listChildren(deptId)
.stream()
.map(DeptDO::getId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@
t1.status,
t1.is_system,
t1.pwd_reset_time,
t1.dept_id
t1.dept_id,
t2.name AS deptName
FROM sys_user AS t1
LEFT JOIN sys_dept AS t2 ON t2.id = t1.dept_id
</sql>

<select id="selectUserPage" resultType="top.continew.admin.system.model.entity.UserDO">
<select id="selectUserPage" resultType="top.continew.admin.system.model.resp.UserDetailResp">
<include refid="selectUser" />
${ew.customSqlSegment}
</select>

<select id="selectUserList" resultType="top.continew.admin.system.model.entity.UserDO">
<select id="selectUserList" resultType="top.continew.admin.system.model.resp.UserDetailResp">
<include refid="selectUser" />
${ew.customSqlSegment}
</select>
Expand Down

0 comments on commit 448f9a0

Please sign in to comment.