fix:太阳能网控,属性下发,不区分在线离线。

This commit is contained in:
tianyongbao
2026-07-01 23:45:27 +08:00
parent ac9ea07328
commit 73993a142c

View File

@@ -2255,74 +2255,32 @@ public class IotController extends BaseController {
}
Map<String, Object> properties = normalizeSolarProperties(request.getProperties());
boolean cache = Boolean.TRUE.equals(request.getCache());
Integer statusCode = queryDeviceStatusCode(device.getIotId());
boolean online = Integer.valueOf(DEVICE_STATUS_ONLINE).equals(statusCode);
Map<String, Object> result = new LinkedHashMap<>();
result.put("deviceId", device.getId());
result.put("serialNum", device.getSerialNum());
result.put("online", online);
result.put("statusCode", statusCode);
result.put("properties", properties);
if (cache) {
if (online) {
return R.fail("设备当前在线,请使用直接下发");
}
if (!cachePendingSolarProperties(device, properties)) {
return R.fail("指令缓存失败,请稍后重试");
}
syncDeviceFieldsAfterSolarCommand(device.getId(), properties);
if (properties.containsKey("salinitySet")) {
setSalinityFreeze(device.getSerialNum(), toDouble(properties.get("salinitySet")));
}
result.put("mode", "cached");
result.put("cached", true);
result.put("sent", false);
MessageOpRecordUtil.addMessageOpRecordUser(
device.getUserId(),
userId,
"设备操作",
String.format("%s(%s),太阳能网控属性缓存下发:%s。",
device.getDeviceName(), device.getSerialNum(), properties)
);
log.info("太阳能网控属性已缓存: userId={}, deviceId={}, serialNum={}, properties={}",
userId, device.getId(), device.getSerialNum(), properties);
return R.ok("缓存成功,设备上线后自动下发", result);
// 太阳能网控统一走缓存下发,设备上线后自动补发,不再区分在线/离线
if (!cachePendingSolarProperties(device, properties)) {
return R.fail("指令缓存失败,请稍后重试");
}
if (!online) {
return R.fail("设备离线或未激活,请使用缓存下发");
}
if (iotCloudService == null) {
return R.fail("飞燕平台配置未启用");
}
boolean success = iotCloudService.setProperty(device.getIotId(), properties, true, 2);
if (!success) {
return R.fail("属性下发失败,请重试");
}
syncDeviceFieldsAfterSolarCommand(device.getId(), properties);
removePendingSolarProperties(device, properties.keySet());
if (properties.containsKey("salinitySet")) {
setSalinityFreeze(device.getSerialNum(), toDouble(properties.get("salinitySet")));
}
result.put("mode", "direct");
result.put("cached", false);
result.put("sent", true);
Map<String, Object> result = new LinkedHashMap<>();
result.put("deviceId", device.getId());
result.put("serialNum", device.getSerialNum());
result.put("properties", properties);
result.put("mode", "cached");
MessageOpRecordUtil.addMessageOpRecordUser(
device.getUserId(),
userId,
"设备操作",
String.format("%s(%s),太阳能网控属性直接下发:%s。",
String.format("%s(%s),太阳能网控属性缓存下发:%s。",
device.getDeviceName(), device.getSerialNum(), properties)
);
log.info("太阳能网控属性下发成功: userId={}, deviceId={}, serialNum={}, properties={}",
log.info("太阳能网控属性已缓存: userId={}, deviceId={}, serialNum={}, properties={}",
userId, device.getId(), device.getSerialNum(), properties);
return R.ok("下发成功", result);
return R.ok("缓存成功,设备上线后自动下发", result);
} catch (IllegalArgumentException e) {
return R.fail(e.getMessage());
} catch (Exception e) {