fix:太阳能网控,属性下发,不区分在线离线。
This commit is contained in:
@@ -2255,74 +2255,32 @@ public class IotController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> properties = normalizeSolarProperties(request.getProperties());
|
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());
|
if (!cachePendingSolarProperties(device, properties)) {
|
||||||
result.put("serialNum", device.getSerialNum());
|
return R.fail("指令缓存失败,请稍后重试");
|
||||||
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 (!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);
|
syncDeviceFieldsAfterSolarCommand(device.getId(), properties);
|
||||||
removePendingSolarProperties(device, properties.keySet());
|
|
||||||
if (properties.containsKey("salinitySet")) {
|
if (properties.containsKey("salinitySet")) {
|
||||||
setSalinityFreeze(device.getSerialNum(), toDouble(properties.get("salinitySet")));
|
setSalinityFreeze(device.getSerialNum(), toDouble(properties.get("salinitySet")));
|
||||||
}
|
}
|
||||||
|
|
||||||
result.put("mode", "direct");
|
Map<String, Object> result = new LinkedHashMap<>();
|
||||||
result.put("cached", false);
|
result.put("deviceId", device.getId());
|
||||||
result.put("sent", true);
|
result.put("serialNum", device.getSerialNum());
|
||||||
|
result.put("properties", properties);
|
||||||
|
result.put("mode", "cached");
|
||||||
|
|
||||||
MessageOpRecordUtil.addMessageOpRecordUser(
|
MessageOpRecordUtil.addMessageOpRecordUser(
|
||||||
device.getUserId(),
|
device.getUserId(),
|
||||||
userId,
|
userId,
|
||||||
"设备操作",
|
"设备操作",
|
||||||
String.format("%s(%s),太阳能网控属性直接下发:%s。",
|
String.format("%s(%s),太阳能网控属性缓存下发:%s。",
|
||||||
device.getDeviceName(), device.getSerialNum(), properties)
|
device.getDeviceName(), device.getSerialNum(), properties)
|
||||||
);
|
);
|
||||||
log.info("太阳能网控属性下发成功: userId={}, deviceId={}, serialNum={}, properties={}",
|
log.info("太阳能网控属性已缓存: userId={}, deviceId={}, serialNum={}, properties={}",
|
||||||
userId, device.getId(), device.getSerialNum(), properties);
|
userId, device.getId(), device.getSerialNum(), properties);
|
||||||
return R.ok("下发成功", result);
|
return R.ok("缓存成功,设备上线后自动下发", result);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
return R.fail(e.getMessage());
|
return R.fail(e.getMessage());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user