【数据资产】
1、新增外部调用模块
Showing
5 changed files
with
10 additions
and
201 deletions
| ... | @@ -52,6 +52,11 @@ | ... | @@ -52,6 +52,11 @@ |
| 52 | <version>${cabr-package.version}</version> | 52 | <version>${cabr-package.version}</version> |
| 53 | </dependency> | 53 | </dependency> |
| 54 | <dependency> | 54 | <dependency> |
| 55 | <groupId>com.csbr.qingcloud</groupId> | ||
| 56 | <artifactId>csbr-cloud-external</artifactId> | ||
| 57 | <version>${cabr-package.version}</version> | ||
| 58 | </dependency> | ||
| 59 | <dependency> | ||
| 55 | <groupId>org.springframework.boot</groupId> | 60 | <groupId>org.springframework.boot</groupId> |
| 56 | <artifactId>spring-boot-starter-undertow</artifactId> | 61 | <artifactId>spring-boot-starter-undertow</artifactId> |
| 57 | </dependency> | 62 | </dependency> | ... | ... |
| 1 | package com.csbr.qingcloud.portal.config; | ||
| 2 | |||
| 3 | import lombok.Data; | ||
| 4 | import org.springframework.boot.context.properties.ConfigurationProperties; | ||
| 5 | import org.springframework.stereotype.Component; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * @program: | ||
| 9 | * @description: 数据港配置 | ||
| 10 | * @author: yio | ||
| 11 | * @create: 2024-05-31 14:16 | ||
| 12 | **/ | ||
| 13 | @Component | ||
| 14 | @ConfigurationProperties(prefix = "dataport") | ||
| 15 | @Data | ||
| 16 | public class DataPortConfig { | ||
| 17 | private String username; | ||
| 18 | private String password; | ||
| 19 | private String authKey; | ||
| 20 | private String registerAuthKey; | ||
| 21 | private String requestUri; | ||
| 22 | private String operatorRegisterUri; | ||
| 23 | private String enterpriseRegisterUri; | ||
| 24 | private String operatorUpdateUri; | ||
| 25 | private String enterpriseUpdateUri; | ||
| 26 | private String connectorRegisterUri; | ||
| 27 | private String destroyConnector; | ||
| 28 | } |
| 1 | package com.csbr.qingcloud.portal.domain.vo.dataPort; | ||
| 2 | |||
| 3 | import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | import lombok.Data; | ||
| 5 | |||
| 6 | import java.io.Serializable; | ||
| 7 | |||
| 8 | /** | ||
| 9 | * @program: | ||
| 10 | * @description: 数据港返回结果 | ||
| 11 | * @author: makejava | ||
| 12 | * @create: 2025-09-05 10:35 | ||
| 13 | **/ | ||
| 14 | @Data | ||
| 15 | @Schema(title = "数据港返回结果") | ||
| 16 | public class DataPortRes<T> implements Serializable { | ||
| 17 | |||
| 18 | /** | ||
| 19 | * 返回码 | ||
| 20 | */ | ||
| 21 | @Schema(description = "返回码") | ||
| 22 | private Integer code; | ||
| 23 | |||
| 24 | /** | ||
| 25 | * 返回描述 | ||
| 26 | */ | ||
| 27 | @Schema(description = "返回描述") | ||
| 28 | private String message; | ||
| 29 | |||
| 30 | /** | ||
| 31 | * 数据 | ||
| 32 | */ | ||
| 33 | @Schema(description = "数据") | ||
| 34 | private T data; | ||
| 35 | |||
| 36 | public DataPortRes(Integer code, T data){ | ||
| 37 | this.code = code; | ||
| 38 | this.data = data; | ||
| 39 | } | ||
| 40 | |||
| 41 | public DataPortRes(Integer code, String message){ | ||
| 42 | this.code = code; | ||
| 43 | this.message = message; | ||
| 44 | } | ||
| 45 | |||
| 46 | /** | ||
| 47 | * 返回成功 | ||
| 48 | * @param data | ||
| 49 | * @param <T> | ||
| 50 | * @return | ||
| 51 | */ | ||
| 52 | public static <T> DataPortRes<T> success(T data) { | ||
| 53 | return new DataPortRes<T>(200, data); | ||
| 54 | } | ||
| 55 | |||
| 56 | /** | ||
| 57 | * 返回失败 | ||
| 58 | * @param message | ||
| 59 | * @return | ||
| 60 | */ | ||
| 61 | public static DataPortRes fail(String message) { | ||
| 62 | return new DataPortRes(500, message); | ||
| 63 | } | ||
| 64 | } |
| ... | @@ -6,9 +6,9 @@ import com.alibaba.fastjson.JSONObject; | ... | @@ -6,9 +6,9 @@ import com.alibaba.fastjson.JSONObject; |
| 6 | import com.csbr.cloud.common.enums.RedisKeyEnum; | 6 | import com.csbr.cloud.common.enums.RedisKeyEnum; |
| 7 | import com.csbr.cloud.common.util.CsbrBeanUtil; | 7 | import com.csbr.cloud.common.util.CsbrBeanUtil; |
| 8 | import com.csbr.cloud.distributelock.util.RedisUtil; | 8 | import com.csbr.cloud.distributelock.util.RedisUtil; |
| 9 | import com.csbr.qingcloud.portal.config.DataPortConfig; | 9 | import com.csbr.cloud.external.config.DataPortConfig; |
| 10 | import com.csbr.cloud.external.util.DataPortConnectUtil; | ||
| 10 | import com.csbr.qingcloud.portal.domain.vo.TdsConnectorAdditionalRSVO; | 11 | import com.csbr.qingcloud.portal.domain.vo.TdsConnectorAdditionalRSVO; |
| 11 | import com.csbr.qingcloud.portal.domain.vo.TdsConnectorIdentityRSVO; | ||
| 12 | import com.csbr.qingcloud.portal.domain.vo.TdsConnectorVerifiableRSVO; | 12 | import com.csbr.qingcloud.portal.domain.vo.TdsConnectorVerifiableRSVO; |
| 13 | import com.csbr.qingcloud.portal.domain.vo.dataPort.*; | 13 | import com.csbr.qingcloud.portal.domain.vo.dataPort.*; |
| 14 | import com.csbr.qingcloud.portal.mybatis.entity.MfEnterprise; | 14 | import com.csbr.qingcloud.portal.mybatis.entity.MfEnterprise; |
| ... | @@ -18,7 +18,6 @@ import com.csbr.qingcloud.portal.mybatis.service.MfTdsConnectorIdentityService; | ... | @@ -18,7 +18,6 @@ import com.csbr.qingcloud.portal.mybatis.service.MfTdsConnectorIdentityService; |
| 18 | import com.csbr.qingcloud.portal.service.DataPortService; | 18 | import com.csbr.qingcloud.portal.service.DataPortService; |
| 19 | import com.csbr.qingcloud.portal.service.TdsConnectorAdditionalService; | 19 | import com.csbr.qingcloud.portal.service.TdsConnectorAdditionalService; |
| 20 | import com.csbr.qingcloud.portal.service.TdsConnectorVerifiableService; | 20 | import com.csbr.qingcloud.portal.service.TdsConnectorVerifiableService; |
| 21 | import com.csbr.qingcloud.portal.util.DataPortConnectUtil; | ||
| 22 | import com.csbr.qingcloud.portal.util.InvokeUtil; | 21 | import com.csbr.qingcloud.portal.util.InvokeUtil; |
| 23 | import com.csbr.qingcloud.portal.util.ZQConfig; | 22 | import com.csbr.qingcloud.portal.util.ZQConfig; |
| 24 | import jakarta.annotation.Resource; | 23 | import jakarta.annotation.Resource; |
| ... | @@ -28,7 +27,9 @@ import org.apache.commons.lang3.StringUtils; | ... | @@ -28,7 +27,9 @@ import org.apache.commons.lang3.StringUtils; |
| 28 | import org.springframework.stereotype.Service; | 27 | import org.springframework.stereotype.Service; |
| 29 | 28 | ||
| 30 | import java.text.SimpleDateFormat; | 29 | import java.text.SimpleDateFormat; |
| 31 | import java.util.*; | 30 | import java.util.Date; |
| 31 | import java.util.HashMap; | ||
| 32 | import java.util.Map; | ||
| 32 | 33 | ||
| 33 | /** | 34 | /** |
| 34 | * @program: daop-projects | 35 | * @program: daop-projects | ... | ... |
| 1 | package com.csbr.qingcloud.portal.util; | ||
| 2 | |||
| 3 | import com.alibaba.fastjson.JSONObject; | ||
| 4 | import com.csbr.cloud.common.enums.SystemError; | ||
| 5 | import com.csbr.cloud.common.exception.CsbrSystemException; | ||
| 6 | import com.csbr.qingcloud.portal.config.DataPortConfig; | ||
| 7 | import com.csbr.qingcloud.portal.domain.vo.dataPort.DataPortRes; | ||
| 8 | import jakarta.annotation.Resource; | ||
| 9 | import lombok.extern.slf4j.Slf4j; | ||
| 10 | import org.apache.commons.lang3.ObjectUtils; | ||
| 11 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 12 | import org.springframework.http.HttpEntity; | ||
| 13 | import org.springframework.http.HttpHeaders; | ||
| 14 | import org.springframework.stereotype.Component; | ||
| 15 | import org.springframework.web.client.RestTemplate; | ||
| 16 | |||
| 17 | /** | ||
| 18 | * @program: daop-projects | ||
| 19 | * @description: | ||
| 20 | * @author: xiaojie | ||
| 21 | * @create: 2025-10-11 11:01 | ||
| 22 | **/ | ||
| 23 | @Slf4j | ||
| 24 | @Component | ||
| 25 | public class DataPortConnectUtil { | ||
| 26 | |||
| 27 | @Resource | ||
| 28 | private DataPortConfig dataPortConfig; | ||
| 29 | |||
| 30 | @Autowired | ||
| 31 | private RestTemplate restTemplate; | ||
| 32 | |||
| 33 | /** | ||
| 34 | * 获取数据港token | ||
| 35 | * @return | ||
| 36 | */ | ||
| 37 | public String getToken() { | ||
| 38 | HttpHeaders headers = new HttpHeaders(); | ||
| 39 | headers.set("Content-Type", "application/json"); | ||
| 40 | headers.set("authKey", dataPortConfig.getAuthKey()); | ||
| 41 | |||
| 42 | JSONObject params = new JSONObject(); | ||
| 43 | params.put("username", dataPortConfig.getUsername()); | ||
| 44 | params.put("password", dataPortConfig.getPassword()); | ||
| 45 | HttpEntity<JSONObject> request = new HttpEntity<>(params, headers); | ||
| 46 | DataPortRes dataPortRes = restTemplate.postForObject( | ||
| 47 | dataPortConfig.getRequestUri() + "/api/user/singleLogin/getThreeUserToken" | ||
| 48 | , request, DataPortRes.class); | ||
| 49 | |||
| 50 | if (ObjectUtils.isEmpty(dataPortRes)) { | ||
| 51 | throw new CsbrSystemException(SystemError.DATA_GET_ERROR, "获取token失败."); | ||
| 52 | } | ||
| 53 | if (200 != dataPortRes.getCode() && 201 != dataPortRes.getCode()) { | ||
| 54 | throw new CsbrSystemException(SystemError.DATA_GET_ERROR, dataPortRes.getMessage()); | ||
| 55 | } | ||
| 56 | return (String) dataPortRes.getData(); | ||
| 57 | } | ||
| 58 | |||
| 59 | /** | ||
| 60 | * 调用数据港接口(authKey调用) | ||
| 61 | * @return | ||
| 62 | */ | ||
| 63 | public Object postByAuthKey(Object obj, String uri) { | ||
| 64 | HttpHeaders headers = new HttpHeaders(); | ||
| 65 | headers.set("Content-Type", "application/json"); | ||
| 66 | headers.set("authKey", dataPortConfig.getRegisterAuthKey()); | ||
| 67 | |||
| 68 | HttpEntity<Object> request = new HttpEntity<>(obj, headers); | ||
| 69 | DataPortRes dataPortRes = restTemplate.postForObject( | ||
| 70 | dataPortConfig.getRequestUri() + uri | ||
| 71 | , request, DataPortRes.class); | ||
| 72 | log.info("======调用数据港接口(authKey调用)======, {}", dataPortRes); | ||
| 73 | if (ObjectUtils.isEmpty(dataPortRes)) { | ||
| 74 | throw new CsbrSystemException(SystemError.DATA_GET_ERROR, "调用数据港接口失败."); | ||
| 75 | } | ||
| 76 | if (200 != dataPortRes.getCode() && 201 != dataPortRes.getCode()) { | ||
| 77 | throw new CsbrSystemException(SystemError.DATA_GET_ERROR, dataPortRes.getMessage()); | ||
| 78 | } | ||
| 79 | return dataPortRes.getData(); | ||
| 80 | } | ||
| 81 | |||
| 82 | /** | ||
| 83 | * 调用数据港接口(Authorization调用) | ||
| 84 | * @return | ||
| 85 | */ | ||
| 86 | public Object postByAuthorization(Object obj, String uri) { | ||
| 87 | HttpHeaders headers = new HttpHeaders(); | ||
| 88 | headers.set("Content-Type", "application/json"); | ||
| 89 | headers.set("Authorization", getToken()); | ||
| 90 | |||
| 91 | HttpEntity<Object> request = new HttpEntity<>(obj, headers); | ||
| 92 | DataPortRes dataPortRes = restTemplate.postForObject( | ||
| 93 | dataPortConfig.getRequestUri() + uri | ||
| 94 | , request, DataPortRes.class); | ||
| 95 | log.info("======调用数据港接口(Authorization调用)======, {}", dataPortRes); | ||
| 96 | if (ObjectUtils.isEmpty(dataPortRes)) { | ||
| 97 | throw new CsbrSystemException(SystemError.DATA_GET_ERROR, "调用数据港接口失败."); | ||
| 98 | } | ||
| 99 | if (200 != dataPortRes.getCode() && 201 != dataPortRes.getCode()) { | ||
| 100 | throw new CsbrSystemException(SystemError.DATA_GET_ERROR, dataPortRes.getMessage()); | ||
| 101 | } | ||
| 102 | return dataPortRes.getData(); | ||
| 103 | } | ||
| 104 | |||
| 105 | } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or sign in to post a comment