GITZYY il y a 5 jours
Parent
commit
2b306d4b72

+ 24 - 0
egress-gateway-service-client/src/main/java/com/hrsk/cloud/eg/client/dto/RedisSetDto.java

@@ -0,0 +1,24 @@
+package com.hrsk.cloud.eg.client.dto;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author zhangyy
+ * @version 1.0
+ * @description: RedisSetDto redis扩展定义类
+ * @date 2024/11/21 13:37
+ */
+@Data
+public class RedisSetDto implements Serializable {
+
+    //redis key
+    private String key;
+
+    //redis value
+    private Object value;
+
+    // 过期时间
+    private long time;
+}

+ 4 - 2
egress-gateway-service-domain/src/main/java/com/hrsk/cloud/eg/domain/api/Api.java

@@ -1,6 +1,7 @@
 package com.hrsk.cloud.eg.domain.api;
 
 import com.google.common.base.Function;
+import com.hrsk.cloud.eg.client.dto.RedisSetDto;
 import com.hrsk.cloud.eg.client.dto.cmd.RouteCmd;
 import com.hrsk.cloud.eg.domain.api.channel.guide.common.EgressApiErrorCodeEnum;
 import com.hrsk.cloud.eg.domain.api.channel.guide.http.HttpApiRequest;
@@ -38,11 +39,11 @@ public class Api {
      * 调用
      * @param input 入参
      */
-    public String invoke(Map<String,Object> input, Function<HttpApiRequest, HttpApiResponse> httpClientFunc){
+    public String invoke(Map<String,Object> input, Function<HttpApiRequest, HttpApiResponse> httpClientFunc,Function<String,Object> redisGetFunction,Function<RedisSetDto,Boolean> redisSetFunction){
         if(target == null){
             throw new BizException(EgressApiErrorCodeEnum.AVAILABLE_API_CHANNEL_NOT_EXIST.getCode(),EgressApiErrorCodeEnum.API_CHANNEL_NOT_EXIST.getMessage());
         }
-        return target.invoke(input,httpClientFunc);
+        return target.invoke(input,httpClientFunc,redisGetFunction,redisSetFunction);
     }
 
     /**
@@ -54,4 +55,5 @@ public class Api {
         target = ApiRoute.getInstance().route(apiChannels,route);
         return this;
     }
+
 }

+ 2 - 1
egress-gateway-service-domain/src/main/java/com/hrsk/cloud/eg/domain/api/ApiChannel.java

@@ -1,6 +1,7 @@
 package com.hrsk.cloud.eg.domain.api;
 
 import com.google.common.base.Function;
+import com.hrsk.cloud.eg.client.dto.RedisSetDto;
 import com.hrsk.cloud.eg.domain.api.channel.guide.common.EgressApiEndpointIntegrationModeEnum;
 import com.hrsk.cloud.eg.domain.api.channel.guide.common.EgressApiErrorCodeEnum;
 import com.hrsk.cloud.eg.domain.api.channel.guide.http.HttpApiRequest;
@@ -83,7 +84,7 @@ public class ApiChannel {
      * @param httpClientFunc httpclient
      * @return 处理结果
      */
-    public String invoke(Map<String,Object> input,Function<HttpApiRequest, HttpApiResponse> httpClientFunc){
+    public String invoke(Map<String,Object> input,Function<HttpApiRequest, HttpApiResponse> httpClientFunc,Function<String,Object> redisGetFunction,Function<RedisSetDto,Boolean> redisSetFunction){
         HttpApiResponse response = null;
         if(StringUtils.equals(integrationMode, EgressApiEndpointIntegrationModeEnum.GUIDE.getCode())){
             config();

+ 0 - 1
egress-gateway-service-domain/src/main/java/com/hrsk/cloud/eg/domain/api/channel/customized/threedocking/LoanDockingApi.java

@@ -9,7 +9,6 @@ import com.hrsk.cloud.eg.domain.api.channel.customized.common.ServerCodeEnums;
 import com.hrsk.cloud.eg.domain.api.channel.guide.http.HttpApiRequest;
 import com.hrsk.cloud.eg.domain.api.channel.guide.http.HttpApiResponse;
 
-import javax.xml.crypto.Data;
 
 /**
  * @author zhangyy

+ 1 - 0
egress-gateway-service-domain/src/main/java/com/hrsk/cloud/eg/domain/common/BeetlHelper.java

@@ -1,6 +1,7 @@
 package com.hrsk.cloud.eg.domain.common;
 
 import com.hrsk.cloud.eg.domain.api.channel.guide.http.HttpApiResponse;
+import com.hrsk.cloud.eg.domain.common.constant.SysErrorCodeEnum;
 import com.hrsk.pangu.tool.exception.SysException;
 import lombok.extern.slf4j.Slf4j;
 import org.beetl.core.Configuration;

+ 1 - 1
egress-gateway-service-domain/src/main/java/com/hrsk/cloud/eg/domain/common/SysErrorCodeEnum.java → egress-gateway-service-domain/src/main/java/com/hrsk/cloud/eg/domain/common/constant/SysErrorCodeEnum.java

@@ -1,4 +1,4 @@
-package com.hrsk.cloud.eg.domain.common;
+package com.hrsk.cloud.eg.domain.common.constant;
 
 /**
  * @author: bianlanzhou

+ 4 - 5
egress-gateway-service-infrastructure/pom.xml

@@ -33,11 +33,6 @@
             <artifactId>spring-boot-starter-test</artifactId>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>com.h2database</groupId>
-            <artifactId>h2</artifactId>
-            <scope>runtime</scope>
-        </dependency>
         <dependency>
             <groupId>com.baomidou</groupId>
             <artifactId>mybatis-plus-boot-starter</artifactId>
@@ -58,5 +53,9 @@
             <groupId>org.apache.httpcomponents</groupId>
             <artifactId>httpclient</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-redis</artifactId>
+        </dependency>
     </dependencies>
 </project>

+ 10 - 0
egress-gateway-service-infrastructure/src/main/java/com/hrsk/cloud/eg/infrastructure/gatewayimpl/ApiGatewayImpl.java

@@ -10,6 +10,7 @@ import com.hrsk.cloud.eg.domain.common.GsonUtils;
 import com.hrsk.cloud.eg.infrastructure.client.http.HttpClient;
 import com.hrsk.cloud.eg.infrastructure.repository.database.dao.EgressApiChannelDao;
 import com.hrsk.cloud.eg.infrastructure.repository.database.entity.EgressApiChannelDo;
+import com.hrsk.cloud.eg.infrastructure.utils.RedisUtil;
 import com.hrsk.pangu.tool.exception.BizException;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.ResponseEntity;
@@ -33,6 +34,9 @@ public class ApiGatewayImpl implements ApiGateway {
     @Resource
     private EgressApiChannelDao egressApiChannelDao;
 
+    @Resource
+    private RedisUtil redisUtil;
+
     /**
      * 调用
      * @param apiInvokeCmd cmd CMD
@@ -64,6 +68,12 @@ public class ApiGatewayImpl implements ApiGateway {
             else{
                 return new HttpApiResponse(response.getStatusCodeValue(),response.getBody());
             }
+        },key->{
+          Object object = redisUtil.get(key);
+           return  object;
+       },
+        (redisSetDto)->{
+          return    redisUtil.setValue(redisSetDto.getKey(),redisSetDto.getValue(),redisSetDto.getTime());
         });
     }
 

+ 20 - 0
egress-gateway-service-infrastructure/src/main/java/com/hrsk/cloud/eg/infrastructure/utils/RedisUtil.java

@@ -46,6 +46,24 @@ public class RedisUtil {
             expire(key, expire);
         }
     }
+
+    /**
+     * 添加值
+     * @param key
+     * @param value
+     * @param expire
+     */
+    public Boolean setValue(String key, Object value, long expire) {
+      try {
+          redisTemplate.opsForValue().set(key, value,expire, TimeUnit.MINUTES);
+          if (expire != NOT_EXPIRE) {
+              expire(key, expire);
+          }
+      } catch (Exception e) {
+          return false;
+      }
+       return true;
+    }
     /**
      * 添加值
      * @param key
@@ -273,4 +291,6 @@ public class RedisUtil {
             log.error("redis set errr",e);
         }
     }
+
+
 }

+ 6 - 6
pom.xml

@@ -27,6 +27,7 @@
         <beetl.version>3.9.3.RELEASE</beetl.version>
         <commons-codec.version>1.15</commons-codec.version>
         <fast2-json>2.0.25</fast2-json>
+        <redis.version>2.7.1</redis.version>
     </properties>
 
     <dependencies>
@@ -128,12 +129,6 @@
                 <artifactId>hessian</artifactId>
                 <version>${hessian.version}</version>
             </dependency>
-            <!-- 数据库版本控制 -->
-            <dependency>
-                <groupId>org.flywaydb</groupId>
-                <artifactId>flyway-core</artifactId>
-                <version>${flyway-core.version}</version>
-            </dependency>
 
             <dependency>
                 <groupId>com.jayway.jsonpath</groupId>
@@ -151,6 +146,11 @@
                 <artifactId>beetl</artifactId>
                 <version>${beetl.version}</version>
             </dependency>
+            <dependency>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-starter-data-redis</artifactId>
+                <version>${redis.version}</version>
+            </dependency>
         </dependencies>
     </dependencyManagement>