音频文本分析详情页面的代码架构完成

This commit is contained in:
ZLI263
2025-11-18 15:12:00 +08:00
parent 9ef5d55487
commit 45d4f668d3
14 changed files with 364 additions and 9 deletions

View File

@@ -0,0 +1,183 @@
package com.rj.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rj.entity.AudioTextAnalysisFurniture;
import com.rj.service.IAudioTextAnalysisFurnitureService;
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.format.annotation.DateTimeFormat;
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;
import java.util.UUID;
/**
* 音频文本-家具意向分析 控制器
*/
@RestController
@RequestMapping("/api/audioTextAnalysisFurniture")
@Tag(name = "语音分析-家具意向", description = "音频文本家具意向分析接口")
@Slf4j
public class AudioTextAnalysisFurnitureController {
@Autowired
private IAudioTextAnalysisFurnitureService furnitureService;
@PostMapping("/add")
@Operation(summary = "新增记录", description = "新增一条家具意向分析记录")
public ResponseEntity<Map<String, Object>> add(@RequestBody AudioTextAnalysisFurniture furniture) {
Map<String, Object> result = new HashMap<>();
try {
if (furniture.getId() == null || furniture.getId().trim().isEmpty()) {
furniture.setId(UUID.randomUUID().toString());
}
LocalDateTime now = LocalDateTime.now();
furniture.setCreatedAt(now);
furniture.setUpdatedAt(now);
boolean success = furnitureService.save(furniture);
result.put("success", success);
result.put("data", furniture);
result.put("message", success ? "新增成功" : "新增失败");
return success ? ResponseEntity.ok(result) : ResponseEntity.badRequest().body(result);
} catch (Exception e) {
log.error("新增家具意向分析失败", 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>> update(@RequestBody AudioTextAnalysisFurniture furniture) {
Map<String, Object> result = new HashMap<>();
try {
if (furniture.getId() == null || furniture.getId().trim().isEmpty()) {
result.put("success", false);
result.put("message", "ID不能为空");
return ResponseEntity.badRequest().body(result);
}
furniture.setUpdatedAt(LocalDateTime.now());
boolean success = furnitureService.updateById(furniture);
result.put("success", success);
result.put("message", success ? "更新成功" : "更新失败");
result.put("data", furniture);
return success ? ResponseEntity.ok(result) : ResponseEntity.badRequest().body(result);
} catch (Exception e) {
log.error("更新家具意向分析失败", e);
result.put("success", false);
result.put("message", "更新异常:" + e.getMessage());
return ResponseEntity.internalServerError().body(result);
}
}
@DeleteMapping("/delete/{id}")
@Operation(summary = "删除记录", description = "根据ID删除家具意向分析记录")
public ResponseEntity<Map<String, Object>> delete(@PathVariable String id) {
Map<String, Object> result = new HashMap<>();
try {
boolean success = furnitureService.removeById(id);
result.put("success", success);
result.put("message", success ? "删除成功" : "删除失败");
return success ? ResponseEntity.ok(result) : ResponseEntity.badRequest().body(result);
} catch (Exception e) {
log.error("删除家具意向分析失败", e);
result.put("success", false);
result.put("message", "删除异常:" + e.getMessage());
return ResponseEntity.internalServerError().body(result);
}
}
@GetMapping("/page")
@Operation(summary = "分页查询", description = "根据条件分页查询家具意向分析记录")
public ResponseEntity<Map<String, Object>> page(
@Parameter(description = "页码", example = "1")
@RequestParam(defaultValue = "1") Integer current,
@Parameter(description = "每页大小", example = "10")
@RequestParam(defaultValue = "10") Integer size,
@Parameter(description = "父ID/音频管理ID") @RequestParam(required = false) String parentId,
@Parameter(description = "客户类型") @RequestParam(required = false) String customerType,
@Parameter(description = "装修风格") @RequestParam(required = false) String decorationStyle,
@Parameter(description = "所属人电话") @RequestParam(required = false) String ownerPhone,
@Parameter(description = "客户电话") @RequestParam(required = false) String customerPhone,
@Parameter(description = "创建开始时间", example = "2025-01-01 00:00:00")
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime createdStart,
@Parameter(description = "创建结束时间", example = "2025-12-31 23:59:59")
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime createdEnd) {
Map<String, Object> result = new HashMap<>();
try {
Page<AudioTextAnalysisFurniture> page = new Page<>(current, size);
LambdaQueryWrapper<AudioTextAnalysisFurniture> wrapper = new LambdaQueryWrapper<>();
if (parentId != null && !parentId.trim().isEmpty()) {
wrapper.eq(AudioTextAnalysisFurniture::getParentId, parentId);
}
if (customerType != null && !customerType.trim().isEmpty()) {
wrapper.eq(AudioTextAnalysisFurniture::getCustomerType, customerType);
}
if (decorationStyle != null && !decorationStyle.trim().isEmpty()) {
wrapper.like(AudioTextAnalysisFurniture::getDecorationStyle, decorationStyle);
}
if (ownerPhone != null && !ownerPhone.trim().isEmpty()) {
wrapper.like(AudioTextAnalysisFurniture::getOwnerPhone, ownerPhone);
}
if (customerPhone != null && !customerPhone.trim().isEmpty()) {
wrapper.like(AudioTextAnalysisFurniture::getCustomerPhone, customerPhone);
}
if (createdStart != null) {
wrapper.ge(AudioTextAnalysisFurniture::getCreatedAt, createdStart);
}
if (createdEnd != null) {
wrapper.le(AudioTextAnalysisFurniture::getCreatedAt, createdEnd);
}
wrapper.orderByDesc(AudioTextAnalysisFurniture::getUpdatedAt);
Page<AudioTextAnalysisFurniture> dataPage = furnitureService.page(page, wrapper);
result.put("success", true);
result.put("message", "查询成功");
result.put("data", dataPage.getRecords());
result.put("total", dataPage.getTotal());
result.put("current", dataPage.getCurrent());
result.put("size", dataPage.getSize());
result.put("pages", dataPage.getPages());
return ResponseEntity.ok(result);
} catch (Exception e) {
log.error("分页查询家具意向分析失败", e);
result.put("success", false);
result.put("message", "查询异常:" + e.getMessage());
return ResponseEntity.internalServerError().body(result);
}
}
@GetMapping("/byParentId")
@Operation(summary = "根据parentId查询", description = "根据父ID查询所有家具意向分析记录")
public ResponseEntity<Map<String, Object>> listByParentId(
@Parameter(description = "父ID/音频管理ID", required = true)
@RequestParam String parentId) {
Map<String, Object> result = new HashMap<>();
try {
LambdaQueryWrapper<AudioTextAnalysisFurniture> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(AudioTextAnalysisFurniture::getParentId, parentId)
.orderByDesc(AudioTextAnalysisFurniture::getUpdatedAt);
List<AudioTextAnalysisFurniture> list = furnitureService.list(wrapper);
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("根据parentId查询家具意向分析失败", e);
result.put("success", false);
result.put("message", "查询异常:" + e.getMessage());
return ResponseEntity.internalServerError().body(result);
}
}
}