Browse Source

add 方法

GITZYY 7 months ago
parent
commit
d967393c47

+ 81 - 66
egress-gateway-service-app/src/main/java/com/hrsk/cloud/eg/app/api/ApiServiceImpl.java

@@ -1,7 +1,19 @@
 package com.hrsk.cloud.eg.app.api;
+import com.google.common.collect.Lists;
+import com.hrsk.cloud.eg.domain.api.*;
+import com.hrsk.cloud.eg.domain.api.common.ApiPayloadTypeEnum;
+import com.hrsk.cloud.eg.infrastructure.clinent.utils.HessianUtils;
+import com.hrsk.cloud.eg.infrastructure.repository.database.entity.EgApiEndpointDo;
+import com.hrsk.cloud.eg.infrastructure.repository.database.mapper.EgApiEndpointMapper;
+import com.hrsk.cloud.eg.infrastructure.service.EgApiEndpointService;
+import com.hrsk.cloud.eg.infrastructure.service.EgApiService;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.annotation.Resource;
+import java.util.List;
+
 /**
  * @author: bianlanzhou
  * @create: 2024-08-02 10:57
@@ -10,70 +22,73 @@ import org.springframework.web.bind.annotation.RestController;
 @RestController
 @RequestMapping("/api")
 public class ApiServiceImpl {
-//    @Resource
-//    private EgApiEndpointMapper egApiEndpointMapper;
-//
-//    @Resource
-//    private ApiGateway apiGateway;
-//
-//    @GetMapping("/save")
-//    public void save(){
-//        EgApiEndpointDo egApiEndpointDo = new EgApiEndpointDo();
-//        egApiEndpointDo.setApiId(1234L);
-//        egApiEndpointDo.setEndpointType("http");
-//        egApiEndpointDo.setCreateUid("100000");
-//        egApiEndpointDo.setCreateUsername("admin");
-//        egApiEndpointDo.setModifyUid("100000");
-//        egApiEndpointDo.setModifyUsername("admin");
-//        egApiEndpointDo.setEndpointConfig(HessianUtils.serialize(createBean()));
-//        egApiEndpointMapper.insert(egApiEndpointDo);
-//    }
-//
-//    @GetMapping("/request")
-//    public void request(){
-//        apiGateway.request();
-//    }
-//
-//    private HttpApiConfig createBean(){
-//        FunctionObject md5 = new FunctionObject();
-//        md5.setCode("md5");
-//        HttpApiConfig hac = new HttpApiConfig()
-//                .setUrl("https://baidu.com");
-//        hac.setContentType(ApiPayloadTypeEnum.APPLICATION_JSON.getCode());
-//        hac.setType("http");
-//        List<KeyValueObject> h = Lists.newArrayList();
-//        KeyValueObject h1 = new KeyValueObject();
-//        h1.setKey("secretKey");
-//        h1.setType("text");
-//        h1.setValue("Khw99%$l%-2gF7P4jXglp_-jQqQirtYnOY5D");
-//        h.add(h1);
-//        KeyValueObject h2 = new KeyValueObject();
-//        h2.setKey("merchantNo");
-//        h2.setType("spel");
-//        h2.setValue("#param.realName");
-//        h.add(h2);
-//        List<ValueObject> p = Lists.newArrayList();
-//        ValueObject p1 = new ValueObject();
-//        p1.setType("text");
-//        p1.setValue("123");
-//        ValueObject p2 = new ValueObject();
-//        p2.setType("text");
-//        p2.setValue("456");
-//        p2.getFunctions().add(md5);
-//        p.add(p1);
-//        p.add(p2);
-//        List<KeyValueObject> s = Lists.newArrayList();
-//        KeyValueObject s1 = new KeyValueObject();
-//        s1.setKey("username");
-//        s1.setType("spel");
-//        s1.setValue("#param.username");
-//        KeyValueObject s2 = new KeyValueObject();
-//        s2.setKey("channel");
-//        s2.setType("spel");
-//        s2.setValue("#param.channel");
-//        s.add(s2);
-//        hac.setPath(p).setSearch(s).setHeader(h).setMethod("GET");
-//        hac.setContent("{\"merchant\":\"xxxxxxfffff\",\"phone\":\"#{\\\"value\\\":\\\"#param.userMobile\\\",\\\"type\\\": \\\"spel\\\",\\\"functions\\\":[ {\\\"code\\\": \\\"md5\\\"}]}\"}");
-//        return hac;
-//    }
+    @Resource
+    private EgApiService egApiService;
+
+    @Resource
+    private EgApiEndpointService egApiEndpointService;
+
+    @Resource
+    private ApiGateway apiGateway;
+
+    @GetMapping("/save")
+    public void save(){
+        EgApiEndpointDo egApiEndpointDo = new EgApiEndpointDo();
+        egApiEndpointDo.setApiId(1234L);
+        egApiEndpointDo.setApiCode("http");
+        egApiEndpointDo.setCreateUid("100000");
+        egApiEndpointDo.setCreateUsername("admin");
+        egApiEndpointDo.setModifyUid("100000");
+        egApiEndpointDo.setModifyUsername("admin");
+        egApiEndpointDo.setApiConfig(HessianUtils.serialize(createBean()));
+        egApiEndpointService.save(egApiEndpointDo);
+    }
+
+    @GetMapping("/request")
+    public void request(){
+        apiGateway.request();
+    }
+
+    private HttpApiConfig createBean(){
+        FunctionObject md5 = new FunctionObject();
+        md5.setCode("md5");
+        HttpApiConfig hac = new HttpApiConfig()
+                .setUrl("https://baidu.com");
+        hac.setContentType(ApiPayloadTypeEnum.APPLICATION_JSON.getCode());
+        hac.setType("http");
+        List<KeyValueObject> h = Lists.newArrayList();
+        KeyValueObject h1 = new KeyValueObject();
+        h1.setKey("secretKey");
+        h1.setType("text");
+        h1.setValue("Khw99%$l%-2gF7P4jXglp_-jQqQirtYnOY5D");
+        h.add(h1);
+        KeyValueObject h2 = new KeyValueObject();
+        h2.setKey("merchantNo");
+        h2.setType("spel");
+        h2.setValue("#param.realName");
+        h.add(h2);
+        List<ValueObject> p = Lists.newArrayList();
+        ValueObject p1 = new ValueObject();
+        p1.setType("text");
+        p1.setValue("123");
+        ValueObject p2 = new ValueObject();
+        p2.setType("text");
+        p2.setValue("456");
+        p2.getFunctions().add(md5);
+        p.add(p1);
+        p.add(p2);
+        List<KeyValueObject> s = Lists.newArrayList();
+        KeyValueObject s1 = new KeyValueObject();
+        s1.setKey("username");
+        s1.setType("spel");
+        s1.setValue("#param.username");
+        KeyValueObject s2 = new KeyValueObject();
+        s2.setKey("channel");
+        s2.setType("spel");
+        s2.setValue("#param.channel");
+        s.add(s2);
+        hac.setPath(p).setSearch(s).setHeader(h).setMethod("GET");
+        hac.setContent("{\"merchant\":\"xxxxxxfffff\",\"phone\":\"#{\\\"value\\\":\\\"#param.userMobile\\\",\\\"type\\\": \\\"spel\\\",\\\"functions\\\":[ {\\\"code\\\": \\\"md5\\\"}]}\"}");
+        return hac;
+    }
 }

+ 70 - 0
egress-gateway-service-client/src/main/java/com/hrsk/cloud/eg/constant/BusinessPrefixEnum.java

@@ -0,0 +1,70 @@
+package com.hrsk.cloud.eg.constant;
+
+/**
+ * @description: BusinessPrefixEnum 
+ * @author zhangyy
+ * @date 2024/8/28 14:48
+ * @version 1.0
+ */
+public enum BusinessPrefixEnum {
+    CHECK_INTO_PREFIX("CHECK_INTO","撞库API前缀"),
+    APPLY_PREFIX("APPLY","进件API前缀")
+
+    ;
+    private String code;
+    private String msg;
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    BusinessPrefixEnum (String code,String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+
+    /** 
+     * @description: 获取code
+     * @param:  
+     * @return:
+     * @author zhangyy
+     * @date: 2024/8/28 14:51
+     */ 
+    public static BusinessPrefixEnum getByCode(String code) {
+        for (BusinessPrefixEnum dataStatus : values()) {
+            if (dataStatus.getCode().equals(code)) {
+                return dataStatus;
+            }
+        }
+        return null;
+    }
+
+    /** 
+     * @description: 获取信息 
+     * @param:  
+     * @return:  
+     * @author zhangyy
+     * @date: 2024/8/28 14:51
+     */ 
+    public static String getByMsg(String code) {
+        for (BusinessPrefixEnum prefixEnum : values()) {
+            if (prefixEnum.getCode().equals(code)) {
+                return prefixEnum.getMsg();
+            }
+        }
+        return null;
+    }
+
+}

+ 23 - 0
egress-gateway-service-client/src/main/java/com/hrsk/cloud/eg/constant/GlobalDataStatusEnum.java

@@ -33,6 +33,13 @@ public enum GlobalDataStatusEnum {
         this.msg = msg;
     }
 
+    /** 
+     * @description: 获取code
+     * @param:  
+     * @return:  
+     * @author zhangyy
+     * @date: 2024/8/28 14:51
+     */ 
     public static GlobalDataStatusEnum getByCode(String code) {
         for (GlobalDataStatusEnum dataStatus : values()) {
             if (dataStatus.getCode().equals(code)) {
@@ -42,4 +49,20 @@ public enum GlobalDataStatusEnum {
         return null;
     }
 
+    /** 
+     * @description: 获取描述信息
+     * @param:  
+     * @return:  
+     * @author zhangyy
+     * @date: 2024/8/28 14:50
+     */ 
+    public static String getByMsg(String code) {
+        for (GlobalDataStatusEnum globalDataStatusEnum : values()) {
+            if (globalDataStatusEnum.getCode().equals(code)) {
+                return globalDataStatusEnum.getMsg();
+            }
+        }
+        return null;
+    }
+
 }

+ 1 - 1
egress-gateway-service-client/src/main/java/com/hrsk/cloud/eg/vo/response/DataVo.java

@@ -5,7 +5,7 @@ import java.io.Serializable;
 /**
  * @author zhangyy
  * @version 1.0
- * @description: DataVo
+ * @description: DataVo  DefaultResponseVo#data 中返回的信息多用与撞库接口返回
  * @date 2024/8/28 11:49
  */
 public class DataVo implements Serializable {

+ 1 - 1
egress-gateway-service-client/src/main/java/com/hrsk/cloud/eg/vo/response/DefaultResponseVo.java

@@ -9,7 +9,7 @@ import java.util.Objects;
 /**
  * Author: zhangyy
  * Date: 2019/4/2
- * Description: No Description
+ * Description:
  */
 public class DefaultResponseVo<T> implements Serializable {
     private T data;

+ 72 - 0
egress-gateway-service-domain/src/main/java/com/hrsk/cloud/eg/domain/common/utils/BeanCopyUtils.java

@@ -0,0 +1,72 @@
+package com.hrsk.cloud.eg.domain.common.utils;
+
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.BeanWrapper;
+import org.springframework.beans.BeanWrapperImpl;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ *
+ * Author:   zhangyy
+ * Date:     2020/4/3 14:29
+ * Description: BeanCopy工具
+ * History:
+ * describe:
+ **/
+public class BeanCopyUtils {
+
+    /**
+     * 空值不复制
+     *
+     * @param source
+     * @return
+     */
+    public static String[] getNullPropertyNames(Object source) {
+        final BeanWrapper src = new BeanWrapperImpl(source);
+        java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();
+
+        Set<String> emptyNames = new HashSet<String>();
+        for (java.beans.PropertyDescriptor pd : pds) {
+            Object srcValue = src.getPropertyValue(pd.getName());
+            if (srcValue == null) emptyNames.add(pd.getName());
+        }
+        String[] result = new String[emptyNames.size()];
+        return emptyNames.toArray(result);
+    }
+
+    /**
+     * 透传数据
+     *
+     * @param <T>
+     */
+    public static <T, K> T copy(final K k, final Class<? extends T> t) {
+        try {
+            T r = t.newInstance();
+            BeanUtils.copyProperties(k, r);
+            return r;
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    /**
+     * 透传数据
+     *
+     * @param <T>
+     */
+    public static <T, K> List<T> copyList(final List<K> kl, final Class<? extends T> t) {
+        try {
+            List<T> l = new ArrayList<>(kl.size());
+            for (K k : kl) {
+                l.add(copy(k, t));
+            }
+            return l;
+        } catch (Exception e) {
+            return new ArrayList<>();
+        }
+    }
+}

+ 10 - 0
egress-gateway-service-infrastructure/src/main/java/com/hrsk/cloud/eg/infrastructure/repository/database/entity/BaseDo.java

@@ -1,5 +1,7 @@
 package com.hrsk.cloud.eg.infrastructure.repository.database.entity;
 
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableField;
 import lombok.Data;
 
 import java.util.Date;
@@ -14,34 +16,42 @@ public class BaseDo {
     /**
      * 主键
      */
+    @TableField(fill = FieldFill.INSERT)
     private Long id;
     /**
      * 创建人ID
      */
+    @TableField(fill = FieldFill.INSERT)
     private String createUid;
     /**
      * 创建名称
      */
+    @TableField(fill = FieldFill.INSERT)
     private String createUsername;
     /**
      * 创建时间
      */
+    @TableField(fill = FieldFill.INSERT)
     private Date gmtCreate;
     /**
      * 修改人ID
      */
+    @TableField(fill = FieldFill.INSERT_UPDATE)
     private String modifyUid;
     /**
      * 修改人名称
      */
+    @TableField(fill = FieldFill.INSERT_UPDATE)
     private String modifyUsername;
     /**
      * 修改时间
      */
+    @TableField(fill = FieldFill.INSERT_UPDATE)
     private Date gmtModify;
     /**
      * 状态 有效(Y 有效 N 无效)
      */
+    @TableField(fill = FieldFill.INSERT)
     private String status;
 
 }