|
@@ -0,0 +1,50 @@
|
|
|
+
|
|
|
+package com.qunzhixinxi.hnqz.admin.aspect;
|
|
|
+
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.constant.enums.ExportType;
|
|
|
+import com.qunzhixinxi.hnqz.common.security.service.HnqzUser;
|
|
|
+
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.SneakyThrows;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
+import org.aspectj.lang.annotation.Around;
|
|
|
+import org.aspectj.lang.annotation.Aspect;
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Aspect
|
|
|
+@AllArgsConstructor
|
|
|
+@Component
|
|
|
+public class ExportGuardAspect {
|
|
|
+
|
|
|
+ @SneakyThrows
|
|
|
+ @Around("@annotation(exportGuard)")
|
|
|
+ public Object around(ProceedingJoinPoint point, ExportGuard exportGuard) {
|
|
|
+ ExportType exportType = ExportType.valueOf(exportGuard.type());
|
|
|
+ if (point.getArgs().length < 1) {
|
|
|
+ throw new RuntimeException("第一个参数必须是用户对象");
|
|
|
+ }
|
|
|
+ HnqzUser user = (HnqzUser) point.getArgs()[0];
|
|
|
+ if (user == null) {
|
|
|
+ throw new RuntimeException("第一个参数必须是用户对象");
|
|
|
+ }
|
|
|
+ String key = ExportType.getAsyncExportCache(exportType, user.getId());
|
|
|
+ // RedisTemplateConfig
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ RedisTemplate<String, Object> redisTemplate = (RedisTemplate<String, Object>) SpringUtil.getBean("redisTemplate");
|
|
|
+ String status = (String) redisTemplate.opsForValue().get(key);
|
|
|
+ if ("GENERATING".equals(status)) {
|
|
|
+ throw new RuntimeException("导出正在生成中,请稍后再试");
|
|
|
+ }
|
|
|
+
|
|
|
+ return point.proceed();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|