20 changed files with 386 additions and 200 deletions
@ -1,12 +1,11 @@
|
||||
package com.mh.user.annotation; |
||||
import javax.servlet.ServletContextAttributeEvent; |
||||
import javax.servlet.ServletContextAttributeListener; |
||||
import javax.servlet.ServletContextEvent; |
||||
import javax.servlet.ServletContextListener; |
||||
import javax.servlet.annotation.WebListener; |
||||
|
||||
@WebListener |
||||
public class applicationListener implements ServletContextListener,ServletContextAttributeListener{ |
||||
public class ApplicationListener implements ServletContextListener,ServletContextAttributeListener{ |
||||
|
||||
@Override |
||||
public void contextDestroyed(ServletContextEvent arg0) { |
@ -0,0 +1,20 @@
|
||||
package com.mh.user.annotation; |
||||
|
||||
import java.lang.annotation.*; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project mh_esi |
||||
* @description 缓存变动 |
||||
* @date 2024-11-19 11:36:47 |
||||
*/ |
||||
@Target(ElementType.METHOD) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Documented |
||||
public @interface CacheChanges { |
||||
|
||||
// 缓存类型
|
||||
String value() default ""; |
||||
|
||||
} |
@ -0,0 +1,75 @@
|
||||
package com.mh.user.aspect; |
||||
|
||||
import com.mh.common.utils.StringUtils; |
||||
import com.mh.user.annotation.CacheChanges; |
||||
import com.mh.user.entity.MeterManageEntity; |
||||
import com.mh.user.service.DeviceCodeParamService; |
||||
import com.mh.user.service.SysDictService; |
||||
import org.aspectj.lang.JoinPoint; |
||||
import org.aspectj.lang.ProceedingJoinPoint; |
||||
import org.aspectj.lang.annotation.After; |
||||
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 java.lang.reflect.Method; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project mh_esi |
||||
* @description 缓存数据切面 |
||||
* @date 2024-11-19 11:40:50 |
||||
*/ |
||||
@Aspect |
||||
@Component |
||||
public class CacheChangesAsp { |
||||
|
||||
@Autowired |
||||
private SysDictService sysDictService; |
||||
|
||||
@Autowired |
||||
private DeviceCodeParamService deviceCodeParamService; |
||||
|
||||
@Pointcut("@annotation(com.mh.user.annotation.CacheChanges)") |
||||
public void cachePointCut() { |
||||
} |
||||
|
||||
@After("cachePointCut()") |
||||
public void afterAdvice(JoinPoint point) throws Throwable { |
||||
// 保存日志
|
||||
updateCacheChanges(point); |
||||
} |
||||
|
||||
private void updateCacheChanges(JoinPoint joinPoint) { |
||||
|
||||
// 获取方法签名
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); |
||||
// 获取方法上的注解
|
||||
CacheChanges cacheChanges = signature.getMethod().getAnnotation(CacheChanges.class); |
||||
// 获取值
|
||||
String value = ""; |
||||
if (cacheChanges != null) { |
||||
value = cacheChanges.value(); |
||||
} |
||||
|
||||
// 获取项目id参数
|
||||
Object[] args = joinPoint.getArgs(); |
||||
|
||||
switch (value) { |
||||
case "sys_dict": |
||||
sysDictService.createDictDataCache(); |
||||
break; |
||||
case "device_code_params": |
||||
MeterManageEntity entity = (MeterManageEntity) args[0]; |
||||
deviceCodeParamService.createCodeParams(entity); |
||||
default: |
||||
break; |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue