fix: 修复导出用户报错

This commit is contained in:
2024-05-20 23:40:59 +08:00
parent 4198cb75eb
commit 655a695753
5 changed files with 110 additions and 53 deletions

View File

@@ -26,6 +26,8 @@ import top.continew.admin.system.model.entity.UserDO;
import top.continew.starter.data.mybatis.plus.datapermission.DataPermission;
import top.continew.starter.security.crypto.annotation.FieldEncrypt;
import java.util.List;
/**
* 用户 Mapper
*
@@ -41,10 +43,19 @@ public interface UserMapper extends DataPermissionMapper<UserDO> {
* @param queryWrapper 查询条件
* @return 分页列表信息
*/
@DataPermission
@DataPermission("t1")
IPage<UserDO> selectUserPage(@Param("page") IPage<UserDO> page,
@Param(Constants.WRAPPER) QueryWrapper<UserDO> queryWrapper);
/**
* 查询列表
*
* @param queryWrapper 查询条件
* @return 列表信息
*/
@DataPermission("t1")
List<UserDO> selectUserList(@Param(Constants.WRAPPER) QueryWrapper<UserDO> queryWrapper);
/**
* 根据用户名查询
*

View File

@@ -16,6 +16,8 @@
package top.continew.admin.system.model.entity;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import top.continew.admin.common.config.mybatis.BCryptEncryptor;
@@ -65,12 +67,14 @@ public class UserDO extends BaseDO {
* 邮箱
*/
@FieldEncrypt
@TableField(insertStrategy = FieldStrategy.NOT_EMPTY)
private String email;
/**
* 手机号码
*/
@FieldEncrypt
@TableField(insertStrategy = FieldStrategy.NOT_EMPTY)
private String phone;
/**

View File

@@ -32,6 +32,7 @@ import top.continew.admin.common.util.helper.LoginHelper;
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 java.io.Serial;
import java.time.LocalDateTime;
@@ -57,83 +58,43 @@ public class UserDetailResp extends BaseDetailResp {
* 用户名
*/
@Schema(description = "用户名", example = "zhangsan")
@ExcelProperty(value = "用户名")
@ExcelProperty(value = "用户名", order = 2)
private String username;
/**
* 昵称
*/
@Schema(description = "昵称", example = "张三")
@ExcelProperty(value = "昵称")
@ExcelProperty(value = "昵称", order = 3)
private String nickname;
/**
* 性别
*/
@Schema(description = "性别0未知12", type = "Integer", allowableValues = {"0", "1", "2"}, example = "1")
@ExcelProperty(value = "性别", converter = ExcelBaseEnumConverter.class)
private GenderEnum gender;
/**
* 邮箱
*/
@Schema(description = "邮箱", example = "123456789@qq.com")
@ExcelProperty(value = "邮箱")
private String email;
/**
* 手机号码
*/
@Schema(description = "手机号码", example = "13811111111")
@ExcelProperty(value = "手机号码")
private String phone;
/**
* 头像地址
*/
@Schema(description = "头像地址", example = "https://himg.bdimg.com/sys/portrait/item/public.1.81ac9a9e.rf1ix17UfughLQjNo7XQ_w.jpg")
@ExcelProperty(value = "头像地址")
private String avatar;
/**
* 状态
*/
@Schema(description = "状态1启用2禁用", type = "Integer", allowableValues = {"1", "2"}, example = "1")
@ExcelProperty(value = "状态", converter = ExcelBaseEnumConverter.class)
@ExcelProperty(value = "状态", converter = ExcelBaseEnumConverter.class, order = 4)
private DisEnableStatusEnum status;
/**
* 是否为系统内置数据
* 性别
*/
@Schema(description = "系统内置", example = "false")
@ExcelProperty(value = "系统内置")
private Boolean isSystem;
/**
* 描述
*/
@Schema(description = "描述", example = "张三描述信息")
@ExcelProperty(value = "描述")
private String description;
/**
* 最后一次修改密码时间
*/
@Schema(description = "最后一次修改密码时间", example = "2023-08-08 08:08:08", type = "string")
private LocalDateTime pwdResetTime;
@Schema(description = "性别0未知12", type = "Integer", allowableValues = {"0", "1", "2"}, example = "1")
@ExcelProperty(value = "性别", converter = ExcelBaseEnumConverter.class, order = 5)
private GenderEnum gender;
/**
* 部门 ID
*/
@Schema(description = "部门 ID", example = "5")
@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;
/**
* 所属部门
*/
@Schema(description = "所属部门", example = "测试部")
@ExcelProperty(value = "所属部门")
@ExcelProperty(value = "所属部门", order = 7)
private String deptName;
/**
@@ -141,15 +102,57 @@ public class UserDetailResp extends BaseDetailResp {
*/
@Schema(description = "角色 ID 列表", example = "2")
@Assemble(prop = ":roleNames", container = ContainerConstants.USER_ROLE_NAME_LIST, handlerType = ManyToManyAssembleOperationHandler.class)
@ExcelProperty(value = "角色 ID 列表", converter = ExcelListConverter.class, order = 8)
private List<Long> roleIds;
/**
* 角色名称列表
*/
@Schema(description = "角色名称列表", example = "测试人员")
@ExcelProperty(value = "角色")
@ExcelProperty(value = "角色", converter = ExcelListConverter.class, order = 9)
private List<String> roleNames;
/**
* 手机号码
*/
@Schema(description = "手机号码", example = "13811111111")
@ExcelProperty(value = "手机号码", order = 10)
private String phone;
/**
* 邮箱
*/
@Schema(description = "邮箱", example = "123456789@qq.com")
@ExcelProperty(value = "邮箱", order = 11)
private String email;
/**
* 是否为系统内置数据
*/
@Schema(description = "系统内置", example = "false")
@ExcelProperty(value = "系统内置", order = 12)
private Boolean isSystem;
/**
* 描述
*/
@Schema(description = "描述", example = "张三描述信息")
@ExcelProperty(value = "描述", order = 13)
private String description;
/**
* 头像地址
*/
@Schema(description = "头像地址", example = "https://himg.bdimg.com/sys/portrait/item/public.1.81ac9a9e.rf1ix17UfughLQjNo7XQ_w.jpg")
@ExcelProperty(value = "头像地址", order = 14)
private String avatar;
/**
* 最后一次修改密码时间
*/
@Schema(description = "最后一次修改密码时间", example = "2023-08-08 08:08:08", type = "string")
private LocalDateTime pwdResetTime;
@Override
public Boolean getDisabled() {
return this.getIsSystem() || Objects.equals(this.getId(), LoginHelper.getUserId());

View File

@@ -55,6 +55,7 @@ import top.continew.admin.system.service.*;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.util.validate.CheckUtils;
import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.query.SortQuery;
import top.continew.starter.extension.crud.model.resp.PageResp;
import top.continew.starter.extension.crud.service.CommonUserService;
import top.continew.starter.extension.crud.service.impl.BaseServiceImpl;
@@ -282,6 +283,18 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
return baseMapper.selectNicknameById(id);
}
@Override
protected <E> List<E> list(UserQuery query, SortQuery sortQuery, Class<E> targetClass) {
QueryWrapper<UserDO> queryWrapper = this.buildQueryWrapper(query);
// 设置排序
super.sort(queryWrapper, sortQuery);
List<UserDO> entityList = baseMapper.selectUserList(queryWrapper);
if (entityClass == targetClass) {
return (List<E>)entityList;
}
return BeanUtil.copyToList(entityList, targetClass);
}
@Override
protected QueryWrapper<UserDO> buildQueryWrapper(UserQuery query) {
String description = query.getDescription();

View File

@@ -2,10 +2,36 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="top.continew.admin.system.mapper.UserMapper">
<select id="selectUserPage" resultType="top.continew.admin.system.model.entity.UserDO">
SELECT t1.*
<sql id="selectUser">
SELECT
t1.id,
t1.create_user,
t1.create_time,
t1.update_user,
t1.update_time,
t1.username,
t1.nickname,
t1.password,
t1.gender,
t1.email,
t1.phone,
t1.avatar,
t1.description,
t1.status,
t1.is_system,
t1.pwd_reset_time,
t1.dept_id
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">
<include refid="selectUser" />
${ew.customSqlSegment}
</select>
<select id="selectUserList" resultType="top.continew.admin.system.model.entity.UserDO">
<include refid="selectUser" />
${ew.customSqlSegment}
</select>