fix 用户管理导入
This commit is contained in:
parent
d3dcc6b5c2
commit
cb868018b0
|
|
@ -100,6 +100,10 @@ public class SysUser extends BaseEntity {
|
|||
*/
|
||||
@TableField(exist = false)
|
||||
private Long roleId;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
public boolean isAdmin()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
package com.chushang.system.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DeptDTO {
|
||||
private Long deptId;
|
||||
private String deptName;
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.chushang.system.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RoleDTO {
|
||||
private Long roleId;
|
||||
private String roleName;
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ import com.chushang.common.log.annotation.SysLog;
|
|||
import com.chushang.common.log.enums.BusinessType;
|
||||
import com.chushang.security.annotation.RequiresPermissions;
|
||||
import com.chushang.security.utils.SecurityUtils;
|
||||
import com.chushang.system.entity.dto.DeptDTO;
|
||||
import com.chushang.system.entity.dto.ListDeptDTO;
|
||||
import com.chushang.security.entity.po.SysDept;
|
||||
import com.chushang.system.service.ISysDeptService;
|
||||
|
|
@ -158,4 +159,9 @@ public class DeptController {
|
|||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
public List<DeptDTO> getDept(){
|
||||
List<DeptDTO> deptDTOS = sysDeptService.getDept();
|
||||
return deptDTOS;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,27 +6,38 @@ import com.chushang.common.core.util.StringUtils;
|
|||
import com.chushang.common.core.web.AjaxResult;
|
||||
import com.chushang.common.log.annotation.SysLog;
|
||||
import com.chushang.common.log.enums.BusinessType;
|
||||
import com.chushang.datascope.annotation.DataScope;
|
||||
import com.chushang.security.annotation.RequiresPermissions;
|
||||
import com.chushang.security.service.TokenService;
|
||||
import com.chushang.security.utils.SecurityUtils;
|
||||
import com.chushang.system.entity.bo.PasswordForm;
|
||||
import com.chushang.system.entity.bo.RoleUser;
|
||||
import com.chushang.system.entity.bo.UserRole;
|
||||
import com.chushang.system.entity.dto.DeptDTO;
|
||||
import com.chushang.system.entity.dto.ListUserDTO;
|
||||
import com.chushang.system.entity.dto.RoleDTO;
|
||||
import com.chushang.system.entity.po.SysPost;
|
||||
import com.chushang.security.entity.po.SysRole;
|
||||
import com.chushang.security.entity.po.SysUser;
|
||||
import com.chushang.security.entity.vo.LoginUser;
|
||||
import com.chushang.system.service.*;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.cache.annotation.CacheRemove;
|
||||
import javax.validation.Valid;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
/**
|
||||
* @author by zhaowenyuan create 2022/8/18 17:50
|
||||
*/
|
||||
|
|
@ -34,6 +45,7 @@ import java.util.stream.Collectors;
|
|||
@RequestMapping(value = "/user")
|
||||
public class UserController {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(UserController.class);
|
||||
@Resource
|
||||
ISysUserService sysUserService;
|
||||
@Resource
|
||||
|
|
@ -319,15 +331,68 @@ public class UserController {
|
|||
tokenService.forcedRetreat(userId);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
@Autowired
|
||||
private ISysDeptService sysDeptService;
|
||||
|
||||
|
||||
/**
|
||||
* todo 导入用户
|
||||
*/
|
||||
@PostMapping(value = "/import")
|
||||
@RequiresPermissions("system:user:import")
|
||||
// @RequiresPermissions("system:user:import")
|
||||
public AjaxResult importUser(MultipartFile file){
|
||||
return AjaxResult.error("暂未开放");
|
||||
if(file.isEmpty()){
|
||||
return AjaxResult.error("文件不能为空");
|
||||
}
|
||||
SysUser sysUser = new SysUser();
|
||||
//查部门
|
||||
List<DeptDTO> dept = sysDeptService.getDept();
|
||||
List<RoleDTO> role = sysRoleService.getRole();
|
||||
|
||||
try {
|
||||
Workbook workbook = new XSSFWorkbook(file.getInputStream());
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
DataFormatter format = new DataFormatter();
|
||||
for (Row row : sheet) {
|
||||
HashSet<Long> roleIds = new HashSet<>();
|
||||
if(row.getRowNum()==0)continue;
|
||||
sysUser.setNickName(format.formatCellValue(row.getCell(0)));
|
||||
sysUser.setUsername(format.formatCellValue(row.getCell(1)));
|
||||
sysUser.setPassword(format.formatCellValue(row.getCell(2)));
|
||||
sysUser.setPhone(format.formatCellValue(row.getCell(3)));
|
||||
if (format.formatCellValue(row.getCell(4)).equals("男")){
|
||||
sysUser.setGender(0);
|
||||
}else if (format.formatCellValue(row.getCell(4)).equals("女")){
|
||||
sysUser.setGender(1);
|
||||
}
|
||||
String deptName = format.formatCellValue(row.getCell(5));
|
||||
for (DeptDTO deptDTO : dept) {
|
||||
if(deptDTO.getDeptName().equals(deptName)){
|
||||
sysUser.setDeptId(deptDTO.getDeptId());
|
||||
break;
|
||||
}
|
||||
}
|
||||
sysUser.setEmail(format.formatCellValue(row.getCell(6)));
|
||||
String roleName = format.formatCellValue(row.getCell(7));
|
||||
String[] split = roleName.split(",");
|
||||
for (RoleDTO roleDTO : role) {
|
||||
for (String name : split) {
|
||||
if(roleDTO.getRoleName().equals(name)){
|
||||
roleIds.add(roleDTO.getRoleId());
|
||||
}
|
||||
}
|
||||
}
|
||||
sysUser.setRoleIds(roleIds);
|
||||
sysUser.setRemark(format.formatCellValue(row.getCell(8)));
|
||||
|
||||
System.out.println(sysUser);
|
||||
//存库
|
||||
save(sysUser);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.chushang.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.chushang.system.entity.dto.DeptDTO;
|
||||
import com.chushang.system.entity.dto.ListDeptDTO;
|
||||
import com.chushang.security.entity.po.SysDept;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
|
@ -30,4 +31,6 @@ public interface SysDeptMapper extends BaseMapper<SysDept> {
|
|||
|
||||
@Select("SELECT dept_id FROM sys_dept WHERE dept_id = #{deptId} or find_in_set( #{deptId} , ancestors )")
|
||||
List<String> listScopeDeptIdByDeptId(@Param("deptId") Long deptId);
|
||||
|
||||
List<DeptDTO> getDept();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.chushang.system.entity.dto.ListRoleDTO;
|
||||
import com.chushang.security.entity.po.SysRole;
|
||||
import com.chushang.system.entity.dto.RoleDTO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -27,4 +28,6 @@ public interface SysRoleMapper extends BaseMapper<SysRole> {
|
|||
SysRole selectRoleById(Long roleId);
|
||||
|
||||
Set<SysRole> selectRoleByUsername(String username);
|
||||
|
||||
List<RoleDTO> getRole();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.chushang.common.core.exception.ResultException;
|
|||
import com.chushang.common.core.text.Convert;
|
||||
import com.chushang.common.core.util.StringUtils;
|
||||
import com.chushang.common.mybatis.enums.Operator;
|
||||
import com.chushang.system.entity.dto.DeptDTO;
|
||||
import com.chushang.system.entity.dto.ListDeptDTO;
|
||||
import com.chushang.security.entity.po.SysDept;
|
||||
import com.chushang.system.entity.vo.TreeSelect;
|
||||
|
|
@ -123,4 +124,6 @@ public interface ISysDeptService extends IService<SysDept> {
|
|||
List<String> listScopeDeptIdByRoleId(Long roleId);
|
||||
|
||||
List<String> listScopeDeptIdByDeptId(Long deptId);
|
||||
|
||||
List<DeptDTO> getDept();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import com.chushang.system.entity.bo.UserRole;
|
|||
import com.chushang.system.entity.dto.ListRoleDTO;
|
||||
import com.chushang.security.entity.po.SysRole;
|
||||
import com.chushang.security.entity.po.SysUser;
|
||||
import com.chushang.system.entity.dto.RoleDTO;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
|
@ -77,4 +78,6 @@ public interface ISysRoleService extends IService<SysRole> {
|
|||
void insertAuthUsers(Long roleId, Collection<Long> userIds);
|
||||
|
||||
String selectRolesByUserName(String username);
|
||||
|
||||
List<RoleDTO> getRole();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.chushang.common.core.exception.ResultException;
|
|||
import com.chushang.common.core.util.SpringUtils;
|
||||
import com.chushang.common.core.util.StringUtils;
|
||||
import com.chushang.datascope.annotation.DataScope;
|
||||
import com.chushang.system.entity.dto.DeptDTO;
|
||||
import com.chushang.system.mapper.SysDeptMapper;
|
||||
import com.chushang.system.service.ISysUserService;
|
||||
import com.chushang.security.utils.SecurityUtils;
|
||||
|
|
@ -116,6 +117,11 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|||
return baseMapper.listScopeDeptIdByDeptId(deptId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeptDTO> getDept() {
|
||||
return baseMapper.getDept();
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归列表
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import com.chushang.datascope.annotation.DataScope;
|
|||
import com.chushang.security.utils.SecurityUtils;
|
||||
import com.chushang.system.entity.bo.RoleUser;
|
||||
import com.chushang.system.entity.bo.UserRole;
|
||||
import com.chushang.system.entity.dto.RoleDTO;
|
||||
import com.chushang.system.mapper.SysRoleMapper;
|
||||
import com.chushang.system.service.ISysRoleMenuService;
|
||||
import com.chushang.system.entity.dto.ListRoleDTO;
|
||||
|
|
@ -175,4 +176,9 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
return CollectionUtil.isEmpty(roleList) ? StringUtils.EMPTY : roleList.stream().map(SysRole::getRoleName)
|
||||
.collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RoleDTO> getRole() {
|
||||
return baseMapper.getRole();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@
|
|||
</if>
|
||||
order by d.parent_dept_id, d.order_num
|
||||
</select>
|
||||
<select id="getDept" resultType="com.chushang.system.entity.dto.DeptDTO">
|
||||
select dept_id,dept_name from sys_dept where del_state = 0
|
||||
</select>
|
||||
|
||||
<update id="updateDeptChildren" parameterType="java.util.List">
|
||||
update sys_dept set ancestors =
|
||||
|
|
|
|||
|
|
@ -89,4 +89,7 @@
|
|||
<include refid="selectRoleVo"/>
|
||||
where r.del_state = FALSE AND u.username = #{username}
|
||||
</select>
|
||||
<select id="getRole" resultType="com.chushang.system.entity.dto.RoleDTO">
|
||||
select role_id , role_name from sys_role where del_state = 0
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue