Commit 22ee1f03a47179201c54e3ff961118479154d0fb

Authored by 杨鸣坤
1 parent 08f97eb0

池州修改

@@ -2,12 +2,17 @@ package com.iot.scheduler.service.chizhou; @@ -2,12 +2,17 @@ package com.iot.scheduler.service.chizhou;
2 2
3 import com.alibaba.fastjson.JSON; 3 import com.alibaba.fastjson.JSON;
4 import com.iot.scheduler.utils.MqttUtils; 4 import com.iot.scheduler.utils.MqttUtils;
  5 +import com.iot.scheduler.utils.SqlTypedValueUtils;
  6 +import com.zaxxer.hikari.HikariConfig;
  7 +import com.zaxxer.hikari.HikariDataSource;
5 import lombok.extern.slf4j.Slf4j; 8 import lombok.extern.slf4j.Slf4j;
6 import org.springframework.stereotype.Service; 9 import org.springframework.stereotype.Service;
7 10
  11 +import java.sql.*;
8 import java.text.MessageFormat; 12 import java.text.MessageFormat;
9 import java.text.SimpleDateFormat; 13 import java.text.SimpleDateFormat;
10 import java.util.*; 14 import java.util.*;
  15 +import java.util.Date;
11 16
12 /** 17 /**
13 * 池州经开区数据上传 18 * 池州经开区数据上传
@@ -20,80 +25,101 @@ public class CzDeviceReportService { @@ -20,80 +25,101 @@ public class CzDeviceReportService {
20 String username = "admin"; 25 String username = "admin";
21 String password = "ly@666yc"; 26 String password = "ly@666yc";
22 27
  28 + String jdbcUrl = "postgresql://106.15.73.210:5433/thingskit";
  29 + String jdbcUserName = "postgres";
  30 + String jdbcPassword = "postgres";
  31 + String selectSql = "SELECT\n" +
  32 + "dc.credentials_id AS sn,\n" +
  33 + "CASE\n" +
  34 + " WHEN ak2.long_v IS NULL OR (ak.bool_v = FALSE AND ak2.long_v IS NOT NULL) THEN 'OFF'\n" +
  35 + " WHEN tkl.long_v = 1 THEN 'ERROR'\n" +
  36 + " WHEN tkl2.long_v = 1 THEN 'STAND'\n" +
  37 + " WHEN tkl3.long_v = 1 THEN 'RUN'\n" +
  38 + " ELSE 'OFF'\n" +
  39 + " END AS status,\n" +
  40 + " de.organization_id\n" +
  41 + " FROM device de \n" +
  42 + "LEFT JOIN ts_kv_latest tkl on de.id = tkl.entity_id AND tkl.key = '64'\n" +
  43 + "LEFT JOIN ts_kv_latest tkl2 on de.id = tkl2.entity_id AND tkl2.key = '535'\n" +
  44 + "LEFT JOIN ts_kv_latest tkl3 on de.id = tkl3.entity_id AND tkl3.key = '534'\n" +
  45 + "LEFT JOIN attribute_kv ak ON de.id = ak.entity_id AND ak.entity_type = 'DEVICE' AND ak.attribute_key = 'active'\n" +
  46 + "LEFT JOIN attribute_kv ak2 ON de.id = ak2.entity_id AND ak2.entity_type = 'DEVICE' AND ak2.attribute_key = 'lastActivityTime'\n" +
  47 + "LEFT JOIN device_credentials dc ON de.id = dc.device_id\n" +
  48 + "WHERE (de.organization_id = '63934b6f-1e02-4d29-ac14-1a64649e2231' or de.organization_id = '35bcdb94-31ec-4750-9ee9-cc855aa66e17')\n" +
  49 + "AND de.device_profile_id = 'b2071bd0-df0b-11f0-9cb8-e3376d1e7978'\n" +
  50 + "union ALL\n" +
  51 + "SELECT \n" +
  52 + "dc.credentials_id AS sn,\n" +
  53 + "CASE\n" +
  54 + " WHEN ak2.long_v IS NULL OR (ak.bool_v = FALSE AND ak2.long_v IS NOT NULL) THEN 'OFF'\n" +
  55 + " ELSE 'RUN'\n" +
  56 + " END AS status,\n" +
  57 + " de.organization_id\n" +
  58 + "FROM device de \n" +
  59 + "LEFT JOIN attribute_kv ak ON de.id = ak.entity_id AND ak.entity_type = 'DEVICE' AND ak.attribute_key = 'active'\n" +
  60 + "LEFT JOIN attribute_kv ak2 ON de.id = ak2.entity_id AND ak2.entity_type = 'DEVICE' AND ak2.attribute_key = 'lastActivityTime'\n" +
  61 + "LEFT JOIN device_credentials dc ON de.id = dc.device_id\n" +
  62 + "WHERE (de.organization_id = '63934b6f-1e02-4d29-ac14-1a64649e2231' or de.organization_id = '35bcdb94-31ec-4750-9ee9-cc855aa66e17')\n" +
  63 + "AND (de.device_profile_id = 'fdf70e30-0272-11f1-9cb8-e3376d1e7978' OR de.device_profile_id = '6c1f9650-0298-11f1-9cb8-e3376d1e7978')\n";
  64 +
23 public void deviceReport() { 65 public void deviceReport() {
24 - List<String> deviceIdList = Arrays.asList("TCKJ-001", "TCKJ-002", "TCKJ-003", "TCKJ-004", "TCKJ-005", "TCKJ-006",  
25 - "TCKJ-007", "TCKJ-008", "TCKJ-009", "TCKJ-010", "TCKJ-011", "TCKJ-012", "TCKJ-013", "TCKJ-014", "TCKJ-015",  
26 - "TCKJ-016", "TCKJ-017", "TCKJ-018", "TCKJ-019", "TCKJ-020", "TCKJ-021", "TCKJ-022", "TCKJ-023", "TCKJ-024",  
27 - "TCKJ-025", "TCKJ-026", "TCKJ-027", "TCKJ-028", "TCKJ-029", "TCKJ-030", "TCKJ-031", "TCKJ-032", "TCKJ-033",  
28 - "TCKJ-034", "TCKJ-035", "TCKJ-036", "TCKJ-037", "TCKJ-038", "TCKJ-039", "TCKJ-040", "TCKJ-041",  
29 - "vJAzZWk1Q2I8cdq7kx3z", "LmiW3ljI4KP487CeMmol", "ceK7YSNLrTjVSSPaFmn3", "6KePBYyCiEgo10iJXIrF",  
30 - "9vrxIQhbaZ542DvCVne0", "XMLN-001", "XMLN-002", "XMLN-003", "XMLN-004", "XMLN-005", "XMLN-006", "XMLN-007",  
31 - "XMLN-008", "XMLN-009", "XMLN-010", "XMLN-011", "XMLN-012", "XMLN-013", "XMLN-014", "XMLN-015", "XMLN-016",  
32 - "XMLN-017", "XMLN-018", "XMLN-019", "XMLN-020", "XMLN-021", "XMLN-022", "XMLN-023", "XMLN-024", "XMLN-025",  
33 - "XMLN-026", "XMLN-027", "XMLN-028", "XMLN-029", "XMLN-030", "XMLN-031", "XMLN-032", "XMLN-033", "XMLN-034",  
34 - "XMLN-035", "XMLN-036", "XMLN-037", "XMLN-038", "XMLN-039", "XMLN-040", "XMLN-041", "XMLN-042", "XMLN-043",  
35 - "XMLN-044", "XMLN-045", "XMLN-046", "XMLN-047", "XMLN-048", "XMLN-049", "XMLN-050", "XMLN-051", "XMLN-052",  
36 - "GYDPF-014", "GYDPF-006", "KBS-1-1", "KBS-1-2", "KBS-3-1", "KBS-3-5", "KBS-3-3", "CS-001", "uzGf4mjzkOPwGO4aCOf3",  
37 - "GYDPF-001", "GYDPF-010", "KBS-1-5", "KBS-2-2", "KBS-3-7", "CS-003", "LBKXrYxLQN9W7qmmqzp5", "rba7VggnqGdNyPvVNs1n",  
38 - "GYDPF-002", "GYDPF-016", "GYDPF-017", "KBS-1-6", "EqFMlJarb2aDwpwvUi6J", "x2173A2HKOiPqeRsKtWY", "GYDPF-005",  
39 - "KBS-1-3", "KBS-2-1", "KBS-3-4", "1fzR6X57k2aafbbkH4po", "lbqMr5pmkNJLWEPSa0yp", "mYz1kUajPOROg0Ewcfhr",  
40 - "6TLlfKBbTMaUZGgHtvuH", "XTE8PKwLSYp29gE1umfW", "MqYu4y0OycHQkzZhothe", "IFeN0lAXlAVQ1fD7gwk1", "hZb9NsRCqtVBSagFqnPS",  
41 - "r22r53PNgY7TeqCK5y14", "KCGSwfTvGCtBfd0qsH63", "4KzFQCncmwFh7UT4vbHp", "GYDPF-007", "KBS-3-2", "t2kkUTZYqxmKLN4X4VPB",  
42 - "9vWKALGoat3XalEtQaRB", "vYtwLMkppPbM3CtB3U9U", "4vwTfMqi8oEtWxdEUrE8", "vVvK2cTLvjYtZX1dksyd", "GYDPF-003",  
43 - "KBS-3-8", "2E6eUu66qxl5Llr6ib5v", "iWbeBfwg36lIpBRMDnvO", "GYDPF-015", "KBS-2-4", "OSbA7X7FGETF0TXub4OS",  
44 - "GYDPF-008", "KBS-2-3", "KBS-2-7", "pRhGGECbXu6FBshyg2yg", "zrVVNRo8QIbjeYjdoCUq", "fjPj3oHW7cL5m0AE1t3y",  
45 - "8dJsgqjmxIIduP4Sr2rL", "GYDPF-012", "KBS-1-4", "JZ8Tbzye8rKotYTbHUJw", "dwToSYEWr04sPtBUxaOH", "GYDPF-009",  
46 - "oe3OmagW5Wi9yw9LfUr3", "2mDiH94D7uSh4CtD2bi0", "ceGyDxlK7xzMoUacIwCv", "gxECiKjMEsVkYyowKIMd", "irAqF3fmzaM5GIo8ZLAx",  
47 - "GYDPF-013", "KBS-2-5", "KBS-3-6", "dxPdbg2UqqYADPMy9TVe", "cjFUpeVPTOh4Uf6wnVH1", "VR5XgpqhFWGMcwdy8yPQ",  
48 - "GYDPF-004", "KBS-1-7", "KBS-2-8", "HEXmiSz0sXsahRHV2bQm", "0lIIGWP49Xuo91TnTvVx", "C99WsNGFSGQSV4n3YmrW",  
49 - "3paJSiHK32wvVM6f1tO8", "GYDPF-011", "KBS-1-8", "KBS-2-6", "yrk5Cxa6EJncWX2kTywa", "xOxHHscmrEBhLTlmyRrF",  
50 - "e3HzLoIl0p3iEM860EdK");  
51 -  
52 - log.info("总设备数量: {}台", deviceIdList.size()); 66 +// List<String> deviceIdList = Arrays.asList("TCKJ-001", "TCKJ-002", "TCKJ-003", "TCKJ-004", "TCKJ-005", "TCKJ-006",
  67 +// "TCKJ-007", "TCKJ-008", "TCKJ-009", "TCKJ-010", "TCKJ-011", "TCKJ-012", "TCKJ-013", "TCKJ-014", "TCKJ-015",
  68 +// "TCKJ-016", "TCKJ-017", "TCKJ-018", "TCKJ-019", "TCKJ-020", "TCKJ-021", "TCKJ-022", "TCKJ-023", "TCKJ-024",
  69 +// "TCKJ-025", "TCKJ-026", "TCKJ-027", "TCKJ-028", "TCKJ-029", "TCKJ-030", "TCKJ-031", "TCKJ-032", "TCKJ-033",
  70 +// "TCKJ-034", "TCKJ-035", "TCKJ-036", "TCKJ-037", "TCKJ-038", "TCKJ-039", "TCKJ-040", "TCKJ-041",
  71 +// "vJAzZWk1Q2I8cdq7kx3z", "LmiW3ljI4KP487CeMmol", "ceK7YSNLrTjVSSPaFmn3", "6KePBYyCiEgo10iJXIrF",
  72 +// "9vrxIQhbaZ542DvCVne0", "XMLN-001", "XMLN-002", "XMLN-003", "XMLN-004", "XMLN-005", "XMLN-006", "XMLN-007",
  73 +// "XMLN-008", "XMLN-009", "XMLN-010", "XMLN-011", "XMLN-012", "XMLN-013", "XMLN-014", "XMLN-015", "XMLN-016",
  74 +// "XMLN-017", "XMLN-018", "XMLN-019", "XMLN-020", "XMLN-021", "XMLN-022", "XMLN-023", "XMLN-024", "XMLN-025",
  75 +// "XMLN-026", "XMLN-027", "XMLN-028", "XMLN-029", "XMLN-030", "XMLN-031", "XMLN-032", "XMLN-033", "XMLN-034",
  76 +// "XMLN-035", "XMLN-036", "XMLN-037", "XMLN-038", "XMLN-039", "XMLN-040", "XMLN-041", "XMLN-042", "XMLN-043",
  77 +// "XMLN-044", "XMLN-045", "XMLN-046", "XMLN-047", "XMLN-048", "XMLN-049", "XMLN-050", "XMLN-051", "XMLN-052",
  78 +// "GYDPF-014", "GYDPF-006", "KBS-1-1", "KBS-1-2", "KBS-3-1", "KBS-3-5", "KBS-3-3", "CS-001", "uzGf4mjzkOPwGO4aCOf3",
  79 +// "GYDPF-001", "GYDPF-010", "KBS-1-5", "KBS-2-2", "KBS-3-7", "CS-003", "LBKXrYxLQN9W7qmmqzp5", "rba7VggnqGdNyPvVNs1n",
  80 +// "GYDPF-002", "GYDPF-016", "GYDPF-017", "KBS-1-6", "EqFMlJarb2aDwpwvUi6J", "x2173A2HKOiPqeRsKtWY", "GYDPF-005",
  81 +// "KBS-1-3", "KBS-2-1", "KBS-3-4", "1fzR6X57k2aafbbkH4po", "lbqMr5pmkNJLWEPSa0yp", "mYz1kUajPOROg0Ewcfhr",
  82 +// "6TLlfKBbTMaUZGgHtvuH", "XTE8PKwLSYp29gE1umfW", "MqYu4y0OycHQkzZhothe", "IFeN0lAXlAVQ1fD7gwk1", "hZb9NsRCqtVBSagFqnPS",
  83 +// "r22r53PNgY7TeqCK5y14", "KCGSwfTvGCtBfd0qsH63", "4KzFQCncmwFh7UT4vbHp", "GYDPF-007", "KBS-3-2", "t2kkUTZYqxmKLN4X4VPB",
  84 +// "9vWKALGoat3XalEtQaRB", "vYtwLMkppPbM3CtB3U9U", "4vwTfMqi8oEtWxdEUrE8", "vVvK2cTLvjYtZX1dksyd", "GYDPF-003",
  85 +// "KBS-3-8", "2E6eUu66qxl5Llr6ib5v", "iWbeBfwg36lIpBRMDnvO", "GYDPF-015", "KBS-2-4", "OSbA7X7FGETF0TXub4OS",
  86 +// "GYDPF-008", "KBS-2-3", "KBS-2-7", "pRhGGECbXu6FBshyg2yg", "zrVVNRo8QIbjeYjdoCUq", "fjPj3oHW7cL5m0AE1t3y",
  87 +// "8dJsgqjmxIIduP4Sr2rL", "GYDPF-012", "KBS-1-4", "JZ8Tbzye8rKotYTbHUJw", "dwToSYEWr04sPtBUxaOH", "GYDPF-009",
  88 +// "oe3OmagW5Wi9yw9LfUr3", "2mDiH94D7uSh4CtD2bi0", "ceGyDxlK7xzMoUacIwCv", "gxECiKjMEsVkYyowKIMd", "irAqF3fmzaM5GIo8ZLAx",
  89 +// "GYDPF-013", "KBS-2-5", "KBS-3-6", "dxPdbg2UqqYADPMy9TVe", "cjFUpeVPTOh4Uf6wnVH1", "VR5XgpqhFWGMcwdy8yPQ",
  90 +// "GYDPF-004", "KBS-1-7", "KBS-2-8", "HEXmiSz0sXsahRHV2bQm", "0lIIGWP49Xuo91TnTvVx", "C99WsNGFSGQSV4n3YmrW",
  91 +// "3paJSiHK32wvVM6f1tO8", "GYDPF-011", "KBS-1-8", "KBS-2-6", "yrk5Cxa6EJncWX2kTywa", "xOxHHscmrEBhLTlmyRrF",
  92 +// "e3HzLoIl0p3iEM860EdK");
  93 +
  94 + List<Object> needSyncDataList = initConnectAndSelectData();
  95 + log.info("总设备数量: {}台", needSyncDataList.size());
  96 +
  97 + Map<String, String> organizeIdAndClientIdMap = new HashMap<>(3);
  98 + organizeIdAndClientIdMap.put("63934b6f-1e02-4d29-ac14-1a64649e2231", "2020672119054331904"); // 安徽鑫米兰电子科技有限公司
  99 + organizeIdAndClientIdMap.put("35bcdb94-31ec-4750-9ee9-cc855aa66e17", "2020672015207559169"); // 安徽同池科技有限公司
  100 + organizeIdAndClientIdMap.put("365c477a-3e7b-4c4d-b80d-3c05379d5fda", "2020672228886376448"); // 凯盛信息显示材料(池州)有限公司
53 101
54 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 102 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
55 String formattedDate = sdf.format(new Date()); 103 String formattedDate = sdf.format(new Date());
56 log.info("上报时间统一为: {}", formattedDate); 104 log.info("上报时间统一为: {}", formattedDate);
57 105
58 - // 用于统计状态分布  
59 - Map<Integer, Integer> statusCountMap = new HashMap<>();  
60 - statusCountMap.put(1, 0);  
61 - statusCountMap.put(2, 0);  
62 - statusCountMap.put(3, 0);  
63 - statusCountMap.put(4, 0);  
64 -  
65 // 用于统计上报结果 106 // 用于统计上报结果
66 int successCount = 0; 107 int successCount = 0;
67 int failCount = 0; 108 int failCount = 0;
68 List<String> failedDevices = new ArrayList<>(); 109 List<String> failedDevices = new ArrayList<>();
69 -  
70 - // 用于记录不同clientId的设备数量  
71 - int clientId1Count = 0;  
72 - int clientId2Count = 0;  
73 - int clientId3Count = 0;  
74 -  
75 - for (int index = 0; index < deviceIdList.size(); index++) {  
76 - String deviceId = deviceIdList.get(index); 110 + for (int index = 0; index < needSyncDataList.size(); index++) {
  111 + Object needSyncData = needSyncDataList.get(index);
  112 + List<Object> dataList = (ArrayList) needSyncData;
  113 + String deviceId = dataList.get(0).toString();
  114 + String status = dataList.get(1).toString();
  115 + String organizeId = dataList.get(2).toString();
77 116
78 // 根据index确定clientId 117 // 根据index确定clientId
79 - String clientId = "2020672015207559169";  
80 - if (index > 45 && index <= 97) {  
81 - clientId = "2020672119054331904";  
82 - clientId2Count++;  
83 - } else if (index > 97) {  
84 - clientId = "2020672228886376448";  
85 - clientId3Count++;  
86 - } else {  
87 - clientId1Count++;  
88 - }  
89 - 118 + String clientId = organizeIdAndClientIdMap.get(organizeId);
90 String topic = MessageFormat.format("/{0}/{1}/properties/report", clientId, deviceId); 119 String topic = MessageFormat.format("/{0}/{1}/properties/report", clientId, deviceId);
91 120
92 // 获取设备状态 121 // 获取设备状态
93 - int deviceState = getDeviceState();  
94 -  
95 - // 统计状态分布  
96 - statusCountMap.put(deviceState, statusCountMap.get(deviceState) + 1); 122 + int deviceState = getDeviceState(status);
97 123
98 Map<String, Object> properties = new HashMap<>(5); 124 Map<String, Object> properties = new HashMap<>(5);
99 properties.put("type", 1); 125 properties.put("type", 1);
@@ -141,8 +167,6 @@ public class CzDeviceReportService { @@ -141,8 +167,6 @@ public class CzDeviceReportService {
141 167
142 // 任务完成,输出统计信息 168 // 任务完成,输出统计信息
143 log.info("========== 设备状态上报任务完成 =========="); 169 log.info("========== 设备状态上报任务完成 ==========");
144 - log.info("任务完成时间: {}", new Date());  
145 - log.info("设备总数: {}台", deviceIdList.size());  
146 log.info("成功上报: {}台", successCount); 170 log.info("成功上报: {}台", successCount);
147 log.info("失败上报: {}台", failCount); 171 log.info("失败上报: {}台", failCount);
148 172
@@ -150,60 +174,104 @@ public class CzDeviceReportService { @@ -150,60 +174,104 @@ public class CzDeviceReportService {
150 log.warn("失败设备列表: {}", failedDevices); 174 log.warn("失败设备列表: {}", failedDevices);
151 } 175 }
152 176
153 - // 输出clientId分布  
154 - log.info("clientId分布统计:");  
155 - log.info(" clientId-2020672015207559169: {}台", clientId1Count);  
156 - log.info(" clientId-2020672119054331904: {}台", clientId2Count);  
157 - log.info(" clientId-2020672228886376448: {}台", clientId3Count);  
158 -  
159 - // 输出状态分布统计  
160 - log.info("设备状态分布统计 (按8:1:0.5:0.5比例):");  
161 - log.info(" 状态1(80%): {}台 (占比: {}%)",  
162 - statusCountMap.get(1),  
163 - String.format("%.1f", statusCountMap.get(1) * 100.0 / deviceIdList.size()));  
164 - log.info(" 状态2(10%): {}台 (占比: {}%)",  
165 - statusCountMap.get(2),  
166 - String.format("%.1f", statusCountMap.get(2) * 100.0 / deviceIdList.size()));  
167 - log.info(" 状态3(5%): {}台 (占比: {}%)",  
168 - statusCountMap.get(3),  
169 - String.format("%.1f", statusCountMap.get(3) * 100.0 / deviceIdList.size()));  
170 - log.info(" 状态4(5%): {}台 (占比: {}%)",  
171 - statusCountMap.get(4),  
172 - String.format("%.1f", statusCountMap.get(4) * 100.0 / deviceIdList.size()));  
173 -  
174 - // 计算实际比例  
175 - double ratio1 = statusCountMap.get(1) / (double) statusCountMap.get(2);  
176 - double ratio3 = statusCountMap.get(3) / (double) statusCountMap.get(2);  
177 - double ratio4 = statusCountMap.get(4) / (double) statusCountMap.get(2);  
178 - log.info("实际比例: {} : 1 : {} : {}",  
179 - String.format("%.1f", ratio1),  
180 - String.format("%.1f", ratio3),  
181 - String.format("%.1f", ratio4));  
182 -  
183 // 任务执行耗时 177 // 任务执行耗时
184 log.info("========== 任务执行结束 =========="); 178 log.info("========== 任务执行结束 ==========");
185 } 179 }
186 180
187 - private int getDeviceState() {  
188 - Random random = new Random();  
189 - double rand = random.nextDouble();  
190 - int status;  
191 -  
192 - if (rand < 0.8) {  
193 - status = 1; // 80%概率  
194 - } else if (rand < 0.9) {  
195 - status = 2; // 10%概率  
196 - } else if (rand < 0.95) {  
197 - status = 3; // 5%概率 181 + private int getDeviceState(String status) {
  182 + int deviceState;
  183 + if ("RUN".equals(status)) {
  184 + deviceState = 1;
  185 + } else if ("STAND".equals(status)) {
  186 + deviceState = 2;
  187 + } else if ("OFF".equals(status)) {
  188 + deviceState = 3;
198 } else { 189 } else {
199 - status = 4; // 5%概率 190 + deviceState = 4;
200 } 191 }
201 192
202 - // 调试日志  
203 - if (log.isTraceEnabled()) {  
204 - log.trace("生成设备状态: random={}, status={}", rand, status); 193 + return deviceState;
  194 + }
  195 +
  196 + private List<Object> initConnectAndSelectData() {
  197 + Connection connection = null;
  198 + PreparedStatement statement = null;
  199 + ResultSet resultSet = null;
  200 + HikariDataSource dataSource = null;
  201 + List<Object> resultList = new ArrayList<>();
  202 +
  203 + log.info("开始连接数据库,URL: {}", jdbcUrl);
  204 +
  205 + try {
  206 + HikariConfig config = new HikariConfig();
  207 + config.setJdbcUrl(jdbcUrl);
  208 + config.setUsername(jdbcUserName);
  209 + config.setPassword(jdbcPassword);
  210 + config.setDriverClassName("org.postgresql.Driver");
  211 + config.setMaximumPoolSize(5);
  212 + config.setMinimumIdle(5);
  213 + config.setConnectionTimeout(60000);
  214 + config.setConnectionTestQuery("SELECT 1");
  215 +
  216 + dataSource = new HikariDataSource(config);
  217 + log.info("Hikari连接池配置完成");
  218 +
  219 + connection = dataSource.getConnection();
  220 + log.info("数据库连接成功");
  221 +
  222 + statement = connection.prepareStatement(selectSql);
  223 + log.info("执行SQL查询: {}", selectSql);
  224 +
  225 + resultSet = statement.executeQuery();
  226 + ResultSetMetaData metaData = resultSet.getMetaData();
  227 + int columnCount = metaData.getColumnCount();
  228 + log.info("查询结果集元数据获取成功,共{}列", columnCount);
  229 +
  230 + int rowCount = 0;
  231 + while (resultSet.next()) {
  232 + List<Object> result = new ArrayList<>(columnCount);
  233 + for (int index = 1; index <= columnCount; index++) {
  234 + int columnType = metaData.getColumnType(index);
  235 + Object value = SqlTypedValueUtils.getTypedValue(resultSet, index, columnType);
  236 + result.add(value);
  237 + }
  238 + resultList.add(result);
  239 + rowCount++;
  240 +
  241 + // 每处理1000行记录一次日志
  242 + if (rowCount % 1000 == 0) {
  243 + log.info("已处理{}行数据", rowCount);
  244 + }
  245 + }
  246 +
  247 + log.info("数据查询完成,共获取{}行数据", rowCount);
  248 +
  249 + } catch (SQLException e) {
  250 + log.error("数据库操作异常,URL: {}, 用户名: {}", jdbcUrl, jdbcUserName, e);
  251 + } catch (Exception e) {
  252 + log.error("初始化数据库连接或查询数据时发生异常", e);
  253 + } finally {
  254 + // 释放资源
  255 + try {
  256 + if (resultSet != null) resultSet.close();
  257 + if (statement != null) statement.close();
  258 + if (connection != null) connection.close();
  259 + log.info("数据库连接资源已释放");
  260 + } catch (SQLException e) {
  261 + log.error("关闭数据库资源时发生异常", e);
  262 + }
  263 +
  264 + if (dataSource != null) {
  265 + try {
  266 + dataSource.close();
  267 + log.info("HikariDataSource连接池已关闭");
  268 + } catch (Exception e) {
  269 + log.error("关闭HikariDataSource连接池时发生异常", e);
  270 + }
  271 + }
205 } 272 }
206 273
207 - return status; 274 + log.info("数据库操作完成,返回{}条记录", resultList.size());
  275 + return resultList;
208 } 276 }
209 } 277 }
@@ -190,7 +190,7 @@ sh: @@ -190,7 +190,7 @@ sh:
190 profileId: "f2292f60-f738-11f0-9cb8-e3376d1e7978" 190 profileId: "f2292f60-f738-11f0-9cb8-e3376d1e7978"
191 deviceProfileId: "f2292f60-f738-11f0-9cb8-e3376d1e7978" 191 deviceProfileId: "f2292f60-f738-11f0-9cb8-e3376d1e7978"
192 userName: "shzh" 192 userName: "shzh"
193 - password: "123456" 193 + password: "Shzh@123.com"
194 tokenUrl: "https://iot.hzzlyun.com/api/auth/login" 194 tokenUrl: "https://iot.hzzlyun.com/api/auth/login"
195 infoUrl: "https://iot.hzzlyun.com/api/yt/device" 195 infoUrl: "https://iot.hzzlyun.com/api/yt/device"
196 detailUrl: "https://iot.hzzlyun.com/api/v1/" 196 detailUrl: "https://iot.hzzlyun.com/api/v1/"
@@ -201,7 +201,7 @@ sl: @@ -201,7 +201,7 @@ sl:
201 profileId: "f2292f60-f738-11f0-9cb8-e3376d1e7978" 201 profileId: "f2292f60-f738-11f0-9cb8-e3376d1e7978"
202 deviceProfileId: "f2292f60-f738-11f0-9cb8-e3376d1e7978" 202 deviceProfileId: "f2292f60-f738-11f0-9cb8-e3376d1e7978"
203 userName: "slzy" 203 userName: "slzy"
204 - password: "123456" 204 + password: "Slzy@123.com"
205 tokenUrl: "https://iot.hzzlyun.com/api/auth/login" 205 tokenUrl: "https://iot.hzzlyun.com/api/auth/login"
206 infoUrl: "https://iot.hzzlyun.com/api/yt/device" 206 infoUrl: "https://iot.hzzlyun.com/api/yt/device"
207 detailUrl: "https://iot.hzzlyun.com/api/v1/" 207 detailUrl: "https://iot.hzzlyun.com/api/v1/"
@@ -212,7 +212,7 @@ gh: @@ -212,7 +212,7 @@ gh:
212 profileId: "f2292f60-f738-11f0-9cb8-e3376d1e7978" 212 profileId: "f2292f60-f738-11f0-9cb8-e3376d1e7978"
213 deviceProfileId: "f2292f60-f738-11f0-9cb8-e3376d1e7978" 213 deviceProfileId: "f2292f60-f738-11f0-9cb8-e3376d1e7978"
214 userName: "ghxcl" 214 userName: "ghxcl"
215 - password: "123456" 215 + password: "Ghxcl@123.com"
216 tokenUrl: "https://iot.hzzlyun.com/api/auth/login" 216 tokenUrl: "https://iot.hzzlyun.com/api/auth/login"
217 infoUrl: "https://iot.hzzlyun.com/api/yt/device" 217 infoUrl: "https://iot.hzzlyun.com/api/yt/device"
218 detailUrl: "https://iot.hzzlyun.com/api/v1/" 218 detailUrl: "https://iot.hzzlyun.com/api/v1/"
@@ -223,7 +223,7 @@ shzz: @@ -223,7 +223,7 @@ shzz:
223 profileId: "f2292f60-f738-11f0-9cb8-e3376d1e7978" 223 profileId: "f2292f60-f738-11f0-9cb8-e3376d1e7978"
224 deviceProfileId: "f2292f60-f738-11f0-9cb8-e3376d1e7978" 224 deviceProfileId: "f2292f60-f738-11f0-9cb8-e3376d1e7978"
225 userName: "shzz" 225 userName: "shzz"
226 - password: "123456" 226 + password: "Shzz@123.com"
227 tokenUrl: "https://iot.hzzlyun.com/api/auth/login" 227 tokenUrl: "https://iot.hzzlyun.com/api/auth/login"
228 infoUrl: "https://iot.hzzlyun.com/api/yt/device" 228 infoUrl: "https://iot.hzzlyun.com/api/yt/device"
229 detailUrl: "https://iot.hzzlyun.com/api/v1/" 229 detailUrl: "https://iot.hzzlyun.com/api/v1/"