diff --git a/data-collect-service/src/main/java/com/ho/datacollect/util/MqttConfigUtil.java b/data-collect-service/src/main/java/com/ho/datacollect/util/MqttConfigUtil.java index cd3110b..2aae29d 100644 --- a/data-collect-service/src/main/java/com/ho/datacollect/util/MqttConfigUtil.java +++ b/data-collect-service/src/main/java/com/ho/datacollect/util/MqttConfigUtil.java @@ -130,7 +130,8 @@ public class MqttConfigUtil { "+/device/e9eee97d793756fa", "+/device/8c062827b5c1548b", "+/device/d143856d757625e1", - "+/device/3522ab4e7faf28b8" + "+/device/3522ab4e7faf28b8", + "1/device/+" }; /** diff --git a/file-center/src/main/java/com/ho/filecenter/controller/FileController.java b/file-center/src/main/java/com/ho/filecenter/controller/FileController.java index a492489..a4c739b 100644 --- a/file-center/src/main/java/com/ho/filecenter/controller/FileController.java +++ b/file-center/src/main/java/com/ho/filecenter/controller/FileController.java @@ -18,6 +18,7 @@ import com.ho.common.tools.util.PageResult; import com.ho.filecenter.entity.MediaFile; import com.ho.filecenter.service.AnotherFileService; import com.ho.filecenter.service.FileService; +import com.ho.filecenter.service.MqttTopicService; import com.ho.filecenter.util.MqttConfigUtil; import com.ho.filecenter.vo.mqtt.*; import com.ho.filecenter.vo.resp.*; @@ -58,6 +59,9 @@ public class FileController { @Autowired AnotherFileService anotherFileService; + + @Autowired + MqttTopicService mqttTopicService; @PostMapping("filePage") @ApiOperation(value = "分页查询文件") public DataResult> filePage(@RequestBody FilePageVO vo, HttpServletRequest request) { @@ -158,7 +162,7 @@ public class FileController { return DataResult.success(fileAttributeResp); } String serialNo = vo.getSerialNo(); - List snList = MqttConfigUtil.getSnList(); + List snList = mqttTopicService.getSnList(); if(snList.stream().anyMatch(s -> s.contains(serialNo))){ fileAttributeResp = fileService.getFileAttribute(vo); }else{ @@ -180,7 +184,7 @@ public class FileController { return DataResult.success(fileDeleteResp); } String serialNo = fileDeleteReqVO.getSerialNo(); - List snList = MqttConfigUtil.getSnList(); + List snList = mqttTopicService.getSnList(); if(snList.stream().anyMatch(s -> s.contains(serialNo))){ fileDeleteResp = fileService.deleteDeviceFiles(fileDeleteReqVO); }else{ @@ -210,7 +214,7 @@ public class FileController { resp.setMsg(CommonConstant.Heartbeat.MSG + serialNo + CommonConstant.Heartbeat.SUCCESS); resp.setHeartbeatStatus(CommonConstant.ONE); log.info("文件上传(向边端上传)开始上传"); - List snList = MqttConfigUtil.getSnList(); + List snList = mqttTopicService.getSnList(); if(snList.stream().anyMatch(s -> s.contains(serialNo))){ fileService.fileUploadForDevice(file, stationId, serialNo, filePath); }else{ @@ -240,7 +244,7 @@ public class FileController { log.info("文件下载(从边端下载到云端)开始下载"); fileService.downloadFromDevice(fileForDeviceReqVO); String serialNo = fileForDeviceReqVO.getSerialNo(); - List snList = MqttConfigUtil.getSnList(); + List snList = mqttTopicService.getSnList(); if(snList.stream().anyMatch(s -> s.contains(serialNo))){ fileService.downloadFromDevice(fileForDeviceReqVO); }else{ diff --git a/file-center/src/main/java/com/ho/filecenter/controller/OrderSendController.java b/file-center/src/main/java/com/ho/filecenter/controller/OrderSendController.java index a30c56b..dc6a250 100644 --- a/file-center/src/main/java/com/ho/filecenter/controller/OrderSendController.java +++ b/file-center/src/main/java/com/ho/filecenter/controller/OrderSendController.java @@ -19,6 +19,7 @@ import com.ho.common.tools.util.PageResult; import com.ho.filecenter.feignclient.BusinessFeignClient; import com.ho.filecenter.feignclient.UserFeignClient; import com.ho.filecenter.service.AnotherOrderSendService; +import com.ho.filecenter.service.MqttTopicService; import com.ho.filecenter.service.OrderSendService; import com.ho.filecenter.util.MqttConfigUtil; import com.ho.filecenter.vo.mqtt.*; @@ -65,6 +66,9 @@ public class OrderSendController { @Autowired AnotherOrderSendService anotherOrderSendService; + @Autowired + MqttTopicService mqttTopicService; + public static final Long TIME_LIMIT = 90L; @PostMapping("orderIssued") @@ -163,8 +167,8 @@ public class OrderSendController { return DataResult.success(heartbeatResp); } log.info("指令下发正常开始下发"); - List snList = MqttConfigUtil.getSnList(); - if(snList.contains(sn)){ + List snList = mqttTopicService.getSnList(); + if(snList.stream().anyMatch(s -> s.contains(sn))){ orderSendService.orderIssued(vo); }else{ anotherOrderSendService.orderIssued(vo); @@ -333,9 +337,9 @@ public class OrderSendController { @TokenIgnore public DataResult sendPlanPowerOrder(@RequestBody OrderPlanPowerReq vo) { String sn = vo.getSn(); - List snList = MqttConfigUtil.getSnList(); + List snList = mqttTopicService.getSnList(); HeartbeatResp heartbeatResp = null; - if(snList.contains(sn)){ + if(snList.stream().anyMatch(s -> s.contains(sn))){ heartbeatResp = orderSendService.sendPlanPowerOrder(vo); }else{ heartbeatResp = anotherOrderSendService.sendPlanPowerOrder(vo); diff --git a/file-center/src/main/java/com/ho/filecenter/mapper/MqttTopicMapper.java b/file-center/src/main/java/com/ho/filecenter/mapper/MqttTopicMapper.java new file mode 100644 index 0000000..62f8c81 --- /dev/null +++ b/file-center/src/main/java/com/ho/filecenter/mapper/MqttTopicMapper.java @@ -0,0 +1,10 @@ +package com.ho.filecenter.mapper; + +import java.util.List; + +/** + * @author kerwin + */ +public interface MqttTopicMapper { + List getSnList(); +} diff --git a/file-center/src/main/java/com/ho/filecenter/service/MqttTopicService.java b/file-center/src/main/java/com/ho/filecenter/service/MqttTopicService.java new file mode 100644 index 0000000..e523083 --- /dev/null +++ b/file-center/src/main/java/com/ho/filecenter/service/MqttTopicService.java @@ -0,0 +1,11 @@ +package com.ho.filecenter.service; + +import java.util.List; + +/** + * @author kerwin + */ +public interface MqttTopicService { + + List getSnList(); +} diff --git a/file-center/src/main/java/com/ho/filecenter/service/impl/MqttTopicServiceImpl.java b/file-center/src/main/java/com/ho/filecenter/service/impl/MqttTopicServiceImpl.java new file mode 100644 index 0000000..e821960 --- /dev/null +++ b/file-center/src/main/java/com/ho/filecenter/service/impl/MqttTopicServiceImpl.java @@ -0,0 +1,24 @@ +package com.ho.filecenter.service.impl; + +import com.ho.filecenter.mapper.MqttTopicMapper; +import com.ho.filecenter.service.MqttTopicService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author kerwin + */ +@Service +@Slf4j +public class MqttTopicServiceImpl implements MqttTopicService { + + @Autowired + MqttTopicMapper mqttTopicMapper; + @Override + public List getSnList() { + return mqttTopicMapper.getSnList(); + } +} diff --git a/file-center/src/main/java/com/ho/filecenter/util/MqttConfigUtil.java b/file-center/src/main/java/com/ho/filecenter/util/MqttConfigUtil.java index 75cac63..9c2fc03 100644 --- a/file-center/src/main/java/com/ho/filecenter/util/MqttConfigUtil.java +++ b/file-center/src/main/java/com/ho/filecenter/util/MqttConfigUtil.java @@ -135,7 +135,8 @@ public class MqttConfigUtil { "+/device/e9eee97d793756fa", "+/device/8c062827b5c1548b", "+/device/d143856d757625e1", - "+/device/3522ab4e7faf28b8" + "+/device/3522ab4e7faf28b8", + "1/device/+" }; /** @@ -181,13 +182,4 @@ public class MqttConfigUtil { } return str; } - - /** - * 获取SN配置合集 - * @return - */ - public static List getSnList(){ - List strings = Arrays.asList(commonTopic); - return strings; - } } diff --git a/file-center/src/main/resources/mapper/MqttTopicMapper.xml b/file-center/src/main/resources/mapper/MqttTopicMapper.xml new file mode 100644 index 0000000..ace1f02 --- /dev/null +++ b/file-center/src/main/resources/mapper/MqttTopicMapper.xml @@ -0,0 +1,10 @@ + + + + + +