|
|
|
|
@@ -7,6 +7,7 @@ import com.rj.entity.AudioManagement;
|
|
|
|
|
import com.rj.entity.CustomerManagement;
|
|
|
|
|
import com.rj.entity.SalesManagement;
|
|
|
|
|
import com.rj.service.IAudioManagementService;
|
|
|
|
|
import com.rj.service.IFileUploadService;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
@@ -20,6 +21,7 @@ import java.time.LocalDateTime;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <p>
|
|
|
|
|
@@ -38,6 +40,9 @@ public class AudioManagementController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private IAudioManagementService audioManagementService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IFileUploadService fileUploadService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增录音
|
|
|
|
|
*/
|
|
|
|
|
@@ -48,6 +53,11 @@ public class AudioManagementController {
|
|
|
|
|
@RequestBody AudioManagement audioManagement) {
|
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
|
|
try {
|
|
|
|
|
// 生成录音ID
|
|
|
|
|
if (audioManagement.getId() == null || audioManagement.getId().trim().isEmpty()) {
|
|
|
|
|
audioManagement.setId(UUID.randomUUID().toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
audioManagement.setCreateTime(LocalDateTime.now());
|
|
|
|
|
audioManagement.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
boolean success = audioManagementService.save(audioManagement);
|
|
|
|
|
@@ -80,9 +90,19 @@ public class AudioManagementController {
|
|
|
|
|
try {
|
|
|
|
|
AudioManagement audio = audioManagementService.getById(id);
|
|
|
|
|
if (audio != null) {
|
|
|
|
|
// 检查音频文件是否存在
|
|
|
|
|
boolean fileExists = fileUploadService.audioFileExists(id);
|
|
|
|
|
|
|
|
|
|
Map<String, Object> audioInfo = new HashMap<>();
|
|
|
|
|
audioInfo.put("audio", audio);
|
|
|
|
|
audioInfo.put("fileExists", fileExists);
|
|
|
|
|
audioInfo.put("fileUrl", audio.getAudioFileUrl());
|
|
|
|
|
audioInfo.put("fileSize", audio.getAudioFileSize());
|
|
|
|
|
audioInfo.put("originalFileName", audio.getAudioFileOriginalName());
|
|
|
|
|
|
|
|
|
|
result.put("success", true);
|
|
|
|
|
result.put("message", "查询成功");
|
|
|
|
|
result.put("data", audio);
|
|
|
|
|
result.put("data", audioInfo);
|
|
|
|
|
return ResponseEntity.ok(result);
|
|
|
|
|
} else {
|
|
|
|
|
result.put("success", false);
|
|
|
|
|
@@ -182,6 +202,10 @@ public class AudioManagementController {
|
|
|
|
|
audio.setSalesName(saleNameMap.getOrDefault(audio.getSalesId(), ""));
|
|
|
|
|
audio.setProjectName(projectNameMap.getOrDefault(audio.getProjectId(), ""));
|
|
|
|
|
// audio.setCustomerName(customerNameMap.getOrDefault(audio.getCustomerId(), ""));
|
|
|
|
|
|
|
|
|
|
// 检查音频文件是否存在
|
|
|
|
|
boolean fileExists = fileUploadService.audioFileExists(audio.getId());
|
|
|
|
|
// 注意:这里不需要设置,因为实体类中已经有这些字段了
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
result.put("success", true);
|
|
|
|
|
@@ -321,4 +345,97 @@ public class AudioManagementController {
|
|
|
|
|
return ResponseEntity.internalServerError().body(result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取录音的音频文件信息
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/{id}/audio-info")
|
|
|
|
|
@Operation(summary = "获取录音的音频文件信息", description = "根据录音ID获取音频文件信息")
|
|
|
|
|
public ResponseEntity<Map<String, Object>> getAudioFileInfo(
|
|
|
|
|
@Parameter(description = "录音ID", required = true)
|
|
|
|
|
@PathVariable String id) {
|
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
|
|
try {
|
|
|
|
|
// 检查录音是否存在
|
|
|
|
|
AudioManagement audio = audioManagementService.getById(id);
|
|
|
|
|
if (audio == null) {
|
|
|
|
|
result.put("success", false);
|
|
|
|
|
result.put("message", "录音不存在");
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查音频文件是否存在
|
|
|
|
|
boolean fileExists = fileUploadService.audioFileExists(id);
|
|
|
|
|
String fileUrl = null;
|
|
|
|
|
|
|
|
|
|
if (fileExists) {
|
|
|
|
|
fileUrl = fileUploadService.getAudioFileUrl(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, Object> audioInfo = new HashMap<>();
|
|
|
|
|
audioInfo.put("audioId", id);
|
|
|
|
|
audioInfo.put("fileExists", fileExists);
|
|
|
|
|
audioInfo.put("fileUrl", fileUrl);
|
|
|
|
|
audioInfo.put("audioInfo", audio);
|
|
|
|
|
|
|
|
|
|
result.put("success", true);
|
|
|
|
|
result.put("message", "获取成功");
|
|
|
|
|
result.put("data", audioInfo);
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(result);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
result.put("success", false);
|
|
|
|
|
result.put("message", "获取音频文件信息异常:" + e.getMessage());
|
|
|
|
|
return ResponseEntity.internalServerError().body(result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除录音及其音频文件
|
|
|
|
|
*/
|
|
|
|
|
@DeleteMapping("/deleteWithFile/{id}")
|
|
|
|
|
@Operation(summary = "删除录音及其音频文件", description = "根据录音ID删除录音信息及其关联的音频文件")
|
|
|
|
|
public ResponseEntity<Map<String, Object>> deleteAudioWithFile(
|
|
|
|
|
@Parameter(description = "录音ID", required = true)
|
|
|
|
|
@PathVariable String id) {
|
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
|
|
try {
|
|
|
|
|
// 获取录音记录
|
|
|
|
|
AudioManagement audio = audioManagementService.getById(id);
|
|
|
|
|
if (audio == null) {
|
|
|
|
|
result.put("success", false);
|
|
|
|
|
result.put("message", "录音记录不存在");
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 先删除音频文件
|
|
|
|
|
boolean fileDeleted = fileUploadService.deleteAudioFile(id);
|
|
|
|
|
|
|
|
|
|
// 清空录音记录中的文件信息
|
|
|
|
|
audio.setAudioFilePath(null);
|
|
|
|
|
audio.setAudioFileUrl(null);
|
|
|
|
|
audio.setAudioFileSize(null);
|
|
|
|
|
audio.setAudioFileOriginalName(null);
|
|
|
|
|
audio.setAudioFileExtension(null);
|
|
|
|
|
audio.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
|
|
|
|
|
boolean recordUpdated = audioManagementService.updateById(audio);
|
|
|
|
|
|
|
|
|
|
if (recordUpdated) {
|
|
|
|
|
result.put("success", true);
|
|
|
|
|
result.put("message", "录音及其音频文件删除成功");
|
|
|
|
|
result.put("fileDeleted", fileDeleted);
|
|
|
|
|
result.put("recordUpdated", recordUpdated);
|
|
|
|
|
return ResponseEntity.ok(result);
|
|
|
|
|
} else {
|
|
|
|
|
result.put("success", false);
|
|
|
|
|
result.put("message", "录音记录更新失败");
|
|
|
|
|
return ResponseEntity.badRequest().body(result);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
result.put("success", false);
|
|
|
|
|
result.put("message", "删除异常:" + e.getMessage());
|
|
|
|
|
return ResponseEntity.internalServerError().body(result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|