mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-11 16:57:12 +08:00
perf: 优化用户及部门查询
This commit is contained in:
@@ -23,6 +23,7 @@ import org.apache.ibatis.annotations.Param;
|
||||
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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
/**
|
||||
* 查询列表
|
||||
@@ -54,7 +55,7 @@ public interface UserMapper extends DataPermissionMapper<UserDO> {
|
||||
* @return 列表信息
|
||||
*/
|
||||
@DataPermission("t1")
|
||||
List<UserDO> selectUserList(@Param(Constants.WRAPPER) QueryWrapper<UserDO> queryWrapper);
|
||||
List<UserDetailResp> selectUserList(@Param(Constants.WRAPPER) QueryWrapper<UserDO> queryWrapper);
|
||||
|
||||
/**
|
||||
* 根据用户名查询
|
||||
|
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
|
@@ -20,6 +20,7 @@ import cn.crane4j.annotation.Assemble;
|
||||
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;
|
||||
@@ -33,6 +34,7 @@ import top.continew.admin.system.service.DeptService;
|
||||
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;
|
||||
@@ -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;
|
||||
@@ -117,6 +120,7 @@ public class UserDetailResp extends BaseDetailResp {
|
||||
*/
|
||||
@Schema(description = "手机号码", example = "13811111111")
|
||||
@ExcelProperty(value = "手机号码", order = 10)
|
||||
@FieldEncrypt
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
@@ -124,6 +128,7 @@ public class UserDetailResp extends BaseDetailResp {
|
||||
*/
|
||||
@Schema(description = "邮箱", example = "123456789@qq.com")
|
||||
@ExcelProperty(value = "邮箱", order = 11)
|
||||
@FieldEncrypt
|
||||
private String email;
|
||||
|
||||
/**
|
||||
|
@@ -17,9 +17,6 @@
|
||||
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;
|
||||
@@ -27,7 +24,6 @@ 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;
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
@@ -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;
|
||||
@@ -288,7 +288,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
|
||||
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;
|
||||
}
|
||||
@@ -309,7 +309,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
|
||||
.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)
|
||||
|
@@ -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>
|
||||
|
Reference in New Issue
Block a user