From 43d11becdfc0d7af00b10e91b962cd0c4738bbf1 Mon Sep 17 00:00:00 2001
From: fwq <582742538@qq.com>
Date: 星期一, 11 十二月 2023 10:41:56 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 /dev/null                                                         |  114 ----------------------
 src/main/java/com/hx/repeat/check/RequestRepeatUtil.java          |   76 +++++++++++++++
 src/main/java/com/hx/common/annotations/repeat/RequestRepeat.java |   17 +++
 src/main/java/com/hx/util/NumberUtil.java                         |   32 ++++++
 src/main/java/com/hx/util/FileConvertTool.java                    |    3 
 5 files changed, 126 insertions(+), 116 deletions(-)

diff --git a/src/main/java/com/hx/common/SpringUtils.java b/src/main/java/com/hx/common/SpringUtils.java
deleted file mode 100644
index 4dd2a6d..0000000
--- a/src/main/java/com/hx/common/SpringUtils.java
+++ /dev/null
@@ -1,114 +0,0 @@
-package com.hx.common;
-
-import org.springframework.aop.framework.AopContext;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.NoSuchBeanDefinitionException;
-import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
-import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
-import org.springframework.stereotype.Component;
-
-/**
- * spring宸ュ叿绫� 鏂逛究鍦ㄩ潪spring绠$悊鐜涓幏鍙朾ean
- * 
- * @author
- */
-@Component
-public final class SpringUtils implements BeanFactoryPostProcessor
-{
-    /** Spring搴旂敤涓婁笅鏂囩幆澧� */
-    private static ConfigurableListableBeanFactory beanFactory;
-
-    @Override
-    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException
-    {
-        SpringUtils.beanFactory = beanFactory;
-    }
-
-    /**
-     * 鑾峰彇瀵硅薄
-     *
-     * @param name
-     * @return Object 涓�涓互鎵�缁欏悕瀛楁敞鍐岀殑bean鐨勫疄渚�
-     * @throws BeansException
-     *
-     */
-    @SuppressWarnings("unchecked")
-    public static <T> T getBean(String name) throws BeansException
-    {
-        return (T) beanFactory.getBean(name);
-    }
-
-    /**
-     * 鑾峰彇绫诲瀷涓簉equiredType鐨勫璞�
-     *
-     * @param clz
-     * @return
-     * @throws BeansException
-     *
-     */
-    public static <T> T getBean(Class<T> clz) throws BeansException
-    {
-        T result = (T) beanFactory.getBean(clz);
-        return result;
-    }
-
-    /**
-     * 濡傛灉BeanFactory鍖呭惈涓�涓笌鎵�缁欏悕绉板尮閰嶇殑bean瀹氫箟锛屽垯杩斿洖true
-     *
-     * @param name
-     * @return boolean
-     */
-    public static boolean containsBean(String name)
-    {
-        return beanFactory.containsBean(name);
-    }
-
-    /**
-     * 鍒ゆ柇浠ョ粰瀹氬悕瀛楁敞鍐岀殑bean瀹氫箟鏄竴涓猻ingleton杩樻槸涓�涓猵rototype銆� 濡傛灉涓庣粰瀹氬悕瀛楃浉搴旂殑bean瀹氫箟娌℃湁琚壘鍒帮紝灏嗕細鎶涘嚭涓�涓紓甯革紙NoSuchBeanDefinitionException锛�
-     *
-     * @param name
-     * @return boolean
-     * @throws NoSuchBeanDefinitionException
-     *
-     */
-    public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException
-    {
-        return beanFactory.isSingleton(name);
-    }
-
-    /**
-     * @param name
-     * @return Class 娉ㄥ唽瀵硅薄鐨勭被鍨�
-     * @throws NoSuchBeanDefinitionException
-     *
-     */
-    public static Class<?> getType(String name) throws NoSuchBeanDefinitionException
-    {
-        return beanFactory.getType(name);
-    }
-
-    /**
-     * 濡傛灉缁欏畾鐨刡ean鍚嶅瓧鍦╞ean瀹氫箟涓湁鍒悕锛屽垯杩斿洖杩欎簺鍒悕
-     *
-     * @param name
-     * @return
-     * @throws NoSuchBeanDefinitionException
-     *
-     */
-    public static String[] getAliases(String name) throws NoSuchBeanDefinitionException
-    {
-        return beanFactory.getAliases(name);
-    }
-
-    /**
-     * 鑾峰彇aop浠g悊瀵硅薄
-     * 
-     * @param invoker
-     * @return
-     */
-    @SuppressWarnings("unchecked")
-    public static <T> T getAopProxy(T invoker)
-    {
-        return (T) AopContext.currentProxy();
-    }
-}
diff --git a/src/main/java/com/hx/common/annotations/repeat/RequestRepeat.java b/src/main/java/com/hx/common/annotations/repeat/RequestRepeat.java
new file mode 100644
index 0000000..a43c68d
--- /dev/null
+++ b/src/main/java/com/hx/common/annotations/repeat/RequestRepeat.java
@@ -0,0 +1,17 @@
+package com.hx.common.annotations.repeat;
+
+import java.lang.annotation.*;
+
+/**
+ * 閲嶅鏍¢獙娉ㄨВ
+ * @author CJH
+ */
+@Target({ElementType.TYPE, ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface RequestRepeat {
+    /**鏄惁閲嶅鏍¢獙锛岄粯璁rue*/
+    boolean isRepeat() default true;
+    /**閲嶅闂撮殧鏃堕棿锛屾绉掞紝榛樿1000姣*/
+    long millisecond() default 1000;
+}
\ No newline at end of file
diff --git a/src/main/java/com/hx/repeat/check/RequestRepeatUtil.java b/src/main/java/com/hx/repeat/check/RequestRepeatUtil.java
new file mode 100644
index 0000000..39f1703
--- /dev/null
+++ b/src/main/java/com/hx/repeat/check/RequestRepeatUtil.java
@@ -0,0 +1,76 @@
+package com.hx.repeat.check;
+
+import com.hx.common.annotations.repeat.RequestRepeat;
+import com.hx.exception.TipsException;
+import com.hx.redis.RedisUtil;
+import com.hx.util.DateUtil;
+import com.hx.util.IPUtils;
+
+import javax.servlet.http.HttpServletRequest;
+import java.lang.reflect.Method;
+import java.util.Date;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * URL闃查噸澶嶆彁浜�
+ * @author CJH
+ */
+public class RequestRepeatUtil {
+
+    /**璇锋眰閲嶅鏍¢獙
+     * 鐩墠鍖哄垎閲嶅鏄疘P鍦板潃鍜岃姹傛柟娉曪紝濡傛灉鎯宠鏇寸簿鍑嗭紝浼燾ode
+     * @param code 鍓嶇紑鏍囪瘑锛岀敤浜庡尯鍒嗕笉鍚岃姹傛潵婧愶紝闀垮害鏈�濂�12浣嶄箣鍐咃紝鍙┖
+     * @param request HttpServletRequest
+     * @param redisUtil redis
+     * @param millisecond 闂撮殧鏃堕棿锛屾绉掞紙榛樿500姣锛�
+     * @param annotateCheck 鏄惁娉ㄨВ鏍¢獙锛屽鏋滄槸锛屽皢浠ユ敞瑙f潵鍋氭牎楠岋紝鍚﹀垯灏卞叏閮ㄥ仛鏍¢獙
+     * @param method 璇锋眰鏂规硶锛屾柟娉曟垨鑰呯被涓婇潰鏈夋牎楠屾敞瑙o紝娉ㄨВ璺宠繃鎴栬�呮嫤鎴�
+     */
+    public static void checkRequest(String code,HttpServletRequest request, RedisUtil redisUtil, Long millisecond
+            , boolean annotateCheck, Method method){
+        //浼樺厛鏍¢獙娉ㄨВ锛屼紭鍏堟柟娉曞啀鍒扮被
+        RequestRepeat requestRepeat =  method.getAnnotation(RequestRepeat.class);
+        if(requestRepeat != null){
+            if(requestRepeat.isRepeat()){
+                check(code,request,redisUtil,requestRepeat.millisecond());
+            }else{
+                return;
+            }
+        }else{
+            requestRepeat = method.getClass().getAnnotation(RequestRepeat.class);
+            if(requestRepeat != null){
+                if(requestRepeat.isRepeat()){
+                    check(code,request,redisUtil,requestRepeat.millisecond());
+                }else{
+                    return;
+                }
+            }
+        }
+        //閫氳繃娉ㄨВ鏍¢獙锛屼笉闇�瑕佸叏閮�
+        if(!annotateCheck){
+            check(code,request,redisUtil,millisecond);
+        }
+    }
+
+    public static void check(String code,HttpServletRequest request,RedisUtil redisUtil,Long millisecond){
+        //娌℃湁璁剧疆锛岄粯璁�0.5绉�
+        if(millisecond == null){
+            millisecond = 500L;
+        }
+        //鑾峰彇璇锋眰鐨処P鍦板潃
+        String ip = IPUtils.getIpAddr(request);
+        //鑾峰彇URL
+        String method = request.getServletPath();
+        if(code != null){
+            code = code+"-"+ip+"-"+method;
+        }else{
+            code = ip+"-"+method;
+        }
+        if(!redisUtil.setIfAbsent(code, DateUtil.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"),millisecond, TimeUnit.MILLISECONDS)){
+            throw new TipsException("璇峰嬁棰戠箒鎿嶄綔锛�");
+        }
+
+    }
+
+
+}
diff --git a/src/main/java/com/hx/util/FileConvertTool.java b/src/main/java/com/hx/util/FileConvertTool.java
index 1598f98..dee2c99 100644
--- a/src/main/java/com/hx/util/FileConvertTool.java
+++ b/src/main/java/com/hx/util/FileConvertTool.java
@@ -44,8 +44,7 @@
     /**
      * 鑾峰彇鏂囦欢base64瀛楃涓�
      * @param urlPath  鏂囦欢璺緞
-     * @return
-     * @throws IOException
+     * @return 杩斿洖base64缂栫爜
      */
     public static String getFileBaseStrByUrl(String urlPath) throws IOException {
         InputStream is = getUrlFile(urlPath);
diff --git a/src/main/java/com/hx/util/NumberUtil.java b/src/main/java/com/hx/util/NumberUtil.java
index 59b9581..9ed21d0 100644
--- a/src/main/java/com/hx/util/NumberUtil.java
+++ b/src/main/java/com/hx/util/NumberUtil.java
@@ -383,4 +383,36 @@
         return str;
     }
 
+    /** 鏍¢獙瀛楃涓叉槸鍚︽暣鏁� */
+    public static boolean checkStrIsInt(String str){
+        if(StringUtils.isEmpty(str)){
+            return false;
+        }
+        try{
+            Integer.parseInt(str);
+            return true;
+        }catch (Exception e){
+            return false;
+        }
+    }
+
+    /**
+     * 瀛楃涓茶浆鏁村舰
+     * @param str
+     * @param defInt    榛樿鏁存暟
+     * @return
+     */
+    public static int strChangeInt(String str, Integer defInt){
+        if(defInt == null){
+            defInt = 0;
+        }
+        if(StringUtils.isEmpty(str)){
+            return defInt;
+        }
+        try{
+            return Integer.parseInt(str);
+        }catch (Exception e){
+            return defInt;
+        }
+    }
 }

--
Gitblit v1.8.0