初始化
commit
9b342f76c4
|
@ -0,0 +1,8 @@
|
||||||
|
# 默认忽略的文件
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# 基于编辑器的 HTTP 客户端请求
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile name="Maven default annotation processors profile" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<module name="bawei-common-cache" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="PROJECT" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="MavenRunner">
|
||||||
|
<option name="delegateBuildToMaven" value="true" />
|
||||||
|
<option name="jreName" value="1.8" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK" />
|
||||||
|
</project>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>bawei-common</artifactId>
|
||||||
|
<groupId>com.bawei</groupId>
|
||||||
|
<version>3.6.0</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>bawei-common-cache</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- 项目redis缓存 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.bawei</groupId>
|
||||||
|
<artifactId>bawei-common-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,61 @@
|
||||||
|
package com.bawei.cache;
|
||||||
|
|
||||||
|
import com.bawei.common.core.utils.thread.ThreadPool;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 缓存基准
|
||||||
|
* @Date 2022-10-18 下午 02:57
|
||||||
|
*/
|
||||||
|
public interface BaseCache<K, V> {
|
||||||
|
|
||||||
|
public static final long time = 2;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public ThreadPool threadPool = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Redis的key 用来 对缓存进行操作
|
||||||
|
* @param key 数据Id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getKey(K key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增/改
|
||||||
|
* @param key 键
|
||||||
|
* @param val 值
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean put(K key, V val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删
|
||||||
|
* @param key 键
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean remove(K key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 延迟删
|
||||||
|
* @param key 键
|
||||||
|
*/
|
||||||
|
public default void delayRemove(K key){
|
||||||
|
ThreadPool.getThreadPool().delayExecute(time, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run () {
|
||||||
|
remove(key);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查
|
||||||
|
* @param key 键
|
||||||
|
* @return val 值
|
||||||
|
*/
|
||||||
|
public V get(K key);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.bawei.cache.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 缓存权限
|
||||||
|
* @Date 2022-10-19 上午 08:34
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ ElementType.METHOD, ElementType.TYPE })
|
||||||
|
public @interface CacheRole {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许操作缓存的微服务
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String serverName() ;
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
package com.bawei.cache.aspect;
|
||||||
|
|
||||||
|
import com.bawei.cache.annotation.CacheRole;
|
||||||
|
import com.bawei.common.core.exception.ServiceException;
|
||||||
|
import com.bawei.common.core.utils.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.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 缓存操作权限切面
|
||||||
|
* @Date 2022-10-19 上午 08:36
|
||||||
|
*/
|
||||||
|
@Aspect
|
||||||
|
@Component
|
||||||
|
public class CacheRuleAsp {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前服务的名称
|
||||||
|
*/
|
||||||
|
@Value("${spring.application.name}")
|
||||||
|
private String applicationName;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定义AOP签名 (切入所有使用鉴权注解的方法)
|
||||||
|
*/
|
||||||
|
public static final String POINTCUT_SIGN = "@annotation(com.bawei.cache.annotation.CacheRole)";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 声明AOP切点
|
||||||
|
*/
|
||||||
|
@Pointcut(POINTCUT_SIGN)
|
||||||
|
public void pointcut()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 环绕切入
|
||||||
|
*
|
||||||
|
* @param joinPoint 切面对象
|
||||||
|
* @return 底层方法执行后的返回值
|
||||||
|
* @throws Throwable 底层方法抛出的异常
|
||||||
|
*/
|
||||||
|
@Around("pointcut()")
|
||||||
|
public Object around(ProceedingJoinPoint joinPoint) throws Throwable{
|
||||||
|
// 注解鉴权
|
||||||
|
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||||
|
// 获取注解的方法
|
||||||
|
Method method = signature.getMethod();
|
||||||
|
// 获取方法上面的注解
|
||||||
|
CacheRole cacheRole = method.getAnnotation(CacheRole.class);
|
||||||
|
if (cacheRole != null){
|
||||||
|
// 判断当前微服务是否要操作权限
|
||||||
|
if (!cacheRole.serverName().equals(applicationName)){
|
||||||
|
throw new ServiceException(StringUtils.format("当前服务[{}],无权限操作服务[{}]的缓存",
|
||||||
|
applicationName,
|
||||||
|
cacheRole.serverName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return joinPoint.proceed();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.bawei.cache.db;
|
||||||
|
|
||||||
|
import com.bawei.cache.BaseCache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 数据库缓存基类
|
||||||
|
* @Date 2022-10-18 下午 03:05
|
||||||
|
*/
|
||||||
|
public interface BaseDatabaseCache<K,V> extends BaseCache<K,V> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过ID获取数据库内数据
|
||||||
|
* @param key 数据ID
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public V getData(K key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基于Key进行刷新
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean refreshData(K key);
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
com.bawei.cache.aspect.CacheRuleAsp
|
Binary file not shown.
|
@ -0,0 +1 @@
|
||||||
|
com.bawei.cache.aspect.CacheRuleAsp
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,5 @@
|
||||||
|
#Generated by Maven
|
||||||
|
#Sun Sep 17 16:49:31 CST 2023
|
||||||
|
version=3.6.0
|
||||||
|
groupId=com.bawei
|
||||||
|
artifactId=bawei-common-cache
|
|
@ -0,0 +1,5 @@
|
||||||
|
com\bawei\cache\BaseCache$1.class
|
||||||
|
com\bawei\cache\BaseCache.class
|
||||||
|
com\bawei\cache\db\BaseDatabaseCache.class
|
||||||
|
com\bawei\cache\annotation\CacheRole.class
|
||||||
|
com\bawei\cache\aspect\CacheRuleAsp.class
|
|
@ -0,0 +1,4 @@
|
||||||
|
D:\ruoyi\bawei-common\bawei-common-cache\src\main\java\com\bawei\cache\aspect\CacheRuleAsp.java
|
||||||
|
D:\ruoyi\bawei-common\bawei-common-cache\src\main\java\com\bawei\cache\db\BaseDatabaseCache.java
|
||||||
|
D:\ruoyi\bawei-common\bawei-common-cache\src\main\java\com\bawei\cache\BaseCache.java
|
||||||
|
D:\ruoyi\bawei-common\bawei-common-cache\src\main\java\com\bawei\cache\annotation\CacheRole.java
|
Loading…
Reference in New Issue