瀏覽代碼

add API决策

GITZYY 7 月之前
父節點
當前提交
2e78c3b0c5

+ 4 - 3
egress-gateway-service-app/src/main/java/com/hrsk/cloud/eg/app/api/ApiCheckIntoServiceImpl.java

@@ -1,5 +1,5 @@
 package com.hrsk.cloud.eg.app.api;
 package com.hrsk.cloud.eg.app.api;
-import com.hrsk.cloud.eg.domain.api.ApiGateway;
+import com.hrsk.cloud.eg.app.business.ApiRouteService;
 import com.hrsk.cloud.eg.dto.data.CheckIntoParamDto;
 import com.hrsk.cloud.eg.dto.data.CheckIntoParamDto;
 import com.hrsk.cloud.eg.vo.response.DataVo;
 import com.hrsk.cloud.eg.vo.response.DataVo;
 import com.hrsk.cloud.eg.vo.response.DefaultResponseVo;
 import com.hrsk.cloud.eg.vo.response.DefaultResponseVo;
@@ -19,7 +19,7 @@ import javax.annotation.Resource;
 public class ApiCheckIntoServiceImpl {
 public class ApiCheckIntoServiceImpl {
 
 
     @Resource
     @Resource
-    private ApiGateway apiGateway;
+    private ApiRouteService  apiRouteService;
 
 
 
 
     /**
     /**
@@ -31,7 +31,8 @@ public class ApiCheckIntoServiceImpl {
      */
      */
     @RequestMapping("/loans/v1")
     @RequestMapping("/loans/v1")
     public DefaultResponseVo<DataVo> checkInto(@RequestBody CheckIntoParamDto paramDto) {
     public DefaultResponseVo<DataVo> checkInto(@RequestBody CheckIntoParamDto paramDto) {
-       return apiGateway.checkIntoRequest(paramDto);
+        DataVo dataVo = apiRouteService.loanCheckInto(paramDto);
+        return DefaultResponseVo.success(dataVo);
     }
     }
 
 
 
 

+ 48 - 0
egress-gateway-service-app/src/main/java/com/hrsk/cloud/eg/app/business/ApiBizHandler.java

@@ -0,0 +1,48 @@
+package com.hrsk.cloud.eg.app.business;
+
+import com.hrsk.cloud.eg.app.constant.ServerCodeEnums;
+import com.hrsk.cloud.eg.app.threedocking.LoanDockingApi;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author zhangyy
+ * @version 1.0
+ * @description: ApiBizHandler
+ * @date 2024/9/13 09:34
+ */
+@Component
+public class ApiBizHandler implements ApplicationContextAware {
+
+    private final Map<ServerCodeEnums, LoanDockingApi> bizHandlerMap = new HashMap<>();
+
+
+
+    public void putBizHandler(ServerCodeEnums  type, LoanDockingApi handler) {
+        bizHandlerMap.put(type, handler);
+    }
+
+    public LoanDockingApi getBizHandler(ServerCodeEnums type) {
+        LoanDockingApi bizHandler = this.bizHandlerMap.get(type);
+        if (bizHandler == null) {
+            throw new RuntimeException("not.found.BizHandler");
+        }
+        return bizHandler;
+    }
+
+    @Override
+    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+        Map<String, LoanDockingApi> beansOfType = applicationContext.getBeansOfType(LoanDockingApi.class);
+        Collection<LoanDockingApi> services = beansOfType.values();
+        for (LoanDockingApi service : services) {
+            ServerCodeEnums type = service.getType();
+            bizHandlerMap.put(type, service);
+        }
+    }
+
+}

+ 135 - 0
egress-gateway-service-app/src/main/java/com/hrsk/cloud/eg/app/business/ApiRouteService.java

@@ -0,0 +1,135 @@
+package com.hrsk.cloud.eg.app.business;
+
+import com.hrsk.cloud.eg.app.constant.JoinMethodEnums;
+import com.hrsk.cloud.eg.app.constant.ServerCodeEnums;
+import com.hrsk.cloud.eg.app.threedocking.LoanDockingApi;
+import com.hrsk.cloud.eg.app.threedocking.impl.*;
+import com.hrsk.cloud.eg.dto.data.CheckIntoParamDto;
+import com.hrsk.cloud.eg.dto.data.egPlan.PlanDto;
+import com.hrsk.cloud.eg.infrastructure.repository.database.entity.ProductBusinessApiInfoDo;
+import com.hrsk.cloud.eg.infrastructure.service.ProductBusinessApiInfoService;
+import com.hrsk.cloud.eg.vo.response.DataVo;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import javax.annotation.Resource;
+
+/**
+ * @author zhangyy
+ * @version 1.0
+ * @description: ApiRouteService
+ * @date 2024/9/13 09:29
+ */
+@Slf4j
+@Service
+public class ApiRouteService {
+
+    @Resource
+    private ProductBusinessApiInfoService apiInfoService;
+
+    @Resource
+    private ApiBizHandler apiBizHandler;
+
+    @Resource
+    private QingyuCreditService qingyuCreditService;
+
+    @Resource
+    private XinluCreditService xinluCreditService;
+
+    @Resource
+    private OpenApiCreditService openApiCreditService;
+
+    @Resource
+    private QingyuV2CreditService qingyuV2CreditService;
+
+    @Resource
+    private XiangKeDaCreditService xiangKeDaCreditService;
+
+    @Resource
+    private RxkCreditService rxkCreditService;
+
+    @Resource
+    private OpenApiAesCreditService openApiAesCreditService;
+
+    @Resource
+    private HuirongCrmCreditService huirongCrmCreditService;
+
+    @Resource
+    private JinDieV2CreditService jinDieV2CreditService;
+
+    @Resource
+    private JinDieV3CreditService jinDieV3CreditService;
+
+    @Resource
+    private QingyuV3CreditService qingyuV3CreditService;
+
+
+    /**
+     * API 路由
+     *
+     * @param xdProduct
+     * @return
+     */
+    public LoanDockingApi apiRouter(PlanDto xdProduct) {
+        if (null == xdProduct.getApiId()) return null;
+        ProductBusinessApiInfoDo apiInfo = apiInfoService.getApiInfoByRedis(xdProduct.getApiId());
+        LoanDockingApi apiService = null;
+        JoinMethodEnums method = JoinMethodEnums.getByCode(apiInfo.getJoinMethod());
+
+        if (null == method) return null;
+        switch (method) {
+            case CRM_QY:
+                apiService = qingyuCreditService;
+                break;
+            case CRM_XL:
+                apiService = xinluCreditService;
+                break;
+            case OPEN_API:
+                apiService = openApiCreditService;
+                break;
+            case CRM_QY_V2:
+                apiService = qingyuV2CreditService;
+                break;
+            case CRM_XKD:
+                apiService = xiangKeDaCreditService;
+                break;
+            case CRM_RXK:
+                apiService = rxkCreditService;
+                break;
+            case HUIRONG_CRM:
+                apiService = huirongCrmCreditService;
+                break;
+            case CRM_EC:
+                break;
+            case CRM_JD:
+                apiService = jinDieV2CreditService;
+                break;
+            case CRM_JDV3:
+                apiService = jinDieV3CreditService;
+                break;
+            case BUSI_API:
+                apiService = apiBizHandler.getBizHandler(ServerCodeEnums.map.get(apiInfo.getJointType()));
+                break;
+            case CRM_QY_V3:
+                apiService = qingyuV3CreditService;
+                break;
+            case OPEN_API_AES:
+                apiService = openApiAesCreditService;
+                break;
+            default:
+                log.error("不支持的对接方式:productId={}", xdProduct.getPlanId());
+        }
+        return apiService;
+    }
+
+    /**
+     * @description:  助贷撞库api
+     * @param:
+     * @return:
+     * @author zhangyy
+     * @date: 2024/9/13 09:59
+     */
+    public DataVo loanCheckInto(CheckIntoParamDto checkIntoParamDto){
+        LoanDockingApi loanDockingApi = apiRouter(checkIntoParamDto.getPlan());
+      return   loanDockingApi.qualityCheck(checkIntoParamDto.getUser(),checkIntoParamDto.getPlan());
+    }
+}

+ 44 - 0
egress-gateway-service-app/src/main/java/com/hrsk/cloud/eg/app/constant/JoinMethodEnums.java

@@ -0,0 +1,44 @@
+package com.hrsk.cloud.eg.app.constant;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@Getter
+@AllArgsConstructor
+public enum JoinMethodEnums {
+
+    OPEN_API("1", "我方通用API"),
+    BUSI_API("2", "合作方CRM"),
+    CRM_EC("3", "三方CRM(ec)"),
+    CRM_QY("4", "三方CRM(庆鱼)"),
+    CRM_JD("5", "三方CRM(锦蝶)"),
+    CRM_RXK("6", "三方CRM(融享客)"),
+    CRM_XL("7", "三方CRM(鑫鹿)"),
+    CRM_QY_V2("8", "三方CRM(庆鱼2.0)"),
+    CRM_XKD("10", "三方CRM(享客达)"),
+    HUIRONG_CRM("9", "惠融易客CRM"),
+    CRM_QY_V3("11", "三方CRM(庆鱼3.0)"),
+    CRM_JDV3("12", "三方CRM(锦蝶V3)"),
+    OPEN_API_AES("13", "我方通用AES模式");
+
+
+    private String code;
+    private String message;
+
+    static Map<String, JoinMethodEnums> map = new HashMap();
+
+    static {
+        for (JoinMethodEnums value : JoinMethodEnums.values()) {
+            map.put(value.code, value);
+        }
+    }
+
+    public static JoinMethodEnums getByCode(String code) {
+        return map.get(code);
+    }
+
+
+}

+ 1 - 1
egress-gateway-service-client/src/main/java/com/hrsk/cloud/eg/dto/data/egPlan/PlanDto.java

@@ -22,7 +22,7 @@ public class PlanDto  implements Serializable {
      * apiId
      * apiId
      *
      *
      * */
      * */
-    private Long apiId;
+    private Integer apiId;
     /**
     /**
      * 推广计划id
      * 推广计划id
      * */
      * */

+ 11 - 0
egress-gateway-service-infrastructure/src/main/java/com/hrsk/cloud/eg/infrastructure/constant/RedisConstant.java

@@ -0,0 +1,11 @@
+package com.hrsk.cloud.eg.infrastructure.constant;
+
+/**
+ * @author zhangyy
+ * @version 1.0
+ * @description: RedisConstant
+ * @date 2024/9/13 09:45
+ */
+public class RedisConstant {
+  public static   String BUSINESS_API_KEY="business:api:%s";
+}

+ 7 - 0
egress-gateway-service-infrastructure/src/main/java/com/hrsk/cloud/eg/infrastructure/service/ProductBusinessApiInfoService.java

@@ -28,5 +28,12 @@ public interface ProductBusinessApiInfoService extends IService<ProductBusinessA
      * @version 1.0
      * @version 1.0
      */
      */
     List<ProductBusinessApiInfoDo> selectByJointJonintTypeForList(String huizhong);
     List<ProductBusinessApiInfoDo> selectByJointJonintTypeForList(String huizhong);
+
+    /**
+     * 缓存对应的api对接数据
+     * @param apiId
+     * @return
+     */
+    ProductBusinessApiInfoDo getApiInfoByRedis(Integer apiId);
 }
 }
 
 

+ 23 - 1
egress-gateway-service-infrastructure/src/main/java/com/hrsk/cloud/eg/infrastructure/service/impl/ProductBusinessApiInfoServiceImpl.java

@@ -1,18 +1,24 @@
 package com.hrsk.cloud.eg.infrastructure.service.impl;
 package com.hrsk.cloud.eg.infrastructure.service.impl;
 
 
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.hrsk.cloud.eg.infrastructure.repository.database.entity.ProductBusinessApiInfoDo;
 import com.hrsk.cloud.eg.infrastructure.repository.database.entity.ProductBusinessApiInfoDo;
 import com.hrsk.cloud.eg.infrastructure.repository.database.mapper.ProductBusinessApiInfoMapper;
 import com.hrsk.cloud.eg.infrastructure.repository.database.mapper.ProductBusinessApiInfoMapper;
 import com.hrsk.cloud.eg.infrastructure.service.ProductBusinessApiInfoService;
 import com.hrsk.cloud.eg.infrastructure.service.ProductBusinessApiInfoService;
+import com.hrsk.cloud.eg.infrastructure.utils.RedisUtil;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.CollectionUtils;
 
 
+import javax.annotation.Resource;
 import java.util.Collections;
 import java.util.Collections;
 import java.util.List;
 import java.util.List;
 
 
+import static com.hrsk.cloud.eg.infrastructure.constant.RedisConstant.BUSINESS_API_KEY;
+
 /**
 /**
  * 商户对接配置信息表业务层
  * 商户对接配置信息表业务层
  *
  *
@@ -23,6 +29,8 @@ import java.util.List;
 @Service
 @Service
 public class ProductBusinessApiInfoServiceImpl extends ServiceImpl<ProductBusinessApiInfoMapper, ProductBusinessApiInfoDo> implements ProductBusinessApiInfoService {
 public class ProductBusinessApiInfoServiceImpl extends ServiceImpl<ProductBusinessApiInfoMapper, ProductBusinessApiInfoDo> implements ProductBusinessApiInfoService {
 
 
+    @Resource
+    private RedisUtil redisUtil;
 
 
     @Override
     @Override
     public List<ProductBusinessApiInfoDo> selectByJointCodeForList(String apiCode) {
     public List<ProductBusinessApiInfoDo> selectByJointCodeForList(String apiCode) {
@@ -47,4 +55,18 @@ public class ProductBusinessApiInfoServiceImpl extends ServiceImpl<ProductBusine
         }
         }
         return productBusinessApiInfoDos;
         return productBusinessApiInfoDos;
     }
     }
+
+    @Override
+    public ProductBusinessApiInfoDo getApiInfoByRedis(Integer apiId) {
+        String key = String.format(BUSINESS_API_KEY, apiId);
+        Object value = redisUtil.get(key);
+        if (null == value || StringUtils.isBlank((String) value)) {
+            ProductBusinessApiInfoDo api = getById(apiId);
+            if (null != api) {
+                redisUtil.set(key, JSON.toJSONString(api));
+            }
+            return api;
+        }
+        return JSONObject.parseObject((String) value, ProductBusinessApiInfoDo.class);
+    }
 }
 }