feat: 增加下达mqtt命令功能接口

dev
huangfeng 3 months ago
parent ff765f4bf4
commit db48dee2c3

@ -54,7 +54,7 @@ public class CmdController extends BaseController {
@PostMapping("send")
@ApiOperation("下达命令")
// @Log(title = "下达命令", type = "新增")
@Log(title = "下达命令", type = "新增")
public ResponseReult<String> send(@RequestBody CmdModel model) throws Exception {
cmdsService.send(model);
return ResponseReult.success("OK");

@ -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<String> send(@RequestBody MessageSend msg) throws Exception {
mqttPublisherService.publish(msg);
return ResponseReult.success("OK");
}
}

@ -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);
}
}
}

@ -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);

Loading…
Cancel
Save