初始化

master
fst1996 2023-09-15 16:20:42 +08:00
commit 6a5b6c137e
7 changed files with 272 additions and 0 deletions

47
.gitignore vendored 100644
View File

@ -0,0 +1,47 @@
######################################################################
# Build Tools
.gradle
/build/
!gradle/wrapper/gradle-wrapper.jar
target/
!.mvn/wrapper/maven-wrapper.jar
######################################################################
# IDE
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### JRebel ###
rebel.xml
### NetBeans ###
nbproject/private/
build/*
nbbuild/
dist/
nbdist/
.nb-gradle/
target/
######################################################################
# Others
*.log
*.xml.versionsBackup
*.swp
!*/build/*.java
!*/build/*.html
!*/build/*.xml

46
pom.xml 100644
View File

@ -0,0 +1,46 @@
<?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>menghang-common</artifactId>
<groupId>com.bawei</groupId>
<version>3.6.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<version>3.6.0</version>
<artifactId>menghang-common-cache</artifactId>
<repositories>
<repository>
<id>menghang-public</id>
<name>梦航-public</name>
<url>http://192.168.111.130:8081/repository/maven-public/</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>menghang-releases</id>
<name>梦航-releases</name>
<url>http://192.168.111.130:8081/repository/maven-releases/</url>
</repository>
</distributionManagement>
<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>menghang-common-redis</artifactId>
<version>3.6.0</version>
</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