Commit c2987ff257401c27907f52ba68f305e15114fa5e

Authored by 杨鸣坤
1 parent f4b9cc4b

新康达数据同步接口开发

@@ -35,6 +35,65 @@ @@ -35,6 +35,65 @@
35 <artifactId>spring-boot-starter-test</artifactId> 35 <artifactId>spring-boot-starter-test</artifactId>
36 <scope>test</scope> 36 <scope>test</scope>
37 </dependency> 37 </dependency>
  38 + <dependency>
  39 + <groupId>com.zaxxer</groupId>
  40 + <artifactId>HikariCP</artifactId>
  41 + <version>4.0.3</version>
  42 + </dependency>
  43 + <dependency>
  44 + <groupId>com.zaxxer</groupId>
  45 + <artifactId>HikariCP-java7</artifactId>
  46 + <version>2.4.13</version>
  47 + </dependency>
  48 + <dependency>
  49 + <groupId>org.postgresql</groupId>
  50 + <artifactId>postgresql</artifactId>
  51 + <version>42.7.3</version>
  52 + </dependency>
  53 + <dependency>
  54 + <groupId>org.apache.httpcomponents</groupId>
  55 + <artifactId>httpclient</artifactId>
  56 + <version>4.5.8</version>
  57 + </dependency>
  58 + <!--工具类-->
  59 + <dependency>
  60 + <groupId>org.apache.commons</groupId>
  61 + <artifactId>commons-lang3</artifactId>
  62 + <version>3.6</version>
  63 + </dependency>
  64 +
  65 + <!--工具类-->
  66 + <dependency>
  67 + <groupId>org.apache.commons</groupId>
  68 + <artifactId>commons-collections4</artifactId>
  69 + <version>4.2</version>
  70 + </dependency>
  71 +
  72 + <dependency>
  73 + <groupId>com.alibaba</groupId>
  74 + <artifactId>fastjson</artifactId>
  75 + <version>1.2.60</version>
  76 + </dependency>
  77 + <dependency>
  78 + <groupId>org.springframework.boot</groupId>
  79 + <artifactId>spring-boot-starter-data-redis</artifactId>
  80 + <version>2.0.9.RELEASE</version>
  81 + </dependency>
  82 + <dependency>
  83 + <groupId>redis.clients</groupId>
  84 + <artifactId>jedis</artifactId>
  85 + <version>2.9.0</version>
  86 + </dependency>
  87 + <dependency>
  88 + <groupId>org.eclipse.paho</groupId>
  89 + <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
  90 + <version>1.2.5</version>
  91 + </dependency>
  92 + <dependency>
  93 + <groupId>org.apache.poi</groupId>
  94 + <artifactId>poi-ooxml</artifactId>
  95 + <version>5.2.5</version> <!-- 建议使用最新稳定版 -->
  96 + </dependency>
38 </dependencies> 97 </dependencies>
39 98
40 <build> 99 <build>
1 package com.iot.scheduler.controller; 1 package com.iot.scheduler.controller;
2 2
  3 +import com.iot.scheduler.service.XinkangdaDeviceReportService;
  4 +import jakarta.annotation.Resource;
3 import org.springframework.web.bind.annotation.GetMapping; 5 import org.springframework.web.bind.annotation.GetMapping;
4 import org.springframework.web.bind.annotation.RestController; 6 import org.springframework.web.bind.annotation.RestController;
5 7
6 @RestController 8 @RestController
7 public class HealthController { 9 public class HealthController {
8 10
  11 + @Resource
  12 + private XinkangdaDeviceReportService xinkangdaDeviceReportService;
  13 +
9 @GetMapping("/health") 14 @GetMapping("/health")
10 public String health() { 15 public String health() {
11 return "IoT Scheduler is running..."; 16 return "IoT Scheduler is running...";
12 } 17 }
  18 +
  19 + @GetMapping("/xkdDeviceRegister")
  20 + public void xkdDeviceRegister() {
  21 + xinkangdaDeviceReportService.batchDeviceReport();
  22 + }
13 } 23 }
  1 +package com.iot.scheduler.model;
  2 +
  3 +import lombok.Data;
  4 +
  5 +/**
  6 + * 设备属性
  7 + */
  8 +@Data
  9 +public class XkdDeviceData {
  10 +
  11 + /**
  12 + * 已注册的设备唯一标识
  13 + */
  14 + private String deviceId;
  15 +
  16 + /**
  17 + * 数据批次(如8位日期20260202+自增序列号;每批次次上传都是新的)
  18 + */
  19 + private String dataBatch;
  20 +
  21 + /**
  22 + * 数据采集时间,ISO 8601 格式(如 "2026-02-09T13:00:00+08:00")
  23 + */
  24 + private String collectionTime;
  25 +
  26 + /**
  27 + * 设备状态:取值:RUN(运行),OFF(关机),ERROR(故障),STAND(待机)
  28 + */
  29 + private String status;
  30 +
  31 + /**
  32 + * 是否报警:true 表示报警(对应 1),false 表示正常(对应 0)
  33 + */
  34 + private boolean alarm;
  35 +
  36 + /**
  37 + * 报警类型名称,即使无报警,alarm 和 alarmName也必须提供
  38 + */
  39 + private String alarmName;
  40 +
  41 + /**
  42 + * 效率
  43 + */
  44 + private Double efficiency;
  45 +}
  1 +package com.iot.scheduler.model;
  2 +
  3 +import lombok.Data;
  4 +
  5 +/**
  6 + * 设备信息
  7 + */
  8 +@Data
  9 +public class XkdDeviceInfo {
  10 +
  11 + /**
  12 + * 设备唯一标识(由企业自定义,全局唯一 建议:企业首字母缩写+8位数字)
  13 + */
  14 + private String deviceId;
  15 +
  16 + /**
  17 + * 设备名称
  18 + */
  19 + private String deviceName;
  20 +
  21 + /**
  22 + * 设备类型:取值:1(加工设备),2(装配设备),3(检测设备),4(辅助设备)
  23 + */
  24 + private String deviceType;
  25 +
  26 + /**
  27 + * 安装位置(建议格式:楼栋-楼层-区域)
  28 + */
  29 + private String location;
  30 +}
  1 +package com.iot.scheduler.service;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.iot.scheduler.model.XkdDeviceData;
  5 +import com.iot.scheduler.model.XkdDeviceInfo;
  6 +import com.zaxxer.hikari.HikariConfig;
  7 +import com.zaxxer.hikari.HikariDataSource;
  8 +import lombok.extern.slf4j.Slf4j;
  9 +import org.apache.http.Consts;
  10 +import org.apache.http.HttpEntity;
  11 +import org.apache.http.client.methods.CloseableHttpResponse;
  12 +import org.apache.http.client.methods.HttpPost;
  13 +import org.apache.http.entity.ContentType;
  14 +import org.apache.http.entity.StringEntity;
  15 +import org.apache.http.impl.client.CloseableHttpClient;
  16 +import org.apache.http.impl.client.HttpClients;
  17 +import org.apache.poi.ss.usermodel.Row;
  18 +import org.apache.poi.ss.usermodel.Sheet;
  19 +import org.apache.poi.ss.usermodel.Workbook;
  20 +import org.apache.poi.ss.usermodel.WorkbookFactory;
  21 +import org.springframework.beans.factory.annotation.Value;
  22 +import org.springframework.stereotype.Service;
  23 +
  24 +import java.io.*;
  25 +import java.sql.*;
  26 +import java.text.SimpleDateFormat;
  27 +import java.time.ZonedDateTime;
  28 +import java.time.format.DateTimeFormatter;
  29 +import java.util.*;
  30 +import java.util.Date;
  31 +
  32 +/**
  33 + * 新康达设备属性上报
  34 + */
  35 +@Service
  36 +@Slf4j
  37 +public class XinkangdaDeviceReportService {
  38 +
  39 + @Value("${xkd.third.devicesRegisterUrl:http://117.64.210.63:8087/api/v1/devices/register}")
  40 + private String devicesRegisterUrl;
  41 +
  42 + @Value("${xkd.third.dataUploadUrl:http://117.64.210.63:8087/api/v1/data/upload}")
  43 + private String dataUploadUrl;
  44 +
  45 + @Value("${xkd.third.enterpriseId:PLMOKNJIB8}")
  46 + private String enterpriseId;
  47 +
  48 + @Value("${xkd.third.apiKey:UiOpAsDfGhJkLzXcVbNmQwEr6TyUiOpAsD}")
  49 + private String apiKey;
  50 +
  51 + @Value("${xkd.third.jdbcUrl:jdbc:postgresql://192.168.0.61:5433/thingskit}")
  52 + private String jdbcUrl;
  53 +
  54 + @Value("${xkd.third.jdbcUserName:postgres}")
  55 + private String jdbcUserName;
  56 +
  57 + @Value("${xkd.third.jdbcPassword:postgres}")
  58 + private String jdbcPassword;
  59 +
  60 + @Value("${xkd.third.selectSql:SELECT * FROM ts_kv_dictionary;}")
  61 + private String selectSql;
  62 +
  63 +
  64 + /**
  65 + * 批量企业设备上报
  66 + */
  67 + public void batchDeviceReport() {
  68 + List<Object> needSyncDataList = initConnectAndSelectData();
  69 + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
  70 + String dataBatch = simpleDateFormat.format(new Date());
  71 +
  72 + ZonedDateTime now = ZonedDateTime.now();
  73 + String iso8601 = now.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
  74 + for (int i = 0; i < needSyncDataList.size(); i++) {
  75 + Object needSyncData = needSyncDataList.get(i);
  76 + try {
  77 + List<Object> dataList = (ArrayList) needSyncData;
  78 + String deviceId = dataList.get(0).toString();
  79 +
  80 + log.info("开始处理设备[{}]的数据,进度: {}/{}", deviceId, i + 1, needSyncDataList.size());
  81 +
  82 + XkdDeviceData data = new XkdDeviceData();
  83 + data.setDeviceId(deviceId);
  84 + String status = dataList.get(2).toString();
  85 + data.setStatus(status);
  86 + data.setDataBatch(dataBatch);
  87 + data.setCollectionTime(iso8601);
  88 + data.setAlarm(false);
  89 + data.setAlarmName("无");
  90 + data.setEfficiency(86.7D);
  91 +
  92 + boolean sendResult = sendDataUpload(data);
  93 + } catch (Exception e) {
  94 +
  95 + }
  96 + }
  97 + }
  98 +
  99 + private List<Object> initConnectAndSelectData() {
  100 + Connection connection = null;
  101 + PreparedStatement statement = null;
  102 + ResultSet resultSet = null;
  103 + HikariDataSource dataSource = null;
  104 + List<Object> resultList = new ArrayList<>();
  105 +
  106 + log.info("开始连接数据库,URL: {}", jdbcUrl);
  107 +
  108 + try {
  109 + HikariConfig config = new HikariConfig();
  110 + config.setJdbcUrl(jdbcUrl);
  111 + config.setUsername(jdbcUserName);
  112 + config.setPassword(jdbcPassword);
  113 + config.setDriverClassName("org.postgresql.Driver");
  114 + config.setMaximumPoolSize(5);
  115 + config.setMinimumIdle(5);
  116 + config.setConnectionTimeout(60000);
  117 + config.setConnectionTestQuery("SELECT 1");
  118 +
  119 + dataSource = new HikariDataSource(config);
  120 + log.info("Hikari连接池配置完成");
  121 +
  122 + connection = dataSource.getConnection();
  123 + log.info("数据库连接成功");
  124 +
  125 + statement = connection.prepareStatement(selectSql);
  126 + log.info("执行SQL查询: {}", selectSql);
  127 +
  128 + resultSet = statement.executeQuery();
  129 + ResultSetMetaData metaData = resultSet.getMetaData();
  130 + int columnCount = metaData.getColumnCount();
  131 + log.info("查询结果集元数据获取成功,共{}列", columnCount);
  132 +
  133 + int rowCount = 0;
  134 + while (resultSet.next()) {
  135 + List<Object> result = new ArrayList<>(columnCount);
  136 + for (int index = 1; index <= columnCount; index++) {
  137 + int columnType = metaData.getColumnType(index);
  138 + Object value = getTypedValue(resultSet, index, columnType);
  139 + result.add(value);
  140 + }
  141 + resultList.add(result);
  142 + rowCount++;
  143 +
  144 + // 每处理1000行记录一次日志
  145 + if (rowCount % 1000 == 0) {
  146 + log.info("已处理{}行数据", rowCount);
  147 + }
  148 + }
  149 +
  150 + log.info("数据查询完成,共获取{}行数据", rowCount);
  151 +
  152 + } catch (SQLException e) {
  153 + log.error("数据库操作异常,URL: {}, 用户名: {}", jdbcUrl, jdbcUserName, e);
  154 + } catch (Exception e) {
  155 + log.error("初始化数据库连接或查询数据时发生异常", e);
  156 + } finally {
  157 + // 释放资源
  158 + try {
  159 + if (resultSet != null) resultSet.close();
  160 + if (statement != null) statement.close();
  161 + if (connection != null) connection.close();
  162 + log.info("数据库连接资源已释放");
  163 + } catch (SQLException e) {
  164 + log.error("关闭数据库资源时发生异常", e);
  165 + }
  166 +
  167 + if (dataSource != null) {
  168 + try {
  169 + dataSource.close();
  170 + log.info("HikariDataSource连接池已关闭");
  171 + } catch (Exception e) {
  172 + log.error("关闭HikariDataSource连接池时发生异常", e);
  173 + }
  174 + }
  175 + }
  176 +
  177 + log.info("数据库操作完成,返回{}条记录", resultList.size());
  178 + return resultList;
  179 + }
  180 +
  181 + private Object getTypedValue(ResultSet rs, int index, int sqlType) throws SQLException {
  182 + Object value;
  183 +
  184 + try {
  185 + switch (sqlType) {
  186 + case Types.BIT:
  187 + case Types.BOOLEAN:
  188 + value = rs.getBoolean(index);
  189 + return rs.wasNull() ? null : value;
  190 +
  191 + case Types.TINYINT:
  192 + case Types.SMALLINT:
  193 + case Types.INTEGER:
  194 + value = rs.getInt(index);
  195 + return rs.wasNull() ? null : value;
  196 +
  197 + case Types.BIGINT:
  198 + value = rs.getLong(index);
  199 + return rs.wasNull() ? null : value;
  200 +
  201 + case Types.FLOAT:
  202 + case Types.REAL:
  203 + value = rs.getFloat(index);
  204 + return rs.wasNull() ? null : value;
  205 +
  206 + case Types.DOUBLE:
  207 + value = rs.getDouble(index);
  208 + return rs.wasNull() ? null : value;
  209 +
  210 + case Types.NUMERIC:
  211 + case Types.DECIMAL:
  212 + value = rs.getBigDecimal(index);
  213 + return rs.wasNull() ? null : value;
  214 +
  215 + case Types.CHAR:
  216 + case Types.VARCHAR:
  217 + case Types.LONGVARCHAR:
  218 + case Types.NCHAR:
  219 + case Types.NVARCHAR:
  220 + case Types.LONGNVARCHAR:
  221 + value = rs.getString(index);
  222 + return rs.wasNull() ? null : value;
  223 +
  224 + case Types.DATE:
  225 + java.sql.Date date = rs.getDate(index);
  226 + return date != null ? date.toLocalDate() : null;
  227 +
  228 + case Types.TIME:
  229 + Time time = rs.getTime(index);
  230 + return time != null ? time.toLocalTime() : null;
  231 +
  232 + case Types.TIMESTAMP:
  233 + Timestamp timestamp = rs.getTimestamp(index);
  234 + return timestamp != null ? timestamp.toLocalDateTime() : null;
  235 +
  236 + case Types.BINARY:
  237 + case Types.VARBINARY:
  238 + case Types.LONGVARBINARY:
  239 + value = rs.getBytes(index);
  240 + return rs.wasNull() ? null : value;
  241 +
  242 + case Types.BLOB:
  243 + value = rs.getBlob(index);
  244 + return rs.wasNull() ? null : value;
  245 +
  246 + case Types.CLOB:
  247 + value = rs.getClob(index);
  248 + return rs.wasNull() ? null : value;
  249 +
  250 + default:
  251 + value = rs.getObject(index);
  252 + return rs.wasNull() ? null : value;
  253 + }
  254 + } catch (SQLException e) {
  255 + log.error("获取结果集第{}列数据时发生异常,数据类型: {}", index, sqlType, e);
  256 + throw e;
  257 + }
  258 + }
  259 +
  260 +// private void dataUpload(XkdDeviceInfo info) {
  261 +// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
  262 +// String dataBatch = simpleDateFormat.format(new Date());
  263 +// XkdDeviceData data = new XkdDeviceData();
  264 +// data.setDeviceId(info.getDeviceId());
  265 +// data.setDataBatch(dataBatch);
  266 +// ZonedDateTime now = ZonedDateTime.now();
  267 +// String iso8601 = now.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
  268 +// data.setCollectionTime(iso8601);
  269 +// data.setStatus("RUN");
  270 +// data.setAlarm(false);
  271 +// data.setAlarmName("无");
  272 +// data.setEfficiency(78D);
  273 +//
  274 +// sendDataUpload(data);
  275 +// }
  276 +
  277 + private boolean sendDataUpload(XkdDeviceData data) {
  278 + String deviceId = data.getDeviceId();
  279 + log.info("开始上报设备[{}]的数据,请求URL: {}", deviceId, dataUploadUrl);
  280 +
  281 + HttpPost httpPost = new HttpPost(dataUploadUrl);
  282 + CloseableHttpClient httpClient = HttpClients.createDefault();
  283 + String requestBody = JSON.toJSONString(data);
  284 +
  285 + log.info("设备[{}]上报请求体: {}", deviceId, requestBody);
  286 +
  287 + StringEntity entity = new StringEntity(requestBody, ContentType.create("application/json", Consts.UTF_8));
  288 + httpPost.setEntity(entity);
  289 + httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
  290 + httpPost.setHeader("X-Enterprise-ID", enterpriseId);
  291 + httpPost.setHeader("X-API-Key", apiKey);
  292 +
  293 + try (CloseableHttpResponse execute = httpClient.execute(httpPost)) {
  294 + int statusCode = execute.getStatusLine().getStatusCode();
  295 +
  296 + HttpEntity res = execute.getEntity();
  297 + String responseBody = "";
  298 + if (res != null) {
  299 + try (InputStream is = res.getContent();
  300 + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
  301 + byte[] buf = new byte[128];
  302 + int len;
  303 + while ((len = is.read(buf)) != -1) {
  304 + byteArrayOutputStream.write(buf, 0, len);
  305 + }
  306 + responseBody = byteArrayOutputStream.toString("UTF-8");
  307 + }
  308 + }
  309 +
  310 + log.info("设备[{}]上报响应,状态码: {},响应内容: {}", deviceId, statusCode, responseBody);
  311 +
  312 + if (statusCode >= 200 && statusCode < 300) {
  313 + return true;
  314 + } else {
  315 + log.error("设备[{}]上报失败,HTTP状态码: {},响应: {}", deviceId, statusCode, responseBody);
  316 + return false;
  317 + }
  318 +
  319 + } catch (IOException e) {
  320 + log.error("设备[{}]上报请求发生IO异常", deviceId, e);
  321 + return false;
  322 + } finally {
  323 + try {
  324 + httpClient.close();
  325 + } catch (IOException e) {
  326 + log.error("关闭HTTP客户端时发生异常", e);
  327 + }
  328 + }
  329 + }
  330 +
  331 + // 设备注册,只需要执行一次,本地执行完成
  332 + public void devicesRegister() {
  333 + String filePath = "C:\\Users\\PC\\Desktop\\xdkdevice.xlsx";
  334 + try (InputStream in = new FileInputStream(new File(filePath));
  335 + // 使用 WorkbookFactory 自动根据文件格式创建合适的 Workbook
  336 + Workbook workbook = WorkbookFactory.create(in)) {
  337 + Sheet sheet = workbook.getSheetAt(0);
  338 + int lastRowNum = sheet.getLastRowNum();
  339 + for (int index = 1; index <= lastRowNum; index++) {
  340 + Row row = sheet.getRow(index);
  341 + XkdDeviceInfo info = new XkdDeviceInfo();
  342 + info.setDeviceId(row.getCell(4).getStringCellValue());
  343 + info.setDeviceName(row.getCell(3).getStringCellValue());
  344 + info.setDeviceType(row.getCell(5).getStringCellValue());
  345 + info.setLocation(row.getCell(1).getStringCellValue() + "-" + row.getCell(2).getStringCellValue());
  346 + sendReportDevice(info);
  347 +// dataUpload(info);
  348 + }
  349 + } catch (Exception e) {
  350 + e.printStackTrace();
  351 + }
  352 + }
  353 +
  354 + private boolean sendReportDevice(XkdDeviceInfo info) {
  355 + String deviceId = info.getDeviceId();
  356 + log.info("开始上报设备[{}]的数据,请求URL: {}", deviceId, devicesRegisterUrl);
  357 +
  358 + HttpPost httpPost = new HttpPost(devicesRegisterUrl);
  359 + CloseableHttpClient httpClient = HttpClients.createDefault();
  360 + String requestBody = JSON.toJSONString(info);
  361 +
  362 + log.info("设备[{}]上报请求体: {}", deviceId, requestBody);
  363 +
  364 + StringEntity entity = new StringEntity(requestBody, ContentType.create("application/json", Consts.UTF_8));
  365 + httpPost.setEntity(entity);
  366 + httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
  367 + httpPost.setHeader("X-Enterprise-ID", enterpriseId);
  368 + httpPost.setHeader("X-API-Key", apiKey);
  369 +
  370 + try (CloseableHttpResponse execute = httpClient.execute(httpPost)) {
  371 + int statusCode = execute.getStatusLine().getStatusCode();
  372 +
  373 + HttpEntity res = execute.getEntity();
  374 + String responseBody = "";
  375 + if (res != null) {
  376 + try (InputStream is = res.getContent();
  377 + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
  378 + byte[] buf = new byte[128];
  379 + int len;
  380 + while ((len = is.read(buf)) != -1) {
  381 + byteArrayOutputStream.write(buf, 0, len);
  382 + }
  383 + responseBody = byteArrayOutputStream.toString("UTF-8");
  384 + }
  385 + }
  386 +
  387 + log.info("设备[{}]上报响应,状态码: {},响应内容: {}", deviceId, statusCode, responseBody);
  388 +
  389 + if (statusCode >= 200 && statusCode < 300) {
  390 + return true;
  391 + } else {
  392 + log.error("设备[{}]上报失败,HTTP状态码: {},响应: {}", deviceId, statusCode, responseBody);
  393 + return false;
  394 + }
  395 +
  396 + } catch (IOException e) {
  397 + log.error("设备[{}]上报请求发生IO异常", deviceId, e);
  398 + return false;
  399 + } finally {
  400 + try {
  401 + httpClient.close();
  402 + } catch (IOException e) {
  403 + log.error("关闭HTTP客户端时发生异常", e);
  404 + }
  405 + }
  406 + }
  407 +}
@@ -11,23 +11,23 @@ public class ChizhouZoneScheduler extends AbstractZoneScheduler { @@ -11,23 +11,23 @@ public class ChizhouZoneScheduler extends AbstractZoneScheduler {
11 11
12 @Override 12 @Override
13 protected String getZoneName() { 13 protected String getZoneName() {
14 - return "Chizhou (池州经开区)"; 14 + return "xkd (新康达)";
15 } 15 }
16 16
17 - @Scheduled(cron = "${scheduler.chizhou.pull:0 0/10 * * * ?}")  
18 - public void pullDevicesFromThirdParty() {  
19 - String taskName = "Pull Devices (3rd Party -> IoT)";  
20 - logStart(taskName);  
21 - try {  
22 - // TODO: Implement actual logic  
23 - log.info("[{}] Simulating pulling devices...", getZoneName());  
24 - Thread.sleep(1000);  
25 - } catch (Exception e) {  
26 - logError(taskName, e);  
27 - } finally {  
28 - logEnd(taskName);  
29 - }  
30 - } 17 +// @Scheduled(cron = "${scheduler.chizhou.pull:0 0/10 * * * ?}")
  18 +// public void pullDevicesFromThirdParty() {
  19 +// String taskName = "Pull Devices (3rd Party -> IoT)";
  20 +// logStart(taskName);
  21 +// try {
  22 +// // TODO: Implement actual logic
  23 +// log.info("[{}] Simulating pulling devices...", getZoneName());
  24 +// Thread.sleep(1000);
  25 +// } catch (Exception e) {
  26 +// logError(taskName, e);
  27 +// } finally {
  28 +// logEnd(taskName);
  29 +// }
  30 +// }
31 31
32 @Scheduled(cron = "${scheduler.chizhou.push:0 0/15 * * * ?}") 32 @Scheduled(cron = "${scheduler.chizhou.push:0 0/15 * * * ?}")
33 public void pushDevicesToThirdParty() { 33 public void pushDevicesToThirdParty() {
@@ -5,7 +5,7 @@ spring: @@ -5,7 +5,7 @@ spring:
5 banner-mode: off 5 banner-mode: off
6 6
7 server: 7 server:
8 - port: 8080 8 + port: 33221
9 9
10 logging: 10 logging:
11 level: 11 level:
@@ -24,3 +24,24 @@ scheduler: @@ -24,3 +24,24 @@ scheduler:
24 panji: 24 panji:
25 pull: "0 0/5 * * * ?" 25 pull: "0 0/5 * * * ?"
26 push: "0 0/10 * * * ?" 26 push: "0 0/10 * * * ?"
  27 +
  28 +xkd:
  29 + third:
  30 + devicesRegisterUrl: "http://117.64.210.63:8087/api/v1/devices/register"
  31 + dataUploadUrl: "http://117.64.210.63:8087/api/v1/data/upload"
  32 + enterpriseId: "PLMOKNJIB8"
  33 + apiKey: "UiOpAsDfGhJkLzXcVbNmQwEr6TyUiOpAsD"
  34 + jdbcUrl: "jdbc:postgresql://192.168.0.61:5433/thingskit"
  35 + jdbcUserName: "postgres"
  36 + jdbcPassword: "postgres"
  37 + selectSql: "SELECT
  38 + dc.credentials_id AS deviceId,
  39 + de.name AS deviceName
  40 +FROM
  41 + device de
  42 + LEFT JOIN tk_organization tko ON de.organization_id = tko.id
  43 + LEFT JOIN ts_kv_latest tkl ON de.id = tkl.entity_id AND tkl.KEY = 61
  44 + LEFT JOIN device_credentials dc ON de.id = dc.device_id
  45 +WHERE
  46 + de.tenant_id = '0414df80-f01d-11f0-9cb8-e3376d1e7978'
  47 + AND de.device_profile_id = '0418b010-f01d-11f0-9cb8-e3376d1e7978'"
No preview for this file type