初始化

master
ZhangXushuo 2023-10-17 19:07:26 +08:00
commit 9b342f76c4
21 changed files with 273 additions and 0 deletions

8
.idea/.gitignore vendored 100644
View File

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

13
.idea/compiler.xml 100644
View File

@ -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>

View File

@ -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>

16
.idea/misc.xml 100644
View File

@ -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>

6
.idea/vcs.xml 100644
View File

@ -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>

28
pom.xml 100644
View File

@ -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>

View File

@ -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;
/**
* Rediskey
* @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);
}

View File

@ -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() ;
}

View File

@ -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();
}
}

View File

@ -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);
}

View File

@ -0,0 +1 @@
com.bawei.cache.aspect.CacheRuleAsp

Binary file not shown.

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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