设备mqtt收发数据

This commit is contained in:
2025-07-30 17:13:57 +08:00
parent ac353b1078
commit a119ccc8d6
13 changed files with 238 additions and 115 deletions

View File

@ -1,9 +1,11 @@
package com.fuyuanshen.app.controller;
import cn.hutool.json.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
import com.fuyuanshen.app.domain.dto.APPReNameDTO;
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
import com.fuyuanshen.app.domain.vo.APPDeviceTypeVo;
import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo;
import com.fuyuanshen.app.service.AppDeviceBizService;
@ -23,6 +25,7 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Map;
/**
* APP设备信息管理
@ -129,7 +132,8 @@ public class AppDeviceController extends BaseController {
* 0关灯1强光模式2弱光模式, 3爆闪模式, 4泛光模式
*/
@PostMapping("/lightModeSettings")
public R<Void> lightModeSettings(@RequestBody JSONObject params) {
public R<Void> lightModeSettings(@RequestBody DeviceInstructDto params) {
// params 转 JSONObject
appDeviceService.lightModeSettings(params);
return R.ok();
}
@ -139,7 +143,7 @@ public class AppDeviceController extends BaseController {
*
*/
@PostMapping("/lightBrightnessSettings")
public R<Void> lightBrightnessSettings(@RequestBody JSONObject params) {
public R<Void> lightBrightnessSettings(@RequestBody DeviceInstructDto params) {
appDeviceService.lightBrightnessSettings(params);
return R.ok();
}
@ -149,7 +153,7 @@ public class AppDeviceController extends BaseController {
*
*/
@PostMapping("/laserModeSettings")
public R<Void> laserModeSettings(@RequestBody JSONObject params) {
public R<Void> laserModeSettings(@RequestBody DeviceInstructDto params) {
appDeviceService.laserModeSettings(params);
return R.ok();
}
@ -159,7 +163,7 @@ public class AppDeviceController extends BaseController {
*
*/
@PostMapping("/mapReverseGeocoding")
public R<Void> mapReverseGeocoding(@RequestBody JSONObject params) {
public R<Void> mapReverseGeocoding(@RequestBody DeviceInstructDto params) {
String mapJson = appDeviceService.mapReverseGeocoding(params);
return R.ok(mapJson);
}

View File

@ -0,0 +1,16 @@
package com.fuyuanshen.app.domain.dto;
import lombok.Data;
@Data
public class DeviceInstructDto {
private Long deviceId;
private String deviceImei;
/**
* 下发指令
*/
private Object instructValue;
}

View File

@ -10,6 +10,7 @@ import com.fuyuanshen.app.domain.AppPersonnelInfo;
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
import com.fuyuanshen.app.domain.dto.APPReNameDTO;
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
import com.fuyuanshen.app.domain.vo.APPDeviceTypeVo;
import com.fuyuanshen.app.domain.vo.AppDeviceBindRecordVo;
import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo;
@ -17,7 +18,6 @@ import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
import com.fuyuanshen.app.mapper.AppDeviceBindRecordMapper;
import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper;
import com.fuyuanshen.app.mapper.equipment.APPDeviceMapper;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.core.exception.ServiceException;
import com.fuyuanshen.common.core.utils.ImageToCArrayConverter;
import com.fuyuanshen.common.core.utils.MapstructUtils;
@ -384,14 +384,14 @@ public class AppDeviceBizService {
* 灯光模式
* 0关灯1强光模式2弱光模式, 3爆闪模式, 4泛光模式
*/
public void lightModeSettings(JSONObject params) {
public void lightModeSettings(DeviceInstructDto params) {
try {
Long deviceId = params.getLong("deviceId");
Long deviceId = params.getDeviceId();
Device device = deviceMapper.selectById(deviceId);
if(device == null){
throw new ServiceException("设备不存在");
}
Integer instructValue = params.getInteger("instructValue");
Integer instructValue = (Integer) params.getInstructValue();
ArrayList<Integer> intData = new ArrayList<>();
intData.add(1);
intData.add(instructValue);
@ -408,14 +408,14 @@ public class AppDeviceBizService {
}
//灯光亮度设置
public void lightBrightnessSettings(JSONObject params) {
public void lightBrightnessSettings(DeviceInstructDto params) {
try {
Long deviceId = params.getLong("deviceId");
Long deviceId = params.getDeviceId();
Device device = deviceMapper.selectById(deviceId);
if(device == null){
throw new ServiceException("设备不存在");
}
String instructValue = params.getString("instructValue");
String instructValue = (String)params.getInstructValue();
ArrayList<Integer> intData = new ArrayList<>();
intData.add(5);
String[] values = instructValue.split("\\.");
@ -440,14 +440,14 @@ public class AppDeviceBizService {
}
//激光模式设置
public void laserModeSettings(JSONObject params) {
public void laserModeSettings(DeviceInstructDto params) {
try {
Long deviceId = params.getLong("deviceId");
Long deviceId = params.getDeviceId();
Device device = deviceMapper.selectById(deviceId);
if(device == null){
throw new ServiceException("设备不存在");
}
Integer instructValue = params.getInteger("instructValue");
Integer instructValue = (Integer) params.getInstructValue();
ArrayList<Integer> intData = new ArrayList<>();
intData.add(4);
intData.add(instructValue);
@ -463,12 +463,15 @@ public class AppDeviceBizService {
}
}
public String mapReverseGeocoding(JSONObject params) {
Long deviceId = params.getLong("deviceId");
Device device = deviceMapper.selectById(deviceId);
if(device == null){
public String mapReverseGeocoding(DeviceInstructDto params) {
// Long deviceId = params.getDeviceId();
// Device device = deviceMapper.selectById(deviceId);
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("device_imei", params.getDeviceImei());
List<Device> devices = deviceMapper.selectList(queryWrapper);
if(ObjectUtils.length( devices) ==0){
throw new ServiceException("设备不存在");
}
return RedisUtils.getCacheObject("device:location:" + device.getDeviceImei());
return RedisUtils.getCacheObject("device:location:" + devices.get(0).getDeviceImei());
}
}