mqtt消息添加心跳包处理,设备新增运行状态字段以及接口
This commit is contained in:
@ -2,8 +2,12 @@ package com.fastbee.data.controller;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
|
||||
import com.dtflys.forest.annotation.Post;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.exception.ServiceException;
|
||||
import com.fastbee.iot.domain.DeviceReportInfo;
|
||||
import com.fastbee.iot.mapper.DeviceReportInfoMapper;
|
||||
import com.fastbee.iot.model.dto.DeviceOperationDTO;
|
||||
import com.fastbee.mqttclient.PubMqttCallBack;
|
||||
import com.fastbee.mqttclient.PubMqttClient;
|
||||
@ -20,6 +24,7 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* 下发指令操作设备
|
||||
* @author mijiupro
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/device/operation")
|
||||
@ -31,6 +36,9 @@ public class DeviceOperationController {
|
||||
@Autowired
|
||||
private PubMqttCallBack pubMqttCallBack;
|
||||
|
||||
@Autowired
|
||||
private DeviceReportInfoMapper deviceReportInfoMapper;
|
||||
|
||||
/**
|
||||
* 下发指令控制阀门设备
|
||||
*/
|
||||
|
@ -8,6 +8,10 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
|
||||
import com.fastbee.common.exception.ServiceException;
|
||||
import com.fastbee.iot.mapper.DeviceReportInfoMapper;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -42,6 +46,9 @@ public class DeviceReportInfoController extends BaseController
|
||||
@Autowired
|
||||
private IDeviceReportInfoService deviceReportInfoService;
|
||||
|
||||
@Autowired
|
||||
private DeviceReportInfoMapper deviceReportInfoMapper;
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@ -83,27 +90,25 @@ public class DeviceReportInfoController extends BaseController
|
||||
//统计是设备相关信息
|
||||
@GetMapping("/list/count")
|
||||
@ApiOperation("统计是设备相关信息")
|
||||
public AjaxResult listCount(DeviceReportInfo deviceReportInfo)
|
||||
{
|
||||
List<DeviceReportInfo> list = deviceReportInfoService.selectDeviceReportInfoList(deviceReportInfo);
|
||||
AtomicInteger onLineTotal= new AtomicInteger();
|
||||
list.forEach(d->{
|
||||
if(d.getType()==1){
|
||||
if(Boolean.TRUE.equals(stringRedisTemplate.hasKey("neixiang_device_online_status:" + 147 + ":" + d.getSerialNumber())))
|
||||
{
|
||||
onLineTotal.getAndIncrement();
|
||||
}
|
||||
} else if ( d.getType()==2) {
|
||||
if(d.getOnLine()==1){
|
||||
onLineTotal.getAndIncrement();
|
||||
}
|
||||
public AjaxResult listCount(DeviceReportInfo deviceReportInfo) {
|
||||
List<DeviceReportInfo> list = deviceReportInfoService.selectDeviceReportInfoList(deviceReportInfo);
|
||||
int onLineTotal = 0; // 使用普通的整型变量来计数
|
||||
for (DeviceReportInfo d : list) {
|
||||
if (d.getType() == 1) {
|
||||
if (Boolean.TRUE.equals(stringRedisTemplate.hasKey("neixiang_device_online_status:" + 147 + ":" + d.getSerialNumber()))) {
|
||||
onLineTotal++;
|
||||
}
|
||||
});
|
||||
Map<String,Object> resp=new HashMap<>();
|
||||
resp.put("allTotal",list.size());
|
||||
resp.put("onLineTotal",onLineTotal.get());
|
||||
return AjaxResult.success((resp));
|
||||
} else if (d.getType() == 2) {
|
||||
if (d.getOnLine() == 1) {
|
||||
onLineTotal++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<String, Object> resp = new HashMap<>();
|
||||
resp.put("allTotal", list.size());
|
||||
resp.put("onLineTotal", onLineTotal);
|
||||
return AjaxResult.success(resp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出设备上电审核前上报的基础信息列表
|
||||
@ -171,4 +176,34 @@ public class DeviceReportInfoController extends BaseController
|
||||
public AjaxResult updateStatus(@RequestBody List<DeviceReportInfo> deviceReportInfos){
|
||||
return toAjax(deviceReportInfoService.updateDeviceReportStatus(deviceReportInfos));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新设备当前状态
|
||||
*/
|
||||
@PostMapping("/update/run/status")
|
||||
public AjaxResult updateStatus(String deviceNumber,Integer status){
|
||||
boolean update = new LambdaUpdateChainWrapper<>(deviceReportInfoMapper)
|
||||
.set(DeviceReportInfo::getStatus, status)
|
||||
.eq(DeviceReportInfo::getSerialNumber, deviceNumber)
|
||||
.update();
|
||||
if(!update){
|
||||
throw new ServiceException("更新设备运行状态失败!");
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
/**
|
||||
* 查询设备运行状态
|
||||
*/
|
||||
@GetMapping("/get/run/status")
|
||||
public AjaxResult getStatus(String deviceNumber){
|
||||
List<DeviceReportInfo> list = new LambdaQueryChainWrapper<>(deviceReportInfoMapper)
|
||||
.select(DeviceReportInfo::getStatus)
|
||||
.eq(DeviceReportInfo::getSerialNumber, deviceNumber)
|
||||
.list();
|
||||
if(!list.isEmpty()){
|
||||
return AjaxResult.success(list.get(0).getStatus());
|
||||
}
|
||||
return AjaxResult.error("设备不存在!");
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user