Skip to content

Commit

Permalink
fix: 修复导出用户报错
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed May 20, 2024
1 parent 4198cb7 commit 655a695
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import top.continew.starter.data.mybatis.plus.datapermission.DataPermission;
import top.continew.starter.security.crypto.annotation.FieldEncrypt;

import java.util.List;

/**
* 用户 Mapper
*
Expand All @@ -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);

/**
* 根据用户名查询
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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 java.io.Serial;
import java.time.LocalDateTime;
Expand All @@ -57,98 +58,100 @@ 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:未知;1:男;2:)", type = "Integer", allowableValues = {"0", "1", "2"}, example = "1")
@ExcelProperty(value = "性别", converter = ExcelBaseEnumConverter.class)
private GenderEnum gender;
@Schema(description = "状态(1:启用;2:禁用)", type = "Integer", allowableValues = {"1", "2"}, example = "1")
@ExcelProperty(value = "状态", converter = ExcelBaseEnumConverter.class, order = 4)
private DisEnableStatusEnum status;

/**
* 邮箱
* 性别
*/
@Schema(description = "邮箱", example = "123456789@qq.com")
@ExcelProperty(value = "邮箱")
private String email;
@Schema(description = "性别(0:未知;1:男;2:女)", type = "Integer", allowableValues = {"0", "1", "2"}, example = "1")
@ExcelProperty(value = "性别", converter = ExcelBaseEnumConverter.class, order = 5)
private GenderEnum gender;

/**
* 手机号码
* 部门 ID
*/
@Schema(description = "手机号码", example = "13811111111")
@ExcelProperty(value = "手机号码")
private String phone;
@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 = "https://himg.bdimg.com/sys/portrait/item/public.1.81ac9a9e.rf1ix17UfughLQjNo7XQ_w.jpg")
@ExcelProperty(value = "头像地址")
private String avatar;
@Schema(description = "所属部门", example = "测试部")
@ExcelProperty(value = "所属部门", order = 7)
private String deptName;

/**
* 状态
* 角色 ID 列表
*/
@Schema(description = "状态(1:启用;2:禁用)", type = "Integer", allowableValues = {"1", "2"}, example = "1")
@ExcelProperty(value = "状态", converter = ExcelBaseEnumConverter.class)
private DisEnableStatusEnum status;
@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 = "false")
@ExcelProperty(value = "系统内置")
private Boolean isSystem;
@Schema(description = "角色名称列表", example = "测试人员")
@ExcelProperty(value = "角色", converter = ExcelListConverter.class, order = 9)
private List<String> roleNames;

/**
* 描述
* 手机号码
*/
@Schema(description = "描述", example = "张三描述信息")
@ExcelProperty(value = "描述")
private String description;
@Schema(description = "手机号码", example = "13811111111")
@ExcelProperty(value = "手机号码", order = 10)
private String phone;

/**
* 最后一次修改密码时间
* 邮箱
*/
@Schema(description = "最后一次修改密码时间", example = "2023-08-08 08:08:08", type = "string")
private LocalDateTime pwdResetTime;
@Schema(description = "邮箱", example = "123456789@qq.com")
@ExcelProperty(value = "邮箱", order = 11)
private String email;

/**
* 部门 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;
@Schema(description = "系统内置", example = "false")
@ExcelProperty(value = "系统内置", order = 12)
private Boolean isSystem;

/**
* 所属部门
* 描述
*/
@Schema(description = "所属部门", example = "测试部")
@ExcelProperty(value = "所属部门")
private String deptName;
@Schema(description = "描述", example = "张三描述信息")
@ExcelProperty(value = "描述", order = 13)
private String description;

/**
* 角色 ID 列表
* 头像地址
*/
@Schema(description = "角色 ID 列表", example = "2")
@Assemble(prop = ":roleNames", container = ContainerConstants.USER_ROLE_NAME_LIST, handlerType = ManyToManyAssembleOperationHandler.class)
private List<Long> roleIds;
@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 = "测试人员")
@ExcelProperty(value = "角色")
private List<String> roleNames;
@Schema(description = "最后一次修改密码时间", example = "2023-08-08 08:08:08", type = "string")
private LocalDateTime pwdResetTime;

@Override
public Boolean getDisabled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
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;
Expand Down Expand Up @@ -282,6 +283,18 @@ public String getNicknameById(Long id) {
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();
Expand Down
30 changes: 28 additions & 2 deletions continew-admin-system/src/main/resources/mapper/UserMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down

0 comments on commit 655a695

Please sign in to comment.