音频文件上传、并可浏览器访问
This commit is contained in:
@@ -11,6 +11,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
* http://localhost:9060/swagger-ui/index.html?urls.primaryName=public-api
|
||||
* http://101.43.230.106:8180/aismartcard/aicardbackend
|
||||
*
|
||||
*
|
||||
*/
|
||||
@MapperScan("com.rj.mapper")
|
||||
@SpringBootApplication
|
||||
|
||||
@@ -31,6 +31,7 @@ public interface CstAIStreamingService {
|
||||
|
||||
// @SystemMessage(fromResource = "system.txt")
|
||||
public Flux<String> chatMemoryIdRAG(@MemoryId String memoryId, @UserMessage String message);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -88,3 +88,4 @@ public class PasswordUtil {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -72,3 +72,4 @@ public class ServiceManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,3 +171,4 @@ public class AuthController {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -310,3 +310,4 @@ public class MenuController {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -280,3 +280,4 @@ public class RoleController {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -286,3 +286,4 @@ public class UserRoleController {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -135,5 +135,24 @@ public class AudioManagement implements Serializable {
|
||||
@TableField("update_time")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@Schema(description = "音频文件路径")
|
||||
@TableField("audio_file_path")
|
||||
private String audioFilePath;
|
||||
|
||||
@Schema(description = "音频文件访问URL")
|
||||
@TableField("audio_file_url")
|
||||
private String audioFileUrl;
|
||||
|
||||
@Schema(description = "音频文件大小(字节)")
|
||||
@TableField("audio_file_size")
|
||||
private Long audioFileSize;
|
||||
|
||||
@Schema(description = "音频文件原始名称")
|
||||
@TableField("audio_file_original_name")
|
||||
private String audioFileOriginalName;
|
||||
|
||||
@Schema(description = "音频文件扩展名")
|
||||
@TableField("audio_file_extension")
|
||||
private String audioFileExtension;
|
||||
|
||||
}
|
||||
|
||||
@@ -37,3 +37,4 @@ public class LoginResponse {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -56,3 +56,4 @@ public class AudioStatisticsScheduler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,3 +19,4 @@ public interface IMenuService extends IService<Menu> {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -19,3 +19,4 @@ public interface IRoleService extends IService<Role> {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -19,3 +19,4 @@ public interface IUserRoleService extends IService<UserRole> {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -23,3 +23,4 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -23,3 +23,4 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -23,3 +23,4 @@ public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> i
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -9,3 +9,4 @@
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
||||
|
||||
@@ -24,3 +24,4 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user