Browse Source

fix:[系统管理] [用户管理] 导出修改

master
memorylkf 3 weeks ago
parent
commit
6d114c0898
8 changed files with 145 additions and 22 deletions
  1. +31
    -2
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysUserController.java
  2. +87
    -0
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/dto/UserExportDto.java
  3. +3
    -3
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysDeptServiceImpl.java
  4. +3
    -3
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysRoleServiceImpl.java
  5. +4
    -4
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysUserServiceImpl.java
  6. +1
    -1
      hxhq-modules/hxhq-system/src/main/resources/mapper/system/SysDeptMapper.xml
  7. +1
    -1
      hxhq-modules/hxhq-system/src/main/resources/mapper/system/SysRoleMapper.xml
  8. +15
    -8
      hxhq-modules/hxhq-system/src/main/resources/mapper/system/SysUserMapper.xml

+ 31
- 2
hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/controller/SysUserController.java View File

@ -1,12 +1,15 @@
package com.hxhq.system.controller; package com.hxhq.system.controller;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.hxhq.business.enums.dept.DeptTypeEnum;
import com.hxhq.system.dto.UserExportDto;
import com.hxhq.system.service.ISysConfigService; import com.hxhq.system.service.ISysConfigService;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -101,8 +104,26 @@ public class SysUserController extends BaseController
public void export(HttpServletResponse response, SysUser user) public void export(HttpServletResponse response, SysUser user)
{ {
List<SysUser> list = userService.selectUserList(user); List<SysUser> list = userService.selectUserList(user);
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
util.exportExcel(response, list, "用户数据");
List<UserExportDto> userList = new ArrayList<>();
for(SysUser u : list){
UserExportDto exportDto = new UserExportDto();
exportDto.setUserName(u.getUserName());
exportDto.setNickName(u.getNickName());
exportDto.setPhonenumber(u.getPhonenumber());
exportDto.setDeptName(u.getDept()==null?"":u.getDept().getDeptName());
exportDto.setRoleName(getRoleName(u.getRoles()));
exportDto.setStatus(u.getStatus());
userList.add(exportDto);
}
ExcelUtil<UserExportDto> util = new ExcelUtil<UserExportDto>(UserExportDto.class);
util.exportExcel(response, userList, "用户数据");
}
private String getRoleName(List<SysRole> roleList){
if(roleList==null || roleList.size()==0){
return "";
}
return String.join(",",roleList.stream().map(o->o.getRoleName()).toArray(String[]::new));
} }
@Log(title = "用户管理", businessType = BusinessType.IMPORT) @Log(title = "用户管理", businessType = BusinessType.IMPORT)
@ -282,6 +303,10 @@ public class SysUserController extends BaseController
{ {
return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在"); return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
} }
SysDept sysDept = deptService.selectDeptById(user.getDeptId());
if(!sysDept.getType().equals(DeptTypeEnum.subject.getValue()) && !sysDept.getType().equals(DeptTypeEnum.team.getValue())){
return error("新增用户'" + user.getUserName() + "'失败,部门必须选到学科或者小组");
}
user.setCreateBy(SecurityUtils.getUsername()); user.setCreateBy(SecurityUtils.getUsername());
user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
return toAjax(userService.insertUser(user)); return toAjax(userService.insertUser(user));
@ -311,6 +336,10 @@ public class SysUserController extends BaseController
{ {
return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在"); return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
} }
SysDept sysDept = deptService.selectDeptById(user.getDeptId());
if(!sysDept.getType().equals(DeptTypeEnum.subject.getValue()) && !sysDept.getType().equals(DeptTypeEnum.team.getValue())){
return error("修改用户'" + user.getUserName() + "'失败,部门必须选到学科或者小组");
}
user.setUpdateBy(SecurityUtils.getUsername()); user.setUpdateBy(SecurityUtils.getUsername());
return toAjax(userService.updateUser(user)); return toAjax(userService.updateUser(user));
} }

+ 87
- 0
hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/dto/UserExportDto.java View File

@ -0,0 +1,87 @@
package com.hxhq.system.dto;
import com.hxhq.common.core.annotation.Excel;
/**
* @author memory
*/
public class UserExportDto {
/**
* 账号
*/
@Excel(name = "账号")
private String userName;
/**
* 姓名
*/
@Excel(name = "姓名")
private String nickName;
/**
* 手机
*/
@Excel(name = "手机")
private String phonenumber;
/**
* 所属部门/学科
*/
@Excel(name = "所属部门/学科")
private String deptName;
/**
* 所属角色
*/
@Excel(name = "所属角色")
private String roleName;
/**
* 状态
*/
@Excel(name = "状态", readConverterExp = "0=启用,1=禁用")
private String status;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getNickName() {
return nickName;
}
public void setNickName(String nickName) {
this.nickName = nickName;
}
public String getPhonenumber() {
return phonenumber;
}
public void setPhonenumber(String phonenumber) {
this.phonenumber = phonenumber;
}
public String getDeptName() {
return deptName;
}
public void setDeptName(String deptName) {
this.deptName = deptName;
}
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}

+ 3
- 3
hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysDeptServiceImpl.java View File

@ -43,7 +43,7 @@ public class SysDeptServiceImpl implements ISysDeptService
* @return 部门信息集合 * @return 部门信息集合
*/ */
@Override @Override
@DataScope(deptAlias = "d")
// @DataScope(deptAlias = "d")
public List<SysDept> selectDeptList(SysDept dept) public List<SysDept> selectDeptList(SysDept dept)
{ {
return deptMapper.selectDeptList(dept); return deptMapper.selectDeptList(dept);
@ -58,7 +58,7 @@ public class SysDeptServiceImpl implements ISysDeptService
@Override @Override
public List<TreeSelect> selectDeptTreeList(SysDept dept) public List<TreeSelect> selectDeptTreeList(SysDept dept)
{ {
List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
List<SysDept> depts = deptMapper.selectDeptList(dept);
return buildDeptTreeSelect(depts); return buildDeptTreeSelect(depts);
} }
@ -195,7 +195,7 @@ public class SysDeptServiceImpl implements ISysDeptService
{ {
SysDept dept = new SysDept(); SysDept dept = new SysDept();
dept.setDeptId(deptId); dept.setDeptId(deptId);
List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
List<SysDept> depts = deptMapper.selectDeptList(dept);
if (StringUtils.isEmpty(depts)) if (StringUtils.isEmpty(depts))
{ {
throw new ServiceException("没有权限访问部门数据!"); throw new ServiceException("没有权限访问部门数据!");

+ 3
- 3
hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysRoleServiceImpl.java View File

@ -53,7 +53,7 @@ public class SysRoleServiceImpl implements ISysRoleService
* @return 角色数据集合信息 * @return 角色数据集合信息
*/ */
@Override @Override
@DataScope(deptAlias = "d")
// @DataScope(deptAlias = "d")
public List<SysRole> selectRoleList(SysRole role) public List<SysRole> selectRoleList(SysRole role)
{ {
return roleMapper.selectRoleList(role); return roleMapper.selectRoleList(role);
@ -113,7 +113,7 @@ public class SysRoleServiceImpl implements ISysRoleService
@Override @Override
public List<SysRole> selectRoleAll() public List<SysRole> selectRoleAll()
{ {
return SpringUtils.getAopProxy(this).selectRoleList(new SysRole());
return roleMapper.selectRoleList(new SysRole());
} }
/** /**
@ -204,7 +204,7 @@ public class SysRoleServiceImpl implements ISysRoleService
{ {
SysRole role = new SysRole(); SysRole role = new SysRole();
role.setRoleId(roleId); role.setRoleId(roleId);
List<SysRole> roles = SpringUtils.getAopProxy(this).selectRoleList(role);
List<SysRole> roles = roleMapper.selectRoleList(role);
if (StringUtils.isEmpty(roles)) if (StringUtils.isEmpty(roles))
{ {
throw new ServiceException("没有权限访问角色数据!"); throw new ServiceException("没有权限访问角色数据!");

+ 4
- 4
hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysUserServiceImpl.java View File

@ -75,7 +75,7 @@ public class SysUserServiceImpl implements ISysUserService
* @return 用户信息集合信息 * @return 用户信息集合信息
*/ */
@Override @Override
@DataScope(deptAlias = "d", userAlias = "u")
// @DataScope(deptAlias = "d", userAlias = "u")
public List<SysUser> selectUserList(SysUser user) public List<SysUser> selectUserList(SysUser user)
{ {
return userMapper.selectUserList(user); return userMapper.selectUserList(user);
@ -88,7 +88,7 @@ public class SysUserServiceImpl implements ISysUserService
* @return 用户信息集合信息 * @return 用户信息集合信息
*/ */
@Override @Override
@DataScope(deptAlias = "d", userAlias = "u")
// @DataScope(deptAlias = "d", userAlias = "u")
public List<SysUser> selectAllocatedList(SysUser user) public List<SysUser> selectAllocatedList(SysUser user)
{ {
return userMapper.selectAllocatedList(user); return userMapper.selectAllocatedList(user);
@ -101,7 +101,7 @@ public class SysUserServiceImpl implements ISysUserService
* @return 用户信息集合信息 * @return 用户信息集合信息
*/ */
@Override @Override
@DataScope(deptAlias = "d", userAlias = "u")
// @DataScope(deptAlias = "d", userAlias = "u")
public List<SysUser> selectUnallocatedList(SysUser user) public List<SysUser> selectUnallocatedList(SysUser user)
{ {
return userMapper.selectUnallocatedList(user); return userMapper.selectUnallocatedList(user);
@ -245,7 +245,7 @@ public class SysUserServiceImpl implements ISysUserService
{ {
SysUser user = new SysUser(); SysUser user = new SysUser();
user.setUserId(userId); user.setUserId(userId);
List<SysUser> users = SpringUtils.getAopProxy(this).selectUserList(user);
List<SysUser> users = userMapper.selectUserList(user);
if (StringUtils.isEmpty(users)) if (StringUtils.isEmpty(users))
{ {
throw new ServiceException("没有权限访问用户数据!"); throw new ServiceException("没有权限访问用户数据!");

+ 1
- 1
hxhq-modules/hxhq-system/src/main/resources/mapper/system/SysDeptMapper.xml View File

@ -44,7 +44,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND status = #{status} AND status = #{status}
</if> </if>
<!-- 数据范围过滤 --> <!-- 数据范围过滤 -->
${params.dataScope}
-- ${params.dataScope}
order by d.parent_id, d.order_num order by d.parent_id, d.order_num
</select> </select>

+ 1
- 1
hxhq-modules/hxhq-system/src/main/resources/mapper/system/SysRoleMapper.xml View File

@ -52,7 +52,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and date_format(r.create_time,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d') and date_format(r.create_time,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d')
</if> </if>
<!-- 数据范围过滤 --> <!-- 数据范围过滤 -->
${params.dataScope}
-- ${params.dataScope}
order by r.role_id desc order by r.role_id desc
</select> </select>

+ 15
- 8
hxhq-modules/hxhq-system/src/main/resources/mapper/system/SysUserMapper.xml View File

@ -58,15 +58,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql> </sql>
<select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult"> <select id="selectUserList" parameterType="SysUser" 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 from sys_user u
left join sys_dept d on u.dept_id = d.dept_id
where u.del_flag = '0'
<include refid="selectUserVo"/>
-- 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 from sys_user u
-- left join sys_dept d on u.dept_id = d.dept_id
where u.del_flag = '0' and u.user_id&lt;>1
<if test="userId != null and userId != 0"> <if test="userId != null and userId != 0">
AND u.user_id = #{userId} AND u.user_id = #{userId}
</if> </if>
<if test="userName != null and userName != ''"> <if test="userName != null and userName != ''">
AND u.user_name like concat('%', #{userName}, '%') AND u.user_name like concat('%', #{userName}, '%')
</if> </if>
<if test="nickName != null and nickName != ''">
AND u.nick_name like concat('%', #{nickName}, '%')
</if>
<if test="status != null and status != ''"> <if test="status != null and status != ''">
AND u.status = #{status} AND u.status = #{status}
</if> </if>
@ -82,8 +86,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="deptId != null and deptId != 0"> <if test="deptId != null and deptId != 0">
AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, ancestors) )) AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, ancestors) ))
</if> </if>
<if test="roleId != null and roleId != 0">
AND ur.role_id=#{roleId}
</if>
<!-- 数据范围过滤 --> <!-- 数据范围过滤 -->
${params.dataScope}
-- ${params.dataScope}
</select> </select>
<select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult"> <select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult">
@ -92,7 +99,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
left join sys_dept d on u.dept_id = d.dept_id left join sys_dept d on u.dept_id = d.dept_id
left join sys_user_role ur on u.user_id = ur.user_id left join sys_user_role ur on u.user_id = ur.user_id
left join sys_role r on r.role_id = ur.role_id left join sys_role r on r.role_id = ur.role_id
where u.del_flag = '0' and r.role_id = #{roleId}
where u.del_flag = '0' and u.user_id&lt;>1 and r.role_id = #{roleId}
<if test="userName != null and userName != ''"> <if test="userName != null and userName != ''">
AND u.user_name like concat('%', #{userName}, '%') AND u.user_name like concat('%', #{userName}, '%')
</if> </if>
@ -100,7 +107,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND u.phonenumber like concat('%', #{phonenumber}, '%') AND u.phonenumber like concat('%', #{phonenumber}, '%')
</if> </if>
<!-- 数据范围过滤 --> <!-- 数据范围过滤 -->
${params.dataScope}
-- ${params.dataScope}
</select> </select>
<select id="selectAllocatedListSimple" resultType="java.lang.Long"> <select id="selectAllocatedListSimple" resultType="java.lang.Long">
@ -123,7 +130,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
left join sys_dept d on u.dept_id = d.dept_id left join sys_dept d on u.dept_id = d.dept_id
left join sys_user_role ur on u.user_id = ur.user_id left join sys_user_role ur on u.user_id = ur.user_id
left join sys_role r on r.role_id = ur.role_id left join sys_role r on r.role_id = ur.role_id
where u.del_flag = '0' and (r.role_id != #{roleId} or r.role_id IS NULL)
where u.del_flag = '0' and u.user_id&lt;>1 and (r.role_id != #{roleId} or r.role_id IS NULL)
and u.user_id not in (select u.user_id from sys_user u inner join sys_user_role ur on u.user_id = ur.user_id and ur.role_id = #{roleId}) and u.user_id not in (select u.user_id from sys_user u inner join sys_user_role ur on u.user_id = ur.user_id and ur.role_id = #{roleId})
<if test="userName != null and userName != ''"> <if test="userName != null and userName != ''">
AND u.user_name like concat('%', #{userName}, '%') AND u.user_name like concat('%', #{userName}, '%')
@ -132,7 +139,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND u.phonenumber like concat('%', #{phonenumber}, '%') AND u.phonenumber like concat('%', #{phonenumber}, '%')
</if> </if>
<!-- 数据范围过滤 --> <!-- 数据范围过滤 -->
${params.dataScope}
-- ${params.dataScope}
</select> </select>
<select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult"> <select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">

Loading…
Cancel
Save