添加水电双计设备在线状态维护,以及下发修改设备地址码指令接口等
This commit is contained in:
@ -11,11 +11,13 @@ import com.fastbee.rechargecard.domain.NgWaterPumpUsageRecords;
|
|||||||
import com.fastbee.rechargecard.mapper.NgWaterPumpUsageRecordsMapper;
|
import com.fastbee.rechargecard.mapper.NgWaterPumpUsageRecordsMapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author gsb
|
* @author gsb
|
||||||
@ -34,6 +36,8 @@ public class DeviceOtherMsgConsumer {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private NgWaterPumpUsageRecordsMapper ngWaterPumpUsageRecordsMapper;
|
private NgWaterPumpUsageRecordsMapper ngWaterPumpUsageRecordsMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PubMqttClient pubMqttClient;
|
private PubMqttClient pubMqttClient;
|
||||||
@ -44,7 +48,6 @@ public class DeviceOtherMsgConsumer {
|
|||||||
//处理emq订阅的非 property/post 属性上报的消息 ,因为其他消息量小,放在一起处理
|
//处理emq订阅的非 property/post 属性上报的消息 ,因为其他消息量小,放在一起处理
|
||||||
|
|
||||||
Long productId;//产品id
|
Long productId;//产品id
|
||||||
|
|
||||||
Long packetId;//包号
|
Long packetId;//包号
|
||||||
byte[] data = bo.getData();//数据
|
byte[] data = bo.getData();//数据
|
||||||
String topic=bo.getTopicName();//主题
|
String topic=bo.getTopicName();//主题
|
||||||
@ -55,7 +58,7 @@ public class DeviceOtherMsgConsumer {
|
|||||||
String serialNumber= split[2];//设备序列号
|
String serialNumber= split[2];//设备序列号
|
||||||
|
|
||||||
System.err.println("主题:"+topic+"--产品id:"+productId+"--设备序列号:"+serialNumber);
|
System.err.println("主题:"+topic+"--产品id:"+productId+"--设备序列号:"+serialNumber);
|
||||||
//设备上报数据消息
|
//设备上报数据消息---------------------------------------------------------------------------------
|
||||||
if(topic.endsWith("/info/up")){
|
if(topic.endsWith("/info/up")){
|
||||||
deviceDataReportHandler(new String(data));
|
deviceDataReportHandler(new String(data));
|
||||||
//保存使用记录
|
//保存使用记录
|
||||||
@ -66,25 +69,27 @@ public class DeviceOtherMsgConsumer {
|
|||||||
if(jsonObject.getStr("type").equals("waterEleData")){
|
if(jsonObject.getStr("type").equals("waterEleData")){
|
||||||
String data1 = jsonObject.getStr("data");
|
String data1 = jsonObject.getStr("data");
|
||||||
if(JSONUtil.parseObj(data1).get("action").equals("timeMsg")){
|
if(JSONUtil.parseObj(data1).get("action").equals("timeMsg")){
|
||||||
|
//更新设备在线状态
|
||||||
|
updateDeviceOnlineStatus( productId,serialNumber);
|
||||||
pumpUsageRecords.setMessageContent(JSONUtil.toJsonStr(jsonObject));
|
pumpUsageRecords.setMessageContent(JSONUtil.toJsonStr(jsonObject));
|
||||||
int i = ngWaterPumpUsageRecordsMapper.insertNgWaterPumpUsageRecords(pumpUsageRecords);
|
int i = ngWaterPumpUsageRecordsMapper.insertNgWaterPumpUsageRecords(pumpUsageRecords);
|
||||||
if(i<1){
|
if(i<1){
|
||||||
System.err.println("--------------------------保存使用记录失败!---------------------------");
|
System.err.println("--------------------------保存使用记录失败!---------------------------");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//构建回复消息-----------------------------------------------------------------------------
|
||||||
//构建回复消息
|
|
||||||
Map<String,Object> reportMsg=new HashMap<>();
|
Map<String,Object> reportMsg=new HashMap<>();
|
||||||
reportMsg.put("code",0);
|
reportMsg.put("code",0);
|
||||||
reportMsg.put("msg","ok");
|
reportMsg.put("msg","ok");
|
||||||
issueInstructionsProducer.receiveDataReportResponse(productId.toString(),serialNumber,JSONUtil.toJsonStr(reportMsg));
|
issueInstructionsProducer.receiveDataReportResponse(productId.toString(),serialNumber,JSONUtil.toJsonStr(reportMsg));
|
||||||
} else if ( topic.endsWith("/info/reply")) {
|
}
|
||||||
|
//打印设备
|
||||||
|
else if ( topic.endsWith("/info/reply")) {
|
||||||
platformDataReportAckHandler(new String(data));
|
platformDataReportAckHandler(new String(data));
|
||||||
|
}
|
||||||
} else if (topic.endsWith("/cmd/down")) {
|
else if (topic.endsWith("/cmd/down")) {
|
||||||
platformCmdHandler(new String(data));
|
platformCmdHandler(new String(data));
|
||||||
//回应
|
//回应
|
||||||
|
|
||||||
@ -97,6 +102,27 @@ public class DeviceOtherMsgConsumer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新设备在线状态
|
||||||
|
*/
|
||||||
|
private void updateDeviceOnlineStatus(Long productId,String serialNumber){
|
||||||
|
try {
|
||||||
|
//判断
|
||||||
|
if(Boolean.TRUE.equals(stringRedisTemplate.hasKey("neixiang_device_online_status:" + productId + ":" + serialNumber))){
|
||||||
|
//重新设置过期时间
|
||||||
|
stringRedisTemplate.expire("neixiang_device_online_status:"+productId+":"+serialNumber,1200, TimeUnit.SECONDS);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
stringRedisTemplate.opsForValue().set("neixiang_device_online_status:"+productId+":"+serialNumber,"1",1200, TimeUnit.SECONDS);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("=>更新设备在线状态出错",e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理设备数据上报
|
* 处理设备数据上报
|
||||||
* @param data 消息
|
* @param data 消息
|
||||||
|
@ -29,7 +29,7 @@ public class DeviceOperationController {
|
|||||||
private PubMqttCallBack pubMqttCallBack;
|
private PubMqttCallBack pubMqttCallBack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下发指令控制设备
|
* 下发指令控制阀门设备
|
||||||
*/
|
*/
|
||||||
@PostMapping("/control")
|
@PostMapping("/control")
|
||||||
public AjaxResult control(@RequestBody DeviceOperationDTO deviceOperationDTO){
|
public AjaxResult control(@RequestBody DeviceOperationDTO deviceOperationDTO){
|
||||||
@ -57,4 +57,24 @@ public class DeviceOperationController {
|
|||||||
return AjaxResult.error("未知命令!");
|
return AjaxResult.error("未知命令!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下发指令CMD控制设备指令
|
||||||
|
*/
|
||||||
|
@PostMapping("/control/cmd")
|
||||||
|
public AjaxResult controlCmd(@RequestBody DeviceOperationDTO deviceOperationDTO){
|
||||||
|
//构建主题
|
||||||
|
String topic ="hzlink/"+deviceOperationDTO.getProductId()+"/"+deviceOperationDTO.getDeviceNumber()+"/cmd/down";
|
||||||
|
//构建消息
|
||||||
|
Map<String,Object> param = new HashMap<>();
|
||||||
|
//远程阀控
|
||||||
|
param.put("cmd",Integer.parseInt(deviceOperationDTO.getOperationType()));
|
||||||
|
|
||||||
|
Map<String,Object> data = new HashMap<>();
|
||||||
|
data.put("addr",deviceOperationDTO.getAddr());
|
||||||
|
param.put("data",data);
|
||||||
|
pubMqttClient.publish(1,true,topic, JSONUtil.toJsonStr(param));
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
|
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@ -38,6 +39,9 @@ public class DeviceReportInfoController extends BaseController
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IDeviceReportInfoService deviceReportInfoService;
|
private IDeviceReportInfoService deviceReportInfoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询设备上电审核前上报的基础信息列表
|
* 查询设备上电审核前上报的基础信息列表
|
||||||
*/
|
*/
|
||||||
@ -48,6 +52,20 @@ public class DeviceReportInfoController extends BaseController
|
|||||||
{
|
{
|
||||||
startPage();
|
startPage();
|
||||||
List<DeviceReportInfo> list = deviceReportInfoService.selectDeviceReportInfoList(deviceReportInfo);
|
List<DeviceReportInfo> list = deviceReportInfoService.selectDeviceReportInfoList(deviceReportInfo);
|
||||||
|
//查询设备在线状态
|
||||||
|
list.forEach(d->{
|
||||||
|
if(d.getType()==1){
|
||||||
|
Boolean hassed = stringRedisTemplate.hasKey("neixiang_device_online_status:" + 147 + ":" + d.getSerialNumber());
|
||||||
|
if(hassed){
|
||||||
|
d.setOnLine(1);
|
||||||
|
}else{
|
||||||
|
d.setOnLine(0);
|
||||||
|
}
|
||||||
|
} else if ( d.getType()==2) {
|
||||||
|
//展连流量计设备在线状态判断
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,6 @@ public class UserConsumptionDetailsController extends BaseController
|
|||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出用户充值卡账单明细记录列表
|
* 导出用户充值卡账单明细记录列表
|
||||||
*/
|
*/
|
||||||
|
@ -154,4 +154,6 @@ public class DeviceReportInfo extends BaseEntity
|
|||||||
@ApiModelProperty("设备类型:1.水电双计 2.流量计")
|
@ApiModelProperty("设备类型:1.水电双计 2.流量计")
|
||||||
private Integer type;
|
private Integer type;
|
||||||
|
|
||||||
|
private Integer onLine;//0离线,1在线
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,16 @@ public class DeviceOperationDTO {
|
|||||||
private String operationType;
|
private String operationType;
|
||||||
|
|
||||||
private Integer operationCode;
|
private Integer operationCode;
|
||||||
|
|
||||||
|
private String operationValue;
|
||||||
|
|
||||||
|
private Integer addr;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@lombok.Data
|
||||||
|
private class CMDData {
|
||||||
|
// 设备操作类型
|
||||||
|
public Integer addr =123 ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user