diff --git a/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/CmdController.java b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/CmdController.java index 9f692a0..ba43287 100644 --- a/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/CmdController.java +++ b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/CmdController.java @@ -54,7 +54,7 @@ public class CmdController extends BaseController { @PostMapping("send") @ApiOperation("下达命令") -// @Log(title = "下达命令", type = "新增") + @Log(title = "下达命令", type = "新增") public ResponseReult send(@RequestBody CmdModel model) throws Exception { cmdsService.send(model); return ResponseReult.success("OK"); diff --git a/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/MqttController.java b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/MqttController.java new file mode 100644 index 0000000..242bb1d --- /dev/null +++ b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/MqttController.java @@ -0,0 +1,34 @@ +package com.shxy.xymanager_admin.controller; + +import com.shxy.xymanager_common.annotation.Log; +import com.shxy.xymanager_common.base.BaseController; +import com.shxy.xymanager_common.base.ResponseReult; +import com.shxy.xymanager_common.model.mqtt.MessageSend; +import com.shxy.xymanager_framework.mqtt.MqttPublisherService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +@RestController +@Api(tags = {"mqtt相关接口"}) +@RequestMapping("mqtt") +@Slf4j +public class MqttController extends BaseController { + + @Resource + MqttPublisherService mqttPublisherService; + + @PostMapping("send") + @ApiOperation("下达命令") + @Log(title = "下达命令", type = "下达") + public ResponseReult send(@RequestBody MessageSend msg) throws Exception { + mqttPublisherService.publish(msg); + return ResponseReult.success("OK"); + } +} diff --git a/xymanager_framework/src/main/java/com/shxy/xymanager_framework/mqtt/MqttSubscriber.java b/xymanager_framework/src/main/java/com/shxy/xymanager_framework/mqtt/MqttSubscriber.java index a933a24..2ab40ab 100644 --- a/xymanager_framework/src/main/java/com/shxy/xymanager_framework/mqtt/MqttSubscriber.java +++ b/xymanager_framework/src/main/java/com/shxy/xymanager_framework/mqtt/MqttSubscriber.java @@ -40,7 +40,7 @@ public class MqttSubscriber implements IMqttMessageListener { MessageUpload msg = JSONUtil.json2Object(json, MessageUpload.class); messageHandler.process(msg); } catch (Exception ex) { - log.error("mqtt收到消息处理异常, 消息是:" + json, ex); + log.error("mqtt收到消息处理异常, " + ex.getMessage() + "消息体是:" + json, ex); } } } diff --git a/xymanager_framework/src/main/java/com/shxy/xymanager_framework/mqtt/PhotoHandler.java b/xymanager_framework/src/main/java/com/shxy/xymanager_framework/mqtt/PhotoHandler.java index 5121820..d6ce2d7 100644 --- a/xymanager_framework/src/main/java/com/shxy/xymanager_framework/mqtt/PhotoHandler.java +++ b/xymanager_framework/src/main/java/com/shxy/xymanager_framework/mqtt/PhotoHandler.java @@ -2,11 +2,13 @@ package com.shxy.xymanager_framework.mqtt; import com.shxy.xymanager_common.entity.TerminalPhoto; import com.shxy.xymanager_common.entity.Terminals; +import com.shxy.xymanager_common.exception.ApiException; import com.shxy.xymanager_common.model.mqtt.DeviceUploadImageDataEvent; import com.shxy.xymanager_common.util.DateUtil; import com.shxy.xymanager_dao.dao.TerminalPhotoDao; import com.shxy.xymanager_service.service.TerminalExtService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.util.Base64Utils; @@ -41,6 +43,10 @@ public class PhotoHandler { log.error("mqtt收到图片,但是该装置" + deviceId + "不存在"); return; } + if (StringUtils.isBlank(upload.getData())) { + log.error("mqtt收到图片,但是图片data内容是空的"); + throw new ApiException("图片data内容是空的"); + } int length = deviceId.length(); Date now = new Date(); String folder = DateUtil.format(now, "yyyy/MM/dd") + "/" + deviceId.substring(length - 2);