增加拉取继电器时,同时查询Mqtt
This commit is contained in:
parent
5e3d392722
commit
3a1a541144
|
|
@ -412,16 +412,32 @@ public class SurvDeviceDeployController extends JeecgController<SurvDeviceDeploy
|
||||||
case IotConstants.lhviot_standard:
|
case IotConstants.lhviot_standard:
|
||||||
List<SurvDeviceDeployRelaygroup> relays = relaygroupService.getRelayByGroup(deploy.getId());
|
List<SurvDeviceDeployRelaygroup> relays = relaygroupService.getRelayByGroup(deploy.getId());
|
||||||
deviceRelayVo.setModuleList(relays);
|
deviceRelayVo.setModuleList(relays);
|
||||||
|
List<String> variables = new ArrayList<>();//收集所有查询变量
|
||||||
//初始化指令
|
//初始化指令
|
||||||
if(!relays.isEmpty()){
|
if(!relays.isEmpty()){
|
||||||
for (SurvDeviceDeployRelaygroup relaygroup : relays) {
|
for (SurvDeviceDeployRelaygroup relaygroup : relays) {
|
||||||
List<SurvDeviceDeployRelay> r = relayService.initCmd(relaygroup.getRelayList());
|
List<SurvDeviceDeployRelay> r = relayService.initCmd(relaygroup.getRelayList());
|
||||||
relaygroup.setRelayList(r);
|
relaygroup.setRelayList(r);
|
||||||
|
if(!r.isEmpty()){
|
||||||
|
for (SurvDeviceDeployRelay survDeviceDeployRelay : r) {
|
||||||
|
if(StringUtils.isNotBlank(survDeviceDeployRelay.getRelayKey())) {
|
||||||
|
variables.add(survDeviceDeployRelay.getRelayKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SurvDeviceDeployRun> runs = runService.listByDeploy(deploy.getId());
|
List<SurvDeviceDeployRun> runs = runService.listByDeploy(deploy.getId());
|
||||||
deviceRelayVo.setRunStatus(runs);
|
deviceRelayVo.setRunStatus(runs);
|
||||||
|
if(runs!=null && !runs.isEmpty()){
|
||||||
|
for (SurvDeviceDeployRun run : runs) {
|
||||||
|
if(StringUtils.isNotBlank(run.getRunKey())) {
|
||||||
|
variables.add(run.getRunKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//拉取完后,顺便触发一次查询所有继电器和运行状态
|
||||||
|
boolean b= p3Service.sendMqttDeviceQuery(deploy,variables);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
List<SurvDeviceDeployRelay> pageList = relayService.relayList(deployId,null);
|
List<SurvDeviceDeployRelay> pageList = relayService.relayList(deployId,null);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package org.jeecg.modules.appmana.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
@ -9,8 +10,10 @@ import org.jeecg.common.constant.IotConstants;
|
||||||
import org.jeecg.common.constant.PollutionConstants;
|
import org.jeecg.common.constant.PollutionConstants;
|
||||||
import org.jeecg.common.constant.enums.PollutionEnum;
|
import org.jeecg.common.constant.enums.PollutionEnum;
|
||||||
import org.jeecg.common.entity.*;
|
import org.jeecg.common.entity.*;
|
||||||
|
import org.jeecg.common.iot.lhiot.QueryCmd;
|
||||||
import org.jeecg.common.util.DateUtilTools;
|
import org.jeecg.common.util.DateUtilTools;
|
||||||
import org.jeecg.common.util.EntityFieldUtil;
|
import org.jeecg.common.util.EntityFieldUtil;
|
||||||
|
import org.jeecg.common.util.LhIotUtil;
|
||||||
import org.jeecg.common.vo.*;
|
import org.jeecg.common.vo.*;
|
||||||
import org.jeecg.common.vo.statistic.DTOIotSummray;
|
import org.jeecg.common.vo.statistic.DTOIotSummray;
|
||||||
import org.jeecg.modules.appmana.service.IScEquZhibiaoService;
|
import org.jeecg.modules.appmana.service.IScEquZhibiaoService;
|
||||||
|
|
@ -729,4 +732,15 @@ public class IotCommonP3ServiceImpl {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean sendMqttDeviceQuery(SurvDeviceDeploy deploy, List<String> variables) {
|
||||||
|
boolean result = true;
|
||||||
|
log.error("===========预发送指令========={}============",variables.size());
|
||||||
|
if(deploy!=null && variables!=null && !variables.isEmpty()){
|
||||||
|
QueryCmd queryCmd = LhIotUtil.ConstructCmd(variables);
|
||||||
|
String cmdStr = JSONObject.toJSONString(queryCmd);
|
||||||
|
mqttService.publish(deploy.getDeviceIotUrl(),cmdStr);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package org.jeecg.common.iot.lhiot;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class QueryCmd {
|
||||||
|
@ApiModelProperty("指令")
|
||||||
|
private QueryCmdDetail rw_prot;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
package org.jeecg.common.iot.lhiot;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class QueryCmdDetail {
|
||||||
|
|
||||||
|
|
||||||
|
private static final AtomicInteger counter = new AtomicInteger(0);
|
||||||
|
private static final DateTimeFormatter FORMATTER =
|
||||||
|
DateTimeFormatter.ofPattern("yyyyMMddHHmmss")
|
||||||
|
.withZone(ZoneId.systemDefault());
|
||||||
|
|
||||||
|
|
||||||
|
@ApiModelProperty("指令类型")
|
||||||
|
private String dir = "down";
|
||||||
|
|
||||||
|
@ApiModelProperty("指令id")
|
||||||
|
private String id = generate();
|
||||||
|
|
||||||
|
@ApiModelProperty("寄存器编号集合")
|
||||||
|
private List<QueryCmdRegister> r_data;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 线程安全的高并发版本
|
||||||
|
*/
|
||||||
|
public static String generate() {
|
||||||
|
// 1. 生成时间戳部分
|
||||||
|
String timestamp = FORMATTER.format(Instant.now());
|
||||||
|
|
||||||
|
// 2. 生成4位随机数(使用AtomicInteger保证线程安全)
|
||||||
|
int random = counter.incrementAndGet() % 10000;
|
||||||
|
if (random < 0) {
|
||||||
|
random = -random;
|
||||||
|
}
|
||||||
|
String randomStr = String.format("%04d", random);
|
||||||
|
|
||||||
|
return timestamp + randomStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
package org.jeecg.common.iot.lhiot;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class QueryCmdRegister {
|
||||||
|
|
||||||
|
@ApiModelProperty("寄存器编号")
|
||||||
|
private String name;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package org.jeecg.common.iot.lhiot;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ResponseCmd {
|
||||||
|
@ApiModelProperty("指令")
|
||||||
|
private ResponseCmdDetail rw_prot;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
package org.jeecg.common.iot.lhiot;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ResponseCmdData {
|
||||||
|
|
||||||
|
@ApiModelProperty("寄存器编号")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty("寄存器值")
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
@ApiModelProperty("是否报错")
|
||||||
|
private String err;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package org.jeecg.common.iot.lhiot;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ResponseCmdDetail {
|
||||||
|
@ApiModelProperty("指令类型")
|
||||||
|
private String dir;
|
||||||
|
|
||||||
|
@ApiModelProperty("指令id")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@ApiModelProperty("数据")
|
||||||
|
private List<ResponseCmdData> r_data;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
package org.jeecg.common.util;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jeecg.common.entity.SurvDeviceDeploy;
|
||||||
|
import org.jeecg.common.iot.lhiot.QueryCmd;
|
||||||
|
import org.jeecg.common.iot.lhiot.QueryCmdDetail;
|
||||||
|
import org.jeecg.common.iot.lhiot.QueryCmdRegister;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class LhIotUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指令构造器
|
||||||
|
*/
|
||||||
|
public static QueryCmd ConstructCmd(List<String> codes){
|
||||||
|
QueryCmd queryCmd = new QueryCmd();
|
||||||
|
if(codes!=null && !codes.isEmpty()){
|
||||||
|
List<QueryCmdRegister> registers = new ArrayList<>();
|
||||||
|
for (String code : codes) {
|
||||||
|
QueryCmdRegister queryCmdRegister = new QueryCmdRegister();
|
||||||
|
queryCmdRegister.setName(code);
|
||||||
|
registers.add(queryCmdRegister);
|
||||||
|
}
|
||||||
|
QueryCmdDetail queryCmdDetail = new QueryCmdDetail();
|
||||||
|
queryCmdDetail.setR_data(registers);
|
||||||
|
queryCmd.setRw_prot(queryCmdDetail);
|
||||||
|
return queryCmd;
|
||||||
|
}else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue