BJQ6075 设备控制类
This commit is contained in:
@ -28,6 +28,7 @@ public class TestController extends BaseController {
|
||||
|
||||
private final DeviceBJQBizService appDeviceService;
|
||||
|
||||
|
||||
/**
|
||||
* 上传设备logo图片
|
||||
*/
|
||||
|
||||
@ -0,0 +1,120 @@
|
||||
package com.fuyuanshen.app.controller.device.bjq;
|
||||
|
||||
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
|
||||
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
|
||||
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessAnnotation;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessBatcAnnotation;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
|
||||
import com.fuyuanshen.web.service.device.DeviceBJQBizService;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* BJQ6075 设备控制类
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/app/bjq6075/device")
|
||||
public class AppDeviceBJQ6075Controller extends BaseController {
|
||||
|
||||
private final DeviceBJQBizService appDeviceService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public R<AppDeviceDetailVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
return R.ok(appDeviceService.getInfo(id));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 人员信息登记
|
||||
*/
|
||||
@PostMapping(value = "/registerPersonInfo")
|
||||
// @FunctionAccessAnnotation("registerPersonInfo")
|
||||
public R<Void> registerPersonInfo(@Validated(AddGroup.class) @RequestBody AppPersonnelInfoBo bo) {
|
||||
return toAjax(appDeviceService.registerPersonInfo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送信息
|
||||
*/
|
||||
@PostMapping(value = "/sendMessage")
|
||||
@FunctionAccessBatcAnnotation(value = "sendMessage", timeOut = 30, batchMaxTimeOut = 40)
|
||||
public R<Void> sendMessage(@RequestBody AppDeviceSendMsgBo bo) {
|
||||
return toAjax(appDeviceService.sendMessage(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送报警信息
|
||||
*/
|
||||
@PostMapping(value = "/sendAlarmMessage")
|
||||
@FunctionAccessBatcAnnotation(value = "sendAlarmMessage", timeOut = 5, batchMaxTimeOut = 10)
|
||||
public R<Void> sendAlarmMessage(@RequestBody AppDeviceSendMsgBo bo) {
|
||||
return toAjax(appDeviceService.sendAlarmMessage(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传设备logo图片
|
||||
*/
|
||||
@PostMapping("/uploadLogo")
|
||||
@FunctionAccessAnnotation("uploadLogo")
|
||||
public R<Void> upload(@Validated @ModelAttribute AppDeviceLogoUploadDto bo) {
|
||||
|
||||
MultipartFile file = bo.getFile();
|
||||
if (file.getSize() > 1024 * 1024 * 2) {
|
||||
return R.warn("图片不能大于2M");
|
||||
}
|
||||
appDeviceService.uploadDeviceLogo(bo);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 灯光模式
|
||||
* 0(关灯),1(强光模式),2(弱光模式), 3(爆闪模式), 4(泛光模式)
|
||||
*/
|
||||
// @FunctionAccessAnnotation("lightModeSettings")
|
||||
@PostMapping("/lightModeSettings")
|
||||
public R<Void> lightModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
// params 转 JSONObject
|
||||
appDeviceService.lightModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 灯光亮度设置
|
||||
*/
|
||||
// @FunctionAccessAnnotation("lightBrightnessSettings")
|
||||
@PostMapping("/lightBrightnessSettings")
|
||||
public R<Void> lightBrightnessSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService.lightBrightnessSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 激光模式设置
|
||||
*/
|
||||
@PostMapping("/laserModeSettings")
|
||||
// @FunctionAccessAnnotation("laserModeSettings")
|
||||
public R<Void> laserModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService.laserModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@ -11,6 +11,7 @@ public class AppDeviceLogoUploadDto {
|
||||
private Long deviceId;
|
||||
|
||||
private String deviceImei;
|
||||
|
||||
/**
|
||||
* 文件
|
||||
*/
|
||||
@ -25,4 +26,5 @@ public class AppDeviceLogoUploadDto {
|
||||
private List<Long> deviceIds;
|
||||
|
||||
private Integer chunkSize;
|
||||
|
||||
}
|
||||
|
||||
@ -21,6 +21,8 @@ public class MqttRuleEngine {
|
||||
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
||||
|
||||
private final LinkedHashMap<String, MqttMessageRule> rulesMap = new LinkedHashMap<>();
|
||||
|
||||
|
||||
public MqttRuleEngine(List<MqttMessageRule> rules) {
|
||||
// 按优先级排序
|
||||
rules.sort(Comparator.comparing(MqttMessageRule::getPriority));
|
||||
@ -28,14 +30,16 @@ public class MqttRuleEngine {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 执行匹配
|
||||
*
|
||||
* @param context 处理上下文
|
||||
* @return
|
||||
*/
|
||||
public boolean executeRule(MqttRuleContext context) {
|
||||
int commandType = context.getCommandType();
|
||||
MqttMessageRule mqttMessageRule = rulesMap.get("Light_"+commandType);
|
||||
MqttMessageRule mqttMessageRule = rulesMap.get("Light_" + commandType);
|
||||
if (mqttMessageRule != null) {
|
||||
threadPoolTaskExecutor.execute(() -> mqttMessageRule.execute(context));
|
||||
return true;
|
||||
@ -43,4 +47,5 @@ public class MqttRuleEngine {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,7 +3,6 @@ package com.fuyuanshen.global.mqtt.constants;
|
||||
|
||||
public interface MqttConstants {
|
||||
|
||||
|
||||
/**
|
||||
* 全局发布消息的key
|
||||
*/
|
||||
@ -13,4 +12,5 @@ public interface MqttConstants {
|
||||
* 全局订阅消息的key
|
||||
*/
|
||||
String GLOBAL_SUB_KEY = "A/";
|
||||
|
||||
}
|
||||
|
||||
@ -25,6 +25,8 @@ import java.util.Objects;
|
||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
|
||||
|
||||
/**
|
||||
* 6075
|
||||
*
|
||||
* @author: 默苍璃
|
||||
* @date: 2025-11-05 17:41
|
||||
*/
|
||||
|
||||
@ -28,6 +28,7 @@ public class DeviceBJQController extends BaseController {
|
||||
|
||||
private final DeviceBJQBizService appDeviceService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备详细信息
|
||||
*
|
||||
@ -39,6 +40,7 @@ public class DeviceBJQController extends BaseController {
|
||||
return R.ok(appDeviceService.getInfo(id));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 人员信息登记
|
||||
*/
|
||||
@ -74,7 +76,7 @@ public class DeviceBJQController extends BaseController {
|
||||
public R<Void> upload(@Validated @ModelAttribute AppDeviceLogoUploadDto bo) {
|
||||
|
||||
MultipartFile file = bo.getFile();
|
||||
if(file.getSize()>1024*1024*2){
|
||||
if (file.getSize() > 1024 * 1024 * 2) {
|
||||
return R.warn("图片不能大于2M");
|
||||
}
|
||||
appDeviceService.uploadDeviceLogo(bo);
|
||||
@ -90,7 +92,7 @@ public class DeviceBJQController extends BaseController {
|
||||
public R<Void> batchUploadLogo(@Validated @ModelAttribute AppDeviceLogoUploadDto bo) {
|
||||
|
||||
MultipartFile file = bo.getFile();
|
||||
if(file.getSize()>1024*1024*2){
|
||||
if (file.getSize() > 1024 * 1024 * 2) {
|
||||
return R.warn("图片不能大于2M");
|
||||
}
|
||||
appDeviceService.batchUploadLogo(bo);
|
||||
@ -112,7 +114,6 @@ public class DeviceBJQController extends BaseController {
|
||||
|
||||
/**
|
||||
* 灯光亮度设置
|
||||
*
|
||||
*/
|
||||
// @FunctionAccessAnnotation("lightBrightnessSettings")
|
||||
@PostMapping("/lightBrightnessSettings")
|
||||
@ -123,7 +124,6 @@ public class DeviceBJQController extends BaseController {
|
||||
|
||||
/**
|
||||
* 激光模式设置
|
||||
*
|
||||
*/
|
||||
@PostMapping("/laserModeSettings")
|
||||
// @FunctionAccessAnnotation("laserModeSettings")
|
||||
|
||||
@ -42,6 +42,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
return appDeviceService.queryWebDeviceList(bo, pageQuery);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 绑定设备
|
||||
*/
|
||||
@ -59,6 +60,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
return toAjax(appDeviceService.unBindDevice(id));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询设备类型列表
|
||||
*/
|
||||
@ -68,6 +70,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
return R.ok(typeList);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 重命名设备
|
||||
*
|
||||
@ -100,7 +103,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
*/
|
||||
@GetMapping("/instructionRecord")
|
||||
public TableDataInfo<InstructionRecordVo> getInstructionRecord(InstructionRecordDto dto, PageQuery pageQuery) {
|
||||
return appDeviceService.getInstructionRecord(dto,pageQuery);
|
||||
return appDeviceService.getInstructionRecord(dto, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,7 +114,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
pageQuery.setPageNum(1);
|
||||
pageQuery.setPageSize(2000);
|
||||
TableDataInfo<InstructionRecordVo> instructionRecord = appDeviceService.getInstructionRecord(dto, pageQuery);
|
||||
if(instructionRecord.getRows() == null){
|
||||
if (instructionRecord.getRows() == null) {
|
||||
return;
|
||||
}
|
||||
ExcelUtil.exportExcel(instructionRecord.getRows(), "设备操作日志", InstructionRecordVo.class, response);
|
||||
@ -123,7 +126,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
*/
|
||||
@GetMapping("/locationHistory")
|
||||
public TableDataInfo<LocationHistoryVo> getLocationHistory(InstructionRecordDto dto, PageQuery pageQuery) {
|
||||
return appDeviceService.getLocationHistory(dto,pageQuery);
|
||||
return appDeviceService.getLocationHistory(dto, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,7 +137,7 @@ public class DeviceControlCenterController extends BaseController {
|
||||
pageQuery.setPageNum(1);
|
||||
pageQuery.setPageSize(2000);
|
||||
TableDataInfo<LocationHistoryVo> result = appDeviceService.getLocationHistory(dto, pageQuery);
|
||||
if(result.getRows() == null){
|
||||
if (result.getRows() == null) {
|
||||
return;
|
||||
}
|
||||
ExcelUtil.exportExcel(result.getRows(), "历史轨迹记录", LocationHistoryVo.class, response);
|
||||
@ -147,4 +150,5 @@ public class DeviceControlCenterController extends BaseController {
|
||||
public R<List<LocationHistoryDetailVo>> getLocationHistoryDetail(Long id) {
|
||||
return R.ok(appDeviceService.getLocationHistoryDetail(id));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,140 @@
|
||||
package com.fuyuanshen.web.controller.device.bjq;
|
||||
|
||||
import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
|
||||
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
|
||||
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceDetailVo;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.validate.AddGroup;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessAnnotation;
|
||||
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessBatcAnnotation;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
|
||||
import com.fuyuanshen.web.service.device.DeviceBJQBizService;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* web后台:设备控制类
|
||||
* 6075
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/bjq6075/device")
|
||||
public class DeviceBJQ6075Controller extends BaseController {
|
||||
|
||||
private final DeviceBJQBizService appDeviceService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备详细信息
|
||||
*
|
||||
* @param id 主键
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public R<AppDeviceDetailVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long id) {
|
||||
return R.ok(appDeviceService.getInfo(id));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 人员信息登记
|
||||
*/
|
||||
@PostMapping(value = "/registerPersonInfo")
|
||||
// @FunctionAccessAnnotation("registerPersonInfo")
|
||||
public R<Void> registerPersonInfo(@Validated(AddGroup.class) @RequestBody AppPersonnelInfoBo bo) {
|
||||
return toAjax(appDeviceService.registerPersonInfo(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送信息
|
||||
*/
|
||||
@PostMapping(value = "/sendMessage")
|
||||
@FunctionAccessBatcAnnotation(value = "sendMessage", timeOut = 30, batchMaxTimeOut = 40)
|
||||
public R<Void> sendMessage(@RequestBody AppDeviceSendMsgBo bo) {
|
||||
return toAjax(appDeviceService.sendMessage(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送报警信息
|
||||
*/
|
||||
@PostMapping(value = "/sendAlarmMessage")
|
||||
@FunctionAccessBatcAnnotation(value = "sendAlarmMessage", timeOut = 5, batchMaxTimeOut = 10)
|
||||
public R<Void> sendAlarmMessage(@RequestBody AppDeviceSendMsgBo bo) {
|
||||
return toAjax(appDeviceService.sendAlarmMessage(bo));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传设备logo图片
|
||||
*/
|
||||
@PostMapping("/uploadLogo")
|
||||
@FunctionAccessAnnotation("uploadLogo")
|
||||
public R<Void> upload(@Validated @ModelAttribute AppDeviceLogoUploadDto bo) {
|
||||
|
||||
MultipartFile file = bo.getFile();
|
||||
if (file.getSize() > 1024 * 1024 * 2) {
|
||||
return R.warn("图片不能大于2M");
|
||||
}
|
||||
appDeviceService.uploadDeviceLogo(bo);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量上传设备logo图片
|
||||
*/
|
||||
@PostMapping("/batchUploadLogo")
|
||||
@FunctionAccessAnnotation("batchUploadLogo")
|
||||
public R<Void> batchUploadLogo(@Validated @ModelAttribute AppDeviceLogoUploadDto bo) {
|
||||
|
||||
MultipartFile file = bo.getFile();
|
||||
if (file.getSize() > 1024 * 1024 * 2) {
|
||||
return R.warn("图片不能大于2M");
|
||||
}
|
||||
appDeviceService.batchUploadLogo(bo);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 灯光模式
|
||||
* 0(关灯),1(强光模式),2(弱光模式), 3(爆闪模式), 4(泛光模式)
|
||||
*/
|
||||
// @FunctionAccessAnnotation("lightModeSettings")
|
||||
@PostMapping("/lightModeSettings")
|
||||
public R<Void> lightModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
// params 转 JSONObject
|
||||
appDeviceService.lightModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 灯光亮度设置
|
||||
*/
|
||||
// @FunctionAccessAnnotation("lightBrightnessSettings")
|
||||
@PostMapping("/lightBrightnessSettings")
|
||||
public R<Void> lightBrightnessSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService.lightBrightnessSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 激光模式设置
|
||||
*/
|
||||
@PostMapping("/laserModeSettings")
|
||||
// @FunctionAccessAnnotation("laserModeSettings")
|
||||
public R<Void> laserModeSettings(@RequestBody DeviceInstructDto params) {
|
||||
appDeviceService.laserModeSettings(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@ -69,8 +69,8 @@ public class DeviceBJQBizService {
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在" + deviceId);
|
||||
}
|
||||
if(getDeviceStatus(device.getDeviceImei())){
|
||||
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
try {
|
||||
ClassPathResource resource = new ClassPathResource("image/background.png");
|
||||
@ -78,26 +78,26 @@ public class DeviceBJQBizService {
|
||||
|
||||
byte[] largeData = ImageWithTextGenerate.generate160x80ImageWithText2(bo.getSendMsg(), inputStream, 25600);
|
||||
int[] ints = convertHexToDecimal(largeData);
|
||||
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + ":app_send_message_data" , Arrays.toString(ints), Duration.ofSeconds(5 * 60L));
|
||||
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + ":app_send_message_data", Arrays.toString(ints), Duration.ofSeconds(5 * 60L));
|
||||
|
||||
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + ":app_send_message_data");
|
||||
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + ":app_send_message_data");
|
||||
|
||||
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
|
||||
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, 0, 512);
|
||||
log.info("发送信息第0块数据大小: {} 字节",specificChunk.length);
|
||||
log.info("发送信息第0块数据大小: {} 字节", specificChunk.length);
|
||||
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
intData.add(6);
|
||||
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));
|
||||
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)
|
||||
@ -106,10 +106,10 @@ public class DeviceBJQBizService {
|
||||
|
||||
recordDeviceLog(deviceId, device.getDeviceName(), "发送信息", bo.getSendMsg(), AppLoginHelper.getUserId());
|
||||
} catch (Exception e) {
|
||||
log.info("发送信息设备发送信息失败:{}" ,deviceId);
|
||||
log.info("发送信息设备发送信息失败:{}", deviceId);
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
//发送消息
|
||||
// 发送消息
|
||||
messageSending(device.getDeviceImei());
|
||||
}
|
||||
|
||||
@ -119,11 +119,12 @@ public class DeviceBJQBizService {
|
||||
|
||||
/**
|
||||
* 记录设备操作日志
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param content 日志内容
|
||||
* @param operator 操作人
|
||||
*/
|
||||
private void recordDeviceLog(Long deviceId,String deviceName, String deviceAction, String content, Long operator) {
|
||||
private void recordDeviceLog(Long deviceId, String deviceName, String deviceAction, String content, Long operator) {
|
||||
try {
|
||||
// 创建设备日志实体
|
||||
com.fuyuanshen.equipment.domain.DeviceLog deviceLog = new com.fuyuanshen.equipment.domain.DeviceLog();
|
||||
@ -171,62 +172,62 @@ public class DeviceBJQBizService {
|
||||
AppPersonnelInfoVo personnelInfoVo = MapstructUtils.convert(appPersonnelInfo, AppPersonnelInfoVo.class);
|
||||
vo.setPersonnelInfo(personnelInfoVo);
|
||||
}
|
||||
//设备在线状态
|
||||
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei()+ DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
//设备在线状态
|
||||
if("1".equals(onlineStatus)){
|
||||
// 设备在线状态
|
||||
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
// 设备在线状态
|
||||
if ("1".equals(onlineStatus)) {
|
||||
vo.setOnlineStatus(1);
|
||||
}else if("2".equals(onlineStatus)){
|
||||
} else if ("2".equals(onlineStatus)) {
|
||||
vo.setOnlineStatus(2);
|
||||
}else{
|
||||
} else {
|
||||
vo.setOnlineStatus(0);
|
||||
}
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX);
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_STATUS_KEY_PREFIX);
|
||||
// 获取电量
|
||||
if(StringUtils.isNotBlank(deviceStatus)){
|
||||
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{
|
||||
} else {
|
||||
vo.setBatteryPercentage("0");
|
||||
}
|
||||
|
||||
String lightModeStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LIGHT_MODE_KEY_PREFIX);
|
||||
String lightModeStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LIGHT_MODE_KEY_PREFIX);
|
||||
// 获取电量
|
||||
if(StringUtils.isNotBlank(deviceStatus)){
|
||||
if (StringUtils.isNotBlank(deviceStatus)) {
|
||||
vo.setMainLightMode(lightModeStatus);
|
||||
}
|
||||
|
||||
String lightBrightnessStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(lightBrightnessStatus)){
|
||||
String lightBrightnessStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(lightBrightnessStatus)) {
|
||||
vo.setLightBrightness(lightBrightnessStatus);
|
||||
}
|
||||
|
||||
String laserLightMode = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LASER_MODE_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(laserLightMode)){
|
||||
String laserLightMode = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LASER_MODE_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(laserLightMode)) {
|
||||
vo.setLaserLightMode(laserLightMode);
|
||||
}
|
||||
|
||||
// 获取经度纬度
|
||||
String locationKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX;
|
||||
String locationKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_LOCATION_KEY_PREFIX;
|
||||
String locationInfo = RedisUtils.getCacheObject(locationKey);
|
||||
if(StringUtils.isNotBlank(locationInfo)){
|
||||
if (StringUtils.isNotBlank(locationInfo)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(locationInfo);
|
||||
vo.setLongitude(jsonObject.get("longitude").toString());
|
||||
vo.setLatitude(jsonObject.get("latitude").toString());
|
||||
vo.setAddress((String)jsonObject.get("address"));
|
||||
vo.setAddress((String) jsonObject.get("address"));
|
||||
}
|
||||
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ device.getDeviceImei()+ DEVICE_ALARM_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(alarmStatus)){
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(alarmStatus)) {
|
||||
vo.setAlarmStatus(alarmStatus);
|
||||
}
|
||||
|
||||
String lightBrightness = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ device.getDeviceImei()+ DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(lightBrightness)){
|
||||
String lightBrightness = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(lightBrightness)) {
|
||||
vo.setLightBrightness(lightBrightness);
|
||||
}
|
||||
|
||||
@ -234,15 +235,14 @@ public class DeviceBJQBizService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean registerPersonInfo(AppPersonnelInfoBo bo) {
|
||||
Long deviceId = bo.getDeviceId();
|
||||
Device deviceObj = deviceMapper.selectById(deviceId);
|
||||
if (deviceObj == null) {
|
||||
throw new RuntimeException("请先将设备入库!!!");
|
||||
}
|
||||
if(getDeviceStatus(deviceObj.getDeviceImei())){
|
||||
throw new ServiceException(deviceObj.getDeviceName()+",设备已断开连接");
|
||||
if (getDeviceStatus(deviceObj.getDeviceImei())) {
|
||||
throw new ServiceException(deviceObj.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
QueryWrapper<AppPersonnelInfo> qw = new QueryWrapper<AppPersonnelInfo>()
|
||||
.eq("device_id", deviceId);
|
||||
@ -266,7 +266,7 @@ public class DeviceBJQBizService {
|
||||
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);
|
||||
String logContent = "单位:"+bo.getUnitName()+",职位:"+bo.getPosition()+",姓名:"+bo.getName()+",ID:"+bo.getCode();
|
||||
String logContent = "单位:" + bo.getUnitName() + ",职位:" + bo.getPosition() + ",姓名:" + bo.getName() + ",ID:" + bo.getCode();
|
||||
recordDeviceLog(deviceId, deviceObj.getDeviceName(), "人员信息登记", logContent, AppLoginHelper.getUserId());
|
||||
if (ObjectUtils.length(appPersonnelInfoVos) == 0) {
|
||||
AppPersonnelInfo appPersonnelInfo = MapstructUtils.convert(bo, AppPersonnelInfo.class);
|
||||
@ -297,6 +297,7 @@ public class DeviceBJQBizService {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void uploadDeviceLogo2(AppDeviceLogoUploadDto bo) {
|
||||
try {
|
||||
Device device = deviceMapper.selectById(bo.getDeviceId());
|
||||
@ -322,25 +323,26 @@ public class DeviceBJQBizService {
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
// map.put("instruct", combinedData);
|
||||
String[] specificChunk = ImageToCArrayConverter.getChunk2(hexArray, 0, bo.getChunkSize());
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(), 1 , Arrays.toString(specificChunk));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY+device.getDeviceImei(),Arrays.toString(specificChunk));
|
||||
mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), 1, Arrays.toString(specificChunk));
|
||||
log.info("发送点阵数据到设备消息=>topic:{},payload:{}", MqttConstants.GLOBAL_PUB_KEY + device.getDeviceImei(), Arrays.toString(specificChunk));
|
||||
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "上传开机画面", "上传开机画面", AppLoginHelper.getUserId());
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
public void uploadDeviceLogo(AppDeviceLogoUploadDto bo) {
|
||||
try {
|
||||
Device device = deviceMapper.selectById(bo.getDeviceId());
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if(getDeviceStatus(device.getDeviceImei())){
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
// throw new ServiceException(device.getDeviceName()+",设备已断开连接");
|
||||
log.info(device.getDeviceName()+",设备已断开连接");
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "上传开机画面", device.getDeviceName()+",设备已断开连接", AppLoginHelper.getUserId());
|
||||
log.info(device.getDeviceName() + ",设备已断开连接");
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "上传开机画面", device.getDeviceName() + ",设备已断开连接", AppLoginHelper.getUserId());
|
||||
return;
|
||||
}
|
||||
MultipartFile file = bo.getFile();
|
||||
@ -351,9 +353,9 @@ public class DeviceBJQBizService {
|
||||
log.info("原始数据大小: {} 字节", largeData.length);
|
||||
|
||||
int[] ints = convertHexToDecimal(largeData);
|
||||
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() +DEVICE_BOOT_LOGO_KEY_PREFIX, Arrays.toString(ints), Duration.ofSeconds(5 * 60L));
|
||||
RedisUtils.setCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_BOOT_LOGO_KEY_PREFIX, Arrays.toString(ints), Duration.ofSeconds(5 * 60L));
|
||||
|
||||
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_BOOT_LOGO_KEY_PREFIX);
|
||||
String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + device.getDeviceImei() + DEVICE_BOOT_LOGO_KEY_PREFIX);
|
||||
|
||||
byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
|
||||
byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, 0, 512);
|
||||
@ -363,18 +365,18 @@ public class DeviceBJQBizService {
|
||||
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));
|
||||
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));
|
||||
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "上传开机画面", "上传开机画面", AppLoginHelper.getUserId());
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
@ -389,11 +391,11 @@ public class DeviceBJQBizService {
|
||||
try {
|
||||
Long deviceId = params.getDeviceId();
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if(device == null){
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if(getDeviceStatus(device.getDeviceImei())){
|
||||
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
Integer instructValue = Integer.parseInt(params.getInstructValue());
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
@ -404,26 +406,26 @@ public class DeviceBJQBizService {
|
||||
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));
|
||||
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));
|
||||
LightModeEnum modeEnum = LightModeEnum.getByCode(instructValue);
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "灯光模式", modeEnum!=null?modeEnum.getName():null, AppLoginHelper.getUserId());
|
||||
} catch (Exception e){
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "灯光模式", modeEnum != null ? modeEnum.getName() : null, AppLoginHelper.getUserId());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
//灯光亮度设置
|
||||
// 灯光亮度设置
|
||||
public void lightBrightnessSettings(DeviceInstructDto params) {
|
||||
try {
|
||||
Long deviceId = params.getDeviceId();
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if(device == null){
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if(getDeviceStatus(device.getDeviceImei())){
|
||||
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
String instructValue = params.getInstructValue();
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
@ -431,10 +433,10 @@ public class DeviceBJQBizService {
|
||||
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);
|
||||
@ -442,25 +444,25 @@ public class DeviceBJQBizService {
|
||||
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));
|
||||
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){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
}
|
||||
|
||||
//激光模式设置
|
||||
// 激光模式设置
|
||||
public void laserModeSettings(DeviceInstructDto params) {
|
||||
try {
|
||||
Long deviceId = params.getDeviceId();
|
||||
Device device = deviceMapper.selectById(deviceId);
|
||||
if(device == null){
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
if(getDeviceStatus(device.getDeviceImei())){
|
||||
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
Integer instructValue = Integer.parseInt(params.getInstructValue());
|
||||
ArrayList<Integer> intData = new ArrayList<>();
|
||||
@ -471,15 +473,15 @@ public class DeviceBJQBizService {
|
||||
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));
|
||||
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));
|
||||
// 1代表开启激光灯,此时主灯关闭,主灯控件为关机状态,为0代表关闭激光灯
|
||||
if("1".equals(params.getInstructValue())){
|
||||
if ("1".equals(params.getInstructValue())) {
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "激光模式设置", "开启激光灯", AppLoginHelper.getUserId());
|
||||
}else{
|
||||
} else {
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "激光模式设置", "关闭激光灯", AppLoginHelper.getUserId());
|
||||
}
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送指令失败");
|
||||
}
|
||||
@ -489,7 +491,7 @@ public class DeviceBJQBizService {
|
||||
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("device_imei", params.getDeviceImei());
|
||||
List<Device> devices = deviceMapper.selectList(queryWrapper);
|
||||
if(ObjectUtils.length( devices) ==0){
|
||||
if (ObjectUtils.length(devices) == 0) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
return RedisUtils.getCacheObject("device:location:" + devices.get(0).getDeviceImei());
|
||||
@ -507,8 +509,8 @@ public class DeviceBJQBizService {
|
||||
if (device == null) {
|
||||
throw new ServiceException("设备不存在" + deviceId);
|
||||
}
|
||||
if(getDeviceStatus(device.getDeviceImei())){
|
||||
throw new ServiceException(device.getDeviceName()+",设备已断开连接");
|
||||
if (getDeviceStatus(device.getDeviceImei())) {
|
||||
throw new ServiceException(device.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
try {
|
||||
|
||||
@ -521,39 +523,39 @@ public class DeviceBJQBizService {
|
||||
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));
|
||||
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)
|
||||
.set("send_msg", bo.getSendMsg());
|
||||
deviceMapper.update(updateWrapper);
|
||||
if("0".equals(bo.getInstructValue())){
|
||||
if ("0".equals(bo.getInstructValue())) {
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "解除告警信息", "关闭设备", AppLoginHelper.getUserId());
|
||||
}else{
|
||||
} else {
|
||||
recordDeviceLog(device.getId(), device.getDeviceName(), "发送告警信息", bo.getSendMsg(), AppLoginHelper.getUserId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("设备发送告警信息信息失败:{}" ,deviceId);
|
||||
log.info("设备发送告警信息信息失败:{}", deviceId);
|
||||
throw new ServiceException("设备发送告警信息信息失败");
|
||||
}
|
||||
messageSending(device.getDeviceImei());
|
||||
}
|
||||
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("发送告警信息指令失败");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
private void messageSending(String deviceImei){
|
||||
String sendMessageIng = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + deviceImei + ":messageSending";
|
||||
private void messageSending(String deviceImei) {
|
||||
String sendMessageIng = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + ":messageSending";
|
||||
RedisUtils.setCacheObject(sendMessageIng, "1", Duration.ofDays(1));
|
||||
}
|
||||
|
||||
private boolean getDeviceStatus(String deviceImei) {
|
||||
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX ;
|
||||
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX;
|
||||
return RedisUtils.getCacheObject(deviceOnlineStatusRedisKey) == null;
|
||||
}
|
||||
|
||||
|
||||
@ -59,8 +59,8 @@ public class DeviceBizService {
|
||||
private final RealTimeStatusEngine realTimeStatusEngine;
|
||||
private final DeviceLogMapper deviceLogMapper;
|
||||
private final AppDeviceShareMapper appDeviceShareMapper;
|
||||
private final AppUserMapper appUserMapper;;
|
||||
|
||||
private final AppUserMapper appUserMapper;
|
||||
;
|
||||
|
||||
|
||||
public List<APPDeviceTypeVo> getTypeList() {
|
||||
@ -84,37 +84,37 @@ public class DeviceBizService {
|
||||
}
|
||||
Page<AppDeviceVo> result = deviceMapper.queryAppBindDeviceList(pageQuery.build(), bo);
|
||||
List<AppDeviceVo> records = result.getRecords();
|
||||
if(records != null && !records.isEmpty()){
|
||||
if (records != null && !records.isEmpty()) {
|
||||
records.forEach(item -> {
|
||||
if(item.getCommunicationMode()!=null && item.getCommunicationMode() == 0){
|
||||
if (item.getCommunicationMode() != null && item.getCommunicationMode() == 0) {
|
||||
|
||||
//设备在线状态
|
||||
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
if("1".equals(onlineStatus)){
|
||||
// 设备在线状态
|
||||
String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
if ("1".equals(onlineStatus)) {
|
||||
item.setOnlineStatus(1);
|
||||
}else if("2".equals(onlineStatus)){
|
||||
} else if ("2".equals(onlineStatus)) {
|
||||
item.setOnlineStatus(2);
|
||||
}else{
|
||||
} else {
|
||||
item.setOnlineStatus(0);
|
||||
}
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX+ item.getDeviceImei() + DEVICE_STATUS_KEY_PREFIX);
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_STATUS_KEY_PREFIX);
|
||||
// 获取电量
|
||||
if(StringUtils.isNotBlank(deviceStatus)){
|
||||
if (StringUtils.isNotBlank(deviceStatus)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(deviceStatus);
|
||||
item.setBattery(jsonObject.getString("batteryPercentage"));
|
||||
}else{
|
||||
} else {
|
||||
item.setBattery("0");
|
||||
}
|
||||
|
||||
String location = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ item.getDeviceImei()+ DEVICE_LOCATION_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(location)){
|
||||
String location = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_LOCATION_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(location)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(location);
|
||||
item.setLatitude(jsonObject.getString("latitude"));
|
||||
item.setLongitude(jsonObject.getString("longitude"));
|
||||
}
|
||||
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ item.getDeviceImei()+ DEVICE_ALARM_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(alarmStatus)){
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(alarmStatus)) {
|
||||
item.setAlarmStatus(alarmStatus);
|
||||
}
|
||||
}
|
||||
@ -126,11 +126,11 @@ public class DeviceBizService {
|
||||
public TableDataInfo<WebDeviceVo> queryWebDeviceList(DeviceQueryCriteria bo, PageQuery pageQuery) {
|
||||
Page<WebDeviceVo> result = deviceMapper.queryWebDeviceList(pageQuery.build(), bo);
|
||||
List<WebDeviceVo> records = result.getRecords();
|
||||
if(records != null && !records.isEmpty()){
|
||||
if (records != null && !records.isEmpty()) {
|
||||
records.forEach(item -> {
|
||||
if(item.getCommunicationMode()!=null && Ints.asList(0, 2).contains(item.getCommunicationMode())){
|
||||
if (item.getCommunicationMode() != null && Ints.asList(0, 2).contains(item.getCommunicationMode())) {
|
||||
|
||||
//设备在线状态
|
||||
// 设备在线状态
|
||||
// String onlineStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ item.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX);
|
||||
// if("1".equals(onlineStatus)){
|
||||
// item.setOnlineStatus(1);
|
||||
@ -139,24 +139,24 @@ public class DeviceBizService {
|
||||
// }else{
|
||||
// item.setOnlineStatus(0);
|
||||
// }
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX+ item.getDeviceImei() + DEVICE_STATUS_KEY_PREFIX);
|
||||
String deviceStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_STATUS_KEY_PREFIX);
|
||||
// 获取电量
|
||||
if(StringUtils.isNotBlank(deviceStatus)){
|
||||
if (StringUtils.isNotBlank(deviceStatus)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(deviceStatus);
|
||||
item.setBattery(jsonObject.getString("batteryPercentage"));
|
||||
}else{
|
||||
} else {
|
||||
item.setBattery("0");
|
||||
}
|
||||
|
||||
String location = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ item.getDeviceImei()+ DEVICE_LOCATION_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(location)){
|
||||
String location = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_LOCATION_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(location)) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(location);
|
||||
item.setLatitude(jsonObject.getString("latitude"));
|
||||
item.setLongitude(jsonObject.getString("longitude"));
|
||||
}
|
||||
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY +DEVICE_KEY_PREFIX+ item.getDeviceImei()+ DEVICE_ALARM_KEY_PREFIX);
|
||||
if(StringUtils.isNotBlank(alarmStatus)){
|
||||
String alarmStatus = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + item.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX);
|
||||
if (StringUtils.isNotBlank(alarmStatus)) {
|
||||
item.setAlarmStatus(alarmStatus);
|
||||
}
|
||||
}
|
||||
@ -165,6 +165,7 @@ public class DeviceBizService {
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
|
||||
public int bindDevice(AppDeviceBo bo) {
|
||||
Integer mode = bo.getCommunicationMode();
|
||||
Long userId = AppLoginHelper.getUserId();
|
||||
@ -274,7 +275,7 @@ public class DeviceBizService {
|
||||
if (count == 0) {
|
||||
throw new RuntimeException("请先绑定设备!!!");
|
||||
}
|
||||
if(count<2){
|
||||
if (count < 2) {
|
||||
UpdateWrapper<Device> deviceUpdateWrapper = new UpdateWrapper<>();
|
||||
deviceUpdateWrapper.eq("id", device.getId())
|
||||
.set("binding_user_id", null)
|
||||
@ -291,7 +292,7 @@ public class DeviceBizService {
|
||||
appDeviceBindRecordMapper.deleteById(appDeviceBindRecord.getId()));
|
||||
}
|
||||
AppUserVo appUserVo = appUserMapper.selectVoById(userId);
|
||||
if(appUserVo != null){
|
||||
if (appUserVo != null) {
|
||||
QueryWrapper<AppDeviceShare> appDeviceShareQueryWrapper = new QueryWrapper<>();
|
||||
appDeviceShareQueryWrapper.eq("device_id", device.getId());
|
||||
appDeviceShareQueryWrapper.eq("phonenumber", appUserVo.getPhonenumber());
|
||||
@ -301,7 +302,7 @@ public class DeviceBizService {
|
||||
appDeviceShareMapper.deleteById(appDeviceShare.getId()));
|
||||
}
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
QueryWrapper<AppDeviceBindRecord> bindRecordQueryWrapper = new QueryWrapper<>();
|
||||
bindRecordQueryWrapper.eq("device_id", device.getId());
|
||||
Long count = appDeviceBindRecordMapper.selectCount(bindRecordQueryWrapper);
|
||||
@ -341,7 +342,7 @@ public class DeviceBizService {
|
||||
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("device_imei", params.getDeviceImei());
|
||||
List<Device> devices = deviceMapper.selectList(queryWrapper);
|
||||
if(ObjectUtils.length( devices) ==0){
|
||||
if (ObjectUtils.length(devices) == 0) {
|
||||
throw new ServiceException("设备不存在");
|
||||
}
|
||||
return RedisUtils.getCacheObject("device:location:" + devices.get(0).getDeviceImei());
|
||||
@ -351,11 +352,11 @@ public class DeviceBizService {
|
||||
try {
|
||||
// String commandType = statusDto.getTypeName()+"_" + statusDto.getFunctionMode();"FunctionAccessBatchStatusRule"
|
||||
DeviceStatusRule rule = realTimeStatusEngine.getDeviceStatusRule(statusDto.getTypeName());
|
||||
if(rule == null){
|
||||
if (rule == null) {
|
||||
throw new ServiceException("未匹配到处理命令");
|
||||
}
|
||||
return rule.getStatus(statusDto);
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
@ -393,7 +394,7 @@ public class DeviceBizService {
|
||||
long endTime = today.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||
|
||||
String deviceImei = device.getDeviceImei();
|
||||
String a = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ deviceImei + DEVICE_LOCATION_KEY_PREFIX + ":history";
|
||||
String a = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + deviceImei + DEVICE_LOCATION_KEY_PREFIX + ":history";
|
||||
Collection<String> list = RedisUtils.zRangeByScoreDesc(a, startTime, endTime);
|
||||
if (CollectionUtil.isEmpty(list)) {
|
||||
return null;
|
||||
@ -401,12 +402,12 @@ public class DeviceBizService {
|
||||
|
||||
|
||||
Map<String, List<JSONObject>> map = new LinkedHashMap<>();
|
||||
for (String obj : list){
|
||||
for (String obj : list) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(obj);
|
||||
Long timestamp = jsonObject.getLong("timestamp");
|
||||
LocalDate date = LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault()).toLocalDate();
|
||||
String address = jsonObject.getString("address");
|
||||
if(StringUtils.isBlank( address) || "[]".equals(address)){
|
||||
if (StringUtils.isBlank(address) || "[]".equals(address)) {
|
||||
continue;
|
||||
}
|
||||
if (map.containsKey(date.toString())) {
|
||||
@ -424,7 +425,7 @@ public class DeviceBizService {
|
||||
detailVo.setDate(entry.getKey());
|
||||
detailVo.setDeviceName(device.getDeviceName());
|
||||
detailVo.setStartLocation(entry.getValue().get(0).getString("address"));
|
||||
detailVo.setEndLocation(entry.getValue().get(entry.getValue().size()-1).getString("address"));
|
||||
detailVo.setEndLocation(entry.getValue().get(entry.getValue().size() - 1).getString("address"));
|
||||
String jsonString = JSONArray.toJSONString(entry.getValue());
|
||||
List<Object> strings = JSONArray.parseArray(jsonString);
|
||||
detailVo.setDetailList(strings);
|
||||
|
||||
@ -58,7 +58,6 @@ public class WebDeviceVo implements Serializable {
|
||||
*/
|
||||
private Integer deviceStatus;
|
||||
|
||||
|
||||
/**绑定状态
|
||||
* 0 未绑定
|
||||
* 1 已绑定
|
||||
|
||||
Reference in New Issue
Block a user