批量导入,全局异常拦截,用户角色

master
chen 2 years ago
parent dbf9b77a12
commit b60d97d219
  1. 53
      pom.xml
  2. 3
      src/main/java/com/huoran/iasf/IASFApplication.java
  3. 16
      src/main/java/com/huoran/iasf/common/aop/aspect/DataScopeAspect.java
  4. 3
      src/main/java/com/huoran/iasf/common/config/WebMvcConfigurer.java
  5. 47
      src/main/java/com/huoran/iasf/common/exception/BusinessException.java
  6. 42
      src/main/java/com/huoran/iasf/common/exception/code/BaseResponseCode.java
  7. 28
      src/main/java/com/huoran/iasf/common/exception/handler/RestExceptionHandler.java
  8. 16
      src/main/java/com/huoran/iasf/common/shiro/CustomAccessControlFilter.java
  9. 25
      src/main/java/com/huoran/iasf/common/utils/ExcelAttribute.java
  10. 183
      src/main/java/com/huoran/iasf/common/utils/ExcelImportHelper.java
  11. 187
      src/main/java/com/huoran/iasf/common/utils/ExcelStyleUtil.java
  12. 28
      src/main/java/com/huoran/iasf/common/utils/GenUtils.java
  13. 7
      src/main/java/com/huoran/iasf/common/utils/R.java
  14. 22
      src/main/java/com/huoran/iasf/common/utils/ValidatorUtils.java
  15. 25
      src/main/java/com/huoran/iasf/controller/DeptController.java
  16. 9
      src/main/java/com/huoran/iasf/controller/PermissionController.java
  17. 85
      src/main/java/com/huoran/iasf/controller/RoleController.java
  18. 89
      src/main/java/com/huoran/iasf/controller/UserController.java
  19. 21
      src/main/java/com/huoran/iasf/controller/UserDeptController.java
  20. 10
      src/main/java/com/huoran/iasf/controller/UserGroupController.java
  21. 53
      src/main/java/com/huoran/iasf/controller/api/TestController.java
  22. 6
      src/main/java/com/huoran/iasf/entity/SysDept.java
  23. 21
      src/main/java/com/huoran/iasf/entity/SysRole.java
  24. 32
      src/main/java/com/huoran/iasf/entity/SysUser.java
  25. 42
      src/main/java/com/huoran/iasf/entity/UserDept.java
  26. 9
      src/main/java/com/huoran/iasf/mapper/SysUserMapper.java
  27. 16
      src/main/java/com/huoran/iasf/mapper/UserDeptMapper.java
  28. 149
      src/main/java/com/huoran/iasf/mapper/xml/SysUserMapper.xml
  29. 5
      src/main/java/com/huoran/iasf/mapper/xml/UserDeptMapper.xml
  30. 6
      src/main/java/com/huoran/iasf/service/DeptService.java
  31. 54
      src/main/java/com/huoran/iasf/service/HttpSessionService.java
  32. 2
      src/main/java/com/huoran/iasf/service/RedisService.java
  33. 10
      src/main/java/com/huoran/iasf/service/RoleService.java
  34. 16
      src/main/java/com/huoran/iasf/service/SysRoleDeptService.java
  35. 16
      src/main/java/com/huoran/iasf/service/UserDeptService.java
  36. 20
      src/main/java/com/huoran/iasf/service/UserService.java
  37. 41
      src/main/java/com/huoran/iasf/service/impl/DeptServiceImpl.java
  38. 58
      src/main/java/com/huoran/iasf/service/impl/HomeServiceImpl.java
  39. 8
      src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java
  40. 47
      src/main/java/com/huoran/iasf/service/impl/RoleServiceImpl.java
  41. 3
      src/main/java/com/huoran/iasf/service/impl/SysDictDetailServiceImpl.java
  42. 5
      src/main/java/com/huoran/iasf/service/impl/SysFilesServiceImpl.java
  43. 6
      src/main/java/com/huoran/iasf/service/impl/SysGeneratorServiceImpl.java
  44. 4
      src/main/java/com/huoran/iasf/service/impl/SysRoleDeptServiceImpl.java
  45. 20
      src/main/java/com/huoran/iasf/service/impl/UserDeptServiceImpl.java
  46. 700
      src/main/java/com/huoran/iasf/service/impl/UserServiceImpl.java
  47. 55
      src/main/java/com/huoran/iasf/vo/ImportUserFailureVo.java
  48. 45
      src/main/java/com/huoran/iasf/vo/req/ExcelImpUserReq.java
  49. 28
      src/main/java/com/huoran/iasf/vo/req/UserListReq.java
  50. 18
      src/main/java/com/huoran/iasf/vo/resp/DeptRespNodeVO.java
  51. 3
      src/main/java/com/huoran/iasf/vo/resp/PermissionRespNode.java
  52. 65
      src/main/java/com/huoran/iasf/vo/resp/UserListResp.java
  53. 2
      src/test/java/com/company/project/CodeGenerator.java

@ -30,6 +30,11 @@
<fastjson.version>1.2.74</fastjson.version> <fastjson.version>1.2.74</fastjson.version>
<knife4j.version>2.0.2</knife4j.version> <knife4j.version>2.0.2</knife4j.version>
<easy-captcha.version>1.6.2</easy-captcha.version> <easy-captcha.version>1.6.2</easy-captcha.version>
<poi.version>4.0.1</poi.version>
<poi-ooxml.version>4.0.1</poi-ooxml.version>
<easypoi-base.version>4.1.3</easypoi-base.version>
<easypoi-web.version>4.1.3</easypoi-web.version>
<easypoi-annotation.version>4.1.3</easypoi-annotation.version>
</properties> </properties>
<dependencies> <dependencies>
@ -50,11 +55,11 @@
</dependency> </dependency>
<!--数据源--> <!--数据源-->
<dependency> <!-- <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId> <artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.version}</version> <version>${druid.version}</version>
</dependency> </dependency>-->
<!--redis 依赖--> <!--redis 依赖-->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
@ -173,6 +178,50 @@
<version>5.3.6</version> <version>5.3.6</version>
</dependency> </dependency>
<!-- Easy poi-->
<!-- excle导入导出依赖包 start -->
<!-- excel文件导入导出 -->
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>${easypoi-base.version}</version>
<exclusions>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
<exclusion>
<artifactId>poi-ooxml-schemas</artifactId>
<groupId>org.apache.poi</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>${easypoi-web.version}</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>${easypoi-annotation.version}</version>
</dependency>
<!-- excle导入导出依赖包 end -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi-ooxml.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

@ -1,6 +1,5 @@
package com.huoran.iasf; package com.huoran.iasf;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
@ -11,7 +10,7 @@ import org.springframework.core.env.Environment;
import java.net.InetAddress; import java.net.InetAddress;
@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class) @SpringBootApplication
@MapperScan("com.huoran.iasf.mapper") @MapperScan("com.huoran.iasf.mapper")
@Slf4j @Slf4j
@ServletComponentScan(basePackages = {"com.huoran.iasf.common.filter"}) //这一句完成了配置,Springboot的”懒理念“真的厉害。 @ServletComponentScan(basePackages = {"com.huoran.iasf.common.filter"}) //这一句完成了配置,Springboot的”懒理念“真的厉害。

@ -3,10 +3,11 @@ package com.huoran.iasf.common.aop.aspect;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huoran.iasf.common.exception.BusinessException; import com.huoran.iasf.common.exception.BusinessException;
import com.huoran.iasf.common.exception.code.BaseResponseCode;
import com.huoran.iasf.common.utils.Constant; import com.huoran.iasf.common.utils.Constant;
import com.huoran.iasf.entity.SysRole; import com.huoran.iasf.entity.SysRole;
import com.huoran.iasf.entity.SysUser;
import com.huoran.iasf.service.HttpSessionService; import com.huoran.iasf.service.HttpSessionService;
import org.apache.commons.lang.StringUtils;
import org.aspectj.lang.JoinPoint; import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Before;
@ -17,7 +18,6 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -38,8 +38,6 @@ public class DataScopeAspect {
@Resource @Resource
com.huoran.iasf.service.RoleService roleService; com.huoran.iasf.service.RoleService roleService;
@Resource @Resource
com.huoran.iasf.service.SysRoleDeptService sysRoleDeptService;
@Resource
com.huoran.iasf.service.DeptService deptService; com.huoran.iasf.service.DeptService deptService;
@Resource @Resource
com.huoran.iasf.service.UserService userService; com.huoran.iasf.service.UserService userService;
@ -90,15 +88,15 @@ public class DataScopeAspect {
*/ */
private List<String> getUserIdsByRoles(List<com.huoran.iasf.entity.SysRole> sysRoles, String userId) { private List<String> getUserIdsByRoles(List<com.huoran.iasf.entity.SysRole> sysRoles, String userId) {
//本人 //本人
com.huoran.iasf.entity.SysUser sysUser = userService.getById(userId); SysUser sysUser = userService.getById(userId);
//本部门 //本部门
com.huoran.iasf.entity.SysDept sysDept = deptService.getById(sysUser.getDeptId()); // SysDept sysDept = deptService.getById(sysUser.getDeptId());
//部门ids, 定义哪些部门最终拥有权限查看 //部门ids, 定义哪些部门最终拥有权限查看
LinkedList<Object> deptList = new LinkedList<>(); LinkedList<Object> deptList = new LinkedList<>();
//用户ids,定义列表中哪些人创建的可查看 //用户ids,定义列表中哪些人创建的可查看
LinkedList<Object> userIdList = new LinkedList<>(); LinkedList<Object> userIdList = new LinkedList<>();
//根据数据权限范围分组, 不同的数据范围不同的逻辑处理 //根据数据权限范围分组, 不同的数据范围不同的逻辑处理
Map<Integer, List<com.huoran.iasf.entity.SysRole>> dataScopeMap = sysRoles.parallelStream().collect(Collectors.groupingBy(com.huoran.iasf.entity.SysRole::getDataScope)); /*Map<Integer, List<SysRole>> dataScopeMap = sysRoles.parallelStream().collect(Collectors.groupingBy(com.huoran.iasf.entity.SysRole::getDataScope));
dataScopeMap.forEach((k, v) -> { dataScopeMap.forEach((k, v) -> {
if (Constant.DATA_SCOPE_CUSTOM.equals(k)) { if (Constant.DATA_SCOPE_CUSTOM.equals(k)) {
//自定义 //自定义
@ -121,14 +119,14 @@ public class DataScopeAspect {
//自己 //自己
userIdList.add(userId); userIdList.add(userId);
} }
}); });*/
if (!CollectionUtils.isEmpty(deptList)) { if (!CollectionUtils.isEmpty(deptList)) {
QueryWrapper<com.huoran.iasf.entity.SysUser> queryWrapper = Wrappers.<com.huoran.iasf.entity.SysUser>query().select("id").in("dept_id", deptList); QueryWrapper<com.huoran.iasf.entity.SysUser> queryWrapper = Wrappers.<com.huoran.iasf.entity.SysUser>query().select("id").in("dept_id", deptList);
userIdList.addAll(userService.listObjs(queryWrapper)); userIdList.addAll(userService.listObjs(queryWrapper));
} }
//如果配置了角色数据范围, 最终没有查到userId, 那么返回无数据 //如果配置了角色数据范围, 最终没有查到userId, 那么返回无数据
if (CollectionUtils.isEmpty(userIdList)) { if (CollectionUtils.isEmpty(userIdList)) {
throw new BusinessException("无数据"); throw new BusinessException(BaseResponseCode.NOT_ACCOUNT);
} }
return userIdList.parallelStream().map(Object::toString).collect(Collectors.toList()); return userIdList.parallelStream().map(Object::toString).collect(Collectors.toList());
} }

@ -105,7 +105,8 @@ public class WebMvcConfigurer extends WebMvcConfigurationSupport {
WebMvcConfigurer.super.addCorsMappings(registry); WebMvcConfigurer.super.addCorsMappings(registry);
registry.addMapping("/**") registry.addMapping("/**")
.allowedHeaders("*") .allowedHeaders("*")
.allowedMethods("POST", "GET", "PUT", "DELETE") .allowCredentials(true)
.allowedMethods("*")
.allowedOrigins("*"); .allowedOrigins("*");
} }

@ -1,7 +1,9 @@
package com.huoran.iasf.common.exception; package com.huoran.iasf.common.exception;
import com.huoran.iasf.common.exception.code.BaseResponseCode; import com.huoran.iasf.common.exception.code.BaseResponseCode;
import com.huoran.iasf.common.exception.code.ResponseCodeInterface; import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
/** /**
* BusinessException * BusinessException
@ -10,44 +12,9 @@ import com.huoran.iasf.common.exception.code.ResponseCodeInterface;
* @version V1.0 * @version V1.0
* @date 2022年7月28日 * @date 2022年7月28日
*/ */
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class BusinessException extends RuntimeException { public class BusinessException extends RuntimeException {
private BaseResponseCode baseResponseCode;
/**
* 异常编号
*/
private final int messageCode;
/**
* 对messageCode 异常信息进行补充说明
*/
private final String detailMessage;
public BusinessException(int messageCode, String message) {
super(message);
this.messageCode = messageCode;
this.detailMessage = message;
}
public BusinessException(String message) {
super(message);
this.messageCode = BaseResponseCode.OPERATION_ERROR.getCode();
this.detailMessage = message;
}
/**
* 构造函数
*
* @param code 异常码
*/
public BusinessException(ResponseCodeInterface code) {
this(code.getCode(), code.getMsg());
}
public int getMessageCode() {
return messageCode;
}
public String getDetailMessage() {
return detailMessage;
}
} }

@ -1,5 +1,9 @@
package com.huoran.iasf.common.exception.code; package com.huoran.iasf.common.exception.code;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
/** /**
* 错误码 * 错误码
@ -8,14 +12,29 @@ package com.huoran.iasf.common.exception.code;
* @version V1.0 * @version V1.0
* @date 2022年7月28日 * @date 2022年7月28日
*/ */
@Getter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public enum BaseResponseCode implements ResponseCodeInterface { public enum BaseResponseCode implements ResponseCodeInterface {
/** /**
* 错误码 * 错误码
*/ */
SUCCESS(200, "success"), USERNAME_EXISTS(10008, "用户名已存在!"),
SYSTEM_BUSY(10001, "系统繁忙,请稍候再试"), KEY_OR_TOMEUNIT(10009, "key or TomeUnit 不能为空!"),
DICTIONARY_DATA_FAILED(10010, "获取字典数据失败"),
UPLOAD_EMPTY(10011, "上传内容为空"),
UPLOAD_FAILED(10012, "上传失败"),
VERIFICATION_CODE_ERROR(10007, "验证码错误!"),
VERIFICATION_CODE_EXPIRED(10006, "验证码已过期!"),
CANNOT_SAME(10005, "新密码不能与旧密码相同!"),
EXCEL_FILE_INVALID(10004, "上传excel文件错误!"),
VALID_EXCEPTION(10003, "参数格式校验异常!"),
OPERATION_ERROR(10002, "操作失败"), OPERATION_ERROR(10002, "操作失败"),
SYSTEM_BUSY(10001, "系统繁忙,请稍候再试"),
SUCCESS(200, "success"),
EXCEL_FILE_FORMAT_ERROR(40007, "请根据模板使用说明录入正确的用户信息!"),
TOKEN_ERROR(401001, "登录凭证已过期,请重新登录"), TOKEN_ERROR(401001, "登录凭证已过期,请重新登录"),
DATA_ERROR(401003, "传入数据异常"), DATA_ERROR(401003, "传入数据异常"),
NOT_ACCOUNT(401004, "该用户不存在,请先注册"), NOT_ACCOUNT(401004, "该用户不存在,请先注册"),
@ -31,29 +50,16 @@ public enum BaseResponseCode implements ResponseCodeInterface {
OPERATION_MENU_PERMISSION_BTN_ERROR(401013, "操作后的菜单类型是按钮,所属菜单必须为菜单类型"), OPERATION_MENU_PERMISSION_BTN_ERROR(401013, "操作后的菜单类型是按钮,所属菜单必须为菜单类型"),
OPERATION_MENU_PERMISSION_URL_NOT_NULL(401015, "菜单权限的url不能为空"), OPERATION_MENU_PERMISSION_URL_NOT_NULL(401015, "菜单权限的url不能为空"),
OPERATION_MENU_PERMISSION_URL_PERMS_NULL(401016, "菜单权限的标识符不能为空"), OPERATION_MENU_PERMISSION_URL_PERMS_NULL(401016, "菜单权限的标识符不能为空"),
EXCEL_FILE_NULL(40006, "导入失败,导入数据为空!")
; ;
/** /**
* 错误码 * 错误码
*/ */
private final int code; private int code;
/** /**
* 错误消息 * 错误消息
*/ */
private final String msg; private String msg;
BaseResponseCode(int code, String msg) {
this.code = code;
this.msg = msg;
}
@Override
public int getCode() {
return code;
}
@Override
public String getMsg() {
return msg;
}
} }

@ -1,19 +1,21 @@
package com.huoran.iasf.common.exception.handler; package com.huoran.iasf.common.exception.handler;
import com.google.common.collect.Maps;
import com.huoran.iasf.common.exception.BusinessException; import com.huoran.iasf.common.exception.BusinessException;
import com.huoran.iasf.common.exception.code.BaseResponseCode; import com.huoran.iasf.common.exception.code.BaseResponseCode;
import com.huoran.iasf.common.utils.R; import com.huoran.iasf.common.utils.R;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.AuthorizationException; import org.apache.shiro.authz.AuthorizationException;
import org.springframework.validation.ObjectError; import org.springframework.validation.BindingResult;
import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException; import javax.validation.ConstraintViolationException;
import java.util.List; import java.util.HashMap;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
/** /**
* RestExceptionHandler * RestExceptionHandler
@ -41,8 +43,8 @@ public class RestExceptionHandler {
@ExceptionHandler(value = BusinessException.class) @ExceptionHandler(value = BusinessException.class)
R businessExceptionHandler(BusinessException e) { R businessExceptionHandler(BusinessException e) {
log.error("Exception,exception:{}", e, e); log.error("Exception,exception:{}", e, e);
BaseResponseCode em = e.getBaseResponseCode();
return new R(e.getMessageCode(), e.getMessage()); return new R(em.getCode(), em.getMsg());
} }
/** /**
@ -56,13 +58,19 @@ public class RestExceptionHandler {
} }
/** /**
* 处理validation 框架异常 * 处理参数格式校验异常
*/ */
@ExceptionHandler(MethodArgumentNotValidException.class) @ExceptionHandler(value = MethodArgumentNotValidException.class)
R methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) { public R handleValidException(MethodArgumentNotValidException e){
log.error("methodArgumentNotValidExceptionHandler bindingResult.allErrors():{},exception:{}", e.getBindingResult().getAllErrors(), e); log.error("参数格式校验异常");
List<ObjectError> errors = e.getBindingResult().getAllErrors(); BindingResult bindingResult = e.getBindingResult();
return R.getResult(BaseResponseCode.METHOD_ARGUMENT_NOT_VALID_EXCEPTION.getCode(), errors.get(0).getDefaultMessage()); HashMap<String, String> errorMap = Maps.newHashMap();
AtomicReference<String> errorMsg = new AtomicReference<>("");
bindingResult.getFieldErrors().forEach(fieldError -> {
errorMsg.set(fieldError.getDefaultMessage());
errorMap.put(fieldError.getField(),fieldError.getDefaultMessage());
});
return R.fail(errorMsg);
} }
/** /**

@ -59,30 +59,30 @@ public class CustomAccessControlFilter extends AccessControlFilter {
UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(token, token); UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(token, token);
getSubject(servletRequest, servletResponse).login(usernamePasswordToken); getSubject(servletRequest, servletResponse).login(usernamePasswordToken);
} catch (BusinessException exception) { } catch (BusinessException exception) {
if (HttpContextUtils.isAjaxRequest(request)) { /* if (HttpContextUtils.isAjaxRequest(request)) {
customResponse(exception.getMessageCode(), exception.getDetailMessage(), servletResponse); customResponse(exception.getBaseResponseCode(), exception.getMessage(), servletResponse);
} else if (exception.getMessageCode() == BaseResponseCode.TOKEN_ERROR.getCode()) { } else if (exception.getMessageCode() == BaseResponseCode.TOKEN_ERROR.getCode()) {
servletRequest.getRequestDispatcher("/index/login").forward(servletRequest, servletResponse); servletRequest.getRequestDispatcher("/index/login").forward(servletRequest, servletResponse);
} else if (exception.getMessageCode() == BaseResponseCode.UNAUTHORIZED_ERROR.getCode()) { } else if (exception.getMessageCode() == BaseResponseCode.UNAUTHORIZED_ERROR.getCode()) {
servletRequest.getRequestDispatcher("/index/403").forward(servletRequest, servletResponse); servletRequest.getRequestDispatcher("/index/403").forward(servletRequest, servletResponse);
} else { } else {
servletRequest.getRequestDispatcher("/index/500").forward(servletRequest, servletResponse); servletRequest.getRequestDispatcher("/index/500").forward(servletRequest, servletResponse);
} }*/
return false; return false;
} catch (AuthenticationException e) { } catch (AuthenticationException e) {
if (HttpContextUtils.isAjaxRequest(request)) { /*if (HttpContextUtils.isAjaxRequest(request)) {
if (e.getCause() instanceof BusinessException) { if (e.getCause() instanceof BusinessException) {
BusinessException exception = (BusinessException) e.getCause(); BusinessException exception = (BusinessException) e.getCause();
customResponse(exception.getMessageCode(), exception.getDetailMessage(), servletResponse); customResponse(exception.getBaseResponseCode(), exception.getMessage(), servletResponse);
} else { } else {
customResponse(BaseResponseCode.SYSTEM_BUSY.getCode(), BaseResponseCode.SYSTEM_BUSY.getMsg(), servletResponse); customResponse(BaseResponseCode.SYSTEM_BUSY.getCode(), BaseResponseCode.SYSTEM_BUSY.getMsg(), servletResponse);
} }
} else { } else {
servletRequest.getRequestDispatcher("/index/403").forward(servletRequest, servletResponse); servletRequest.getRequestDispatcher("/index/403").forward(servletRequest, servletResponse);
} }*/
return false; return false;
} catch (Exception e) { } catch (Exception e) {
if (HttpContextUtils.isAjaxRequest(request)) { /*if (HttpContextUtils.isAjaxRequest(request)) {
if (e.getCause() instanceof BusinessException) { if (e.getCause() instanceof BusinessException) {
BusinessException exception = (BusinessException) e.getCause(); BusinessException exception = (BusinessException) e.getCause();
customResponse(exception.getMessageCode(), exception.getDetailMessage(), servletResponse); customResponse(exception.getMessageCode(), exception.getDetailMessage(), servletResponse);
@ -91,7 +91,7 @@ public class CustomAccessControlFilter extends AccessControlFilter {
} }
} else { } else {
servletRequest.getRequestDispatcher("/index/500").forward(servletRequest, servletResponse); servletRequest.getRequestDispatcher("/index/500").forward(servletRequest, servletResponse);
} }*/
return false; return false;
} }
return true; return true;

@ -0,0 +1,25 @@
package com.huoran.iasf.common.utils;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ExcelAttribute {
/**
* 对应的列名称
*/
String name() default "";
/**
* excel列的索引
*/
int sort();
/**
* 字段类型对应的格式
*/
String format() default "";
}

@ -0,0 +1,183 @@
package com.huoran.iasf.common.utils;
import com.huoran.iasf.common.exception.BusinessException;
import com.huoran.iasf.common.exception.code.BaseResponseCode;
import com.huoran.iasf.vo.req.ExcelImpUserReq;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class ExcelImportHelper {
//判断row是否为空
public static boolean isRowEmpty(Row row) {
if (null == row) {
return true;
}
int firstCellNum = row.getFirstCellNum(); //第一个列位置
int lastCellNum = row.getLastCellNum(); //最后一列位置
int nullCellNum = 0; //空列数量
for (int c = firstCellNum; c < lastCellNum; c++) {
Cell cell = row.getCell(c);
if (null == cell || CellType.BLANK == cell.getCellType()) {
nullCellNum++;
continue;
}
cell.setCellType(CellType.STRING);
String cellValue = cell.getStringCellValue().trim();
if (StringUtils.isEmpty(cellValue)) {
nullCellNum++;
}
}
//所有列都为空
if (nullCellNum == (lastCellNum - firstCellNum)) {
return true;
}
return false;
}
private static Workbook getWorkbook(MultipartFile file) {
String fileName = file.getOriginalFilename();
Workbook workbook = null;
if (fileName.endsWith("xlsx")) {
try {
workbook = new XSSFWorkbook(file.getInputStream());
} catch (IOException e) {
e.printStackTrace();
}
} else if (fileName.endsWith("xls")) {
try {
workbook = new HSSFWorkbook(file.getInputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
return workbook;
}
/**
* @Description : 读取文件数据
* @Param file
* @Author Rong---2021/10/15
*/
public static List<ExcelImpUserReq> readUser(MultipartFile file) {
List<ExcelImpUserReq> list = new ArrayList<>();
Workbook workbook = getWorkbook(file);
ExcelImpUserReq excelImpUserReq = null;
// 循环工作表Sheet
for (int numSheet = 0; numSheet < workbook.getNumberOfSheets(); numSheet++) {
Sheet hssfSheet = workbook.getSheetAt(numSheet);
if (hssfSheet == null) {
continue;
}
int count = 1;
// 循环行Row//开始行2
for (int rowNum = 2; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
Row row = hssfSheet.getRow(rowNum);
if (isRowEmpty(row)) {
count++;
if (count == hssfSheet.getLastRowNum()) {
throw new BusinessException(BaseResponseCode.EXCEL_FILE_NULL);
}
continue;
}
Cell realName;//姓名
Cell userName;//账号
Cell jobNumber;//工号
Cell dept;//所在部门
Cell roleName;//角色
Cell phone;//手机号
Cell email;//邮箱
Cell groupName;//用户组
if (row != null) {
excelImpUserReq = new ExcelImpUserReq();
if (row.getCell(7) != null) {
row.getCell(7).setCellType(CellType.STRING);
groupName = row.getCell(7);
} else {
groupName = row.createCell(7);
}
if (row.getCell(6) != null) {
row.getCell(6).setCellType(CellType.STRING);
email = row.getCell(6);
} else {
email = row.createCell(6);
}
if (row.getCell(5) != null) {
row.getCell(5).setCellType(CellType.STRING);
phone = row.getCell(5);
} else {
phone = row.createCell(5);
}
if (row.getCell(4) != null) {
row.getCell(4).setCellType(CellType.STRING);
dept = row.getCell(4);
} else {
dept = row.createCell(4);
}
if (row.getCell(3) != null) {
row.getCell(3).setCellType(CellType.STRING);
jobNumber = row.getCell(3);
} else {
jobNumber = row.createCell(3);
}
if (row.getCell(2) != null) {
row.getCell(2).setCellType(CellType.STRING);
roleName = row.getCell(2);
} else {
roleName = row.createCell(3);
}
if (row.getCell(1) != null) {
row.getCell(1).setCellType(CellType.STRING);
userName = row.getCell(1);
} else {
userName = row.createCell(1);
}
if (row.getCell(0) != null) {
row.getCell(0).setCellType(CellType.STRING);
realName = row.getCell(0);
} else {
realName = row.createCell(0);
}
excelImpUserReq.setRealName(realName.getStringCellValue());
excelImpUserReq.setUserName(userName.getStringCellValue());
excelImpUserReq.setJobNumber(jobNumber.getStringCellValue());
excelImpUserReq.setDept(dept.getStringCellValue());
excelImpUserReq.setRoleName(roleName.getStringCellValue());
excelImpUserReq.setPhone(phone.getStringCellValue());
excelImpUserReq.setEmail(email.getStringCellValue());
excelImpUserReq.setGroupName(groupName.getStringCellValue());
list.add(excelImpUserReq);
}
}
}
return list;
}
}

@ -0,0 +1,187 @@
package com.huoran.iasf.common.utils;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.excel.entity.params.ExcelForEachParams;
import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler;
import org.apache.poi.ss.usermodel.*;
/**
* @ProjectName: huorantech
* @Package: com.huoran.common.utils
* @ClassName: ExcelStyleUtil
* @Description: easy poi导出设置样式
* @Author: Maureen.Rong
* @CreateDate: 2021/9/1 14:29
* @UpdateDate: 2021/9/1 14:29
* @Version: 1.0
*/
public class ExcelStyleUtil implements IExcelExportStyler {
private static final short STRING_FORMAT = (short) BuiltinFormats.getBuiltinFormat("TEXT");
private static final short FONT_SIZE_TEN = 9;
private static final short FONT_SIZE_ELEVEN = 10;
private static final short FONT_SIZE_TWELVE = 50;
/**
* 大标题样式
*/
private CellStyle headerStyle;
/**
* 每列标题样式
*/
private CellStyle titleStyle;
/**
* 数据行样式
*/
private CellStyle styles;
public ExcelStyleUtil(Workbook workbook) {
this.init(workbook);
}
/**
* 初始化样式
*
* @param workbook
*/
private void init(Workbook workbook) {
this.headerStyle = initHeaderStyle(workbook);
this.titleStyle = initTitleStyle(workbook);
this.styles = initStyles(workbook);
}
/**
* 大标题样式
*
* @param color
* @return
*/
@Override
public CellStyle getHeaderStyle(short color) {
return headerStyle;
}
/**
* 每列标题样式
*
* @param color
* @return
*/
@Override
public CellStyle getTitleStyle(short color) {
return titleStyle;
}
/**
* 数据行样式
*
* @param parity 可以用来表示奇偶行
* @param entity 数据内容
* @return 样式
*/
@Override
public CellStyle getStyles(boolean parity, ExcelExportEntity entity) {
return styles;
}
/**
* 获取样式方法
*
* @param dataRow 数据行
* @param obj 对象
* @param data 数据
*/
@Override
public CellStyle getStyles(Cell cell, int dataRow, ExcelExportEntity entity, Object obj, Object data) {
return getStyles(true, entity);
}
/**
* 模板使用的样式设置
*/
@Override
public CellStyle getTemplateStyles(boolean isSingle, ExcelForEachParams excelForEachParams) {
return null;
}
/**
* 初始化--大标题样式
*
* @param workbook
* @return
*/
private CellStyle initHeaderStyle(Workbook workbook) {
CellStyle style = getBaseCellStyle(workbook);
style.setFont(getFont(workbook, FONT_SIZE_TWELVE, true));
return style;
}
/**
* 初始化--每列标题样式
*
* @param workbook
* @return
*/
private CellStyle initTitleStyle(Workbook workbook) {
CellStyle style = getBaseCellStyle(workbook);
style.setFont(getFont(workbook, FONT_SIZE_ELEVEN, false));
//背景色
style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
return style;
}
/**
* 初始化--数据行样式
*
* @param workbook
* @return
*/
private CellStyle initStyles(Workbook workbook) {
CellStyle style = getBaseCellStyle(workbook);
style.setFont(getFont(workbook, FONT_SIZE_TEN, false));
style.setDataFormat(STRING_FORMAT);
return style;
}
/**
* 基础样式
*
* @return
*/
private CellStyle getBaseCellStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
//下边框
style.setBorderBottom(BorderStyle.THIN);
//左边框
style.setBorderLeft(BorderStyle.THIN);
//上边框
style.setBorderTop(BorderStyle.THIN);
//右边框
style.setBorderRight(BorderStyle.THIN);
//水平居中
style.setAlignment(HorizontalAlignment.CENTER);
//上下居中
style.setVerticalAlignment(VerticalAlignment.CENTER);
//设置自动换行
style.setWrapText(true);
return style;
}
/**
* 字体样式
*
* @param size 字体大小
* @param isBold 是否加粗
* @return
*/
private Font getFont(Workbook workbook, short size, boolean isBold) {
Font font = workbook.createFont();
//字体样式
font.setFontName("宋体");
//是否加粗
font.setBold(isBold);
//字体大小
font.setFontHeightInPoints(size);
return font;
}
}

@ -1,24 +1,10 @@
package com.huoran.iasf.common.utils; package com.huoran.iasf.common.utils;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.huoran.iasf.common.exception.BusinessException;
import com.huoran.iasf.entity.ColumnEntity;
import com.huoran.iasf.entity.TableEntity;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import java.io.File; import java.io.File;
import java.io.IOException; import java.util.ArrayList;
import java.io.StringWriter; import java.util.List;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/** /**
* 代码生成器 工具类 * 代码生成器 工具类
@ -46,7 +32,7 @@ public class GenUtils {
/** /**
* 生成代码 * 生成代码
*/ */
public static void generatorCode(Map<String, String> table, /*public static void generatorCode(Map<String, String> table,
List<Map<String, String>> columns, ZipOutputStream zip) { List<Map<String, String>> columns, ZipOutputStream zip) {
//配置信息 //配置信息
Configuration config = getConfig(); Configuration config = getConfig();
@ -144,10 +130,10 @@ public class GenUtils {
IOUtils.closeQuietly(sw); IOUtils.closeQuietly(sw);
zip.closeEntry(); zip.closeEntry();
} catch (IOException e) { } catch (IOException e) {
throw new BusinessException("渲染模板失败,表名:" + tableEntity.getTableName()); // throw new BusinessException("渲染模板失败,表名:" + tableEntity.getTableName());
}
} }
} }
}*/
/** /**
@ -184,13 +170,13 @@ public class GenUtils {
/** /**
* 获取配置信息 * 获取配置信息
*/ */
public static Configuration getConfig() { /* public static Configuration getConfig() {
try { try {
return new PropertiesConfiguration("generator.properties"); return new PropertiesConfiguration("generator.properties");
} catch (ConfigurationException e) { } catch (ConfigurationException e) {
throw new BusinessException("获取配置文件失败"); throw new BusinessException("获取配置文件失败");
} }
} }*/
/** /**
* 获取文件名 * 获取文件名

@ -15,8 +15,6 @@ import lombok.Data;
@Data @Data
public class R { public class R {
/** /**
* 请求响应code0为成功 其他为失败 * 请求响应code0为成功 其他为失败
*/ */
@ -95,6 +93,11 @@ public class R {
return new R(BaseResponseCode.OPERATION_ERROR.getCode(), msg); return new R(BaseResponseCode.OPERATION_ERROR.getCode(), msg);
} }
public static R fail(Object data) {
return new R(data);
}
/** /**
* 自定义返回 data为null * 自定义返回 data为null
*/ */

@ -2,44 +2,38 @@ package com.huoran.iasf.common.utils;
import com.huoran.iasf.common.exception.BusinessException; import com.huoran.iasf.common.exception.BusinessException;
import org.apache.commons.lang.StringUtils;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import java.util.Set;
/** /**
* hibernate-validator校验工具类 * hibernate-validator校验工具类
* *
*/ */
public class ValidatorUtils { /*public class ValidatorUtils {
private static Validator validator; private static Validator validator;
static { static {
validator = Validation.buildDefaultValidatorFactory().getValidator(); validator = Validation.buildDefaultValidatorFactory().getValidator();
} }
/** *//**
* 校验对象 * 校验对象
* @param object 待校验对象 * @param object 待校验对象
* @param groups 待校验的组 * @param groups 待校验的组
* @throws BusinessException 校验不通过则报RRException异常 * @throws BusinessException 校验不通过则报RRException异常
*/ *//*
public static void validateEntity(Object object, Class<?>... groups) *//* public static void validateEntity(Object object, Class<?>... groups)
throws BusinessException { throws BusinessException {
Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object, groups); Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object, groups);
if (!constraintViolations.isEmpty()) { if (!constraintViolations.isEmpty()) {
ConstraintViolation<Object> constraint = (ConstraintViolation<Object>)constraintViolations.iterator().next(); ConstraintViolation<Object> constraint = (ConstraintViolation<Object>)constraintViolations.iterator().next();
throw new BusinessException(constraint.getMessage()); throw new BusinessException(constraint.getMessage());
} }
} }*//*
/** *//**
* 空判断处理 * 空判断处理
* @param str * @param str
* @param message * @param message
*/ *//*
public static void isBlank(Object str, String message) { public static void isBlank(Object str, String message) {
if (str == null) { if (str == null) {
throw new BusinessException(message); throw new BusinessException(message);
@ -50,4 +44,4 @@ public class ValidatorUtils {
} }
} }
} }
} }*/

@ -4,8 +4,10 @@ import com.huoran.iasf.common.aop.annotation.LogAnnotation;
import com.huoran.iasf.common.utils.R; import com.huoran.iasf.common.utils.R;
import com.huoran.iasf.entity.SysDept; import com.huoran.iasf.entity.SysDept;
import com.huoran.iasf.service.DeptService; import com.huoran.iasf.service.DeptService;
import com.huoran.iasf.vo.resp.DeptRespNodeVO;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -13,7 +15,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.List;
/** /**
* 部门管理 * 部门管理
@ -34,6 +35,10 @@ public class DeptController {
@LogAnnotation(title = "机构管理", action = "新增组织") @LogAnnotation(title = "机构管理", action = "新增组织")
@RequiresPermissions("sys:dept:add") @RequiresPermissions("sys:dept:add")
public R addDept(@RequestBody @Valid SysDept vo) { public R addDept(@RequestBody @Valid SysDept vo) {
boolean ok = deptService.checkDeptRepeat(vo);
if (ok) {
return R.fail("同级下已存在相同的名称:" + vo.getName());
}
deptService.addDept(vo); deptService.addDept(vo);
return R.success(); return R.success();
} }
@ -55,6 +60,10 @@ public class DeptController {
if (StringUtils.isEmpty(vo.getId())) { if (StringUtils.isEmpty(vo.getId())) {
return R.fail("id不能为空"); return R.fail("id不能为空");
} }
boolean ok = deptService.checkDeptRepeat(vo);
if (ok) {
return R.fail("同级下已存在相同的名称:" + vo.getName());
}
deptService.updateDept(vo); deptService.updateDept(vo);
return R.success(); return R.success();
} }
@ -68,14 +77,16 @@ public class DeptController {
} }
@GetMapping("/dept/tree") @GetMapping("/dept/tree")
@ApiOperation(value = "树型组织列表接口") @ApiOperation(value = "树型组织列表接口",response = DeptRespNodeVO.class)
@LogAnnotation(title = "机构管理", action = "树型组织列表") @LogAnnotation(title = "部门管理", action = "树型组织列表")
@RequiresPermissions(value = {"sys:user:list", "sys:user:update", "sys:user:add", "sys:dept:add", "sys:dept:update"}, logical = Logical.OR) @RequiresPermissions(value = {"sys:user:list", "sys:user:update", "sys:user:add", "sys:dept:add", "sys:dept:update"}, logical = Logical.OR)
public R getTree(@RequestParam(required = false) String deptId) { public R getTree(
return R.success(deptService.deptTreeList(deptId, false)); @ApiParam(name = "deptId", value = "部门id",required = false)
@RequestParam(required = false) String deptId) {
return R.success(deptService.deptTreeList(deptId));
} }
@GetMapping("/depts") /* @GetMapping("/depts")
@ApiOperation(value = "获取机构列表接口") @ApiOperation(value = "获取机构列表接口")
@LogAnnotation(title = "机构管理", action = "获取所有组织机构") @LogAnnotation(title = "机构管理", action = "获取所有组织机构")
@RequiresPermissions("sys:dept:list") @RequiresPermissions("sys:dept:list")
@ -88,6 +99,6 @@ public class DeptController {
} }
}); });
return R.success(deptList); return R.success(deptList);
} }*/
} }

@ -77,24 +77,23 @@ public class PermissionController {
@RequiresPermissions("sys:permission:detail") @RequiresPermissions("sys:permission:detail")
public R detailInfo(@PathVariable("id") String id) { public R detailInfo(@PathVariable("id") String id) {
return R.success(permissionService.getById(id)); return R.success(permissionService.getById(id));
} }
@GetMapping("/permissions") /*@GetMapping("/permissions")
@ApiOperation(value = "获取所有菜单权限接口") @ApiOperation(value = "获取所有菜单权限接口")
@LogAnnotation(title = "菜单权限管理", action = "获取所有菜单权限") @LogAnnotation(title = "菜单权限管理", action = "获取所有菜单权限")
@RequiresPermissions("sys:permission:list") @RequiresPermissions("sys:permission:list")
public R getAllMenusPermission() { public R getAllMenusPermission() {
return R.success(permissionService.selectAll()); return R.success(permissionService.selectAll());
} }*/
@GetMapping("/permission/tree") /* @GetMapping("/permission/tree")
@ApiOperation(value = "获取所有目录菜单树接口") @ApiOperation(value = "获取所有目录菜单树接口")
@LogAnnotation(title = "菜单权限管理", action = "获取所有目录菜单树") @LogAnnotation(title = "菜单权限管理", action = "获取所有目录菜单树")
@RequiresPermissions(value = {"sys:permission:update", "sys:permission:add"}, logical = Logical.OR) @RequiresPermissions(value = {"sys:permission:update", "sys:permission:add"}, logical = Logical.OR)
public R getAllMenusPermissionTree(@RequestParam(required = false) String permissionId) { public R getAllMenusPermissionTree(@RequestParam(required = false) String permissionId) {
return R.success(permissionService.selectAllMenuByTree(permissionId)); return R.success(permissionService.selectAllMenuByTree(permissionId));
} }*/
@GetMapping("/permission/tree/all") @GetMapping("/permission/tree/all")
@ApiOperation(value = "获取所有目录菜单树接口") @ApiOperation(value = "获取所有目录菜单树接口")

@ -1,13 +1,16 @@
package com.huoran.iasf.controller; package com.huoran.iasf.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huoran.iasf.common.aop.annotation.LogAnnotation; import com.huoran.iasf.common.aop.annotation.LogAnnotation;
import com.huoran.iasf.common.utils.R; import com.huoran.iasf.common.utils.R;
import com.huoran.iasf.entity.SysRole; import com.huoran.iasf.entity.SysRole;
import com.huoran.iasf.entity.SysRoleDeptEntity; import com.huoran.iasf.entity.SysRolePermission;
import com.huoran.iasf.service.HttpSessionService;
import com.huoran.iasf.service.RolePermissionService;
import com.huoran.iasf.service.RoleService; import com.huoran.iasf.service.RoleService;
import com.huoran.iasf.service.SysRoleDeptService; import com.huoran.iasf.vo.req.RolePermissionOperationReqVO;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
@ -18,6 +21,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
/** /**
@ -34,14 +38,30 @@ public class RoleController {
@Resource @Resource
private RoleService roleService; private RoleService roleService;
@Resource @Resource
private SysRoleDeptService sysRoleDeptService; private RolePermissionService rolePermissionService;
@Resource
private HttpSessionService httpSessionService;
@PostMapping("/role") @PostMapping("/role")
@ApiOperation(value = "新增角色接口") @ApiOperation(value = "新增角色接口")
@LogAnnotation(title = "角色管理", action = "新增角色") @LogAnnotation(title = "角色管理", action = "新增角色")
@RequiresPermissions("sys:role:add") @RequiresPermissions("sys:role:add")
public R addRole(@RequestBody @Valid SysRole vo) { public R addRole(@RequestBody @Valid SysRole vo) {
boolean ok = roleService.checkDeptRepeat(vo);
if (ok) {
return R.fail("已存在相同的角色名称:" + vo.getName());
}
roleService.addRole(vo); roleService.addRole(vo);
//删除角色权限关联
rolePermissionService.remove(Wrappers.<SysRolePermission>lambdaQuery().eq(SysRolePermission::getRoleId, vo.getId()));
if (!CollectionUtils.isEmpty(vo.getPermissions())) {
RolePermissionOperationReqVO reqVO = new RolePermissionOperationReqVO();
reqVO.setRoleId(vo.getId());
reqVO.setPermissionIds(vo.getPermissions());
rolePermissionService.addRolePermission(reqVO);
// 刷新权限
httpSessionService.refreshRolePermission(vo.getId());
}
return R.success(); return R.success();
} }
@ -62,39 +82,11 @@ public class RoleController {
if (StringUtils.isEmpty(vo.getId())) { if (StringUtils.isEmpty(vo.getId())) {
return R.fail("id不能为空"); return R.fail("id不能为空");
} }
roleService.updateRole(vo); boolean ok = roleService.checkDeptRepeat(vo);
return R.success(); if (ok) {
} return R.fail("已存在相同的角色名称:" + vo.getName());
@PostMapping("/role/bindDept")
@ApiOperation(value = "绑定角色部门接口")
@LogAnnotation(title = "角色管理", action = "绑定角色部门信息")
@RequiresPermissions("sys:role:bindDept")
public R bindDept(@RequestBody SysRole vo) {
if (StringUtils.isEmpty(vo.getId())) {
return R.fail("id不能为空");
} }
if (roleService.getById(vo.getId()) == null) { roleService.updateRole(vo);
return R.fail("获取角色失败");
}
//先删除所有绑定
sysRoleDeptService.remove(Wrappers.<SysRoleDeptEntity>lambdaQuery().eq(SysRoleDeptEntity::getRoleId, vo.getId()));
//如果不是自定义
if (vo.getDataScope() != 2) {
vo.setDepts(null);
}
if (!CollectionUtils.isEmpty(vo.getDepts())) {
List<SysRoleDeptEntity> list = new ArrayList<>();
for (String deptId : vo.getDepts()) {
SysRoleDeptEntity sysRoleDeptEntity = new SysRoleDeptEntity();
sysRoleDeptEntity.setDeptId(deptId);
sysRoleDeptEntity.setRoleId(vo.getId());
list.add(sysRoleDeptEntity);
}
sysRoleDeptService.saveBatch(list);
}
roleService.updateById(new SysRole().setId(vo.getId()).setDataScope(vo.getDataScope()));
return R.success(); return R.success();
} }
@ -103,7 +95,19 @@ public class RoleController {
@LogAnnotation(title = "角色管理", action = "查询角色详情") @LogAnnotation(title = "角色管理", action = "查询角色详情")
@RequiresPermissions("sys:role:detail") @RequiresPermissions("sys:role:detail")
public R detailInfo(@PathVariable("id") String id) { public R detailInfo(@PathVariable("id") String id) {
return R.success(roleService.detailInfo(id)); // return R.success(roleService.detailInfo(id));
SysRole role = roleService.getById(id);
QueryWrapper<SysRolePermission> wrapper = new QueryWrapper<>();
wrapper.eq("role_id", id).select("permission_id");
List<SysRolePermission> list = rolePermissionService.list(wrapper);
List<String> permissionList = new ArrayList<>();
list.forEach(rolePermission -> {
permissionList.add(rolePermission.getPermissionId());
});
HashMap<String, Object> map = new HashMap<>();
map.put("role", role);
map.put("permissionList", permissionList);
return R.success(map);
} }
@PostMapping("/roles") @PostMapping("/roles")
@ -116,15 +120,6 @@ public class RoleController {
if (!StringUtils.isEmpty(vo.getName())) { if (!StringUtils.isEmpty(vo.getName())) {
queryWrapper.like(SysRole::getName, vo.getName()); queryWrapper.like(SysRole::getName, vo.getName());
} }
/* if (!StringUtils.isEmpty(vo.getStartTime())) {
queryWrapper.gt(SysRole::getCreateTime, vo.getStartTime());
}
if (!StringUtils.isEmpty(vo.getEndTime())) {
queryWrapper.lt(SysRole::getCreateTime, vo.getEndTime());
}
if (!StringUtils.isEmpty(vo.getStatus())) {
queryWrapper.eq(SysRole::getStatus, vo.getStatus());
}*/
queryWrapper.orderByDesc(SysRole::getCreateTime); queryWrapper.orderByDesc(SysRole::getCreateTime);
return R.success(roleService.page(vo.getQueryPage(), queryWrapper)); return R.success(roleService.page(vo.getQueryPage(), queryWrapper));
} }

@ -5,11 +5,11 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huoran.iasf.common.aop.annotation.LogAnnotation; import com.huoran.iasf.common.aop.annotation.LogAnnotation;
import com.huoran.iasf.common.utils.R; import com.huoran.iasf.common.utils.R;
import com.huoran.iasf.entity.SysUser; import com.huoran.iasf.entity.SysUser;
import com.huoran.iasf.entity.SysUserRole;
import com.huoran.iasf.service.HttpSessionService; import com.huoran.iasf.service.HttpSessionService;
import com.huoran.iasf.service.UserRoleService; import com.huoran.iasf.service.UserRoleService;
import com.huoran.iasf.service.UserService; import com.huoran.iasf.service.UserService;
import com.huoran.iasf.vo.req.UserRoleOperationReqVO; import com.huoran.iasf.vo.req.UserListReq;
import com.huoran.iasf.vo.resp.UserListResp;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
@ -17,13 +17,17 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject; import org.apache.shiro.subject.Subject;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid; import javax.validation.Valid;
import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 用户管理 * 用户管理
@ -50,19 +54,14 @@ public class UserController {
return R.success(userService.login(vo)); return R.success(userService.login(vo));
} }
@PostMapping("/user/register") /* @PostMapping("/user/register")
@ApiOperation(value = "用户注册接口") @ApiOperation(value = "用户注册接口")
public R register(@RequestBody @Valid SysUser vo) { public R register(@RequestBody @Valid SysUser vo) {
userService.register(vo); userService.register(vo);
return R.success(); return R.success();
}
/*@GetMapping("/user/unLogin")
@ApiOperation(value = "引导客户端去登录")
public R unLogin() {
return R.getResult(BaseResponseCode.TOKEN_ERROR);
}*/ }*/
@PutMapping("/user") @PutMapping("/user")
@ApiOperation(value = "更新用户信息接口") @ApiOperation(value = "更新用户信息接口")
@LogAnnotation(title = "用户管理", action = "更新用户信息") @LogAnnotation(title = "用户管理", action = "更新用户信息")
@ -71,41 +70,26 @@ public class UserController {
if (StringUtils.isEmpty(vo.getId())) { if (StringUtils.isEmpty(vo.getId())) {
return R.fail("id不能为空"); return R.fail("id不能为空");
} }
userService.updateUserInfo(vo); userService.updateUserInfo(vo);
return R.success(); return R.success();
} }
@PutMapping("/user/info")
@ApiOperation(value = "更新用户信息接口")
@LogAnnotation(title = "用户管理", action = "更新用户信息")
public R updateUserInfoById(@RequestBody SysUser vo) {
userService.updateUserInfoMy(vo);
return R.success();
}
@GetMapping("/user/{id}") @GetMapping("/user/{id}")
@ApiOperation(value = "查询用户详情接口") @ApiOperation(value = "查询用户详情接口")
@LogAnnotation(title = "用户管理", action = "查询用户详情") @LogAnnotation(title = "用户管理", action = "查询用户详情")
@RequiresPermissions("sys:user:detail") @RequiresPermissions("sys:user:detail")
public R detailInfo(@PathVariable("id") String id) { public R detailInfo(@PathVariable("id") String id) {
return R.success(userService.getById(id)); UserListResp userResp = userService.detailInfo(id);
} return R.success(userResp);
@GetMapping("/user")
@ApiOperation(value = "查询用户详情接口")
@LogAnnotation(title = "用户管理", action = "查询用户详情")
public R youSelfInfo() {
String userId = httpSessionService.getCurrentUserId();
return R.success(userService.getById(userId));
} }
@PostMapping("/users") @PostMapping("/users")
@ApiOperation(value = "分页获取用户列表接口") @ApiOperation(value = "分页获取用户列表接口")
@RequiresPermissions("sys:user:list") @RequiresPermissions("sys:user:list")
@LogAnnotation(title = "用户管理", action = "分页获取用户列表") @LogAnnotation(title = "用户管理", action = "分页获取用户列表")
public R pageInfo(@RequestBody SysUser vo) { public R pageInfo(@RequestBody UserListReq userListReq) {
return R.success(userService.pageInfo(vo)); return userService.pageInfo(userListReq);
} }
@PostMapping("/user") @PostMapping("/user")
@ -117,6 +101,34 @@ public class UserController {
return R.success(); return R.success();
} }
@GetMapping("/checkJobNumber")
@ApiOperation(value = "工号验证")
// @LogAnnotation(title = "用户管理", action = "工号验证")
public R checkJobNumber(@RequestParam String jobNumber) {
SysUser sysUser = userService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getJobNumber, jobNumber));
if (sysUser != null) {
R.fail("工号已存在,请勿重复添加!");
}
return R.success();
}
@GetMapping("/checkUsername")
@ApiOperation(value = "账号验证")
// @LogAnnotation(title = "用户管理", action = "工号验证")
public R checkUsername(@RequestParam String userName) {
SysUser sysUser = userService.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, userName));
if (sysUser != null) {
R.fail("账号已存在,请勿重复添加!");
}
return R.success();
}
@ApiOperation(value = "密码重置", notes = "密码重置")
@GetMapping("/resetPwd")
public R resetPwd(@RequestParam("userId") String userId) {
return userService.resetPwd(userId);
}
@GetMapping("/user/logout") @GetMapping("/user/logout")
@ApiOperation(value = "退出接口") @ApiOperation(value = "退出接口")
@LogAnnotation(title = "用户管理", action = "退出") @LogAnnotation(title = "用户管理", action = "退出")
@ -153,7 +165,7 @@ public class UserController {
return R.success(); return R.success();
} }
@GetMapping("/user/roles/{userId}") /*@GetMapping("/user/roles/{userId}")
@ApiOperation(value = "赋予角色-获取所有角色接口") @ApiOperation(value = "赋予角色-获取所有角色接口")
@LogAnnotation(title = "用户管理", action = "赋予角色-获取所有角色接口") @LogAnnotation(title = "用户管理", action = "赋予角色-获取所有角色接口")
@RequiresPermissions("sys:user:role:detail") @RequiresPermissions("sys:user:role:detail")
@ -181,5 +193,22 @@ public class UserController {
//刷新权限 //刷新权限
httpSessionService.refreshUerId(userId); httpSessionService.refreshUerId(userId);
return R.success(); return R.success();
}*/
@PostMapping("/importStaff")
@ApiOperation("批量导入员工")
public R importStaff(@RequestParam(name = "file") MultipartFile file, HttpServletRequest request) throws IOException {
Map<String, String> map = userService.importStaff(file);
return R.success(map);
}
/**
* 批量导入员工失败数据导出
*/
@ApiOperation(value = "批量导入员工失败数据导出")
@GetMapping("/exportFailure")
public void exportFailureRecord(HttpServletResponse response, @ApiParam(name = "exportCode", value = "importQuestion接口返回的exportCode", required = true) @RequestParam String exportCode) throws Exception {
userService.exportFailureRecord(response, exportCode);
} }
} }

@ -0,0 +1,21 @@
package com.huoran.iasf.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 用户员工部门表 前端控制器
* </p>
*
* @author cheney
* @since 2022-08-15
*/
@RestController
@RequestMapping("//user-dept")
public class UserDeptController {
}

@ -67,9 +67,11 @@ public class UserGroupController {
if (StringUtils.isEmpty(userGroup.getId())) { if (StringUtils.isEmpty(userGroup.getId())) {
return R.fail("id不能为空"); return R.fail("id不能为空");
} }
List<UserGroup> groups = userGroupService.list(new QueryWrapper<UserGroup>(). QueryWrapper<UserGroup> queryWrapper = new QueryWrapper<>();
eq("group_name", userGroup.getGroupName())); queryWrapper.eq("group_name", userGroup.getGroupName());
if (ObjectUtil.isNotNull(groups) && groups.size()>1){ queryWrapper.last(" and id != " + userGroup.getId());
List<UserGroup> groups = userGroupService.list(queryWrapper);
if (ObjectUtil.isNotNull(groups) && groups.size()>0){
R.fail("用户组已存在"); R.fail("用户组已存在");
} }
userGroupService.updateById(userGroup); userGroupService.updateById(userGroup);
@ -85,7 +87,7 @@ public class UserGroupController {
}*/ }*/
@GetMapping("/list") @PostMapping("/list")
@ApiOperation(value = "用户组列表") @ApiOperation(value = "用户组列表")
@LogAnnotation(title = "用户组管理", action = "获取所有用户组机构") @LogAnnotation(title = "用户组管理", action = "获取所有用户组机构")
@RequiresPermissions("sys:userGroup:list") @RequiresPermissions("sys:userGroup:list")

@ -1,53 +0,0 @@
/*
package com.huoran.iasf.controller.api;
import com.huoran.iasf.common.utils.R;
import com.huoran.iasf.service.HttpApiSessionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
*/
/**
* api test示例
*
* @author cheney
* @version V1.0
* @date 2020年5月11日
*//*
@RestController
@RequestMapping("/app/api")
@Api(tags = "test")
public class TestController {
@Resource
HttpApiSessionService httpApiSessionService;
@PostMapping("/login")
@ApiOperation(value = "登录接口")
public R login() {
//TODO 登录
//生成token
String token = httpApiSessionService.geneJsonWebToken("123", "测试用户名");
return R.success(token);
}
@GetMapping("/getCurUserInfo")
@ApiOperation(value = "获取当前登录人信息示例")
public R getAppUserInfo() {
//拿userId与userName
String userId = httpApiSessionService.getCurrentUserId();
String username = httpApiSessionService.getCurrentUsername();
return R.success();
}
}
*/

@ -25,7 +25,7 @@ public class SysDept implements Serializable {
@ApiModelProperty(value = "部门编号(规则:父级关系编码+自己的编码)") @ApiModelProperty(value = "部门编号(规则:父级关系编码+自己的编码)")
private String deptNo; private String deptNo;
@NotBlank(message = "机构名称不能为空") @NotBlank(message = "部门名称不能为空")
@ApiModelProperty(value = "部门名称") @ApiModelProperty(value = "部门名称")
private String name; private String name;
@ -43,14 +43,14 @@ public class SysDept implements Serializable {
@ApiModelProperty(value = "为了维护更深层级关系") @ApiModelProperty(value = "为了维护更深层级关系")
private String relationCode; private String relationCode;
@ApiModelProperty(value = "部门经理user_id") /* @ApiModelProperty(value = "部门经理user_id")
private String deptManagerId; private String deptManagerId;
@ApiModelProperty(value = "部门经理名称") @ApiModelProperty(value = "部门经理名称")
private String managerName; private String managerName;
@ApiModelProperty(value = "部门经理联系电话") @ApiModelProperty(value = "部门经理联系电话")
private String phone; private String phone;*/
@TableField(fill = FieldFill.INSERT) @TableField(fill = FieldFill.INSERT)
private Date createTime; private Date createTime;

@ -3,8 +3,6 @@ package com.huoran.iasf.entity;
import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.huoran.iasf.vo.resp.DeptRespNodeVO;
import com.huoran.iasf.vo.resp.PermissionRespNode;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@ -54,28 +52,9 @@ public class SysRole extends BaseEntity implements Serializable {
@ApiModelProperty(value = "是否删除(1未删除;0已删除)") @ApiModelProperty(value = "是否删除(1未删除;0已删除)")
private Integer deleted; private Integer deleted;
@TableField(exist = false)
@ApiModelProperty(value = "权限菜单")
private List<PermissionRespNode> permissionRespNodes;
@TableField(exist = false)
@ApiModelProperty(value = "部门列表")
private List<DeptRespNodeVO> deptRespNodes;
/* @TableField(exist = false)
@ApiModelProperty(value = "开始时间")
private String startTime;
@TableField(exist = false)
@ApiModelProperty(value = "结束时间")
private String endTime;*/
@TableField(exist = false) @TableField(exist = false)
@ApiModelProperty(value = "权限") @ApiModelProperty(value = "权限")
private List<String> permissions; private List<String> permissions;
@TableField(exist = false)
@ApiModelProperty(value = "部门")
private List<String> depts;
} }

@ -33,7 +33,7 @@ public class SysUser extends BaseEntity implements Serializable {
@ApiModelProperty(value = "加密盐值") @ApiModelProperty(value = "加密盐值")
private String salt; private String salt;
@NotBlank(message = "密码不能为空") // @NotBlank(message = "密码不能为空")
@ApiModelProperty(value = "用户密码") @ApiModelProperty(value = "用户密码")
private String password; private String password;
@ -48,26 +48,37 @@ public class SysUser extends BaseEntity implements Serializable {
@ApiModelProperty(value = "手机号码") @ApiModelProperty(value = "手机号码")
private String phone; private String phone;
@ApiModelProperty(value = "部门id") @ApiModelProperty(value = "用户头像路径")
private String deptId; private String userAvatars;
@TableField(exist = false) /* @TableField(exist = false)
@ApiModelProperty(value = "部门名称") @ApiModelProperty(value = "部门名称")
private String deptName; private String deptName;
@TableField(exist = false) @TableField(exist = false)
@ApiModelProperty(value = "部门编号(规则:父级关系编码+自己的编码)") @ApiModelProperty(value = "部门编号(规则:父级关系编码+自己的编码)")
private String deptNo; private String deptNo;*/
/* @TableField(exist = false)
@ApiModelProperty(value = "部门编号(规则:父级关系编码+自己的编码)")
private String deptNo;*/
@ApiModelProperty(value = "真实名称") @ApiModelProperty(value = "真实名称")
private String realName; private String realName;
@ApiModelProperty(value = "昵称") @ApiModelProperty(value = "工号")
private String nickName; private String jobNumber;
@ApiModelProperty(value = "邮箱(唯一)") @ApiModelProperty(value = "邮箱(唯一)")
private String email; private String email;
@ApiModelProperty(value = "用户组id")
private String groupId;
@TableField(exist = false)
@ApiModelProperty(value = "用户组名称")
private String groupName;
@ApiModelProperty(value = "账户状态(1.正常 0.锁定 )") @ApiModelProperty(value = "账户状态(1.正常 0.锁定 )")
private Integer status; private Integer status;
@ -91,6 +102,9 @@ public class SysUser extends BaseEntity implements Serializable {
@ApiModelProperty(value = "创建时间") @ApiModelProperty(value = "创建时间")
private Date createTime; private Date createTime;
@ApiModelProperty(value = "最后登陆时间")
private Date lastLoginTime;
@TableField(fill = FieldFill.INSERT_UPDATE) @TableField(fill = FieldFill.INSERT_UPDATE)
@ApiModelProperty(value = "更新时间") @ApiModelProperty(value = "更新时间")
private Date updateTime; private Date updateTime;
@ -107,6 +121,10 @@ public class SysUser extends BaseEntity implements Serializable {
@ApiModelProperty(value = "角色id") @ApiModelProperty(value = "角色id")
private List<String> roleIds; private List<String> roleIds;
@TableField(exist = false)
@ApiModelProperty(value = "组织架构id(多个部门id)")
private List<String> deptArchitectureId;
@TableField(exist = false) @TableField(exist = false)
@ApiModelProperty("随机数") @ApiModelProperty("随机数")
// @NotNull(message = "随机数不能为空") // @NotNull(message = "随机数不能为空")

@ -0,0 +1,42 @@
package com.huoran.iasf.entity;
import com.baomidou.mybatisplus.annotation.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 用户员工部门表
* </p>
*
* @author cheney
* @since 2022-08-15
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("sys_user_dept")
@ApiModel(value="UserDept对象", description="用户员工部门表")
public class UserDept implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键")
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@ApiModelProperty(value = "用户员工id")
private String userId;
@ApiModelProperty(value = "部门id")
private String deptId;
@ApiModelProperty(value = "创建时间")
@TableField(fill = FieldFill.INSERT)
private Date createTime;
}

@ -1,7 +1,12 @@
package com.huoran.iasf.mapper; package com.huoran.iasf.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huoran.iasf.entity.SysUser; import com.huoran.iasf.entity.SysUser;
import com.huoran.iasf.vo.req.UserListReq;
import com.huoran.iasf.vo.resp.UserListResp;
import org.apache.ibatis.annotations.Param;
/** /**
* 用户 Mapper * 用户 Mapper
@ -11,4 +16,8 @@ import com.huoran.iasf.entity.SysUser;
* @date 2022年7月28日 * @date 2022年7月28日
*/ */
public interface SysUserMapper extends BaseMapper<SysUser> { public interface SysUserMapper extends BaseMapper<SysUser> {
IPage<UserListResp> userList(Page<UserListResp> page,@Param("req") UserListReq userListReq);
UserListResp detailInfo(String id);
} }

@ -0,0 +1,16 @@
package com.huoran.iasf.mapper;
import com.huoran.iasf.entity.UserDept;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* 用户员工部门表 Mapper 接口
* </p>
*
* @author cheney
* @since 2022-08-15
*/
public interface UserDeptMapper extends BaseMapper<UserDept> {
}

@ -0,0 +1,149 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.huoran.iasf.mapper.SysUserMapper">
<select id="userList" resultType="com.huoran.iasf.vo.resp.UserListResp"
parameterType="com.huoran.iasf.vo.req.UserListReq">
SELECT
s.id,
s.real_name,
s.STATUS,
s.job_number,
s.phone,
s.email,
s.create_time,
s.last_login_time,
s.username,
(
SELECT
GROUP_CONCAT( sd.NAME SEPARATOR ',' )
FROM
sys_user_dept sud
JOIN sys_dept sd ON sd.id = sud.dept_id
AND sd.deleted = 1
WHERE
s.id = sud.user_id
) AS deptArchitectureName,
(
SELECT
GROUP_CONCAT( sd.id SEPARATOR ',' )
FROM
sys_user_dept sud
JOIN sys_dept sd ON sd.id = sud.dept_id
AND sd.deleted = 1
WHERE
s.id = sud.user_id
) AS deptArchitectureId,
(
SELECT
GROUP_CONCAT( r.NAME SEPARATOR ',' )
FROM
sys_user_role ur
JOIN sys_role r ON r.id = ur.role_id
AND r.deleted = 1
WHERE
ur.user_id = s.id
) AS roleName,
(
SELECT
sug.group_name
FROM
sys_user_group sug
WHERE
s.group_id = sug.id and sug.deleted = 1
) AS group_name
FROM
sys_user s
where s.deleted = 1
<if test="req.keyWord != '' and req.keyWord != null">
AND CONCAT(s.username LIKE '%' #{req.keyWord} '%' or s.real_name LIKE '%' #{req.keyWord} '%')
</if>
GROUP BY
s.id
<if test='req.type == 2'>
HAVING
deptArchitectureName is null
</if>
<if test="req.deptArchitectureId != null and req.deptArchitectureId != ''">
HAVING
FIND_IN_SET(#{req.deptArchitectureId},deptArchitectureId)
</if>
ORDER BY
s.create_time DESC
</select>
<select id="detailInfo" resultType="com.huoran.iasf.vo.resp.UserListResp">
SELECT
s.id,
s.real_name,
s.STATUS,
s.job_number,
s.phone,
s.email,
s.create_time,
s.last_login_time,
s.username,
(
SELECT
GROUP_CONCAT( sd.NAME SEPARATOR ',' )
FROM
sys_user_dept sud
JOIN sys_dept sd ON sd.id = sud.dept_id
AND sd.deleted = 1
WHERE
s.id = sud.user_id
) AS deptArchitectureName,
(
SELECT
GROUP_CONCAT( sd.id SEPARATOR ',' )
FROM
sys_user_dept sud
JOIN sys_dept sd ON sd.id = sud.dept_id
AND sd.deleted = 1
WHERE
s.id = sud.user_id
) AS deptArchitectureId,
(
SELECT
GROUP_CONCAT( r.NAME SEPARATOR ',' )
FROM
sys_user_role ur
JOIN sys_role r ON r.id = ur.role_id
AND r.deleted = 1
WHERE
ur.user_id = s.id
) AS roleName,
(
SELECT
GROUP_CONCAT( r.id SEPARATOR ',' )
FROM
sys_user_role ur
JOIN sys_role r ON r.id = ur.role_id
AND r.deleted = 1
WHERE
ur.user_id = s.id
) AS roleId,
(
SELECT
sug.group_name
FROM
sys_user_group sug
WHERE
s.group_id = sug.id and sug.deleted = 1
) AS group_name,
(
SELECT
sug.id
FROM
sys_user_group sug
WHERE
s.group_id = sug.id and sug.deleted = 1
) AS group_id
FROM
sys_user s
WHERE
s.id = #{id} and s.deleted = 1
GROUP BY
s.id
</select>
</mapper>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.huoran.iasf.mapper.UserDeptMapper">
</mapper>

@ -40,8 +40,10 @@ public interface DeptService extends IService<SysDept> {
* 部门树形列表 * 部门树形列表
* *
* @param deptId deptId * @param deptId deptId
* @param disabled 最顶级是否可用
* @return 树形列表 * @return 树形列表
*/ */
List<DeptRespNodeVO> deptTreeList(String deptId, Boolean disabled); List<DeptRespNodeVO> deptTreeList(String deptId);
boolean checkDeptRepeat(SysDept sysDept);
} }

@ -181,25 +181,25 @@ public class HttpSessionService {
* @param userId userId * @param userId userId
*/ */
public void refreshUerId(String userId) { public void refreshUerId(String userId) {
// redisService.delKeys(userTokenPrefix + "*#" + userId); redisService.delKeys(userTokenPrefix + "*#" + userId);
// Set<String> keys = redisService.keys("#" + userId); Set<String> keys = redisService.keys("#" + userId);
// //如果修改了角色/权限, 那么刷新权限 //如果修改了角色/权限, 那么刷新权限
// for (String key : keys) { for (String key : keys) {
// JSONObject redisSession = JSON.parseObject(redisService.get(key)); JSONObject redisSession = JSON.parseObject(redisService.get(key));
//
// List<String> roleNames = getRolesByUserId(userId); List<String> roleNames = getRolesByUserId(userId);
// if (!CollectionUtils.isEmpty(roleNames)) { if (!CollectionUtils.isEmpty(roleNames)) {
// redisSession.put(Constant.ROLES_KEY, roleNames); redisSession.put(Constant.ROLES_KEY, roleNames);
// } }
// Set<String> permissions = getPermissionsByUserId(userId); Set<String> permissions = getPermissionsByUserId(userId);
// redisSession.put(Constant.PERMISSIONS_KEY, permissions); redisSession.put(Constant.PERMISSIONS_KEY, permissions);
// Long redisTokenKeyExpire = redisService.getExpire(key); Long redisTokenKeyExpire = redisService.getExpire(key);
// //刷新token绑定的角色权限 //刷新token绑定的角色权限
// redisService.setAndExpire(key, redisSession.toJSONString(), redisTokenKeyExpire); redisService.setAndExpire(key, redisSession.toJSONString(), redisTokenKeyExpire);
//
// } }
} }
/** /**
@ -208,10 +208,10 @@ public class HttpSessionService {
* @param roleId roleId * @param roleId roleId
*/ */
public void refreshRolePermission(String roleId) { public void refreshRolePermission(String roleId) {
// List<String> userIds = userRoleService.getUserIdsByRoleId(roleId); List<String> userIds = userRoleService.getUserIdsByRoleId(roleId);
// if (!CollectionUtils.isEmpty(userIds)) { if (!CollectionUtils.isEmpty(userIds)) {
// userIds.parallelStream().forEach(this::refreshUerId); userIds.parallelStream().forEach(this::refreshUerId);
// } }
} }
/** /**
@ -220,10 +220,10 @@ public class HttpSessionService {
* @param permissionId permissionId * @param permissionId permissionId
*/ */
public void refreshPermission(String permissionId) { public void refreshPermission(String permissionId) {
// List<String> userIds = permissionService.getUserIdsById(permissionId); List<String> userIds = permissionService.getUserIdsById(permissionId);
// if (!CollectionUtils.isEmpty(userIds)) { if (!CollectionUtils.isEmpty(userIds)) {
// userIds.parallelStream().forEach(this::refreshUerId); userIds.parallelStream().forEach(this::refreshUerId);
// } }
} }

@ -31,7 +31,7 @@ public class RedisService {
public Long getExpire(String key) { public Long getExpire(String key) {
if (null == key) { if (null == key) {
throw new BusinessException(BaseResponseCode.DATA_ERROR.getCode(), "key or TomeUnit 不能为空"); throw new BusinessException(BaseResponseCode.KEY_OR_TOMEUNIT);
} }
return redisTemplate.getExpire(key, TimeUnit.SECONDS); return redisTemplate.getExpire(key, TimeUnit.SECONDS);
} }

@ -28,14 +28,6 @@ public interface RoleService extends IService<SysRole> {
*/ */
void updateRole(SysRole vo); void updateRole(SysRole vo);
/**
* 根据id获取角色详情
*
* @param id id
* @return SysRole
*/
SysRole detailInfo(String id);
/** /**
* 根据id删除 * 根据id删除
* *
@ -58,4 +50,6 @@ public interface RoleService extends IService<SysRole> {
* @return List * @return List
*/ */
List<String> getRoleNames(String userId); List<String> getRoleNames(String userId);
boolean checkDeptRepeat(SysRole vo);
} }

@ -1,16 +0,0 @@
package com.huoran.iasf.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.huoran.iasf.entity.SysRoleDeptEntity;
/**
* 角色部门
*
* @author cheney
* @email *****@mail.com
* @date 2020-09-27 17:30:15
*/
public interface SysRoleDeptService extends IService<SysRoleDeptEntity> {
}

@ -0,0 +1,16 @@
package com.huoran.iasf.service;
import com.huoran.iasf.entity.UserDept;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* <p>
* 用户员工部门表 服务类
* </p>
*
* @author cheney
* @since 2022-08-15
*/
public interface UserDeptService extends IService<UserDept> {
}

@ -1,10 +1,17 @@
package com.huoran.iasf.service; package com.huoran.iasf.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.huoran.iasf.common.utils.R;
import com.huoran.iasf.entity.SysUser; import com.huoran.iasf.entity.SysUser;
import com.huoran.iasf.vo.req.UserListReq;
import com.huoran.iasf.vo.resp.LoginRespVO; import com.huoran.iasf.vo.resp.LoginRespVO;
import com.huoran.iasf.vo.resp.UserListResp;
import com.huoran.iasf.vo.resp.UserOwnRoleRespVO; import com.huoran.iasf.vo.resp.UserOwnRoleRespVO;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
/** /**
* 用户 服务类 * 用户 服务类
@ -40,10 +47,9 @@ public interface UserService extends IService<SysUser> {
/** /**
* 分页 * 分页
* *
* @param vo vo
* @return IPage * @return IPage
*/ */
IPage<SysUser> pageInfo(SysUser vo); R pageInfo(UserListReq userListReq);
/** /**
* 添加用户 * 添加用户
@ -73,4 +79,12 @@ public interface UserService extends IService<SysUser> {
* @param vo vo * @param vo vo
*/ */
void updateUserInfoMy(SysUser vo); void updateUserInfoMy(SysUser vo);
UserListResp detailInfo(String id);
R resetPwd(String userId);
Map<String, String> importStaff(MultipartFile file);
void exportFailureRecord(HttpServletResponse response, String exportCode) throws IOException;
} }

@ -1,21 +1,24 @@
package com.huoran.iasf.service.impl; package com.huoran.iasf.service.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huoran.iasf.common.exception.BusinessException; import com.huoran.iasf.common.exception.BusinessException;
import com.huoran.iasf.common.exception.code.BaseResponseCode; import com.huoran.iasf.common.exception.code.BaseResponseCode;
import com.huoran.iasf.entity.SysDept; import com.huoran.iasf.entity.SysDept;
import com.huoran.iasf.entity.SysUser; import com.huoran.iasf.entity.UserDept;
import com.huoran.iasf.mapper.SysDeptMapper; import com.huoran.iasf.mapper.SysDeptMapper;
import com.huoran.iasf.mapper.SysUserMapper; import com.huoran.iasf.mapper.SysUserMapper;
import com.huoran.iasf.mapper.UserDeptMapper;
import com.huoran.iasf.service.DeptService; import com.huoran.iasf.service.DeptService;
import com.huoran.iasf.vo.resp.DeptRespNodeVO; import com.huoran.iasf.vo.resp.DeptRespNodeVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -37,6 +40,8 @@ public class DeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impleme
@Resource @Resource
private SysDeptMapper sysDeptMapper; private SysDeptMapper sysDeptMapper;
@Resource @Resource
private UserDeptMapper userDeptMapper;
@Resource
private SysUserMapper sysUserMapper; private SysUserMapper sysUserMapper;
@Override @Override
@ -57,6 +62,18 @@ public class DeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impleme
sysDeptMapper.insert(vo); sysDeptMapper.insert(vo);
} }
@Override
public boolean checkDeptRepeat(SysDept sysDept){
QueryWrapper<SysDept> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("name", sysDept.getName());
queryWrapper.eq("pid", sysDept.getPid());
if (StrUtil.isNotEmpty(sysDept.getId())) {
queryWrapper.last(" and id != " + sysDept.getId());
}
List<SysDept> sysDepts = baseMapper.selectList(queryWrapper);
return sysDepts.size() > 0;
}
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updateDept(SysDept vo) { public void updateDept(SysDept vo) {
@ -104,7 +121,11 @@ public class DeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impleme
throw new BusinessException(BaseResponseCode.DATA_ERROR); throw new BusinessException(BaseResponseCode.DATA_ERROR);
} }
List<Object> deptIds = sysDeptMapper.selectObjs(Wrappers.<SysDept>lambdaQuery().select(SysDept::getId).likeRight(SysDept::getRelationCode, sysDept.getRelationCode())); List<Object> deptIds = sysDeptMapper.selectObjs(Wrappers.<SysDept>lambdaQuery().select(SysDept::getId).likeRight(SysDept::getRelationCode, sysDept.getRelationCode()));
List<SysUser> list = sysUserMapper.selectList(Wrappers.<SysUser>lambdaQuery().in(SysUser::getDeptId, deptIds)); /*List<SysUser> list = sysUserMapper.selectList(Wrappers.<SysUser>lambdaQuery().in(SysUser::getDeptId, deptIds));
if (!CollectionUtils.isEmpty(list)) {
throw new BusinessException(BaseResponseCode.NOT_PERMISSION_DELETED_DEPT);
}*/
List<UserDept> list = userDeptMapper.selectList(Wrappers.<UserDept>lambdaQuery().in(UserDept::getDeptId, deptIds));
if (!CollectionUtils.isEmpty(list)) { if (!CollectionUtils.isEmpty(list)) {
throw new BusinessException(BaseResponseCode.NOT_PERMISSION_DELETED_DEPT); throw new BusinessException(BaseResponseCode.NOT_PERMISSION_DELETED_DEPT);
} }
@ -112,7 +133,7 @@ public class DeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impleme
} }
@Override @Override
public List<DeptRespNodeVO> deptTreeList(String deptId, Boolean disabled) { public List<DeptRespNodeVO> deptTreeList(String deptId) {
List<SysDept> list; List<SysDept> list;
if (StringUtils.isEmpty(deptId)) { if (StringUtils.isEmpty(deptId)) {
list = sysDeptMapper.selectList(Wrappers.emptyWrapper()); list = sysDeptMapper.selectList(Wrappers.emptyWrapper());
@ -127,10 +148,10 @@ public class DeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impleme
} }
// 默认加一个顶级方便新增顶级部门 // 默认加一个顶级方便新增顶级部门
DeptRespNodeVO respNodeVO = new DeptRespNodeVO(); DeptRespNodeVO respNodeVO = new DeptRespNodeVO();
respNodeVO.setTitle("默认顶级部门"); respNodeVO.setName("默认顶级部门");
respNodeVO.setId("0"); respNodeVO.setId("0");
respNodeVO.setSpread(true); /* respNodeVO.setSpread(true);
respNodeVO.setDisabled(disabled); respNodeVO.setDisabled(false);*/
respNodeVO.setChildren(getTree(list)); respNodeVO.setChildren(getTree(list));
List<DeptRespNodeVO> result = new ArrayList<>(); List<DeptRespNodeVO> result = new ArrayList<>();
result.add(respNodeVO); result.add(respNodeVO);
@ -143,8 +164,8 @@ public class DeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impleme
if ("0".equals(sysDept.getPid())) { if ("0".equals(sysDept.getPid())) {
DeptRespNodeVO deptTree = new DeptRespNodeVO(); DeptRespNodeVO deptTree = new DeptRespNodeVO();
BeanUtils.copyProperties(sysDept, deptTree); BeanUtils.copyProperties(sysDept, deptTree);
deptTree.setTitle(sysDept.getName()); deptTree.setName(sysDept.getName());
deptTree.setSpread(true); // deptTree.setSpread(true);
deptTree.setChildren(getChild(sysDept.getId(), all)); deptTree.setChildren(getChild(sysDept.getId(), all));
list.add(deptTree); list.add(deptTree);
} }
@ -158,7 +179,7 @@ public class DeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impleme
if (sysDept.getPid().equals(id)) { if (sysDept.getPid().equals(id)) {
DeptRespNodeVO deptTree = new DeptRespNodeVO(); DeptRespNodeVO deptTree = new DeptRespNodeVO();
BeanUtils.copyProperties(sysDept, deptTree); BeanUtils.copyProperties(sysDept, deptTree);
deptTree.setTitle(sysDept.getName()); deptTree.setName(sysDept.getName());
deptTree.setChildren(getChild(sysDept.getId(), all)); deptTree.setChildren(getChild(sysDept.getId(), all));
list.add(deptTree); list.add(deptTree);
} }

@ -1,58 +0,0 @@
package com.huoran.iasf.service.impl;
import com.huoran.iasf.entity.SysDept;
import com.huoran.iasf.entity.SysUser;
import com.huoran.iasf.service.DeptService;
import com.huoran.iasf.service.HomeService;
import com.huoran.iasf.service.PermissionService;
import com.huoran.iasf.service.UserService;
import com.huoran.iasf.vo.resp.HomeRespVO;
import com.huoran.iasf.vo.resp.PermissionRespNode;
import com.huoran.iasf.vo.resp.UserInfoRespVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* 首页
*
* @author cheney
* @version V1.0
* @date 2022年7月28日
*/
@Service
public class HomeServiceImpl implements HomeService {
@Resource
private UserService userService;
@Resource
private DeptService deptService;
@Resource
private PermissionService permissionService;
@Override
public HomeRespVO getHomeInfo(String userId) {
SysUser sysUser = userService.getById(userId);
UserInfoRespVO vo = new UserInfoRespVO();
if (sysUser != null) {
BeanUtils.copyProperties(sysUser, vo);
SysDept sysDept = deptService.getById(sysUser.getDeptId());
if (sysDept != null) {
vo.setDeptId(sysDept.getId());
vo.setDeptName(sysDept.getName());
}
}
List<PermissionRespNode> menus = permissionService.permissionTreeList(userId);
HomeRespVO respVO = new HomeRespVO();
respVO.setMenus(menus);
respVO.setUserInfo(vo);
return respVO;
}
}

@ -163,7 +163,7 @@ public class PermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysP
if ("0".equals(sysPermission.getPid())) { if ("0".equals(sysPermission.getPid())) {
PermissionRespNode permissionRespNode = new PermissionRespNode(); PermissionRespNode permissionRespNode = new PermissionRespNode();
BeanUtils.copyProperties(sysPermission, permissionRespNode); BeanUtils.copyProperties(sysPermission, permissionRespNode);
permissionRespNode.setTitle(sysPermission.getName()); permissionRespNode.setName(sysPermission.getName());
if (type) { if (type) {
permissionRespNode.setChildren(getChildExcBtn(sysPermission.getId(), all)); permissionRespNode.setChildren(getChildExcBtn(sysPermission.getId(), all));
@ -186,7 +186,7 @@ public class PermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysP
if (sysPermission.getPid().equals(id)) { if (sysPermission.getPid().equals(id)) {
PermissionRespNode permissionRespNode = new PermissionRespNode(); PermissionRespNode permissionRespNode = new PermissionRespNode();
BeanUtils.copyProperties(sysPermission, permissionRespNode); BeanUtils.copyProperties(sysPermission, permissionRespNode);
permissionRespNode.setTitle(sysPermission.getName()); permissionRespNode.setName(sysPermission.getName());
permissionRespNode.setChildren(getChildAll(sysPermission.getId(), all)); permissionRespNode.setChildren(getChildAll(sysPermission.getId(), all));
list.add(permissionRespNode); list.add(permissionRespNode);
} }
@ -204,7 +204,7 @@ public class PermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysP
if (sysPermission.getPid().equals(id) && sysPermission.getType() != 3) { if (sysPermission.getPid().equals(id) && sysPermission.getType() != 3) {
PermissionRespNode permissionRespNode = new PermissionRespNode(); PermissionRespNode permissionRespNode = new PermissionRespNode();
BeanUtils.copyProperties(sysPermission, permissionRespNode); BeanUtils.copyProperties(sysPermission, permissionRespNode);
permissionRespNode.setTitle(sysPermission.getName()); permissionRespNode.setName(sysPermission.getName());
permissionRespNode.setChildren(getChildExcBtn(sysPermission.getId(), all)); permissionRespNode.setChildren(getChildExcBtn(sysPermission.getId(), all));
list.add(permissionRespNode); list.add(permissionRespNode);
} }
@ -246,7 +246,7 @@ public class PermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysP
//新增顶级目录是为了方便添加一级目录 //新增顶级目录是为了方便添加一级目录
PermissionRespNode respNode = new PermissionRespNode(); PermissionRespNode respNode = new PermissionRespNode();
respNode.setId("0"); respNode.setId("0");
respNode.setTitle("默认顶级菜单"); respNode.setName("默认顶级菜单");
respNode.setSpread(true); respNode.setSpread(true);
respNode.setChildren(getTree(list, true)); respNode.setChildren(getTree(list, true));
result.add(respNode); result.add(respNode);

@ -1,12 +1,12 @@
package com.huoran.iasf.service.impl; package com.huoran.iasf.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huoran.iasf.common.exception.BusinessException; import com.huoran.iasf.common.exception.BusinessException;
import com.huoran.iasf.common.exception.code.BaseResponseCode; import com.huoran.iasf.common.exception.code.BaseResponseCode;
import com.huoran.iasf.entity.SysRole; import com.huoran.iasf.entity.SysRole;
import com.huoran.iasf.entity.SysRoleDeptEntity;
import com.huoran.iasf.entity.SysRolePermission; import com.huoran.iasf.entity.SysRolePermission;
import com.huoran.iasf.entity.SysUserRole; import com.huoran.iasf.entity.SysUserRole;
import com.huoran.iasf.mapper.SysRoleMapper; import com.huoran.iasf.mapper.SysRoleMapper;
@ -20,7 +20,6 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashSet;
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;
@ -42,13 +41,8 @@ public class RoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impleme
@Resource @Resource
private RolePermissionService rolePermissionService; private RolePermissionService rolePermissionService;
@Resource @Resource
private PermissionService permissionService;
@Resource
private HttpSessionService httpSessionService; private HttpSessionService httpSessionService;
@Resource
private DeptService deptService;
@Resource
private SysRoleDeptService sysRoleDeptService;
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
@ -85,33 +79,11 @@ public class RoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impleme
} }
} }
@Override
public SysRole detailInfo(String id) {
SysRole sysRole = sysRoleMapper.selectById(id);
if (sysRole == null) {
log.error("传入 的 id:{}不合法", id);
throw new BusinessException(BaseResponseCode.DATA_ERROR);
}
List<PermissionRespNode> permissionRespNodes = permissionService.selectAllByTree();
LambdaQueryWrapper<SysRolePermission> queryWrapper = Wrappers.<SysRolePermission>lambdaQuery().select(SysRolePermission::getPermissionId).eq(SysRolePermission::getRoleId, sysRole.getId());
Set<Object> checkList =
new HashSet<>(rolePermissionService.listObjs(queryWrapper));
setChecked(permissionRespNodes, checkList);
sysRole.setPermissionRespNodes(permissionRespNodes);
LambdaQueryWrapper<SysRoleDeptEntity> queryWrapperDept = Wrappers.<SysRoleDeptEntity>lambdaQuery().select(SysRoleDeptEntity::getDeptId).eq(SysRoleDeptEntity::getRoleId, sysRole.getId());
List<DeptRespNodeVO> deptRespNodes = deptService.deptTreeList(null, true);
Set<Object> checkDeptList =
new HashSet<>(sysRoleDeptService.listObjs(queryWrapperDept));
setCheckedDept(deptRespNodes, checkDeptList);
sysRole.setDeptRespNodes(deptRespNodes);
return sysRole;
}
private void setCheckedDept(List<DeptRespNodeVO> deptRespNodes, Set<Object> checkDeptList) { private void setCheckedDept(List<DeptRespNodeVO> deptRespNodes, Set<Object> checkDeptList) {
for (DeptRespNodeVO node : deptRespNodes) { for (DeptRespNodeVO node : deptRespNodes) {
if (checkDeptList.contains(node.getId())) { if (checkDeptList.contains(node.getId())) {
node.setChecked(true); // node.setChecked(true);
} }
setCheckedDept((List<DeptRespNodeVO>) node.getChildren(), checkDeptList); setCheckedDept((List<DeptRespNodeVO>) node.getChildren(), checkDeptList);
} }
@ -163,4 +135,15 @@ public class RoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impleme
} }
return sysRoles.stream().map(SysRole::getName).collect(Collectors.toList()); return sysRoles.stream().map(SysRole::getName).collect(Collectors.toList());
} }
@Override
public boolean checkDeptRepeat(SysRole vo) {
QueryWrapper<SysRole> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("name", vo.getName());
if (StrUtil.isNotEmpty(vo.getId())) {
queryWrapper.last(" and id != " + vo.getId());
}
List<SysRole> sysRoles = baseMapper.selectList(queryWrapper);
return sysRoles.size() > 0;
}
} }

@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huoran.iasf.common.exception.BusinessException; import com.huoran.iasf.common.exception.BusinessException;
import com.huoran.iasf.common.exception.code.BaseResponseCode;
import com.huoran.iasf.entity.SysDictDetailEntity; import com.huoran.iasf.entity.SysDictDetailEntity;
import com.huoran.iasf.entity.SysDictEntity; import com.huoran.iasf.entity.SysDictEntity;
import com.huoran.iasf.mapper.SysDictDetailMapper; import com.huoran.iasf.mapper.SysDictDetailMapper;
@ -36,7 +37,7 @@ public class SysDictDetailServiceImpl extends ServiceImpl<SysDictDetailMapper, S
SysDictEntity sysDictEntity = sysDictMapper.selectById(dictId); SysDictEntity sysDictEntity = sysDictMapper.selectById(dictId);
if (sysDictEntity == null) { if (sysDictEntity == null) {
throw new BusinessException("获取字典数据失败!"); throw new BusinessException(BaseResponseCode.DICTIONARY_DATA_FAILED);
} }
LambdaQueryWrapper<SysDictDetailEntity> wrapper = Wrappers.lambdaQuery(); LambdaQueryWrapper<SysDictDetailEntity> wrapper = Wrappers.lambdaQuery();

@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huoran.iasf.common.config.FileUploadProperties; import com.huoran.iasf.common.config.FileUploadProperties;
import com.huoran.iasf.common.exception.BusinessException; import com.huoran.iasf.common.exception.BusinessException;
import com.huoran.iasf.common.exception.code.BaseResponseCode;
import com.huoran.iasf.common.utils.DateUtils; import com.huoran.iasf.common.utils.DateUtils;
import com.huoran.iasf.common.utils.R; import com.huoran.iasf.common.utils.R;
import com.huoran.iasf.entity.SysFilesEntity; import com.huoran.iasf.entity.SysFilesEntity;
@ -46,7 +47,7 @@ public class SysFilesServiceImpl extends ServiceImpl<SysFilesMapper, SysFilesEnt
@Override @Override
public R saveFile(MultipartFile file, FileParameters fileParameters) { public R saveFile(MultipartFile file, FileParameters fileParameters) {
if (ObjectUtil.isEmpty(file) || file.getSize() <= 0) { if (ObjectUtil.isEmpty(file) || file.getSize() <= 0) {
throw new BusinessException("上传内容为空"); throw new BusinessException(BaseResponseCode.UPLOAD_EMPTY);
} }
//存储文件夹 //存储文件夹
String createTime = DateUtils.format(new Date(), DateUtils.DATEPATTERN); String createTime = DateUtils.format(new Date(), DateUtils.DATEPATTERN);
@ -92,7 +93,7 @@ public class SysFilesServiceImpl extends ServiceImpl<SysFilesMapper, SysFilesEnt
resultMap.put("url", url); resultMap.put("url", url);
return R.success(resultMap); return R.success(resultMap);
} catch (Exception e) { } catch (Exception e) {
throw new BusinessException("上传文件失败"); throw new BusinessException(BaseResponseCode.UPLOAD_FAILED);
} }
} }

@ -1,3 +1,4 @@
/*
package com.huoran.iasf.service.impl; package com.huoran.iasf.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
@ -15,13 +16,15 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
*/
/** /**
* 代码生成 * 代码生成
* *
* @author cheney * @author cheney
* @version V1.0 * @version V1.0
* @date 2022年7月28日 * @date 2022年7月28日
*/ *//*
@Service @Service
@Slf4j @Slf4j
public class SysGeneratorServiceImpl implements ISysGeneratorService { public class SysGeneratorServiceImpl implements ISysGeneratorService {
@ -63,3 +66,4 @@ public class SysGeneratorServiceImpl implements ISysGeneratorService {
} }
*/

@ -1,14 +1,14 @@
package com.huoran.iasf.service.impl; package com.huoran.iasf.service.impl;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huoran.iasf.entity.SysRoleDeptEntity; import com.huoran.iasf.entity.SysRoleDeptEntity;
import com.huoran.iasf.mapper.SysRoleDeptMapper; import com.huoran.iasf.mapper.SysRoleDeptMapper;
import com.huoran.iasf.service.SysRoleDeptService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service("sysRoleDeptService") @Service("sysRoleDeptService")
public class SysRoleDeptServiceImpl extends ServiceImpl<SysRoleDeptMapper, SysRoleDeptEntity> implements SysRoleDeptService { public class SysRoleDeptServiceImpl extends ServiceImpl<SysRoleDeptMapper, SysRoleDeptEntity> implements IService<SysRoleDeptEntity> {
} }

@ -0,0 +1,20 @@
package com.huoran.iasf.service.impl;
import com.huoran.iasf.entity.UserDept;
import com.huoran.iasf.mapper.UserDeptMapper;
import com.huoran.iasf.service.UserDeptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* <p>
* 用户员工部门表 服务实现类
* </p>
*
* @author cheney
* @since 2022-08-15
*/
@Service
public class UserDeptServiceImpl extends ServiceImpl<UserDeptMapper, UserDept> implements UserDeptService {
}

@ -1,30 +1,59 @@
package com.huoran.iasf.service.impl; package com.huoran.iasf.service.impl;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import com.huoran.iasf.common.exception.BusinessException; import com.huoran.iasf.common.exception.BusinessException;
import com.huoran.iasf.common.exception.code.BaseResponseCode; import com.huoran.iasf.common.exception.code.BaseResponseCode;
import com.huoran.iasf.common.utils.ExcelImportHelper;
import com.huoran.iasf.common.utils.ExcelStyleUtil;
import com.huoran.iasf.common.utils.PasswordUtils; import com.huoran.iasf.common.utils.PasswordUtils;
import com.huoran.iasf.entity.SysDept; import com.huoran.iasf.common.utils.R;
import com.huoran.iasf.entity.SysRole; import com.huoran.iasf.entity.*;
import com.huoran.iasf.entity.SysUser;
import com.huoran.iasf.mapper.SysDeptMapper; import com.huoran.iasf.mapper.SysDeptMapper;
import com.huoran.iasf.mapper.SysUserMapper; import com.huoran.iasf.mapper.SysUserMapper;
import com.huoran.iasf.mapper.UserDeptMapper;
import com.huoran.iasf.mapper.UserGroupMapper;
import com.huoran.iasf.service.*; import com.huoran.iasf.service.*;
import com.huoran.iasf.vo.ImportUserFailureVo;
import com.huoran.iasf.vo.req.ExcelImpUserReq;
import com.huoran.iasf.vo.req.UserListReq;
import com.huoran.iasf.vo.req.UserRoleOperationReqVO; import com.huoran.iasf.vo.req.UserRoleOperationReqVO;
import com.huoran.iasf.vo.resp.LoginRespVO; import com.huoran.iasf.vo.resp.LoginRespVO;
import com.huoran.iasf.vo.resp.PermissionRespNode;
import com.huoran.iasf.vo.resp.UserListResp;
import com.huoran.iasf.vo.resp.UserOwnRoleRespVO; import com.huoran.iasf.vo.resp.UserOwnRoleRespVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/** /**
* 用户 服务类 * 用户 服务类
@ -45,6 +74,9 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
private PermissionService permissionService; private PermissionService permissionService;
@Resource @Resource
private UserRoleService userRoleService; private UserRoleService userRoleService;
@Resource
private UserDeptMapper userDeptMapper;
@Resource @Resource
private SysDeptMapper sysDeptMapper; private SysDeptMapper sysDeptMapper;
@Resource @Resource
@ -53,6 +85,12 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
@Resource @Resource
private RedisService redisService; private RedisService redisService;
@Resource
private UserGroupMapper userGroupMapper;
@Resource
StringRedisTemplate stringRedisTemplate;
@Value("${spring.redis.allowMultipleLogin}") @Value("${spring.redis.allowMultipleLogin}")
private Boolean allowMultipleLogin; private Boolean allowMultipleLogin;
@Value("${spring.profiles.active}") @Value("${spring.profiles.active}")
@ -62,7 +100,7 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
public void register(SysUser sysUser) { public void register(SysUser sysUser) {
SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, sysUser.getUsername())); SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, sysUser.getUsername()));
if (sysUserOne != null) { if (sysUserOne != null) {
throw new BusinessException("用户名已存在!"); throw new BusinessException(BaseResponseCode.USERNAME_EXISTS);
} }
sysUser.setSalt(PasswordUtils.getSalt()); sysUser.setSalt(PasswordUtils.getSalt());
String encode = PasswordUtils.encode(sysUser.getPassword(), sysUser.getSalt()); String encode = PasswordUtils.encode(sysUser.getPassword(), sysUser.getSalt());
@ -85,6 +123,8 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
throw new BusinessException(BaseResponseCode.PASSWORD_ERROR); throw new BusinessException(BaseResponseCode.PASSWORD_ERROR);
} }
LoginRespVO respVO = new LoginRespVO(); LoginRespVO respVO = new LoginRespVO();
sysUser.setLastLoginTime(new Date());
sysUserMapper.updateById(sysUser);
BeanUtils.copyProperties(sysUser, respVO); BeanUtils.copyProperties(sysUser, respVO);
//是否删除之前token, 此处控制是否支持多登陆端; //是否删除之前token, 此处控制是否支持多登陆端;
@ -92,15 +132,11 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
if (!allowMultipleLogin) { if (!allowMultipleLogin) {
httpSessionService.abortUserById(sysUser.getId()); httpSessionService.abortUserById(sysUser.getId());
} }
if (StringUtils.isNotBlank(sysUser.getDeptId())) { List<PermissionRespNode> menus = permissionService.permissionTreeList(sysUser.getId());
SysDept sysDept = sysDeptMapper.selectById(sysUser.getDeptId());
if (sysDept != null) {
sysUser.setDeptNo(sysDept.getDeptNo());
}
}
String token = httpSessionService.createTokenAndUser(sysUser, roleService.getRoleNames(sysUser.getId()), permissionService.getPermissionsByUserId(sysUser.getId())); String token = httpSessionService.createTokenAndUser(sysUser, roleService.getRoleNames(sysUser.getId()), permissionService.getPermissionsByUserId(sysUser.getId()));
respVO.setAccessToken(token); respVO.setAccessToken(token);
respVO.setList(menus);
return respVO; return respVO;
} }
@ -115,11 +151,11 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
String value = redisService.get(random); String value = redisService.get(random);
//验证码已过期 //验证码已过期
if (StringUtils.isEmpty(value)) { if (StringUtils.isEmpty(value)) {
throw new BusinessException(10004, "验证码已过期"); throw new BusinessException(BaseResponseCode.VERIFICATION_CODE_EXPIRED);
} }
//验证码错误 //验证码错误
if (!code.equals(value)) { if (!code.equals(value)) {
throw new BusinessException(10005, "验证码错误"); throw new BusinessException(BaseResponseCode.VERIFICATION_CODE_ERROR);
} }
redisService.del(random); redisService.del(random);
} }
@ -127,7 +163,6 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
@Override @Override
public void updateUserInfo(SysUser vo) { public void updateUserInfo(SysUser vo) {
SysUser sysUser = sysUserMapper.selectById(vo.getId()); SysUser sysUser = sysUserMapper.selectById(vo.getId());
if (null == sysUser) { if (null == sysUser) {
throw new BusinessException(BaseResponseCode.DATA_ERROR); throw new BusinessException(BaseResponseCode.DATA_ERROR);
@ -137,7 +172,7 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
if (!sysUser.getUsername().equals(vo.getUsername())) { if (!sysUser.getUsername().equals(vo.getUsername())) {
SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, vo.getUsername())); SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, vo.getUsername()));
if (sysUserOne != null) { if (sysUserOne != null) {
throw new BusinessException("用户名已存在!"); throw new BusinessException(BaseResponseCode.USERNAME_EXISTS);
} }
} }
@ -155,6 +190,30 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
} else { } else {
vo.setPassword(null); vo.setPassword(null);
} }
//删除所有部门
userDeptMapper.delete(Wrappers.<UserDept>lambdaQuery().eq(UserDept::getUserId, vo.getId()));
//更新部门
if (!CollectionUtils.isEmpty(vo.getDeptArchitectureId())) {
List<String> deptArchitectureId = vo.getDeptArchitectureId();
for (String deptId : deptArchitectureId) {
UserDept userDept = new UserDept();
userDept.setUserId(vo.getId());
userDept.setDeptId(deptId);
}
}
LambdaQueryWrapper<SysUserRole> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(SysUserRole::getUserId, vo.getId());
userRoleService.remove(queryWrapper);
if (!CollectionUtils.isEmpty(vo.getRoleIds())) {
UserRoleOperationReqVO reqVO = new UserRoleOperationReqVO();
reqVO.setUserId(vo.getId());
reqVO.setRoleIds(vo.getRoleIds());
userRoleService.addUserRoleInfo(reqVO);
}
//刷新权限
httpSessionService.refreshUerId(vo.getId());
vo.setUpdateId(httpSessionService.getCurrentUserId()); vo.setUpdateId(httpSessionService.getCurrentUserId());
sysUserMapper.updateById(vo); sysUserMapper.updateById(vo);
@ -180,55 +239,85 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
} }
@Override @Override
public IPage<SysUser> pageInfo(SysUser vo) { public UserListResp detailInfo(String id) {
LambdaQueryWrapper<SysUser> queryWrapper = Wrappers.lambdaQuery(); return baseMapper.detailInfo(id);
}
@Override
public R resetPwd(String userId) {
SysUser sysUser = baseMapper.selectById(userId);
sysUser.setSalt(PasswordUtils.getSalt());
String encode = PasswordUtils.encode("111aaa", sysUser.getSalt());
sysUser.setPassword(encode);
int update = baseMapper.updateById(sysUser);
return update>0 ? R.success("重置成功") : R.fail("重置失败");
}
@Override
public R pageInfo(UserListReq userListReq) {
/*LambdaQueryWrapper<SysUser> queryWrapper = Wrappers.lambdaQuery();
if (!StringUtils.isEmpty(vo.getUsername())) { if (!StringUtils.isEmpty(vo.getUsername())) {
queryWrapper.like(SysUser::getUsername, vo.getUsername()); queryWrapper.like(SysUser::getUsername, vo.getUsername());
} }
/* if (!StringUtils.isEmpty(vo.getStartTime())) { *//* if (!StringUtils.isEmpty(vo.getStartTime())) {
queryWrapper.gt(SysUser::getCreateTime, vo.getStartTime()); queryWrapper.gt(SysUser::getCreateTime, vo.getStartTime());
} }
if (!StringUtils.isEmpty(vo.getEndTime())) { if (!StringUtils.isEmpty(vo.getEndTime())) {
queryWrapper.lt(SysUser::getCreateTime, vo.getEndTime()); queryWrapper.lt(SysUser::getCreateTime, vo.getEndTime());
}*/ }*//*
if (!StringUtils.isEmpty(vo.getNickName())) { *//* if (!StringUtils.isEmpty(vo.getNickName())) {
queryWrapper.like(SysUser::getNickName, vo.getNickName()); queryWrapper.like(SysUser::getNickName, vo.getNickName());
} }*//*
if (null != vo.getStatus()) { if (null != vo.getStatus()) {
queryWrapper.eq(SysUser::getStatus, vo.getStatus()); queryWrapper.eq(SysUser::getStatus, vo.getStatus());
} }
if (!StringUtils.isEmpty(vo.getDeptNo())) { // if (!StringUtils.isEmpty(vo.getDeptNo())) {
LambdaQueryWrapper<SysDept> queryWrapperDept = Wrappers.lambdaQuery(); // LambdaQueryWrapper<SysDept> queryWrapperDept = Wrappers.lambdaQuery();
queryWrapperDept.select(SysDept::getId).like(SysDept::getRelationCode, vo.getDeptNo()); // queryWrapperDept.select(SysDept::getId).like(SysDept::getRelationCode, vo.getDeptNo());
List<Object> list = sysDeptMapper.selectObjs(queryWrapperDept); // List<Object> list = sysDeptMapper.selectObjs(queryWrapperDept);
queryWrapper.in(SysUser::getDeptId, list); // queryWrapper.in(SysUser::getDeptId, list);
} // }
queryWrapper.orderByDesc(SysUser::getCreateTime); queryWrapper.orderByDesc(SysUser::getCreateTime);
IPage<SysUser> iPage = sysUserMapper.selectPage(vo.getQueryPage(), queryWrapper); IPage<SysUser> iPage = sysUserMapper.selectPage(vo.getQueryPage(), queryWrapper);
if (!CollectionUtils.isEmpty(iPage.getRecords())) { if (!CollectionUtils.isEmpty(iPage.getRecords())) {
for (SysUser sysUser : iPage.getRecords()) { for (SysUser sysUser : iPage.getRecords()) {
SysDept sysDept = sysDeptMapper.selectById(sysUser.getDeptId()); *//*SysDept sysDept = sysDeptMapper.selectById(sysUser.getDeptId());
if (sysDept != null) { if (sysDept != null) {
sysUser.setDeptName(sysDept.getName()); sysUser.setDeptName(sysDept.getName());
}*//*
} }
}*/
//查询未加入部门的员工,部门id一定清空
if (userListReq.getType()==2){
userListReq.setDeptArchitectureId(null);
} }
}
return iPage; Page<UserListResp> page = new Page<UserListResp>(userListReq.getPageNum(), userListReq.getPageSize());
IPage<UserListResp> userList = baseMapper.userList(page, userListReq);
return R.success(userList);
} }
@Override @Override
public void addUser(SysUser vo) { public void addUser(SysUser vo) {
SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, vo.getUsername()));
if (sysUserOne != null) {
throw new BusinessException("用户已存在,请勿重复添加!");
}
vo.setSalt(PasswordUtils.getSalt()); vo.setSalt(PasswordUtils.getSalt());
String encode = PasswordUtils.encode(vo.getPassword(), vo.getSalt()); String encode = PasswordUtils.encode("111aaa", vo.getSalt());
vo.setPassword(encode); vo.setPassword(encode);
vo.setStatus(1); vo.setStatus(1);
vo.setCreateWhere(1); vo.setCreateWhere(1);
sysUserMapper.insert(vo); sysUserMapper.insert(vo);
if (!CollectionUtils.isEmpty(vo.getDeptArchitectureId())) {
List<String> deptArchitectureId = vo.getDeptArchitectureId();
for (String deptId : deptArchitectureId) {
UserDept userDept = new UserDept();
userDept.setUserId(vo.getId());
userDept.setDeptId(deptId);
userDeptMapper.insert(userDept);
}
}
//用户账号赋予角色
if (!CollectionUtils.isEmpty(vo.getRoleIds())) { if (!CollectionUtils.isEmpty(vo.getRoleIds())) {
UserRoleOperationReqVO reqVO = new UserRoleOperationReqVO(); UserRoleOperationReqVO reqVO = new UserRoleOperationReqVO();
reqVO.setUserId(vo.getId()); reqVO.setUserId(vo.getId());
@ -252,7 +341,7 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
throw new BusinessException(BaseResponseCode.OLD_PASSWORD_ERROR); throw new BusinessException(BaseResponseCode.OLD_PASSWORD_ERROR);
} }
if (sysUser.getPassword().equals(PasswordUtils.encode(vo.getNewPwd(), sysUser.getSalt()))) { if (sysUser.getPassword().equals(PasswordUtils.encode(vo.getNewPwd(), sysUser.getSalt()))) {
throw new BusinessException("新密码不能与旧密码相同"); throw new BusinessException(BaseResponseCode.CANNOT_SAME);
} }
sysUser.setPassword(PasswordUtils.encode(vo.getNewPwd(), sysUser.getSalt())); sysUser.setPassword(PasswordUtils.encode(vo.getNewPwd(), sysUser.getSalt()));
sysUserMapper.updateById(sysUser); sysUserMapper.updateById(sysUser);
@ -270,4 +359,541 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
vo.setOwnRoles(roleIdsByUserId); vo.setOwnRoles(roleIdsByUserId);
return vo; return vo;
} }
@Override
@Transactional
public Map<String, String> importStaff(MultipartFile file) {
List<ExcelImpUserReq> impStaffReqList = ExcelImportHelper.readUser(file);
if (impStaffReqList.size() <= 0) {
//小于等于0为上传空模板的情况下 抛出异常
throw new BusinessException(BaseResponseCode.EXCEL_FILE_FORMAT_ERROR);
}
int count = 0;
List<ImportUserFailureVo> failVo1 = new ArrayList<ImportUserFailureVo>();
// 参数合法性校验,只能上传.xlsx后缀的文件
if (org.apache.commons.lang3.StringUtils.isBlank(file.getOriginalFilename())
|| !file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")).equals(".xlsx")) {
throw new BusinessException(BaseResponseCode.EXCEL_FILE_INVALID);
}
int size = impStaffReqList.size();
Map<String, String> map = new HashMap<>();
Long ii = 1L;//用于记录序列号
Integer countNum = 0;//用于失败原因排序 eg:1、XXXXX 2、XXXXXXX
try {
Integer countSuccess = 0;//统计成功次数
Integer countError = 0;//统计失败次数
List<String> workNumberList = new ArrayList<>();//用来储存新增前用户在excel中输入的所有学号用于excel中的数据判重
List<String> accountList = new ArrayList<>();//用来储存新增前用户在excel中输入的所有账号用于excel中的数据判重
for (int i = 0; i < impStaffReqList.size(); i++) {
boolean ret = true;
++ii;
ExcelImpUserReq req = impStaffReqList.get(i);
ImportUserFailureVo vo1 = new ImportUserFailureVo();
String errMsg = "";
//去除Excel中的全角半角空格
String realName = req.getRealName().replaceAll("\\u00A0", "").trim();
String username = req.getUserName().replaceAll("\\u00A0", "").trim();
String getRoleName = req.getRoleName().replaceAll("\\u00A0", "").trim();
String jobNumber = req.getJobNumber().replaceAll("\\u00A0", "").trim();
String dept = req.getDept().replaceAll("\\u00A0", "").trim();
String getPhone = req.getPhone().replaceAll("\\u00A0", "").trim();
String getEmail = req.getEmail().replaceAll("\\u00A0", "").trim();
String groupName = req.getGroupName().replaceAll("\\u00A0", "").trim();
if (!workNumberList.contains(req.getJobNumber())) {
workNumberList.add(req.getJobNumber());
} else {
//包含excel数据中存在相同学号
++countNum;
vo1.setJobNumber(jobNumber + " *必填项:(当前Excel数据中该工号已存在重复的!)");
errMsg += countNum + " *必填项:(当前Excel数据中该工号号已存在重复的)";
ret = false;
}
if (!accountList.contains(req.getUserName())) {
accountList.add(req.getUserName());
} else {
//包含excel数据中存在相同账号
++countNum;
vo1.setUserName(username + " *必填项:(当前Excel数据中该账号已存在重复的)");
errMsg += countNum + " *必填项:(当前Excel数据中该账号已存在重复的)";
ret = false;
}
//账号id
String usernameId = "0";
vo1.setIndex(ii);
//检验姓名
if ("".equals(realName)) {
++countNum;
vo1.setUserName(realName + " *必填项:(姓名不能为空) ");
errMsg += countNum + "必填项:(姓名不能为空)";
ret = false;
} else {
vo1.setUserName(realName);
}
//检验账号
if ("".equals(username)) {
++countNum;
vo1.setUserName(username + " *必填项:(账号不能为空)");
errMsg += countNum + " *必填项:(账号不能为空)";
ret = false;
} else {
LambdaQueryWrapper<SysUser> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(SysUser::getUsername, username);
SysUser selectOne = baseMapper.selectOne(queryWrapper);
//账号存在,验证该账号相关信息
if (ObjectUtil.isNotNull(selectOne)) {
if (username.equals(selectOne.getUsername())&&jobNumber.equals(selectOne.getJobNumber())){
usernameId=selectOne.getId();
}else {
++countNum;
vo1.setUserName(username + " *必填项:(账号已有重复的)");
errMsg += countNum + " *必填项:(账号已有重复的)";
ret = false;
}
} else {
vo1.setUserName(username + "");
}
}
List<String> roleIds = new ArrayList<>();
//检验角色
if ("".equals(getRoleName)) {
++countNum;
vo1.setRoleName(getRoleName + " *必填项:(角色不能为空)");
errMsg += countNum + " *必填项:(角色不能为空)";
ret = false;
} else {
//分隔多个角色
String[] roleNames = getRoleName.split("/");
for (int r = 0; r < roleNames.length; r++) {
// 查询多个角色是否存在
LambdaQueryWrapper<SysRole> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(SysRole::getName, roleNames[r]);
SysRole role = roleService.getOne(queryWrapper);
if (role != null && !"超级管理员".equals(role.getName())) {
roleIds.add(role.getId());
//存在
vo1.setRoleName(getRoleName);
} else {
//不存在
vo1.setRoleName(getRoleName + " *必填项:(请输入系统中存在的角色)");
errMsg += countNum + " *必填项:(请输入系统中存在的角色)";
ret = false;
}
}
}
//检验工号
if ("".equals(jobNumber)) {
++countNum;
vo1.setJobNumber(jobNumber + " *必填项:(工号不能为空)");
errMsg += countNum + " *必填项:(工号不能为空)";
ret = false;
} else {
LambdaQueryWrapper<SysUser> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(SysUser::getJobNumber, jobNumber);
SysUser selectOne = baseMapper.selectOne(queryWrapper);
if (ObjectUtil.isNotNull(selectOne)) {
++countNum;
vo1.setJobNumber(jobNumber + " *必填项:(工号已经存在重复的)");
errMsg += countNum + " *必填项:(工号已经存在重复的)";
ret = false;
} else {
vo1.setJobNumber(jobNumber + "");
}
}
Integer groupId = 0;
//检验用户组
if (!"".equals(groupName)) {
LambdaQueryWrapper<UserGroup> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(UserGroup::getGroupName, groupName);
UserGroup userGroup1 = userGroupMapper.selectOne(queryWrapper);
if (ObjectUtil.isNotNull(userGroup1)) {
groupId=userGroup1.getId();
}else {
UserGroup userGroup = new UserGroup();
userGroup.setGroupName(groupName);
int insert = userGroupMapper.insert(userGroup);
groupId=userGroup.getId();
}
}
if (!"".equals(getPhone)) {
//校验手机号格式
if (!validPhoneNum("0", getPhone)) {
++countNum;
vo1.setPhone(getPhone + " *请输入正确的手机号!");
errMsg += countNum + " *请输入正确的手机号!";
ret = false;
} else {
//用户账号存在,手机号邮箱则跳过效验
if ("0".equals(usernameId)){
LambdaQueryWrapper<SysUser> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(SysUser::getPhone, getPhone);
SysUser selectOne = baseMapper.selectOne(queryWrapper);
if (ObjectUtil.isNotNull(selectOne)) {
++countNum;
vo1.setPhone(getPhone + " *该手机号已被绑定!");
errMsg += countNum + " *该手机号已被绑定!";
ret = false;
}
vo1.setPhone(getPhone);
}
}
} else {
vo1.setPhone(getPhone);
}
if (!"".equals(getEmail)) {
//校验邮箱格式
if (!isValidEmail(getEmail)) {
++countNum;
vo1.setEmail(getEmail + "*请输入正确的邮箱格式!");
errMsg += countNum + " *请输入正确的邮箱格式!";
ret = false;
} else {
if ("0".equals(usernameId)){
LambdaQueryWrapper<SysUser> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(SysUser::getEmail, getEmail);
SysUser selectOne = baseMapper.selectOne(queryWrapper);
if (ObjectUtil.isNotNull(selectOne)) {
++countNum;
vo1.setEmail(getEmail + " *该邮箱已被绑定!");
errMsg += countNum + " *该邮箱已被绑定!";
ret = false;
}
vo1.setEmail(getEmail);
}
}
} else {
vo1.setEmail(getEmail);
}
ArrayList<String> architectureIds = new ArrayList<>();
//检验所在部门
if ("".equals(dept)) {
++countNum;
vo1.setDept(dept + " *必填项:(请输入正确的员工架构!)");
errMsg += countNum + " *必填项:(请输入正确的员工架构!)";
ret = false;
} else {
if (ret){
//检验是否有多部门
String[] multi = dept.split(",");
//多部门进行循环添加每个部门
if (multi.length>1){
for (int d = 0; d < multi.length; d++) {
HashMap<String, Object> hashMap = automaticAddArchitecture(multi[d], countNum, dept, vo1);
Object countNum1 = hashMap.get("countNum");
//存在错误数据
if (countNum1!=null){
countNum = (Integer) countNum1;
Object vo11 = hashMap.get("vo1");
vo1 = (ImportUserFailureVo) vo11;
Object errMsg1 = hashMap.get("errMsg");
errMsg = (String) errMsg1;
Object ret1 = hashMap.get("ret");
ret = (boolean) ret1;
}else {
//保存架构id
Object architectureId = hashMap.get("architectureId");
String id = "0";
if (architectureId!=null){
id = (String) architectureId;
architectureIds.add(id);
}
}
}
}else{
HashMap<String, Object> hashMap = automaticAddArchitecture(dept, countNum, dept, vo1);
Object countNum1 = hashMap.get("countNum");
//存在错误数据
if (countNum1!=null){
countNum = (Integer) countNum1;
Object vo11 = hashMap.get("vo1");
vo1 = (ImportUserFailureVo) vo11;
Object errMsg1 = hashMap.get("errMsg");
errMsg = (String) errMsg1;
Object ret1 = hashMap.get("ret");
ret = (boolean) ret1;
}else {
//保存架构id
Object architectureId = hashMap.get("architectureId");
String id = "0";
if (architectureId!=null){
id = (String) architectureId;
architectureIds.add(id);
}
}
}
}
}
vo1.setFailureMsg(errMsg);
countNum = 0;
failVo1.add(vo1);
//ret判断 新增成功的插入到数据库 否则则不新增至数据库
if (ret) {
//用户账号不存在
if ("0".equals(usernameId)){
SysUser vo = new SysUser();
vo.setSalt(PasswordUtils.getSalt());
String encode = PasswordUtils.encode("111aaa", vo.getSalt());
vo.setPassword(encode);
vo.setStatus(1);
vo.setCreateWhere(1);
if (groupId!=0){
vo.setGroupId(groupId.toString());
}
sysUserMapper.insert(vo);
if (!CollectionUtils.isEmpty(architectureIds)) {
for (String deptId : architectureIds) {
UserDept userDept = new UserDept();
userDept.setUserId(vo.getId());
userDept.setDeptId(deptId);
userDeptMapper.insert(userDept);
}
}
//用户账号赋予角色
UserRoleOperationReqVO reqVO = new UserRoleOperationReqVO();
reqVO.setUserId(vo.getId());
reqVO.setRoleIds(roleIds);
userRoleService.addUserRoleInfo(reqVO);
}else {
//导入新部门、赋予新角色
List<UserDept> userDepts = userDeptMapper.
selectList(new QueryWrapper<UserDept>().eq("user_id", usernameId));
ArrayList<String> staffDepartmentIds = new ArrayList<>();
for ( UserDept userDept : userDepts) {
staffDepartmentIds.add(userDept.getDeptId());
}
for (String architectureId : architectureIds) {
if (!staffDepartmentIds.contains(architectureId)){
UserDept userDept = new UserDept();
userDept.setUserId(usernameId);
userDept.setDeptId(architectureId);
userDeptMapper.insert(userDept);
}
}
//用户账号赋予角色
UserRoleOperationReqVO reqVO = new UserRoleOperationReqVO();
reqVO.setUserId(usernameId);
reqVO.setRoleIds(roleIds);
userRoleService.addUserRoleInfo(reqVO);
}
//countSuccess:统计累计成功次数
countSuccess++;
} else {
//countError:累计失败次数
countError++;
}
}
String exportCode = "";
// 有导入失败的数据,才会存入redis
if (countError > 0) {
//生成token
exportCode = "FAILURE_IMPORT" + UUID.randomUUID().toString().replace("-", "");
ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
List<ImportUserFailureVo> collect = failVo1.stream().filter(importStaffFailureVo -> {
return !importStaffFailureVo.getFailureMsg().equals("");
}).collect(Collectors.toList());
String failureVOJson = JSON.toJSONString(collect);
ops.set(exportCode, failureVOJson, 30 * 60, TimeUnit.SECONDS);
}
map.put("exportCode", exportCode);//返回导出code
map.put("successNum", countSuccess + "");//本次新增成功数量
map.put("failureNum", countError + "");//本次新增失败数量
return map;
} catch (RuntimeException e) {
System.err.println(e.getMessage());
throw new RuntimeException();
}
}
/**
* 组织架构判重,返回下一层级的父id
*
*/
public String checkArchitectureRepeat(String name ,String pid){
QueryWrapper<SysDept> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("name",name).eq("pid",pid);
SysDept sysDept = sysDeptMapper.selectOne(queryWrapper);
if (sysDept!=null){
return sysDept.getId();
}
return null;
}
/**
* 根据导入部门自动添加组织架构
*/
public HashMap<String, Object> automaticAddArchitecture(String architectureName,Integer countNum,
String dept,ImportUserFailureVo vo1){
HashMap<String, Object> map = Maps.newHashMap();
//获取部门层级
String[] split = architectureName.split("/");
if (split.length>6){
map.put("countNum",++countNum);
map.put("vo1",vo1.setDept(dept + " 员工架构暂不支持第7层级"));
map.put("errMsg",countNum + " 员工架构暂不支持第7层级");
map.put("ret",false);
return map;
}
// 检验输入的一级部门是否存在
//查询一级部门信息
QueryWrapper<SysDept> queryWrapper1 = new QueryWrapper<>();
queryWrapper1.eq("name", split[0]);
SysDept sysDept = sysDeptMapper.selectOne(queryWrapper1);
if (sysDept == null) {
//为空表示不存在该部门,一级部门不存在,表示子级部门都能直接新增,达底端返回部门id
String pid = "0";
for (int j = 0; j < split.length; j++) {
SysDept sysDept1 = new SysDept();
sysDept1.setName(split[j]);
sysDept1.setPid(pid);
int insert = sysDeptMapper.insert(sysDept1);
//添加成功后id赋值给下一层级父id
if (insert>0){
pid = sysDept1.getId();
}
//最后返回部门id
if (split.length-1==j){
map.put("architectureId",pid);
}
}
} else {
String nextLevelPid = sysDept.getId();
//存在一级部门,循环查询下一层级,存在则继续向下判断,否则进行新增,到达底端返回部门id
int pid = 1;
for (int j = 1; j < split.length; j++) {
String nextPid = checkArchitectureRepeat(split[j],nextLevelPid);
//都存在,最后一次循环返回部门id
if (split.length-1==j){
map.put("architectureId",nextPid);
}
//层级已存在,进入下次循环
if (nextPid!=null){
nextLevelPid = nextPid;
continue;
}
//该层级不存在,进行新增
SysDept sysDept1 = new SysDept();
sysDept1.setName(split[j]);
sysDept1.setPid(nextLevelPid);
int insert = sysDeptMapper.insert(sysDept1);
//添加成功后id赋值给下一层级父id
if (insert>0){
nextLevelPid = sysDept1.getId();
}
//最后返回部门id
if (split.length-1==j){
map.put("architectureId",nextLevelPid);
}
}
}
return map;
}
/**
* @Description : 校验手机号
* @Param checkType 校验类型0校验手机号码1校验座机号码2两者都校验满足其一就可
* @Param phoneNum
* @Author Rong---2021/10/18
*/
public static boolean validPhoneNum(String checkType, String phoneNum) {
boolean flag = false;
Pattern p1 = null;
Pattern p2 = null;
Matcher m = null;
p1 = Pattern.compile("^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\\d{8})?$");
p2 = Pattern.compile("^(0[0-9]{2,3}\\-)?([1-9][0-9]{6,7})$");
if ("0".equals(checkType)) {
System.out.println(phoneNum.length());
if (phoneNum.length() != 11) {
return false;
} else {
m = p1.matcher(phoneNum);
flag = m.matches();
}
} else if ("1".equals(checkType)) {
if (phoneNum.length() < 11 || phoneNum.length() >= 16) {
return false;
} else {
m = p2.matcher(phoneNum);
flag = m.matches();
}
} else if ("2".equals(checkType)) {
if (!((phoneNum.length() == 11 && p1.matcher(phoneNum).matches()) || (phoneNum.length() < 16 && p2.matcher(phoneNum).matches()))) {
return false;
} else {
flag = true;
}
}
return flag;
}
/**
* @Description : 校验邮箱
* @Param email
* @Author Rong---2021/10/18
*/
public static boolean isValidEmail(String email) {
if ((email != null) && (!email.isEmpty())) {
return Pattern.matches("^(\\w+([-.][A-Za-z0-9]+)*){3,18}@\\w+([-.][A-Za-z0-9]+)*\\.\\w+([-.][A-Za-z0-9]+)*$", email);
}
return false;
}
@Override
public void exportFailureRecord(HttpServletResponse response, String token) throws IOException {
if (StringUtils.isEmpty(token)) {
return;
}
ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
//获取数据
String record = ops.get(token);
if (StringUtils.isEmpty(record)) {
return;
}
List<ImportUserFailureVo> parse = JSON.parseObject(record, new TypeReference<List<ImportUserFailureVo>>() {
});
parse.sort(Comparator.comparing(ImportUserFailureVo::getIndex));
// 告诉浏览器用什么软件可以打开此文件
response.setHeader("content-Type", "application/vnd.ms-excel");
// 下载文件的默认名称
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("员工导入失败数据表", "UTF-8") + ".xls");
//编码
response.setCharacterEncoding("UTF-8");
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), ImportUserFailureVo.class, parse);
ExportParams exportParams = new ExportParams(null, "delivery", ExcelType.XSSF);
exportParams.setStyle(ExcelStyleUtil.class);
workbook.write(response.getOutputStream());
}
} }

@ -0,0 +1,55 @@
package com.huoran.iasf.vo;
import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelTarget;
import com.huoran.iasf.common.utils.ExcelAttribute;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import lombok.experimental.Accessors;
@Data
@ToString
@Accessors(chain = true)
@ExcelTarget("ImportStaffFailureVo")
public class ImportUserFailureVo {
//第几行
private Long index;
@Excel(name = "姓名", orderNum = "1", isImportField = "id", width = 30)
@ApiModelProperty(value = "姓名")
private String realName;
@ApiModelProperty(value = "账号")
@Excel(name = "账号", orderNum = "2", mergeVertical = false, isImportField = "account", width = 30)
private String userName;
@ApiModelProperty(value = "角色")
@Excel(name = "角色", orderNum = "3", isImportField = "roleName", width = 30)
private String roleName;
@ApiModelProperty(value = "工号")
@Excel(name = "工号", orderNum = "4", isImportField = "workNumber", width = 30)
private String jobNumber;
@ApiModelProperty(value = "所在部门")
@Excel(name = "所在部门", orderNum = "5", isImportField = "dept", width = 30)
private String dept;
@ApiModelProperty(value = "手机号码")
@Excel(name = "手机号码", orderNum = "6", isImportField = "phone", width = 20)
private String phone;
@ApiModelProperty(value = "邮箱")
@Excel(name = "邮箱", orderNum = "7", isImportField = "email", width = 20)
private String email;
@ApiModelProperty(value = "用户组")
@Excel(name = "用户组", orderNum = "8", isImportField = "groupName", width = 20)
private String groupName;
@ExcelAttribute(sort = 9)
@Excel(name = "失败原因", orderNum = "9", isImportField = "failureMsg", width = 50)
private String failureMsg;
}

@ -0,0 +1,45 @@
package com.huoran.iasf.vo.req;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* @Author chen
* @DATE 2022/8/15 17:20
* @Version 1.0
*/
@Data
@ApiModel(value = "批量导入用户数据")
public class ExcelImpUserReq {
@ApiModelProperty(value = "姓名")
@NotNull(message = "姓名不能为空!")
private String realName;
@NotNull(message = "账号不能为空!")
@ApiModelProperty(value = "账号")
private String userName;
@ApiModelProperty(value = "角色")
@NotNull(message = "角色不能为空!")
private String roleName;
@ApiModelProperty(value = "工号")
@NotNull(message = "工号不能为空!")
private String jobNumber;
@ApiModelProperty(value = "所在部门")
private String dept;
@ApiModelProperty(value = "手机号码")
private String phone;
@ApiModelProperty(value = "邮箱")
private String email;
@ApiModelProperty(value = "用户组")
private String groupName;
}

@ -0,0 +1,28 @@
package com.huoran.iasf.vo.req;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @Author chen
* @DATE 2022/8/15 15:27
* @Version 1.0
*/
@Data
public class UserListReq {
@ApiModelProperty(value = "类型:必填一个(1.所有员工 2.未加入部门的员工)", required = true, example = "1")
private Integer type;
@ApiModelProperty(value = "搜索关键词", example = "1")
private String keyWord;
@ApiModelProperty(value = "员工部门主键ID", example = "2")
private String deptArchitectureId;
@ApiModelProperty(value = "当前页数", name = "pageNum", example = "1", required = true)
private Integer pageNum;
@ApiModelProperty(value = "当前页需要显示的数量", name = "pageSize", example = "10", required = true)
private Integer pageSize;
}

@ -20,11 +20,11 @@ public class DeptRespNodeVO {
@ApiModelProperty(value = "组织编码") @ApiModelProperty(value = "组织编码")
private String deptNo; private String deptNo;
@ApiModelProperty(value = "组织名称") @ApiModelProperty(value = "部门名称")
private String title; private String name;
@ApiModelProperty(value = "组织名称") // @ApiModelProperty(value = "组织名称")
private String label; // private String label;
@ApiModelProperty(value = "组织父级id") @ApiModelProperty(value = "组织父级id")
private String pid; private String pid;
@ -35,19 +35,19 @@ public class DeptRespNodeVO {
@ApiModelProperty(value = "组织关系id") @ApiModelProperty(value = "组织关系id")
private String relationCode; private String relationCode;
@ApiModelProperty(value = "是否展开 默认不展开(false)") /* @ApiModelProperty(value = "是否展开 默认不展开(false)")
private boolean spread = true; private boolean spread = true;
@ApiModelProperty(value = "是否选中") @ApiModelProperty(value = "是否选中")
private boolean checked = false; private boolean checked = false;
private boolean disabled = false; private boolean disabled = false;*/
@ApiModelProperty(value = "子集") @ApiModelProperty(value = "子集")
private List<?> children; private List<?> children;
public String getLabel() { // public String getLabel() {
return title; // return title;
} // }
} }

@ -16,8 +16,9 @@ import java.util.List;
public class PermissionRespNode { public class PermissionRespNode {
@ApiModelProperty(value = "id") @ApiModelProperty(value = "id")
private String id; private String id;
@ApiModelProperty(value = "菜单权限名称") @ApiModelProperty(value = "菜单权限名称")
private String title; private String name;
@ApiModelProperty(value = "菜单权限标识,shiro 适配restful") @ApiModelProperty(value = "菜单权限标识,shiro 适配restful")
private String perms; private String perms;

@ -0,0 +1,65 @@
package com.huoran.iasf.vo.resp;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* @Author chen
* @DATE 2022/8/15 15:34
* @Version 1.0
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "UserListResp", description = "用户列表")
public class UserListResp {
@ApiModelProperty(value = "组织架构ID")
private String deptArchitectureId;
@ApiModelProperty(value = "组织架构名称(部门名称)")
private String deptArchitectureName;
@ApiModelProperty(value = "用户组id")
private String groupId;
@ApiModelProperty(value = "用户组名称")
private String groupName;
@ApiModelProperty(value = "职工姓名")
private String realName;
@ApiModelProperty(value = "账户状态(1.正常 0.锁定 )")
private Integer status;
@ApiModelProperty(value = "工号")
private String jobNumber;
@ApiModelProperty(value = "电话")
private String phone;
@ApiModelProperty(value = "邮箱")
private String email;
//用于列表逗号隔开展示
@ApiModelProperty(value = "角色")
private String roleName;
@ApiModelProperty(value = "角色id")
private String roleId;
@ApiModelProperty(value = "账号")
private String username;
@ApiModelProperty(value = "用户id")
private String id;
@ApiModelProperty(value = "创建时间")
private String createTime;
@ApiModelProperty(value = "最后登陆时间")
private String lastLoginTime;
}

@ -61,7 +61,7 @@ public class CodeGenerator {
// 5、策略配置 // 5、策略配置
StrategyConfig strategy = new StrategyConfig(); StrategyConfig strategy = new StrategyConfig();
strategy.setInclude("sys_user_group"); strategy.setInclude("sys_user_dept");
strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略 strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略
strategy.setTablePrefix("sys_"); //生成实体时去掉表前缀 strategy.setTablePrefix("sys_"); //生成实体时去掉表前缀

Loading…
Cancel
Save