初次提交
This commit is contained in:
@ -0,0 +1,22 @@
|
||||
package com.ho.user;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @description: 用户服务
|
||||
* @date 2022/8/9
|
||||
*/
|
||||
@SpringBootApplication(scanBasePackages = {"com.ho.user","com.ho.common.tools"})
|
||||
@MapperScan(basePackages = "com.ho.user.mapper")
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients(basePackages = {"com.ho.user.feignclient"})
|
||||
public class UserCenterApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(UserCenterApplication.class ,args);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,97 @@
|
||||
package com.ho.user.aop;
|
||||
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import org.apache.shiro.authz.AuthorizationException;
|
||||
import org.hibernate.validator.internal.engine.path.PathImpl;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @描述 全局异常处理
|
||||
* @创建人 fancl
|
||||
* @创建时间 2021/2/26
|
||||
* @修改人
|
||||
*/
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
|
||||
//绑定Exception
|
||||
@ExceptionHandler(Exception.class)
|
||||
public <T> DataResult<T> handle(Exception ex) {
|
||||
|
||||
log.error("业务异常e:", ex);
|
||||
//异常的日志都打印记录
|
||||
log.error(ex.getMessage() + ":" + ex.getMessage());
|
||||
|
||||
|
||||
DataResult result = new DataResult(BaseResponseCode.OPERATION_ERRO);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//绑定 BusinessException
|
||||
@ExceptionHandler(BusinessException.class)
|
||||
public <T> DataResult<T> handler(BusinessException businessException) {
|
||||
log.error("业务 BusinessException 异常e:", businessException);
|
||||
return new DataResult<>(businessException.getMessageCode(), businessException.getDetailMessage());
|
||||
}
|
||||
|
||||
//绑定 AuthorizationException
|
||||
@ExceptionHandler(AuthorizationException.class)
|
||||
public <T> DataResult<T> handler(AuthorizationException authorizationException) {
|
||||
log.error("AuthorizationException 异常e:", authorizationException);
|
||||
|
||||
return new DataResult<>(BaseResponseCode.PERMISSION_DENIED);
|
||||
}
|
||||
/**
|
||||
* 参数校验异常处理类
|
||||
* 参数为实体类
|
||||
*
|
||||
* @param ex
|
||||
* @return
|
||||
*/
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
public DataResult handleBindException(MethodArgumentNotValidException ex) {
|
||||
FieldError fieldError = ex.getBindingResult().getFieldError();
|
||||
log.error("参数校验异常:{}({})", fieldError.getDefaultMessage(), fieldError.getField());
|
||||
DataResult result = new DataResult(BaseResponseCode.METHODARGUMENTNOTVALIDEXCEPTION.getCode(), fieldError.getDefaultMessage());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数校验 非实体请求参数
|
||||
*
|
||||
* @param ex
|
||||
* @return
|
||||
*/
|
||||
@ExceptionHandler(value = ConstraintViolationException.class)
|
||||
public DataResult handle(ConstraintViolationException ex) {
|
||||
log.error("业务ConstraintViolationException异常e:", ex);
|
||||
StringBuilder msg = new StringBuilder();
|
||||
Set<ConstraintViolation<?>> constraintViolations = ex.getConstraintViolations();
|
||||
for (ConstraintViolation<?> constraintViolation : constraintViolations) {
|
||||
PathImpl pathImpl = (PathImpl) constraintViolation.getPropertyPath();
|
||||
String paramName = pathImpl.getLeafNode().getName();
|
||||
String message = constraintViolation.getMessage();
|
||||
msg.append(message);
|
||||
}
|
||||
log.error(msg.toString(), ex);
|
||||
// 返回参数错误提示
|
||||
return new DataResult(BaseResponseCode.METHODARGUMENTNOTVALIDEXCEPTION);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
161
user-service/src/main/java/com/ho/user/aop/SysLogAspect.java
Normal file
161
user-service/src/main/java/com/ho/user/aop/SysLogAspect.java
Normal file
@ -0,0 +1,161 @@
|
||||
package com.ho.user.aop;
|
||||
|
||||
import cn.hutool.core.lang.Snowflake;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.entity.UserDetailRespVO;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.util.IPUtils;
|
||||
import com.ho.common.tools.util.RedisCommon;
|
||||
import com.ho.user.api.entity.SysLog;
|
||||
import com.ho.user.mapper.SysLogMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SysLogAspect {
|
||||
|
||||
@Autowired
|
||||
RedisCommon redisCommon;
|
||||
|
||||
@Autowired
|
||||
Snowflake snowflake;
|
||||
|
||||
@Autowired
|
||||
private SysLogMapper sysLogMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 此处的切点是注解的方式
|
||||
* 只要出现 @LogAnnotation注解都会进入
|
||||
* 改为切入点是controller,不然日志记录不清晰,只有LogAnnotation才入库
|
||||
*/
|
||||
//@Pointcut("@annotation(com.ho.common.tools.annotation.LogAnnotation)")
|
||||
@Pointcut("execution(* com.ho.*.controller.*.*(..))")
|
||||
public void logPointCut() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 环绕增强,相当于MethodInterceptor
|
||||
*
|
||||
* @param point
|
||||
* @return
|
||||
* @throws Throwable
|
||||
*/
|
||||
@Around("logPointCut()")
|
||||
public Object around(ProceedingJoinPoint point) throws Throwable {
|
||||
long beginTime = System.currentTimeMillis();
|
||||
ServletRequestAttributes servletAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = servletAttributes.getRequest();
|
||||
MethodSignature signature = (MethodSignature) point.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
String url = request.getRequestURL().toString();
|
||||
String className = point.getTarget().getClass().getName();
|
||||
String methodName = signature.getName();
|
||||
log.info("请求url:{} ,method:{}, 开始时间: {}", url, method, beginTime);
|
||||
//请求参数
|
||||
String params = null;
|
||||
try {
|
||||
//请求的参数
|
||||
Object[] args = point.getArgs();
|
||||
//MultipartFile类型的跳过转Json
|
||||
if (args != null && args.length > 0 && args[0] != null) {
|
||||
String simpleClassName = args[0].getClass().getSimpleName();
|
||||
log.info("SimpleClassName:" + simpleClassName);
|
||||
//不包含文件类型才打印日志
|
||||
if (!StringUtils.isBlank(simpleClassName) && !simpleClassName.contains("Multipart")) {
|
||||
params = JSON.toJSONString(args[0]);
|
||||
log.info("params:" + params);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
UserDetailRespVO user = null;
|
||||
SimpleUser simpleUser = null;
|
||||
//是否是token忽略
|
||||
TokenIgnore tokenIgnoreAnnotation = method.getAnnotation(TokenIgnore.class);
|
||||
if (tokenIgnoreAnnotation == null) {
|
||||
log.info("methodName:{}, className:{}", methodName, className);
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
|
||||
if (!StringUtils.isEmpty(token)) {
|
||||
log.info("token:" + token);
|
||||
//如果是登陆接口,忽略token判断
|
||||
String tokenKey = RedisKeyConstant.User.TOKEN + token;
|
||||
//用户信息
|
||||
user = (UserDetailRespVO) redisCommon.get(tokenKey);
|
||||
String userNameKey = RedisKeyConstant.User.USER_NAME + user.getLoginChannel() + ":" + user.getUsername();
|
||||
simpleUser = (SimpleUser) redisCommon.get(userNameKey);
|
||||
if(simpleUser ==null){
|
||||
log.info("User token has expired ! token :{}", token);
|
||||
throw new BusinessException(BaseResponseCode.TOKEN_PARSE_ERROR);
|
||||
}
|
||||
log.info("userName: {}, groupId:{}, deptId:{}", user.getUsername(), simpleUser.getGroupId(), simpleUser.getDeptId());
|
||||
}
|
||||
}
|
||||
//日志注解
|
||||
LogAnnotation logAnnotation = method.getAnnotation(LogAnnotation.class);
|
||||
//执行目标方法
|
||||
//执行方法
|
||||
Object result = point.proceed();
|
||||
//方法执行结果
|
||||
// log.info("返回:" + JSON.toJSONString(result));
|
||||
//log.info("返回");
|
||||
//执行时长(毫秒)
|
||||
long time = System.currentTimeMillis() - beginTime;
|
||||
log.info("耗时:{}, url:{}" ,time, url);
|
||||
if(time> CommonConstant.timeoutMilliSeconds){
|
||||
log.error("接口超时: url:{}" ,url);
|
||||
}
|
||||
//有日志注解的入库
|
||||
if (logAnnotation != null) {
|
||||
SysLog sysLog = new SysLog();
|
||||
//设置IP地址
|
||||
sysLog.setIp(IPUtils.getIpAddr(request));
|
||||
sysLog.setParams(params);
|
||||
sysLog.setMethod(methodName);
|
||||
sysLog.setOperation(logAnnotation.title() + "-" + logAnnotation.action());
|
||||
//保存日志
|
||||
try {
|
||||
saveSysLog(sysLog, user, simpleUser, time);
|
||||
} catch (Exception e) {
|
||||
log.error("e={}", e);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//保存日志
|
||||
private void saveSysLog(SysLog sysLog, UserDetailRespVO user, SimpleUser simpleUser, long time) {
|
||||
sysLog.setId(snowflake.nextId());
|
||||
sysLog.setGroupId(simpleUser.getGroupId());
|
||||
sysLog.setDeptId(simpleUser.getDeptId());
|
||||
sysLog.setUsername(user.getUsername());
|
||||
sysLog.setUserId(user.getUserId());
|
||||
sysLog.setTime((int) time);
|
||||
log.info(sysLog.toString());
|
||||
sysLogMapper.insertSelective(sysLog);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package com.ho.user.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc:
|
||||
* @date 2022/8/16
|
||||
*/
|
||||
//@Configuration
|
||||
public class CorsConfig {
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
//1. 添加 CORS配置信息
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
//放行哪些原始域
|
||||
config.addAllowedOrigin("*");
|
||||
//是否发送 Cookie
|
||||
config.setAllowCredentials(true);
|
||||
//放行哪些请求方式
|
||||
config.addAllowedMethod("*");
|
||||
//放行哪些原始请求头部信息
|
||||
config.addAllowedHeader("*");
|
||||
//暴露哪些头部信息
|
||||
config.addExposedHeader("*");
|
||||
//2. 添加映射路径
|
||||
UrlBasedCorsConfigurationSource corsConfigurationSource = new UrlBasedCorsConfigurationSource();
|
||||
corsConfigurationSource.registerCorsConfiguration("/**",config);
|
||||
//3. 返回新的CorsFilter
|
||||
return new CorsFilter(corsConfigurationSource);
|
||||
}
|
||||
}
|
||||
183
user-service/src/main/java/com/ho/user/config/RedisCache.java
Normal file
183
user-service/src/main/java/com/ho/user/config/RedisCache.java
Normal file
@ -0,0 +1,183 @@
|
||||
package com.ho.user.config;
|
||||
|
||||
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.UserDetailRespVO;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.shiro.authz.SimpleAuthorizationInfo;
|
||||
import org.apache.shiro.cache.Cache;
|
||||
import org.apache.shiro.cache.CacheException;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @ClassName: RedisCache
|
||||
* TODO:类文件简单描述
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/6 13:53
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/6 13:53
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
@Slf4j
|
||||
public class RedisCache<K, V> implements Cache<K, V> {
|
||||
private final static String PREFIX = "shiro-cache:";
|
||||
private String cacheKey;
|
||||
private long expire = 2;
|
||||
|
||||
|
||||
private RedisService redisService;
|
||||
|
||||
public RedisCache(String name, RedisService redisService) {
|
||||
this.redisService = redisService;
|
||||
//this.cacheKey = PREFIX + name + ":";
|
||||
this.cacheKey = PREFIX + name + ":";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public V get(K key) throws CacheException {
|
||||
log.info("Shiro从缓存中获取数据KEY值[{}]",key);
|
||||
if (key == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
String redisCacheKey = getRedisCacheKey(key);
|
||||
Object rawValue = redisService.get(redisCacheKey);
|
||||
if (rawValue == null) {
|
||||
return null;
|
||||
}
|
||||
//redis存的是对象本身, 不再是String,使用对象类型直接转换
|
||||
//SimpleAuthorizationInfo simpleAuthenticationInfo= JSON.parseObject(rawValue.toString(),SimpleAuthorizationInfo.class);
|
||||
SimpleAuthorizationInfo simpleAuthenticationInfo= (SimpleAuthorizationInfo)rawValue;
|
||||
V value = (V) simpleAuthenticationInfo;
|
||||
return value;
|
||||
} catch (Exception e) {
|
||||
throw new CacheException(e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public V put(K key, V value) throws CacheException {
|
||||
log.info("put key [{}]",key);
|
||||
if (key == null) {
|
||||
log.warn("Saving a null key is meaningless, return value directly without call Redis.");
|
||||
return value;
|
||||
}
|
||||
try {
|
||||
String redisCacheKey = getRedisCacheKey(key);
|
||||
redisService.set(redisCacheKey, value != null ? value : null, expire,TimeUnit.HOURS);
|
||||
return value;
|
||||
} catch (Exception e) {
|
||||
throw new CacheException(e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public V remove(K key) throws CacheException {
|
||||
log.info("remove key [{}]",key);
|
||||
if (key == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
String redisCacheKey = getRedisCacheKey(key);
|
||||
Object rawValue = redisService.get(redisCacheKey);
|
||||
V previous = (V) rawValue;
|
||||
redisService.delete(redisCacheKey);
|
||||
return previous;
|
||||
} catch (Exception e) {
|
||||
throw new CacheException(e);
|
||||
}
|
||||
}
|
||||
private String getRedisCacheKey(K key) {
|
||||
if(null==key){
|
||||
return null;
|
||||
}else {
|
||||
UserDetailRespVO user = (UserDetailRespVO)redisService.get(RedisKeyConstant.User.TOKEN + key);
|
||||
|
||||
//return this.cacheKey+ JwtTokenUtil.getUserId(key.toString());
|
||||
return this.cacheKey + user.getUserId();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void clear() throws CacheException {
|
||||
log.debug("clear cache");
|
||||
Set<String> keys = null;
|
||||
try {
|
||||
keys = redisService.keys(this.cacheKey + "*");
|
||||
} catch (Exception e) {
|
||||
log.error("get keys error", e);
|
||||
}
|
||||
if (keys == null || keys.size() == 0) {
|
||||
return;
|
||||
}
|
||||
for (String key: keys) {
|
||||
redisService.delete(key);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int size() {
|
||||
int result = 0;
|
||||
try {
|
||||
result = redisService.keys(this.cacheKey + "*").size();
|
||||
} catch (Exception e) {
|
||||
log.error("get keys error", e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Set<K> keys() {
|
||||
Set<String> keys = null;
|
||||
try {
|
||||
keys = redisService.keys(this.cacheKey + "*");
|
||||
} catch (Exception e) {
|
||||
log.error("get keys error", e);
|
||||
return Collections.emptySet();
|
||||
}
|
||||
if (CollectionUtils.isEmpty(keys)) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
Set<K> convertedKeys = new HashSet<>();
|
||||
for (String key:keys) {
|
||||
try {
|
||||
convertedKeys.add((K) key);
|
||||
} catch (Exception e) {
|
||||
log.error("deserialize keys error", e);
|
||||
}
|
||||
}
|
||||
return convertedKeys;
|
||||
}
|
||||
@Override
|
||||
public Collection<V> values() {
|
||||
Set<String> keys = null;
|
||||
try {
|
||||
keys = redisService.keys(this.cacheKey + "*");
|
||||
} catch (Exception e) {
|
||||
log.error("get values error", e);
|
||||
return Collections.emptySet();
|
||||
}
|
||||
if (CollectionUtils.isEmpty(keys)) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
List<V> values = new ArrayList<V>(keys.size());
|
||||
for (String key : keys) {
|
||||
V value = null;
|
||||
try {
|
||||
value = (V) redisService.get(key);
|
||||
} catch (Exception e) {
|
||||
log.error("deserialize values= error", e);
|
||||
}
|
||||
if (value != null) {
|
||||
values.add(value);
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableList(values);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package com.ho.user.config;
|
||||
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import org.apache.shiro.cache.Cache;
|
||||
import org.apache.shiro.cache.CacheException;
|
||||
import org.apache.shiro.cache.CacheManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* @ClassName: RedisCacheManager
|
||||
* TODO:类文件简单描述
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/6 17:53
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/6 17:53
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
public class RedisCacheManager implements CacheManager {
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
|
||||
@Override
|
||||
public <K, V> Cache<K, V> getCache(String name) throws CacheException {
|
||||
return new RedisCache(name, redisService);
|
||||
}
|
||||
|
||||
}
|
||||
49
user-service/src/main/java/com/ho/user/config/RsaConfig.java
Normal file
49
user-service/src/main/java/com/ho/user/config/RsaConfig.java
Normal file
@ -0,0 +1,49 @@
|
||||
package com.ho.user.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.interfaces.RSAPrivateKey;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: RSA组件类
|
||||
* @date 2022/11/14
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class RsaConfig {
|
||||
|
||||
//
|
||||
@Value("${rsa.pubKey}")
|
||||
private String rsaPubKey;
|
||||
|
||||
@Value("${rsa.privateKey}")
|
||||
private String rsaPrivateKeyPath;
|
||||
|
||||
//@Bean
|
||||
//todo 后续需要读取文件内容
|
||||
RSAPrivateKey rsaPrivateKey() throws Exception{
|
||||
log.info("初始化RSA私钥");
|
||||
File f = new File(rsaPrivateKeyPath);
|
||||
FileInputStream fis = new FileInputStream(f);
|
||||
DataInputStream dis = new DataInputStream(fis);
|
||||
byte[] keyBytes = new byte[(int)f.length()];
|
||||
dis.readFully(keyBytes);
|
||||
dis.close();
|
||||
PKCS8EncodedKeySpec spec =new PKCS8EncodedKeySpec(keyBytes);
|
||||
KeyFactory kf = KeyFactory.getInstance("RSA");
|
||||
log.info("RSA私钥初始化完毕");
|
||||
|
||||
return (RSAPrivateKey)kf.generatePrivate(spec);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
package com.ho.user.config;
|
||||
|
||||
|
||||
import com.ho.user.util.JwtTokenUtil;
|
||||
import com.ho.user.util.TokenSettings;
|
||||
|
||||
/**
|
||||
* @ClassName: StaticContextInitializer
|
||||
* TODO:类文件简单描述
|
||||
* @Author: 小霍
|
||||
* @CreateDate: 2019/9/26 10:07
|
||||
* @UpdateUser: 小霍
|
||||
* @UpdateDate: 2019/9/26 10:07
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
//@Component
|
||||
public class StaticInitializerUtil {
|
||||
private TokenSettings tokenSettings;
|
||||
|
||||
public StaticInitializerUtil(TokenSettings tokenSettings) {
|
||||
JwtTokenUtil.setTokenSettings(tokenSettings);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
package com.ho.user.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
/**
|
||||
* @描述 swagger2配置
|
||||
* @创建人 fancl
|
||||
* @创建时间 2021/2/12
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class Swagger2Config {
|
||||
|
||||
@Value("${swagger2.projectName}")
|
||||
private String projectName;
|
||||
|
||||
@Value("${swagger2.controllerPath}")
|
||||
private String controllerPath;
|
||||
|
||||
//根据配置启用或关闭swagger接口
|
||||
@Value("${swagger2.enable}")
|
||||
private Boolean enable;
|
||||
|
||||
//Swagger2接口文档版本
|
||||
public static final String VERSION = "1.0.0";
|
||||
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage(controllerPath))
|
||||
.paths(PathSelectors.any()) //可以根据url路径设置哪些请求加入文档,忽略哪些请求
|
||||
.build()
|
||||
.enable(enable);
|
||||
}
|
||||
|
||||
public ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title(projectName) //设置文档的标题
|
||||
.description("REST API") //设置文档的描述
|
||||
.version(VERSION)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,79 @@
|
||||
package com.ho.user.config.shiro;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.apache.shiro.web.filter.AccessControlFilter;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* @ClassName: CustomAccessControlFilter
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/6 23:22
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/6 23:22
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
@Slf4j
|
||||
public class CustomAccessControlFilter extends AccessControlFilter {
|
||||
@Override
|
||||
protected boolean isAccessAllowed(ServletRequest servletRequest, ServletResponse servletResponse, Object o) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onAccessDenied(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException {
|
||||
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
||||
try {
|
||||
Subject subject = getSubject(servletRequest, servletResponse);
|
||||
log.info(request.getMethod());
|
||||
log.info(request.getRequestURL().toString());
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
log.info("token:" +token);
|
||||
if (StringUtils.isEmpty(token)) {
|
||||
//这个地方抛异常不会被ControllerAdvise捕获,所以使用response
|
||||
//throw new BusinessException(BaseResponseCode.TOKEN_ERROR);
|
||||
customRsponse(BaseResponseCode.TOKEN_ERROR.getCode(), BaseResponseCode.TOKEN_ERROR.getMsg(), servletResponse);
|
||||
return false;
|
||||
}
|
||||
CustomPasswordToken customPasswordToken = new CustomPasswordToken(token);
|
||||
getSubject(servletRequest, servletResponse).login(customPasswordToken);
|
||||
}
|
||||
//只捕获认证异常
|
||||
catch (AuthenticationException e){
|
||||
log.error("AuthenticationException !!" + e.getMessage());
|
||||
customRsponse(BaseResponseCode.TOKEN_PAST_DUE.getCode(), BaseResponseCode.TOKEN_PAST_DUE.getMsg(), servletResponse);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void customRsponse(int code, String msg, ServletResponse response) {
|
||||
try {
|
||||
DataResult result = DataResult.getResult(code, msg);
|
||||
|
||||
response.setContentType("application/json; charset=utf-8");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
|
||||
String userJson = JSON.toJSONString(result);
|
||||
OutputStream out = response.getOutputStream();
|
||||
out.write(userJson.getBytes("UTF-8"));
|
||||
out.flush();
|
||||
} catch (IOException e) {
|
||||
log.error("eror={}", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,106 @@
|
||||
package com.ho.user.config.shiro;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.user.util.HttpContextUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.apache.shiro.web.filter.AccessControlFilter;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* @Desc: 这个是之前使用JWT时的Filter
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/6 23:22
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/6 23:22
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
@Slf4j
|
||||
public class CustomAccessControlFilterCopy extends AccessControlFilter {
|
||||
@Override
|
||||
protected boolean isAccessAllowed(ServletRequest servletRequest, ServletResponse servletResponse, Object o) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onAccessDenied(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException {
|
||||
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
||||
try {
|
||||
Subject subject = getSubject(servletRequest, servletResponse);
|
||||
log.info(request.getMethod());
|
||||
log.info(request.getRequestURL().toString());
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
if (StringUtils.isEmpty(token)) {
|
||||
throw new BusinessException(BaseResponseCode.TOKEN_ERROR);
|
||||
}
|
||||
CustomPasswordToken customPasswordToken = new CustomPasswordToken(token);
|
||||
getSubject(servletRequest, servletResponse).login(customPasswordToken);
|
||||
} catch (BusinessException exception) {
|
||||
if (HttpContextUtils.isAjaxRequest(request)) {
|
||||
customRsponse(exception.getMessageCode(), exception.getDetailMessage(), servletResponse);
|
||||
} else if (exception.getMessageCode() == BaseResponseCode.TOKEN_ERROR.getCode()) {
|
||||
servletRequest.getRequestDispatcher("/index/login").forward(servletRequest, servletResponse);
|
||||
} else if (exception.getMessageCode() == BaseResponseCode.UNAUTHORIZED_ERROR.getCode()) {
|
||||
servletRequest.getRequestDispatcher("/index/403").forward(servletRequest, servletResponse);
|
||||
} else {
|
||||
servletRequest.getRequestDispatcher("/index/500").forward(servletRequest, servletResponse);
|
||||
}
|
||||
return false;
|
||||
} catch (AuthenticationException e) {
|
||||
if (HttpContextUtils.isAjaxRequest(request)) {
|
||||
if (e.getCause() instanceof BusinessException) {
|
||||
BusinessException exception = (BusinessException) e.getCause();
|
||||
customRsponse(exception.getMessageCode(), exception.getDetailMessage(), servletResponse);
|
||||
} else {
|
||||
customRsponse(BaseResponseCode.SYSTEM_BUSY.getCode(), BaseResponseCode.SYSTEM_BUSY.getMsg(), servletResponse);
|
||||
}
|
||||
} else {
|
||||
servletRequest.getRequestDispatcher("/index/403").forward(servletRequest, servletResponse);
|
||||
}
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
if (HttpContextUtils.isAjaxRequest(request)) {
|
||||
if (e.getCause() instanceof BusinessException) {
|
||||
BusinessException exception = (BusinessException) e.getCause();
|
||||
customRsponse(exception.getMessageCode(), exception.getDetailMessage(), servletResponse);
|
||||
} else {
|
||||
customRsponse(BaseResponseCode.SYSTEM_BUSY.getCode(), BaseResponseCode.SYSTEM_BUSY.getMsg(), servletResponse);
|
||||
}
|
||||
} else {
|
||||
servletRequest.getRequestDispatcher("/index/500").forward(servletRequest, servletResponse);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void customRsponse(int code, String msg, ServletResponse response) {
|
||||
try {
|
||||
DataResult result = DataResult.getResult(code, msg);
|
||||
|
||||
response.setContentType("application/json; charset=utf-8");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
|
||||
String userJson = JSON.toJSONString(result);
|
||||
OutputStream out = response.getOutputStream();
|
||||
out.write(userJson.getBytes("UTF-8"));
|
||||
out.flush();
|
||||
} catch (IOException e) {
|
||||
log.error("eror={}", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
package com.ho.user.config.shiro;
|
||||
|
||||
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.util.RedisCommon;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.authc.AuthenticationInfo;
|
||||
import org.apache.shiro.authc.AuthenticationToken;
|
||||
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* desc: 判断token是否有效 从缓存中获取,没有获取到说明无效
|
||||
*
|
||||
*/
|
||||
@Slf4j
|
||||
public class CustomHashedCredentialsMatcher extends SimpleCredentialsMatcher {
|
||||
|
||||
@Autowired
|
||||
private RedisCommon redisCommon;
|
||||
|
||||
@Override
|
||||
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
|
||||
CustomPasswordToken customPasswordToken= (CustomPasswordToken) token;
|
||||
String accessToken = (String) customPasswordToken.getPrincipal();
|
||||
//String userId= JwtTokenUtil.getUserId(accessToken);
|
||||
String tokenKey = RedisKeyConstant.User.TOKEN + accessToken;
|
||||
//判断系统是否含有key,含有则
|
||||
if(redisCommon.hasKey(tokenKey)){
|
||||
//延长时间
|
||||
redisCommon.extendUserCachePair(accessToken ,null);
|
||||
}else{
|
||||
log.info("token is invalid!! {}" , accessToken);
|
||||
return false;
|
||||
//throw new BusinessException(BaseResponseCode.TOKEN_PAST_DUE);
|
||||
}
|
||||
|
||||
/*if(redisService.hasKey(Constant.JWT_REFRESH_KEY+userId)&&redisService.getExpire(Constant.JWT_REFRESH_KEY+userId, TimeUnit.MILLISECONDS)>JwtTokenUtil.getRemainingTime(accessToken)){
|
||||
if(!redisService.hasKey(Constant.JWT_REFRESH_IDENTIFICATION+accessToken)){
|
||||
throw new BusinessException(BaseResponseCode.TOKEN_PAST_DUE);
|
||||
}
|
||||
}*/
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package com.ho.user.config.shiro;
|
||||
|
||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||
|
||||
/**
|
||||
* @ClassName: CustomPasswordToken
|
||||
* TODO:类文件简单描述
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/6 17:58
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/6 17:58
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
public class CustomPasswordToken extends UsernamePasswordToken {
|
||||
private String token;
|
||||
|
||||
public CustomPasswordToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPrincipal() {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,99 @@
|
||||
package com.ho.user.config.shiro;
|
||||
|
||||
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.UserDetailRespVO;
|
||||
import com.ho.common.tools.util.RedisCommon;
|
||||
import com.ho.user.service.PermissionService;
|
||||
import com.ho.user.service.RoleService;
|
||||
import com.ho.user.service.UserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.authc.AuthenticationInfo;
|
||||
import org.apache.shiro.authc.AuthenticationToken;
|
||||
import org.apache.shiro.authc.SimpleAuthenticationInfo;
|
||||
import org.apache.shiro.authz.AuthorizationInfo;
|
||||
import org.apache.shiro.authz.SimpleAuthorizationInfo;
|
||||
import org.apache.shiro.realm.AuthorizingRealm;
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName: CustomRealm
|
||||
* TODO:类文件简单描述
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/6 18:02
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/6 18:02
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
@Slf4j
|
||||
public class CustomRealm extends AuthorizingRealm {
|
||||
@Autowired
|
||||
@Lazy
|
||||
private RedisCommon redisCommon;
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
private PermissionService permissionService;
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
private RoleService roleService;
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
UserService userService;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean supports(AuthenticationToken token) {
|
||||
return token instanceof CustomPasswordToken;
|
||||
}
|
||||
|
||||
//认知
|
||||
@Override
|
||||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
|
||||
CustomPasswordToken token = (CustomPasswordToken) authenticationToken;
|
||||
SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo(token.getPrincipal(), token.getPrincipal(), getName());
|
||||
return simpleAuthenticationInfo;
|
||||
}
|
||||
|
||||
//授权
|
||||
@Override
|
||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
|
||||
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
|
||||
String accessToken = (String) SecurityUtils.getSubject().getPrincipal();
|
||||
String userTokenKey = RedisKeyConstant.User.TOKEN + accessToken;
|
||||
|
||||
log.info("doGetAuthorizationInfo, accessToken:{}", accessToken);
|
||||
UserDetailRespVO user = (UserDetailRespVO) redisCommon.get(userTokenKey);
|
||||
if (user != null) {
|
||||
//List<String> roleNames = user.getRoleNames();
|
||||
List<String> roleNames = user.getRoles();
|
||||
if (roleNames != null && !roleNames.isEmpty()) {
|
||||
//authorizationInfo.addRoles(roleService.getRoleNames(userId));
|
||||
//直接把结果集放进去,避免再次执行一遍sql
|
||||
authorizationInfo.addRoles(roleNames);
|
||||
}
|
||||
if (user.getPowerList() != null) {
|
||||
authorizationInfo.setStringPermissions(new HashSet<>(user.getPowerList()));
|
||||
}
|
||||
} else {
|
||||
List<String> roleNames = roleService.getRoleNames(user.getUserId());
|
||||
if (roleNames != null && !roleNames.isEmpty()) {
|
||||
//直接把结果集放进去,避免再次执行一遍sql
|
||||
authorizationInfo.addRoles(roleNames);
|
||||
}
|
||||
authorizationInfo.setStringPermissions(permissionService.getPermissionsByUserId(user.getUserId()));
|
||||
}
|
||||
|
||||
return authorizationInfo;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,131 @@
|
||||
package com.ho.user.config.shiro;
|
||||
|
||||
|
||||
import com.ho.user.config.RedisCacheManager;
|
||||
import org.apache.shiro.mgt.SecurityManager;
|
||||
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
|
||||
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
||||
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
|
||||
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: ShiroConfig
|
||||
* @Author: fancl
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
@Configuration
|
||||
public class ShiroConfig {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
|
||||
DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
|
||||
defaultAdvisorAutoProxyCreator.setProxyTargetClass(true);
|
||||
return defaultAdvisorAutoProxyCreator;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CustomRealm customRealm() {
|
||||
CustomRealm customRealm = new CustomRealm();
|
||||
//不使用jwt, 改用自定义token方式,后续好扩展
|
||||
customRealm.setCredentialsMatcher(customHashedCredentialsMatcher());
|
||||
//增加缓存机制
|
||||
customRealm.setCacheManager(redisCacheManager());
|
||||
return customRealm;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SecurityManager securityManager() {
|
||||
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
|
||||
securityManager.setRealm(customRealm());
|
||||
return securityManager;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CustomHashedCredentialsMatcher customHashedCredentialsMatcher() {
|
||||
return new CustomHashedCredentialsMatcher();
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public RedisCacheManager redisCacheManager() {
|
||||
return new RedisCacheManager();
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) {
|
||||
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
|
||||
shiroFilterFactoryBean.setSecurityManager(securityManager);
|
||||
//自定义拦截器限制并发人数,参考博客:
|
||||
LinkedHashMap<String, Filter> filtersMap = new LinkedHashMap<>();
|
||||
//用来校验token
|
||||
filtersMap.put("token", new CustomAccessControlFilter());
|
||||
shiroFilterFactoryBean.setFilters(filtersMap);
|
||||
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
|
||||
// 配置不会被拦截的链接 顺序判断
|
||||
filterChainDefinitionMap.put("/sys/user/login", "anon");
|
||||
filterChainDefinitionMap.put("/sys/user/getToken", "anon");
|
||||
filterChainDefinitionMap.put("/sys/user/register", "anon");
|
||||
filterChainDefinitionMap.put("/sys/key/decrypt", "anon");
|
||||
filterChainDefinitionMap.put("/mongoId", "anon");
|
||||
filterChainDefinitionMap.put("/outerApi/**", "anon"); //外部api请求
|
||||
//放开从大屏登陆到云平台的url
|
||||
filterChainDefinitionMap.put("/sys/token/loginToCloud", "anon");
|
||||
//验证云平台token
|
||||
filterChainDefinitionMap.put("/sys/token/checkPlatToken", "anon");
|
||||
//使用userId申请大屏token
|
||||
filterChainDefinitionMap.put("/sys/token/applyLargeScreenTokenUserId", "anon");
|
||||
//filterChainDefinitionMap.put("/index/**", "anon");
|
||||
//filterChainDefinitionMap.put("*.html", "anon");
|
||||
//放开swagger-ui地址
|
||||
filterChainDefinitionMap.put("/swagger/**", "anon");
|
||||
filterChainDefinitionMap.put("/v2/api-docs", "anon");
|
||||
filterChainDefinitionMap.put("/swagger-ui.html", "anon");
|
||||
filterChainDefinitionMap.put("/swagger-resources/**", "anon");
|
||||
filterChainDefinitionMap.put("/webjars/**", "anon");
|
||||
filterChainDefinitionMap.put("/druid/**", "anon");
|
||||
filterChainDefinitionMap.put("/favicon.ico", "anon");
|
||||
filterChainDefinitionMap.put("/captcha.jpg", "anon");
|
||||
//filterChainDefinitionMap.put("/","user");
|
||||
filterChainDefinitionMap.put("/csrf", "anon");
|
||||
filterChainDefinitionMap.put("/**", "token,authc");
|
||||
shiroFilterFactoryBean.setLoginUrl("/index/login");
|
||||
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
|
||||
return shiroFilterFactoryBean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启shiro aop注解支持.
|
||||
* 使用代理方式;所以需要开启代码支持;
|
||||
*
|
||||
* @param securityManager
|
||||
* @return org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor
|
||||
* @throws
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/19 10:50
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/19 10:50
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
@Bean
|
||||
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) {
|
||||
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
|
||||
authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
|
||||
return authorizationAttributeSourceAdvisor;
|
||||
}
|
||||
|
||||
|
||||
// @Bean
|
||||
// public ShiroDialect shiroDialect() {
|
||||
// return new ShiroDialect();
|
||||
// }
|
||||
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
package com.ho.user.controller;
|
||||
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.SYS + "checkLicence")
|
||||
@Slf4j
|
||||
public class CheckLicenceController {
|
||||
|
||||
public interface NativeLibrary extends Library {
|
||||
int CheckLicence();
|
||||
NativeLibrary INSTANCE = (NativeLibrary) Native.loadLibrary("/usr/lib/libauth_lib.so", NativeLibrary.class);
|
||||
}
|
||||
|
||||
@PostMapping("check")
|
||||
@ApiOperation(value = "检查licence")
|
||||
@TokenIgnore
|
||||
public DataResult check() {
|
||||
log.info("begin to checkLicence");
|
||||
// -1 失败 0 成功
|
||||
int result = NativeLibrary.INSTANCE.CheckLicence();
|
||||
log.info("check result {}",result);
|
||||
if(CommonConstant.ZERO != result){
|
||||
throw new BusinessException(BaseResponseCode.LOSE_LICENCE);
|
||||
}
|
||||
log.info("end to checkLicence");
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,198 @@
|
||||
package com.ho.user.controller;
|
||||
|
||||
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.entity.PageVO;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.user.api.entity.SysDept;
|
||||
import com.ho.user.api.entity.SysUser;
|
||||
import com.ho.user.api.vo.req.DeptManagerReq;
|
||||
import com.ho.user.feignclient.FlowFeignClient;
|
||||
import com.ho.user.service.DeptService;
|
||||
import com.ho.user.service.PermissionService;
|
||||
import com.ho.user.vo.req.DeptAddReqVO;
|
||||
import com.ho.user.vo.req.DeptQuery;
|
||||
import com.ho.user.vo.req.DeptUpdateReqVO;
|
||||
import com.ho.user.vo.req.UserPageUserByDeptReqVO;
|
||||
import com.ho.user.vo.resp.DeptRespNodeVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
/**
|
||||
* 机构部门实现类
|
||||
*/
|
||||
@RequestMapping(ContextConstant.SYS + "dept")
|
||||
@RestController
|
||||
@Api(tags = "系统模块-机构管理")
|
||||
@Slf4j
|
||||
public class DeptController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private DeptService deptService;
|
||||
|
||||
@Autowired
|
||||
PermissionService permissionService;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Value("${phone.regexp}")
|
||||
String regex;
|
||||
|
||||
@PostMapping("users")
|
||||
@ApiOperation(value = "分页获取组织下所有用户接口")
|
||||
//@LogAnnotation(title = "机构管理",action = "分页获取组织下所有用户")
|
||||
//@RequiresPermissions("sys:dept:user:list")
|
||||
public DataResult<PageVO<SysUser>> pageDeptUserInfos(@RequestBody @Valid UserPageUserByDeptReqVO vo) {
|
||||
//因为查询部门下人员存在越权情况,即子部门的人员无法查询上级公司人员,所以要做个控制
|
||||
|
||||
return DataResult.success(deptService.pageDeptUserInfo(vo));
|
||||
}
|
||||
|
||||
@GetMapping("{id}")
|
||||
@ApiOperation(value = "查询组织详情接口")
|
||||
// @LogAnnotation(title = "机构管理",action = "查询组织详情")
|
||||
//@RequiresPermissions("sys:dept:detail")
|
||||
public DataResult<SysDept> detailInfo(@PathVariable("id") Integer id) {
|
||||
DataResult<SysDept> result = DataResult.success();
|
||||
result.setData(deptService.detailInfo(id));
|
||||
return result;
|
||||
}
|
||||
|
||||
/* @PostMapping("deptpage")
|
||||
@ApiOperation(value = "分页获取组织信息接口")
|
||||
//@LogAnnotation(title = "机构管理",action = "分页获取组织信息")
|
||||
//@RequiresPermissions("sys:dept:list")
|
||||
public DataResult<PageVO<SysDept>> pageInfo(@RequestBody DeptPageReqVO vo) {
|
||||
DataResult<PageVO<SysDept>> result = DataResult.success();
|
||||
result.setData(deptService.pageInfo(vo));
|
||||
return result;
|
||||
}*/
|
||||
|
||||
@PostMapping("tree")
|
||||
@ApiOperation(value = "树型组织列表接口")
|
||||
//@RequiresPermissions(value = {"sys:user:update","sys:user:add","sys:dept:add","sys:dept:update"},logical = Logical.OR)
|
||||
public DataResult<List<DeptRespNodeVO>> getTree(@RequestBody(required = false) @Valid DeptQuery query) {
|
||||
DataResult<List<DeptRespNodeVO>> result = DataResult.success();
|
||||
result.setData(deptService.deptTreeList(query, null));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("tree/enabled")
|
||||
@ApiOperation(value = "获取所有启用的部门接口")
|
||||
public DataResult<List<DeptRespNodeVO>> getSelectAllByStatus(@RequestBody(required = false) @Valid DeptQuery query) {
|
||||
DataResult<List<DeptRespNodeVO>> result = DataResult.success();
|
||||
result.setData(deptService.deptTreeList(query, "enableStatus"));
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("list")
|
||||
@ApiOperation(value = "组织机构列表(根据id)")
|
||||
//@RequiresPermissions(value = {"sys:user:update","sys:user:add","sys:dept:add","sys:dept:update"},logical = Logical.OR)
|
||||
public DataResult<List<SysDept>> getSubDepts(@RequestParam Integer deptId) {
|
||||
DataResult<List<SysDept>> result = DataResult.success();
|
||||
result.setData(deptService.depListByDeptId(deptId));
|
||||
return result;
|
||||
}
|
||||
|
||||
/* @GetMapping("get")
|
||||
@ApiOperation(value = "获取机构列表接口")
|
||||
//@LogAnnotation(title = "机构管理",action = "获取所有组织机构")
|
||||
//@RequiresPermissions("sys:dept:list")
|
||||
public DataResult<List<SysDept>> getDeptAll() {
|
||||
DataResult<List<SysDept>> result = DataResult.success();
|
||||
result.setData(deptService.selectAll());
|
||||
return result;
|
||||
}*/
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增组织接口")
|
||||
@LogAnnotation(title = "机构管理", action = "新增组织")
|
||||
@RequiresPermissions("sys:dept:add")
|
||||
public DataResult<SysDept> addDept(@RequestBody @Valid DeptAddReqVO vo, HttpServletRequest request) {
|
||||
if (StringUtils.hasLength(vo.getPhone()) && StringUtils.isEmpty(vo.getPhone())) {
|
||||
String phone = vo.getPhone();
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(phone);
|
||||
if (!matcher.matches()) {
|
||||
throw new BusinessException(BaseResponseCode.INCORRECT_MOBILE_NUMBER_FORMAT);
|
||||
}
|
||||
}
|
||||
String token = request.getHeader(CommonConstant.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = redisService.getSimpleUserByToken(token);
|
||||
if (CommonConstant.TOP_PARENT_ID.equals(vo.getPid())) {
|
||||
if (!simpleUser.getPlatSuper()) {
|
||||
log.error("非平台管理员无法创建顶级部门", vo.getPid());
|
||||
throw new BusinessException(BaseResponseCode.NON_PLATFORM_ADMINISTRATOR);
|
||||
}
|
||||
}
|
||||
DataResult<SysDept> result = DataResult.success();
|
||||
result.setData(deptService.addDept(vo));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping("update")
|
||||
@ApiOperation(value = "更新组织信息接口")
|
||||
@LogAnnotation(title = "机构管理", action = "更新组织信息")
|
||||
@RequiresPermissions("sys:dept:update")
|
||||
public DataResult updateDept(@RequestBody @Valid DeptUpdateReqVO vo) {
|
||||
if (StringUtils.hasLength(vo.getPhone()) && StringUtils.isEmpty(vo.getPhone())) {
|
||||
String phone = vo.getPhone();
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(phone);
|
||||
if (!matcher.matches()) {
|
||||
throw new BusinessException(BaseResponseCode.INCORRECT_MOBILE_NUMBER_FORMAT);
|
||||
}
|
||||
}
|
||||
//如果顶级部门是自己,提示
|
||||
if (vo.getId().equals(vo.getPid())) {
|
||||
throw new BusinessException(BaseResponseCode.PARENT_DEPT_CANNOT_SELF);
|
||||
}
|
||||
deptService.updateDept(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@DeleteMapping("{id}")
|
||||
@ApiOperation(value = "删除组织接口")
|
||||
@LogAnnotation(title = "机构管理", action = "删除组织")
|
||||
@RequiresPermissions("sys:dept:deleted")
|
||||
public DataResult deleted(@PathVariable("id") Integer id) {
|
||||
deptService.deleted(id);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("/detail/getDeptUser")
|
||||
@ApiOperation(value = "根据deptId查询部门下的人员")
|
||||
public DataResult<List<SysUser>> getDeptUser(@RequestBody DeptManagerReq deptManagerReq) {
|
||||
DataResult<List<SysUser>> result = DataResult.success();
|
||||
result.setData(deptService.getDeptUser(deptManagerReq));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("getUserInfosPage")
|
||||
@ApiOperation(value = "分页获取组织下所有用户接口(短信接口使用)")
|
||||
public DataResult<PageVO<SysUser>> getUserInfosPage(@RequestBody UserPageUserByDeptReqVO vo) {
|
||||
//因为查询部门下人员存在越权情况,即子部门的人员无法查询上级公司人员,所以要做个控制
|
||||
return DataResult.success(deptService.getUserInfosPage(vo));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,190 @@
|
||||
package com.ho.user.controller;
|
||||
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.entity.PageVO;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.user.entity.SysDict;
|
||||
import com.ho.user.api.entity.SysSubDict;
|
||||
import com.ho.user.service.DictService;
|
||||
import com.ho.user.vo.req.*;
|
||||
import com.ho.user.vo.resp.DictRespVo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: 字典Controller
|
||||
* @date 2022/8/18
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.SYS + "dict")
|
||||
@Api(tags = "系统模块-字典管理")
|
||||
public class DictController {
|
||||
|
||||
@Resource
|
||||
DictService dictService;
|
||||
|
||||
|
||||
@GetMapping("type/{type}")
|
||||
@ApiOperation(value = "查询字典类型接口(根据类型)")
|
||||
//@RequiresPermissions("sys:dept:add")
|
||||
// @LogAnnotation(title = "字典管理", action = "根据type查询字典类型")
|
||||
public DataResult<List<SysDict>> detailInfo(@PathVariable("type") String type) {
|
||||
DataResult<List<SysDict>> result = DataResult.success();
|
||||
result.setData(dictService.selectDictListByType(type));
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
@PostMapping("typeList")
|
||||
@ApiOperation(value = "查询字典列表接口(根据类型)")
|
||||
// @LogAnnotation(title = "字典管理",action = "根据类型查询字典")
|
||||
public DataResult<DictRespVo> dictList(@RequestBody @Valid DictSearchReqVO vo) {
|
||||
DataResult<DictRespVo> result = DataResult.success();
|
||||
DictTypeAndLabelReqVO typeAndLabelReqVO = new DictTypeAndLabelReqVO();
|
||||
typeAndLabelReqVO.setType(vo.getType());
|
||||
result.setData(dictService.selectDict(typeAndLabelReqVO));
|
||||
return result;
|
||||
}
|
||||
|
||||
/* @PostMapping("label")
|
||||
@ApiOperation(value = "查询字典列表接口(根据类型和标签)")
|
||||
@LogAnnotation(title = "字典管理",action = "根据类型和标签查询字典")
|
||||
public DataResult<DictRespVo> dictLabelList(@RequestBody @Valid DictTypeAndLabelReqVO vo) {
|
||||
DataResult<DictRespVo> result = DataResult.success();
|
||||
result.setData(dictService.selectDict(vo));
|
||||
return result;
|
||||
}*/
|
||||
|
||||
@PostMapping("all/page")
|
||||
@ApiOperation(value = "分页查询字典列表接口")
|
||||
public DataResult<PageVO<DictRespVo>> dictList(@RequestBody @Valid DictPageReqVO vo) {
|
||||
DataResult<PageVO<DictRespVo>> result = DataResult.success();
|
||||
PageVO<DictRespVo> list = dictService.all(vo);
|
||||
result.setData(list);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("typeAll")
|
||||
@ApiOperation(value = "查询所有字典列表接口")
|
||||
public DataResult<List<DictRespVo>> typeList() {
|
||||
DataResult<List<DictRespVo>> result = DataResult.success();
|
||||
result.setData(dictService.selectDictType());
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("type")
|
||||
@ApiOperation(value = "新增字典类型接口")
|
||||
@LogAnnotation(title = "字典管理", action = "新增字典类型")
|
||||
public DataResult<SysDict> addDictType(@RequestBody @Valid DictAddTypeVO vo) {
|
||||
DataResult<SysDict> result = DataResult.success();
|
||||
//先判断是否有相同的type的值
|
||||
SysDict dict = dictService.selectDictByType(vo);
|
||||
if (dict != null) {
|
||||
throw new BusinessException(BaseResponseCode.DICT_ALREADY_EXISTS);
|
||||
}
|
||||
result.setData(dictService.addTypeDict(vo));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping
|
||||
@ApiOperation(value = "新增字典接口")
|
||||
@LogAnnotation(title = "字典管理", action = "新增字典")
|
||||
//@RequiresPermissions("sys:dict:add")
|
||||
public DataResult<SysSubDict> addDict(@RequestBody @Valid DictAddReqVO vo) {
|
||||
DataResult<SysSubDict> result = DataResult.success();
|
||||
//先判断是否有相同value的值
|
||||
SysSubDict subDict = dictService.selectSubDictByTV(vo.getType(), vo.getLabel());
|
||||
if (subDict != null) {
|
||||
throw new BusinessException(BaseResponseCode.SUB_DICT_ALREADY_EXISTS);
|
||||
}
|
||||
//先判断 键 值 是否有相同的值
|
||||
SysSubDict sysSubDict = new SysSubDict();
|
||||
sysSubDict.setLabel(vo.getLabel());
|
||||
sysSubDict.setType(vo.getType());
|
||||
//sysSubDict.setId(null);
|
||||
List<SysSubDict> subDictList = dictService.selectSubDictByKey(sysSubDict);
|
||||
if (!subDictList.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.DICT_EXISTENCE_EXISTENCE_KEY_VALUE);
|
||||
}
|
||||
//判断排序
|
||||
SysSubDict subDictSort = dictService.selectSubDictBySort(vo.getType(), vo.getSort());
|
||||
if (subDictSort != null) {
|
||||
throw new BusinessException(BaseResponseCode.SORT_CODE_BEEN_USED_PLEASE_CORRECT_SORT);
|
||||
}
|
||||
result.setData(dictService.addSubDict(vo));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* @DeleteMapping("id/{id}")
|
||||
@ApiOperation(value = "删除字典类型接口根据id")
|
||||
@LogAnnotation(title = "字典管理", action = "根据id删除字典类型")
|
||||
//@RequiresPermissions("sys:dict:deleted")
|
||||
public DataResult deletedById(@PathVariable("id") Integer id) {
|
||||
dictService.deletedById(id);
|
||||
return DataResult.success();
|
||||
}*/
|
||||
|
||||
/* @DeleteMapping("type/{type}")
|
||||
@ApiOperation(value = "删除字典接口根据类型")
|
||||
@LogAnnotation(title = "字典管理", action = "根据类型删除字典")
|
||||
public DataResult deletedByType(@PathVariable("type") String type) {
|
||||
dictService.deletedByType(type);
|
||||
return DataResult.success();
|
||||
}*/
|
||||
|
||||
@DeleteMapping("sub/{id}")
|
||||
@ApiOperation(value = "删除字典根据id")
|
||||
@LogAnnotation(title = "字典管理", action = "根据id删除字典")
|
||||
public DataResult deletedSubById(@PathVariable("id") Integer id) {
|
||||
dictService.deletedSubById(id);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
@PutMapping("type")
|
||||
@ApiOperation(value = "更新字典类型接口")
|
||||
@LogAnnotation(title = "字典管理", action = "更新字典类型")
|
||||
//@RequiresPermissions("sys:dict:update")
|
||||
public DataResult updateDict(@RequestBody @Valid DictUpdateReqVO vo) {
|
||||
//提前判断是否数据库中存在相同的type值
|
||||
DictAddTypeVO dictAddTypeVo = new DictAddTypeVO();
|
||||
dictAddTypeVo.setType(vo.getType());
|
||||
dictAddTypeVo.setTypeName(vo.getTypeName());
|
||||
SysDict sysDict = dictService.selectDictByTypeAndName(dictAddTypeVo);
|
||||
if (sysDict != null) {
|
||||
throw new BusinessException(BaseResponseCode.DICT_ALREADY_EXISTS);
|
||||
}
|
||||
dictService.updateDict(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PutMapping("sub")
|
||||
@ApiOperation(value = "更新字典接口")
|
||||
@LogAnnotation(title = "字典管理", action = "更新字典")
|
||||
//@RequiresPermissions("sys:dict:update")
|
||||
public DataResult updateSubDict(@RequestBody @Valid DictSubUpdateReqVO vo) {
|
||||
//先判断 键 值 是否有相同的值
|
||||
SysSubDict sysSubDict = new SysSubDict();
|
||||
sysSubDict.setLabel(vo.getLabel());
|
||||
sysSubDict.setType(vo.getType());
|
||||
sysSubDict.setId(vo.getId());
|
||||
List<SysSubDict> subDictList = dictService.selectSubDictByKey(sysSubDict);
|
||||
if (!subDictList.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.DICT_EXISTENCE_EXISTENCE_KEY_VALUE);
|
||||
}
|
||||
dictService.updateSubDict(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package com.ho.user.controller;
|
||||
|
||||
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.user.service.HomeService;
|
||||
import com.ho.user.util.JwtTokenUtil;
|
||||
import com.ho.user.vo.resp.HomeRespVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 首页
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.SYS + "home")
|
||||
@Api(tags = "首页数据")
|
||||
public class HomeController {
|
||||
@Autowired
|
||||
private HomeService homeService;
|
||||
|
||||
@GetMapping
|
||||
@ApiOperation(value = "获取首页数据接口")
|
||||
public DataResult<HomeRespVO> getHomeInfo(HttpServletRequest request) {
|
||||
String accessToken = request.getHeader("authorization");
|
||||
/**
|
||||
* 通过access_token拿userId
|
||||
*/
|
||||
//String userId = JwtTokenUtil.getUserId(accessToken);
|
||||
String userId = "";
|
||||
DataResult<HomeRespVO> result = DataResult.success();
|
||||
result.setData(homeService.getHomeInfo(userId));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
package com.ho.user.controller;
|
||||
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.user.api.vo.req.DecryptReqVO;
|
||||
import com.ho.common.tools.util.RSAUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: 密钥相关Controller
|
||||
* @date 2022/11/14
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.SYS + "key")
|
||||
@Api(tags = "系统模块-密钥管理")
|
||||
@Slf4j
|
||||
public class KeyController {
|
||||
|
||||
@Value("${rsa.pubKey}")
|
||||
private String rsaPubKey;
|
||||
|
||||
@Value("${rsa.privateKey}")
|
||||
private String privateKey;
|
||||
|
||||
@GetMapping("getPublicKey")
|
||||
@ApiOperation(value = "获取公钥")
|
||||
@TokenIgnore
|
||||
public DataResult getPublicKey() {
|
||||
log.info("获取密钥");
|
||||
return DataResult.success(rsaPubKey);
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation(hidden = true, value = "解密测试")
|
||||
@RequestMapping("decrypt")
|
||||
public DataResult decrypt(@RequestBody DecryptReqVO decryptReqVO) {
|
||||
log.info("encryptText: {}", decryptReqVO);
|
||||
String s = RSAUtil.decode(decryptReqVO.getEncryptText(), privateKey);
|
||||
|
||||
return DataResult.success();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,302 @@
|
||||
package com.ho.user.controller;
|
||||
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SysPermission;
|
||||
import com.ho.common.tools.entity.UserDetailRespVO;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.user.api.entity.PermStationRelation;
|
||||
import com.ho.user.api.vo.req.QueryPermissionReqVo;
|
||||
import com.ho.user.entity.PermissionRespNode;
|
||||
import com.ho.user.service.PermissionService;
|
||||
import com.ho.user.service.RedisUpdateService;
|
||||
import com.ho.user.vo.req.PermissionAddReqVO;
|
||||
import com.ho.user.vo.req.PermissionUpdateReqVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 权限入口
|
||||
*/
|
||||
@RequestMapping(ContextConstant.SYS + "permission")
|
||||
@RestController
|
||||
@Api(tags = "系统模块-菜单权限管理")
|
||||
@Slf4j
|
||||
public class PermissionController {
|
||||
|
||||
@Autowired
|
||||
private PermissionService permissionService;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
RedisUpdateService redisUpdateService;
|
||||
|
||||
@Autowired
|
||||
RedissonClient redissonClient;
|
||||
|
||||
@GetMapping("{id}")
|
||||
@ApiOperation(value = "查询菜单权限接口")
|
||||
//@LogAnnotation(title = "菜单权限管理",action = "查询菜单权限")
|
||||
//@RequiresPermissions("sys:permission:detail")
|
||||
public DataResult<SysPermission> detailInfo(@PathVariable("id") Integer id) {
|
||||
DataResult<SysPermission> result = DataResult.success();
|
||||
result.setData(permissionService.detailInfo(id));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("tree/all")
|
||||
@ApiOperation(value = "获取所有目录菜单树接口")
|
||||
//@LogAnnotation(title = "菜单权限管理",action = "获取所有目录菜单树")
|
||||
//@RequiresPermissions(value = {"sys:role:update","sys:role:add"},logical = Logical.OR)
|
||||
public DataResult<List<PermissionRespNode>> getAllPermissionTree(@RequestBody(required = false) @Valid QueryPermissionReqVo query) {
|
||||
DataResult<List<PermissionRespNode>> result = DataResult.success();
|
||||
if (query == null) {
|
||||
query = new QueryPermissionReqVo();
|
||||
}
|
||||
result.setData(permissionService.selectAllByTree(query, null, null));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("all/get")
|
||||
@ApiOperation(value = "获取所有菜单(跟当前登录人没有关系)")
|
||||
public DataResult<List<PermissionRespNode>> getAll() {
|
||||
DataResult<List<PermissionRespNode>> result = DataResult.success();
|
||||
QueryPermissionReqVo query = new QueryPermissionReqVo();
|
||||
result.setData(permissionService.getAll(query));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("all/enabledType")
|
||||
@ApiOperation(value = "角色管理获取所有启用及按钮类型菜单树接口")
|
||||
public DataResult<List<PermissionRespNode>> getSelectRoleAll() {
|
||||
DataResult<List<PermissionRespNode>> result = DataResult.success();
|
||||
QueryPermissionReqVo query = new QueryPermissionReqVo();
|
||||
result.setData(permissionService.selectAllByTree(query, null, "enableType"));
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("all/enabled")
|
||||
@ApiOperation(value = "获取所有启用目录菜单树接口")
|
||||
public DataResult<List<PermissionRespNode>> getSelectAllByStatus() {
|
||||
DataResult<List<PermissionRespNode>> result = DataResult.success();
|
||||
QueryPermissionReqVo query = new QueryPermissionReqVo();
|
||||
result.setData(permissionService.selectAllByTree(query, "enableStatus", null));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增菜单权限接口")
|
||||
@LogAnnotation(title = "菜单权限管理", action = "新增菜单权限")
|
||||
@RequiresPermissions("sys:permission:add")
|
||||
public DataResult<SysPermission> addPermission(@RequestBody @Valid PermissionAddReqVO vo, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
String userTokenKey = RedisKeyConstant.User.TOKEN + token;
|
||||
UserDetailRespVO user = (UserDetailRespVO) redisService.get(userTokenKey);
|
||||
//权限标识如果传了值,就判断是否有相同的
|
||||
if (!StrUtil.isBlank(vo.getPerms())) {
|
||||
SysPermission sysPermission = permissionService.selectByPerms(vo.getPerms());
|
||||
if (sysPermission != null) {
|
||||
throw new BusinessException(BaseResponseCode.PERMISSION_ALREADY_EXISTS);
|
||||
}
|
||||
}
|
||||
//增加之前判断它所属的父节点的删除状态以及启用状态
|
||||
// 删除状态:不能添加子节点 0 已删除
|
||||
//不可启用状态 :进行提示 0 不启用
|
||||
|
||||
//如果不是顶级节点
|
||||
if (!CommonConstant.TOP_PARENT_ID.equals(vo.getPid())) {
|
||||
SysPermission sysPermission = permissionService.selectByPrimaryKey(vo.getPid());
|
||||
//如果是删除状态
|
||||
if (CommonConstant.DELETED_FLAG.equals(sysPermission.getDeleted())) {
|
||||
throw new BusinessException(BaseResponseCode.PARENT_MENU_DELENTION_STATUS);
|
||||
}
|
||||
//如果是未启用状态
|
||||
if (CommonConstant.ZERO.equals(sysPermission.getStatus())) {
|
||||
throw new BusinessException(BaseResponseCode.PARENT_MENU_NOT_ADD_ENABLED);
|
||||
}
|
||||
}
|
||||
//如果是顶级菜单,那么 show必填
|
||||
if (CommonConstant.TOP_PARENT_ID.equals(vo.getPid())) {
|
||||
//如果等于3(按钮)则不判断show
|
||||
if (CommonConstant.BUTTON_FLAG.equals(vo.getType())) {
|
||||
//判断新增父级节点是的type是否为按钮,如果是按钮的话,则进行提示
|
||||
if (CommonConstant.BUTTON_FLAG.equals(vo.getType())) {
|
||||
throw new BusinessException(BaseResponseCode.PARENT_NODE_TYPE_NOT_BUTTON);
|
||||
}
|
||||
} else {
|
||||
if (StringUtils.isEmpty(vo.getShow())
|
||||
|| (!CommonConstant.MenuShowType.ALL.equals(vo.getShow())
|
||||
&& !CommonConstant.MenuShowType.PC.equals(vo.getShow())
|
||||
&& !CommonConstant.MenuShowType.APP.equals(vo.getShow()))
|
||||
) {
|
||||
throw new BusinessException(BaseResponseCode.MENU_SHOW_TYPE_NOT_RIGHT);
|
||||
}
|
||||
}
|
||||
}
|
||||
//如果是顶级菜单,那么名称不能为"系统管理",因为”系统管理“有特殊用处,用于控制平台管理员的查询数据
|
||||
/*if (CommonConstant.TOP_PARENT_ID.equals(vo.getPid()) && CommonConstant.SYS_MENU_NAME.equals(vo.getName())) {
|
||||
throw new BusinessException(BaseResponseCode.SYS_MENU_NAME_NOT_RIGHT);
|
||||
}*/
|
||||
//如果是顶级菜单,那么名称不能为"菜单管理"
|
||||
if (CommonConstant.TOP_PARENT_ID.equals(vo.getPid()) && CommonConstant.PERMISSION_MENU_NAME.equals(vo.getName())) {
|
||||
throw new BusinessException(BaseResponseCode.SYS_MENU_NAME_NOT_RIGHT);
|
||||
}
|
||||
//增加分布式锁
|
||||
//定义锁
|
||||
RLock lock = null;
|
||||
SysPermission sysPermission = null;
|
||||
try {
|
||||
lock = redissonClient.getLock(RedisKeyConstant.LOCK_KEY_PERMISSION);
|
||||
//获取锁,没有获取到锁的阻塞在lock.lock() 这行
|
||||
lock.lock();
|
||||
sysPermission = permissionService.addPermission(vo);
|
||||
//新增完菜单后需要更新超管缓存的菜单列表
|
||||
/* try {
|
||||
redisUpdateService.updateSuperPermsCache();
|
||||
} catch (Exception e) {
|
||||
log.error("更新超管缓存的菜单列表出错");
|
||||
}*/
|
||||
} finally {
|
||||
if (lock != null && lock.isHeldByCurrentThread()) {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
return DataResult.success(sysPermission);
|
||||
}
|
||||
|
||||
@PutMapping("update")
|
||||
@ApiOperation(value = "更新菜单权限接口")
|
||||
@LogAnnotation(title = "菜单权限管理", action = "更新菜单权限")
|
||||
@RequiresPermissions("sys:permission:update")
|
||||
public DataResult updatePermission(@RequestBody @Valid PermissionUpdateReqVO vo) {
|
||||
//判断其他id是否有该perms的数据
|
||||
//查询系统管理那个记录
|
||||
SysPermission sysManageMenu = permissionService.findSysManageMenu();
|
||||
//顶级菜单的 系统管理不能被修改
|
||||
if (sysManageMenu != null && sysManageMenu.getId().equals(vo.getId())) {
|
||||
//判断是否要更改为禁用,更改为禁用时进行提示
|
||||
if (!CommonConstant.STATUS_FLAG.equals(vo.getStatus())) {
|
||||
throw new BusinessException(BaseResponseCode.SYS_MENU_NAME_STATUS_CANNOT);
|
||||
}
|
||||
//只允许改图标
|
||||
PermissionUpdateReqVO updateReqVO = new PermissionUpdateReqVO();
|
||||
updateReqVO.setId(vo.getId());
|
||||
updateReqVO.setIcon(vo.getIcon());
|
||||
updateReqVO.setOrderNum(vo.getOrderNum());
|
||||
updateReqVO.setPid(vo.getPid());
|
||||
updateReqVO.setShow(vo.getShow());
|
||||
updateReqVO.setType(CommonConstant.MENU_FLAG);
|
||||
updateReqVO.setName(vo.getName());
|
||||
vo = updateReqVO;
|
||||
//throw new BusinessException(BaseResponseCode.SYS_MENU_NAME_CANNOT_MODIFY);
|
||||
//permissionService.updateLittle(updateVo);
|
||||
}
|
||||
//如果是顶级菜单,那么 show必填
|
||||
if (CommonConstant.TOP_PARENT_ID.equals(vo.getPid())) {
|
||||
//是按钮不用判断show
|
||||
if (!CommonConstant.BUTTON_FLAG.equals(vo.getType())) {
|
||||
if (StringUtils.isEmpty(vo.getShow())
|
||||
|| (!CommonConstant.MenuShowType.ALL.equals(vo.getShow())
|
||||
&& !CommonConstant.MenuShowType.PC.equals(vo.getShow())
|
||||
&& !CommonConstant.MenuShowType.APP.equals(vo.getShow()))
|
||||
) {
|
||||
throw new BusinessException(BaseResponseCode.MENU_SHOW_TYPE_NOT_RIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//查看是否是菜单管理,菜单管理也不可以禁用
|
||||
SysPermission theMenu = permissionService.findTheMenu();
|
||||
if (theMenu != null && theMenu.getId().equals(vo.getId())) {
|
||||
//判断是否要更改为禁用,更改为禁用时进行提示
|
||||
if (!CommonConstant.STATUS_FLAG.equals(vo.getStatus())) {
|
||||
throw new BusinessException(BaseResponseCode.MENU_NAME_STATUS_CANNOT);
|
||||
}
|
||||
}
|
||||
//定义锁
|
||||
RLock lock = null;
|
||||
try {
|
||||
lock = redissonClient.getLock(RedisKeyConstant.LOCK_KEY_PERMISSION);
|
||||
//获取锁,没有获取到锁的阻塞在lock.lock() 这行
|
||||
lock.lock();
|
||||
permissionService.updatePermission(vo);
|
||||
} finally {
|
||||
if (lock != null && lock.isHeldByCurrentThread()) {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
//如果是修改菜单状态,还会修改子集菜单
|
||||
//更新超管菜单
|
||||
// redisUpdateService.updateSuperPermsCache();
|
||||
return DataResult.success(vo);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@DeleteMapping("{id}")
|
||||
@ApiOperation(value = "删除菜单权限接口")
|
||||
@LogAnnotation(title = "菜单权限管理", action = "删除菜单权限")
|
||||
@RequiresPermissions("sys:permission:deleted")
|
||||
public DataResult deleted(@PathVariable("id") Integer id) {
|
||||
DataResult result = DataResult.success();
|
||||
//查询系统管理那个记录
|
||||
SysPermission sysManageMenu = permissionService.findSysManageMenu();
|
||||
//顶级菜单的 系统管理不能被修改
|
||||
if (sysManageMenu != null && sysManageMenu.getId().equals(id)) {
|
||||
throw new BusinessException(BaseResponseCode.SYS_MENU_NAME_CANNOT_MODIFY);
|
||||
}
|
||||
//判断是否为menu的数据,如果是则不能被删除
|
||||
SysPermission theMenu = permissionService.findTheMenu();
|
||||
if (theMenu != null && theMenu.getId().equals(id)) {
|
||||
throw new BusinessException(BaseResponseCode.SYS_MENU_NOT_DELETE_MENU);
|
||||
}
|
||||
//增加分布式锁
|
||||
//定义锁
|
||||
RLock lock = null;
|
||||
try {
|
||||
lock = redissonClient.getLock(RedisKeyConstant.LOCK_KEY_PERMISSION);
|
||||
//获取锁,没有获取到锁的阻塞在lock.lock() 这行
|
||||
lock.lock();
|
||||
permissionService.deleted(id);
|
||||
} finally {
|
||||
if (lock != null && lock.isHeldByCurrentThread()) {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
//更新超管菜单
|
||||
// redisUpdateService.updateSuperPermsCache();
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据电站查询该电站的专属菜单
|
||||
@PostMapping("per/exclusiveMenu")
|
||||
@ApiOperation(value = "根据电站查询该电站的专属菜单")
|
||||
public DataResult<List<PermissionRespNode>> getStationPer(@RequestBody PermStationRelation permStationRelation, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
String userTokenKey = RedisKeyConstant.User.TOKEN + token;
|
||||
UserDetailRespVO user = (UserDetailRespVO) redisService.get(userTokenKey);
|
||||
DataResult<List<PermissionRespNode>> result = DataResult.success();
|
||||
result.setData(permissionService.getStationPer(permStationRelation.getStationId(),user));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,121 @@
|
||||
package com.ho.user.controller;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.entity.PageVO;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.util.PageUtilsOld;
|
||||
import com.ho.user.entity.SysPosition;
|
||||
import com.ho.user.service.PositionService;
|
||||
import com.ho.user.vo.req.PositionAddReqVO;
|
||||
import com.ho.user.vo.req.PositionDeleteReqVO;
|
||||
import com.ho.user.vo.req.PositionQueryReqVO;
|
||||
import com.ho.user.vo.req.PositionUpdateReqVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description 岗位Controller
|
||||
* Author yule
|
||||
* Date 2022/12/1 15:56
|
||||
*/
|
||||
@RequestMapping(ContextConstant.SYS + "position")
|
||||
@RestController
|
||||
@Api(tags = "系统模块-岗位管理")
|
||||
@Slf4j
|
||||
public class PositionController {
|
||||
|
||||
@Autowired
|
||||
PositionService positionService;
|
||||
|
||||
|
||||
@GetMapping("selectOne/{id}")
|
||||
@ApiOperation(value = "根据id查询岗位对象")
|
||||
//@LogAnnotation(title = "岗位管理", action = "根据id查询岗位对象")
|
||||
public DataResult<SysPosition> selectList(@PathVariable("id") @NotNull(message = "岗位id不能为空") Integer id) {
|
||||
SysPosition sysPosition = positionService.selectById(id);
|
||||
return DataResult.success(sysPosition);
|
||||
}
|
||||
|
||||
@PostMapping("selectList")
|
||||
@ApiOperation(value = "查询岗位列表")
|
||||
public DataResult<Page<SysPosition>> selectList(@RequestBody PositionQueryReqVO vo) {
|
||||
PageVO<SysPosition> pageVO = null;
|
||||
if (vo == null) {
|
||||
//如果没有条件,查全部岗位
|
||||
PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
|
||||
List<SysPosition> positions = positionService.selectAll();
|
||||
pageVO = PageUtilsOld.getPageVO(positions);
|
||||
} else {
|
||||
//条件存在,进行条件的模糊查询
|
||||
PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
|
||||
List<SysPosition> positions = positionService.selectObscure(vo);
|
||||
pageVO = PageUtilsOld.getPageVO(positions);
|
||||
}
|
||||
return DataResult.success(pageVO);
|
||||
}
|
||||
|
||||
@PostMapping("selectAll")
|
||||
@ApiOperation(value = "查询所有岗位 不分页")
|
||||
public DataResult<List<SysPosition>> selectAll() {
|
||||
//如果没有条件,查全部岗位
|
||||
List<SysPosition> positions = positionService.selectAvailable();
|
||||
|
||||
return DataResult.success(positions);
|
||||
}
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增岗位")
|
||||
@LogAnnotation(title = "岗位管理", action = "新增岗位")
|
||||
public DataResult addPosition(@RequestBody @Valid PositionAddReqVO vo) {
|
||||
//先判断是否有相同的type的值
|
||||
SysPosition sysPosition = new SysPosition();
|
||||
BeanUtils.copyProperties(vo, sysPosition);
|
||||
List<SysPosition> positions = positionService.selectAccuratePositionByInfo(sysPosition);
|
||||
if (!positions.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.POSITION_ALREADY_EXISTS);
|
||||
}
|
||||
int count = positionService.add(vo);
|
||||
if (count != 1) {
|
||||
throw new BusinessException(BaseResponseCode.OPERATION_ERRO);
|
||||
}
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("update")
|
||||
@ApiOperation(value = "修改岗位")
|
||||
@LogAnnotation(title = "岗位管理", action = "修改岗位")
|
||||
public DataResult updatePosition(@RequestBody @Valid PositionUpdateReqVO vo) {
|
||||
//先判断是否有相同的type的值
|
||||
SysPosition sysPosition =new SysPosition();
|
||||
BeanUtils.copyProperties(vo, sysPosition);
|
||||
List<SysPosition> positions = positionService.selectAccuratePositionByInfo(sysPosition);
|
||||
if (!positions.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.POSITION_ALREADY_EXISTS);
|
||||
}
|
||||
positionService.updatePosition(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("delete")
|
||||
@ApiOperation(value = "删除岗位")
|
||||
@LogAnnotation(title = "岗位管理", action = "删除岗位")
|
||||
public DataResult deletePosition(@RequestBody @Valid PositionDeleteReqVO vo) {
|
||||
positionService.deleted(vo.getId());
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,164 @@
|
||||
package com.ho.user.controller;
|
||||
|
||||
|
||||
import cn.hutool.core.lang.Snowflake;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.entity.PageVO;
|
||||
import com.ho.common.tools.entity.SysRole;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.user.service.RedisUpdateService;
|
||||
import com.ho.user.service.RoleService;
|
||||
import com.ho.user.service.UserRoleService;
|
||||
import com.ho.user.vo.req.RoleAddReqVO;
|
||||
import com.ho.user.vo.req.RolePageReqVO;
|
||||
import com.ho.user.vo.req.RoleUpdateReqVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Role入口
|
||||
*/
|
||||
@RequestMapping(ContextConstant.SYS + "role")
|
||||
@RestController
|
||||
@Api(tags = "系统模块-角色管理")
|
||||
@Slf4j
|
||||
public class RoleController {
|
||||
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
|
||||
@Autowired
|
||||
private UserRoleService userRoleService;
|
||||
|
||||
@Autowired
|
||||
RedisUpdateService redisUpdateService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
Snowflake snowflake;
|
||||
|
||||
@GetMapping("{id}")
|
||||
@ApiOperation(value = "查询角色详情接口")
|
||||
//@LogAnnotation(title = "角色管理",action = "查询角色详情")
|
||||
//@RequiresPermissions("sys:role:detail")
|
||||
public DataResult<SysRole> detailInfo(@PathVariable("id") Integer id) {
|
||||
DataResult<SysRole> result = DataResult.success();
|
||||
result.setData(roleService.detailInfo(id, null));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("page")
|
||||
@ApiOperation(value = "分页获取角色信息接口")
|
||||
//@LogAnnotation(title = "角色管理",action = "分页获取角色信息")
|
||||
//@RequiresPermissions("sys:role:list")
|
||||
public DataResult<PageVO<SysRole>> pageInfo(@RequestBody RolePageReqVO vo) {
|
||||
DataResult<PageVO<SysRole>> result = DataResult.success();
|
||||
result.setData(roleService.pageInfo(vo));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("list")
|
||||
@ApiOperation(value = "获取角色信息接口(不分页)")
|
||||
//@LogAnnotation(title = "角色管理",action = "分页获取角色信息")
|
||||
//@RequiresPermissions("sys:role:list")
|
||||
public DataResult<List<SysRole>> infoList() {
|
||||
DataResult<List<SysRole>> result = DataResult.success();
|
||||
RolePageReqVO vo = new RolePageReqVO();
|
||||
result.setData(roleService.listInfo(vo));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增角色接口")
|
||||
@LogAnnotation(title = "角色管理", action = "新增角色")
|
||||
@RequiresPermissions("sys:role:add")
|
||||
public DataResult<SysRole> addRole(@RequestBody @Valid RoleAddReqVO vo) {
|
||||
//新增的角色名不能是 超级管理员
|
||||
if (CommonConstant.SUPER_ROLE.equals(vo.getName())) {
|
||||
throw new BusinessException(BaseResponseCode.ROLE_NAME_CANNOT_BE_SUPER);
|
||||
}
|
||||
//如果code被赋值了,那么清空
|
||||
vo.setCode(null);
|
||||
DataResult<SysRole> result = DataResult.success();
|
||||
result.setData(roleService.addRole(vo));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping("update")
|
||||
@ApiOperation(value = "更新角色信息接口")
|
||||
@LogAnnotation(title = "角色管理", action = "更新角色信息")
|
||||
@RequiresPermissions("sys:role:update")
|
||||
public DataResult updateRole(@RequestBody @Valid RoleUpdateReqVO vo, HttpServletRequest request) {
|
||||
|
||||
//超级管理员这个角色不能修改
|
||||
SysRole sysRole = roleService.detailInfo(vo.getId(), null);
|
||||
if (sysRole == null) {
|
||||
throw new BusinessException(BaseResponseCode.DATA_NOT_EXISTS);
|
||||
}
|
||||
//平台超级管理员不能变更
|
||||
if (CommonConstant.SUPER_ROLE_CODE.equals(sysRole.getCode())) {
|
||||
throw new BusinessException(BaseResponseCode.SUPER_ROLE_CANNOT_MODIFY);
|
||||
}
|
||||
//系统内置角色不能操作
|
||||
if (sysRole.getCode().startsWith(CommonConstant.SYS_INNER_ROLE_PREFIX)) {
|
||||
//throw new BusinessException(BaseResponseCode.INNER_ROLE_CANNOT_MODIFY);
|
||||
//内置角色只变更所属菜单
|
||||
vo.setName(null);
|
||||
vo.setDescription(null);
|
||||
vo.setStatus(null);
|
||||
}
|
||||
//request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN)
|
||||
//先修改物理数据
|
||||
roleService.updateRole(vo);
|
||||
//修改缓存,将这个角色影响的用户缓存做清理,让用户重新登陆获取最新角色列表
|
||||
try {
|
||||
List<Integer> roleIds = new ArrayList<>();
|
||||
roleIds.add(vo.getId());
|
||||
redisUpdateService.cleanLoginInfosByRoleId(roleIds);
|
||||
} catch (Exception e) {
|
||||
log.error("修改角色接口 清除缓存是报错:" + e.getMessage());
|
||||
}
|
||||
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@DeleteMapping("{id}")
|
||||
@ApiOperation(value = "删除角色接口")
|
||||
@LogAnnotation(title = "角色管理", action = "删除角色")
|
||||
@RequiresPermissions("sys:role:deleted")
|
||||
public DataResult deleted(@PathVariable("id") Integer id) {
|
||||
//删除角色时要先判断角色是否被使用
|
||||
List<Integer> roleIds = new ArrayList<>();
|
||||
roleIds.add(id);
|
||||
List<String> userIdsByRoleIds = userRoleService.getUserIdsByRoleIds(roleIds);
|
||||
if (!userIdsByRoleIds.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.ROLE_ALREADY_USED);
|
||||
}
|
||||
roleService.deletedRole(id);
|
||||
//删除缓存 ,捕获一次
|
||||
try {
|
||||
redisUpdateService.cleanLoginInfosByRoleId(roleIds);
|
||||
} catch (Exception e) {
|
||||
log.error("删除角色接口 清除缓存是报错:" + e.getMessage());
|
||||
}
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package com.ho.user.controller;
|
||||
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.user.service.RolePermissionService;
|
||||
import com.ho.user.vo.req.RolePermissionOperationReqVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* Role关联菜单
|
||||
*/
|
||||
@RequestMapping(ContextConstant.SYS + "/role/permission")
|
||||
@RestController
|
||||
@Api(tags = "系统管理-角色和菜单关联接口")
|
||||
public class RolePermissionController {
|
||||
|
||||
@Autowired
|
||||
private RolePermissionService rolePermissionService;
|
||||
|
||||
@PostMapping
|
||||
@ApiOperation(value = "修改或者新增角色菜单权限接口")
|
||||
@LogAnnotation(title = "角色和菜单关联接口", action = "修改或者新增角色菜单权限")
|
||||
@RequiresPermissions(value = {"sys:role:update", "sys:role:add"}, logical = Logical.OR)
|
||||
public DataResult operationRolePermission(@RequestBody @Valid RolePermissionOperationReqVO vo) {
|
||||
rolePermissionService.addRolePermission(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
package com.ho.user.controller;
|
||||
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.user.api.entity.PermStationRelation;
|
||||
import com.ho.user.service.PermStationRelationService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: 电站关联菜单
|
||||
* @DateTime: 2023/6/14 9:04
|
||||
*/
|
||||
@RequestMapping(ContextConstant.SYS + "/station/permission")
|
||||
@RestController
|
||||
@Api(tags = "系统管理-电站和菜单关联接口")
|
||||
public class StationPermissionController {
|
||||
@Autowired
|
||||
private PermStationRelationService permStationRelationService;
|
||||
|
||||
/* @PostMapping("page")
|
||||
@ApiOperation(value = "分页获取角色信息接口")
|
||||
//@LogAnnotation(title = "角色管理",action = "分页获取角色信息")
|
||||
//@RequiresPermissions("sys:role:list")
|
||||
public DataResult<PageVO<StationPermissionRespVo>> pageInfo(@RequestBody StationPermissionReqVo vo) {
|
||||
DataResult<PageVO<StationPermissionRespVo>> result = DataResult.success();
|
||||
result.setData(permStationRelationService.pageInfo(vo));
|
||||
return result;
|
||||
}*/
|
||||
|
||||
|
||||
@GetMapping("{id}")
|
||||
@ApiOperation(value = "查询角色详情接口")
|
||||
public DataResult<PermStationRelation> detailInfo(@PathVariable("id") Integer id) {
|
||||
DataResult<PermStationRelation> result = DataResult.success();
|
||||
//返回结果只有当前电站所关联的菜单数据
|
||||
result.setData(permStationRelationService.detailInfo(id));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增电站关联菜单接口")
|
||||
@LogAnnotation(title = "电站菜单管理", action = "新增关联关系")
|
||||
public DataResult add(@RequestBody @Valid PermStationRelation vo) {
|
||||
//入参电站id和菜单idList
|
||||
permStationRelationService.insertSelective(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PutMapping("update")
|
||||
@ApiOperation(value = "更新电站菜单信息接口")
|
||||
@LogAnnotation(title = "电站菜单管理", action = "更新电站菜单信息接口")
|
||||
public DataResult update(@RequestBody @Valid PermStationRelation vo) {
|
||||
//入参电站id和菜单idList
|
||||
//先删除后进行插入
|
||||
permStationRelationService.update(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("delete")
|
||||
@ApiOperation(value = "删除电站关联菜单信息接口")
|
||||
public DataResult delete(@RequestBody @Valid PermStationRelation vo) {
|
||||
//根据电站id进行删除
|
||||
permStationRelationService.deleteBatch(vo.getPermissions());
|
||||
return DataResult.success();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,77 @@
|
||||
package com.ho.user.controller;
|
||||
|
||||
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.UserDetailRespVO;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.user.api.entity.SysLog;
|
||||
import com.ho.user.service.LogService;
|
||||
import com.ho.user.vo.req.SysLogPageReqVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName: SysLogController
|
||||
* TODO:类文件简单描述
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/23 16:15
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/23 16:15
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
@RequestMapping(ContextConstant.SYS + "logs")
|
||||
@Api(tags = "系统模块-系统操作日志管理")
|
||||
@RestController
|
||||
public class SysLogController {
|
||||
|
||||
@Autowired
|
||||
private LogService logService;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
|
||||
@PostMapping("page")
|
||||
@ApiOperation(value = "分页查询系统操作日志接口")
|
||||
//@LogAnnotation(title = "系统操作日志管理", action = "分页查询系统操作日志")
|
||||
//@RequiresPermissions("sys:log:list")
|
||||
public DataResult<PageResult<SysLog>> pageInfo(@RequestBody SysLogPageReqVO vo, HttpServletRequest request) {
|
||||
String token = request.getHeader(CommonConstant.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = redisService.getSimpleUserByToken(token);
|
||||
//对输入的时间进行处理
|
||||
if(vo.getStartTime() != null){
|
||||
String beginTime = vo.getStartTime()+CommonConstant.START_SUFFIX_TIMESTAMP;
|
||||
String time = vo.getEndTime()+CommonConstant.END_SUFFIX_TIMESTAMP;
|
||||
vo.setStartTime(beginTime);
|
||||
vo.setEndTime(time);
|
||||
}
|
||||
PageResult<SysLog> sysLogPageVO = logService.pageInfo(vo,simpleUser);
|
||||
DataResult<PageResult<SysLog>> result = DataResult.success();
|
||||
result.setData(sysLogPageVO);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@DeleteMapping("delete")
|
||||
@ApiOperation(value = "删除日志接口")
|
||||
@LogAnnotation(title = "系统操作日志管理", action = "删除系统操作日志")
|
||||
@RequiresPermissions("sys:log:deleted")
|
||||
public DataResult deleted(@RequestBody @ApiParam(value = "日志id集合") List<Long> logIds) {
|
||||
logService.deleted(logIds);
|
||||
return DataResult.success();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,266 @@
|
||||
package com.ho.user.controller;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.entity.UserDetailRespVO;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.user.api.entity.SysDept;
|
||||
import com.ho.user.api.entity.SysUser;
|
||||
import com.ho.user.api.vo.req.LoginFromLargeScreenVO;
|
||||
import com.ho.user.api.vo.req.UserReq;
|
||||
import com.ho.user.service.DeptService;
|
||||
import com.ho.user.service.EncryptComponent;
|
||||
import com.ho.user.service.UserService;
|
||||
import com.ho.user.vo.req.LoginReqVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: token获取或重新登陆
|
||||
* @date 2023/1/11
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "大屏和云平台登陆")
|
||||
@RequestMapping(ContextConstant.SYS + "token")
|
||||
@Slf4j
|
||||
public class TokenController {
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@Autowired
|
||||
DeptService deptService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
EncryptComponent encryptComponent;
|
||||
|
||||
@Value("${spring.profiles.active}")
|
||||
String env;
|
||||
|
||||
@GetMapping("checkPlatToken")
|
||||
@ApiOperation(value = "验证平台token是否有效")
|
||||
@TokenIgnore
|
||||
public DataResult<Boolean> checkPlatToken(HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
String tokenKey = RedisKeyConstant.User.TOKEN + token;
|
||||
if (redisService.hasKey(tokenKey)) {
|
||||
return DataResult.success(true);
|
||||
} else {
|
||||
return DataResult.success(false);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("applyLargeScreenToken")
|
||||
@ApiOperation(value = "申请大屏token")
|
||||
public DataResult<UserDetailRespVO> getLargeScreenToken(HttpServletRequest request) {
|
||||
//能进到这个方法的肯定已经登陆了
|
||||
String token = request.getHeader(CommonConstant.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = redisService.getSimpleUserByToken(token);
|
||||
UserDetailRespVO userDetail = redisService.getUserDetailByToken(token);
|
||||
//如何判断是重复登陆?因为 largeScreenToken 不过期,所以如果这个largeScreenToken存在,就直接返回,而不再重新生成
|
||||
String bigUserNameKey = redisService.getUserNameKeyForBigToken(userDetail.getUsername());
|
||||
if (redisService.hasKey(bigUserNameKey)) {
|
||||
//
|
||||
log.info("已经存在 大屏token,将直接返回");
|
||||
SimpleUser simpleUserByBigScreenToken = (SimpleUser) redisService.get(bigUserNameKey);
|
||||
//SimpleUser simpleUserByBigScreenToken = redisService.getSimpleUserByBigScreenToken(bigUserNameKey);
|
||||
String bigToken = simpleUserByBigScreenToken.getToken();
|
||||
UserDetailRespVO userDetailByLargeScreenToken = redisService.getUserDetailByLargeScreenToken(bigToken);
|
||||
log.info("得到缓存中的 UserDetailRespVO 并返回 :" + userDetailByLargeScreenToken);
|
||||
return DataResult.success(userDetailByLargeScreenToken);
|
||||
}
|
||||
//不存在,重新生成大屏token
|
||||
String bigToken = IdUtil.simpleUUID();
|
||||
//大屏登陆返回对象,这个对象的元素直接从缓存中拿
|
||||
UserDetailRespVO userDetailBig = new UserDetailRespVO();
|
||||
userDetailBig.setUserId(userDetail.getUserId());
|
||||
userDetailBig.setUsername(userDetail.getUsername());
|
||||
userDetailBig.setAccessToken(bigToken);
|
||||
userDetailBig.setGroupId(userDetail.getGroupId());
|
||||
//因为部门信息有可能已经变更,所以不再保存部门
|
||||
//userDetailBig.setDeptId(userDetail.getDeptId());
|
||||
//userDetailBig.setDeptName(userDetail.getDeptName());
|
||||
//生成SimpleUser对象
|
||||
SimpleUser simpleUserBig = new SimpleUser();
|
||||
simpleUserBig.setGroupId(simpleUser.getGroupId());
|
||||
simpleUserBig.setUserId(simpleUser.getUserId());
|
||||
simpleUserBig.setToken(bigToken);
|
||||
//生成2对大屏token对象, 这两个缓存也设置为2小时过期,因为有接口刷新延续机制
|
||||
//1.token对应的 UserDetailRespVO 对象
|
||||
String tokenKey = RedisKeyConstant.User.TOKEN_LARGE_SCREEN + bigToken;
|
||||
redisService.set(tokenKey, userDetailBig, 365, TimeUnit.DAYS);
|
||||
//2.userName 对应的SimpleUser对象
|
||||
String userNameKey = RedisKeyConstant.User.USER_NAME_LARGE_SCREEN + "pc:" + userDetail.getUsername();
|
||||
redisService.set(userNameKey, simpleUserBig, 365, TimeUnit.DAYS);
|
||||
|
||||
return DataResult.success(userDetailBig);
|
||||
}
|
||||
|
||||
@PostMapping("applyLargeScreenTokenUserId")
|
||||
@ApiOperation(value = "申请大屏token-使用用户id")
|
||||
@TokenIgnore
|
||||
public DataResult<UserDetailRespVO> applyLargeScreenTokenUserId(@RequestBody UserReq userReq) {
|
||||
//使用用户id查询用户信息
|
||||
|
||||
log.info("userId:" + userReq.getUserId());
|
||||
SysUser sysUser = userService.selectById(userReq.getUserId());
|
||||
if (sysUser == null) {
|
||||
throw new BusinessException(BaseResponseCode.NOT_ACCOUNT);
|
||||
}
|
||||
log.info("userName:" + sysUser.getUsername());
|
||||
//如何判断是重复登陆?因为 largeScreenToken 不过期,所以如果这个largeScreenToken存在,就直接返回,而不再重新生成
|
||||
String bigUserNameKey = redisService.getUserNameKeyForBigToken(sysUser.getUsername());
|
||||
if (redisService.hasKey(bigUserNameKey)) {
|
||||
//
|
||||
log.info("已经存在 大屏token,将直接返回");
|
||||
SimpleUser simpleUserByBigScreenToken = (SimpleUser) redisService.get(bigUserNameKey);
|
||||
//SimpleUser simpleUserByBigScreenToken = redisService.getSimpleUserByBigScreenToken(bigUserNameKey);
|
||||
String bigToken = simpleUserByBigScreenToken.getToken();
|
||||
UserDetailRespVO userDetailByLargeScreenToken = redisService.getUserDetailByLargeScreenToken(bigToken);
|
||||
log.info("得到缓存中的 UserDetailRespVO 并返回 :" + userDetailByLargeScreenToken);
|
||||
return DataResult.success(userDetailByLargeScreenToken);
|
||||
}
|
||||
//不存在,重新生成大屏token
|
||||
String bigToken = IdUtil.simpleUUID();
|
||||
//大屏登陆返回对象,这个对象的元素直接从缓存中拿
|
||||
UserDetailRespVO userDetailBig = new UserDetailRespVO();
|
||||
userDetailBig.setUserId(sysUser.getId());
|
||||
userDetailBig.setUsername(sysUser.getUsername());
|
||||
userDetailBig.setAccessToken(bigToken);
|
||||
userDetailBig.setGroupId(sysUser.getGroupId());
|
||||
//因为部门信息有可能已经变更,所以不再保存部门
|
||||
//userDetailBig.setDeptId(userDetail.getDeptId());
|
||||
//userDetailBig.setDeptName(userDetail.getDeptName());
|
||||
//生成SimpleUser对象
|
||||
SimpleUser simpleUserBig = new SimpleUser();
|
||||
simpleUserBig.setGroupId(sysUser.getGroupId());
|
||||
simpleUserBig.setUserId(sysUser.getId());
|
||||
simpleUserBig.setToken(bigToken);
|
||||
//生成2对大屏token对象, 这两个缓存也设置为2小时过期,因为有接口刷新延续机制
|
||||
//1.token对应的 UserDetailRespVO 对象
|
||||
String tokenKey = RedisKeyConstant.User.TOKEN_LARGE_SCREEN + bigToken;
|
||||
redisService.set(tokenKey, userDetailBig, 365, TimeUnit.DAYS);
|
||||
//2.userName 对应的SimpleUser对象
|
||||
String userNameKey = RedisKeyConstant.User.USER_NAME_LARGE_SCREEN + "pc:" + sysUser.getUsername();
|
||||
redisService.set(userNameKey, simpleUserBig, 365, TimeUnit.DAYS);
|
||||
|
||||
return DataResult.success(userDetailBig);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("loginToCloud")
|
||||
//这个方法携带的是 大屏token,所以shiro和 Aspect都不要拦截
|
||||
@TokenIgnore
|
||||
@ApiOperation(value = "使用大屏token登陆到云平台")
|
||||
public DataResult<UserDetailRespVO> loginToCloud(@RequestBody LoginFromLargeScreenVO largeScreenVO) {
|
||||
/**
|
||||
* 登陆过程就是一个完整的登陆验证并颁发token的过程,只是这个登陆是使用大屏token,而不是用户名密码,需要如下两步
|
||||
* 登陆后用户原有token会被冲掉
|
||||
* 1.这个过程需要缓存中一定存在这个大屏token
|
||||
* 2.如果存在,使用这个里面的用户名判断用户状态后直接颁发 云平台token 套件
|
||||
*/
|
||||
String bigToken = largeScreenVO.getBigToken();
|
||||
String username = "";
|
||||
//1.验证缓存中的大屏token
|
||||
String userDetailKey = redisService.getUserDetailKeyForBigToken(bigToken);
|
||||
if (redisService.hasKey(userDetailKey)) {
|
||||
UserDetailRespVO userDetailBigScreen = (UserDetailRespVO) redisService.get(userDetailKey);
|
||||
username = userDetailBigScreen.getUsername();
|
||||
//
|
||||
|
||||
} else {
|
||||
//不存在就报错
|
||||
throw new BusinessException(BaseResponseCode.INVALID_BIG_SCREEN_TOKEN);
|
||||
}
|
||||
//2.验证 username 登陆 并颁发云平台token
|
||||
//查询用户
|
||||
SysUser user = userService.getUserByName(username);
|
||||
//用户不存在
|
||||
if (user == null) {
|
||||
throw new BusinessException(BaseResponseCode.NOT_ACCOUNT);
|
||||
}
|
||||
//状态0 (锁定状态)
|
||||
if (CommonConstant.USER.STATUS_LOCKING.equals(user.getStatus())) {
|
||||
throw new BusinessException(BaseResponseCode.USER_LOCK);
|
||||
}
|
||||
//判断部门是否被禁用
|
||||
SysDept dept = deptService.detailInfo(user.getDeptId());
|
||||
if (!CommonConstant.STATUS_FLAG.equals(dept.getStatus())) {
|
||||
throw new BusinessException(BaseResponseCode.TO_BELONGING_DEPT_DISABLE);
|
||||
}
|
||||
//把aesKey 和iv passwd 解密,此时还是加密的
|
||||
LoginReqVO loginReqTemp = new LoginReqVO();
|
||||
loginReqTemp.setAesKey(largeScreenVO.getAesKey());
|
||||
loginReqTemp.setIv(largeScreenVO.getIv());
|
||||
|
||||
//执行解密,使用私钥对aesKey和iv分别进行解密,然后AES解密
|
||||
//本地环境不加密
|
||||
if (!CommonConstant.Env.DEV.equals(env)) {
|
||||
loginReqTemp = encryptComponent.decryptSecret(loginReqTemp);
|
||||
|
||||
}
|
||||
//使用用户名查询用户并颁发token
|
||||
//获取用户信息
|
||||
UserDetailRespVO userDetail = userService.getUserDetail(user.getId(), RedisKeyConstant.User.LOGIN_CHANNEL_PC);
|
||||
//赋值 登陆渠道 登陆方式
|
||||
//因为是大屏过来的,所以这两个值 赋值为 pc 和 account
|
||||
userDetail.setLoginChannel(RedisKeyConstant.User.LOGIN_CHANNEL_PC);
|
||||
userDetail.setLoginType(RedisKeyConstant.User.LOGIN_TYPE_ACCOUNT);
|
||||
String token = IdUtil.simpleUUID();
|
||||
userDetail.setAccessToken(token);
|
||||
log.info("user:{} ,token:{}", user.getUsername(), token);
|
||||
//生成SimpleUser对象
|
||||
SimpleUser simpleUser = userService.generateSimpleUser(user, userDetail.getDeptId(), token, loginReqTemp);
|
||||
log.info("simpleUser:" + simpleUser);
|
||||
//清除用户用户原有缓存
|
||||
//清除用户登陆缓存
|
||||
userService.removeUserCache(user.getUsername(), RedisKeyConstant.User.LOGIN_CHANNEL_PC);
|
||||
//设置缓存键值对 这两个缓存时间2小时 这个登陆方式固定为pc
|
||||
redisService.set(RedisKeyConstant.User.TOKEN + token, userDetail, 2, TimeUnit.HOURS);
|
||||
redisService.set(RedisKeyConstant.User.USER_NAME + RedisKeyConstant.User.LOGIN_CHANNEL_PC + ":" + user.getUsername(), simpleUser, 2, TimeUnit.HOURS);
|
||||
|
||||
|
||||
return DataResult.success(userDetail);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("applyCommonLargeScreenToken")
|
||||
@ApiOperation(value = "申请通用大屏token")
|
||||
public DataResult<UserDetailRespVO> applyCommonLargeScreenToken(HttpServletRequest request) {
|
||||
//能进到这个方法的肯定已经登陆了
|
||||
String token = request.getHeader(CommonConstant.ACCESS_TOKEN);
|
||||
String tokenCommonLargeScreen = RedisKeyConstant.User.TOKEN_COMMON_LARGE_SCREEN+token;
|
||||
if (redisService.hasKey(tokenCommonLargeScreen)) {
|
||||
SimpleUser simpleUserByBigScreenToken = (SimpleUser) redisService.get(tokenCommonLargeScreen);
|
||||
simpleUserByBigScreenToken.setToken(token);
|
||||
redisService.set(tokenCommonLargeScreen, simpleUserByBigScreenToken, 7, TimeUnit.DAYS);
|
||||
log.info("已经存在 大屏token,将直接返回,simpleUserByBigScreenToken:{}", simpleUserByBigScreenToken);
|
||||
return DataResult.success(simpleUserByBigScreenToken);
|
||||
}
|
||||
SimpleUser simpleUser = redisService.getSimpleUserByToken(token);
|
||||
simpleUser.setToken(token);
|
||||
//不存在,重新生成大屏token
|
||||
redisService.set(tokenCommonLargeScreen, simpleUser, 7, TimeUnit.DAYS);
|
||||
return DataResult.success(simpleUser);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,238 @@
|
||||
package com.ho.user.controller;
|
||||
|
||||
import cn.hutool.core.lang.Snowflake;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.entity.OrderDept;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.user.api.entity.SysDept;
|
||||
import com.ho.user.api.entity.SysLog;
|
||||
import com.ho.user.api.entity.SysSubDict;
|
||||
import com.ho.user.api.entity.SysUser;
|
||||
import com.ho.user.api.vo.req.OrderUserSelectReqVo;
|
||||
import com.ho.user.api.vo.req.QueryDeptReqVO;
|
||||
import com.ho.user.api.vo.req.QueryUserReqVO;
|
||||
import com.ho.user.api.vo.req.SysSubDictVO;
|
||||
import com.ho.user.entity.SysUserPosition;
|
||||
import com.ho.user.mapper.SysDictMapper;
|
||||
import com.ho.user.mapper.SysLogMapper;
|
||||
import com.ho.user.service.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc:
|
||||
* @date 2022/9/2
|
||||
*/
|
||||
@RestController
|
||||
@ApiIgnore
|
||||
@RequestMapping("outerApi")
|
||||
@Slf4j
|
||||
public class UserCenterApiController {
|
||||
|
||||
@Autowired
|
||||
DeptService deptService;
|
||||
|
||||
@Autowired
|
||||
PositionService positionService;
|
||||
|
||||
@Autowired
|
||||
UserPostService userPostService;
|
||||
|
||||
@Autowired
|
||||
DeptOrderUserService deptOrderUserService;
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@Autowired
|
||||
SysLogMapper sysLogMapper;
|
||||
|
||||
@Autowired
|
||||
Snowflake snowflake;
|
||||
|
||||
@Autowired
|
||||
SysDictMapper sysDictMapper;
|
||||
|
||||
|
||||
@PostMapping( "selectBySubId")
|
||||
DataResult<SysSubDict> getDictById(@RequestBody Integer priority){
|
||||
SysSubDict dict = sysDictMapper.selectBySubId(priority);
|
||||
return DataResult.success(dict);
|
||||
}
|
||||
|
||||
@PostMapping( "selectBySubIds")
|
||||
DataResult<List<SysSubDict>> getDictByIds(@RequestBody List<Integer> Ids){
|
||||
List<SysSubDict> dicts = sysDictMapper.getDictByIds(Ids);
|
||||
return DataResult.success(dicts);
|
||||
}
|
||||
|
||||
//根据部门id 查询顶级部门
|
||||
@PostMapping("getTopDept")
|
||||
public DataResult<SysDept> getTopDept(@RequestBody QueryDeptReqVO vo) {
|
||||
SysDept topDept = deptService.getTopDept(vo.getDeptId());
|
||||
return DataResult.success(topDept);
|
||||
}
|
||||
|
||||
|
||||
//得到部门
|
||||
@PostMapping("getDept")
|
||||
public DataResult<List<SysDept>> getDept(@RequestBody List<QueryDeptReqVO> queryDeptReqVO) {
|
||||
DataResult<List<SysDept>> result = DataResult.success();
|
||||
List<Integer> deptIds = queryDeptReqVO.stream().map(QueryDeptReqVO::getDeptId).collect(Collectors.toList());
|
||||
result.setData(deptService.selectByIds(deptIds));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("getUsers")
|
||||
public DataResult<List<SysUser>> queryUser(@RequestBody List<QueryUserReqVO> queryUserReqVO) {
|
||||
List<String> userIds = new ArrayList<>();
|
||||
List<SysUser> sysUsers = new ArrayList<>();
|
||||
if (queryUserReqVO != null && !queryUserReqVO.isEmpty()) {
|
||||
for (QueryUserReqVO userReqVO : queryUserReqVO) {
|
||||
userIds.add(userReqVO.getUserId());
|
||||
}
|
||||
}
|
||||
if (!userIds.isEmpty()) {
|
||||
sysUsers = userService.selectIds(userIds);
|
||||
}
|
||||
return DataResult.success(sysUsers);
|
||||
}
|
||||
|
||||
//根据模糊匹配用户名查询用户 多个
|
||||
@PostMapping("getUserByNameConcat")
|
||||
public DataResult<List<SysUser>> getUserByNameConcat(@RequestBody QueryUserReqVO queryUserReqVO) {
|
||||
return DataResult.success(userService.getUserListByNameConcat(queryUserReqVO.getUserName(), queryUserReqVO.getGroupId()));
|
||||
}
|
||||
|
||||
//根据用户id查询用户
|
||||
@PostMapping("getUserById")
|
||||
public DataResult<SysUser> getUserById(@RequestBody String userId) {
|
||||
SysUser sysUser = userService.selectById(userId);
|
||||
return DataResult.success(sysUser);
|
||||
}
|
||||
|
||||
@PostMapping("queryUserById")
|
||||
public SysUser queryUserById(@RequestBody String userId) {
|
||||
return userService.selectById(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 外部请求记录日志
|
||||
*
|
||||
* @param sysLog
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("insertLog")
|
||||
public DataResult insertLog(@RequestBody SysLog sysLog) {
|
||||
|
||||
sysLogMapper.insertSelective(sysLog);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
//根据用户id查询用户
|
||||
@PostMapping("getUserByIds")
|
||||
public DataResult<List<SysUser>> getUserByIds(@RequestBody Set<String> userIds) {
|
||||
List<String> list = userIds.stream().collect(Collectors.toList());
|
||||
return DataResult.success(userService.selectIds(list));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据岗位编码查询岗位用户
|
||||
* @param postIds
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("selectByPostIds")
|
||||
public DataResult<List<SysUser>> selectByPostIds(@RequestBody List<Integer> postIds){
|
||||
//根据岗位id查询对应的用户
|
||||
List<String> userIds = userPostService.getUserIdsByPostIds(postIds);
|
||||
//根据用户id查询用户
|
||||
List<SysUser> sysUsers = userService.selectPostUserIds(userIds,postIds);
|
||||
return DataResult.success(sysUsers);
|
||||
}
|
||||
|
||||
@PostMapping("selectAllPostUser")
|
||||
public DataResult<List<SysUser>> selectAllPostUser(){
|
||||
//根据岗位id查询对应的用户
|
||||
List<SysUserPosition> sysUserPositions = userPostService.getByPostIds(new ArrayList<>());
|
||||
List<Integer> postIds = sysUserPositions.stream().map(SysUserPosition::getPositionId).collect(Collectors.toList());
|
||||
List<String> userIds = sysUserPositions.stream().map(SysUserPosition::getUserId).collect(Collectors.toList());
|
||||
//根据用户id查询用户
|
||||
List<SysUser> sysUsers = userService.selectPostUserIds(userIds,postIds);
|
||||
return DataResult.success(sysUsers);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据postCodes 查岗位id 在查询到对应的人员id 根据人员id查询到人
|
||||
*
|
||||
* @param vo
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("selectByPostCodeTree")
|
||||
public DataResult<List<OrderDept>> selectByPostCodeTree(@RequestBody OrderUserSelectReqVo vo) {
|
||||
//根据groupId查询顶级部门
|
||||
SysDept topDept = deptService.detailInfo(vo.getGroupId());
|
||||
List<OrderDept> orderDepts = new ArrayList<>();
|
||||
//没查到顶级部门就不往下走了
|
||||
if (topDept == null) {
|
||||
return DataResult.success(orderDepts);
|
||||
}
|
||||
List<Integer> postIds = positionService.selectPostIds(vo.getPostCodes());
|
||||
//查不到信息返回空,不要报错
|
||||
if (postIds == null || postIds.isEmpty()) {
|
||||
//throw new BusinessException(BaseResponseCode.NO_RELEVANT_POSITIONS);
|
||||
return DataResult.success(orderDepts);
|
||||
}
|
||||
List<SysUser> sysUsers = userPostService.selectUserByPostIds(vo, postIds);
|
||||
if (sysUsers == null || sysUsers.isEmpty()) {
|
||||
//throw new BusinessException(BaseResponseCode.NO_QUALIFIED_PERSONNEL_IN_ALL_DEPARTMENTS);
|
||||
return DataResult.success(orderDepts);
|
||||
}
|
||||
//
|
||||
OrderDept orderDeptTop = deptOrderUserService.getDeptUser(topDept, sysUsers);
|
||||
|
||||
//等级的那个部门可以直接挂人
|
||||
//以List形势返回
|
||||
List<OrderDept> deptAndUsers = new ArrayList<>();
|
||||
deptAndUsers.add(orderDeptTop);
|
||||
return DataResult.success(deptAndUsers);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对外提供上送数据专用
|
||||
* @param vo
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("getSysSubDict")
|
||||
@TokenIgnore
|
||||
public Map<String, String> getSysSubDict(@RequestBody SysSubDictVO vo) {
|
||||
Map<String, String> sysSubDict = userService.getSysSubDict(vo);
|
||||
return sysSubDict;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对外提供上送数据专用
|
||||
* @param deptId
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("getSysDeptByDeptId")
|
||||
@TokenIgnore
|
||||
public List<SysDept> getSysDeptByDeptId(@RequestBody Integer deptId) {
|
||||
List<SysDept> sysSubDict = deptService.depListByDeptId(deptId);
|
||||
return sysSubDict;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,545 @@
|
||||
package com.ho.user.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.crypto.digest.BCrypt;
|
||||
import com.ho.common.tools.annotation.HzPermission;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.PermissionConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.entity.SysRole;
|
||||
import com.ho.common.tools.entity.UserDetailRespVO;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.AESEncryptUtil;
|
||||
import com.ho.common.tools.util.FastUtils;
|
||||
import com.ho.user.api.entity.SysDept;
|
||||
import com.ho.user.api.entity.SysUser;
|
||||
import com.ho.user.api.entity.WorkOrderUser;
|
||||
import com.ho.user.entity.SysTheme;
|
||||
import com.ho.user.service.*;
|
||||
import com.ho.user.vo.req.*;
|
||||
import com.ho.user.vo.resp.SysUserThemeRespVo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.time.DateUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: 用户入口
|
||||
* @date 2022/8/10
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "系统模块-用户管理")
|
||||
@RequestMapping(ContextConstant.SYS + "/user")
|
||||
@Slf4j
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
RoleService roleService;
|
||||
|
||||
@Autowired
|
||||
private UserRoleService userRoleService;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private DeptService deptService;
|
||||
|
||||
@Autowired
|
||||
EncryptComponent encryptComponent;
|
||||
|
||||
@Value("${spring.profiles.active}")
|
||||
String env;
|
||||
|
||||
|
||||
@GetMapping("{id}")
|
||||
@ApiOperation(value = "查询用户详情接口")
|
||||
//@LogAnnotation(title = "用户管理",action = "查询用户详情")
|
||||
//@RequiresPermissions("sys:user:detail")
|
||||
public DataResult<SysUser> detailInfo(@PathVariable("id") String id) {
|
||||
DataResult<SysUser> result = DataResult.success();
|
||||
result.setData(userService.detailInfo(id));
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户详情接口(新)
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("get")
|
||||
@ApiOperation(value = "查询用户详情接口(新)")
|
||||
//@LogAnnotation(title = "用户管理",action = "查询用户详情")
|
||||
public DataResult<UserDetailRespVO> yourSelfInfo(@RequestParam(required = false) String type,HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
String userTokenKey = RedisKeyConstant.User.TOKEN + token;
|
||||
//根据用户的登陆方式(账号还是手机号),延长对应缓存
|
||||
if (redisService.hasKey(userTokenKey)) {
|
||||
//每次获取用户信息,都会进行过期时间的延长
|
||||
UserDetailRespVO user = (UserDetailRespVO) redisService.get(userTokenKey);
|
||||
SimpleUser simpleUser = (SimpleUser) redisService.getSimpleUserByToken(token);
|
||||
//获取到缓存的token中的roleIds,根据roleIds进行菜单查找
|
||||
if(null != type){
|
||||
user.setConfigType(type);
|
||||
}
|
||||
UserDetailRespVO vo = userService.yourSelfInfo(user, simpleUser.getPlatSuper());
|
||||
//延长token时间
|
||||
//redisCommon.extendKeyTime(userTokenKey, null);
|
||||
//String userNameKey = RedisKeyConstant.User.USER_NAME + user.getUsername();
|
||||
//登陆方式,账号或手机号,都使用同一个key,此处没必要区分是手机号还是账号登陆的
|
||||
//已经有Aspect在延长token时长了,其他地方不用再延长了
|
||||
//redisCommon.extendKeyTime(userNameKey, null);
|
||||
return DataResult.success(vo);
|
||||
}
|
||||
//没有就让用户重新登陆
|
||||
else {
|
||||
log.info("User token has expired ! token :{}", token);
|
||||
throw new BusinessException(BaseResponseCode.TOKEN_PARSE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回的参数类型和youSelfInfo信息一样,这样前端就可以通过login获取到全部信息,不用再调用用户详情接口了
|
||||
* 2022-11-10修改 同一个账号在pc端还是移动端登陆需要分别判断,不能走同一个token
|
||||
* 2022-11-23 同一用户不允许重复登陆
|
||||
*
|
||||
* @param loginReqVO
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "login")
|
||||
@ApiOperation(value = "用户登录接口")
|
||||
@TokenIgnore
|
||||
public DataResult<UserDetailRespVO> login(@RequestBody @Valid LoginReqVO loginReqVO) {
|
||||
//登陆缓存有两个键值对,一个是Key是 userName:SimpleUser ,另一个是Key是token,value是UserDetailRespVO
|
||||
//这个userName可能为账号或者手机号
|
||||
//先判断用户是否登陆成功
|
||||
//判断是账号还是手机号
|
||||
//手机号登陆的
|
||||
if (FastUtils.checkPhoneNumber(loginReqVO.getUsername())) {
|
||||
loginReqVO.setLoginType(RedisKeyConstant.User.LOGIN_TYPE_PHONE);
|
||||
} else {
|
||||
loginReqVO.setLoginType(RedisKeyConstant.User.LOGIN_TYPE_ACCOUNT);
|
||||
}
|
||||
|
||||
//验证登陆
|
||||
SysUser user = null;
|
||||
//手机号登陆的
|
||||
if (RedisKeyConstant.User.LOGIN_TYPE_PHONE.equals(loginReqVO.getLoginType())) {
|
||||
user = userService.getUserByPhone(loginReqVO.getUsername());
|
||||
}
|
||||
//账号登陆的
|
||||
else if (RedisKeyConstant.User.LOGIN_TYPE_ACCOUNT.equals(loginReqVO.getLoginType())) {
|
||||
user = userService.getUserByName(loginReqVO.getUsername());
|
||||
}
|
||||
if (user == null) {
|
||||
throw new BusinessException(BaseResponseCode.NOT_ACCOUNT);
|
||||
}
|
||||
|
||||
if (CommonConstant.TWO.equals(user.getPeriodOfValidity())){
|
||||
Date date = DateUtils.addHours(user.getUpdateTime(), 6);
|
||||
Date now = new Date();
|
||||
if(DateUtil.compare(now,date)>=0){
|
||||
throw new BusinessException(BaseResponseCode.LOSE_EFFICACY);
|
||||
}
|
||||
}
|
||||
//状态0 (锁定状态)
|
||||
if (CommonConstant.USER.STATUS_LOCKING.equals(user.getStatus())) {
|
||||
throw new BusinessException(BaseResponseCode.USER_LOCK);
|
||||
}
|
||||
//校验部门状态是否为禁用
|
||||
if(!CommonConstant.ZERO.equals(user.getDeptId())){
|
||||
SysDept dept = deptService.detailInfo(user.getDeptId());
|
||||
if(!CommonConstant.STATUS_FLAG.equals(dept.getStatus())){
|
||||
throw new BusinessException(BaseResponseCode.TO_BELONGING_DEPT_DISABLE);
|
||||
}
|
||||
}
|
||||
//执行解密,使用私钥对aesKey和iv分别进行解密,然后AES解密
|
||||
//本地环境不加密
|
||||
// if (!CommonConstant.Env.DEV.equals(env)) {
|
||||
loginReqVO = encryptComponent.decryptSecret(loginReqVO);
|
||||
// }
|
||||
//即使走了缓存也要再校验一次密码
|
||||
//要使用明文密码
|
||||
if (!BCrypt.checkpw(loginReqVO.getPassword(), user.getPassword())) {
|
||||
throw new BusinessException(BaseResponseCode.PASSWORD_ERROR);
|
||||
}
|
||||
//清除用户登陆缓存
|
||||
//userService.removeUserCache(user.getUsername(), loginReqVO.getType());
|
||||
//若是特殊用户,则不更删除缓存,允许多点登录
|
||||
Map<String, String> map = userService.checkSpecialUser();
|
||||
if(null == map.get(user.getUsername())){
|
||||
userService.removeUserCache(user.getUsername(), loginReqVO.getType());
|
||||
}
|
||||
|
||||
|
||||
log.info("Not have user's RedisCache info ,next to find from DB");
|
||||
//解密密码并校验
|
||||
return DataResult.success(userService.login(loginReqVO, user));
|
||||
}
|
||||
|
||||
@PostMapping(value = "getToken")
|
||||
@ApiOperation(value = "用户登录接口")
|
||||
@TokenIgnore
|
||||
public DataResult<UserDetailRespVO> getToken(@RequestBody @Valid LoginReqVO loginReqVO) {
|
||||
if (FastUtils.checkPhoneNumber(loginReqVO.getUsername())) {
|
||||
loginReqVO.setLoginType(RedisKeyConstant.User.LOGIN_TYPE_PHONE);
|
||||
} else {
|
||||
loginReqVO.setLoginType(RedisKeyConstant.User.LOGIN_TYPE_ACCOUNT);
|
||||
}
|
||||
|
||||
//验证登陆
|
||||
SysUser user = null;
|
||||
//手机号登陆的
|
||||
if (RedisKeyConstant.User.LOGIN_TYPE_PHONE.equals(loginReqVO.getLoginType())) {
|
||||
user = userService.getUserByPhone(loginReqVO.getUsername());
|
||||
}
|
||||
//账号登陆的
|
||||
else if (RedisKeyConstant.User.LOGIN_TYPE_ACCOUNT.equals(loginReqVO.getLoginType())) {
|
||||
user = userService.getUserByName(loginReqVO.getUsername());
|
||||
}
|
||||
if (user == null) {
|
||||
throw new BusinessException(BaseResponseCode.NOT_ACCOUNT);
|
||||
}
|
||||
|
||||
if (CommonConstant.TWO.equals(user.getPeriodOfValidity())){
|
||||
Date date = DateUtils.addHours(user.getUpdateTime(), 6);
|
||||
Date now = new Date();
|
||||
if(DateUtil.compare(now,date)>=0){
|
||||
throw new BusinessException(BaseResponseCode.LOSE_EFFICACY);
|
||||
}
|
||||
}
|
||||
//状态0 (锁定状态)
|
||||
if (CommonConstant.USER.STATUS_LOCKING.equals(user.getStatus())) {
|
||||
throw new BusinessException(BaseResponseCode.USER_LOCK);
|
||||
}
|
||||
//校验部门状态是否为禁用
|
||||
if(!CommonConstant.ZERO.equals(user.getDeptId())){
|
||||
SysDept dept = deptService.detailInfo(user.getDeptId());
|
||||
if(!CommonConstant.STATUS_FLAG.equals(dept.getStatus())){
|
||||
throw new BusinessException(BaseResponseCode.TO_BELONGING_DEPT_DISABLE);
|
||||
}
|
||||
}
|
||||
//即使走了缓存也要再校验一次密码
|
||||
//要使用明文密码
|
||||
if (!BCrypt.checkpw(loginReqVO.getPassword(), user.getPassword())) {
|
||||
throw new BusinessException(BaseResponseCode.PASSWORD_ERROR);
|
||||
}
|
||||
//清除用户登陆缓存
|
||||
//userService.removeUserCache(user.getUsername(), loginReqVO.getType());
|
||||
//若是特殊用户,则不更删除缓存,允许多点登录
|
||||
Map<String, String> map = userService.checkSpecialUser();
|
||||
if(null == map.get(user.getUsername())){
|
||||
userService.removeUserCache(user.getUsername(), loginReqVO.getType());
|
||||
}
|
||||
|
||||
|
||||
log.info("Not have user's RedisCache info ,next to find from DB");
|
||||
//解密密码并校验
|
||||
return DataResult.success(userService.login(loginReqVO, user));
|
||||
}
|
||||
/**
|
||||
* 原登陆接口, 已过期,使用登陆成功就将原有token失效
|
||||
* @param loginReqVO
|
||||
* @return
|
||||
*/
|
||||
//@PostMapping(value = "login")
|
||||
//@ApiOperation(value = "用户登录接口")
|
||||
//@TokenIgnore
|
||||
public DataResult<UserDetailRespVO> login2(@RequestBody @Valid LoginReqVO loginReqVO) {
|
||||
//登陆缓存有两个键值对,一个是Key是 userName:SimpleUser ,另一个是Key是token,value是UserDetailRespVO
|
||||
//这个userName可能为账号或者手机号
|
||||
|
||||
String userNameKey = RedisKeyConstant.User.USER_NAME + loginReqVO.getType() + ":" + loginReqVO.getUsername();
|
||||
//判断是账号还是手机号
|
||||
//手机号登陆的
|
||||
if (FastUtils.checkPhoneNumber(loginReqVO.getUsername())) {
|
||||
loginReqVO.setLoginType(RedisKeyConstant.User.LOGIN_TYPE_PHONE);
|
||||
} else {
|
||||
loginReqVO.setLoginType(RedisKeyConstant.User.LOGIN_TYPE_ACCOUNT);
|
||||
}
|
||||
//执行解密,使用私钥对aesKey和iv分别进行解密,然后AES解密
|
||||
//本地环境不加密
|
||||
if (!CommonConstant.Env.DEV.equals(env)) {
|
||||
loginReqVO = encryptComponent.decryptSecret(loginReqVO);
|
||||
}
|
||||
//为避免重复登陆,看缓存中是否有用户信息
|
||||
if (redisService.hasKey(userNameKey)) {
|
||||
SimpleUser simpleUser = (SimpleUser) redisService.get(userNameKey);
|
||||
if (simpleUser != null) {
|
||||
String token = simpleUser.getToken();
|
||||
String userTokenKey = RedisKeyConstant.User.TOKEN + token;
|
||||
UserDetailRespVO userDetail = (UserDetailRespVO) redisService.get(userTokenKey);
|
||||
//需要判断使用是同一个渠道登陆的
|
||||
if (loginReqVO.getType().equals(userDetail.getLoginChannel())) {
|
||||
//相同,走缓存,不相同说明这个渠道没登陆过,重新安排一次登陆
|
||||
} else {
|
||||
//没有登陆的情况
|
||||
DataResult.success(userService.login(loginReqVO, null));
|
||||
}
|
||||
SysUser user = null;
|
||||
//手机号登陆的
|
||||
if (RedisKeyConstant.User.LOGIN_TYPE_PHONE.equals(userDetail.getLoginType())) {
|
||||
user = userService.getUserByPhone(loginReqVO.getUsername());
|
||||
}
|
||||
//账号登陆的
|
||||
else if (RedisKeyConstant.User.LOGIN_TYPE_ACCOUNT.equals(userDetail.getLoginType())) {
|
||||
user = userService.getUserByName(loginReqVO.getUsername());
|
||||
}
|
||||
if (user == null) {
|
||||
throw new BusinessException(BaseResponseCode.NOT_ACCOUNT);
|
||||
}
|
||||
//状态2 (锁定状态) 暂时没用到
|
||||
if (user.getStatus() == 2) {
|
||||
throw new BusinessException(BaseResponseCode.USER_LOCK);
|
||||
}
|
||||
//即使走了缓存也要再校验一次密码
|
||||
//要使用明文密码
|
||||
if (!BCrypt.checkpw(loginReqVO.getPassword(), user.getPassword())) {
|
||||
throw new BusinessException(BaseResponseCode.PASSWORD_ERROR);
|
||||
}
|
||||
//解密密码并校验
|
||||
return DataResult.success(userDetail);
|
||||
}
|
||||
}
|
||||
log.info("Not have user's RedisCache info ,next to find from DB");
|
||||
//没缓存就走DB
|
||||
//解密密码并校验
|
||||
|
||||
return DataResult.success(userService.login(loginReqVO ,null));
|
||||
}
|
||||
|
||||
//解密演示,不对外提供接口
|
||||
@ApiIgnore
|
||||
@PostMapping(value = "login1")
|
||||
@TokenIgnore
|
||||
public DataResult<UserDetailRespVO> login1(@RequestBody @Valid LoginReqVO loginReqVO) {
|
||||
//使用私钥对aesKey和iv分别进行解密,然后AES解密
|
||||
loginReqVO = encryptComponent.decryptSecret(loginReqVO);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("register")
|
||||
@ApiOperation(value = "用户注册接口")
|
||||
public DataResult<String> register(@RequestBody @Valid RegisterReqVO vo) {
|
||||
DataResult<String> result = DataResult.success();
|
||||
result.setData(userService.register(vo));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增用户接口")
|
||||
@RequiresPermissions("sys:user:add")
|
||||
@LogAnnotation(title = "用户管理", action = "新增用户")
|
||||
public DataResult addUser(@RequestBody @Valid UserAddReqVO vo) {
|
||||
userService.addUser(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PutMapping("info")
|
||||
@ApiOperation(value = "更新用户信息接口")
|
||||
@LogAnnotation(title = "用户管理", action = "更新用户信息")
|
||||
@RequiresPermissions("sys:user:update")
|
||||
public DataResult updateUserInfoById(@RequestBody @Valid UserUpdateReqVO vo, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
String userTokenKey = RedisKeyConstant.User.TOKEN + token;
|
||||
UserDetailRespVO user = (UserDetailRespVO) redisService.get(userTokenKey);
|
||||
String operationId = user.getUserId();
|
||||
//判断手机号是否被其他人占用
|
||||
SysUser userByPhone = userService.getUserByPhone(vo.getPhone());
|
||||
if (userByPhone != null) {
|
||||
//这个手机号如果被其他人占用要提示
|
||||
if (!userByPhone.getId().equals(vo.getId())) {
|
||||
throw new BusinessException(BaseResponseCode.PHONE_IS_USED_BY_OTHER_PERSON);
|
||||
}
|
||||
}
|
||||
//这个token是操作者的token
|
||||
userService.updateUserInfo(vo, operationId, token);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("logout")
|
||||
@ApiOperation(value = "退出接口")
|
||||
//@LogAnnotation(title = "用户管理",action = "退出")
|
||||
@TokenIgnore
|
||||
public DataResult logout(HttpServletRequest request) {
|
||||
String accessToken = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
// String refreshToken = request.getHeader(Constant.REFRESH_TOKEN);
|
||||
//暂时不传递 refresh_token
|
||||
userService.logout(accessToken);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PutMapping("pwd")
|
||||
@ApiOperation(value = "修改密码接口")
|
||||
@LogAnnotation(title = "用户管理", action = "更新密码")
|
||||
public DataResult updatePwd(@RequestBody UpdatePasswordReqVO vo, HttpServletRequest request) {
|
||||
String accessToken = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = redisService.getSimpleUserByToken(accessToken);
|
||||
//解密旧密码
|
||||
String oldPwdPlain = AESEncryptUtil.decrypt(vo.getOldPwd(), simpleUser.getAesKey(), simpleUser.getIv());
|
||||
String newPwdPlain = AESEncryptUtil.decrypt(vo.getNewPwd(), simpleUser.getAesKey(), simpleUser.getIv());
|
||||
vo.setOldPwd(oldPwdPlain);
|
||||
vo.setNewPwd(newPwdPlain);
|
||||
if (simpleUser != null) {
|
||||
userService.updatePwd(vo, simpleUser.getUserId(), accessToken);
|
||||
}
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PutMapping("resetpwd")
|
||||
@ApiOperation(value = "重置密码接口")
|
||||
@LogAnnotation(title = "用户管理", action = "重置密码")
|
||||
@HzPermission(PermissionConstant.SYS_USER_RESETPWD)
|
||||
public DataResult resetPwd(@RequestBody ResetPasswordReqVO vo) {
|
||||
userService.resetPwd(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping("delete")
|
||||
@ApiOperation(value = "删除用户接口")
|
||||
@LogAnnotation(title = "用户管理", action = "删除用户")
|
||||
@RequiresPermissions("sys:user:deleted")
|
||||
public DataResult deletedUser(@RequestBody @ApiParam(value = "用户id集合") List<String> userIds, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
String userTokenKey = RedisKeyConstant.User.TOKEN + token;
|
||||
UserDetailRespVO user = (UserDetailRespVO) redisService.get(userTokenKey);
|
||||
String operationId = user.getUserId();
|
||||
userService.deletedUsers(userIds, operationId);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
//原来的查询工单维修人员方法,已改为使用下面的新方法
|
||||
/*@PostMapping("workOrder/findWorkers")
|
||||
@ApiOperation(value = "工单维修人员列表")
|
||||
public DataResult<List<WorkOrderUser>> findWorkers(HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = redisService.getSimpleUserByToken(token);
|
||||
//查询工单维修角色下的人员列表
|
||||
//先用角色code查角色
|
||||
SysRole roleInfo = roleService.findRoleInfoByRoleCode(CommonConstant.ROLE_WORK_ORDER_DO);
|
||||
if (roleInfo == null) {
|
||||
throw new BusinessException(BaseResponseCode.ROLE_INFO_NOT_FOUND);
|
||||
}
|
||||
List<Integer> roleIds = new ArrayList<>();
|
||||
roleIds.add(roleInfo.getId());
|
||||
List<String> userIdsByRoleIds = userRoleService.getUserIdsByRoleIds(roleIds);
|
||||
UserPageUserByDeptReqVO userQuery = new UserPageUserByDeptReqVO();
|
||||
userQuery.setUserIds(userIdsByRoleIds);
|
||||
//人员所属部门
|
||||
List<Integer> depts = simpleUser.getDepts();
|
||||
//根据部门和对应的角色用户匹配结果
|
||||
List<SysUser> userListByDeptIdsAndUserIds = userService.getUserListByDeptIdsAndUserIds(depts, userQuery);
|
||||
List<WorkOrderUser> userList = new ArrayList<>();
|
||||
if (!userListByDeptIdsAndUserIds.isEmpty()) {
|
||||
for (SysUser sysUser : userListByDeptIdsAndUserIds) {
|
||||
WorkOrderUser user = new WorkOrderUser();
|
||||
user.setUserId(sysUser.getId());
|
||||
user.setUsername(sysUser.getUsername());
|
||||
user.setRealName(sysUser.getRealName());
|
||||
user.setPhone(sysUser.getPhone());
|
||||
userList.add(user);
|
||||
}
|
||||
}
|
||||
return DataResult.success(userList);
|
||||
}*/
|
||||
|
||||
@PostMapping("workOrder/findWorkers")
|
||||
@ApiOperation(value = "工单维修人员列表")
|
||||
public DataResult<List<WorkOrderUser>> findWorkers(HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser simpleUser = redisService.getSimpleUserByToken(token);
|
||||
//查询工单维修角色下的人员列表
|
||||
//先用角色code查角色
|
||||
SysRole roleInfo = roleService.findRoleInfoByRoleCode(CommonConstant.ROLE_WORK_ORDER_DO);
|
||||
if (roleInfo == null) {
|
||||
throw new BusinessException(BaseResponseCode.ROLE_INFO_NOT_FOUND);
|
||||
}
|
||||
List<Integer> roleIds = new ArrayList<>();
|
||||
roleIds.add(roleInfo.getId());
|
||||
List<String> userIdsByRoleIds = userRoleService.getUserIdsByRoleIds(roleIds);
|
||||
UserPageUserByDeptReqVO userQuery = new UserPageUserByDeptReqVO();
|
||||
userQuery.setUserIds(userIdsByRoleIds);
|
||||
//人员所属部门
|
||||
List<Integer> depts = simpleUser.getDepts();
|
||||
//根据部门和对应的角色用户匹配结果
|
||||
List<SysUser> userListByDeptIdsAndUserIds = userService.getUserListByDeptIdsAndUserIds(depts, userQuery,null);
|
||||
List<WorkOrderUser> userList = new ArrayList<>();
|
||||
if (!userListByDeptIdsAndUserIds.isEmpty()) {
|
||||
for (SysUser sysUser : userListByDeptIdsAndUserIds) {
|
||||
WorkOrderUser user = new WorkOrderUser();
|
||||
user.setUserId(sysUser.getId());
|
||||
user.setUsername(sysUser.getUsername());
|
||||
user.setRealName(sysUser.getRealName());
|
||||
user.setPhone(sysUser.getPhone());
|
||||
userList.add(user);
|
||||
}
|
||||
}
|
||||
return DataResult.success(userList);
|
||||
}
|
||||
|
||||
@PostMapping("getMac")
|
||||
@ApiOperation(value = "获取mac地址")
|
||||
@TokenIgnore
|
||||
public DataResult getMac() {
|
||||
log.info("begin to getMac");
|
||||
// -1 失败 0 成功
|
||||
try {
|
||||
Process proc = Runtime.getRuntime().exec("/bin/bash /data/so/test.sh");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
log.info("end to getMac");
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@GetMapping("getUserTheme/{userId}")
|
||||
@ApiOperation(value = "获取用户主题信息")
|
||||
public DataResult getUserTheme(@PathVariable String userId) {
|
||||
SysUserThemeRespVo theme = userService.getUserTheme(userId);
|
||||
return DataResult.success(theme);
|
||||
}
|
||||
|
||||
@GetMapping("getSysTheme")
|
||||
@ApiOperation(value = "获取用户主题信息")
|
||||
public DataResult getSysTheme() {
|
||||
List<SysTheme> theme = userService.getSysTheme();
|
||||
return DataResult.success(theme);
|
||||
}
|
||||
|
||||
@PostMapping("addUserTheme")
|
||||
@ApiOperation(value = "新增用户主题信息")
|
||||
public DataResult addUserTheme(@RequestBody SysUserThemeReqVo sysUserThemeReqVo) {
|
||||
if(sysUserThemeReqVo.getUserId() == null || sysUserThemeReqVo.getUserId() ==""){
|
||||
throw new BusinessException(BaseResponseCode.PARAM_CHECK_FAIL);
|
||||
}
|
||||
userService.addUserTheme(sysUserThemeReqVo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package com.ho.user.controller;
|
||||
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.user.service.UserRoleService;
|
||||
import com.ho.user.vo.req.UserRoleOperationReqVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* 用户角色关联入口
|
||||
*/
|
||||
@RequestMapping(ContextConstant.SYS + "user/role")
|
||||
@RestController
|
||||
@Api(tags = "系统管理-用户和角色关联接口")
|
||||
public class UserRoleController {
|
||||
|
||||
@Autowired
|
||||
private UserRoleService userRoleService;
|
||||
|
||||
@PostMapping
|
||||
@ApiOperation(value = "修改或者新增用户角色接口")
|
||||
@LogAnnotation(title = "用户和角色关联接口", action = "修改或者新增用户角色")
|
||||
public DataResult operationUserRole(@RequestBody @Valid UserRoleOperationReqVO vo) {
|
||||
userRoleService.addUserRoleInfo(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
}
|
||||
23
user-service/src/main/java/com/ho/user/entity/IdControl.java
Normal file
23
user-service/src/main/java/com/ho/user/entity/IdControl.java
Normal file
@ -0,0 +1,23 @@
|
||||
package com.ho.user.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* @version 1.0.0
|
||||
* @ClassName iIdControl.java
|
||||
* @Description TODO
|
||||
* @createTime 2022年09月22日 09:18:00
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class IdControl {
|
||||
|
||||
private Integer id;
|
||||
private String type;
|
||||
private Integer currentVal;
|
||||
}
|
||||
@ -0,0 +1,65 @@
|
||||
package com.ho.user.entity;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
public class PermissionRespNode {
|
||||
@ApiModelProperty(value = "id")
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "菜单权限名称")
|
||||
private String title;
|
||||
|
||||
@ApiModelProperty(value = "菜单名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "菜单权限标识,shiro 适配restful")
|
||||
private String perms;
|
||||
|
||||
@ApiModelProperty(value = "接口地址")
|
||||
private String url;
|
||||
|
||||
@ApiModelProperty(value = "请求方式 和url 配合使用 (我们用 路径匹配的方式做权限管理的时候用到)")
|
||||
private String method;
|
||||
|
||||
@ApiModelProperty(value = "父级id")
|
||||
private Integer pid;
|
||||
|
||||
@ApiModelProperty(value = "父级名称")
|
||||
private String pidName;
|
||||
|
||||
@ApiModelProperty(value = "编码(前后端分离 前段对按钮显示隐藏控制 btn-permission-search 代表 菜单权限管理的列表查询按钮)")
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty(value = "排序码")
|
||||
private Integer orderNum;
|
||||
|
||||
@ApiModelProperty(value = "是否展开 默认不展开(false)")
|
||||
private boolean spread=true;
|
||||
|
||||
@ApiModelProperty(value = "菜单权限类型(1:目录;2:菜单;3:按钮)")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty(value = "icon图标")
|
||||
private String icon;
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
@ApiModelProperty(value = "启用状态:1:启用;2:未启用")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "菜单归属--菜单展示类型:all(通用类型) pc(仅PC端展示) app(仅APP展示)")
|
||||
private String show;
|
||||
|
||||
@ApiModelProperty(value = "是否选中 默认false")
|
||||
private boolean checked;
|
||||
private List<?> children;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package com.ho.user.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.apache.shiro.authz.SimpleAuthorizationInfo;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: 自定义权限对象,继承自框架,扩展了用户的部门等信息
|
||||
* @date 2022/8/24
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class SimpleAuther extends SimpleAuthorizationInfo {
|
||||
|
||||
}
|
||||
25
user-service/src/main/java/com/ho/user/entity/SysDict.java
Normal file
25
user-service/src/main/java/com/ho/user/entity/SysDict.java
Normal file
@ -0,0 +1,25 @@
|
||||
package com.ho.user.entity;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc:
|
||||
* @date 2022/8/18
|
||||
*/
|
||||
@ToString
|
||||
@Setter
|
||||
@Getter
|
||||
public class SysDict implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
private String type;
|
||||
private String typeName;
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
package com.ho.user.entity;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @TableName sys_position
|
||||
*/
|
||||
@Data
|
||||
public class SysPosition implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ApiModelProperty(value = "岗位编号")
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 岗位编码
|
||||
*/
|
||||
@ApiModelProperty(value = "岗位编码")
|
||||
private String postCode;
|
||||
|
||||
/**
|
||||
* 岗位名称
|
||||
*/
|
||||
@ApiModelProperty(value = "岗位名称")
|
||||
private String name;
|
||||
|
||||
|
||||
/**
|
||||
* 岗位状态(0:禁用 1:正常 )
|
||||
*/
|
||||
@ApiModelProperty(value = "岗位状态(0:禁用 1:正常 )")
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@ApiModelProperty(value = "修改时间")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 是否删除(1未删除;0已删除)
|
||||
*/
|
||||
@ApiModelProperty(value = "是否删除(1未删除;0已删除)")
|
||||
private Integer deleted;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@ApiModelProperty(value = "备注")
|
||||
private String desc;
|
||||
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package com.ho.user.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class SysRolePermission implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private Integer roleId;
|
||||
|
||||
private Integer permissionId;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
|
||||
|
||||
}
|
||||
16
user-service/src/main/java/com/ho/user/entity/SysTheme.java
Normal file
16
user-service/src/main/java/com/ho/user/entity/SysTheme.java
Normal file
@ -0,0 +1,16 @@
|
||||
package com.ho.user.entity;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SysTheme {
|
||||
@ApiModelProperty(value = "主题编码")
|
||||
private String title;
|
||||
|
||||
@ApiModelProperty(value = "主题内容")
|
||||
private String theme;
|
||||
|
||||
@ApiModelProperty(value = "主题名称")
|
||||
private String name;
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package com.ho.user.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @TableName sys_user_position
|
||||
*/
|
||||
@Data
|
||||
public class SysUserPosition implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 岗位id
|
||||
*/
|
||||
private Integer positionId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package com.ho.user.entity;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class SysUserRole implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String userId;
|
||||
|
||||
private Integer roleId;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
package com.ho.user.feignclient;
|
||||
|
||||
import com.ho.business.entity.Station;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.user.api.vo.req.QueryDeptReqVO;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@FeignClient(value = ContextConstant.BUSINESS_SERVICE, fallback = BusinessFeignClientFallback.class)
|
||||
public interface BusinessFeignClient {
|
||||
// 根据部门id查电站
|
||||
@PostMapping(value = ContextConstant.ROOT_CONTEXT +ContextConstant.BUSINESS + "outerApi/selectByDeptId")
|
||||
DataResult<List<Station>> selectByDeptId(@RequestBody QueryDeptReqVO queryDeptReqVO);
|
||||
|
||||
// 根据部门id查电站
|
||||
@PostMapping(value = ContextConstant.ROOT_CONTEXT +ContextConstant.BUSINESS + "outerApi/selectByDeptIds")
|
||||
DataResult<List<Station>> selectByDeptIds(@RequestBody QueryDeptReqVO queryDeptReqVO);
|
||||
|
||||
// 根据部门ids查电站(多个)
|
||||
@PostMapping(value = ContextConstant.ROOT_CONTEXT +ContextConstant.BUSINESS + "outerApi/selectByGroupId")
|
||||
DataResult<List<Station>> selectByGroupId(Integer groupId);
|
||||
|
||||
/*
|
||||
// 根据部门ids查电站(多个)
|
||||
@PostMapping(value = ContextConstant.ROOT_CONTEXT +ContextConstant.BUSINESS + "outerApi/selectByName")
|
||||
DataResult<List<Station>> selectByName(String name);
|
||||
|
||||
// 根据电站id查电站(多个)
|
||||
@PostMapping(value = ContextConstant.ROOT_CONTEXT +ContextConstant.BUSINESS + "outerApi/selectByStationIds")
|
||||
DataResult<List<Station>> selectByStationIds(List<Integer> stationIds);
|
||||
*/
|
||||
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package com.ho.user.feignclient;
|
||||
|
||||
import com.ho.business.entity.Station;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.user.api.vo.req.QueryDeptReqVO;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Component
|
||||
public class BusinessFeignClientFallback implements BusinessFeignClient {
|
||||
|
||||
Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Override
|
||||
public DataResult<List<Station>> selectByDeptId(QueryDeptReqVO queryDeptReqVO) {
|
||||
log.error("调用 [BusinessClient.selectByDeptId] 异常!");
|
||||
throw new BusinessException(BaseResponseCode.FEIGN_CALL_FAIL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataResult<List<Station>> selectByDeptIds(QueryDeptReqVO queryDeptReqVO) {
|
||||
log.error("调用 [BusinessClient.selectByDeptIds] 异常!");
|
||||
throw new BusinessException(BaseResponseCode.FEIGN_CALL_FAIL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataResult<List<Station>> selectByGroupId(Integer groupId) {
|
||||
log.error("调用 [BusinessClient.selectByGroupId] 异常!");
|
||||
throw new BusinessException(BaseResponseCode.FEIGN_CALL_FAIL);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package com.ho.user.feignclient;
|
||||
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.flow.entity.SendSmsConfig;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* @Description flow模块的远程调用
|
||||
* Author yule
|
||||
* Date 2023/3/28 10:23
|
||||
*/
|
||||
@FeignClient(value = ContextConstant.FLOW_CENTER, fallback = FlowFeignClientFallback.class)
|
||||
public interface FlowFeignClient {
|
||||
/**
|
||||
* 部署工作流
|
||||
* @param groupId 集团id
|
||||
*/
|
||||
@PostMapping(value = ContextConstant.ROOT_CONTEXT +ContextConstant.FLOW_CONTEXT + "outerApi/deploymentWorkflow")
|
||||
DataResult deploymentWorkflow(@RequestBody Integer groupId);
|
||||
|
||||
@PostMapping(value = ContextConstant.ROOT_CONTEXT +ContextConstant.FLOW_CONTEXT + "outerApi/updateSendSmsUserInfo")
|
||||
void updateSendSmsUserInfo(@RequestBody SendSmsConfig vo);
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package com.ho.user.feignclient;
|
||||
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.flow.entity.SendSmsConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Description flow模块的失败回滚
|
||||
* Author yule
|
||||
* Date 2023/3/28 10:23
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class FlowFeignClientFallback implements FlowFeignClient{
|
||||
|
||||
@Override
|
||||
public DataResult deploymentWorkflow(Integer groupId) {
|
||||
log.error("调用 [FlowFeignClient.selectWorkOrderByStationId] 异常!");
|
||||
throw new BusinessException(BaseResponseCode.FEIGN_CALL_FAIL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSendSmsUserInfo(SendSmsConfig vo) {
|
||||
log.error("调用 [FlowFeignClient.updateSendSmsUserInfo] 异常!");
|
||||
throw new BusinessException(BaseResponseCode.FEIGN_CALL_FAIL);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.ho.user.mapper;
|
||||
|
||||
import com.ho.user.entity.IdControl;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface IdControlMapper {
|
||||
|
||||
Integer insert(IdControl idControl);
|
||||
|
||||
IdControl selectCurrentVal(String type);
|
||||
|
||||
void updateCurrentVal(String type,Integer currentVal);
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package com.ho.user.mapper;
|
||||
|
||||
|
||||
|
||||
import com.ho.user.api.entity.PermStationRelation;
|
||||
import com.ho.user.vo.req.StationPermissionReqVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yy
|
||||
* @description 针对表【perm_station_relation】的数据库操作Mapper
|
||||
* @createDate 2023-06-06 14:37:06
|
||||
* @Entity entity.PermStationRelation
|
||||
*/
|
||||
@Mapper
|
||||
public interface PermStationRelationMapper{
|
||||
// 增
|
||||
int insertSelective(PermStationRelation record);
|
||||
|
||||
// 删
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
//批量删除
|
||||
|
||||
// 改
|
||||
int updateByPrimaryKeySelective(PermStationRelation record);
|
||||
|
||||
int updateByPrimaryKey(PermStationRelation record);
|
||||
|
||||
// 根据电站ID查询
|
||||
List<PermStationRelation> selectByStationId(Integer stationId);
|
||||
|
||||
// 根据菜单ID查询
|
||||
List<PermStationRelation> selectByPermissionId(Integer permissionId);
|
||||
|
||||
void deleteBatch(@Param("ids") List<Integer> ids);
|
||||
|
||||
void deleteBatchStationId(@Param("ids") List<Integer> ids);
|
||||
|
||||
List<PermStationRelation> selectAll(StationPermissionReqVo vo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,64 @@
|
||||
package com.ho.user.mapper;
|
||||
|
||||
import com.ho.user.api.entity.SysDept;
|
||||
import com.ho.user.vo.req.DeptQuery;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysDeptMapper {
|
||||
|
||||
SysDept selectByPrimaryKey(Integer deptId);
|
||||
|
||||
List<SysDept> selectAll(@Param("query") DeptQuery query, String enableStatus);
|
||||
|
||||
//List<Integer> selectChildIds(String relationCode);
|
||||
|
||||
//关联的部门名称
|
||||
//List<SysDept> selectEnableByRelationCode(String relationCode, String enableStatus);
|
||||
|
||||
//List<SysDept> selectAllByIds(String relationCode);
|
||||
|
||||
//查询该结构的所有子机构(包含自己)
|
||||
List<SysDept> selectChildByIds(List<Integer> list, @Param("query") DeptQuery query, String enableStatus);
|
||||
|
||||
List<SysDept> selectAllByNotContainChild(List<Integer> list, @Param("query") DeptQuery query, String enableStatus);
|
||||
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
int insert(SysDept record);
|
||||
|
||||
int insertSelective(SysDept record);
|
||||
|
||||
//根据pid查询pid的那条数据
|
||||
SysDept selectByPid(Integer id);
|
||||
|
||||
int updateByPrimaryKeySelective(SysDept record);
|
||||
|
||||
int updateByPrimaryKey(SysDept record);
|
||||
|
||||
/**
|
||||
* 多个数据 要用 @Param
|
||||
*
|
||||
* @param oldStr
|
||||
* @param newStr
|
||||
* @param relationCode
|
||||
* @return
|
||||
*/
|
||||
int updateRelationCode(@Param("oldStr") String oldStr, @Param("newStr") String newStr, @Param("relationCode") String relationCode);
|
||||
|
||||
//根据id=pid 查询下级
|
||||
List<SysDept> selectBelow(Integer deptId);
|
||||
|
||||
//
|
||||
List<SysDept> selectDeptsByPid(@Param("ids") List<Integer> ids, String status);
|
||||
|
||||
//根据pid和名字 查询同级下是否有同名
|
||||
List<SysDept> selectByPidAndName(@Param("pid") Integer pid, @Param("name") String name,@Param("id") Integer id);
|
||||
|
||||
SysDept selectByIdAndStatus(Integer deptId);
|
||||
|
||||
List<SysDept> selectByGroup(Integer groupId);
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
package com.ho.user.mapper;
|
||||
|
||||
import com.ho.user.entity.SysDict;
|
||||
import com.ho.user.api.entity.SysSubDict;
|
||||
import com.ho.user.vo.req.DictPageReqVO;
|
||||
import com.ho.user.vo.resp.DictRespVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysDictMapper {
|
||||
|
||||
SysDict selectByPrimaryKey(Integer id);
|
||||
|
||||
int deleteByPrimaryKey(@Param("id") Integer id);
|
||||
|
||||
int insertDict(@Param("record") SysDict record);
|
||||
|
||||
int insertSubDict(@Param("record")SysSubDict record);
|
||||
|
||||
int updateDict(@Param("record")SysDict dict);
|
||||
|
||||
int updateByPrimaryKey(@Param("record")SysSubDict record);
|
||||
|
||||
SysDict selectByType( String type);
|
||||
|
||||
List<DictRespVo> selectAll(@Param("record") DictPageReqVO vo);
|
||||
|
||||
List<SysDict> selectTypeAll();
|
||||
|
||||
int deleteByType(@Param("type")String type);
|
||||
|
||||
SysSubDict selectSubDictByValue(String value);
|
||||
|
||||
SysDict selectById(Integer id);
|
||||
|
||||
SysSubDict selectBySubId(Integer id);
|
||||
|
||||
|
||||
List<SysSubDict> selectSubDictByType(String type);
|
||||
|
||||
List<SysSubDict> selectSubDictByTypeList(@Param("typeList") List<String> typeList);
|
||||
|
||||
int updateSubDict(@Param("record")SysSubDict subDict);
|
||||
|
||||
SysSubDict selectSubDictByTV(@Param("type")String type, @Param("value")String value);
|
||||
|
||||
SysDict selectDictByTypeAndName(@Param("record")SysDict queryDict);
|
||||
|
||||
List<SysDict> selectDictListByType(String type);
|
||||
|
||||
List<SysSubDict> selectSubDictByKey(@Param("record") SysSubDict sysSubDict);
|
||||
|
||||
SysSubDict selectSubDictBySort(@Param("type") String type, Long sort);
|
||||
|
||||
List<SysSubDict> getDictByIds(List<Integer> ids);
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package com.ho.user.mapper;
|
||||
|
||||
|
||||
import com.ho.user.vo.req.SysLogPageReqVO;
|
||||
import com.ho.user.api.entity.SysLog;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
@Mapper
|
||||
public interface SysLogMapper {
|
||||
int deleteByPrimaryKey(String id);
|
||||
|
||||
int insert(SysLog record);
|
||||
|
||||
int insertSelective(SysLog record);
|
||||
|
||||
SysLog selectByPrimaryKey(Long id);
|
||||
|
||||
int updateByPrimaryKeySelective(SysLog record);
|
||||
|
||||
int updateByPrimaryKey(SysLog record);
|
||||
|
||||
List<SysLog> selectAll(SysLogPageReqVO vo);
|
||||
|
||||
void batchDeletedLog(List<Long> logIds);
|
||||
|
||||
//管理员查询所有日志
|
||||
List<SysLog> selectAllLogs(String endTime,String startTime,String operation, String username);
|
||||
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
package com.ho.user.mapper;
|
||||
|
||||
|
||||
import com.ho.common.tools.entity.SysPermission;
|
||||
import com.ho.user.api.vo.req.QueryPermissionReqVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysPermissionMapper {
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
int insert(SysPermission record);
|
||||
|
||||
int insertSelective(@Param("record") SysPermission record);
|
||||
|
||||
SysPermission selectByPrimaryKey(Integer id);
|
||||
|
||||
//查询单个记录
|
||||
SysPermission selectOneByCondition(SysPermission sysPermission);
|
||||
|
||||
int updateByPrimaryKeySelective(SysPermission record);
|
||||
|
||||
int updateByPrimaryKey(SysPermission record);
|
||||
|
||||
//type是菜单类型
|
||||
//List<SysPermission> selectInfoByIds(@Param("ids") List<String> ids , @Param("type") Integer type);
|
||||
List<SysPermission> selectInfoByIds(@Param("query") QueryPermissionReqVo query,@Param("ids") List<Integer> ids );
|
||||
|
||||
List<SysPermission> selectTopMenu();
|
||||
|
||||
List<SysPermission> selectAll(@Param("query") QueryPermissionReqVo query,String enableStatus,String enableType);
|
||||
|
||||
List<SysPermission> selectChild(Integer pid);
|
||||
//查询父id下的所有菜单
|
||||
List<SysPermission> selectChilds(List<Integer> pids);
|
||||
|
||||
SysPermission selectByPerms(String perms);
|
||||
|
||||
//通过pid 查询父级菜单
|
||||
SysPermission selectByPid(Integer pid);
|
||||
|
||||
//其他id的perms数据
|
||||
SysPermission selectOtherByIdAndPerms(Integer id, String perms );
|
||||
|
||||
|
||||
List<SysPermission> selectByName(SysPermission selectByName);
|
||||
|
||||
List<SysPermission> selectByScope();
|
||||
|
||||
List<SysPermission> selectByIds(@Param("ids") List<Integer> perIds);
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
package com.ho.user.mapper;
|
||||
|
||||
import com.ho.user.api.entity.SysUser;
|
||||
import com.ho.user.api.vo.req.OrderUserSelectReqVo;
|
||||
import com.ho.user.entity.SysPosition;
|
||||
import com.ho.user.vo.req.PositionAddReqVO;
|
||||
import com.ho.user.vo.req.PositionQueryReqVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yule
|
||||
* @description 针对表【sys_position】的数据库操作Mapper
|
||||
* @createDate 2022-12-01 15:55:30
|
||||
* @Entity com.ho.user.entity.SysPosition
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysPositionMapper {
|
||||
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
int insertSelective(SysPosition record);
|
||||
|
||||
SysPosition selectByPrimaryKey(Integer id);
|
||||
|
||||
int updateByPrimaryKeySelective(SysPosition record);
|
||||
|
||||
List<SysPosition> selectByInfo(SysPosition sysPosition);
|
||||
|
||||
|
||||
List<SysPosition> select(SysPosition sysPosition);
|
||||
|
||||
//岗位ids对应的岗位列表
|
||||
List<SysPosition> selectPostListByPostIds(@Param("list") List<Integer> postIds);
|
||||
|
||||
List<SysPosition> selectObscure(PositionQueryReqVO vo);
|
||||
|
||||
List<SysPosition> getPositionByTop();
|
||||
|
||||
List<Integer> selectPostIds(@Param("list") List<String> postCodes);
|
||||
|
||||
List<SysUser> selectUserByPostIds(@Param("vo") OrderUserSelectReqVo vo,@Param("list")List<Integer> postIds);
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package com.ho.user.mapper;
|
||||
|
||||
|
||||
import com.ho.common.tools.entity.SysRole;
|
||||
import com.ho.user.vo.req.RolePageReqVO;
|
||||
import com.ho.user.vo.req.RoleUpdateReqVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysRoleMapper {
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
int insert(SysRole record);
|
||||
|
||||
int insertSelective(SysRole record);
|
||||
|
||||
SysRole selectByPrimaryKey(Integer id);
|
||||
|
||||
int updateByPrimaryKeySelective(SysRole record);
|
||||
|
||||
int updateByPrimaryKey(SysRole record);
|
||||
|
||||
List<SysRole> selectAll(RolePageReqVO vo);
|
||||
|
||||
List<SysRole> getRoleInfoByIds(List<Integer> ids);
|
||||
|
||||
//查询是否有其他这个名称的数据
|
||||
List<SysRole> selectOthers(RoleUpdateReqVO vo);
|
||||
|
||||
//按条件查询
|
||||
List<SysRole> selectListByCondition(RolePageReqVO vo);
|
||||
|
||||
//根据角色编号查对象
|
||||
SysRole findByCode(String roleCode);
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
package com.ho.user.mapper;
|
||||
|
||||
|
||||
import com.ho.user.entity.SysRolePermission;
|
||||
import com.ho.user.vo.req.RolePermissionOperationReqVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
@Mapper
|
||||
public interface SysRolePermissionMapper {
|
||||
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
int insert(SysRolePermission record);
|
||||
|
||||
int insertSelective(SysRolePermission record);
|
||||
|
||||
SysRolePermission selectByPrimaryKey(Integer id);
|
||||
|
||||
int updateByPrimaryKeySelective(SysRolePermission record);
|
||||
|
||||
int updateByPrimaryKey(SysRolePermission record);
|
||||
|
||||
int removeByRoleId(Integer roleId);
|
||||
|
||||
List<Integer> getPermissionIdsByRoles(@Param("roleIds") List<Integer> roleIds);
|
||||
|
||||
int batchRolePermission(List<SysRolePermission> list);
|
||||
|
||||
int removeByPermissionId(Integer permissionId);
|
||||
|
||||
List<Integer> getRoleIds(Integer permissionId);
|
||||
|
||||
List<Integer> getPermissionIdsByRoleId(Integer roleId);
|
||||
|
||||
int deleteRolePermissions(@Param("vo") RolePermissionOperationReqVO reqVO);
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
package com.ho.user.mapper;
|
||||
|
||||
import com.ho.user.api.entity.SysUser;
|
||||
import com.ho.user.api.vo.req.OrderUserSelectReqVo;
|
||||
import com.ho.user.entity.SysTheme;
|
||||
import com.ho.user.vo.req.SysUserThemeReqVo;
|
||||
import com.ho.user.vo.req.UserPageReqVO;
|
||||
import com.ho.user.vo.req.UserPageUserByDeptReqVO;
|
||||
import com.ho.user.vo.resp.SysUserThemeRespVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysUserMapper {
|
||||
|
||||
SysUser getUserInfoByName(String username);
|
||||
|
||||
//按人员名称模糊查询列表,用于工单
|
||||
List<SysUser> getUserInfoListByName(String username, Integer groupId);
|
||||
|
||||
//根据手机号查询
|
||||
SysUser getUserInfoByPhone(String phone);
|
||||
|
||||
int deleteByPrimaryKey(String id);
|
||||
|
||||
int insert(SysUser record);
|
||||
|
||||
int insertSelective(SysUser record);
|
||||
|
||||
SysUser selectByPrimaryKey(String id);
|
||||
|
||||
int updateByPrimaryKeySelective(SysUser record);
|
||||
|
||||
int updateByPrimaryKey(SysUser record);
|
||||
|
||||
List<SysUser> selectAll(UserPageReqVO vo);
|
||||
|
||||
List<SysUser> selectUserInfoByDeptIds(@Param("list") List<Integer> deptIds, @Param("vo") UserPageUserByDeptReqVO vo,@Param("groupId") Integer groupId);
|
||||
|
||||
List<SysUser> getUserListByDeptId(Integer deptId);
|
||||
|
||||
int deletedUsers(@Param("sysUser") SysUser sysUser, @Param("list") List<String> list);
|
||||
|
||||
List<SysUser> selectByIds(@Param("list") List<String> userIds, @Param("vo") OrderUserSelectReqVo vo);
|
||||
|
||||
|
||||
List<SysUser> selectPostUserIds(@Param("userIds")List<String> userIds,@Param("postIds")List<Integer> postIds);
|
||||
|
||||
SysUserThemeRespVo getUserTheme(String userId);
|
||||
|
||||
List<SysTheme> getSysTheme();
|
||||
|
||||
void deletedUserTheme(String userId);
|
||||
|
||||
void addUserTheme(SysUserThemeReqVo vo);
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
package com.ho.user.mapper;
|
||||
|
||||
import com.ho.user.entity.SysUserPosition;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yule
|
||||
* @description 针对表【sys_user_position】的数据库操作Mapper
|
||||
* @createDate 2022-12-05 13:57:12
|
||||
* @Entity com.ho.user.entity.SysUserPosition
|
||||
*/
|
||||
public interface SysUserPositionMapper {
|
||||
|
||||
int insert(SysUserPosition record);
|
||||
|
||||
int insertSelective(SysUserPosition record);
|
||||
|
||||
int batchUserPosition(List<SysUserPosition> list);
|
||||
|
||||
SysUserPosition selectByPrimaryKey(Integer id);
|
||||
|
||||
List<Integer> selectPostIdsByUserId(String userId);
|
||||
|
||||
int updateByPrimaryKeySelective(SysUserPosition record);
|
||||
|
||||
int updateByPrimaryKey(SysUserPosition record);
|
||||
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
int removeByPostId(Integer id);
|
||||
|
||||
int removeByUserId(String userId);
|
||||
|
||||
int removeByUserIds(@Param("list") List<String> list);
|
||||
|
||||
//根据岗位id查询
|
||||
List<SysUserPosition> selectByPostId(@Param("id") Integer id);
|
||||
|
||||
List<String> getUserIdsByPostIds(@Param("list") List<Integer> postIds);
|
||||
|
||||
//根据岗位id查询
|
||||
List<SysUserPosition> selectByPostIds(@Param("list") List<Integer> postIds);
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package com.ho.user.mapper;
|
||||
|
||||
|
||||
import com.ho.user.entity.SysUserRole;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysUserRoleMapper {
|
||||
|
||||
|
||||
int insert(SysUserRole record);
|
||||
|
||||
int insertSelective(SysUserRole record);
|
||||
|
||||
SysUserRole selectByPrimaryKey(Integer id);
|
||||
|
||||
int updateByPrimaryKeySelective(SysUserRole record);
|
||||
|
||||
int updateByPrimaryKey(SysUserRole record);
|
||||
|
||||
List<Integer> getRoleIdsByUserId(String userId);
|
||||
|
||||
int batchUserRole(List<SysUserRole> list);
|
||||
|
||||
List<String> getInfoByUserIdByRoleId(Integer roleId);
|
||||
|
||||
List<String> getUserIdsByRoleIds(List<Integer> roleIds);
|
||||
|
||||
int removeByUserIds( @Param("list") List<String> list);
|
||||
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
int removeByUserId(String userId);
|
||||
|
||||
int removeByRoleId(Integer roleId);
|
||||
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package com.ho.user.service;
|
||||
|
||||
import com.ho.common.tools.entity.OrderDept;
|
||||
import com.ho.user.api.entity.SysDept;
|
||||
import com.ho.user.api.entity.SysUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: 部门下的人员,为工作流配置模块服务
|
||||
* @date 2023/2/13
|
||||
*/
|
||||
public interface DeptOrderUserService {
|
||||
|
||||
/**
|
||||
* 部门下的人员树结构
|
||||
* @param topDept 顶级部门
|
||||
* @param sysUsers 符合条件的人员列表
|
||||
* @return
|
||||
*/
|
||||
OrderDept getDeptUser(SysDept topDept ,List<SysUser> sysUsers );
|
||||
|
||||
}
|
||||
@ -0,0 +1,84 @@
|
||||
package com.ho.user.service;
|
||||
|
||||
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import com.ho.user.api.entity.SysDept;
|
||||
import com.ho.user.api.entity.SysUser;
|
||||
import com.ho.user.api.vo.req.DeptManagerReq;
|
||||
import com.ho.user.vo.req.DeptAddReqVO;
|
||||
import com.ho.user.vo.req.DeptQuery;
|
||||
import com.ho.user.vo.req.DeptUpdateReqVO;
|
||||
import com.ho.user.vo.req.UserPageUserByDeptReqVO;
|
||||
import com.ho.user.vo.resp.DeptRespNodeVO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName: DeptService
|
||||
* 集团服务类
|
||||
* @Author: fancl
|
||||
* @CreateDate: 2022/8/10
|
||||
* @UpdateUser: fancl
|
||||
* @UpdateDate: 2022/8/10
|
||||
*/
|
||||
public interface DeptService {
|
||||
|
||||
SysDept addDept(DeptAddReqVO vo);
|
||||
|
||||
void updateDept(DeptUpdateReqVO vo);
|
||||
|
||||
SysDept detailInfo(Integer id);
|
||||
|
||||
void deleted(Integer id);
|
||||
|
||||
List<DeptRespNodeVO> deptTreeList(DeptQuery query,String enableStatus);
|
||||
|
||||
List<SysDept> depListByDeptId(Integer deptId);
|
||||
|
||||
PageResult<SysUser> pageDeptUserInfo(UserPageUserByDeptReqVO vo);
|
||||
|
||||
/**
|
||||
* 查一个人的部门列表 根据人员的token而不是Id
|
||||
* @return
|
||||
*/
|
||||
List<SysDept> getUserDepts();
|
||||
|
||||
Boolean checkUserHasDeptPower(Integer deptId, List<SysDept> userDepts);
|
||||
|
||||
/**
|
||||
* 获取顶级Dept 迭代查询获取,然后放置到缓存中
|
||||
* @param deptId
|
||||
* @return
|
||||
*/
|
||||
SysDept getTopDept(Integer deptId );
|
||||
|
||||
List<SysDept> selectByIds(List<Integer> ids);
|
||||
|
||||
SysDept selectByPrimaryKey(Integer deptId);
|
||||
|
||||
//List<SysDept> selectEnableByRelationCode(String relationCode, String enable);
|
||||
|
||||
//List<SysDept> selectAllByRelationCode(String relationCode);
|
||||
|
||||
List<SysUser> getDeptUser(DeptManagerReq deptManagerReq);
|
||||
|
||||
|
||||
List<SysDept> getSubsidiaryDepts(List<SysDept> sysDepts,String status);
|
||||
|
||||
|
||||
public List<SysDept> getAllToTop(SysDept dept,List<SysDept> all);
|
||||
|
||||
List<SysDept> selectByGroupId(Integer groupId);
|
||||
|
||||
|
||||
int getHierarchy(Map<Integer,SysDept> map,SysDept dept,Integer count);
|
||||
|
||||
/**
|
||||
* 获取当前登录人以及传入所属部门id中的人
|
||||
* @param vo
|
||||
* @return
|
||||
*/
|
||||
PageResult<SysUser> getUserInfosPage(UserPageUserByDeptReqVO vo);
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
package com.ho.user.service;
|
||||
|
||||
import com.ho.common.tools.entity.PageVO;
|
||||
import com.ho.user.entity.SysDict;
|
||||
import com.ho.user.vo.req.*;
|
||||
import com.ho.user.api.entity.SysSubDict;
|
||||
import com.ho.user.vo.resp.DictRespVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc:
|
||||
* @date 2022/8/18
|
||||
*/
|
||||
public interface DictService {
|
||||
SysDict addTypeDict(DictAddTypeVO vo);
|
||||
|
||||
SysSubDict addSubDict(DictAddReqVO vo);
|
||||
|
||||
SysDict updateDict(DictUpdateReqVO vo);
|
||||
|
||||
SysSubDict updateSubDict(DictSubUpdateReqVO vo);
|
||||
|
||||
// SysDict detailInfoById(Integer id);
|
||||
|
||||
// void deletedById(Integer id);
|
||||
|
||||
SysDict selectDictByType(DictAddTypeVO vo);
|
||||
|
||||
PageVO<DictRespVo> all(DictPageReqVO vo);
|
||||
|
||||
DictRespVo selectDict(DictTypeAndLabelReqVO vo);
|
||||
|
||||
// void deletedByType(String type);
|
||||
|
||||
List<DictRespVo> selectDictType();
|
||||
|
||||
SysSubDict selectSubDictByValue(DictAddReqVO vo);
|
||||
|
||||
List<SysSubDict> selectSubDictByType(String type);
|
||||
|
||||
List<SysSubDict> selectSubDictByTypeList(List<String> typeList);
|
||||
|
||||
SysSubDict selectSubDictByTV(String type, String value);
|
||||
|
||||
void deletedSubById(Integer id);
|
||||
|
||||
SysDict selectDictByTypeAndName(DictAddTypeVO dictAddTypeVo);
|
||||
|
||||
List<SysDict> selectDictListByType(String type);
|
||||
|
||||
List<SysSubDict> selectSubDictByKey(SysSubDict sysSubDict);
|
||||
|
||||
SysSubDict selectSubDictBySort(String type, Long sort);
|
||||
|
||||
|
||||
//PageVO<SysUser> pageDeptUserInfo(UserPageUserByDeptReqVO vo);
|
||||
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package com.ho.user.service;
|
||||
|
||||
import com.ho.user.vo.req.LoginReqVO;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: 加解密类
|
||||
* @date 2022/11/17
|
||||
*/
|
||||
public interface EncryptComponent {
|
||||
|
||||
LoginReqVO decryptSecret(LoginReqVO loginReqVO);
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
package com.ho.user.service;
|
||||
|
||||
|
||||
import com.ho.user.vo.resp.HomeRespVO;
|
||||
|
||||
/**
|
||||
* @ClassName: HomeService
|
||||
*/
|
||||
public interface HomeService {
|
||||
|
||||
HomeRespVO getHomeInfo(String userId);
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.ho.user.service;
|
||||
|
||||
import com.ho.user.entity.IdControl;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* @version 1.0.0
|
||||
* @ClassName IdControlService.java
|
||||
* @Description TODO
|
||||
* @createTime 2022年09月22日 09:21:00
|
||||
*/
|
||||
public interface IdControlService {
|
||||
|
||||
Integer insert (IdControl control);
|
||||
|
||||
IdControl selectCurrentVal(String type);
|
||||
|
||||
void updateCurrentVal(String type,Integer currentVal);
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package com.ho.user.service;
|
||||
|
||||
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.user.vo.req.SysLogPageReqVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName: LogService
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/23 16:17
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/23 16:17
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
public interface LogService {
|
||||
|
||||
PageResult pageInfo(SysLogPageReqVO vo, SimpleUser simpleUser);
|
||||
|
||||
|
||||
void deleted(List<Long> logIds);
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package com.ho.user.service;
|
||||
|
||||
|
||||
import com.ho.business.vo.req.deviceModel.DeviceModelDeleteReqVo;
|
||||
import com.ho.common.tools.entity.PageVO;
|
||||
import com.ho.user.api.entity.PermStationRelation;
|
||||
import com.ho.user.vo.req.StationPermissionReqVo;
|
||||
import com.ho.user.vo.resp.StationPermissionRespVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yy
|
||||
* @description 针对表【perm_station_relation】的数据库操作Service
|
||||
* @createDate 2023-06-06 14:37:06
|
||||
*/
|
||||
public interface PermStationRelationService{
|
||||
// 增
|
||||
int insertSelective(PermStationRelation record);
|
||||
|
||||
// 删
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
// 改
|
||||
int updateByPrimaryKeySelective(PermStationRelation record);
|
||||
|
||||
int updateByPrimaryKey(PermStationRelation record);
|
||||
|
||||
// 根据电站ID查询
|
||||
List<PermStationRelation> selectByStationId(Integer stationId);
|
||||
|
||||
List<PermStationRelation> selectByPermissionId(Integer permissionId);
|
||||
|
||||
//批量删除
|
||||
void deleteBatch(List<Integer> ids);
|
||||
|
||||
void update(PermStationRelation record);
|
||||
|
||||
PermStationRelation detailInfo(Integer id);
|
||||
|
||||
// PageVO<StationPermissionRespVo> pageInfo(StationPermissionReqVo vo);
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
package com.ho.user.service;
|
||||
|
||||
|
||||
import com.ho.common.tools.entity.PageVO;
|
||||
import com.ho.common.tools.entity.SysPermission;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.entity.UserDetailRespVO;
|
||||
import com.ho.user.api.vo.req.QueryPermissionReqVo;
|
||||
import com.ho.user.entity.PermissionRespNode;
|
||||
import com.ho.user.vo.req.PermissionAddReqVO;
|
||||
import com.ho.user.vo.req.PermissionPageReqVO;
|
||||
import com.ho.user.vo.req.PermissionUpdateReqVO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @ClassName: PermissionService
|
||||
* @Author: fancl
|
||||
* @CreateDate: 2019/9/19 11:39
|
||||
* @UpdateUser: fancl
|
||||
* @UpdateDate: 2019/9/19 11:39
|
||||
*/
|
||||
public interface PermissionService {
|
||||
|
||||
List<SysPermission> getPermission(String userId);
|
||||
|
||||
List<SysPermission> getPermissionByRoleIds(List<Integer> roleIds);
|
||||
|
||||
List<SysPermission> getPermissionByTop();
|
||||
|
||||
SysPermission addPermission(PermissionAddReqVO vo);
|
||||
|
||||
SysPermission detailInfo(Integer permissionId);
|
||||
|
||||
//查询 系统管理 这条记录
|
||||
SysPermission findSysManageMenu();
|
||||
|
||||
//查询 菜单管理 这个记录
|
||||
SysPermission findTheMenu();
|
||||
|
||||
void updatePermission(PermissionUpdateReqVO vo);
|
||||
|
||||
Integer updateByPrimaryKeySelective(SysPermission vo);
|
||||
|
||||
void deleted(Integer permissionId);
|
||||
|
||||
PageVO<SysPermission> pageInfo(PermissionPageReqVO vo);
|
||||
|
||||
List<SysPermission> selectAll(QueryPermissionReqVo query, String enableStatus, String enableType);
|
||||
|
||||
Set<String> getPermissionsByUserId(String userId);
|
||||
|
||||
List<PermissionRespNode> permissionTreeList(String userId);
|
||||
|
||||
List<PermissionRespNode> selectAllByTree(QueryPermissionReqVo query, String enableStatus, String enableType);
|
||||
|
||||
SysPermission selectByPerms(String perms);
|
||||
|
||||
//通过jwt和缓存获取当前用户
|
||||
SimpleUser getCurrentSimpleUser();
|
||||
|
||||
SysPermission selectByPrimaryKey(Integer pid);
|
||||
|
||||
//查询所有系统管理的菜单,包括子菜单 ,做递归查询
|
||||
List<SysPermission> getSysMangeMenus(List<SysPermission> list, List<Integer> queryIds);
|
||||
|
||||
|
||||
List<PermissionRespNode> getStationPer(Integer stationId, UserDetailRespVO user);
|
||||
|
||||
List<PermissionRespNode> getAll(QueryPermissionReqVo query);
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
package com.ho.user.service;
|
||||
|
||||
import com.ho.user.entity.SysPosition;
|
||||
import com.ho.user.vo.req.PositionAddReqVO;
|
||||
import com.ho.user.vo.req.PositionQueryReqVO;
|
||||
import com.ho.user.vo.req.PositionUpdateReqVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description 岗位管理业务类
|
||||
* Author yule
|
||||
* Date 2022/12/1 15:57
|
||||
*/
|
||||
public interface PositionService {
|
||||
|
||||
//新增岗位
|
||||
int add(PositionAddReqVO vo);
|
||||
|
||||
SysPosition selectById(Integer id);
|
||||
|
||||
//根据条件查询岗位(精确查询)
|
||||
List<SysPosition> selectAccuratePositionByInfo(SysPosition sysPosition);
|
||||
|
||||
//岗位以上的
|
||||
List<SysPosition> getPositionByTop();
|
||||
|
||||
//查询全部
|
||||
List<SysPosition> selectAll();
|
||||
|
||||
List<SysPosition> selectAvailable();
|
||||
|
||||
//根据条件模糊查询
|
||||
List<SysPosition> selectObscure(PositionQueryReqVO vo);
|
||||
|
||||
//根据id删除
|
||||
void deleted(Integer id);
|
||||
|
||||
//更新岗位信息
|
||||
void updatePosition(PositionUpdateReqVO vo);
|
||||
|
||||
List<Integer> selectPostIds(List<String> postCodes);
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package com.ho.user.service;
|
||||
|
||||
import com.ho.common.tools.entity.UserDetailRespVO;
|
||||
import com.ho.user.api.entity.SysUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description 修改redis中的数据
|
||||
* Author yule
|
||||
* Date 2022/9/19 17:55
|
||||
*/
|
||||
public interface RedisUpdateService {
|
||||
|
||||
void updateRedis(UserDetailRespVO userDetail, SysUser user);
|
||||
|
||||
/**
|
||||
* 根据角色名清理用户登陆缓存
|
||||
* @param roleIds 需要变更的角色
|
||||
*/
|
||||
void cleanLoginInfosByRoleId(List<Integer> roleIds);
|
||||
|
||||
/**
|
||||
* 更新超管的缓存信息
|
||||
*/
|
||||
void updateSuperPermsCache();
|
||||
|
||||
//获取token 的key
|
||||
String getTokenKey();
|
||||
|
||||
//得到用户userName的key
|
||||
String getUserNameKey(String userName);
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
package com.ho.user.service;
|
||||
|
||||
|
||||
import com.ho.user.vo.req.RolePermissionOperationReqVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName: RolePermissionService
|
||||
* TODO:类文件简单描述
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/19 11:39
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/19 11:39
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
public interface RolePermissionService {
|
||||
|
||||
int removeByRoleId(Integer roleId);
|
||||
|
||||
List<Integer> getPermissionIdsByRoles(List<Integer> roleIds);
|
||||
|
||||
void addRolePermission(RolePermissionOperationReqVO vo);
|
||||
|
||||
void addRolePermissions(RolePermissionOperationReqVO vo);
|
||||
|
||||
int removeByPermissionId(Integer permissionId);
|
||||
|
||||
List<Integer> getRoleIds(Integer permissionId);
|
||||
|
||||
List<Integer> getPermissionIdsByRoleId(Integer roleId);
|
||||
|
||||
|
||||
int deleteRolePermissions(RolePermissionOperationReqVO reqVO);
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package com.ho.user.service;
|
||||
|
||||
import com.ho.common.tools.entity.PageVO;
|
||||
import com.ho.common.tools.entity.SysRole;
|
||||
import com.ho.user.vo.req.RoleAddReqVO;
|
||||
import com.ho.user.vo.req.RolePageReqVO;
|
||||
import com.ho.user.vo.req.RoleUpdateReqVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName: RoleService
|
||||
* TODO:类文件简单描述
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/19 11:38
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/19 11:38
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
public interface RoleService {
|
||||
|
||||
SysRole addRole(RoleAddReqVO vo);
|
||||
|
||||
void updateRole(RoleUpdateReqVO vo);
|
||||
|
||||
SysRole detailInfo(Integer id,String enableStatus);
|
||||
|
||||
void deletedRole(Integer id);
|
||||
|
||||
PageVO<SysRole> pageInfo(RolePageReqVO vo);
|
||||
|
||||
List<SysRole> listInfo(RolePageReqVO vo);
|
||||
|
||||
List<SysRole> getRoleInfoByUserId(String userId);
|
||||
|
||||
List<SysRole> getRoleInfoByRoleIds(List<Integer> roleIds);
|
||||
|
||||
List<String> getRoleNames(String userId);
|
||||
|
||||
List<SysRole> selectAllRoles();
|
||||
|
||||
//根据角色编号查询角色对象
|
||||
SysRole findRoleInfoByRoleCode(String roleCode);
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package com.ho.user.service;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: 用户中心提供给外部接口实现类
|
||||
* @date 2023/2/12
|
||||
*/
|
||||
public interface UserCenterService {
|
||||
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
package com.ho.user.service;
|
||||
|
||||
import com.ho.user.api.entity.SysUser;
|
||||
import com.ho.user.api.vo.req.OrderUserSelectReqVo;
|
||||
import com.ho.user.entity.SysPosition;
|
||||
import com.ho.user.entity.SysUserPosition;
|
||||
import com.ho.user.vo.req.UserPostOperationReqVO;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: 用户岗位关联
|
||||
* @date 2022/12/6
|
||||
*/
|
||||
public interface UserPostService {
|
||||
|
||||
//根据postId删除用户
|
||||
int removeByPostId(Integer postId);
|
||||
|
||||
//根据用户id查询 用户的岗位列表
|
||||
List<Integer> getPostIdsByUserId(String userId);
|
||||
//用户岗位关联
|
||||
void addUserPostInfo(UserPostOperationReqVO vo);
|
||||
//根据用户Id 删除关联数据
|
||||
int removeByUserId(String userId);
|
||||
|
||||
//批量清除关联
|
||||
int removeByUserIds(List<String> userIds);
|
||||
|
||||
List<String> getUserIdsByPostIds(List<Integer> postIds);
|
||||
|
||||
//用户岗位列表
|
||||
List<SysPosition> getPostListByUserId(String userid);
|
||||
|
||||
|
||||
List<SysUser> selectUserByPostIds(OrderUserSelectReqVo vo, List<Integer> postIds);
|
||||
|
||||
List<SysUserPosition> getByPostIds(List<Integer> postIds);
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package com.ho.user.service;
|
||||
|
||||
|
||||
import com.ho.user.vo.req.UserRoleOperationReqVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName: UserRoleService
|
||||
* TODO:类文件简单描述
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/19 11:39
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/19 11:39
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
public interface UserRoleService {
|
||||
|
||||
int removeByRoleId(Integer roleId);
|
||||
|
||||
List<Integer> getRoleIdsByUserId(String userId);
|
||||
|
||||
void addUserRoleInfo(UserRoleOperationReqVO vo);
|
||||
|
||||
int removeByUserId(String userId);
|
||||
|
||||
int removeByUserIds(List<String> userIds);
|
||||
|
||||
List<String> getUserIdsByRoleIds(List<Integer> roleIds);
|
||||
|
||||
}
|
||||
118
user-service/src/main/java/com/ho/user/service/UserService.java
Normal file
118
user-service/src/main/java/com/ho/user/service/UserService.java
Normal file
@ -0,0 +1,118 @@
|
||||
package com.ho.user.service;
|
||||
|
||||
import com.ho.common.tools.entity.PageVO;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.entity.UserDetailRespVO;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import com.ho.user.api.entity.SysDept;
|
||||
import com.ho.user.api.entity.SysUser;
|
||||
import com.ho.user.api.vo.req.OrderUserSelectReqVo;
|
||||
import com.ho.user.api.vo.req.SysSubDictVO;
|
||||
import com.ho.user.entity.SysTheme;
|
||||
import com.ho.user.vo.req.*;
|
||||
import com.ho.user.vo.resp.SysUserThemeRespVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc:
|
||||
* @date 2022/8/10
|
||||
*/
|
||||
public interface UserService {
|
||||
|
||||
UserDetailRespVO login(LoginReqVO vo, SysUser sysUser);
|
||||
|
||||
//生成SimpleUser对象
|
||||
SimpleUser generateSimpleUser(SysUser sysUser, Integer deptId, String token, LoginReqVO loginReqVO);
|
||||
|
||||
void addUser(UserAddReqVO vo);
|
||||
|
||||
String register(RegisterReqVO vo);
|
||||
|
||||
// String refreshToken(String refreshToken,String accessToken);
|
||||
|
||||
void updateUserInfo(UserUpdateReqVO vo, String operationId, String token);
|
||||
|
||||
PageVO<SysUser> pageInfo(UserPageReqVO vo);
|
||||
|
||||
SysUser detailInfo(String userId);
|
||||
|
||||
SysUser getUserByName(String userName);
|
||||
|
||||
//根据用户名模糊匹配
|
||||
List<SysUser> getUserListByNameConcat(String userName, Integer groupId);
|
||||
|
||||
SysUser getUserByPhone(String phone);
|
||||
|
||||
PageResult<SysUser> selectUserInfoByDeptIds(int pageNum, int pageSize, List<SysDept> depts, UserPageUserByDeptReqVO vo);
|
||||
|
||||
|
||||
void logout(String accessToken);
|
||||
|
||||
void updatePwd(UpdatePasswordReqVO vo, String userId, String accessToken);
|
||||
|
||||
|
||||
void resetPwd(ResetPasswordReqVO vo);
|
||||
|
||||
List<SysUser> getUserListByDeptIds(List<Integer> deptIds);
|
||||
|
||||
//根据部门列表和人员id列表(根据角色过滤后的)获取人员列表
|
||||
List<SysUser> getUserListByDeptIdsAndUserIds(List<Integer> deptIds, UserPageUserByDeptReqVO userQuery, Integer groupId);
|
||||
|
||||
void deletedUsers(List<String> userIds, String operationId);
|
||||
|
||||
|
||||
void setUserOwnRole(String userId, List<Integer> roleIds);
|
||||
|
||||
void setUserOwnPosition(String userId, List<Integer> positionIds);
|
||||
|
||||
//查询用户详情
|
||||
UserDetailRespVO getUserDetail(String userId, String loginChannel);
|
||||
|
||||
|
||||
List<SysUser> selectIds(List<String> userIds);
|
||||
|
||||
UserDetailRespVO yourSelfInfo(UserDetailRespVO user, boolean platSuper);
|
||||
|
||||
//清除用户缓存
|
||||
void removeUserCache(String username, String loginChannel);
|
||||
|
||||
List<SysUser> selectByIds(List<String> userIdsByPostIds, OrderUserSelectReqVo vo);
|
||||
|
||||
SysUser selectById(String userId);
|
||||
|
||||
List<SysUser> selectByDeptId(Integer deptId);
|
||||
|
||||
List<SysUser> selectByDeptIds(List<Integer> deptIds);
|
||||
|
||||
/**
|
||||
* 筛选特殊用户
|
||||
* @return
|
||||
*/
|
||||
Map<String,String> checkSpecialUser();
|
||||
|
||||
/**
|
||||
* 根据类型获对应的字典
|
||||
* @return
|
||||
*/
|
||||
Map<String, String> getSysSubDict(SysSubDictVO vo);
|
||||
|
||||
|
||||
/**
|
||||
* 根据id查询用户带有岗位
|
||||
* @param userIds
|
||||
* @param postIds
|
||||
* @return
|
||||
*/
|
||||
List<SysUser> selectPostUserIds(List<String> userIds,List<Integer> postIds);
|
||||
|
||||
|
||||
SysUserThemeRespVo getUserTheme(String userId);
|
||||
|
||||
List<SysTheme> getSysTheme();
|
||||
|
||||
void addUserTheme(SysUserThemeReqVo sysUserThemeReqVo);
|
||||
}
|
||||
@ -0,0 +1,154 @@
|
||||
package com.ho.user.service.impl;
|
||||
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.entity.OrderDept;
|
||||
import com.ho.user.api.entity.SysDept;
|
||||
import com.ho.user.api.entity.SysUser;
|
||||
import com.ho.user.service.DeptOrderUserService;
|
||||
import com.ho.user.service.DeptService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc:
|
||||
* @date 2023/2/13
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DeptOrderUserServiceImpl implements DeptOrderUserService {
|
||||
|
||||
@Autowired
|
||||
DeptService deptService;
|
||||
|
||||
@Override
|
||||
public OrderDept getDeptUser(SysDept topDept, List<SysUser> sysUsers) {
|
||||
|
||||
//以下是人的集合
|
||||
Map<Integer, List<OrderDept>> userMap = sysUsers.stream().map(user -> {
|
||||
OrderDept order = new OrderDept();
|
||||
//
|
||||
String deptId = user.getDeptId().toString();
|
||||
order.setId(user.getId());
|
||||
order.setDeptId(user.getDeptId());
|
||||
order.setType("person");
|
||||
order.setUserId(user.getId());
|
||||
order.setName(user.getRealName());
|
||||
return order;
|
||||
}).collect(Collectors.groupingBy(OrderDept::getDeptId));
|
||||
//过滤部门
|
||||
List<Integer> deptIdList = new ArrayList<>();
|
||||
for (SysUser userDatum : sysUsers) {
|
||||
if (!deptIdList.contains(userDatum.getDeptId())) {
|
||||
deptIdList.add(userDatum.getDeptId());
|
||||
}
|
||||
}
|
||||
|
||||
//根据顶级部门(集团)查到所有有效的部门
|
||||
//String relationCode = topDept.getRelationCode();
|
||||
String enableStatus = "enableStatus";
|
||||
List<OrderDept> orderDepts = new ArrayList<>();
|
||||
List<SysDept> depts =new ArrayList<>();
|
||||
depts.add(topDept);
|
||||
List<SysDept> sysDepts = deptService.getSubsidiaryDepts(depts, CommonConstant.DEPT_KEY);
|
||||
for (SysDept sysDept : sysDepts) {
|
||||
OrderDept orderDept = new OrderDept();
|
||||
orderDept.setPid(sysDept.getPid());
|
||||
orderDept.setId(String.valueOf(sysDept.getId()));
|
||||
orderDept.setDeptId(sysDept.getId());
|
||||
orderDept.setType("dept");
|
||||
orderDept.setName(sysDept.getName());
|
||||
orderDepts.add(orderDept);
|
||||
}
|
||||
//顶级的那个数据
|
||||
OrderDept orderDeptTop = new OrderDept();
|
||||
orderDeptTop.setPid(topDept.getPid());
|
||||
orderDeptTop.setId(String.valueOf(topDept.getId()));
|
||||
orderDeptTop.setDeptId(topDept.getId());
|
||||
orderDeptTop.setType("dept");
|
||||
orderDeptTop.setName(topDept.getName());
|
||||
List<OrderDept> child = new ArrayList<>();
|
||||
|
||||
//去除没有子部门并且没有人员的机构元素
|
||||
while (true) {
|
||||
//一次只能找到最下层结构没有子部门并且没有挂人的
|
||||
List<OrderDept> noSubList = new ArrayList<>();
|
||||
for (OrderDept orderDept : orderDepts) {
|
||||
boolean hasSub =false;
|
||||
for(OrderDept dept: orderDepts){
|
||||
if(orderDept.getDeptId().equals(dept.getPid())){
|
||||
hasSub =true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!hasSub && !userMap.containsKey(orderDept.getDeptId())){
|
||||
noSubList.add(orderDept);
|
||||
}
|
||||
}
|
||||
//没有
|
||||
if (noSubList.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
Map<Integer, OrderDept> noSubMap = noSubList.stream().collect(Collectors.toMap(OrderDept::getDeptId, orderDept -> orderDept));
|
||||
//下一次循环时
|
||||
List<OrderDept> newOrderDepts = new ArrayList<>();
|
||||
for (OrderDept orderDept : orderDepts) {
|
||||
if(noSubMap.containsKey(orderDept.getDeptId())){
|
||||
continue;
|
||||
}
|
||||
newOrderDepts.add(orderDept);
|
||||
}
|
||||
orderDepts = newOrderDepts;
|
||||
}
|
||||
|
||||
//生成部门树
|
||||
for (OrderDept orderDept : orderDepts) {
|
||||
//
|
||||
if (orderDept.getPid().equals(orderDeptTop.getDeptId())) {
|
||||
//拿到所有的子部门
|
||||
List<OrderDept> deptChild = getChild(orderDept.getDeptId(), orderDepts, userMap);
|
||||
//顶级部门下一层的二级部门增加人员
|
||||
if(userMap.containsKey(orderDept.getDeptId())){
|
||||
deptChild.addAll(userMap.get(orderDept.getDeptId()));
|
||||
}
|
||||
orderDept.setChildren(deptChild);
|
||||
child.add(orderDept);
|
||||
|
||||
}
|
||||
}
|
||||
//顶层部门下的人员集合
|
||||
if (userMap.containsKey(orderDeptTop.getDeptId())) {
|
||||
List<OrderDept> persons = userMap.get(orderDeptTop.getDeptId());
|
||||
child.addAll(persons);
|
||||
}
|
||||
//设置顶级部门下的child
|
||||
orderDeptTop.setChildren(child);
|
||||
return orderDeptTop;
|
||||
}
|
||||
|
||||
//递归方法
|
||||
public List<OrderDept> getChild(Integer pid, List<OrderDept> all, Map<Integer, List<OrderDept>> userMap) {
|
||||
List<OrderDept> list = new ArrayList<>();
|
||||
for (OrderDept orderDept : all) {
|
||||
if (orderDept.getPid().equals(pid)) {
|
||||
List<OrderDept> deptChild = getChild(orderDept.getDeptId(), all, userMap);
|
||||
//如果
|
||||
if (userMap.containsKey(orderDept.getDeptId())) {
|
||||
deptChild.addAll(userMap.get(orderDept.getDeptId()));
|
||||
}
|
||||
orderDept.setChildren(deptChild);
|
||||
list.add(orderDept);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,250 @@
|
||||
package com.ho.user.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Snowflake;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.entity.PageVO;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.util.PageUtilsOld;
|
||||
import com.ho.user.entity.SysDict;
|
||||
import com.ho.user.vo.req.*;
|
||||
import com.ho.user.api.entity.SysSubDict;
|
||||
import com.ho.user.mapper.SysDictMapper;
|
||||
import com.ho.user.service.DictService;
|
||||
import com.ho.user.vo.resp.DictRespVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: 字典实现类
|
||||
* @date 2022/8/18
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DictServiceImpl implements DictService {
|
||||
|
||||
@Autowired
|
||||
SysDictMapper dictMapper;
|
||||
|
||||
@Autowired
|
||||
Snowflake snowflake;
|
||||
|
||||
@Override
|
||||
public SysDict addTypeDict(DictAddTypeVO vo) {
|
||||
SysDict sysDict = new SysDict();
|
||||
BeanUtils.copyProperties(vo,sysDict);
|
||||
dictMapper.insertDict(sysDict);
|
||||
return sysDict;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysSubDict addSubDict(DictAddReqVO vo) {
|
||||
SysSubDict subDict = new SysSubDict();
|
||||
BeanUtils.copyProperties(vo, subDict);
|
||||
subDict.setLabelEn(vo.getLabel());
|
||||
dictMapper.insertSubDict(subDict);
|
||||
return subDict;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SysDict updateDict(DictUpdateReqVO vo) {
|
||||
SysDict dict = new SysDict();
|
||||
BeanUtils.copyProperties(vo, dict);
|
||||
SysDict sysDict = dictMapper.selectById(vo.getId());
|
||||
if (sysDict == null){
|
||||
throw new BusinessException(BaseResponseCode.DICT_DELETED_EXISTS);
|
||||
}
|
||||
int upDictRet = dictMapper.updateDict(dict);
|
||||
log.info("修改sys_dict记录数:" + upDictRet);
|
||||
List<SysSubDict> sysSubDicts = selectSubDictByType(sysDict.getType());
|
||||
int upSubDictRet = 0;
|
||||
for (SysSubDict sysSubDict : sysSubDicts) {
|
||||
sysSubDict.setType(vo.getType());
|
||||
upSubDictRet = dictMapper.updateSubDict(sysSubDict);
|
||||
}
|
||||
log.info("修改sys_sub_dict记录数:" + upSubDictRet);
|
||||
return dict;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysSubDict updateSubDict(DictSubUpdateReqVO vo) {
|
||||
SysSubDict sysSubDict = dictMapper.selectBySubId(vo.getId());
|
||||
//先判断是否有相同value的值
|
||||
// if(!vo.getValue().equals(sysSubDict.getValue())){
|
||||
// SysSubDict subDict = selectSubDictByTV(vo.getType(), vo.getValue());
|
||||
// if (subDict != null) {
|
||||
// throw new BusinessException(BaseResponseCode.DICT_ALREADY_EXISTS);
|
||||
// }
|
||||
// }
|
||||
if(!vo.getSort().equals(sysSubDict.getSort())){
|
||||
//判断排序
|
||||
SysSubDict subDictSort = selectSubDictBySort(vo.getType(), vo.getSort());
|
||||
if (subDictSort != null) {
|
||||
throw new BusinessException(BaseResponseCode.SORT_CODE_BEEN_USED_PLEASE_CORRECT_SORT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SysSubDict subDict = new SysSubDict();
|
||||
BeanUtils.copyProperties(vo,subDict);
|
||||
List<SysSubDict> sysSubDicts = selectSubDictByType(vo.getType());
|
||||
if (sysSubDicts.size() == 0){
|
||||
throw new BusinessException(BaseResponseCode.DICT_DELETED_EXISTS);
|
||||
}
|
||||
dictMapper.updateSubDict(subDict);
|
||||
return subDict;
|
||||
}
|
||||
//
|
||||
// @Override
|
||||
// public SysDict detailInfoById(Integer id) {
|
||||
// SysDict sysDict = dictMapper.selectByPrimaryKey(id);
|
||||
// return sysDict;
|
||||
// }
|
||||
|
||||
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void deletedById(Integer id) {
|
||||
// //通过id删除dict
|
||||
// SysDict dict = new SysDict();
|
||||
// dict.setId(id);
|
||||
// SysDict sysDict1 = dictMapper.selectById(id);
|
||||
// if (sysDict1 == null){
|
||||
// throw new BusinessException(BaseResponseCode.DICT_DELETED_EXISTS);
|
||||
// }
|
||||
// SysDict sysDict = dictMapper.selectById(id);
|
||||
// dictMapper.deleteByPrimaryKey(id);
|
||||
// //先查询sub_dict中的type,在对其进行删除
|
||||
// SysSubDict subDict = new SysSubDict();
|
||||
// subDict.setType(sysDict.getType());
|
||||
// subDict.setDeleted(CommonConstant.DELETED_FLAG);
|
||||
// dictMapper.updateByPrimaryKey(subDict);
|
||||
//
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void deletedByType(String type) {
|
||||
// dictMapper.deleteByType(type);
|
||||
// SysSubDict subDict = new SysSubDict();
|
||||
// subDict.setType(type);
|
||||
// subDict.setDeleted(CommonConstant.DELETED_FLAG);
|
||||
// dictMapper.updateByPrimaryKey(subDict);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void deletedSubById(Integer id) {
|
||||
SysSubDict subDict = new SysSubDict();
|
||||
subDict.setDeleted(CommonConstant.DELETED_FLAG);
|
||||
subDict.setId(id);
|
||||
dictMapper.updateSubDict(subDict);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysSubDict> selectSubDictByType(String type) {
|
||||
List<SysSubDict> sysSubDicts = dictMapper.selectSubDictByType(type);
|
||||
return sysSubDicts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysSubDict> selectSubDictByTypeList(List<String> typeList) {
|
||||
List<SysSubDict> sysSubDicts = dictMapper.selectSubDictByTypeList(typeList);
|
||||
return sysSubDicts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DictRespVo selectDict(DictTypeAndLabelReqVO vo) {
|
||||
SysDict sysDict = dictMapper.selectByType(vo.getType());
|
||||
DictRespVo dictRespVo = new DictRespVo();
|
||||
BeanUtils.copyProperties(sysDict,dictRespVo);
|
||||
List<SysSubDict> sysSubDicts = selectSubDictByType(vo.getType());
|
||||
dictRespVo.setList(sysSubDicts);
|
||||
return dictRespVo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public PageVO<DictRespVo> all(DictPageReqVO vo) {
|
||||
PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
|
||||
List<DictRespVo> sysDicts = dictMapper.selectAll(vo);
|
||||
// for (DictRespVo sysDict : sysDicts) {
|
||||
// List<SysSubDict> sysSubDicts = dictMapper.selectSubDictByType(sysDict.getType());
|
||||
// sysDict.setList(sysSubDicts);
|
||||
// }
|
||||
return PageUtilsOld.getPageVO(sysDicts);
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public PageVO<SysDept> pageInfo(DeptPageReqVO vo) {
|
||||
return null;
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public List<DictRespVo> selectDictType() {
|
||||
List<SysDict> sysDicts = dictMapper.selectTypeAll();
|
||||
List<DictRespVo> respVos = new ArrayList<>();
|
||||
for (SysDict sysDict : sysDicts) {
|
||||
DictRespVo vo = new DictRespVo();
|
||||
BeanUtils.copyProperties(sysDict,vo);
|
||||
List<SysSubDict> sysSubDicts = selectSubDictByType(sysDict.getType());
|
||||
vo.setList(sysSubDicts);
|
||||
respVos.add(vo);
|
||||
}
|
||||
return respVos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysDict selectDictByTypeAndName(DictAddTypeVO vo) {
|
||||
SysDict queryDict = new SysDict();
|
||||
BeanUtils.copyProperties(vo,queryDict);
|
||||
SysDict sysDict = dictMapper.selectDictByTypeAndName(queryDict);
|
||||
return sysDict;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysDict selectDictByType(DictAddTypeVO vo) {
|
||||
SysDict sysDict = dictMapper.selectByType(vo.getType());
|
||||
return sysDict;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDict> selectDictListByType(String type) {
|
||||
List<SysDict> sysDicts = dictMapper.selectDictListByType(type);
|
||||
return sysDicts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysSubDict selectSubDictByValue(DictAddReqVO vo) {
|
||||
SysSubDict subDict = dictMapper.selectSubDictByValue(vo.getValue());
|
||||
return subDict;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysSubDict selectSubDictByTV(String type, String value) {
|
||||
SysSubDict subDict = dictMapper.selectSubDictByTV(type,value);
|
||||
return subDict;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysSubDict> selectSubDictByKey(SysSubDict sysSubDict) {
|
||||
List<SysSubDict> subDictList = dictMapper.selectSubDictByKey(sysSubDict);
|
||||
return subDictList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysSubDict selectSubDictBySort(String type, Long sort) {
|
||||
SysSubDict subDictSort = dictMapper.selectSubDictBySort(type,sort);
|
||||
return subDictSort;
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
package com.ho.user.service.impl;
|
||||
|
||||
import com.ho.common.tools.util.AESEncryptUtil;
|
||||
import com.ho.common.tools.util.RSAUtil;
|
||||
import com.ho.user.service.EncryptComponent;
|
||||
import com.ho.user.vo.req.LoginReqVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc:
|
||||
* @date 2022/11/17
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class EncryptComponentImpl implements EncryptComponent {
|
||||
|
||||
@Value("${rsa.privateKey}")
|
||||
String privateKey;
|
||||
|
||||
/**
|
||||
* @param loginReqVO 带密文的对象
|
||||
* @return 解密后的对象
|
||||
*/
|
||||
@Override
|
||||
public LoginReqVO decryptSecret(LoginReqVO loginReqVO) {
|
||||
String aesKey = RSAUtil.decode(loginReqVO.getAesKey(), privateKey);
|
||||
String iv = RSAUtil.decode(loginReqVO.getIv(), privateKey);
|
||||
if (loginReqVO.getPassword() != null) {
|
||||
String passwd = AESEncryptUtil.decrypt(loginReqVO.getPassword(), aesKey, iv);
|
||||
loginReqVO.setPassword(passwd);
|
||||
}
|
||||
loginReqVO.setAesKey(aesKey);
|
||||
loginReqVO.setIv(iv);
|
||||
|
||||
log.info("解密后的 aesKey:{}, iv: {}", loginReqVO.getAesKey(), loginReqVO.getIv());
|
||||
return loginReqVO;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
package com.ho.user.service.impl;
|
||||
|
||||
|
||||
import com.ho.user.entity.PermissionRespNode;
|
||||
import com.ho.user.api.entity.SysDept;
|
||||
import com.ho.user.api.entity.SysUser;
|
||||
import com.ho.user.service.DeptService;
|
||||
import com.ho.user.service.HomeService;
|
||||
import com.ho.user.service.PermissionService;
|
||||
import com.ho.user.service.UserService;
|
||||
import com.ho.user.vo.resp.HomeRespVO;
|
||||
import com.ho.user.vo.resp.UserInfoRespVO;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName: HomeServiceImpl
|
||||
* 首页实现类
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class HomeServiceImpl implements HomeService {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private DeptService deptService;
|
||||
|
||||
@Autowired
|
||||
private PermissionService permissionService;
|
||||
|
||||
@Override
|
||||
public HomeRespVO getHomeInfo(String userId) {
|
||||
|
||||
SysUser sysUser = userService.detailInfo(userId);
|
||||
UserInfoRespVO vo = new UserInfoRespVO();
|
||||
|
||||
if (sysUser != null) {
|
||||
BeanUtils.copyProperties(sysUser, vo);
|
||||
SysDept sysDept = deptService.detailInfo(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;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package com.ho.user.service.impl;
|
||||
|
||||
|
||||
import com.ho.user.entity.IdControl;
|
||||
import com.ho.user.mapper.IdControlMapper;
|
||||
import com.ho.user.service.IdControlService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* @version 1.0.0
|
||||
* @ClassName IdControlService.java
|
||||
* @Description TODO
|
||||
* @createTime 2022年09月22日 09:21:00
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class IdControlServiceImpl implements IdControlService{
|
||||
@Autowired
|
||||
private IdControlMapper idControlMapper;
|
||||
|
||||
@Override
|
||||
public Integer insert(IdControl control) {
|
||||
Integer insert = idControlMapper.insert(control);
|
||||
return insert;
|
||||
|
||||
}
|
||||
@Override
|
||||
public IdControl selectCurrentVal(String type) {
|
||||
IdControl idControl = idControlMapper.selectCurrentVal(type);
|
||||
return idControl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCurrentVal(String type,Integer currentVal) {
|
||||
idControlMapper.updateCurrentVal(type,currentVal);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,93 @@
|
||||
package com.ho.user.service.impl;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import com.ho.common.tools.util.PageUtils;
|
||||
import com.ho.common.tools.util.RedisCommon;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.user.api.entity.SysDept;
|
||||
import com.ho.user.api.entity.SysLog;
|
||||
import com.ho.user.mapper.SysLogMapper;
|
||||
import com.ho.user.service.DeptService;
|
||||
import com.ho.user.service.LogService;
|
||||
import com.ho.user.service.PermissionService;
|
||||
import com.ho.user.vo.req.SysLogPageReqVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName: LogServiceImpl
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/23 16:18
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/23 16:18
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class LogServiceImpl implements LogService{
|
||||
@Autowired
|
||||
private SysLogMapper sysLogMapper;
|
||||
|
||||
@Autowired
|
||||
private DeptService deptService;
|
||||
|
||||
@Autowired
|
||||
private PermissionService permissionService;
|
||||
|
||||
@Autowired
|
||||
private RedisCommon redisCommon;
|
||||
|
||||
@Override
|
||||
public PageResult pageInfo(SysLogPageReqVO vo, SimpleUser simpleUser) {
|
||||
//判断用户是否为超管
|
||||
if(CommonConstant.TOP_PARENT_ID.equals(simpleUser.getGroupId())){
|
||||
if(CommonConstant.TOP_PARENT_ID.equals(simpleUser.getDeptId())){
|
||||
//超管可以查询所有
|
||||
String endTime = vo.getEndTime();
|
||||
String startTime = vo.getStartTime();
|
||||
String operation = vo.getOperation();
|
||||
String username = vo.getUsername();
|
||||
PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
|
||||
List<SysLog> sysLogs = sysLogMapper.selectAllLogs(endTime,startTime,operation,username);
|
||||
return PageUtils.getPageResult(new PageInfo<>(sysLogs));
|
||||
}
|
||||
}
|
||||
Integer deptId = simpleUser.getDeptId();
|
||||
//如果没传入部门,仅查询用户所属部门下的数据
|
||||
if (deptId == null) {
|
||||
SimpleUser currentSimpleUser = permissionService.getCurrentSimpleUser();
|
||||
deptId = currentSimpleUser.getDeptId();
|
||||
}
|
||||
SysDept sysDept = deptService.detailInfo(deptId);
|
||||
if (null == sysDept) {
|
||||
log.error("传入 的 id:{}不合法", deptId);
|
||||
throw new BusinessException(BaseResponseCode.DATA_ERROR);
|
||||
}
|
||||
List<SysDept> sysDeptList =new ArrayList<>();
|
||||
sysDeptList.add(sysDept);
|
||||
List<SysDept> sysDepts = deptService.getSubsidiaryDepts(sysDeptList,CommonConstant.DEPT_KEY);
|
||||
vo.setDepts(sysDepts);
|
||||
vo.setGroupId(simpleUser.getGroupId());
|
||||
vo.setUserId(null);
|
||||
vo.setUsername(vo.getUsername());
|
||||
PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
|
||||
|
||||
List<SysLog> sysLogs = sysLogMapper.selectAll(vo);
|
||||
return PageUtils.getPageResult(new PageInfo<>(sysLogs));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deleted(List<Long> logIds) {
|
||||
sysLogMapper.batchDeletedLog(logIds);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,148 @@
|
||||
package com.ho.user.service.impl;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.ho.business.entity.Station;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.entity.PageVO;
|
||||
import com.ho.common.tools.entity.SysPermission;
|
||||
import com.ho.common.tools.entity.SysRole;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.util.PageUtilsOld;
|
||||
import com.ho.user.api.entity.PermStationRelation;
|
||||
import com.ho.user.feignclient.BusinessFeignClient;
|
||||
import com.ho.user.mapper.PermStationRelationMapper;
|
||||
import com.ho.user.mapper.SysPermissionMapper;
|
||||
import com.ho.user.service.PermStationRelationService;
|
||||
import com.ho.user.vo.req.StationPermissionReqVo;
|
||||
import com.ho.user.vo.resp.StationPermissionRespVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* @TableName perm_station_relation
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PermStationRelationImpl implements PermStationRelationService {
|
||||
@Autowired
|
||||
PermStationRelationMapper permStationRelationMapper;
|
||||
|
||||
@Autowired
|
||||
SysPermissionMapper sysPermissionMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public int insertSelective(PermStationRelation record) {
|
||||
if (!record.getPermissions().isEmpty()) {
|
||||
//新增电站与菜单的关联数据
|
||||
//关联表自身进行数据新增
|
||||
for (Integer permissionId : record.getPermissions()) {
|
||||
|
||||
PermStationRelation permStationRelation = new PermStationRelation();
|
||||
permStationRelation.setStationId(record.getStationId());
|
||||
permStationRelation.setPermissionId(permissionId);
|
||||
Date date = new Date();
|
||||
SimpleDateFormat fmt = new SimpleDateFormat(CommonConstant.DATE);
|
||||
String dateStr = fmt.format(date);
|
||||
permStationRelation.setCreateTime(dateStr);
|
||||
permStationRelation.setStationName(record.getStationName());
|
||||
permStationRelationMapper.insertSelective(permStationRelation);
|
||||
}
|
||||
}
|
||||
return permStationRelationMapper.insertSelective(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteByPrimaryKey(Integer id) {
|
||||
return permStationRelationMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateByPrimaryKeySelective(PermStationRelation record) {
|
||||
return permStationRelationMapper.updateByPrimaryKeySelective(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateByPrimaryKey(PermStationRelation record) {
|
||||
return permStationRelationMapper.updateByPrimaryKey(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(PermStationRelation record) {
|
||||
if (record.getPermissions() != null && !record.getPermissions().isEmpty()) {
|
||||
//不为空时,将该菜单关联的电站全部删除后再重新增加
|
||||
//根据菜单Id
|
||||
List<PermStationRelation> permStationRelations = selectByStationId(record.getStationId());
|
||||
//删除
|
||||
if (!permStationRelations.isEmpty()) {
|
||||
List<Integer> idList = permStationRelations.stream().map(s -> {
|
||||
return s.getId();
|
||||
}
|
||||
).collect(Collectors.toList());
|
||||
permStationRelationMapper.deleteBatch(idList);
|
||||
}
|
||||
|
||||
//添加
|
||||
//关联表自身进行数据新增
|
||||
for (Integer permissionId : record.getPermissions()) {
|
||||
PermStationRelation permStationRelation = new PermStationRelation();
|
||||
permStationRelation.setStationId(record.getStationId());
|
||||
permStationRelation.setPermissionId(permissionId);
|
||||
permStationRelation.setStationName(record.getStationName());
|
||||
Date date = new Date();
|
||||
SimpleDateFormat fmt = new SimpleDateFormat(CommonConstant.DATE);
|
||||
String dateStr = fmt.format(date);
|
||||
permStationRelation.setCreateTime(dateStr);
|
||||
permStationRelationMapper.insertSelective(permStationRelation);
|
||||
}
|
||||
} else {
|
||||
//在更改时,判断电站list是否为空,为空的话就将更为公共,再根据菜单Id找到关联表,检查是否有数据,有则删掉
|
||||
//根据电站Id
|
||||
List<PermStationRelation> permStationRelations = selectByStationId(record.getStationId());
|
||||
if (!permStationRelations.isEmpty()) {
|
||||
List<Integer> idList = permStationRelations.stream().map(s -> {
|
||||
return s.getId();
|
||||
}
|
||||
).collect(Collectors.toList());
|
||||
deleteBatch(idList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PermStationRelation> selectByStationId(Integer stationId) {
|
||||
return permStationRelationMapper.selectByStationId(stationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PermStationRelation> selectByPermissionId(Integer permissionId) {
|
||||
return permStationRelationMapper.selectByPermissionId(permissionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBatch(List<Integer> ids) {
|
||||
permStationRelationMapper.deleteBatchStationId(ids);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PermStationRelation detailInfo(Integer id) {
|
||||
PermStationRelation permStationRelation = new PermStationRelation();
|
||||
//入参电站Id 查询关联表 ,返回菜单数据
|
||||
List<PermStationRelation> permStationRelations = selectByStationId(id);
|
||||
List<Integer> collect = permStationRelations.stream().map(s -> {
|
||||
return s.getPermissionId();
|
||||
}
|
||||
).collect(Collectors.toList());
|
||||
permStationRelation.setPermissions(collect);
|
||||
permStationRelation.setStationId(id);
|
||||
return permStationRelation;
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,137 @@
|
||||
package com.ho.user.service.impl;
|
||||
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.user.entity.SysPosition;
|
||||
import com.ho.user.entity.SysUserPosition;
|
||||
import com.ho.user.mapper.SysPositionMapper;
|
||||
import com.ho.user.mapper.SysUserPositionMapper;
|
||||
import com.ho.user.service.PositionService;
|
||||
import com.ho.user.vo.req.PositionAddReqVO;
|
||||
import com.ho.user.vo.req.PositionQueryReqVO;
|
||||
import com.ho.user.vo.req.PositionUpdateReqVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description 岗位管理业务实现类
|
||||
* Author yule
|
||||
* Date 2022/12/1 15:58
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PositionServiceImpl implements PositionService {
|
||||
|
||||
@Autowired
|
||||
SysPositionMapper sysPositionMapper;
|
||||
|
||||
@Autowired
|
||||
SysUserPositionMapper sysUserPositionMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public int add(PositionAddReqVO vo) {
|
||||
SysPosition sysPosition = new SysPosition();
|
||||
BeanUtils.copyProperties(vo, sysPosition);
|
||||
sysPosition.setDeleted(1);
|
||||
sysPosition.setStatus(vo.getStatus());
|
||||
sysPosition.setCreateTime(new Date());
|
||||
sysPosition.setUpdateTime(new Date());
|
||||
int i = sysPositionMapper.insertSelective(sysPosition);
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysPosition selectById(Integer id) {
|
||||
SysPosition sysPosition = sysPositionMapper.selectByPrimaryKey(id);
|
||||
return sysPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysPosition> selectAccuratePositionByInfo(SysPosition sysPosition) {
|
||||
List<SysPosition> positions = sysPositionMapper.selectByInfo(sysPosition);
|
||||
return positions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysPosition> getPositionByTop() {
|
||||
List<SysPosition> positions = sysPositionMapper.getPositionByTop();
|
||||
return positions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysPosition> selectAll() {
|
||||
List<SysPosition> positions = sysPositionMapper.selectByInfo(null);
|
||||
return positions;
|
||||
}
|
||||
|
||||
//查询所有可用的
|
||||
@Override
|
||||
public List<SysPosition> selectAvailable() {
|
||||
SysPosition vo = new SysPosition();
|
||||
vo.setStatus(1);
|
||||
List<SysPosition> positions = sysPositionMapper.select(vo);
|
||||
return positions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysPosition> selectObscure(PositionQueryReqVO vo) {
|
||||
List<SysPosition> positions = sysPositionMapper.selectObscure(vo);
|
||||
return positions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleted(Integer id) {
|
||||
//根据id查询
|
||||
SysPosition position = sysPositionMapper.selectByPrimaryKey(id);
|
||||
if (position == null) {
|
||||
throw new BusinessException(BaseResponseCode.POSITION_NOT_EXISTS);
|
||||
}
|
||||
//如果为禁用状态时,说明岗位下没有人使用
|
||||
//判断所删除的状态是否未启用状态,如果未启用状态则不能删除
|
||||
if (position.getStatus().equals(CommonConstant.ONE)) {
|
||||
throw new BusinessException(BaseResponseCode.POSITION_CANNOT_NOT_STATE_DELETE);
|
||||
}
|
||||
position.setUpdateTime(new Date());
|
||||
position.setDeleted(0);
|
||||
|
||||
int count = sysPositionMapper.updateByPrimaryKeySelective(position);
|
||||
if (count != 1) {
|
||||
throw new BusinessException(BaseResponseCode.OPERATION_ERRO);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePosition(PositionUpdateReqVO vo) {
|
||||
SysPosition sysPosition = new SysPosition();
|
||||
BeanUtils.copyProperties(vo, sysPosition);
|
||||
sysPosition.setUpdateTime(new Date());
|
||||
|
||||
SysPosition origPosition = sysPositionMapper.selectByPrimaryKey(vo.getId());
|
||||
if (origPosition == null) {
|
||||
throw new BusinessException(BaseResponseCode.POSITION_NOT_EXISTS);
|
||||
}
|
||||
//修改判断
|
||||
//修改为禁用时,判断下面是否有人员
|
||||
if (CommonConstant.ZERO.equals(vo.getStatus())) {
|
||||
//根据岗位id查询
|
||||
List<SysUserPosition> sysUserPositions = sysUserPositionMapper.selectByPostId(vo.getId());
|
||||
if (!sysUserPositions.isEmpty() || sysUserPositions == null) {
|
||||
throw new BusinessException(BaseResponseCode.POSITION_ASSOCIATED_USER_CANNOT_DISABLE);
|
||||
}
|
||||
}
|
||||
sysPositionMapper.updateByPrimaryKeySelective(sysPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> selectPostIds(List<String> postCodes) {
|
||||
List<Integer> postIds = sysPositionMapper.selectPostIds(postCodes);
|
||||
return postIds;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,243 @@
|
||||
package com.ho.user.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.entity.SysPermission;
|
||||
import com.ho.common.tools.entity.UserDetailRespVO;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.user.api.entity.SysUser;
|
||||
import com.ho.user.mapper.SysPermissionMapper;
|
||||
import com.ho.user.mapper.SysUserMapper;
|
||||
import com.ho.user.service.*;
|
||||
import com.ho.user.vo.req.UserPageReqVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @Description TODO
|
||||
* Author yule
|
||||
* Date 2022/9/19 17:56
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class RedisUpdateServiceImpl implements RedisUpdateService {
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
DeptService deptService;
|
||||
|
||||
@Autowired
|
||||
UserRoleService userRoleService;
|
||||
|
||||
@Autowired
|
||||
SysUserMapper sysUserMapper;
|
||||
|
||||
@Autowired
|
||||
SysPermissionMapper permissionMapper;
|
||||
|
||||
@Autowired
|
||||
PermissionService permissionService;
|
||||
|
||||
|
||||
@Override
|
||||
public void updateRedis(UserDetailRespVO userDetail, SysUser sysUser) {
|
||||
String accessToken = userDetail.getAccessToken();
|
||||
//判断更新人是否是本人
|
||||
redisService.set(RedisKeyConstant.User.TOKEN + accessToken, userDetail, 2, TimeUnit.HOURS);
|
||||
//SimpleUser不需要改
|
||||
//redisService.set(RedisKeyConstant.User.USER_NAME +userDetail.getLoginChannel() + ":"+ userDetail.getUsername(), simpleUser, 2, TimeUnit.HOURS);
|
||||
//redisService.set(RedisKeyConstant.User.IDENTIFY_CACHE_KEY + sysUser.getId(), userDetail.getPowerList(), 2, TimeUnit.HOURS);
|
||||
redisService.delete(RedisKeyConstant.User.IDENTIFY_CACHE_KEY + sysUser.getId());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanLoginInfosByRoleId(List<Integer> roleIds) {
|
||||
log.info("cleanLoginInfosByRoleId:" + roleIds);
|
||||
if (!roleIds.isEmpty()) {
|
||||
List<String> userIdsByRoleIds = userRoleService.getUserIdsByRoleIds(roleIds);
|
||||
if (userIdsByRoleIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (String userId : userIdsByRoleIds) {
|
||||
//查用户信息
|
||||
SysUser sysUser = sysUserMapper.selectByPrimaryKey(userId);
|
||||
if (sysUser != null) {
|
||||
String userNameKeyPc = RedisKeyConstant.User.USER_NAME +RedisKeyConstant.User.LOGIN_CHANNEL_PC +":"+ sysUser.getUsername();
|
||||
String userNameKeyApp = RedisKeyConstant.User.USER_NAME +RedisKeyConstant.User.LOGIN_CHANNEL_APP +":"+ sysUser.getUsername();
|
||||
//如果有缓存就删除
|
||||
if (redisService.hasKey(userNameKeyPc)) {
|
||||
SimpleUser simpleUser = (SimpleUser) redisService.get(userNameKeyPc);
|
||||
String token = simpleUser.getToken();
|
||||
String tokenKey = RedisKeyConstant.User.TOKEN + token;
|
||||
String shiroKey = RedisKeyConstant.User.IDENTIFY_CACHE_KEY + userId;
|
||||
redisService.delete(userNameKeyPc);
|
||||
redisService.delete(tokenKey);
|
||||
redisService.delete(shiroKey);
|
||||
}
|
||||
if (redisService.hasKey(userNameKeyApp)) {
|
||||
SimpleUser simpleUser = (SimpleUser) redisService.get(userNameKeyApp);
|
||||
String token = simpleUser.getToken();
|
||||
String tokenKey = RedisKeyConstant.User.TOKEN + token;
|
||||
String shiroKey = RedisKeyConstant.User.IDENTIFY_CACHE_KEY + userId;
|
||||
redisService.delete(userNameKeyApp);
|
||||
redisService.delete(tokenKey);
|
||||
redisService.delete(shiroKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新超管的菜单信息
|
||||
*/
|
||||
@Override
|
||||
public void updateSuperPermsCache() {
|
||||
|
||||
//根据超管查询出所有超管用户
|
||||
UserPageReqVO userPageReqVO = new UserPageReqVO();
|
||||
userPageReqVO.setSuperRole("super");
|
||||
List<SysUser> sysUsers = sysUserMapper.selectAll(userPageReqVO);
|
||||
|
||||
//查询全部有效菜单
|
||||
SysPermission sysManageMenu = permissionService.findSysManageMenu();
|
||||
if (sysManageMenu != null) {
|
||||
List<SysPermission> menuList = new ArrayList<>();
|
||||
menuList.add(sysManageMenu);
|
||||
List<Integer> queryIds = new ArrayList<>();
|
||||
queryIds.add(sysManageMenu.getId());
|
||||
List<SysPermission> permissions = permissionService.getSysMangeMenus(menuList, queryIds);
|
||||
sysManageMenu.setChildren(getPermTree(sysManageMenu.getId(), permissions));
|
||||
//将菜单放入userDetail对象
|
||||
List<SysPermission> menus = new ArrayList<>();
|
||||
menus.add(sysManageMenu);
|
||||
|
||||
//包含这个用户就更新这个用户的 menuList 和powerList
|
||||
if (!sysUsers.isEmpty()) {
|
||||
for (SysUser sysUser : sysUsers) {
|
||||
String userNameKeyPc = RedisKeyConstant.User.USER_NAME + RedisKeyConstant.User.LOGIN_CHANNEL_PC + ":" + sysUser.getUsername();
|
||||
String userNameKeyApp = RedisKeyConstant.User.USER_NAME + RedisKeyConstant.User.LOGIN_CHANNEL_APP + ":" + sysUser.getUsername();
|
||||
//用户处于登陆状态
|
||||
if (redisService.hasKey(userNameKeyPc)) {
|
||||
SimpleUser simpleUser = (SimpleUser) redisService.get(userNameKeyPc);
|
||||
if (simpleUser != null) {
|
||||
String tokenKey = RedisKeyConstant.User.TOKEN + simpleUser.getToken();
|
||||
UserDetailRespVO userDetail = (UserDetailRespVO) redisService.get(tokenKey);
|
||||
if (userDetail != null) {
|
||||
//userDetail.setMenuList(menus);
|
||||
//userDetail.setPowerList(powerList);
|
||||
redisService.set(tokenKey, userDetail, 2, TimeUnit.HOURS);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (redisService.hasKey(userNameKeyApp)) {
|
||||
SimpleUser simpleUser = (SimpleUser) redisService.get(userNameKeyApp);
|
||||
if (simpleUser != null) {
|
||||
String tokenKey = RedisKeyConstant.User.TOKEN + simpleUser.getToken();
|
||||
UserDetailRespVO userDetail = (UserDetailRespVO) redisService.get(tokenKey);
|
||||
if (userDetail != null) {
|
||||
//userDetail.setMenuList(menus);
|
||||
//userDetail.setPowerList(powerList);
|
||||
redisService.set(tokenKey, userDetail, 2, TimeUnit.HOURS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public List<SysPermission> getPermTree(Integer id, List<SysPermission> permissions) {
|
||||
List<SysPermission> list = new ArrayList<>();
|
||||
for (SysPermission permission : permissions) {
|
||||
if (permission.getPid().equals(id) && CommonConstant.MENU_FLAG.equals(permission.getType())) {
|
||||
permission.setChildren(getPermTree(permission.getId(), permissions));
|
||||
list.add(permission);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTokenKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUserNameKey(String userName) {
|
||||
//RedisKeyConstant.User.USER_NAME +loginReqVO.getType() + ":" + loginReqVO.getUsername()
|
||||
return null;
|
||||
}
|
||||
|
||||
//找到所有超管的菜单
|
||||
/*private List<SysPermission> getSuperPerms() {
|
||||
UserPageReqVO userPageReqVO = new UserPageReqVO();
|
||||
userPageReqVO.setSuperRole("super");
|
||||
List<SysUser> sysUsers = sysUserMapper.selectAll(userPageReqVO);
|
||||
//查询全部有效菜单
|
||||
List<SysPermission> sysPermissions = permissionMapper.selectAll(null);
|
||||
return sysPermissions;
|
||||
}*/
|
||||
|
||||
//找到所有超管的菜单 ,只查系统菜单下的
|
||||
private List<SysPermission> getSuperPerms() {
|
||||
List<SysPermission> permissions = new ArrayList<>();
|
||||
//超管,只查询 系统管理下 的菜单
|
||||
//SysPermission sysManageMenu = permissionService.findSysManageMenu();
|
||||
SysPermission sysPermissionQuery = new SysPermission();
|
||||
//sysPermissionQuery.setName(CommonConstant.SYS_MENU_NAME);
|
||||
//sysPermissionQuery.setPid(CommonConstant.TOP_PARENT_ID);
|
||||
sysPermissionQuery.setId(CommonConstant.SYS_MENU_Id);
|
||||
SysPermission sysManageMenu = permissionMapper.selectOneByCondition(sysPermissionQuery);
|
||||
if (sysManageMenu != null) {
|
||||
List<SysPermission> list = new ArrayList<>();
|
||||
list.add(sysManageMenu);
|
||||
List<Integer> queryIds = new ArrayList<>();
|
||||
queryIds.add(sysManageMenu.getId());
|
||||
|
||||
//permissions = permissionService.getSysMangeMenus(list, queryIds);
|
||||
permissions = getSysMangeMenus(list, queryIds);
|
||||
}
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public List<SysPermission> getSysMangeMenus(List<SysPermission> list, List<Integer> queryIds) {
|
||||
if (queryIds == null || queryIds.isEmpty()) {
|
||||
return list;
|
||||
}
|
||||
//查询父id在queryIds中的
|
||||
List<SysPermission> sysPermissions = permissionMapper.selectChilds(queryIds);
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
list.addAll(sysPermissions);
|
||||
//将ids作为下一次循环的入参
|
||||
for (SysPermission sysPermission : sysPermissions) {
|
||||
ids.add(sysPermission.getId());
|
||||
}
|
||||
return getSysMangeMenus(list, ids);
|
||||
}
|
||||
|
||||
|
||||
private List<String> dealPowerTag(List<SysPermission> permissions) {
|
||||
final List<String> powerList = new ArrayList<>();
|
||||
permissions.stream().filter(p -> !StrUtil.isBlank(p.getPerms())).forEach(p -> {
|
||||
powerList.add(p.getPerms());
|
||||
});
|
||||
return powerList;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,102 @@
|
||||
package com.ho.user.service.impl;
|
||||
|
||||
|
||||
import cn.hutool.core.lang.Snowflake;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.user.entity.SysRolePermission;
|
||||
import com.ho.user.mapper.SysRolePermissionMapper;
|
||||
import com.ho.user.service.RolePermissionService;
|
||||
import com.ho.user.vo.req.RolePermissionOperationReqVO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Service
|
||||
public class RolePermissionServiceImpl implements RolePermissionService {
|
||||
|
||||
@Autowired
|
||||
private SysRolePermissionMapper sysRolePermissionMapper;
|
||||
|
||||
@Autowired
|
||||
Snowflake snowflake;
|
||||
|
||||
@Override
|
||||
public int removeByRoleId(Integer roleId) {
|
||||
return sysRolePermissionMapper.removeByRoleId(roleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getPermissionIdsByRoles(List<Integer> roleIds) {
|
||||
|
||||
return sysRolePermissionMapper.getPermissionIdsByRoles(roleIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRolePermission(RolePermissionOperationReqVO vo) {
|
||||
|
||||
Date createTime = new Date();
|
||||
List<SysRolePermission> list = new ArrayList<>();
|
||||
for (Integer permissionId:vo.getPermissionIds()){
|
||||
SysRolePermission sysRolePermission = new SysRolePermission();
|
||||
//sysRolePermission.setId(UUID.randomUUID().toString());
|
||||
// sysRolePermission.setId(snowflake.nextIdStr());
|
||||
sysRolePermission.setCreateTime(createTime);
|
||||
sysRolePermission.setPermissionId(permissionId);
|
||||
sysRolePermission.setRoleId(vo.getRoleId());
|
||||
list.add(sysRolePermission);
|
||||
}
|
||||
sysRolePermissionMapper.removeByRoleId(vo.getRoleId());
|
||||
int count = sysRolePermissionMapper.batchRolePermission(list);
|
||||
if (count==0){
|
||||
throw new BusinessException(BaseResponseCode.OPERATION_ERRO);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRolePermissions(RolePermissionOperationReqVO vo) {
|
||||
|
||||
Date createTime = new Date();
|
||||
List<SysRolePermission> list = new ArrayList<>();
|
||||
for (Integer permissionId:vo.getPermissionIds()){
|
||||
SysRolePermission sysRolePermission = new SysRolePermission();
|
||||
//sysRolePermission.setId(UUID.randomUUID().toString());
|
||||
// sysRolePermission.setId(snowflake.nextIdStr());
|
||||
sysRolePermission.setCreateTime(createTime);
|
||||
sysRolePermission.setPermissionId(permissionId);
|
||||
sysRolePermission.setRoleId(vo.getRoleId());
|
||||
list.add(sysRolePermission);
|
||||
}
|
||||
int count = sysRolePermissionMapper.batchRolePermission(list);
|
||||
if (count==0){
|
||||
throw new BusinessException(BaseResponseCode.OPERATION_ERRO);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeByPermissionId(Integer permissionId) {
|
||||
|
||||
return sysRolePermissionMapper.removeByPermissionId(permissionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getRoleIds(Integer permissionId) {
|
||||
|
||||
return sysRolePermissionMapper.getRoleIds(permissionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getPermissionIdsByRoleId(Integer roleId) {
|
||||
|
||||
return sysRolePermissionMapper.getPermissionIdsByRoleId(roleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteRolePermissions(RolePermissionOperationReqVO reqVO) {
|
||||
return sysRolePermissionMapper.deleteRolePermissions(reqVO);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,336 @@
|
||||
package com.ho.user.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Snowflake;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.entity.PageVO;
|
||||
import com.ho.common.tools.entity.SysPermission;
|
||||
import com.ho.common.tools.entity.SysRole;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.CodeUtil;
|
||||
import com.ho.common.tools.util.PageUtilsOld;
|
||||
import com.ho.user.api.entity.SysDept;
|
||||
import com.ho.user.api.vo.req.QueryPermissionReqVo;
|
||||
import com.ho.user.entity.IdControl;
|
||||
import com.ho.user.entity.PermissionRespNode;
|
||||
import com.ho.user.mapper.SysRoleMapper;
|
||||
import com.ho.user.mapper.SysUserRoleMapper;
|
||||
import com.ho.user.service.*;
|
||||
import com.ho.user.util.TokenSettings;
|
||||
import com.ho.user.vo.req.RoleAddReqVO;
|
||||
import com.ho.user.vo.req.RolePageReqVO;
|
||||
import com.ho.user.vo.req.RolePermissionOperationReqVO;
|
||||
import com.ho.user.vo.req.RoleUpdateReqVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class RoleServiceImpl implements RoleService {
|
||||
|
||||
@Autowired
|
||||
private SysRoleMapper sysRoleMapper;
|
||||
|
||||
@Autowired
|
||||
private UserRoleService userRoleService;
|
||||
@Autowired
|
||||
private RolePermissionService rolePermissionService;
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
@Autowired
|
||||
private RedisUpdateService redisUpdateService;
|
||||
@Autowired
|
||||
private TokenSettings tokenSettings;
|
||||
@Autowired
|
||||
private SysUserRoleMapper sysUserRoleMapper;
|
||||
@Autowired
|
||||
private PermissionService permissionService;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private Snowflake snowflake;
|
||||
|
||||
@Autowired
|
||||
private IdControlService idControlService;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public SysRole addRole(RoleAddReqVO vo) {
|
||||
//相同角色名不能相同
|
||||
RolePageReqVO query = new RolePageReqVO();
|
||||
query.setRoleName(vo.getName());
|
||||
List<SysRole> sysRoles = sysRoleMapper.selectListByCondition(query);
|
||||
if (!sysRoles.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.ROLE_NAME_ALREADY_EXITS);
|
||||
}
|
||||
SysRole sysRole = new SysRole();
|
||||
BeanUtils.copyProperties(vo, sysRole);
|
||||
//生成一个随机的角色编号
|
||||
IdControl idControl = idControlService.selectCurrentVal(CommonConstant.ROLE_KEY);
|
||||
IdControl control = null;
|
||||
Integer currentVal = null;
|
||||
if (idControl == null) {
|
||||
control = new IdControl();
|
||||
control.setType(CommonConstant.ROLE_KEY);
|
||||
control.setCurrentVal(0);
|
||||
Integer insert = idControlService.insert(control);
|
||||
currentVal = control.getCurrentVal();
|
||||
} else {
|
||||
currentVal = idControl.getCurrentVal();
|
||||
}
|
||||
Integer result = ++currentVal;
|
||||
String roleCode = CodeUtil.getCode(CodeUtil.AUTO_ROLE_PREFIX, String.valueOf(result), 6, "0");
|
||||
sysRole.setCode(roleCode);
|
||||
|
||||
sysRole.setCreateTime(new Date());
|
||||
int count = sysRoleMapper.insertSelective(sysRole);
|
||||
if (count != 1) {
|
||||
throw new BusinessException(BaseResponseCode.OPERATION_ERRO);
|
||||
}
|
||||
idControlService.updateCurrentVal(CommonConstant.ROLE_KEY, currentVal);
|
||||
//根菜单(permission中pid为0的)
|
||||
//List<SysPermission> permissionByTop = permissionService.getPermissionByTop();
|
||||
//List<Integer> permissions = vo.getPermissions();
|
||||
//permissionByTop.stream().forEach(p -> permissions.add(p.getId()));/
|
||||
if (null != vo.getPermissions() && !vo.getPermissions().isEmpty()) {
|
||||
RolePermissionOperationReqVO reqVO = new RolePermissionOperationReqVO();
|
||||
reqVO.setRoleId(sysRole.getId());
|
||||
reqVO.setPermissionIds(vo.getPermissions());
|
||||
rolePermissionService.addRolePermission(reqVO);
|
||||
}
|
||||
|
||||
return sysRole;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void updateRole(RoleUpdateReqVO vo) {
|
||||
//查询其他id是否有同名的
|
||||
//只有名称不为空时才判断
|
||||
if (!StringUtils.isEmpty(vo.getName())) {
|
||||
List<SysRole> roleExitsList = sysRoleMapper.selectOthers(vo);
|
||||
if (!roleExitsList.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.ROLE_NAME_ALREADY_EXITS);
|
||||
}
|
||||
}
|
||||
SysRole sysRole = sysRoleMapper.selectByPrimaryKey(vo.getId());
|
||||
if (null == sysRole) {
|
||||
log.error("传入 的 id:{}不合法", vo.getId());
|
||||
throw new BusinessException(BaseResponseCode.DATA_ERROR);
|
||||
}
|
||||
if (!sysRole.getStatus().equals(vo.getStatus()) && CommonConstant.STATUS.equals(vo.getStatus())) {
|
||||
//禁用角色时要先判断角色是否被使用
|
||||
List<Integer> roleIds = new ArrayList<>();
|
||||
roleIds.add(vo.getId());
|
||||
List<String> userIdsByRoleIds = userRoleService.getUserIdsByRoleIds(roleIds);
|
||||
if (!userIdsByRoleIds.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.ROLE_ALREADY_USED);
|
||||
}
|
||||
}
|
||||
//查看角色是否有人使用
|
||||
SysRole update = new SysRole();
|
||||
BeanUtils.copyProperties(vo, update);
|
||||
update.setUpdateTime(new Date());
|
||||
int count = sysRoleMapper.updateByPrimaryKeySelective(update);
|
||||
if (count != 1) {
|
||||
throw new BusinessException(BaseResponseCode.OPERATION_ERRO);
|
||||
}
|
||||
// rolePermissionService.removeByRoleId(sysRole.getId());
|
||||
QueryPermissionReqVo query = new QueryPermissionReqVo();
|
||||
//拿到当前登录人的可以修改角色时下的菜单
|
||||
List<SysPermission> list = permissionService.selectAll(query,null, "enableType");
|
||||
//查询修改前的角色拥有的菜单id
|
||||
List<Integer> permissionIdsByRoleId = rolePermissionService.getPermissionIdsByRoleId(vo.getId());
|
||||
Map<Integer, Integer> permissionIdMap = permissionIdsByRoleId.stream()
|
||||
.collect(Collectors.toMap(Integer->Integer, Integer->Integer));
|
||||
|
||||
//拿到前端送过来的需要更改的菜单,进行增加或删除
|
||||
if (null != vo.getPermissions() && !vo.getPermissions().isEmpty()) {
|
||||
Map<Integer, Integer> voPermissionIdMap = vo.getPermissions().stream()
|
||||
.collect(Collectors.toMap(Integer->Integer, Integer->Integer));
|
||||
//用户传的和本身所拥有的进行对比,对比出未选择的,如果未选择的数据存在permissionIdsByRoleId中,则进行删除
|
||||
List<Integer> notChooseList =new ArrayList<>();
|
||||
for (SysPermission sysPermission : list) {
|
||||
if(!voPermissionIdMap.containsKey(sysPermission.getId())){
|
||||
notChooseList.add(sysPermission.getId());
|
||||
}
|
||||
}
|
||||
//如果两个list都存在,则无需做增删
|
||||
//如果原本存在,更新后不存在,则进行删除
|
||||
List<Integer> deletePermissionIds = new ArrayList<>();
|
||||
for (Integer permissionId : notChooseList) {
|
||||
if(!voPermissionIdMap.containsValue(permissionId)){
|
||||
deletePermissionIds.add(permissionId);
|
||||
}
|
||||
}
|
||||
//如果原本不存在,更新后存在,则进行增加
|
||||
List<Integer> addPermissionIds = new ArrayList<>();
|
||||
for (Integer permission : vo.getPermissions()) {
|
||||
if(!permissionIdMap.containsValue(permission)){
|
||||
addPermissionIds.add(permission);
|
||||
}
|
||||
}
|
||||
RolePermissionOperationReqVO reqVO = new RolePermissionOperationReqVO();
|
||||
reqVO.setRoleId(sysRole.getId());
|
||||
if (null != addPermissionIds && !addPermissionIds.isEmpty()) {
|
||||
//进行增加
|
||||
reqVO.setPermissionIds(addPermissionIds);
|
||||
rolePermissionService.addRolePermissions(reqVO);
|
||||
}
|
||||
if (null != deletePermissionIds && !deletePermissionIds.isEmpty()) {
|
||||
//进行删除
|
||||
reqVO.setPermissionIds(deletePermissionIds);
|
||||
rolePermissionService.deleteRolePermissions(reqVO);
|
||||
}
|
||||
|
||||
|
||||
/* RolePermissionOperationReqVO reqVO = new RolePermissionOperationReqVO();
|
||||
reqVO.setRoleId(sysRole.getId());
|
||||
List<Integer> permissions = vo.getPermissions();
|
||||
//根菜单的那条数据不能删除(permission中 pid为0的不能删除)
|
||||
//List<SysPermission> permissionByTop = permissionService.getPermissionByTop();
|
||||
//permissionByTop.stream().forEach(p -> permissions.add(p.getId()));
|
||||
reqVO.setPermissionIds(vo.getPermissions());
|
||||
rolePermissionService.addRolePermission(reqVO);*/
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysRole detailInfo(Integer id, String enableStatus) {
|
||||
SysRole sysRole = sysRoleMapper.selectByPrimaryKey(id);
|
||||
if (sysRole == null) {
|
||||
log.error("传入 的 id:{}不合法", id);
|
||||
throw new BusinessException(BaseResponseCode.DATA_ERROR);
|
||||
}
|
||||
//前端并没有用到permissionRespNodes,而是根据 /permission/tree/all 接口的全量数据, 再匹配这个接口的permissions集合进行选中匹配
|
||||
//所以各个集团的管理员,应该控制 /permission/tree/all这个接口的返回
|
||||
QueryPermissionReqVo query = new QueryPermissionReqVo();
|
||||
List<PermissionRespNode> permissionRespNodes = permissionService.selectAllByTree(query, enableStatus, null);
|
||||
List<Integer> permissionIds = rolePermissionService.getPermissionIdsByRoleId(sysRole.getId());
|
||||
Set<Integer> checkList = new HashSet<>(permissionIds);
|
||||
setheckced(permissionRespNodes, checkList);
|
||||
//sysRole.setPermissionRespNodes(permissionRespNodes);
|
||||
sysRole.setPermissions(permissionIds);
|
||||
|
||||
return sysRole;
|
||||
}
|
||||
|
||||
|
||||
private void setheckced(List<PermissionRespNode> list, Set<Integer> checkList) {
|
||||
|
||||
for (PermissionRespNode node : list) {
|
||||
|
||||
if (checkList.contains(node.getId()) && (node.getChildren() == null || node.getChildren().isEmpty())) {
|
||||
node.setChecked(true);
|
||||
}
|
||||
setheckced((List<PermissionRespNode>) node.getChildren(), checkList);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void deletedRole(Integer id) {
|
||||
//超级管理员不能删除
|
||||
SysRole sysRoleRecord = sysRoleMapper.selectByPrimaryKey(id);
|
||||
if (sysRoleRecord == null) {
|
||||
throw new BusinessException(BaseResponseCode.OPERATION_ERRO);
|
||||
}
|
||||
if (CommonConstant.SUPER_ROLE_CODE.equals(sysRoleRecord.getCode())) {
|
||||
throw new BusinessException(BaseResponseCode.SUPER_CANOT_DELETE);
|
||||
}
|
||||
//角色状态为启用状态不能删除
|
||||
if (CommonConstant.STATUS_FLAG .equals(sysRoleRecord.getStatus())) {
|
||||
throw new BusinessException(BaseResponseCode.ROLE_ENABLED_NOT_DELETED);
|
||||
}
|
||||
//系统内置角色不能操作
|
||||
if (sysRoleRecord.getCode().startsWith(CommonConstant.SYS_INNER_ROLE_PREFIX)) {
|
||||
throw new BusinessException(BaseResponseCode.INNER_ROLE_CANNOT_MODIFY);
|
||||
}
|
||||
SysRole sysRole = new SysRole();
|
||||
sysRole.setId(id);
|
||||
sysRole.setUpdateTime(new Date());
|
||||
sysRole.setDeleted(0);
|
||||
int count = sysRoleMapper.updateByPrimaryKeySelective(sysRole);
|
||||
if (count != 1) {
|
||||
throw new BusinessException(BaseResponseCode.OPERATION_ERRO);
|
||||
}
|
||||
List<String> userIds = sysUserRoleMapper.getInfoByUserIdByRoleId(id);
|
||||
rolePermissionService.removeByRoleId(id);
|
||||
userRoleService.removeByRoleId(id);
|
||||
|
||||
}
|
||||
|
||||
//清除角色所关联的
|
||||
|
||||
@Override
|
||||
public PageVO<SysRole> pageInfo(RolePageReqVO vo) {
|
||||
PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
|
||||
List<SysRole> sysRoles = sysRoleMapper.selectAll(vo);
|
||||
return PageUtilsOld.getPageVO(sysRoles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRole> listInfo(RolePageReqVO vo) {
|
||||
vo.setStatus(1);
|
||||
List<SysRole> sysRoles = sysRoleMapper.selectAll(vo);
|
||||
return sysRoles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRole> getRoleInfoByUserId(String userId) {
|
||||
|
||||
List<Integer> roleIds = userRoleService.getRoleIdsByUserId(userId);
|
||||
if (roleIds.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return sysRoleMapper.getRoleInfoByIds(roleIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRole> getRoleInfoByRoleIds(List<Integer> roleIds) {
|
||||
|
||||
return sysRoleMapper.getRoleInfoByIds(roleIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRoleNames(String userId) {
|
||||
|
||||
List<SysRole> sysRoles = getRoleInfoByUserId(userId);
|
||||
if (null == sysRoles || sysRoles.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
List<String> list = new ArrayList<>();
|
||||
for (SysRole sysRole : sysRoles) {
|
||||
list.add(sysRole.getCode());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRole> selectAllRoles() {
|
||||
|
||||
return sysRoleMapper.selectAll(new RolePageReqVO());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysRole findRoleInfoByRoleCode(String roleCode) {
|
||||
SysRole sysRole = sysRoleMapper.findByCode(roleCode);
|
||||
return sysRole;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,113 @@
|
||||
package com.ho.user.service.impl;
|
||||
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.user.api.entity.SysUser;
|
||||
import com.ho.user.api.vo.req.OrderUserSelectReqVo;
|
||||
import com.ho.user.entity.SysPosition;
|
||||
import com.ho.user.entity.SysUserPosition;
|
||||
import com.ho.user.mapper.SysPositionMapper;
|
||||
import com.ho.user.mapper.SysUserPositionMapper;
|
||||
import com.ho.user.service.UserPostService;
|
||||
import com.ho.user.vo.req.UserPostOperationReqVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: 用户岗位关联
|
||||
* @date 2022/12/6
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class UserPostServiceImpl implements UserPostService {
|
||||
|
||||
@Autowired
|
||||
SysUserPositionMapper userPositionMapper;
|
||||
|
||||
@Autowired
|
||||
SysPositionMapper positionMapper;
|
||||
|
||||
@Override
|
||||
public int removeByPostId(Integer postId) {
|
||||
int i = userPositionMapper.removeByPostId(postId);
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getPostIdsByUserId(String userId) {
|
||||
List<Integer> postIds = userPositionMapper.selectPostIdsByUserId(userId);
|
||||
return postIds;
|
||||
}
|
||||
|
||||
//新增人员岗位关联
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addUserPostInfo(UserPostOperationReqVO vo) {
|
||||
if (vo.getPostIds() == null || vo.getPostIds().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Date createTime = new Date();
|
||||
List<SysUserPosition> list = new ArrayList<>();
|
||||
for (Integer postId : vo.getPostIds()) {
|
||||
SysUserPosition sysUserPosition = new SysUserPosition();
|
||||
sysUserPosition.setCreateTime(createTime);
|
||||
sysUserPosition.setUserId(vo.getUserId());
|
||||
sysUserPosition.setPositionId(postId);
|
||||
list.add(sysUserPosition);
|
||||
}
|
||||
userPositionMapper.removeByUserId(vo.getUserId());
|
||||
int count = userPositionMapper.batchUserPosition(list);
|
||||
if (count == 0) {
|
||||
throw new BusinessException(BaseResponseCode.OPERATION_ERRO);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeByUserId(String userId) {
|
||||
int i = userPositionMapper.removeByUserId(userId);
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeByUserIds(List<String> userIds) {
|
||||
int i = userPositionMapper.removeByUserIds(userIds);
|
||||
return i;
|
||||
}
|
||||
|
||||
//暂时应该用不到
|
||||
@Override
|
||||
public List<String> getUserIdsByPostIds(List<Integer> postIds) {
|
||||
List<String> postUserIds = userPositionMapper.getUserIdsByPostIds(postIds);
|
||||
return postUserIds;
|
||||
}
|
||||
|
||||
//用户岗位列表
|
||||
@Override
|
||||
public List<SysPosition> getPostListByUserId(String userid) {
|
||||
//用户岗位ids
|
||||
List<Integer> postIds = userPositionMapper.selectPostIdsByUserId(userid);
|
||||
if (!postIds.isEmpty()) {
|
||||
List<SysPosition> sysPositions = positionMapper.selectPostListByPostIds(postIds);
|
||||
return sysPositions;
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysUser> selectUserByPostIds(OrderUserSelectReqVo vo, List<Integer> postIds) {
|
||||
List<SysUser> sysUsers = positionMapper.selectUserByPostIds(vo, postIds);
|
||||
return sysUsers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysUserPosition> getByPostIds(List<Integer> postIds) {
|
||||
return userPositionMapper.selectByPostIds(postIds);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
package com.ho.user.service.impl;
|
||||
|
||||
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.user.entity.SysUserRole;
|
||||
import com.ho.user.mapper.SysUserRoleMapper;
|
||||
import com.ho.user.service.UserRoleService;
|
||||
import com.ho.user.vo.req.UserRoleOperationReqVO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户角色关联服务类
|
||||
*/
|
||||
@Service
|
||||
public class UserRoleServiceImpl implements UserRoleService{
|
||||
|
||||
@Autowired
|
||||
private SysUserRoleMapper sysUserRoleMapper;
|
||||
|
||||
@Override
|
||||
public int removeByRoleId(Integer roleId) {
|
||||
return sysUserRoleMapper.removeByRoleId(roleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getRoleIdsByUserId(String userId) {
|
||||
return sysUserRoleMapper.getRoleIdsByUserId(userId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void addUserRoleInfo(UserRoleOperationReqVO vo) {
|
||||
if(vo.getRoleIds()==null||vo.getRoleIds().isEmpty()){
|
||||
return;
|
||||
}
|
||||
Date createTime=new Date();
|
||||
List<SysUserRole> list=new ArrayList<>();
|
||||
|
||||
for (Integer roleId:vo.getRoleIds()){
|
||||
SysUserRole sysUserRole=new SysUserRole();
|
||||
// sysUserRole.setId(snowflake.nextIdStr());
|
||||
sysUserRole.setCreateTime(createTime);
|
||||
sysUserRole.setUserId(vo.getUserId());
|
||||
sysUserRole.setRoleId(roleId);
|
||||
list.add(sysUserRole);
|
||||
}
|
||||
//将根目录的角色加进来,避免无法获取tree的根
|
||||
|
||||
sysUserRoleMapper.removeByUserId(vo.getUserId());
|
||||
int count=sysUserRoleMapper.batchUserRole(list);
|
||||
if (count==0){
|
||||
throw new BusinessException(BaseResponseCode.OPERATION_ERRO);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeByUserId(String userId) {
|
||||
|
||||
return sysUserRoleMapper.removeByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeByUserIds(List<String> userIds) {
|
||||
return sysUserRoleMapper.removeByUserIds(userIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUserIdsByRoleIds(List<Integer> roleIds) {
|
||||
|
||||
return sysUserRoleMapper.getUserIdsByRoleIds(roleIds);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,38 @@
|
||||
package com.ho.user.util;
|
||||
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* http上下文
|
||||
*
|
||||
*/
|
||||
public class HttpContextUtils {
|
||||
|
||||
public static HttpServletRequest getHttpServletRequest() {
|
||||
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
}
|
||||
/**
|
||||
* 判断是否是 ajax/app请求
|
||||
* @Author:
|
||||
* @CreateDate: 2019/11/6 14:42
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/11/6 14:42
|
||||
* @Version: 0.0.1
|
||||
* @param request
|
||||
* @return boolean
|
||||
* @throws
|
||||
*/
|
||||
public static boolean isAjaxRequest(HttpServletRequest request){
|
||||
|
||||
String accept = request.getHeader("accept");
|
||||
String xRequestedWith = request.getHeader("X-Requested-With");
|
||||
|
||||
// 如果是异步请求或是手机端,则直接返回信息
|
||||
return ((accept != null && accept.indexOf("application/json") != -1
|
||||
|| (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1)
|
||||
));
|
||||
}
|
||||
}
|
||||
306
user-service/src/main/java/com/ho/user/util/JwtTokenUtil.java
Normal file
306
user-service/src/main/java/com/ho/user/util/JwtTokenUtil.java
Normal file
@ -0,0 +1,306 @@
|
||||
package com.ho.user.util;
|
||||
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
import java.time.Duration;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: JwtTokenUtil
|
||||
* TODO:类文件简单描述
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/6 23:49
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/6 23:49
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
@Slf4j
|
||||
public class JwtTokenUtil {
|
||||
|
||||
private static String secretKey;
|
||||
private static Duration accessTokenExpireTime;
|
||||
private static Duration refreshTokenExpireTime;
|
||||
private static Duration refreshTokenExpireAppTime;
|
||||
private static String issuer;
|
||||
|
||||
public static void setTokenSettings(TokenSettings tokenSettings) {
|
||||
secretKey = tokenSettings.getSecretKey();
|
||||
accessTokenExpireTime = tokenSettings.getAccessTokenExpireTime();
|
||||
refreshTokenExpireTime = tokenSettings.getRefreshTokenExpireTime();
|
||||
refreshTokenExpireAppTime = tokenSettings.getRefreshTokenExpireAppTime();
|
||||
issuer = tokenSettings.getIssuer();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成 access_token
|
||||
*
|
||||
* @param subject
|
||||
* @param claims
|
||||
* @return java.lang.String
|
||||
* @throws
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/26 10:22
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/26 10:22
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
/* public static String getAccessToken(String subject, Map<String, Object> claims) {
|
||||
|
||||
return generateToken(issuer, subject, claims, accessTokenExpireTime.toMillis(), secretKey);
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 生产 App端 refresh_token
|
||||
*
|
||||
* @param subject
|
||||
* @param claims
|
||||
* @return java.lang.String
|
||||
* @throws
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/26 10:24
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/26 10:24
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
/* public static String getRefreshAppToken(String subject, Map<String, Object> claims) {
|
||||
return generateToken(issuer, subject, claims, refreshTokenExpireAppTime.toMillis(), secretKey);
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 生产 PC refresh_token
|
||||
*
|
||||
* @param subject
|
||||
* @param claims
|
||||
* @return java.lang.String
|
||||
* @throws
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/26 10:24
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/26 10:24
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
/*public static String getRefreshToken(String subject, Map<String, Object> claims) {
|
||||
return generateToken(issuer, subject, claims, refreshTokenExpireTime.toMillis(), secretKey);
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 签发token
|
||||
*
|
||||
* @param issuer 签发人
|
||||
* @param subject 代表这个JWT的主体,即它的所有人 一般是用户id
|
||||
* @param claims 存储在JWT里面的信息 一般放些用户的权限/角色信息
|
||||
* @param ttlMillis 有效时间(毫秒)
|
||||
* @return java.lang.String
|
||||
* @throws
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/7 20:42
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/7 20:42
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
/*public static String generateToken(String issuer, String subject, Map<String, Object> claims, long ttlMillis, String secret) {
|
||||
|
||||
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
|
||||
|
||||
long nowMillis = System.currentTimeMillis();
|
||||
Date now = new Date(nowMillis);
|
||||
|
||||
byte[] signingKey = DatatypeConverter.parseBase64Binary(secret);
|
||||
|
||||
JwtBuilder builder = Jwts.builder();
|
||||
if (null != claims) {
|
||||
builder.setClaims(claims);
|
||||
}
|
||||
if (!StringUtils.isEmpty(subject)) {
|
||||
builder.setSubject(subject);
|
||||
}
|
||||
if (!StringUtils.isEmpty(issuer)) {
|
||||
builder.setIssuer(issuer);
|
||||
}
|
||||
builder.setIssuedAt(now);
|
||||
if (ttlMillis >= 0) {
|
||||
long expMillis = nowMillis + ttlMillis;
|
||||
Date exp = new Date(expMillis);
|
||||
builder.setExpiration(exp);
|
||||
}
|
||||
builder.signWith(signatureAlgorithm, signingKey);
|
||||
return builder.compact();
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* 获取用户id
|
||||
*
|
||||
* @param token
|
||||
* @return java.lang.String
|
||||
* @throws
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/7 17:29
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/7 17:29
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
/* public static String getUserId(String token) {
|
||||
String userId = null;
|
||||
try {
|
||||
Claims claims = getClaimsFromToken(token);
|
||||
userId = claims.getSubject();
|
||||
} catch (Exception e) {
|
||||
log.error("eror={}", e);
|
||||
}
|
||||
return userId;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 获取用户名
|
||||
*
|
||||
* @param token
|
||||
* @return java.lang.String
|
||||
* @throws
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/23 15:39
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/23 15:39
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
/* public static String getUserName(String token) {
|
||||
|
||||
String username = null;
|
||||
try {
|
||||
Claims claims = getClaimsFromToken(token);
|
||||
username = (String) claims.get(RedisKeyConstant.User.TOKEN+token);
|
||||
} catch (Exception e) {
|
||||
log.error("eror={}", e);
|
||||
}
|
||||
return username;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 从令牌中获取数据声明
|
||||
*
|
||||
* @param token
|
||||
* @return io.jsonwebtoken.Claims
|
||||
* @throws
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/7 21:21
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/7 21:21
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
/* public static Claims getClaimsFromToken(String token) {
|
||||
Claims claims;
|
||||
try {
|
||||
claims = Jwts.parser().setSigningKey(DatatypeConverter.parseBase64Binary(secretKey)).parseClaimsJws(token).getBody();
|
||||
} catch (Exception e) {
|
||||
claims = null;
|
||||
}
|
||||
return claims;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 校验令牌
|
||||
*
|
||||
* @param token
|
||||
* @return java.lang.Boolean
|
||||
* @throws
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/7 22:15
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/7 22:15
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
/* public static Boolean validateToken(String token) {
|
||||
Claims claimsFromToken = getClaimsFromToken(token);
|
||||
return (null != claimsFromToken && !isTokenExpired(token));
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 验证token 是否过期
|
||||
*
|
||||
* @param token
|
||||
* @param secretKey
|
||||
* @return java.lang.Boolean
|
||||
* @throws
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/7 21:27
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/7 21:27
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
/* public static Boolean isTokenExpired(String token) {
|
||||
|
||||
try {
|
||||
Claims claims = getClaimsFromToken(token);
|
||||
Date expiration = claims.getExpiration();
|
||||
return expiration.before(new Date());
|
||||
} catch (Exception e) {
|
||||
log.error("error={}", e);
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 刷新token
|
||||
*
|
||||
* @param refreshToken
|
||||
* @param claims 主动去刷新的时候 改变JWT payload 内的信息
|
||||
* @return java.lang.String
|
||||
* @throws
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/7 22:14
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/7 22:14
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
/*public static String refreshToken(String refreshToken, Map<String, Object> claims) {
|
||||
String refreshedToken;
|
||||
try {
|
||||
Claims parserclaims = getClaimsFromToken(refreshToken);
|
||||
*//**
|
||||
* 刷新token的时候如果为空说明原先的 用户信息不变 所以就引用上个token里的内容
|
||||
*//*
|
||||
if (null == claims) {
|
||||
claims = parserclaims;
|
||||
}
|
||||
refreshedToken = generateToken(parserclaims.getIssuer(), parserclaims.getSubject(), claims, accessTokenExpireTime.toMillis(), secretKey);
|
||||
} catch (Exception e) {
|
||||
refreshedToken = null;
|
||||
log.error("error={}", e);
|
||||
}
|
||||
return refreshedToken;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 获取token的剩余过期时间
|
||||
*
|
||||
|
||||
* @return long
|
||||
* @throws
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/7 22:19
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/7 22:19
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
/* public static long getRemainingTime(String token) {
|
||||
long result = 0;
|
||||
try {
|
||||
long nowMillis = System.currentTimeMillis();
|
||||
result = getClaimsFromToken(token).getExpiration().getTime() - nowMillis;
|
||||
} catch (Exception e) {
|
||||
log.error("error={}", e);
|
||||
}
|
||||
return result;
|
||||
}*/
|
||||
|
||||
public static void main(String[] args) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
112
user-service/src/main/java/com/ho/user/util/PasswordEncoder.java
Normal file
112
user-service/src/main/java/com/ho/user/util/PasswordEncoder.java
Normal file
@ -0,0 +1,112 @@
|
||||
package com.ho.user.util;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
/**
|
||||
* @ClassName: PasswordEncoder
|
||||
* 密码加密
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/7 13:45
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/7 13:45
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
public class PasswordEncoder {
|
||||
|
||||
private final static String[] hexDigits = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d",
|
||||
"e", "f"};
|
||||
|
||||
private final static String MD5 = "MD5";
|
||||
private final static String SHA = "SHA";
|
||||
|
||||
private Object salt;
|
||||
private String algorithm;
|
||||
|
||||
public PasswordEncoder(Object salt) {
|
||||
this(salt, MD5);
|
||||
}
|
||||
|
||||
public PasswordEncoder(Object salt, String algorithm) {
|
||||
this.salt = salt;
|
||||
this.algorithm = algorithm;
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码加密
|
||||
*
|
||||
* @param rawPass
|
||||
* @return
|
||||
*/
|
||||
public String encode(String rawPass) {
|
||||
String result = null;
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance(algorithm);
|
||||
// 加密后的字符串
|
||||
result = byteArrayToHexString(md.digest(mergePasswordAndSalt(rawPass).getBytes("utf-8")));
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码匹配验证
|
||||
*
|
||||
* @param encPass 密文
|
||||
* @param rawPass 明文
|
||||
* @return
|
||||
*/
|
||||
public boolean matches(String encPass, String rawPass) {
|
||||
String pass1 = "" + encPass;
|
||||
String pass2 = encode(rawPass);
|
||||
|
||||
return pass1.equals(pass2);
|
||||
}
|
||||
|
||||
private String mergePasswordAndSalt(String password) {
|
||||
if (password == null) {
|
||||
password = "";
|
||||
}
|
||||
|
||||
if ((salt == null) || "".equals(salt)) {
|
||||
return password;
|
||||
} else {
|
||||
return password + "{" + salt.toString() + "}";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换字节数组为16进制字串
|
||||
*
|
||||
* @param b 字节数组
|
||||
* @return 16进制字串
|
||||
*/
|
||||
private String byteArrayToHexString(byte[] b) {
|
||||
StringBuffer resultSb = new StringBuffer();
|
||||
for (int i = 0; i < b.length; i++) {
|
||||
resultSb.append(byteToHexString(b[i]));
|
||||
}
|
||||
return resultSb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字节转换为16进制
|
||||
*
|
||||
* @param b
|
||||
* @return
|
||||
*/
|
||||
private static String byteToHexString(byte b) {
|
||||
int n = b;
|
||||
if (n < 0) {
|
||||
n = 256 + n;
|
||||
}
|
||||
int d1 = n / 16;
|
||||
int d2 = n % 16;
|
||||
return hexDigits[d1] + hexDigits[d2];
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package com.ho.user.util;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @ClassName: PasswordUtils
|
||||
* 密码工具类
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/7 13:44
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/7 13:44
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
public class PasswordUtils {
|
||||
|
||||
/**
|
||||
* 匹配密码
|
||||
* @param salt 盐
|
||||
* @param rawPass 明文
|
||||
* @param encPass 密文
|
||||
* @return
|
||||
*/
|
||||
public static boolean matches(String salt, String rawPass, String encPass) {
|
||||
return new PasswordEncoder(salt).matches(encPass, rawPass);
|
||||
}
|
||||
|
||||
/**
|
||||
* 明文密码加密
|
||||
* @param rawPass 明文
|
||||
* @param salt
|
||||
* @return
|
||||
*/
|
||||
public static String encode(String rawPass, String salt) {
|
||||
return new PasswordEncoder(salt).encode(rawPass);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取加密盐
|
||||
* @return
|
||||
*/
|
||||
public static String getSalt() {
|
||||
return UUID.randomUUID().toString().replaceAll("-", "").substring(0, 20);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package com.ho.user.util;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
/**
|
||||
* @ClassName: TokenSettings
|
||||
* TODO:类文件简单描述
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/7 20:46
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/7 20:46
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "jwt")
|
||||
@Data
|
||||
public class TokenSettings {
|
||||
private String secretKey;
|
||||
private Duration accessTokenExpireTime;
|
||||
private Duration refreshTokenExpireTime;
|
||||
private Duration refreshTokenExpireAppTime;
|
||||
private String issuer;
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
package com.ho.user.vo.req;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* @ClassName: DeptAddReqVO
|
||||
* TODO:类文件简单描述
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/19 13:30
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/19 13:30
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
@Data
|
||||
public class DeptAddReqVO {
|
||||
@ApiModelProperty(value = "机构名称")
|
||||
@NotBlank(message = "机构名称不能为空")
|
||||
@Length(min = 1, max = 50,message = "名称不能超过50个字符")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "父级id 一级为 0")
|
||||
private Integer pid;
|
||||
|
||||
@ApiModelProperty(value = "部门经理id")
|
||||
private String deptManagerId;
|
||||
|
||||
@ApiModelProperty(value = "部门经理名称 ---负责人")
|
||||
private String managerName;
|
||||
|
||||
@ApiModelProperty(value = "部门经理电话 ---联系电话")
|
||||
//@Pattern(regexp = "^[1][3,4,5,6,7,8,9][0-9]{9}$", message = "手机号格式有误")
|
||||
private String phone;
|
||||
|
||||
@ApiModelProperty(value = "机构状态(1:正常;0:弃用)")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "邮箱")
|
||||
@Email(message = "邮箱格式有误")
|
||||
private String email;
|
||||
|
||||
@ApiModelProperty(value = "排序码")
|
||||
// @NotNull(message = "排序码不能为空")
|
||||
private Integer orderNum;
|
||||
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package com.ho.user.vo.req;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @ClassName: DeptPageReqVO
|
||||
* TODO:类文件简单描述
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/19 15:27
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/19 15:27
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
@Data
|
||||
public class DeptPageReqVO {
|
||||
@ApiModelProperty(value = "第几页")
|
||||
private int pageNum=1;
|
||||
|
||||
@ApiModelProperty(value = "分页数量")
|
||||
private int pageSize=10;
|
||||
}
|
||||
28
user-service/src/main/java/com/ho/user/vo/req/DeptQuery.java
Normal file
28
user-service/src/main/java/com/ho/user/vo/req/DeptQuery.java
Normal file
@ -0,0 +1,28 @@
|
||||
package com.ho.user.vo.req;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: TODO
|
||||
* @DateTime: 2023/1/3 18:00
|
||||
*/
|
||||
@Data
|
||||
public class DeptQuery {
|
||||
|
||||
@ApiModelProperty(value = "名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "机构状态(1:正常;0:弃用)")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "deptId")
|
||||
@ApiParam
|
||||
private Integer deptId;
|
||||
|
||||
@ApiModelProperty(value = "deptId" ,hidden = true)
|
||||
private Integer groupId;
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
package com.ho.user.vo.req;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @ClassName: DeptUpdateReqVO
|
||||
* 更新 组织
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/19 14:04
|
||||
* @UpdateUser:
|
||||
* @UpdateDate: 2019/9/19 14:04
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
@Data
|
||||
public class DeptUpdateReqVO {
|
||||
|
||||
@ApiModelProperty(value = "机构id")
|
||||
@NotNull(message = "机构id不能为空")
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "机构名称")
|
||||
@NotBlank(message = "机构名称不能为空")
|
||||
@Length(min = 1, max = 50,message = "名称不能超过50个字符")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "父级id")
|
||||
private Integer pid;
|
||||
|
||||
@ApiModelProperty(value = "机构状态(1:正常;0:弃用)")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "部门经理id")
|
||||
private String deptManagerId;
|
||||
|
||||
@ApiModelProperty(value = "部门经理名称 ---负责人")
|
||||
private String managerName;
|
||||
|
||||
@ApiModelProperty(value = "部门经理电话 ---联系电话")
|
||||
// @Pattern(regexp = "^[1][3,4,5,6,7,8,9][0-9]{9}$", message = "手机号格式有误")
|
||||
private String phone;
|
||||
|
||||
@ApiModelProperty(value = "排序码")
|
||||
// @NotNull(message = "排序码不能为空")
|
||||
private Integer orderNum;
|
||||
|
||||
@ApiModelProperty(value = "邮箱")
|
||||
@Email(message = "邮箱格式有误")
|
||||
private String email;
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
package com.ho.user.vo.req;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
import org.hibernate.validator.constraints.Range;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* @ClassName: DictAddReqVO
|
||||
*新增字典入参
|
||||
* @Author:
|
||||
* @CreateDate: 2019/9/19 13:30
|
||||
* @Version: 0.0.1
|
||||
*/
|
||||
@ToString
|
||||
@Getter
|
||||
@Setter
|
||||
public class DictAddReqVO {
|
||||
|
||||
@ApiModelProperty(value = "参数类型")
|
||||
@NotBlank(message = "参数类型不能为空")
|
||||
@Length(max = 50,message = "类型不能超过50个字符")
|
||||
private String type;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "标签名称")
|
||||
@NotBlank(message = "标签名称不能为空")
|
||||
@Length(max = 50,message = "标签不能超过50个字符")
|
||||
private String label;
|
||||
|
||||
@ApiModelProperty(value = "标签值")
|
||||
@NotBlank(message = "标签值不能为空")
|
||||
@Length(max = 50,message = "标签值不能超过50个字符")
|
||||
private String value;
|
||||
|
||||
@ApiModelProperty(value = "排序")
|
||||
@Max(value =100000,message = "排序字码过大")
|
||||
private Long sort;
|
||||
|
||||
@ApiModelProperty(value = "描述")
|
||||
@Length( max = 200,message = "描述不能超过200个字符")
|
||||
private String desc;
|
||||
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package com.ho.user.vo.req;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* @Description 添加类型
|
||||
* Author yule
|
||||
* Date 2022/8/23 15:25
|
||||
*/
|
||||
@ToString
|
||||
@Getter
|
||||
@Setter
|
||||
public class DictAddTypeVO {
|
||||
|
||||
@ApiModelProperty(value = "参数类型")
|
||||
@NotBlank(message = "参数类型不能为空")
|
||||
@Length(max = 50,message = "类型不能超过50个字符")
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty(value = "参数类型名称")
|
||||
@NotBlank(message = "参数类型名称不能为空")
|
||||
@Length(max = 50,message = "描述不能超过50个字符")
|
||||
private String typeName;
|
||||
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
package com.ho.user.vo.req;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Description 查询Dcit
|
||||
* Author yule
|
||||
* Date 2022/8/22 15:30
|
||||
*/
|
||||
@Data
|
||||
public class DictPageReqVO {
|
||||
@ApiModelProperty(value = "第几页")
|
||||
private int pageNum=1;
|
||||
|
||||
@ApiModelProperty(value = "分页数量")
|
||||
private int pageSize=10;
|
||||
|
||||
@ApiModelProperty(value = "类型")
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty(value = "类型名称")
|
||||
private String typeName;
|
||||
|
||||
@ApiModelProperty(value = "标签")
|
||||
private String label;
|
||||
|
||||
@ApiModelProperty(value = "标签值")
|
||||
private String value;
|
||||
|
||||
@ApiModelProperty(value = "排序")
|
||||
private int sort;
|
||||
|
||||
@ApiModelProperty(value = "描述")
|
||||
private String desc;
|
||||
|
||||
@ApiModelProperty(value = "开始时间")
|
||||
private String startTime;
|
||||
|
||||
@ApiModelProperty(value = "结束时间")
|
||||
private String endTime;
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user