forked from dyf/fys-Multi-tenant
提交代码8
This commit is contained in:
@ -544,17 +544,17 @@ public class AudioProcessService {
|
||||
extension = "." + extension;
|
||||
}
|
||||
|
||||
return timestamp;
|
||||
return timestamp+extension;
|
||||
}
|
||||
|
||||
public List<AppFileVo> queryAudioFileList(Long deviceId) {
|
||||
if(deviceId == null){
|
||||
return null;
|
||||
}
|
||||
Long userId = LoginHelper.getUserId();
|
||||
// Long userId = LoginHelper.getUserId();
|
||||
AppBusinessFileBo bo = new AppBusinessFileBo();
|
||||
bo.setBusinessId(deviceId);
|
||||
bo.setCreateBy(userId);
|
||||
// bo.setCreateBy(userId);
|
||||
bo.setFileType(3L);
|
||||
return appBusinessFileService.queryAppFileList(bo);
|
||||
}
|
||||
|
||||
@ -109,6 +109,15 @@ public class RegisEquipReceiverMessageHandler implements MessageHandler {
|
||||
Device device = deviceMapper.selectDeviceByImei(imei);
|
||||
if (device != null) {
|
||||
log.warn("Device already exists for IMEI: {}", imei);
|
||||
String redisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX +
|
||||
imei + ":regis";
|
||||
String value = RedisUtils.getCacheObject(redisKey);
|
||||
if (value != null) {
|
||||
log.warn("regis/imei发送次数频率过快: {}", imei);
|
||||
return;
|
||||
}
|
||||
sendSuccessMessage(imei);
|
||||
RedisUtils.setCacheObject(redisKey, device, Duration.ofSeconds(10));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -130,13 +139,17 @@ public class RegisEquipReceiverMessageHandler implements MessageHandler {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
sendSuccessMessage(imei);
|
||||
|
||||
}
|
||||
|
||||
private void sendSuccessMessage(String imei) {
|
||||
// 解析原始JSON数据
|
||||
JSONObject originalData = new JSONObject();
|
||||
originalData.put("code", 200);
|
||||
// 发送到MQTT
|
||||
String topic = "regis/" + imei;
|
||||
mqttGateway.sendMsgToMqtt(topic, originalData.toString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,135 @@
|
||||
package com.fuyuanshen.web.controller.device;
|
||||
|
||||
import com.fuyuanshen.app.domain.dto.AppAudioFileDto;
|
||||
import com.fuyuanshen.app.domain.dto.AppFileRenameDto;
|
||||
import com.fuyuanshen.app.domain.dto.TextToSpeechRequest;
|
||||
import com.fuyuanshen.app.service.AudioProcessService;
|
||||
import com.fuyuanshen.app.service.VideoProcessService;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit;
|
||||
import com.fuyuanshen.common.web.core.BaseController;
|
||||
import com.fuyuanshen.equipment.domain.vo.AppFileVo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* APP 视频处理控制器
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/video")
|
||||
public class WebVideoController extends BaseController {
|
||||
|
||||
private final VideoProcessService videoProcessService;
|
||||
private final AudioProcessService audioProcessService;
|
||||
|
||||
/**
|
||||
* 上传视频转码code默认1:RGB565 2:BGR565
|
||||
*/
|
||||
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS,message = "请勿重复提交!")
|
||||
public R<List<String>> uploadVideo(@RequestParam("file") MultipartFile file, @RequestParam(defaultValue = "1") int code) {
|
||||
return R.ok(videoProcessService.processVideo(file, code));
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传音频文件并转码
|
||||
*/
|
||||
@PostMapping(value = "/audio", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS,message = "请勿重复提交!")
|
||||
public R<List<String>> uploadAudio(@RequestParam("file") MultipartFile file) {
|
||||
return R.ok(audioProcessService.processAudio(file));
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字转音频TTS服务
|
||||
*/
|
||||
@GetMapping("/audioTTS")
|
||||
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS,message = "请勿重复提交!")
|
||||
public R<List<String>> uploadAudioTTS(@RequestParam String text) throws IOException {
|
||||
return R.ok(audioProcessService.generateStandardPcmData(text));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 提取文本内容(只支持txt/docx)
|
||||
*/
|
||||
@PostMapping(value = "/extract", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS,message = "请勿重复提交!")
|
||||
public R<String> extract(@RequestParam("file") MultipartFile file) throws Exception {
|
||||
return R.ok("Success",audioProcessService.extract(file));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传音频文件进行处理
|
||||
* 支持MP3、WAV、PCM格式
|
||||
*/
|
||||
@PostMapping("/uploadAudioToOss")
|
||||
public R<String> uploadAudioToOss(@ModelAttribute AppAudioFileDto bo) {
|
||||
try {
|
||||
String result = audioProcessService.uploadAudioToOss(bo);
|
||||
return R.ok(result);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return R.fail("文件格式错误: " + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
|
||||
return R.fail("上传处理失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 文本转语音
|
||||
* 支持MP3、WAV、PCM格式
|
||||
*/
|
||||
@PostMapping("/ttsToOss")
|
||||
public R<String> textToSpeech(@RequestBody TextToSpeechRequest request) {
|
||||
try {
|
||||
if (request.getDeviceId() == null) {
|
||||
return R.fail("设备ID不能为空");
|
||||
}
|
||||
|
||||
String result = audioProcessService.textToSpeech(
|
||||
request.getDeviceId(),
|
||||
request.getText(),
|
||||
request.getFileSuffix()
|
||||
);
|
||||
return R.ok(result);
|
||||
} catch (Exception e) {
|
||||
return R.fail("文本转语音失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询语音文件列表
|
||||
*/
|
||||
@GetMapping("/queryAudioFileList")
|
||||
public R<List<AppFileVo>> queryAudioFileList(Long deviceId) {
|
||||
return R.ok(audioProcessService.queryAudioFileList(deviceId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除语音文件
|
||||
*/
|
||||
@GetMapping("/deleteAudioFile")
|
||||
public R<Void> deleteAudioFile(Long fileId,Long deviceId) {
|
||||
return audioProcessService.deleteAudioFile(fileId,deviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件重命名
|
||||
*/
|
||||
@PostMapping("/renameAudioFile")
|
||||
public R<Void> renameAudioFile(@RequestBody AppFileRenameDto bo) {
|
||||
return audioProcessService.renameAudioFile(bo);
|
||||
}
|
||||
}
|
||||
@ -7,10 +7,12 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceHBY100JDetailVo;
|
||||
import com.fuyuanshen.app.mapper.AppDeviceShareMapper;
|
||||
import com.fuyuanshen.common.core.constant.GlobalConstants;
|
||||
import com.fuyuanshen.common.core.domain.model.AppLoginUser;
|
||||
import com.fuyuanshen.common.core.domain.model.LoginUser;
|
||||
import com.fuyuanshen.common.core.exception.ServiceException;
|
||||
import com.fuyuanshen.common.core.utils.StringUtils;
|
||||
import com.fuyuanshen.common.redis.utils.RedisUtils;
|
||||
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
|
||||
import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
import com.fuyuanshen.equipment.domain.AppBusinessFile;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
@ -57,6 +59,8 @@ public class DeviceHBY100JBizService {
|
||||
|
||||
|
||||
private static final String DEVICE_TYPE = "HBY100/";
|
||||
|
||||
private static final Long pcUserId = 0L;
|
||||
/**
|
||||
* 记录设备操作日志
|
||||
*
|
||||
@ -155,6 +159,17 @@ public class DeviceHBY100JBizService {
|
||||
vo.setAlarmMode(sirenAlarm.getMode());
|
||||
}
|
||||
}
|
||||
|
||||
String voicePlayRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX +
|
||||
device.getDeviceImei() + ":voicePlay";
|
||||
String voicePlayStatus = RedisUtils.getCacheObject(voicePlayRedisKey);
|
||||
if(StringUtils.isNotBlank(voicePlayStatus)){
|
||||
FuncType6VoicePlayRequest funcType6VoicePlayRequest = JSONObject.parseObject(voicePlayStatus, FuncType6VoicePlayRequest.class);
|
||||
if(funcType6VoicePlayRequest.getData() != null){
|
||||
vo.setVolume(funcType6VoicePlayRequest.getData().getVoiceBroadcast());
|
||||
}
|
||||
}
|
||||
|
||||
String strobeModeRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX +
|
||||
device.getDeviceImei() + ":strobeMode";
|
||||
String strobeModeStatus = RedisUtils.getCacheObject(strobeModeRedisKey);
|
||||
@ -236,7 +251,7 @@ public class DeviceHBY100JBizService {
|
||||
if (deviceIds == null || deviceIds.isEmpty()) {
|
||||
throw new ServiceException("请选择设备");
|
||||
}
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
AppLoginUser loginUser = AppLoginHelper.getLoginUser();
|
||||
bo.getDeviceIds().forEach(deviceId -> {
|
||||
Device deviceObj = deviceMapper.selectById(deviceId);
|
||||
if (getDeviceStatus(deviceObj.getDeviceImei())) {
|
||||
@ -254,9 +269,9 @@ public class DeviceHBY100JBizService {
|
||||
request.setData(data);
|
||||
log.info("HBY100J强制报警,下发设备参数:{}", request);
|
||||
mqttGateway.sendMsgToMqtt(buildMqttTopic(deviceObj.getDeviceImei()), 1, JSON.toJSONString(request));
|
||||
Long userId = loginUser == null ? pcUserId : loginUser.getUserId();
|
||||
|
||||
|
||||
recordDeviceLog(deviceId, deviceObj.getDeviceName(), "强制报警激活", "强制报警激活", loginUser.getUserId());
|
||||
recordDeviceLog(deviceId, deviceObj.getDeviceName(), "强制报警激活", "强制报警激活", userId);
|
||||
});
|
||||
|
||||
}
|
||||
@ -271,7 +286,7 @@ public class DeviceHBY100JBizService {
|
||||
throw new ServiceException(deviceObj.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
AppLoginUser loginUser = AppLoginHelper.getLoginUser();
|
||||
SysOssVo sysOssVo = sysOssMapper.selectVoById(appBusinessFileVo.getFileId());
|
||||
FuncType5UpdateVoiceRequest request = new FuncType5UpdateVoiceRequest();
|
||||
request.setRequestId(GenerateIdUtil.generateNumericId());
|
||||
@ -295,8 +310,8 @@ public class DeviceHBY100JBizService {
|
||||
updateWrapper2.eq("id", appBusinessFileVo.getId());
|
||||
updateWrapper2.set("use_status", 1);
|
||||
appBusinessFileMapper.update(updateWrapper2);
|
||||
|
||||
recordDeviceLog(deviceObj.getId(), deviceObj.getDeviceName(), "更新语音", "更新语音", loginUser.getUserId());
|
||||
Long userId = loginUser == null ? pcUserId : loginUser.getUserId();
|
||||
recordDeviceLog(deviceObj.getId(), deviceObj.getDeviceName(), "更新语音", "更新语音", userId);
|
||||
}
|
||||
|
||||
private String buildMqttTopic(String deviceImei) {
|
||||
@ -309,7 +324,7 @@ public class DeviceHBY100JBizService {
|
||||
if (getDeviceStatus(deviceObj.getDeviceImei())) {
|
||||
throw new ServiceException(deviceObj.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
AppLoginUser loginUser = AppLoginHelper.getLoginUser();
|
||||
FuncType10StrobeModeRequest request = new FuncType10StrobeModeRequest();
|
||||
request.setRequestId(GenerateIdUtil.generateNumericId());
|
||||
request.setImei(deviceObj.getDeviceImei());
|
||||
@ -322,7 +337,8 @@ public class DeviceHBY100JBizService {
|
||||
log.info("HBY100J爆闪模式开启/关闭,下发设备参数:{}", request);
|
||||
mqttGateway.sendMsgToMqtt(buildMqttTopic(deviceObj.getDeviceImei()), 1, JSON.toJSONString(request));
|
||||
String content = params.getEnable() != null && params.getEnable() == 1 ? "爆闪模式开启" : "爆闪模式关闭";
|
||||
recordDeviceLog(deviceObj.getId(), deviceObj.getDeviceName(), content, content, loginUser.getUserId());
|
||||
Long userId = loginUser == null ? pcUserId : loginUser.getUserId();
|
||||
recordDeviceLog(deviceObj.getId(), deviceObj.getDeviceName(), content, content, userId);
|
||||
}
|
||||
|
||||
public void lightAdjustment(HBY100JLightAdjustmentDto params) {
|
||||
@ -334,7 +350,7 @@ public class DeviceHBY100JBizService {
|
||||
if (getDeviceStatus(deviceObj.getDeviceImei())) {
|
||||
throw new ServiceException(deviceObj.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
AppLoginUser loginUser = AppLoginHelper.getLoginUser();
|
||||
FuncType13BrightnessRequest request = new FuncType13BrightnessRequest();
|
||||
request.setRequestId(GenerateIdUtil.generateNumericId());
|
||||
request.setImei(deviceObj.getDeviceImei());
|
||||
@ -347,7 +363,8 @@ public class DeviceHBY100JBizService {
|
||||
request.setData(data);
|
||||
log.info("HBY100J灯光调节,下发设备参数:{}", request);
|
||||
mqttGateway.sendMsgToMqtt(buildMqttTopic(deviceObj.getDeviceImei()), 1, JSON.toJSONString(request));
|
||||
recordDeviceLog(deviceObj.getId(), deviceObj.getDeviceName(), "灯光调节", "灯光调节", loginUser.getUserId());
|
||||
Long userId = loginUser == null ? pcUserId : loginUser.getUserId();
|
||||
recordDeviceLog(deviceObj.getId(), deviceObj.getDeviceName(), "灯光调节", "灯光调节", userId);
|
||||
}
|
||||
|
||||
public void strobeFrequency(HBY100JStrobeFrequencyDto params) {
|
||||
@ -358,7 +375,7 @@ public class DeviceHBY100JBizService {
|
||||
if (getDeviceStatus(deviceObj.getDeviceImei())) {
|
||||
throw new ServiceException(deviceObj.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
AppLoginUser loginUser = AppLoginHelper.getLoginUser();
|
||||
FuncType11FrequencyRequest request = new FuncType11FrequencyRequest();
|
||||
request.setRequestId(GenerateIdUtil.generateNumericId());
|
||||
request.setImei(deviceObj.getDeviceImei());
|
||||
@ -369,7 +386,8 @@ public class DeviceHBY100JBizService {
|
||||
request.setData(data);
|
||||
log.info("HBY100J爆闪频率,下发设备参数:{}", request);
|
||||
mqttGateway.sendMsgToMqtt(buildMqttTopic(deviceObj.getDeviceImei()), 1, JSON.toJSONString(request));
|
||||
recordDeviceLog(deviceObj.getId(), deviceObj.getDeviceName(), "爆闪频率", "爆闪频率", loginUser.getUserId());
|
||||
Long userId = loginUser == null ? pcUserId : loginUser.getUserId();
|
||||
recordDeviceLog(deviceObj.getId(), deviceObj.getDeviceName(), "爆闪频率", "爆闪频率", userId);
|
||||
}
|
||||
|
||||
public void updateVolume(HBY100JUpdateVolumeDto params) {
|
||||
@ -380,7 +398,7 @@ public class DeviceHBY100JBizService {
|
||||
if (getDeviceStatus(deviceObj.getDeviceImei())) {
|
||||
throw new ServiceException(deviceObj.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
AppLoginUser loginUser = AppLoginHelper.getLoginUser();
|
||||
FuncType9UpdateVolumeRequest request = new FuncType9UpdateVolumeRequest();
|
||||
request.setRequestId(GenerateIdUtil.generateNumericId());
|
||||
request.setImei(deviceObj.getDeviceImei());
|
||||
@ -391,7 +409,8 @@ public class DeviceHBY100JBizService {
|
||||
request.setData(data);
|
||||
log.info("HBY100J更新音量,下发设备参数:{}", JSON.toJSONString(request));
|
||||
mqttGateway.sendMsgToMqtt(buildMqttTopic(deviceObj.getDeviceImei()), 1, JSON.toJSONString(request));
|
||||
recordDeviceLog(deviceObj.getId(), deviceObj.getDeviceName(), "更新音量", "更新音量", loginUser.getUserId());
|
||||
Long userId = loginUser == null ? pcUserId : loginUser.getUserId();
|
||||
recordDeviceLog(deviceObj.getId(), deviceObj.getDeviceName(), "更新音量", "更新音量", userId);
|
||||
}
|
||||
|
||||
public void voiceBroadcast(HBY100JVoiceBroadcastDto params) {
|
||||
@ -402,7 +421,7 @@ public class DeviceHBY100JBizService {
|
||||
if (getDeviceStatus(deviceObj.getDeviceImei())) {
|
||||
throw new ServiceException(deviceObj.getDeviceName() + ",设备已断开连接");
|
||||
}
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
AppLoginUser loginUser = AppLoginHelper.getLoginUser();
|
||||
FuncType6VoicePlayRequest request = new FuncType6VoicePlayRequest();
|
||||
request.setRequestId(GenerateIdUtil.generateNumericId());
|
||||
request.setImei(deviceObj.getDeviceImei());
|
||||
@ -413,7 +432,8 @@ public class DeviceHBY100JBizService {
|
||||
request.setData(data);
|
||||
log.info("HBY100J语音播报,下发设备参数:{}", request);
|
||||
mqttGateway.sendMsgToMqtt(buildMqttTopic(deviceObj.getDeviceImei()), 1, JSON.toJSONString(request));
|
||||
recordDeviceLog(deviceObj.getId(), deviceObj.getDeviceName(), "语音播报", "语音播报", loginUser.getUserId());
|
||||
Long userId = loginUser == null ? pcUserId : loginUser.getUserId();
|
||||
recordDeviceLog(deviceObj.getId(), deviceObj.getDeviceName(), "语音播报", "语音播报", userId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user