diff --git a/business-service-dao/src/main/java/com/ho/business/service/impl/IargeScreenShowServiceImpl.java b/business-service-dao/src/main/java/com/ho/business/service/impl/IargeScreenShowServiceImpl.java index c5bca5e..303f53c 100644 --- a/business-service-dao/src/main/java/com/ho/business/service/impl/IargeScreenShowServiceImpl.java +++ b/business-service-dao/src/main/java/com/ho/business/service/impl/IargeScreenShowServiceImpl.java @@ -82,6 +82,7 @@ public class IargeScreenShowServiceImpl implements IargeScreenShowService { private final static BigDecimal parameter = new BigDecimal("18.3"); private final static BigDecimal four = new BigDecimal("0.4"); 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 BigDecimal hundred = new BigDecimal(100); private final static int FENGStationId = 418; @@ -503,8 +504,8 @@ public class IargeScreenShowServiceImpl implements IargeScreenShowService { //等效节约煤 等效节约煤=所有电站总充*节约标准煤转换系数(04) BigDecimal equivalentCoal = totalCharge.multiply(four); energySavingRespVo.setEquivalentCoal(equivalentCoal); - //等效经济收入 等效经济收入=所有电站总充*对应谷时电价 - energySavingRespVo.setIncome(income); + //等效经济收入 等效经济收入=等效节约煤*煤价 (600元/吨) 等效节约煤此处单位为kg,故而单价调整为0.6元/kg + energySavingRespVo.setIncome(equivalentCoal.multiply(coalPrice)); return energySavingRespVo; } diff --git a/file-center/src/main/java/com/ho/filecenter/config/AnotherMqttConfig.java b/file-center/src/main/java/com/ho/filecenter/config/AnotherMqttConfig.java new file mode 100644 index 0000000..6f56325 --- /dev/null +++ b/file-center/src/main/java/com/ho/filecenter/config/AnotherMqttConfig.java @@ -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; + } +} 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 7571407..16ac047 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 @@ -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> 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 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 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 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 snList = MqttConfigUtil.getSnList(); + if(snList.contains(serialNo)){ + fileService.downloadFromDevice(fileForDeviceReqVO); + }else{ + anotherFileService.downloadFromDevice(fileForDeviceReqVO); + } } return DataResult.success(resp); } 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 03d88a1..a30c56b 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 @@ -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 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 sendPlanPowerOrder(@RequestBody OrderPlanPowerReq vo) { - HeartbeatResp heartbeatResp = orderSendService.sendPlanPowerOrder(vo); + String sn = vo.getSn(); + List snList = MqttConfigUtil.getSnList(); + HeartbeatResp heartbeatResp = null; + if(snList.contains(sn)){ + heartbeatResp = orderSendService.sendPlanPowerOrder(vo); + }else{ + heartbeatResp = anotherOrderSendService.sendPlanPowerOrder(vo); + } return DataResult.success(heartbeatResp); } diff --git a/file-center/src/main/java/com/ho/filecenter/util/AnotherMqttConfigUtil.java b/file-center/src/main/java/com/ho/filecenter/util/AnotherMqttConfigUtil.java new file mode 100644 index 0000000..2785899 --- /dev/null +++ b/file-center/src/main/java/com/ho/filecenter/util/AnotherMqttConfigUtil.java @@ -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 getSnList(){ + List strings = Arrays.asList(commonTopic); + return strings; + } +} 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 d0ff660..a34df1b 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 @@ -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 getSnList(){ + List strings = Arrays.asList(commonTopic); + return strings; + } } diff --git a/file-center/src/main/resources/bootstrap.yml b/file-center/src/main/resources/bootstrap.yml index f5f2bd6..f09bcfd 100644 --- a/file-center/src/main/resources/bootstrap.yml +++ b/file-center/src/main/resources/bootstrap.yml @@ -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 \ No newline at end of file diff --git a/file-center/src/main/resources/lib/file-src-1.0.jar b/file-center/src/main/resources/lib/file-src-1.0.jar index 39b845d..65d3d59 100644 Binary files a/file-center/src/main/resources/lib/file-src-1.0.jar and b/file-center/src/main/resources/lib/file-src-1.0.jar differ