update 优化 使用翻译注解简化用户查询 调整用户查询逻辑

2.X
疯狂的狮子Li 1 year ago
parent e4eed35da4
commit 203c3fdefd

@ -10,10 +10,10 @@ import org.dromara.common.core.domain.R;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.core.utils.file.MimeTypeUtils;
import org.dromara.common.encrypt.annotation.ApiEncrypt;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.web.core.BaseController;
import org.dromara.resource.api.RemoteFileService;
import org.dromara.resource.api.domain.RemoteFile;
import org.dromara.system.domain.bo.SysUserBo;
@ -22,7 +22,6 @@ import org.dromara.system.domain.bo.SysUserProfileBo;
import org.dromara.system.domain.vo.AvatarVo;
import org.dromara.system.domain.vo.ProfileVo;
import org.dromara.system.domain.vo.SysUserVo;
import org.dromara.system.service.ISysRoleService;
import org.dromara.system.service.ISysUserService;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
@ -44,7 +43,6 @@ import java.util.Arrays;
public class SysProfileController extends BaseController {
private final ISysUserService userService;
private final ISysRoleService roleService;
@DubboReference
private RemoteFileService remoteFileService;
@ -55,7 +53,6 @@ public class SysProfileController extends BaseController {
@GetMapping
public R<ProfileVo> profile() {
SysUserVo user = userService.selectUserById(LoginHelper.getUserId());
user.setRoles(roleService.selectRolesByUserId(user.getUserId()));
ProfileVo profileVo = new ProfileVo();
profileVo.setUser(user);
profileVo.setRoleGroup(userService.selectUserRoleGroup(user.getUserId()));

@ -10,7 +10,6 @@ import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.constant.UserConstants;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StreamUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.encrypt.annotation.ApiEncrypt;
@ -72,9 +71,8 @@ public class SysUserController extends BaseController {
@SaCheckPermission("system:user:export")
@PostMapping("/export")
public void export(SysUserBo user, HttpServletResponse response) {
List<SysUserVo> list = userService.selectUserList(user);
List<SysUserExportVo> listVo = MapstructUtils.convert(list, SysUserExportVo.class);
ExcelUtil.exportExcel(listVo, "用户数据", SysUserExportVo.class, response);
List<SysUserExportVo> list = userService.selectUserExportList(user);
ExcelUtil.exportExcel(list, "用户数据", SysUserExportVo.class, response);
}
/**

@ -1,8 +1,6 @@
package org.dromara.system.domain.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.ReverseAutoMapping;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.dromara.common.excel.annotation.ExcelDictFormat;
@ -20,7 +18,6 @@ import java.util.Date;
@Data
@NoArgsConstructor
@AutoMapper(target = SysUserVo.class, convertGenerate = false)
public class SysUserExportVo implements Serializable {
@Serial
@ -85,14 +82,12 @@ public class SysUserExportVo implements Serializable {
/**
*
*/
@ReverseAutoMapping(target = "deptName", source = "dept.deptName")
@ExcelProperty(value = "部门名称")
private String deptName;
/**
*
*/
@ReverseAutoMapping(target = "leaderName", source = "dept.leaderName")
@ExcelProperty(value = "部门负责人")
private String leaderName;

@ -2,13 +2,13 @@ package org.dromara.system.domain.vo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import org.dromara.common.sensitive.annotation.Sensitive;
import org.dromara.common.sensitive.core.SensitiveStrategy;
import org.dromara.common.translation.annotation.Translation;
import org.dromara.common.translation.constant.TransConstant;
import org.dromara.system.domain.SysUser;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@ -114,9 +114,10 @@ public class SysUserVo implements Serializable {
private Date createTime;
/**
*
*
*/
private SysDeptVo dept;
@Translation(type = TransConstant.DEPT_ID_TO_NAME, mapper = "deptId")
private String deptName;
/**
*

@ -22,12 +22,8 @@ import org.dromara.system.domain.bo.SysUserBo;
import org.dromara.system.domain.vo.SysDeptVo;
import org.dromara.system.domain.vo.SysRoleVo;
import org.dromara.system.domain.vo.SysUserVo;
import org.dromara.system.mapper.SysDeptMapper;
import org.dromara.system.mapper.SysUserMapper;
import org.dromara.system.service.ISysConfigService;
import org.dromara.system.service.ISysPermissionService;
import org.dromara.system.service.ISysRoleService;
import org.dromara.system.service.ISysUserService;
import org.dromara.system.service.*;
import org.springframework.stereotype.Service;
import java.util.List;
@ -46,7 +42,7 @@ public class RemoteUserServiceImpl implements RemoteUserService {
private final ISysPermissionService permissionService;
private final ISysConfigService configService;
private final ISysRoleService roleService;
private final SysDeptMapper deptMapper;
private final ISysDeptService deptService;
private final SysUserMapper userMapper;
@Override
@ -176,11 +172,9 @@ public class RemoteUserServiceImpl implements RemoteUserService {
loginUser.setUserType(userVo.getUserType());
loginUser.setMenuPermission(permissionService.getMenuPermission(userVo.getUserId()));
loginUser.setRolePermission(permissionService.getRolePermission(userVo.getUserId()));
SysDeptVo dept = deptMapper.selectVoById(userVo.getDeptId());
SysDeptVo dept = deptService.selectDeptById(userVo.getDeptId());
loginUser.setDeptName(ObjectUtil.isNull(dept) ? "" : dept.getDeptName());
List<SysRoleVo> roles = DataPermissionHelper.ignore(() -> {
return roleService.selectRolesByUserId(userVo.getUserId());
});
List<SysRoleVo> roles = roleService.selectRolesByUserId(userVo.getUserId());
loginUser.setRoles(BeanUtil.copyToList(roles, RoleDTO.class));
return loginUser;
}

@ -8,6 +8,7 @@ import org.dromara.common.mybatis.annotation.DataColumn;
import org.dromara.common.mybatis.annotation.DataPermission;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import org.dromara.system.domain.SysUser;
import org.dromara.system.domain.vo.SysUserExportVo;
import org.dromara.system.domain.vo.SysUserVo;
import java.util.List;
@ -20,7 +21,7 @@ import java.util.List;
public interface SysUserMapper extends BaseMapperPlus<SysUser, SysUserVo> {
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "deptName", value = "u.dept_id"),
@DataColumn(key = "userName", value = "u.user_id")
})
Page<SysUserVo> selectPageUserList(@Param("page") Page<SysUser> page, @Param(Constants.WRAPPER) Wrapper<SysUser> queryWrapper);
@ -35,7 +36,7 @@ public interface SysUserMapper extends BaseMapperPlus<SysUser, SysUserVo> {
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "u.user_id")
})
List<SysUserVo> selectUserList(@Param(Constants.WRAPPER) Wrapper<SysUser> queryWrapper);
List<SysUserExportVo> selectUserExportList(@Param(Constants.WRAPPER) Wrapper<SysUser> queryWrapper);
/**
*

@ -3,6 +3,7 @@ package org.dromara.system.service;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.system.domain.bo.SysUserBo;
import org.dromara.system.domain.vo.SysUserExportVo;
import org.dromara.system.domain.vo.SysUserVo;
import java.util.List;
@ -23,7 +24,7 @@ public interface ISysUserService {
* @param user
* @return
*/
List<SysUserVo> selectUserList(SysUserBo user);
List<SysUserExportVo> selectUserExportList(SysUserBo user);
/**
*

@ -28,6 +28,7 @@ import org.dromara.system.domain.SysUserRole;
import org.dromara.system.domain.bo.SysUserBo;
import org.dromara.system.domain.vo.SysPostVo;
import org.dromara.system.domain.vo.SysRoleVo;
import org.dromara.system.domain.vo.SysUserExportVo;
import org.dromara.system.domain.vo.SysUserVo;
import org.dromara.system.mapper.*;
import org.dromara.system.service.ISysUserService;
@ -68,8 +69,8 @@ public class SysUserServiceImpl implements ISysUserService {
* @return
*/
@Override
public List<SysUserVo> selectUserList(SysUserBo user) {
return baseMapper.selectUserList(this.buildQueryWrapper(user));
public List<SysUserExportVo> selectUserExportList(SysUserBo user) {
return baseMapper.selectUserExportList(this.buildQueryWrapper(user));
}
private Wrapper<SysUser> buildQueryWrapper(SysUserBo user) {
@ -162,7 +163,12 @@ public class SysUserServiceImpl implements ISysUserService {
*/
@Override
public SysUserVo selectUserById(Long userId) {
return baseMapper.selectVoById(userId);
SysUserVo user = baseMapper.selectVoById(userId);
if (ObjectUtil.isNull(user)) {
return user;
}
user.setRoles(roleMapper.selectRolesByUserId(user.getUserId()));
return user;
}
/**

@ -4,31 +4,21 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.dromara.system.mapper.SysUserMapper">
<!-- 多结构嵌套自动映射需带上每个实体的主键id 否则映射会失败 -->
<resultMap type="org.dromara.system.domain.vo.SysUserVo" id="SysUserResult">
<id property="userId" column="user_id"/>
<result property="deptId" column="dept_id"/>
<association property="dept" column="dept_id" resultMap="deptResult"/>
</resultMap>
<resultMap id="deptResult" type="org.dromara.system.domain.vo.SysDeptVo">
<id property="deptId" column="dept_id"/>
<result property="email" column="dept_email"/>
<result property="status" column="dept_status"/>
<result property="createTime" column="dept_create_time"/>
<resultMap type="org.dromara.system.domain.vo.SysUserExportVo" id="SysUserExportResult">
<id property="userId" column="user_id"/>
</resultMap>
<select id="selectPageUserList" resultMap="SysUserResult">
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex,
u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
d.dept_name, d.leader, u1.user_name as leaderName
u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark
from sys_user u
left join sys_dept d on u.dept_id = d.dept_id
left join sys_user u1 on u1.user_id = d.leader
${ew.getCustomSqlSegment}
</select>
<select id="selectUserList" resultMap="SysUserResult">
<select id="selectUserExportList" resultMap="SysUserExportResult">
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex,
u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
d.dept_name, d.leader, u1.user_name as leaderName

Loading…
Cancel
Save