分批次发送mqtt指令

This commit is contained in:
zhangyue 2026-05-27 16:20:05 +08:00
parent fe033c805d
commit 1aba7557e0
1 changed files with 18 additions and 3 deletions

View File

@ -739,9 +739,24 @@ public class IotCommonP3ServiceImpl {
try{
log.error("===========预发送指令========={}============", variables.size());
if (deploy != null && variables != null && !variables.isEmpty()) {
QueryCmd queryCmd = LhIotUtil.ConstructCmd(variables);
String cmdStr = JSONObject.toJSONString(queryCmd);
mqttService.sendMessage(deploy.getDeviceIotUrl(), cmdStr);
if(variables.size()>10){
//如果超过十个分多次十个一组
int batchSize = 10;
for (int i = 0; i < variables.size(); i += batchSize) {
int end = Math.min(i + batchSize, variables.size());
List<String> batch = variables.subList(i, end);
// 处理这一批数据
QueryCmd queryCmd = LhIotUtil.ConstructCmd(batch);
String cmdStr = JSONObject.toJSONString(queryCmd);
mqttService.sendMessage(deploy.getDeviceIotUrl(), cmdStr);
log.error("===========当前批次指令========={}============", batch);
}
}
}
}catch (Exception e){
//抛出未注入时的报错