音频分段逻辑的代码架构
This commit is contained in:
@@ -0,0 +1,305 @@
|
||||
package com.rj.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.rj.entity.AudioManagementSegments;
|
||||
import com.rj.service.IAudioManagementSegmentsService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 录音分段管理表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* 对应表:audio_management_segments
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/audioManagementSegments")
|
||||
@Tag(name = "录音分段管理", description = "录音分段管理相关接口")
|
||||
@Slf4j
|
||||
public class AudioManagementSegmentsController {
|
||||
|
||||
@Autowired
|
||||
private IAudioManagementSegmentsService audioManagementSegmentsService;
|
||||
|
||||
/**
|
||||
* 新增录音分段
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
@Operation(summary = "新增录音分段", description = "添加新的录音分段信息")
|
||||
public ResponseEntity<Map<String, Object>> addSegment(
|
||||
@Parameter(description = "录音分段信息", required = true)
|
||||
@RequestBody AudioManagementSegments segment) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (segment.getCreateTime() == null) {
|
||||
segment.setCreateTime(LocalDateTime.now());
|
||||
}
|
||||
boolean success = audioManagementSegmentsService.save(segment);
|
||||
if (success) {
|
||||
result.put("success", true);
|
||||
result.put("message", "录音分段添加成功");
|
||||
result.put("data", segment);
|
||||
return ResponseEntity.ok(result);
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "录音分段添加失败");
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("录音分段添加异常:{}", e.getMessage(), e);
|
||||
result.put("success", false);
|
||||
result.put("message", "录音分段添加异常:" + e.getMessage());
|
||||
return ResponseEntity.internalServerError().body(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询录音分段
|
||||
*/
|
||||
@GetMapping("/get/{id}")
|
||||
@Operation(summary = "根据ID查询录音分段", description = "根据分段ID获取录音分段详细信息")
|
||||
public ResponseEntity<Map<String, Object>> getSegmentById(
|
||||
@Parameter(description = "分段ID", required = true)
|
||||
@PathVariable String id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
AudioManagementSegments segment = audioManagementSegmentsService.getById(id);
|
||||
if (segment != null) {
|
||||
result.put("success", true);
|
||||
result.put("message", "查询成功");
|
||||
result.put("data", segment);
|
||||
return ResponseEntity.ok(result);
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "录音分段不存在");
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("录音分段查询异常:{}", e.getMessage(), e);
|
||||
result.put("success", false);
|
||||
result.put("message", "查询异常:" + e.getMessage());
|
||||
return ResponseEntity.internalServerError().body(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询录音分段列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "分页查询录音分段列表", description = "分页查询录音分段信息列表")
|
||||
public ResponseEntity<Map<String, Object>> getSegmentList(
|
||||
@Parameter(description = "页码", example = "1")
|
||||
@RequestParam(defaultValue = "1") Integer current,
|
||||
@Parameter(description = "每页大小", example = "10")
|
||||
@RequestParam(defaultValue = "10") Integer size,
|
||||
@Parameter(description = "父录音ID")
|
||||
@RequestParam(required = false) String parentId,
|
||||
@Parameter(description = "租户ID")
|
||||
@RequestParam(required = false) String tenantId,
|
||||
@Parameter(description = "设备编号(模糊查询)")
|
||||
@RequestParam(required = false) String deviceNo,
|
||||
@Parameter(description = "销售姓名(模糊查询)")
|
||||
@RequestParam(required = false) String salesName,
|
||||
@Parameter(description = "销售电话(模糊查询)")
|
||||
@RequestParam(required = false) String salesPhone,
|
||||
@Parameter(description = "意向级别")
|
||||
@RequestParam(required = false) String intentionLevel,
|
||||
@Parameter(description = "上传状态")
|
||||
@RequestParam(required = false) String uploadStatus,
|
||||
@Parameter(description = "同步状态")
|
||||
@RequestParam(required = false) String syncStatus) {
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
Page<AudioManagementSegments> page = new Page<>(current, size);
|
||||
LambdaQueryWrapper<AudioManagementSegments> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
if (parentId != null && !parentId.trim().isEmpty()) {
|
||||
queryWrapper.eq(AudioManagementSegments::getParentId, parentId);
|
||||
}
|
||||
if (tenantId != null && !tenantId.trim().isEmpty()) {
|
||||
queryWrapper.eq(AudioManagementSegments::getTenantId, tenantId);
|
||||
}
|
||||
if (deviceNo != null && !deviceNo.trim().isEmpty()) {
|
||||
queryWrapper.like(AudioManagementSegments::getDeviceNo, deviceNo);
|
||||
}
|
||||
if (salesName != null && !salesName.trim().isEmpty()) {
|
||||
queryWrapper.like(AudioManagementSegments::getSalesName, salesName);
|
||||
}
|
||||
if (salesPhone != null && !salesPhone.trim().isEmpty()) {
|
||||
queryWrapper.like(AudioManagementSegments::getSalesPhone, salesPhone);
|
||||
}
|
||||
if (intentionLevel != null && !intentionLevel.trim().isEmpty()) {
|
||||
queryWrapper.eq(AudioManagementSegments::getIntentionLevel, intentionLevel);
|
||||
}
|
||||
if (uploadStatus != null && !uploadStatus.trim().isEmpty()) {
|
||||
queryWrapper.eq(AudioManagementSegments::getUploadStatus, uploadStatus);
|
||||
}
|
||||
if (syncStatus != null && !syncStatus.trim().isEmpty()) {
|
||||
queryWrapper.eq(AudioManagementSegments::getSyncStatus, syncStatus);
|
||||
}
|
||||
|
||||
// 按创建时间倒序排列
|
||||
queryWrapper.orderByDesc(AudioManagementSegments::getCreateTime);
|
||||
|
||||
Page<AudioManagementSegments> segmentPage = audioManagementSegmentsService.page(page, queryWrapper);
|
||||
|
||||
result.put("success", true);
|
||||
result.put("message", "查询成功");
|
||||
result.put("data", segmentPage.getRecords());
|
||||
result.put("total", segmentPage.getTotal());
|
||||
result.put("current", segmentPage.getCurrent());
|
||||
result.put("size", segmentPage.getSize());
|
||||
result.put("pages", segmentPage.getPages());
|
||||
|
||||
return ResponseEntity.ok(result);
|
||||
} catch (Exception e) {
|
||||
log.error("录音分段分页查询异常:{}", e.getMessage(), e);
|
||||
result.put("success", false);
|
||||
result.put("message", "查询异常:" + e.getMessage());
|
||||
return ResponseEntity.internalServerError().body(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据父ID查询录音分段列表(不分页)
|
||||
*/
|
||||
@GetMapping("/listByParentId")
|
||||
@Operation(summary = "根据父ID查询录音分段列表(不分页)",
|
||||
description = "根据父录音ID查询所有分段列表,不分页")
|
||||
public ResponseEntity<Map<String, Object>> listByParentId(
|
||||
@Parameter(description = "父录音ID", required = true)
|
||||
@RequestParam String parentId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
LambdaQueryWrapper<AudioManagementSegments> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(AudioManagementSegments::getParentId, parentId);
|
||||
// 通常按开始时间或段索引排序
|
||||
queryWrapper.orderByAsc(AudioManagementSegments::getStartTime);
|
||||
|
||||
List<AudioManagementSegments> list = audioManagementSegmentsService.list(queryWrapper);
|
||||
|
||||
result.put("success", true);
|
||||
result.put("message", "查询成功");
|
||||
result.put("data", list);
|
||||
result.put("count", list.size());
|
||||
return ResponseEntity.ok(result);
|
||||
} catch (Exception e) {
|
||||
log.error("根据父ID查询录音分段列表异常:{}", e.getMessage(), e);
|
||||
result.put("success", false);
|
||||
result.put("message", "查询异常:" + e.getMessage());
|
||||
return ResponseEntity.internalServerError().body(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新录音分段信息
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新录音分段信息", description = "更新录音分段详细信息")
|
||||
public ResponseEntity<Map<String, Object>> updateSegment(
|
||||
@Parameter(description = "录音分段信息", required = true)
|
||||
@RequestBody AudioManagementSegments segment) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (segment.getId() == null || segment.getId().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "分段ID不能为空");
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
|
||||
boolean success = audioManagementSegmentsService.updateById(segment);
|
||||
|
||||
if (success) {
|
||||
result.put("success", true);
|
||||
result.put("message", "录音分段信息更新成功");
|
||||
result.put("data", segment);
|
||||
return ResponseEntity.ok(result);
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "录音分段信息更新失败");
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("录音分段更新异常:{}", e.getMessage(), e);
|
||||
result.put("success", false);
|
||||
result.put("message", "更新异常:" + e.getMessage());
|
||||
return ResponseEntity.internalServerError().body(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID删除录音分段
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@Operation(summary = "删除录音分段", description = "根据分段ID删除录音分段信息")
|
||||
public ResponseEntity<Map<String, Object>> deleteSegment(
|
||||
@Parameter(description = "分段ID", required = true)
|
||||
@PathVariable String id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
boolean success = audioManagementSegmentsService.removeById(id);
|
||||
if (success) {
|
||||
result.put("success", true);
|
||||
result.put("message", "录音分段删除成功");
|
||||
return ResponseEntity.ok(result);
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "录音分段删除失败");
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("录音分段删除异常:{}", e.getMessage(), e);
|
||||
result.put("success", false);
|
||||
result.put("message", "删除异常:" + e.getMessage());
|
||||
return ResponseEntity.internalServerError().body(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除录音分段
|
||||
*/
|
||||
@DeleteMapping("/batchDelete")
|
||||
@Operation(summary = "批量删除录音分段", description = "根据分段ID列表批量删除录音分段信息")
|
||||
public ResponseEntity<Map<String, Object>> batchDeleteSegments(
|
||||
@Parameter(description = "分段ID列表", required = true)
|
||||
@RequestBody List<String> ids) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "分段ID列表不能为空");
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
|
||||
boolean success = audioManagementSegmentsService.removeByIds(ids);
|
||||
if (success) {
|
||||
result.put("success", true);
|
||||
result.put("message", "批量删除成功,共删除 " + ids.size() + " 条记录");
|
||||
return ResponseEntity.ok(result);
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "批量删除失败");
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("批量删除录音分段异常:{}", e.getMessage(), e);
|
||||
result.put("success", false);
|
||||
result.put("message", "批量删除异常:" + e.getMessage());
|
||||
return ResponseEntity.internalServerError().body(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user