20260909:优化查询问题

This commit is contained in:
zhugongping 2026-09-09 16:29:18 +08:00
parent d6377494b4
commit 175a001fe7
3 changed files with 13 additions and 16 deletions

View File

@ -254,20 +254,19 @@ public class ToolController extends BaseController {
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace();
log.error("发生错误:{}", ex.getMessage(), ex); log.error("发生错误:{}", ex.getMessage(), ex);
} }
} }
@ApiOperation("mqtt钩子处理") @ApiOperation("mqtt钩子处理")
@PostMapping("/mqtt/webhookv5") @PostMapping("/mqtt/webhookv5")
public void webHookProcessv5(@RequestBody JSONObject json) { public void webHookProcessV5(@RequestBody JSONObject json) {
try { try {
String clientid = json.getString("clientid"); String clientid = json.getString("clientid");
String event = json.getString("event"); String event = json.getString("event");
String peername = json.getString("peername"); // 类似 127.0.0.1:8812 String peername = json.getString("peername"); // 类似 127.0.0.1:8812
String ipAddress = peername; String ipAddress = peername;
if (peername.indexOf(":") != -1) { if (peername.contains(":")) {
ipAddress = peername.substring(0, peername.indexOf(":")); ipAddress = peername.substring(0, peername.indexOf(":"));
} }
log.info("webhook:{},clientid:{},peername:{}", event, clientid, peername); log.info("webhook:{},clientid:{},peername:{}", event, clientid, peername);
@ -310,18 +309,17 @@ public class ToolController extends BaseController {
// 影子模式,发布属性和功能 // 影子模式,发布属性和功能
if (device.getIsShadow() == 1) { if (device.getIsShadow() == 1) {
ThingsModelShadow shadow = deviceService.getDeviceShadowThingsModel(device); ThingsModelShadow shadow = deviceService.getDeviceShadowThingsModel(device);
if (shadow.getProperties().size() > 0) { if (!shadow.getProperties().isEmpty()) {
messagePublish.publishProperty(device.getProductId(), device.getSerialNumber(), shadow.getProperties(), 3); messagePublish.publishProperty(device.getProductId(), device.getSerialNumber(), shadow.getProperties(), 3);
} }
if (shadow.getFunctions().size() > 0) { if (!shadow.getFunctions().isEmpty()) {
messagePublish.publishFunction(device.getProductId(), device.getSerialNumber(), shadow.getFunctions(), 3); messagePublish.publishFunction(device.getProductId(), device.getSerialNumber(), shadow.getFunctions(), 3);
} }
} }
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); log.error("发生错误:{}", ex.getMessage());
log.error("发生错误:" + ex.getMessage());
} }
} }

View File

@ -210,7 +210,7 @@ public class DataRepairServiceImpl implements IDataRepairService {
public void executeDataRepair(String serialNumber, boolean isShadow, List<DeviceLog> currentLogs) { public void executeDataRepair(String serialNumber, boolean isShadow, List<DeviceLog> currentLogs) {
if (CollectionUtils.isEmpty(currentLogs) || isShadow) { if (CollectionUtils.isEmpty(currentLogs) || isShadow) {
log.debug("无数据或为影子模式,不执行数据修复: serialNumber={}, isShadow={}", serialNumber, isShadow); //log.debug("无数据或为影子模式,不执行数据修复: serialNumber={}, isShadow={}", serialNumber, isShadow);
return; return;
} }

View File

@ -648,8 +648,7 @@ public class DeviceServiceImpl implements IDeviceService {
*/ */
@Override @Override
@DSTransactional @DSTransactional
public List<ThingsModelSimpleItem> reportDeviceThingsModelValue(ThingsModelValuesInput input, int type, public List<ThingsModelSimpleItem> reportDeviceThingsModelValue(ThingsModelValuesInput input, int type, boolean isShadow) {
boolean isShadow) {
String serialNumber = input.getDeviceNumber(); String serialNumber = input.getDeviceNumber();
String key = RedisKeyBuilder.buildTSLVCacheKey(input.getProductId(), serialNumber); String key = RedisKeyBuilder.buildTSLVCacheKey(input.getProductId(), serialNumber);
Map<String, String> maps = new HashMap<>(); Map<String, String> maps = new HashMap<>();
@ -675,6 +674,9 @@ public class DeviceServiceImpl implements IDeviceService {
ThingsModelSimpleItem::getValue, ThingsModelSimpleItem::getValue,
(oldValue, newValue) -> oldValue)); (oldValue, newValue) -> oldValue));
} }
// 查询设备信息
Device device = this.selectDeviceBySerialNumber(serialNumber);
for (ThingsModelSimpleItem item : thingsModelValueRemarkItem) { for (ThingsModelSimpleItem item : thingsModelValueRemarkItem) {
String identity = item.getId(); String identity = item.getId();
if (identity.startsWith("array_")) { if (identity.startsWith("array_")) {
@ -746,11 +748,9 @@ public class DeviceServiceImpl implements IDeviceService {
valueItem.setId(identity); valueItem.setId(identity);
if (id.startsWith("array_")) { if (id.startsWith("array_")) {
// 查询是否有缓存,如果没有先进行缓存 // 查询是否有缓存,如果没有先进行缓存
if (!redisCache.containsKey(key)) { // if (!redisCache.containsKey(key)) {
Device device = this.selectDeviceBySerialNumber(serialNumber); // itslValueCache.addCacheDeviceStatus(input.getProductId(), serialNumber);
this.selectDeviceByDeviceId(device.getDeviceId()); // }
}
int index = Integer.parseInt(id.substring(6, 8)); int index = Integer.parseInt(id.substring(6, 8));
if (isShadow) { if (isShadow) {
String[] shadows = cacheIdentifier.getShadow().split(","); String[] shadows = cacheIdentifier.getShadow().split(",");
@ -791,7 +791,6 @@ public class DeviceServiceImpl implements IDeviceService {
/* ★★★★★★★★★★★★★★★★★★★★★★ 存储数据 - 开始 ★★★★★★★★★★★★★★★★★★★★★★ */ /* ★★★★★★★★★★★★★★★★★★★★★★ 存储数据 - 开始 ★★★★★★★★★★★★★★★★★★★★★★ */
ThingsModelType modelType = ThingsModelType.getType(thingModels.getType()); ThingsModelType modelType = ThingsModelType.getType(thingModels.getType());
Device device = this.selectDeviceBySerialNumber(serialNumber);
switch (modelType) { switch (modelType) {
case PROP: case PROP:
if (1 == thingModels.getIsHistory()) { if (1 == thingModels.getIsHistory()) {