WEB端解绑设备

This commit is contained in:
2025-07-30 18:39:12 +08:00
parent 4fa4e5ec29
commit ceeda046ea
7 changed files with 267 additions and 69 deletions

View File

@ -82,23 +82,23 @@ public class AppDeviceBizService {
public int sendMessage(AppDeviceSendMsgBo bo) {
List<Long> deviceIds = bo.getDeviceIds();
if(deviceIds == null || deviceIds.isEmpty()){
if (deviceIds == null || deviceIds.isEmpty()) {
throw new ServiceException("请选择设备");
}
for (Long deviceId : deviceIds){
for (Long deviceId : deviceIds) {
Device deviceObj = deviceMapper.selectById(deviceId);
if(deviceObj==null) {
throw new ServiceException("设备不存在"+deviceId);
if (deviceObj == null) {
throw new ServiceException("设备不存在" + deviceId);
}
byte[] msg = ReliableTextToBitmap.textToBitmapBytes(bo.getSendMsg());
ArrayList<Integer> intData = new ArrayList<>();
intData.add(2);
buildArr(convertHexToDecimal(msg),intData);
buildArr(convertHexToDecimal(msg), intData);
Map<String, Object> map = new HashMap<>();
map.put("instruct", intData);
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+deviceObj.getDeviceImei(), 1 ,JSON.toJSONString(map));
log.info("发送设备消息topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+deviceObj.getDeviceImei(),bo.getSendMsg());
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), 1, JSON.toJSONString(map));
log.info("发送设备消息topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), bo.getSendMsg());
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id", deviceId)
@ -147,7 +147,7 @@ public class AppDeviceBizService {
.set("update_time", new Date())
.set("binding_time", new Date());
return appDeviceBindRecordMapper.update(null, deviceUpdateWrapper);
}else{
} else {
AppDeviceBindRecord bindRecord = new AppDeviceBindRecord();
bindRecord.setDeviceId(device.getId());
bindRecord.setBindingUserId(userId);
@ -183,7 +183,7 @@ public class AppDeviceBizService {
.set("binding_user_id", userId)
.set("binding_time", new Date());
return appDeviceBindRecordMapper.update(null, deviceUpdateWrapper);
}else{
} else {
AppDeviceBindRecord bindRecord = new AppDeviceBindRecord();
bindRecord.setDeviceId(device.getId());
bindRecord.setBindingUserId(userId);
@ -204,7 +204,12 @@ public class AppDeviceBizService {
}
public int unBindDevice(Long id) {
return unBindDevice(id, null);
}
public int unBindDevice(Long id, Long userId) {
Device device = deviceMapper.selectById(id);
if (device == null) {
throw new RuntimeException("请先将设备入库!!!");
@ -216,7 +221,9 @@ public class AppDeviceBizService {
.set("binding_time", null);
deviceMapper.update(null, deviceUpdateWrapper);
Long userId = AppLoginHelper.getUserId();
if (userId == null){
userId = AppLoginHelper.getUserId();
}
QueryWrapper<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
bindRecordQueryWrapper.eq("device_id", device.getId());
bindRecordQueryWrapper.eq("binding_user_id", userId);
@ -228,6 +235,7 @@ public class AppDeviceBizService {
return 1;
}
public AppDeviceDetailVo getInfo(Long id) {
Device device = deviceMapper.selectById(id);
if (device == null) {
@ -241,7 +249,7 @@ public class AppDeviceBizService {
vo.setDeviceMac(device.getDeviceMac());
vo.setDeviceStatus(device.getDeviceStatus());
DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType());
if(deviceType!=null){
if (deviceType != null) {
vo.setCommunicationMode(Integer.valueOf(deviceType.getCommunicationMode()));
vo.setTypeName(deviceType.getTypeName());
}
@ -252,7 +260,7 @@ public class AppDeviceBizService {
QueryWrapper<AppPersonnelInfo> qw = new QueryWrapper<AppPersonnelInfo>()
.eq("device_id", device.getId());
AppPersonnelInfo appPersonnelInfo = appPersonnelInfoMapper.selectOne(qw);
if(appPersonnelInfo != null){
if (appPersonnelInfo != null) {
AppPersonnelInfoVo personnelInfoVo = MapstructUtils.convert(appPersonnelInfo, AppPersonnelInfoVo.class);
vo.setPersonnelInfo(personnelInfoVo);
}
@ -281,24 +289,24 @@ public class AppDeviceBizService {
// int[] a = new int[]{6,6,6,6,6,6};
ArrayList<Integer> intData = new ArrayList<>();
intData.add(2);
buildArr(convertHexToDecimal(unitName),intData);
buildArr(convertHexToDecimal(position),intData);
buildArr(convertHexToDecimal(name),intData);
buildArr(convertHexToDecimal(id),intData);
buildArr(convertHexToDecimal(unitName), intData);
buildArr(convertHexToDecimal(position), intData);
buildArr(convertHexToDecimal(name), intData);
buildArr(convertHexToDecimal(id), intData);
intData.add(0);
intData.add(0);
intData.add(0);
intData.add(0);
Map<String, Object> map = new HashMap<>();
map.put("instruct", intData);
System.out.println(JSON.toJSONString( map));
System.out.println(JSON.toJSONString(map));
}
public boolean registerPersonInfo(AppPersonnelInfoBo bo) {
Long deviceId = bo.getDeviceId();
Device deviceObj = deviceMapper.selectById(deviceId);
if(deviceObj == null){
if (deviceObj == null) {
throw new RuntimeException("请先将设备入库!!!");
}
QueryWrapper<AppPersonnelInfo> qw = new QueryWrapper<AppPersonnelInfo>()
@ -311,30 +319,30 @@ public class AppDeviceBizService {
byte[] id = generateFixedBitmapData(bo.getCode(), 120);
ArrayList<Integer> intData = new ArrayList<>();
intData.add(2);
buildArr(convertHexToDecimal(unitName),intData);
buildArr(convertHexToDecimal(position),intData);
buildArr(convertHexToDecimal(name),intData);
buildArr(convertHexToDecimal(id),intData);
buildArr(convertHexToDecimal(unitName), intData);
buildArr(convertHexToDecimal(position), intData);
buildArr(convertHexToDecimal(name), intData);
buildArr(convertHexToDecimal(id), intData);
intData.add(0);
intData.add(0);
intData.add(0);
intData.add(0);
Map<String, Object> map = new HashMap<>();
map.put("instruct", intData);
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+deviceObj.getDeviceImei(), 1 , JSON.toJSONString( map));
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+deviceObj.getDeviceImei(),bo);
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), 1, JSON.toJSONString(map));
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), bo);
if(ObjectUtils.length(appPersonnelInfoVos) == 0){
if (ObjectUtils.length(appPersonnelInfoVos) == 0) {
AppPersonnelInfo appPersonnelInfo = MapstructUtils.convert(bo, AppPersonnelInfo.class);
return appPersonnelInfoMapper.insertOrUpdate(appPersonnelInfo);
}else {
} else {
UpdateWrapper<AppPersonnelInfo> uw = new UpdateWrapper<>();
uw.eq("device_id", deviceId)
.set("name", bo.getName())
.set("position", bo.getPosition())
.set("unit_name", bo.getUnitName())
.set("code",bo.getCode());
return appPersonnelInfoMapper.update(null, uw)>0;
.set("code", bo.getCode());
return appPersonnelInfoMapper.update(null, uw) > 0;
}
@ -343,20 +351,20 @@ public class AppDeviceBizService {
public void uploadDeviceLogo(AppDeviceLogoUploadDto bo) {
try {
Device device = deviceMapper.selectById(bo.getDeviceId());
if(device == null){
if (device == null) {
throw new ServiceException("设备不存在");
}
MultipartFile file = bo.getFile();
byte[] largeData = ImageToCArrayConverter.convertImageToCArray(file.getInputStream(), 160, 80,25600);
System.out.println("长度:"+largeData.length);
byte[] largeData = ImageToCArrayConverter.convertImageToCArray(file.getInputStream(), 160, 80, 25600);
System.out.println("长度:" + largeData.length);
System.out.println("原始数据大小: " + largeData.length + " 字节");
int[] ints = convertHexToDecimal(largeData);
RedisUtils.setCacheObject("app_logo_data:"+device.getDeviceImei(), Arrays.toString(ints), Duration.ofSeconds(30*60L));
RedisUtils.setCacheObject("app_logo_data:" + device.getDeviceImei(), Arrays.toString(ints), Duration.ofSeconds(30 * 60L));
String data = RedisUtils.getCacheObject("app_logo_data:"+device.getDeviceImei());
String data = RedisUtils.getCacheObject("app_logo_data:" + device.getDeviceImei());
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, 0, 512);
@ -366,16 +374,16 @@ public class AppDeviceBizService {
ArrayList<Integer> intData = new ArrayList<>();
intData.add(3);
intData.add(1);
ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk),intData);
ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk), intData);
intData.add(0);
intData.add(0);
intData.add(0);
intData.add(0);
Map<String, Object> map = new HashMap<>();
map.put("instruct", intData);
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , JSON.toJSONString(map));
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),JSON.toJSONString(map));
} catch (Exception e){
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, JSON.toJSONString(map));
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), JSON.toJSONString(map));
} catch (Exception e) {
e.printStackTrace();
}
}
@ -388,7 +396,7 @@ public class AppDeviceBizService {
try {
Long deviceId = params.getLong("deviceId");
Device device = deviceMapper.selectById(deviceId);
if(device == null){
if (device == null) {
throw new ServiceException("设备不存在");
}
Integer instructValue = params.getInteger("instructValue");
@ -400,19 +408,19 @@ public class AppDeviceBizService {
intData.add(0);
Map<String, Object> map = new HashMap<>();
map.put("instruct", intData);
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , JSON.toJSONString(map));
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),JSON.toJSONString(map));
} catch (Exception e){
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, JSON.toJSONString(map));
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), JSON.toJSONString(map));
} catch (Exception e) {
e.printStackTrace();
}
}
//灯光亮度设置
// 灯光亮度设置
public void lightBrightnessSettings(JSONObject params) {
try {
Long deviceId = params.getLong("deviceId");
Device device = deviceMapper.selectById(deviceId);
if(device == null){
if (device == null) {
throw new ServiceException("设备不存在");
}
String instructValue = params.getString("instructValue");
@ -421,10 +429,10 @@ public class AppDeviceBizService {
String[] values = instructValue.split("\\.");
String value1 = values[0];
String value2 = values[1];
if(StringUtils.isNoneBlank(value1)){
if (StringUtils.isNoneBlank(value1)) {
intData.add(Integer.parseInt(value1));
}
if(StringUtils.isNoneBlank(value2)){
if (StringUtils.isNoneBlank(value2)) {
intData.add(Integer.parseInt(value2));
}
intData.add(0);
@ -432,19 +440,19 @@ public class AppDeviceBizService {
intData.add(0);
Map<String, Object> map = new HashMap<>();
map.put("instruct", intData);
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , JSON.toJSONString(map));
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),JSON.toJSONString(map));
} catch (Exception e){
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, JSON.toJSONString(map));
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), JSON.toJSONString(map));
} catch (Exception e) {
e.printStackTrace();
}
}
//激光模式设置
// 激光模式设置
public void laserModeSettings(JSONObject params) {
try {
Long deviceId = params.getLong("deviceId");
Device device = deviceMapper.selectById(deviceId);
if(device == null){
if (device == null) {
throw new ServiceException("设备不存在");
}
Integer instructValue = params.getInteger("instructValue");
@ -456,9 +464,9 @@ public class AppDeviceBizService {
intData.add(0);
Map<String, Object> map = new HashMap<>();
map.put("instruct", intData);
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , JSON.toJSONString(map));
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),JSON.toJSONString(map));
} catch (Exception e){
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, JSON.toJSONString(map));
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), JSON.toJSONString(map));
} catch (Exception e) {
e.printStackTrace();
}
}
@ -466,7 +474,7 @@ public class AppDeviceBizService {
public String mapReverseGeocoding(JSONObject params) {
Long deviceId = params.getLong("deviceId");
Device device = deviceMapper.selectById(deviceId);
if(device == null){
if (device == null) {
throw new ServiceException("设备不存在");
}
return RedisUtils.getCacheObject("device:location:" + device.getDeviceImei());