Merge branch 'dyf-device' into prod

This commit is contained in:
2025-12-19 14:08:03 +08:00
13 changed files with 180 additions and 50 deletions

View File

@ -0,0 +1,64 @@
package com.fuyuanshen;
import com.fuyuanshen.equipment.utils.AlibabaTTSUtil;
import com.fuyuanshen.equipment.utils.AudioProcessUtil;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* @author: 默苍璃
* @date: 2025-12-1518:51
*/
public class Text {
public static void main(String[] args) throws IOException {
String text = "简述人生观的主要内容。\n" +
"人生观的主要内容包括以下三个方面:\n" +
"1.人生目的:回答“人为什么活着”的根本问题。它规定了人生的方向,是人生观的核心。\n" +
"2.人生态度:回答“人应该怎样活着”的问题。它是指人们通过生活实践形成的对人生问题的一种稳定的心理倾向和基本意图。\n" +
"3.人生价值:回答“什么样的人生才有意义”的问题。它是指人的生命及其实践活动对于社会和个人所具有的作用和意义。\n" +
"人生目的、人生态度和人生价值相互联系、相辅相成,共同构成一个有机整体。\n" +
"人生目的是人生观的核心,它决定人生态度和人生价值的方向;人生态度影响人生目的的实现和人生价值的创造;人生价值是衡量人生观正确与否的尺度。";
AlibabaTTSUtil alibabaTTSUtil = new AlibabaTTSUtil();
AudioProcessUtil audioProcessUtil = new AudioProcessUtil();
byte[] rawPcmData = alibabaTTSUtil.generateStandardPcmData(text);
// 使用AudioProcessUtil转换成带头44字节 PCM
byte[] pcmData = audioProcessUtil.rawPcmToStandardWav(rawPcmData);
// String savedPath = audioProcessUtil.saveWavToFile(pcmData, "test_output.wav");
// if (savedPath != null) {
// log.info("测试文件已保存: {}", savedPath);
// }
// 保存WAV文件到本地
String savedPath = saveByteArrayToFile(pcmData, "人生观.wav");
if (savedPath != null) {
System.out.println("WAV文件已保存: " + savedPath);
}
}
private static String saveByteArrayToFile(byte[] data, String filename) throws IOException {
// 确定保存路径(可以是临时目录或指定目录)
String directory = System.getProperty("java.io.tmpdir"); // 使用系统临时目录
File dir = new File(directory);
if (!dir.exists()) {
dir.mkdirs();
}
// 创建完整文件路径
File file = new File(dir, filename);
// 写入文件
try (FileOutputStream fos = new FileOutputStream(file)) {
fos.write(data);
}
return file.getAbsolutePath();
}
}

View File

@ -64,4 +64,5 @@ public class AppVideoController extends BaseController {
public R<String> extract(@RequestParam("file") MultipartFile file) throws Exception {
return R.ok("Success",audioProcessService.extract(file));
}
}

View File

@ -10,22 +10,43 @@ import org.springframework.integration.mqtt.core.MqttPahoClientFactory;
@Configuration
public class MqttConfiguration {
@Autowired
private MqttPropertiesConfig mqttPropertiesConfig;
/** 创建连接工厂 **/
/**
* 创建连接工厂
**/
@Bean
public MqttPahoClientFactory mqttPahoClientFactory(){
public MqttPahoClientFactory mqttPahoClientFactory() {
DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(true); //设置新会话
options.setUserName(mqttPropertiesConfig.getUsername());
options.setPassword(mqttPropertiesConfig.getPassword().toCharArray());
options.setServerURIs(new String[]{mqttPropertiesConfig.getUrl()});
options.setCleanSession(true); // 设置新会话
// 修复用户名为null时的空指针异常
String username = mqttPropertiesConfig.getUsername();
if (username != null) {
options.setUserName(username);
}
// 修复密码为null时的空指针异常
String password = mqttPropertiesConfig.getPassword();
if (password != null) {
options.setPassword(password.toCharArray());
}
// 修复URL为null时的空指针异常
String url = mqttPropertiesConfig.getUrl();
if (url != null) {
options.setServerURIs(new String[]{url});
}
options.setAutomaticReconnect(true); // 启用自动重连
options.setConnectionTimeout(10); // 设置连接超时时间
options.setKeepAliveInterval(60); // 设置心跳间隔
factory.setConnectionOptions(options);
return factory;
}
}

View File

@ -39,8 +39,14 @@ public class MqttInboundConfiguration {
public MessageProducer messageProducer(){
// 生成一个不重复的随机数
String clientId = mqttPropertiesConfig.getSubClientId() + "_" + UUID.fastUUID();
// 修复URL为null时的空指针异常
String url = mqttPropertiesConfig.getUrl();
if (url == null) {
throw new IllegalStateException("MQTT服务器URL未配置");
}
MqttPahoMessageDrivenChannelAdapter mqttPahoMessageDrivenChannelAdapter = new MqttPahoMessageDrivenChannelAdapter(
mqttPropertiesConfig.getUrl(),
url,
clientId,
mqttPahoClientFactory,
mqttPropertiesConfig.getSubTopic().split(",")

View File

@ -32,8 +32,14 @@ public class MqttOutboundConfiguration {
@ServiceActivator(inputChannel = "mqttOutboundChannel") // 指定处理器针对哪个通道的消息进行处理
public MessageHandler mqttOutboundMessageHandler(){
String clientId = mqttPropertiesConfig.getPubClientId() + "_" + UUID.fastUUID();
// 修复URL为null时的空指针异常
String url = mqttPropertiesConfig.getUrl();
if (url == null) {
throw new IllegalStateException("MQTT服务器URL未配置");
}
MqttPahoMessageHandler mqttPahoMessageHandler = new MqttPahoMessageHandler(
mqttPropertiesConfig.getUrl(),
url,
clientId,
mqttPahoClientFactory
);

View File

@ -59,6 +59,7 @@ public class DeviceFenceAccessRecordController extends BaseController {
ExcelUtil.exportExcel(list, "围栏进出记录", DeviceFenceAccessRecordVo.class, response);
}
/**
* 获取围栏进出记录详细信息
*

View File

@ -103,6 +103,7 @@ public class DeviceGeoFenceController extends BaseController {
return toAjax(deviceGeoFenceService.updateByBo(bo));
}
/**
* 删除电子围栏
*
@ -130,6 +131,7 @@ public class DeviceGeoFenceController extends BaseController {
return ResponseEntity.ok(response);
}
/**
* 添加电子围栏终端
*