2025-07-19 09:36:35 +08:00
|
|
|
|
package com.fuyuanshen.app.service;
|
|
|
|
|
|
2025-07-31 09:08:17 +08:00
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
2025-07-22 18:37:02 +08:00
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
2025-07-30 08:50:44 +08:00
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
2025-07-19 09:36:35 +08:00
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
2025-07-28 18:26:02 +08:00
|
|
|
|
import com.fuyuanshen.app.domain.AppDeviceBindRecord;
|
2025-07-19 09:36:35 +08:00
|
|
|
|
import com.fuyuanshen.app.domain.AppPersonnelInfo;
|
|
|
|
|
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
|
|
|
|
|
import com.fuyuanshen.app.domain.dto.APPReNameDTO;
|
2025-07-28 18:26:02 +08:00
|
|
|
|
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
|
2025-08-12 17:03:11 +08:00
|
|
|
|
import com.fuyuanshen.app.domain.dto.AppRealTimeStatusDto;
|
2025-07-30 17:13:57 +08:00
|
|
|
|
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
|
2025-07-19 09:36:35 +08:00
|
|
|
|
import com.fuyuanshen.app.domain.vo.APPDeviceTypeVo;
|
|
|
|
|
import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo;
|
|
|
|
|
import com.fuyuanshen.app.domain.vo.AppPersonnelInfoVo;
|
2025-07-28 18:26:02 +08:00
|
|
|
|
import com.fuyuanshen.app.mapper.AppDeviceBindRecordMapper;
|
2025-07-19 09:36:35 +08:00
|
|
|
|
import com.fuyuanshen.app.mapper.AppPersonnelInfoMapper;
|
|
|
|
|
import com.fuyuanshen.app.mapper.equipment.APPDeviceMapper;
|
2025-08-14 11:51:27 +08:00
|
|
|
|
import com.fuyuanshen.app.service.device.status.base.DeviceStatusRule;
|
|
|
|
|
import com.fuyuanshen.app.service.device.status.base.RealTimeStatusEngine;
|
2025-07-31 19:03:04 +08:00
|
|
|
|
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
2025-07-22 18:37:02 +08:00
|
|
|
|
import com.fuyuanshen.common.core.exception.ServiceException;
|
2025-08-04 15:35:59 +08:00
|
|
|
|
import com.fuyuanshen.common.core.utils.*;
|
2025-07-19 09:36:35 +08:00
|
|
|
|
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
|
|
|
|
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
2025-07-28 18:26:02 +08:00
|
|
|
|
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
2025-07-19 09:36:35 +08:00
|
|
|
|
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
|
|
|
|
|
import com.fuyuanshen.equipment.domain.Device;
|
|
|
|
|
import com.fuyuanshen.equipment.domain.DeviceType;
|
|
|
|
|
import com.fuyuanshen.equipment.domain.dto.AppDeviceBo;
|
2025-07-22 18:37:02 +08:00
|
|
|
|
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
|
2025-07-19 09:36:35 +08:00
|
|
|
|
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
|
|
|
|
import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
|
|
|
|
|
import com.fuyuanshen.equipment.enums.BindingStatusEnum;
|
|
|
|
|
import com.fuyuanshen.equipment.enums.CommunicationModeEnum;
|
|
|
|
|
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
|
|
|
|
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
2025-08-12 17:03:11 +08:00
|
|
|
|
import com.fuyuanshen.equipment.service.DeviceService;
|
2025-07-30 08:50:44 +08:00
|
|
|
|
import com.fuyuanshen.global.mqtt.config.MqttGateway;
|
2025-07-31 18:09:20 +08:00
|
|
|
|
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
|
2025-07-30 08:50:44 +08:00
|
|
|
|
import com.fuyuanshen.global.mqtt.constants.MqttConstants;
|
2025-07-19 09:36:35 +08:00
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2025-08-04 15:35:59 +08:00
|
|
|
|
import org.springframework.core.io.ClassPathResource;
|
2025-07-19 09:36:35 +08:00
|
|
|
|
import org.springframework.stereotype.Service;
|
2025-07-28 18:26:02 +08:00
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
2025-07-19 09:36:35 +08:00
|
|
|
|
|
2025-08-04 15:35:59 +08:00
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
2025-07-28 18:26:02 +08:00
|
|
|
|
import java.time.Duration;
|
|
|
|
|
import java.util.*;
|
2025-07-21 15:24:26 +08:00
|
|
|
|
|
2025-07-31 18:09:20 +08:00
|
|
|
|
import static com.fuyuanshen.common.core.constant.GlobalConstants.GLOBAL_REDIS_KEY;
|
|
|
|
|
import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.buildArr;
|
|
|
|
|
import static com.fuyuanshen.common.core.utils.Bitmap80x12Generator.generateFixedBitmapData;
|
|
|
|
|
import static com.fuyuanshen.common.core.utils.ImageToCArrayConverter.convertHexToDecimal;
|
2025-08-07 15:41:57 +08:00
|
|
|
|
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
2025-07-31 18:09:20 +08:00
|
|
|
|
|
2025-07-19 09:36:35 +08:00
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public class AppDeviceBizService {
|
|
|
|
|
|
|
|
|
|
private final APPDeviceMapper appDeviceMapper;
|
|
|
|
|
private final DeviceMapper deviceMapper;
|
|
|
|
|
private final AppPersonnelInfoMapper appPersonnelInfoMapper;
|
|
|
|
|
private final DeviceTypeMapper deviceTypeMapper;
|
2025-07-22 18:37:02 +08:00
|
|
|
|
private final MqttGateway mqttGateway;
|
2025-07-28 18:26:02 +08:00
|
|
|
|
private final AppDeviceBindRecordMapper appDeviceBindRecordMapper;
|
2025-08-12 17:03:11 +08:00
|
|
|
|
private final RealTimeStatusEngine realTimeStatusEngine;
|
|
|
|
|
private final DeviceService deviceService;
|
|
|
|
|
|
2025-07-19 09:36:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<APPDeviceTypeVo> getTypeList() {
|
|
|
|
|
Long userId = AppLoginHelper.getUserId();
|
|
|
|
|
return appDeviceMapper.getTypeList(userId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void reName(APPReNameDTO reNameDTO) {
|
|
|
|
|
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
|
|
|
|
updateWrapper.eq("id", reNameDTO.getId())
|
|
|
|
|
.eq("binding_user_id", AppLoginHelper.getUserId())
|
|
|
|
|
.set("device_name", reNameDTO.getDeviceName());
|
|
|
|
|
deviceMapper.update(updateWrapper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-07-22 18:37:02 +08:00
|
|
|
|
public int sendMessage(AppDeviceSendMsgBo bo) {
|
|
|
|
|
List<Long> deviceIds = bo.getDeviceIds();
|
2025-07-30 18:39:12 +08:00
|
|
|
|
if (deviceIds == null || deviceIds.isEmpty()) {
|
2025-07-22 18:37:02 +08:00
|
|
|
|
throw new ServiceException("请选择设备");
|
|
|
|
|
}
|
2025-07-30 18:39:12 +08:00
|
|
|
|
for (Long deviceId : deviceIds) {
|
2025-08-04 15:35:59 +08:00
|
|
|
|
Device device = deviceMapper.selectById(deviceId);
|
|
|
|
|
if (device == null) {
|
2025-07-30 18:39:12 +08:00
|
|
|
|
throw new ServiceException("设备不存在" + deviceId);
|
2025-07-22 18:37:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-08-04 15:35:59 +08:00
|
|
|
|
try {
|
|
|
|
|
ClassPathResource resource = new ClassPathResource("image/background.png");
|
|
|
|
|
InputStream inputStream = resource.getInputStream();
|
|
|
|
|
|
|
|
|
|
// String backgroundImagePath = "D:\\background.png"; // 替换为实际背景图片路径
|
|
|
|
|
byte[] largeData = ImageWithTextGenerate.generate160x80ImageWithText2(bo.getSendMsg(), inputStream, 25600);
|
|
|
|
|
int[] ints = convertHexToDecimal(largeData);
|
2025-08-07 15:41:57 +08:00
|
|
|
|
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_SEND_MESSAGE_KEY_PREFIX , Arrays.toString(ints), Duration.ofSeconds(30 * 60L));
|
2025-08-04 15:35:59 +08:00
|
|
|
|
|
2025-08-07 15:41:57 +08:00
|
|
|
|
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_SEND_MESSAGE_KEY_PREFIX);
|
2025-08-04 15:35:59 +08:00
|
|
|
|
|
|
|
|
|
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
|
|
|
|
|
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, 0, 512);
|
2025-08-07 15:41:57 +08:00
|
|
|
|
log.info("发送信息第0块数据大小: {} 字节",specificChunk.length);
|
|
|
|
|
// log.info("第0块数据: {}", Arrays.toString(specificChunk));
|
2025-08-04 15:35:59 +08:00
|
|
|
|
|
|
|
|
|
ArrayList<Integer> intData = new ArrayList<>();
|
|
|
|
|
intData.add(6);
|
|
|
|
|
intData.add(1);
|
|
|
|
|
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));
|
2025-08-07 15:41:57 +08:00
|
|
|
|
log.info("发送信息点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),JSON.toJSONString(map));
|
2025-08-04 15:35:59 +08:00
|
|
|
|
|
|
|
|
|
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
|
|
|
|
updateWrapper.eq("id", deviceId)
|
|
|
|
|
.eq("binding_user_id", AppLoginHelper.getUserId())
|
|
|
|
|
.set("send_msg", bo.getSendMsg());
|
|
|
|
|
deviceMapper.update(updateWrapper);
|
|
|
|
|
} catch (Exception e) {
|
2025-08-07 15:41:57 +08:00
|
|
|
|
log.info("发送信息设备发送信息失败:{}" ,deviceId);
|
2025-08-04 15:35:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-07-22 18:37:02 +08:00
|
|
|
|
}
|
|
|
|
|
return 1;
|
2025-07-19 09:36:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TableDataInfo<AppDeviceVo> queryAppDeviceList(DeviceQueryCriteria bo, PageQuery pageQuery) {
|
|
|
|
|
if (bo.getBindingUserId() == null) {
|
|
|
|
|
Long userId = AppLoginHelper.getUserId();
|
|
|
|
|
bo.setBindingUserId(userId);
|
|
|
|
|
}
|
|
|
|
|
Page<AppDeviceVo> result = deviceMapper.queryAppBindDeviceList(pageQuery.build(), bo);
|
2025-07-31 18:09:20 +08:00
|
|
|
|
List<AppDeviceVo> records = result.getRecords();
|
|
|
|
|
if(records != null && !records.isEmpty()){
|
|
|
|
|
records.forEach(item -> {
|
|
|
|
|
if(item.getCommunicationMode()!=null && item.getCommunicationMode() == 0){
|
|
|
|
|
|
|
|
|
|
//设备在线状态
|
2025-08-07 15:41:57 +08:00
|
|
|
|
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
2025-07-31 18:09:20 +08:00
|
|
|
|
if(StringUtils.isNotBlank(onlineStatus)){
|
|
|
|
|
|
|
|
|
|
item.setOnlineStatus(1);
|
|
|
|
|
}else{
|
|
|
|
|
item.setOnlineStatus(0);
|
|
|
|
|
}
|
2025-08-07 15:41:57 +08:00
|
|
|
|
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX+ item.getDeviceImei() + DEVICE_STATUS_KEY_PREFIX);
|
2025-07-31 18:09:20 +08:00
|
|
|
|
// 获取电量
|
|
|
|
|
if(StringUtils.isNotBlank(deviceStatus)){
|
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(deviceStatus);
|
|
|
|
|
item.setBattery(jsonObject.getString("batteryPercentage"));
|
|
|
|
|
}else{
|
|
|
|
|
item.setBattery("0");
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-07 15:41:57 +08:00
|
|
|
|
String location = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ item.getDeviceImei()+ DEVICE_LOCATION_KEY_PREFIX);
|
2025-08-01 11:11:36 +08:00
|
|
|
|
if(StringUtils.isNotBlank(location)){
|
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(location);
|
|
|
|
|
item.setLatitude(jsonObject.getString("latitude"));
|
|
|
|
|
item.setLongitude(jsonObject.getString("longitude"));
|
|
|
|
|
}
|
2025-08-07 15:41:57 +08:00
|
|
|
|
|
|
|
|
|
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ item.getDeviceImei()+ DEVICE_ALARM_KEY_PREFIX);
|
|
|
|
|
if(StringUtils.isNotBlank(alarmStatus)){
|
|
|
|
|
item.setAlarmStatus(alarmStatus);
|
|
|
|
|
}
|
2025-07-31 18:09:20 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-07-19 09:36:35 +08:00
|
|
|
|
return TableDataInfo.build(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int bindDevice(AppDeviceBo bo) {
|
|
|
|
|
Integer mode = bo.getCommunicationMode();
|
|
|
|
|
Long userId = AppLoginHelper.getUserId();
|
|
|
|
|
if (mode == CommunicationModeEnum.FOUR_G.getValue()) {
|
|
|
|
|
|
|
|
|
|
String deviceImei = bo.getDeviceImei();
|
|
|
|
|
QueryWrapper<Device> qw = new QueryWrapper<Device>()
|
|
|
|
|
.eq("device_imei", deviceImei);
|
|
|
|
|
List<Device> devices = deviceMapper.selectList(qw);
|
|
|
|
|
if (devices.isEmpty()) {
|
|
|
|
|
throw new RuntimeException("请先将设备入库!!!");
|
|
|
|
|
}
|
|
|
|
|
Device device = devices.get(0);
|
|
|
|
|
if (device.getBindingStatus() != null && device.getBindingStatus() == BindingStatusEnum.BOUND.getCode()) {
|
|
|
|
|
throw new RuntimeException("设备已绑定");
|
|
|
|
|
}
|
2025-07-28 18:26:02 +08:00
|
|
|
|
|
|
|
|
|
QueryWrapper<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
bindRecordQueryWrapper.eq("device_id", device.getId());
|
|
|
|
|
AppDeviceBindRecord appDeviceBindRecord = appDeviceBindRecordMapper.selectOne(bindRecordQueryWrapper);
|
|
|
|
|
if (appDeviceBindRecord != null) {
|
|
|
|
|
UpdateWrapper<AppDeviceBindRecord> deviceUpdateWrapper = new UpdateWrapper<>();
|
|
|
|
|
deviceUpdateWrapper.eq("device_id", device.getId())
|
|
|
|
|
.set("binding_status", BindingStatusEnum.BOUND.getCode())
|
|
|
|
|
.set("binding_user_id", userId)
|
|
|
|
|
.set("update_time", new Date())
|
|
|
|
|
.set("binding_time", new Date());
|
|
|
|
|
return appDeviceBindRecordMapper.update(null, deviceUpdateWrapper);
|
2025-07-30 18:39:12 +08:00
|
|
|
|
} else {
|
2025-07-28 18:26:02 +08:00
|
|
|
|
AppDeviceBindRecord bindRecord = new AppDeviceBindRecord();
|
|
|
|
|
bindRecord.setDeviceId(device.getId());
|
|
|
|
|
bindRecord.setBindingUserId(userId);
|
|
|
|
|
bindRecord.setBindingTime(new Date());
|
|
|
|
|
bindRecord.setCreateBy(userId);
|
|
|
|
|
appDeviceBindRecordMapper.insert(bindRecord);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-19 09:36:35 +08:00
|
|
|
|
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
|
|
|
|
deviceUpdateWrapper.eq("id", device.getId())
|
|
|
|
|
.set("binding_status", BindingStatusEnum.BOUND.getCode())
|
|
|
|
|
.set("binding_user_id", userId)
|
|
|
|
|
.set("binding_time", new Date());
|
|
|
|
|
return deviceMapper.update(null, deviceUpdateWrapper);
|
|
|
|
|
} else if (mode == CommunicationModeEnum.BLUETOOTH.getValue()) {
|
|
|
|
|
String deviceMac = bo.getDeviceMac();
|
|
|
|
|
QueryWrapper<Device> qw = new QueryWrapper<Device>()
|
|
|
|
|
.eq("device_mac", deviceMac);
|
|
|
|
|
List<Device> devices = deviceMapper.selectList(qw);
|
|
|
|
|
if (devices.isEmpty()) {
|
|
|
|
|
throw new RuntimeException("请先将设备入库!!!");
|
|
|
|
|
}
|
|
|
|
|
Device device = devices.get(0);
|
2025-07-28 18:26:02 +08:00
|
|
|
|
|
|
|
|
|
QueryWrapper<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
bindRecordQueryWrapper.eq("device_id", device.getId());
|
|
|
|
|
bindRecordQueryWrapper.eq("binding_user_id", userId);
|
|
|
|
|
AppDeviceBindRecord appDeviceBindRecord = appDeviceBindRecordMapper.selectOne(bindRecordQueryWrapper);
|
|
|
|
|
if (appDeviceBindRecord != null) {
|
|
|
|
|
UpdateWrapper<AppDeviceBindRecord> deviceUpdateWrapper = new UpdateWrapper<>();
|
|
|
|
|
deviceUpdateWrapper.eq("device_id", device.getId())
|
|
|
|
|
.eq("binding_user_id", userId)
|
|
|
|
|
.set("binding_user_id", userId)
|
|
|
|
|
.set("binding_time", new Date());
|
|
|
|
|
return appDeviceBindRecordMapper.update(null, deviceUpdateWrapper);
|
2025-07-30 18:39:12 +08:00
|
|
|
|
} else {
|
2025-07-28 18:26:02 +08:00
|
|
|
|
AppDeviceBindRecord bindRecord = new AppDeviceBindRecord();
|
|
|
|
|
bindRecord.setDeviceId(device.getId());
|
|
|
|
|
bindRecord.setBindingUserId(userId);
|
|
|
|
|
bindRecord.setBindingTime(new Date());
|
|
|
|
|
bindRecord.setCreateBy(userId);
|
|
|
|
|
appDeviceBindRecordMapper.insert(bindRecord);
|
2025-07-19 09:36:35 +08:00
|
|
|
|
}
|
2025-07-28 18:26:02 +08:00
|
|
|
|
|
2025-07-19 09:36:35 +08:00
|
|
|
|
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
|
|
|
|
deviceUpdateWrapper.eq("id", device.getId())
|
|
|
|
|
.set("binding_status", BindingStatusEnum.BOUND.getCode())
|
|
|
|
|
.set("binding_user_id", userId)
|
|
|
|
|
.set("binding_time", new Date());
|
|
|
|
|
return deviceMapper.update(null, deviceUpdateWrapper);
|
|
|
|
|
} else {
|
|
|
|
|
throw new RuntimeException("通讯方式错误");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-30 18:39:12 +08:00
|
|
|
|
|
2025-07-19 09:36:35 +08:00
|
|
|
|
public int unBindDevice(Long id) {
|
2025-07-31 09:08:17 +08:00
|
|
|
|
return unBindDevice(id, null, 1);
|
2025-07-30 18:39:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 09:08:17 +08:00
|
|
|
|
public int unBindDevice(Long id, Long userId, int type) {
|
2025-07-19 09:36:35 +08:00
|
|
|
|
Device device = deviceMapper.selectById(id);
|
|
|
|
|
if (device == null) {
|
|
|
|
|
throw new RuntimeException("请先将设备入库!!!");
|
|
|
|
|
}
|
|
|
|
|
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
|
|
|
|
deviceUpdateWrapper.eq("id", device.getId())
|
|
|
|
|
.set("binding_user_id", null)
|
2025-07-28 18:26:02 +08:00
|
|
|
|
.set("binding_status", BindingStatusEnum.UNBOUND.getCode())
|
2025-07-19 09:36:35 +08:00
|
|
|
|
.set("binding_time", null);
|
2025-07-28 18:26:02 +08:00
|
|
|
|
deviceMapper.update(null, deviceUpdateWrapper);
|
|
|
|
|
|
2025-07-31 09:08:17 +08:00
|
|
|
|
if (userId == null) {
|
|
|
|
|
userId = AppLoginHelper.getUserId();
|
2025-07-30 18:39:12 +08:00
|
|
|
|
}
|
2025-07-28 18:26:02 +08:00
|
|
|
|
QueryWrapper<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
bindRecordQueryWrapper.eq("device_id", device.getId());
|
2025-07-31 09:08:17 +08:00
|
|
|
|
// 设备端解绑 0:设备端解绑 1:web端解绑
|
|
|
|
|
if (type == 1) {
|
|
|
|
|
bindRecordQueryWrapper.eq("binding_user_id", userId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AppDeviceBindRecord appDeviceBindRecord = appDeviceBindRecordMapper.selectOne(bindRecordQueryWrapper);
|
|
|
|
|
// if (appDeviceBindRecord != null) {
|
|
|
|
|
// return appDeviceBindRecordMapper.deleteById(appDeviceBindRecord.getId());
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
List<AppDeviceBindRecord> appDeviceBindRecordList = appDeviceBindRecordMapper.selectList(bindRecordQueryWrapper);
|
|
|
|
|
if (CollectionUtil.isNotEmpty(appDeviceBindRecordList)) {
|
|
|
|
|
appDeviceBindRecordList.forEach(appDeviceBindRecord ->
|
|
|
|
|
appDeviceBindRecordMapper.deleteById(appDeviceBindRecord.getId()));
|
2025-07-28 18:26:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
2025-07-19 09:36:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-07-30 18:39:12 +08:00
|
|
|
|
|
2025-07-19 09:36:35 +08:00
|
|
|
|
public AppDeviceDetailVo getInfo(Long id) {
|
|
|
|
|
Device device = deviceMapper.selectById(id);
|
2025-07-21 15:24:26 +08:00
|
|
|
|
if (device == null) {
|
|
|
|
|
throw new RuntimeException("请先将设备入库!!!");
|
|
|
|
|
}
|
2025-07-19 09:36:35 +08:00
|
|
|
|
AppDeviceDetailVo vo = new AppDeviceDetailVo();
|
|
|
|
|
vo.setDeviceId(device.getId());
|
|
|
|
|
vo.setDeviceName(device.getDeviceName());
|
|
|
|
|
vo.setDevicePic(device.getDevicePic());
|
|
|
|
|
vo.setDeviceImei(device.getDeviceImei());
|
|
|
|
|
vo.setDeviceMac(device.getDeviceMac());
|
|
|
|
|
vo.setDeviceStatus(device.getDeviceStatus());
|
|
|
|
|
DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType());
|
2025-07-30 18:39:12 +08:00
|
|
|
|
if (deviceType != null) {
|
2025-07-19 09:36:35 +08:00
|
|
|
|
vo.setCommunicationMode(Integer.valueOf(deviceType.getCommunicationMode()));
|
|
|
|
|
vo.setTypeName(deviceType.getTypeName());
|
|
|
|
|
}
|
|
|
|
|
vo.setBluetoothName(device.getBluetoothName());
|
|
|
|
|
|
2025-07-21 15:24:26 +08:00
|
|
|
|
vo.setSendMsg(device.getSendMsg());
|
|
|
|
|
|
|
|
|
|
QueryWrapper<AppPersonnelInfo> qw = new QueryWrapper<AppPersonnelInfo>()
|
|
|
|
|
.eq("device_id", device.getId());
|
|
|
|
|
AppPersonnelInfo appPersonnelInfo = appPersonnelInfoMapper.selectOne(qw);
|
2025-07-30 18:39:12 +08:00
|
|
|
|
if (appPersonnelInfo != null) {
|
2025-07-19 09:36:35 +08:00
|
|
|
|
AppPersonnelInfoVo personnelInfoVo = MapstructUtils.convert(appPersonnelInfo, AppPersonnelInfoVo.class);
|
|
|
|
|
vo.setPersonnelInfo(personnelInfoVo);
|
|
|
|
|
}
|
2025-07-31 18:09:20 +08:00
|
|
|
|
//设备在线状态
|
2025-08-07 15:41:57 +08:00
|
|
|
|
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
2025-07-31 18:09:20 +08:00
|
|
|
|
if(StringUtils.isNotBlank(onlineStatus)){
|
|
|
|
|
vo.setOnlineStatus(1);
|
|
|
|
|
}else{
|
|
|
|
|
vo.setOnlineStatus(0);
|
|
|
|
|
}
|
2025-08-07 15:41:57 +08:00
|
|
|
|
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
2025-07-31 18:09:20 +08:00
|
|
|
|
// 获取电量
|
|
|
|
|
if(StringUtils.isNotBlank(deviceStatus)){
|
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(deviceStatus);
|
|
|
|
|
vo.setMainLightMode(jsonObject.getString("mainLightMode"));
|
|
|
|
|
vo.setLaserLightMode(jsonObject.getString("laserLightMode"));
|
|
|
|
|
vo.setBatteryPercentage(jsonObject.getString("batteryPercentage"));
|
|
|
|
|
vo.setChargeState(jsonObject.getString("chargeState"));
|
|
|
|
|
vo.setBatteryRemainingTime(jsonObject.getString("batteryRemainingTime"));
|
|
|
|
|
}else{
|
|
|
|
|
vo.setBatteryPercentage("0");
|
|
|
|
|
}
|
2025-07-31 19:03:04 +08:00
|
|
|
|
|
|
|
|
|
// 获取经度纬度
|
2025-08-07 15:41:57 +08:00
|
|
|
|
String locationKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_LOCATION_KEY_PREFIX;
|
2025-08-01 11:11:36 +08:00
|
|
|
|
String locationInfo = RedisUtils.getCacheObject(locationKey);
|
2025-07-31 19:03:04 +08:00
|
|
|
|
if(StringUtils.isNotBlank(locationInfo)){
|
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(locationInfo);
|
2025-08-01 16:27:17 +08:00
|
|
|
|
vo.setLongitude(jsonObject.get("longitude").toString());
|
|
|
|
|
vo.setLatitude(jsonObject.get("latitude").toString());
|
2025-07-31 19:03:04 +08:00
|
|
|
|
vo.setAddress((String)jsonObject.get("address"));
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-19 09:36:35 +08:00
|
|
|
|
return vo;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-28 18:26:02 +08:00
|
|
|
|
|
2025-07-19 09:36:35 +08:00
|
|
|
|
public boolean registerPersonInfo(AppPersonnelInfoBo bo) {
|
2025-07-21 15:24:26 +08:00
|
|
|
|
Long deviceId = bo.getDeviceId();
|
2025-07-22 18:37:02 +08:00
|
|
|
|
Device deviceObj = deviceMapper.selectById(deviceId);
|
2025-07-30 18:39:12 +08:00
|
|
|
|
if (deviceObj == null) {
|
2025-07-22 18:37:02 +08:00
|
|
|
|
throw new RuntimeException("请先将设备入库!!!");
|
|
|
|
|
}
|
2025-07-21 15:24:26 +08:00
|
|
|
|
QueryWrapper<AppPersonnelInfo> qw = new QueryWrapper<AppPersonnelInfo>()
|
|
|
|
|
.eq("device_id", deviceId);
|
|
|
|
|
List<AppPersonnelInfoVo> appPersonnelInfoVos = appPersonnelInfoMapper.selectVoList(qw);
|
2025-07-22 18:37:02 +08:00
|
|
|
|
// unitName,position,name,id
|
2025-07-28 18:26:02 +08:00
|
|
|
|
byte[] unitName = generateFixedBitmapData(bo.getUnitName(), 120);
|
|
|
|
|
byte[] position = generateFixedBitmapData(bo.getPosition(), 120);
|
|
|
|
|
byte[] name = generateFixedBitmapData(bo.getName(), 120);
|
|
|
|
|
byte[] id = generateFixedBitmapData(bo.getCode(), 120);
|
|
|
|
|
ArrayList<Integer> intData = new ArrayList<>();
|
|
|
|
|
intData.add(2);
|
2025-07-30 18:39:12 +08:00
|
|
|
|
buildArr(convertHexToDecimal(unitName), intData);
|
|
|
|
|
buildArr(convertHexToDecimal(position), intData);
|
|
|
|
|
buildArr(convertHexToDecimal(name), intData);
|
|
|
|
|
buildArr(convertHexToDecimal(id), intData);
|
2025-07-28 18:26:02 +08:00
|
|
|
|
intData.add(0);
|
|
|
|
|
intData.add(0);
|
|
|
|
|
intData.add(0);
|
|
|
|
|
intData.add(0);
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
map.put("instruct", intData);
|
2025-07-30 18:39:12 +08:00
|
|
|
|
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), 1, JSON.toJSONString(map));
|
|
|
|
|
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + deviceObj.getDeviceImei(), bo);
|
2025-07-22 18:37:02 +08:00
|
|
|
|
|
2025-07-30 18:39:12 +08:00
|
|
|
|
if (ObjectUtils.length(appPersonnelInfoVos) == 0) {
|
2025-07-21 15:24:26 +08:00
|
|
|
|
AppPersonnelInfo appPersonnelInfo = MapstructUtils.convert(bo, AppPersonnelInfo.class);
|
|
|
|
|
return appPersonnelInfoMapper.insertOrUpdate(appPersonnelInfo);
|
2025-07-30 18:39:12 +08:00
|
|
|
|
} else {
|
2025-07-21 15:24:26 +08:00
|
|
|
|
UpdateWrapper<AppPersonnelInfo> uw = new UpdateWrapper<>();
|
|
|
|
|
uw.eq("device_id", deviceId)
|
|
|
|
|
.set("name", bo.getName())
|
|
|
|
|
.set("position", bo.getPosition())
|
|
|
|
|
.set("unit_name", bo.getUnitName())
|
2025-07-30 18:39:12 +08:00
|
|
|
|
.set("code", bo.getCode());
|
|
|
|
|
return appPersonnelInfoMapper.update(null, uw) > 0;
|
2025-07-21 15:24:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-07-19 09:36:35 +08:00
|
|
|
|
}
|
2025-07-28 18:26:02 +08:00
|
|
|
|
|
2025-08-04 15:35:59 +08:00
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
|
|
byte[] largeData = ImageToCArrayConverter.convertImageToCArray("E:\\workspace\\demo.png", 160, 80, 25600);
|
|
|
|
|
System.out.println("长度:" + largeData.length);
|
|
|
|
|
|
|
|
|
|
System.out.println("原始数据大小: " + largeData.length + " 字节");
|
|
|
|
|
|
|
|
|
|
int[] ints = convertHexToDecimal(largeData);
|
|
|
|
|
System.out.println("转换后的数据: " + Arrays.toString(ints));
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-28 18:26:02 +08:00
|
|
|
|
public void uploadDeviceLogo(AppDeviceLogoUploadDto bo) {
|
|
|
|
|
try {
|
|
|
|
|
Device device = deviceMapper.selectById(bo.getDeviceId());
|
2025-07-30 18:39:12 +08:00
|
|
|
|
if (device == null) {
|
2025-07-28 18:26:02 +08:00
|
|
|
|
throw new ServiceException("设备不存在");
|
|
|
|
|
}
|
|
|
|
|
MultipartFile file = bo.getFile();
|
|
|
|
|
|
2025-07-30 18:39:12 +08:00
|
|
|
|
byte[] largeData = ImageToCArrayConverter.convertImageToCArray(file.getInputStream(), 160, 80, 25600);
|
2025-08-07 15:41:57 +08:00
|
|
|
|
log.info("长度:" + largeData.length);
|
2025-07-28 18:26:02 +08:00
|
|
|
|
|
2025-08-07 15:41:57 +08:00
|
|
|
|
log.info("原始数据大小: {} 字节", largeData.length);
|
2025-07-28 18:26:02 +08:00
|
|
|
|
|
|
|
|
|
int[] ints = convertHexToDecimal(largeData);
|
2025-08-07 15:41:57 +08:00
|
|
|
|
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_BOOT_LOGO_KEY_PREFIX, Arrays.toString(ints), Duration.ofSeconds(30 * 60L));
|
2025-07-28 18:26:02 +08:00
|
|
|
|
|
2025-08-07 15:41:57 +08:00
|
|
|
|
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_BOOT_LOGO_KEY_PREFIX);
|
2025-07-28 18:26:02 +08:00
|
|
|
|
|
|
|
|
|
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
|
|
|
|
|
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, 0, 512);
|
2025-08-07 15:41:57 +08:00
|
|
|
|
log.info("第0块数据大小: {} 字节", specificChunk.length);
|
|
|
|
|
// log.info("第0块数据: {}", Arrays.toString(specificChunk));
|
2025-07-28 18:26:02 +08:00
|
|
|
|
|
|
|
|
|
ArrayList<Integer> intData = new ArrayList<>();
|
|
|
|
|
intData.add(3);
|
|
|
|
|
intData.add(1);
|
|
|
|
|
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){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-30 08:50:44 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 灯光模式
|
|
|
|
|
* 0(关灯),1(强光模式),2(弱光模式), 3(爆闪模式), 4(泛光模式)
|
|
|
|
|
*/
|
2025-07-30 17:13:57 +08:00
|
|
|
|
public void lightModeSettings(DeviceInstructDto params) {
|
2025-07-30 08:50:44 +08:00
|
|
|
|
try {
|
2025-07-30 17:13:57 +08:00
|
|
|
|
Long deviceId = params.getDeviceId();
|
2025-07-30 08:50:44 +08:00
|
|
|
|
Device device = deviceMapper.selectById(deviceId);
|
|
|
|
|
if(device == null){
|
|
|
|
|
throw new ServiceException("设备不存在");
|
|
|
|
|
}
|
2025-07-31 18:09:20 +08:00
|
|
|
|
Integer instructValue = Integer.parseInt(params.getInstructValue());
|
2025-07-30 08:50:44 +08:00
|
|
|
|
ArrayList<Integer> intData = new ArrayList<>();
|
|
|
|
|
intData.add(1);
|
|
|
|
|
intData.add(instructValue);
|
|
|
|
|
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){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//灯光亮度设置
|
2025-07-30 17:13:57 +08:00
|
|
|
|
public void lightBrightnessSettings(DeviceInstructDto params) {
|
2025-07-30 08:50:44 +08:00
|
|
|
|
try {
|
2025-07-30 17:13:57 +08:00
|
|
|
|
Long deviceId = params.getDeviceId();
|
2025-07-30 08:50:44 +08:00
|
|
|
|
Device device = deviceMapper.selectById(deviceId);
|
|
|
|
|
if(device == null){
|
|
|
|
|
throw new ServiceException("设备不存在");
|
|
|
|
|
}
|
2025-07-31 18:09:20 +08:00
|
|
|
|
String instructValue = params.getInstructValue();
|
2025-07-30 08:50:44 +08:00
|
|
|
|
ArrayList<Integer> intData = new ArrayList<>();
|
|
|
|
|
intData.add(5);
|
|
|
|
|
String[] values = instructValue.split("\\.");
|
|
|
|
|
String value1 = values[0];
|
|
|
|
|
String value2 = values[1];
|
|
|
|
|
if(StringUtils.isNoneBlank(value1)){
|
|
|
|
|
intData.add(Integer.parseInt(value1));
|
|
|
|
|
}
|
|
|
|
|
if(StringUtils.isNoneBlank(value2)){
|
|
|
|
|
intData.add(Integer.parseInt(value2));
|
|
|
|
|
}
|
|
|
|
|
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){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//激光模式设置
|
2025-07-30 17:13:57 +08:00
|
|
|
|
public void laserModeSettings(DeviceInstructDto params) {
|
2025-07-30 08:50:44 +08:00
|
|
|
|
try {
|
2025-07-30 17:13:57 +08:00
|
|
|
|
Long deviceId = params.getDeviceId();
|
2025-07-30 08:50:44 +08:00
|
|
|
|
Device device = deviceMapper.selectById(deviceId);
|
|
|
|
|
if(device == null){
|
|
|
|
|
throw new ServiceException("设备不存在");
|
|
|
|
|
}
|
2025-07-31 18:09:20 +08:00
|
|
|
|
Integer instructValue = Integer.parseInt(params.getInstructValue());
|
2025-07-30 08:50:44 +08:00
|
|
|
|
ArrayList<Integer> intData = new ArrayList<>();
|
|
|
|
|
intData.add(4);
|
|
|
|
|
intData.add(instructValue);
|
|
|
|
|
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){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-30 17:13:57 +08:00
|
|
|
|
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){
|
2025-07-30 08:50:44 +08:00
|
|
|
|
throw new ServiceException("设备不存在");
|
|
|
|
|
}
|
2025-07-30 17:13:57 +08:00
|
|
|
|
return RedisUtils.getCacheObject("device:location:" + devices.get(0).getDeviceImei());
|
2025-07-30 08:50:44 +08:00
|
|
|
|
}
|
2025-08-04 15:35:59 +08:00
|
|
|
|
|
|
|
|
|
public int sendAlarmMessage(AppDeviceSendMsgBo bo) {
|
|
|
|
|
try {
|
|
|
|
|
List<Long> deviceIds = bo.getDeviceIds();
|
|
|
|
|
if (deviceIds == null || deviceIds.isEmpty()) {
|
|
|
|
|
throw new ServiceException("请选择设备");
|
|
|
|
|
}
|
|
|
|
|
for (Long deviceId : deviceIds) {
|
|
|
|
|
Device device = deviceMapper.selectById(deviceId);
|
|
|
|
|
if (device == null) {
|
|
|
|
|
throw new ServiceException("设备不存在" + deviceId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
ArrayList<Integer> intData = new ArrayList<>();
|
|
|
|
|
intData.add(7);
|
|
|
|
|
intData.add(Integer.parseInt(bo.getInstructValue()));
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
|
|
UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
|
|
|
|
|
updateWrapper.eq("id", deviceId)
|
|
|
|
|
.eq("binding_user_id", AppLoginHelper.getUserId())
|
|
|
|
|
.set("send_msg", bo.getSendMsg());
|
|
|
|
|
deviceMapper.update(updateWrapper);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.info("设备发送信息失败:{}" ,deviceId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2025-08-12 17:03:11 +08:00
|
|
|
|
|
|
|
|
|
public Map<String, Object> getRealTimeStatus(AppRealTimeStatusDto statusDto) {
|
|
|
|
|
try {
|
|
|
|
|
String commandType = statusDto.getTypeName()+"_" + statusDto.getFunctionMode();
|
|
|
|
|
DeviceStatusRule rule = realTimeStatusEngine.getDeviceStatusRule(commandType);
|
|
|
|
|
if(rule == null){
|
|
|
|
|
throw new ServiceException("未匹配到处理命令");
|
|
|
|
|
}
|
|
|
|
|
return rule.getStatus(statusDto);
|
|
|
|
|
} catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Device getDeviceInfo(String deviceMac) {
|
|
|
|
|
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
queryWrapper.eq("device_mac", deviceMac);
|
|
|
|
|
List<Device> devices = deviceMapper.selectList(queryWrapper);
|
|
|
|
|
if(ObjectUtils.length(devices) ==0){
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return devices.get(0);
|
|
|
|
|
}
|
2025-07-19 09:36:35 +08:00
|
|
|
|
}
|