|
|
@@ -1,21 +1,12 @@
|
|
|
package com.shkpr.service.bespokegateway.zydma.constants;
|
|
|
|
|
|
import com.fasterxml.jackson.annotation.JsonAlias;
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.shkpr.service.bespokegateway.core.constants.*;
|
|
|
-import com.shkpr.service.bespokegateway.core.domain.CallingEndpoint;
|
|
|
-import com.shkpr.service.bespokegateway.core.domain.IntegrationKey;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.Data;
|
|
|
import lombok.Getter;
|
|
|
import lombok.Setter;
|
|
|
-import org.apache.commons.lang3.ObjectUtils;
|
|
|
-import org.apache.http.HttpHeaders;
|
|
|
-import org.apache.http.client.fluent.Request;
|
|
|
-import org.apache.http.client.fluent.Response;
|
|
|
-import org.springframework.http.MediaType;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
@@ -28,37 +19,18 @@ import java.util.stream.Collectors;
|
|
|
* @since 1.0.0
|
|
|
*/
|
|
|
public abstract class IotPlatformMetadata {
|
|
|
-
|
|
|
- private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
- private static final ObjectMapper objectMapper = new ObjectMapper();
|
|
|
-
|
|
|
- //系统名称
|
|
|
- public static String NAME = "zaoyang-iot";
|
|
|
- //最大查询小时
|
|
|
- public static int MAX_QUERY_HOU = (7 * 24) - 1;
|
|
|
-
|
|
|
/**
|
|
|
- * 获取密钥
|
|
|
+ * 系统名称
|
|
|
*/
|
|
|
- public static IntegrationKey getKey(CallingEndpoint endpoint) throws IOException {
|
|
|
- //请求token
|
|
|
- Response response = Request.Post(endpoint.getUrl() + Uri.GENERATE_TOKEN)
|
|
|
- .addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
|
|
- .bodyByteArray(objectMapper.writeValueAsBytes(
|
|
|
- new HashMap<String, String>() {{
|
|
|
- put(Params.USERNAME, endpoint.getAccessKey());
|
|
|
- put(Params.PASSWORD, endpoint.getSecretKey());
|
|
|
- }}
|
|
|
- ))
|
|
|
- .execute();
|
|
|
- //解析token
|
|
|
- TokenResult tokenResult = objectMapper.readValue(response.returnContent().asString(), TokenResult.class);
|
|
|
- TokenResult.TokenData data = tokenResult.getData();
|
|
|
- if (!tokenResult.isOk() || !ObjectUtils.allNotNull(data, data.getUserToken(), data.getTokenType(), data.getAccessToken()))
|
|
|
- return null;
|
|
|
-
|
|
|
- return new IntegrationKey(null, data.getUserToken(), null, data.getTokenType() + " " + data.getAccessToken());
|
|
|
- }
|
|
|
+ public static final String NAME = "zaoyang-iot";
|
|
|
+ /**
|
|
|
+ * 最大查询小时
|
|
|
+ */
|
|
|
+ public static final int MAX_QUERY_HOU = (7 * 24) - 1;
|
|
|
+ /**
|
|
|
+ * 日期格式
|
|
|
+ */
|
|
|
+ private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
/**
|
|
|
* 获取历史数据参数
|
|
|
@@ -190,10 +162,20 @@ public abstract class IotPlatformMetadata {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 任务key
|
|
|
+ */
|
|
|
+ public interface SchedulingKeys {
|
|
|
+ /**
|
|
|
+ * 采集物联网平台
|
|
|
+ */
|
|
|
+ String COLLECT_IOT_PLATFORM = "collect-iot-platform";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* token结果
|
|
|
*/
|
|
|
@Data
|
|
|
- private static class TokenResult {
|
|
|
+ public static class TokenResult {
|
|
|
private Integer code;
|
|
|
private String msg;
|
|
|
private TokenData data;
|
|
|
@@ -203,7 +185,7 @@ public abstract class IotPlatformMetadata {
|
|
|
}
|
|
|
|
|
|
@Data
|
|
|
- private static class TokenData {
|
|
|
+ public static class TokenData {
|
|
|
@JsonAlias("user_token")
|
|
|
private String userToken;
|
|
|
@JsonAlias("access_token")
|