文件服务双发代码提交
This commit is contained in:
@ -82,6 +82,7 @@ public class IargeScreenShowServiceImpl implements IargeScreenShowService {
|
|||||||
private final static BigDecimal parameter = new BigDecimal("18.3");
|
private final static BigDecimal parameter = new BigDecimal("18.3");
|
||||||
private final static BigDecimal four = new BigDecimal("0.4");
|
private final static BigDecimal four = new BigDecimal("0.4");
|
||||||
private final static BigDecimal fours = new BigDecimal("40");
|
private final static BigDecimal fours = new BigDecimal("40");
|
||||||
|
private final static BigDecimal coalPrice = new BigDecimal("0.6");//煤炭价格
|
||||||
private final static Integer maxSize = 30;
|
private final static Integer maxSize = 30;
|
||||||
private final static BigDecimal hundred = new BigDecimal(100);
|
private final static BigDecimal hundred = new BigDecimal(100);
|
||||||
private final static int FENGStationId = 418;
|
private final static int FENGStationId = 418;
|
||||||
@ -503,8 +504,8 @@ public class IargeScreenShowServiceImpl implements IargeScreenShowService {
|
|||||||
//等效节约煤 等效节约煤=所有电站总充*节约标准煤转换系数(04)
|
//等效节约煤 等效节约煤=所有电站总充*节约标准煤转换系数(04)
|
||||||
BigDecimal equivalentCoal = totalCharge.multiply(four);
|
BigDecimal equivalentCoal = totalCharge.multiply(four);
|
||||||
energySavingRespVo.setEquivalentCoal(equivalentCoal);
|
energySavingRespVo.setEquivalentCoal(equivalentCoal);
|
||||||
//等效经济收入 等效经济收入=所有电站总充*对应谷时电价
|
//等效经济收入 等效经济收入=等效节约煤*煤价 (600元/吨) 等效节约煤此处单位为kg,故而单价调整为0.6元/kg
|
||||||
energySavingRespVo.setIncome(income);
|
energySavingRespVo.setIncome(equivalentCoal.multiply(coalPrice));
|
||||||
return energySavingRespVo;
|
return energySavingRespVo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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.exception.DataResult;
|
||||||
import com.ho.common.tools.service.RedisService;
|
import com.ho.common.tools.service.RedisService;
|
||||||
import com.ho.common.tools.util.CommonBytesUtil;
|
import com.ho.common.tools.util.CommonBytesUtil;
|
||||||
|
import com.ho.common.tools.util.MqttUtil;
|
||||||
import com.ho.common.tools.util.PageResult;
|
import com.ho.common.tools.util.PageResult;
|
||||||
import com.ho.filecenter.entity.MediaFile;
|
import com.ho.filecenter.entity.MediaFile;
|
||||||
|
import com.ho.filecenter.service.AnotherFileService;
|
||||||
import com.ho.filecenter.service.FileService;
|
import com.ho.filecenter.service.FileService;
|
||||||
|
import com.ho.filecenter.util.MqttConfigUtil;
|
||||||
import com.ho.filecenter.vo.mqtt.*;
|
import com.ho.filecenter.vo.mqtt.*;
|
||||||
import com.ho.filecenter.vo.resp.*;
|
import com.ho.filecenter.vo.resp.*;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
@ -53,6 +56,8 @@ public class FileController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
CommonBytesUtil bytesUtil;
|
CommonBytesUtil bytesUtil;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
AnotherFileService anotherFileService;
|
||||||
@PostMapping("filePage")
|
@PostMapping("filePage")
|
||||||
@ApiOperation(value = "分页查询文件")
|
@ApiOperation(value = "分页查询文件")
|
||||||
public DataResult<PageResult<MediaFile>> filePage(@RequestBody FilePageVO vo, HttpServletRequest request) {
|
public DataResult<PageResult<MediaFile>> filePage(@RequestBody FilePageVO vo, HttpServletRequest request) {
|
||||||
@ -152,7 +157,13 @@ public class FileController {
|
|||||||
fileAttributeResp.setList(new ArrayList<>());
|
fileAttributeResp.setList(new ArrayList<>());
|
||||||
return DataResult.success(fileAttributeResp);
|
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);
|
return DataResult.success(fileAttributeResp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +179,13 @@ public class FileController {
|
|||||||
fileDeleteResp.setMsg(msg + CommonConstant.Heartbeat.FAIL);
|
fileDeleteResp.setMsg(msg + CommonConstant.Heartbeat.FAIL);
|
||||||
return DataResult.success(fileDeleteResp);
|
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);
|
return DataResult.success(fileDeleteResp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,7 +210,12 @@ public class FileController {
|
|||||||
resp.setMsg(CommonConstant.Heartbeat.MSG + serialNo + CommonConstant.Heartbeat.SUCCESS);
|
resp.setMsg(CommonConstant.Heartbeat.MSG + serialNo + CommonConstant.Heartbeat.SUCCESS);
|
||||||
resp.setHeartbeatStatus(CommonConstant.ONE);
|
resp.setHeartbeatStatus(CommonConstant.ONE);
|
||||||
log.info("文件上传(向边端上传)开始上传");
|
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);
|
return DataResult.success(resp);
|
||||||
}
|
}
|
||||||
@ -217,6 +239,13 @@ public class FileController {
|
|||||||
resp.setHeartbeatStatus(CommonConstant.ONE);
|
resp.setHeartbeatStatus(CommonConstant.ONE);
|
||||||
log.info("文件下载(从边端下载到云端)开始下载");
|
log.info("文件下载(从边端下载到云端)开始下载");
|
||||||
fileService.downloadFromDevice(fileForDeviceReqVO);
|
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);
|
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.common.tools.util.PageResult;
|
||||||
import com.ho.filecenter.feignclient.BusinessFeignClient;
|
import com.ho.filecenter.feignclient.BusinessFeignClient;
|
||||||
import com.ho.filecenter.feignclient.UserFeignClient;
|
import com.ho.filecenter.feignclient.UserFeignClient;
|
||||||
|
import com.ho.filecenter.service.AnotherOrderSendService;
|
||||||
import com.ho.filecenter.service.OrderSendService;
|
import com.ho.filecenter.service.OrderSendService;
|
||||||
|
import com.ho.filecenter.util.MqttConfigUtil;
|
||||||
import com.ho.filecenter.vo.mqtt.*;
|
import com.ho.filecenter.vo.mqtt.*;
|
||||||
import com.ho.filecenter.vo.resp.HeartbeatResp;
|
import com.ho.filecenter.vo.resp.HeartbeatResp;
|
||||||
import com.ho.filecenter.vo.resp.OrderProcessDetailResp;
|
import com.ho.filecenter.vo.resp.OrderProcessDetailResp;
|
||||||
@ -60,6 +62,9 @@ public class OrderSendController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
UserFeignClient userFeignClient;
|
UserFeignClient userFeignClient;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
AnotherOrderSendService anotherOrderSendService;
|
||||||
|
|
||||||
public static final Long TIME_LIMIT = 90L;
|
public static final Long TIME_LIMIT = 90L;
|
||||||
|
|
||||||
@PostMapping("orderIssued")
|
@PostMapping("orderIssued")
|
||||||
@ -158,7 +163,12 @@ public class OrderSendController {
|
|||||||
return DataResult.success(heartbeatResp);
|
return DataResult.success(heartbeatResp);
|
||||||
}
|
}
|
||||||
log.info("指令下发正常开始下发");
|
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){
|
if(vo.getPlanTemId() != null){
|
||||||
String hourValue ="";
|
String hourValue ="";
|
||||||
String minuteValue ="";
|
String minuteValue ="";
|
||||||
@ -322,7 +332,14 @@ public class OrderSendController {
|
|||||||
// @LogAnnotation(title = "命令下发曲线", action = "命令下发曲线")
|
// @LogAnnotation(title = "命令下发曲线", action = "命令下发曲线")
|
||||||
@TokenIgnore
|
@TokenIgnore
|
||||||
public DataResult<HeartbeatResp> sendPlanPowerOrder(@RequestBody OrderPlanPowerReq vo) {
|
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);
|
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;
|
package com.ho.filecenter.util;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class MqttConfigUtil {
|
public class MqttConfigUtil {
|
||||||
|
|
||||||
public static String[] commonTopic = new String[]{
|
public static String[] commonTopic = new String[]{
|
||||||
@ -174,4 +177,13 @@ public class MqttConfigUtil {
|
|||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取SN配置合集
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<String> getSnList(){
|
||||||
|
List<String> strings = Arrays.asList(commonTopic);
|
||||||
|
return strings;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -78,3 +78,11 @@ switch:
|
|||||||
fileDefaultLogic: true
|
fileDefaultLogic: true
|
||||||
#命令下发默认逻辑的开关 true 为打开 ,false为关闭
|
#命令下发默认逻辑的开关 true 为打开 ,false为关闭
|
||||||
orderSendDefaultLogic: true
|
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