文件服务双发代码提交
This commit is contained in:
@ -0,0 +1,75 @@
|
||||
package com.ho.filecenter.config;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.ho.filecenter.util.AnotherMqttConfigUtil;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.IMqttToken;
|
||||
import org.eclipse.paho.client.mqttv3.MqttClient;
|
||||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author wp
|
||||
* @desc: Mqtt配置类
|
||||
* @date 2025/06/11
|
||||
*/
|
||||
@Configuration
|
||||
@Data
|
||||
@ConfigurationProperties("mqtt1")
|
||||
@Slf4j
|
||||
public class AnotherMqttConfig {
|
||||
|
||||
//服务器url
|
||||
@Value("${mqtt1.url}")
|
||||
String url;
|
||||
//超时时间
|
||||
@Value("${mqtt1.timeout}")
|
||||
Integer timeout;
|
||||
//会话保持时间
|
||||
@Value("${mqtt1.keepAlive}")
|
||||
Integer keepAlive;
|
||||
|
||||
@Value("${mqtt1.userName}")
|
||||
String userName;
|
||||
|
||||
@Value("${mqtt1.passWord}")
|
||||
String passWord;
|
||||
|
||||
@Autowired
|
||||
AnotherFileEdgeResponseConsumer fileEdgeResponseConsumer;
|
||||
|
||||
//文件响应
|
||||
@Bean(name = "AnotherFileEdgeResponse")
|
||||
public MqttClient initFileResponseClient() {
|
||||
String clientId = IdUtil.simpleUUID();
|
||||
log.info("clientId:" + clientId);
|
||||
MqttClient client =null;
|
||||
try {
|
||||
client = new MqttClient(url, clientId,null);
|
||||
MqttConnectOptions options = new MqttConnectOptions();
|
||||
options.setUserName(userName);
|
||||
options.setPassword(passWord.toCharArray());
|
||||
options.setCleanSession(true);
|
||||
options.setConnectionTimeout(timeout);
|
||||
options.setKeepAliveInterval(keepAlive);
|
||||
client.setCallback(fileEdgeResponseConsumer);
|
||||
IMqttToken iMqttToken = client.connectWithResult(options);
|
||||
boolean complete = iMqttToken.isComplete();
|
||||
log.info("FileResponseClient建立连接:{}", complete);
|
||||
|
||||
//这里监听的是
|
||||
String[] topic = AnotherMqttConfigUtil.getFileResponseTopic();
|
||||
int[] qos = new int[topic.length];
|
||||
client.subscribe(topic,qos);
|
||||
log.info("已订阅topic:{}", topic);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return client;
|
||||
}
|
||||
}
|
||||
@ -13,9 +13,12 @@ import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.CommonBytesUtil;
|
||||
import com.ho.common.tools.util.MqttUtil;
|
||||
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.util.MqttConfigUtil;
|
||||
import com.ho.filecenter.vo.mqtt.*;
|
||||
import com.ho.filecenter.vo.resp.*;
|
||||
import io.swagger.annotations.Api;
|
||||
@ -53,6 +56,8 @@ public class FileController {
|
||||
@Autowired
|
||||
CommonBytesUtil bytesUtil;
|
||||
|
||||
@Autowired
|
||||
AnotherFileService anotherFileService;
|
||||
@PostMapping("filePage")
|
||||
@ApiOperation(value = "分页查询文件")
|
||||
public DataResult<PageResult<MediaFile>> filePage(@RequestBody FilePageVO vo, HttpServletRequest request) {
|
||||
@ -152,7 +157,13 @@ public class FileController {
|
||||
fileAttributeResp.setList(new ArrayList<>());
|
||||
return DataResult.success(fileAttributeResp);
|
||||
}
|
||||
fileAttributeResp = fileService.getFileAttribute(vo);
|
||||
String serialNo = vo.getSerialNo();
|
||||
List<String> snList = MqttConfigUtil.getSnList();
|
||||
if(snList.contains(serialNo)){
|
||||
fileAttributeResp = fileService.getFileAttribute(vo);
|
||||
}else{
|
||||
fileAttributeResp = anotherFileService.getFileAttribute(vo);
|
||||
}
|
||||
return DataResult.success(fileAttributeResp);
|
||||
}
|
||||
|
||||
@ -168,7 +179,13 @@ public class FileController {
|
||||
fileDeleteResp.setMsg(msg + CommonConstant.Heartbeat.FAIL);
|
||||
return DataResult.success(fileDeleteResp);
|
||||
}
|
||||
fileDeleteResp = fileService.deleteDeviceFiles(fileDeleteReqVO);
|
||||
String serialNo = fileDeleteReqVO.getSerialNo();
|
||||
List<String> snList = MqttConfigUtil.getSnList();
|
||||
if(snList.contains(serialNo)){
|
||||
fileDeleteResp = fileService.deleteDeviceFiles(fileDeleteReqVO);
|
||||
}else{
|
||||
fileDeleteResp = anotherFileService.deleteDeviceFiles(fileDeleteReqVO);
|
||||
}
|
||||
return DataResult.success(fileDeleteResp);
|
||||
}
|
||||
|
||||
@ -193,7 +210,12 @@ public class FileController {
|
||||
resp.setMsg(CommonConstant.Heartbeat.MSG + serialNo + CommonConstant.Heartbeat.SUCCESS);
|
||||
resp.setHeartbeatStatus(CommonConstant.ONE);
|
||||
log.info("文件上传(向边端上传)开始上传");
|
||||
fileService.fileUploadForDevice(file, stationId, serialNo, filePath);
|
||||
List<String> snList = MqttConfigUtil.getSnList();
|
||||
if(snList.contains(serialNo)){
|
||||
fileService.fileUploadForDevice(file, stationId, serialNo, filePath);
|
||||
}else{
|
||||
anotherFileService.fileUploadForDevice(file, stationId, serialNo, filePath);
|
||||
}
|
||||
}
|
||||
return DataResult.success(resp);
|
||||
}
|
||||
@ -217,6 +239,13 @@ public class FileController {
|
||||
resp.setHeartbeatStatus(CommonConstant.ONE);
|
||||
log.info("文件下载(从边端下载到云端)开始下载");
|
||||
fileService.downloadFromDevice(fileForDeviceReqVO);
|
||||
String serialNo = fileForDeviceReqVO.getSerialNo();
|
||||
List<String> snList = MqttConfigUtil.getSnList();
|
||||
if(snList.contains(serialNo)){
|
||||
fileService.downloadFromDevice(fileForDeviceReqVO);
|
||||
}else{
|
||||
anotherFileService.downloadFromDevice(fileForDeviceReqVO);
|
||||
}
|
||||
}
|
||||
return DataResult.success(resp);
|
||||
}
|
||||
|
||||
@ -18,7 +18,9 @@ import com.ho.common.tools.service.RedisService;
|
||||
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.OrderSendService;
|
||||
import com.ho.filecenter.util.MqttConfigUtil;
|
||||
import com.ho.filecenter.vo.mqtt.*;
|
||||
import com.ho.filecenter.vo.resp.HeartbeatResp;
|
||||
import com.ho.filecenter.vo.resp.OrderProcessDetailResp;
|
||||
@ -60,6 +62,9 @@ public class OrderSendController {
|
||||
@Autowired
|
||||
UserFeignClient userFeignClient;
|
||||
|
||||
@Autowired
|
||||
AnotherOrderSendService anotherOrderSendService;
|
||||
|
||||
public static final Long TIME_LIMIT = 90L;
|
||||
|
||||
@PostMapping("orderIssued")
|
||||
@ -158,7 +163,12 @@ public class OrderSendController {
|
||||
return DataResult.success(heartbeatResp);
|
||||
}
|
||||
log.info("指令下发正常开始下发");
|
||||
orderSendService.orderIssued(vo);
|
||||
List<String> snList = MqttConfigUtil.getSnList();
|
||||
if(snList.contains(sn)){
|
||||
orderSendService.orderIssued(vo);
|
||||
}else{
|
||||
anotherOrderSendService.orderIssued(vo);
|
||||
}
|
||||
if(vo.getPlanTemId() != null){
|
||||
String hourValue ="";
|
||||
String minuteValue ="";
|
||||
@ -322,7 +332,14 @@ public class OrderSendController {
|
||||
// @LogAnnotation(title = "命令下发曲线", action = "命令下发曲线")
|
||||
@TokenIgnore
|
||||
public DataResult<HeartbeatResp> sendPlanPowerOrder(@RequestBody OrderPlanPowerReq vo) {
|
||||
HeartbeatResp heartbeatResp = orderSendService.sendPlanPowerOrder(vo);
|
||||
String sn = vo.getSn();
|
||||
List<String> snList = MqttConfigUtil.getSnList();
|
||||
HeartbeatResp heartbeatResp = null;
|
||||
if(snList.contains(sn)){
|
||||
heartbeatResp = orderSendService.sendPlanPowerOrder(vo);
|
||||
}else{
|
||||
heartbeatResp = anotherOrderSendService.sendPlanPowerOrder(vo);
|
||||
}
|
||||
return DataResult.success(heartbeatResp);
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,66 @@
|
||||
package com.ho.filecenter.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class AnotherMqttConfigUtil {
|
||||
|
||||
public static String[] commonTopic = new String[]{
|
||||
"+/device/27d83a2844ff5866",
|
||||
"+/device/77ba753718908d1a",
|
||||
"1/device/+"
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取文件请求监听主题
|
||||
* @return
|
||||
*/
|
||||
public static String[] getFileRequestTopic(){
|
||||
String log = "/file/request";
|
||||
String[] str = new String[commonTopic.length];
|
||||
for (int i = 0; i < commonTopic.length; i++) {
|
||||
str[i] = commonTopic[i]+log;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取文件响应监听主题
|
||||
* @return
|
||||
*/
|
||||
public static String[] getFileResponseTopic(){
|
||||
String log = "/file/response";
|
||||
String[] str = new String[commonTopic.length];
|
||||
for (int i = 0; i < commonTopic.length; i++) {
|
||||
str[i] = commonTopic[i]+log;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public static String[] getCurveResponseTopic(){
|
||||
String log = "/curve/response";
|
||||
String[] str = new String[commonTopic.length];
|
||||
for (int i = 0; i < commonTopic.length; i++) {
|
||||
str[i] = commonTopic[i]+log;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public static String[] getDispatchResponseTopic(){
|
||||
String log = "/dispatch/response";
|
||||
String[] str = new String[commonTopic.length];
|
||||
for (int i = 0; i < commonTopic.length; i++) {
|
||||
str[i] = commonTopic[i]+log;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取SN配置合集
|
||||
* @return
|
||||
*/
|
||||
public static List<String> getSnList(){
|
||||
List<String> strings = Arrays.asList(commonTopic);
|
||||
return strings;
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,8 @@
|
||||
package com.ho.filecenter.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class MqttConfigUtil {
|
||||
|
||||
public static String[] commonTopic = new String[]{
|
||||
@ -174,4 +177,13 @@ public class MqttConfigUtil {
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取SN配置合集
|
||||
* @return
|
||||
*/
|
||||
public static List<String> getSnList(){
|
||||
List<String> strings = Arrays.asList(commonTopic);
|
||||
return strings;
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,3 +78,11 @@ switch:
|
||||
fileDefaultLogic: true
|
||||
#命令下发默认逻辑的开关 true 为打开 ,false为关闭
|
||||
orderSendDefaultLogic: true
|
||||
|
||||
#mqtt接外部数据使用
|
||||
mqtt1:
|
||||
url: tcp://1.95.131.171:1883
|
||||
userName: root
|
||||
passWord: zzkj@688737
|
||||
timeout: 5000
|
||||
keepAlive: 60
|
||||
Binary file not shown.
Reference in New Issue
Block a user