[Fix]同步

This commit is contained in:
xiezubing1
2021-11-08 17:09:14 +08:00
parent bbbe83b737
commit 41b81f0682
18 changed files with 369 additions and 349 deletions

View File

@ -29,7 +29,7 @@ import com.ruoyi.system.domain.SysOperLog;
/**
* 操作日志记录处理
*
*
* @author ruoyi
*/
@Aspect
@ -51,7 +51,7 @@ public class LogAspect
/**
* 拦截异常操作
*
*
* @param joinPoint 切点
* @param e 异常
*/
@ -108,7 +108,7 @@ public class LogAspect
/**
* 获取注解中对方法的描述信息 用于Controller层注解
*
*
* @param log 日志
* @param operLog 操作日志
* @throws Exception
@ -136,7 +136,7 @@ public class LogAspect
/**
* 获取请求的参数放到log中
*
*
* @param operLog 操作日志
* @throws Exception 异常
*/
@ -183,7 +183,7 @@ public class LogAspect
/**
* 判断是否需要过滤的对象。
*
*
* @param o 对象信息。
* @return 如果是需要过滤的对象则返回true否则返回false。
*/

View File

@ -1,132 +1,114 @@
package com.ruoyi.framework.config;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import javax.sql.DataSource;
import org.apache.ibatis.io.VFS;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.boot.autoconfigure.SpringBootVFS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.util.ClassUtils;
import com.ruoyi.common.utils.StringUtils;
/**
* Mybatis支持*匹配扫描包
*
* @author ruoyi
*/
@Configuration
public class MyBatisConfig
{
@Autowired
private Environment env;
static final String DEFAULT_RESOURCE_PATTERN = "**/*.class";
public static String setTypeAliasesPackage(String typeAliasesPackage)
{
ResourcePatternResolver resolver = (ResourcePatternResolver) new PathMatchingResourcePatternResolver();
MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
List<String> allResult = new ArrayList<String>();
try
{
for (String aliasesPackage : typeAliasesPackage.split(","))
{
List<String> result = new ArrayList<String>();
aliasesPackage = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
+ ClassUtils.convertClassNameToResourcePath(aliasesPackage.trim()) + "/" + DEFAULT_RESOURCE_PATTERN;
Resource[] resources = resolver.getResources(aliasesPackage);
if (resources != null && resources.length > 0)
{
MetadataReader metadataReader = null;
for (Resource resource : resources)
{
if (resource.isReadable())
{
metadataReader = metadataReaderFactory.getMetadataReader(resource);
try
{
result.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage().getName());
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
}
}
}
if (result.size() > 0)
{
HashSet<String> hashResult = new HashSet<String>(result);
allResult.addAll(hashResult);
}
}
if (allResult.size() > 0)
{
typeAliasesPackage = String.join(",", (String[]) allResult.toArray(new String[0]));
}
else
{
throw new RuntimeException("mybatis typeAliasesPackage 路径扫描错误,参数typeAliasesPackage:" + typeAliasesPackage + "未找到任何包");
}
}
catch (IOException e)
{
e.printStackTrace();
}
return typeAliasesPackage;
}
public Resource[] resolveMapperLocations(String[] mapperLocations)
{
ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
List<Resource> resources = new ArrayList<Resource>();
if (mapperLocations != null)
{
for (String mapperLocation : mapperLocations)
{
try
{
Resource[] mappers = resourceResolver.getResources(mapperLocation);
resources.addAll(Arrays.asList(mappers));
}
catch (IOException e)
{
// ignore
}
}
}
return resources.toArray(new Resource[resources.size()]);
}
@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception
{
String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage");
String mapperLocations = env.getProperty("mybatis.mapperLocations");
String configLocation = env.getProperty("mybatis.configLocation");
typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage);
VFS.addImplClass(SpringBootVFS.class);
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource);
sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ",")));
sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));
return sessionFactory.getObject();
}
}
//package com.ruoyi.framework.config;
//
//import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
//import com.ruoyi.common.utils.StringUtils;
//import org.apache.ibatis.io.VFS;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.boot.autoconfigure.SpringBootVFS;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.env.Environment;
//import org.springframework.core.io.DefaultResourceLoader;
//import org.springframework.core.io.Resource;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.core.io.support.ResourcePatternResolver;
//import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
//import org.springframework.core.type.classreading.MetadataReader;
//import org.springframework.core.type.classreading.MetadataReaderFactory;
//import org.springframework.util.ClassUtils;
//
//import javax.sql.DataSource;
//import java.io.IOException;
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.HashSet;
//import java.util.List;
//
///**
// * Mybatis支持*匹配扫描包
// *
// * @author ruoyi
// */
//@Configuration
//public class MyBatisConfig {
// @Autowired
// private Environment env;
//
// static final String DEFAULT_RESOURCE_PATTERN = "**/*.class";
//
// public static String setTypeAliasesPackage(String typeAliasesPackage) {
// ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
// MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
// List<String> allResult = new ArrayList<>();
// try {
// for (String aliasesPackage : typeAliasesPackage.split(",")) {
// List<String> result = new ArrayList<>();
// aliasesPackage = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
// + ClassUtils.convertClassNameToResourcePath(aliasesPackage.trim()) + "/" + DEFAULT_RESOURCE_PATTERN;
// Resource[] resources = resolver.getResources(aliasesPackage);
// if (resources != null && resources.length > 0) {
// MetadataReader metadataReader = null;
// for (Resource resource : resources) {
// if (resource.isReadable()) {
// metadataReader = metadataReaderFactory.getMetadataReader(resource);
// try {
// result.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage().getName());
// } catch (ClassNotFoundException e) {
// e.printStackTrace();
// }
// }
// }
// }
// if (result.size() > 0) {
// HashSet<String> hashResult = new HashSet<>(result);
// allResult.addAll(hashResult);
// }
// }
// if (allResult.size() > 0) {
// typeAliasesPackage = String.join(",", (String[]) allResult.toArray(new String[0]));
// } else {
// throw new RuntimeException("mybatis typeAliasesPackage 路径扫描错误,参数typeAliasesPackage:" + typeAliasesPackage + "未找到任何包");
// }
// } catch (IOException e) {
// e.printStackTrace();
// }
// return typeAliasesPackage;
// }
//
// public Resource[] resolveMapperLocations(String[] mapperLocations) {
// ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
// List<Resource> resources = new ArrayList<>();
// if (mapperLocations != null) {
// for (String mapperLocation : mapperLocations) {
// try {
// Resource[] mappers = resourceResolver.getResources(mapperLocation);
// resources.addAll(Arrays.asList(mappers));
// } catch (IOException e) {
// // ignore
// }
// }
// }
// return resources.toArray(new Resource[resources.size()]);
// }
//
// @Bean
// public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception
// {
// String typeAliasesPackage = env.getProperty("mybatis-plus.type-aliases-package");
// String mapperLocations = env.getProperty("mybatis-plus.mapper-locations");
// String configLocation = env.getProperty("mybatis.configLocation");
// typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage);
// VFS.addImplClass(SpringBootVFS.class);
//
// // final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
// MybatisSqlSessionFactoryBean sessionFactory=new MybatisSqlSessionFactoryBean();
// sessionFactory.setDataSource(dataSource);
// sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
// sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ",")));
// sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));
// //如果有enum也需要在第二步return之前加入,直接配置是没用的
// //sessionFactory.setTypeEnumsPackage("com.ruoyi.**.enums");
// return sessionFactory.getObject();
// }
//}

View File

@ -10,7 +10,7 @@ import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.core.redis.RedisUtils;
import com.ruoyi.common.filter.RepeatedlyRequestWrapper;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpHelper;
@ -19,7 +19,7 @@ import com.ruoyi.framework.interceptor.RepeatSubmitInterceptor;
/**
* 判断请求url和数据是否和上一次相同
* 如果和上次相同,则是重复提交表单。 有效时间为10秒内。
*
*
* @author ruoyi
*/
@Component
@ -34,7 +34,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
private String header;
@Autowired
private RedisCache redisCache;
private RedisUtils redisUtils;
@SuppressWarnings("unchecked")
@Override
@ -69,7 +69,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
// 唯一标识指定key + 消息头)
String cacheRepeatKey = Constants.REPEAT_SUBMIT_KEY + submitKey;
Object sessionObj = redisCache.getCacheObject(cacheRepeatKey);
Object sessionObj = redisUtils.getCacheObject(cacheRepeatKey);
if (sessionObj != null)
{
Map<String, Object> sessionMap = (Map<String, Object>) sessionObj;
@ -84,7 +84,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
}
Map<String, Object> cacheMap = new HashMap<String, Object>();
cacheMap.put(url, nowDataMap);
redisCache.setCacheObject(cacheRepeatKey, cacheMap, annotation.interval(), TimeUnit.MILLISECONDS);
redisUtils.setCacheObject(cacheRepeatKey, cacheMap, annotation.interval(), TimeUnit.MILLISECONDS);
return false;
}

View File

@ -10,7 +10,7 @@ import org.springframework.stereotype.Component;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.core.redis.RedisUtils;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.exception.user.CaptchaException;
import com.ruoyi.common.exception.user.CaptchaExpireException;
@ -26,7 +26,7 @@ import com.ruoyi.system.service.ISysUserService;
/**
* 登录校验方法
*
*
* @author ruoyi
*/
@Component
@ -39,8 +39,8 @@ public class SysLoginService
private AuthenticationManager authenticationManager;
@Autowired
private RedisCache redisCache;
private RedisUtils redisUtils;
@Autowired
private ISysUserService userService;
@ -49,7 +49,7 @@ public class SysLoginService
/**
* 登录验证
*
*
* @param username 用户名
* @param password 密码
* @param code 验证码
@ -94,7 +94,7 @@ public class SysLoginService
/**
* 校验验证码
*
*
* @param username 用户名
* @param code 验证码
* @param uuid 唯一标识
@ -103,8 +103,8 @@ public class SysLoginService
public void validateCaptcha(String username, String code, String uuid)
{
String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
String captcha = redisCache.getCacheObject(verifyKey);
redisCache.deleteObject(verifyKey);
String captcha = redisUtils.getCacheObject(verifyKey);
redisUtils.deleteObject(verifyKey);
if (captcha == null)
{
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire")));

View File

@ -6,7 +6,7 @@ import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.RegisterBody;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.core.redis.RedisUtils;
import com.ruoyi.common.exception.user.CaptchaException;
import com.ruoyi.common.exception.user.CaptchaExpireException;
import com.ruoyi.common.utils.MessageUtils;
@ -19,7 +19,7 @@ import com.ruoyi.system.service.ISysUserService;
/**
* 注册校验方法
*
*
* @author ruoyi
*/
@Component
@ -32,7 +32,7 @@ public class SysRegisterService
private ISysConfigService configService;
@Autowired
private RedisCache redisCache;
private RedisUtils redisUtils;
/**
* 注册
@ -92,7 +92,7 @@ public class SysRegisterService
/**
* 校验验证码
*
*
* @param username 用户名
* @param code 验证码
* @param uuid 唯一标识
@ -101,8 +101,8 @@ public class SysRegisterService
public void validateCaptcha(String username, String code, String uuid)
{
String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
String captcha = redisCache.getCacheObject(verifyKey);
redisCache.deleteObject(verifyKey);
String captcha = redisUtils.getCacheObject(verifyKey);
redisUtils.deleteObject(verifyKey);
if (captcha == null)
{
throw new CaptchaExpireException();

View File

@ -9,7 +9,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.core.redis.RedisUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.ip.AddressUtils;
@ -47,7 +47,7 @@ public class TokenService
private static final Long MILLIS_MINUTE_TEN = 20 * 60 * 1000L;
@Autowired
private RedisCache redisCache;
private RedisUtils redisUtils;
/**
* 获取用户身份信息
@ -66,7 +66,7 @@ public class TokenService
// 解析对应的权限以及用户信息
String uuid = (String) claims.get(Constants.LOGIN_USER_KEY);
String userKey = getTokenKey(uuid);
LoginUser user = redisCache.getCacheObject(userKey);
LoginUser user = redisUtils.getCacheObject(userKey);
return user;
}
catch (Exception e)
@ -95,7 +95,7 @@ public class TokenService
if (StringUtils.isNotEmpty(token))
{
String userKey = getTokenKey(token);
redisCache.deleteObject(userKey);
redisUtils.deleteObject(userKey);
}
}
@ -144,7 +144,7 @@ public class TokenService
loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE);
// 根据uuid将loginUser缓存
String userKey = getTokenKey(loginUser.getToken());
redisCache.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES);
redisUtils.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES);
}
/**