Ai红线分析代码框架
This commit is contained in:
202
src/main/java/com/rj/controller/RedLineRecordController.java
Normal file
202
src/main/java/com/rj/controller/RedLineRecordController.java
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
package com.rj.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.rj.entity.RedLineRecord;
|
||||||
|
import com.rj.service.IRedLineRecordService;
|
||||||
|
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.time.format.DateTimeFormatter;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 触及红线记录表前端控制器
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/redLineRecord")
|
||||||
|
@Tag(name = "触及红线记录(red_line_record)", description = "增删改查与分页")
|
||||||
|
public class RedLineRecordController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IRedLineRecordService redLineRecordService;
|
||||||
|
|
||||||
|
@PostMapping("/add")
|
||||||
|
@Operation(summary = "新增")
|
||||||
|
public ResponseEntity<Map<String, Object>> add(
|
||||||
|
@Parameter(description = "实体", required = true) @RequestBody RedLineRecord entity) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
try {
|
||||||
|
if (entity.getId() == null || entity.getId().trim().isEmpty()) {
|
||||||
|
entity.setId(UUID.randomUUID().toString());
|
||||||
|
}
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
if (entity.getCreateTime() == null) {
|
||||||
|
entity.setCreateTime(now);
|
||||||
|
}
|
||||||
|
entity.setUpdateTime(now);
|
||||||
|
boolean ok = redLineRecordService.save(entity);
|
||||||
|
if (ok) {
|
||||||
|
result.put("success", true);
|
||||||
|
result.put("message", "添加成功");
|
||||||
|
result.put("data", entity);
|
||||||
|
return ResponseEntity.ok(result);
|
||||||
|
}
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "添加失败");
|
||||||
|
return ResponseEntity.badRequest().body(result);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("red_line_record add error", e);
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "添加异常:" + e.getMessage());
|
||||||
|
return ResponseEntity.internalServerError().body(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get/{id}")
|
||||||
|
@Operation(summary = "按ID查询")
|
||||||
|
public ResponseEntity<Map<String, Object>> getById(@PathVariable String id) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
try {
|
||||||
|
RedLineRecord one = redLineRecordService.getById(id);
|
||||||
|
if (one != null) {
|
||||||
|
result.put("success", true);
|
||||||
|
result.put("message", "查询成功");
|
||||||
|
result.put("data", one);
|
||||||
|
return ResponseEntity.ok(result);
|
||||||
|
}
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "记录不存在");
|
||||||
|
return ResponseEntity.notFound().build();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("red_line_record get error, id={}", id, e);
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "查询异常:" + e.getMessage());
|
||||||
|
return ResponseEntity.internalServerError().body(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/list")
|
||||||
|
@Operation(summary = "分页查询")
|
||||||
|
public ResponseEntity<Map<String, Object>> list(
|
||||||
|
@RequestParam(defaultValue = "1") Integer current,
|
||||||
|
@RequestParam(defaultValue = "10") Integer size,
|
||||||
|
@RequestParam(required = false) String audioManagementId,
|
||||||
|
@RequestParam(required = false) String audioManagementSegmentsId,
|
||||||
|
@RequestParam(required = false) String redLineType,
|
||||||
|
@RequestParam(required = false) String reasonKeyword,
|
||||||
|
@RequestParam(required = false) String createStartTime,
|
||||||
|
@RequestParam(required = false) String createEndTime) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
try {
|
||||||
|
Page<RedLineRecord> page = new Page<>(current, size);
|
||||||
|
LambdaQueryWrapper<RedLineRecord> q = new LambdaQueryWrapper<>();
|
||||||
|
if (audioManagementId != null && !audioManagementId.trim().isEmpty()) {
|
||||||
|
q.eq(RedLineRecord::getAudioManagementId, audioManagementId);
|
||||||
|
}
|
||||||
|
if (audioManagementSegmentsId != null && !audioManagementSegmentsId.trim().isEmpty()) {
|
||||||
|
q.eq(RedLineRecord::getAudioManagementSegmentsId, audioManagementSegmentsId);
|
||||||
|
}
|
||||||
|
if (redLineType != null && !redLineType.trim().isEmpty()) {
|
||||||
|
q.eq(RedLineRecord::getRedLineType, redLineType);
|
||||||
|
}
|
||||||
|
if (reasonKeyword != null && !reasonKeyword.trim().isEmpty()) {
|
||||||
|
q.like(RedLineRecord::getReasonText, reasonKeyword);
|
||||||
|
}
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
if (createStartTime != null && !createStartTime.trim().isEmpty()) {
|
||||||
|
try {
|
||||||
|
q.ge(RedLineRecord::getCreateTime, LocalDateTime.parse(createStartTime, formatter));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "创建开始时间格式错误,请使用:yyyy-MM-dd HH:mm:ss");
|
||||||
|
return ResponseEntity.badRequest().body(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (createEndTime != null && !createEndTime.trim().isEmpty()) {
|
||||||
|
try {
|
||||||
|
q.le(RedLineRecord::getCreateTime, LocalDateTime.parse(createEndTime, formatter));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "创建结束时间格式错误,请使用:yyyy-MM-dd HH:mm:ss");
|
||||||
|
return ResponseEntity.badRequest().body(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
q.orderByDesc(RedLineRecord::getCreateTime);
|
||||||
|
Page<RedLineRecord> data = redLineRecordService.page(page, q);
|
||||||
|
result.put("success", true);
|
||||||
|
result.put("message", "查询成功");
|
||||||
|
result.put("data", data.getRecords());
|
||||||
|
result.put("total", data.getTotal());
|
||||||
|
result.put("current", data.getCurrent());
|
||||||
|
result.put("size", data.getSize());
|
||||||
|
result.put("pages", data.getPages());
|
||||||
|
return ResponseEntity.ok(result);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("red_line_record list error", e);
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "查询异常:" + e.getMessage());
|
||||||
|
return ResponseEntity.internalServerError().body(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update")
|
||||||
|
@Operation(summary = "更新")
|
||||||
|
public ResponseEntity<Map<String, Object>> update(@RequestBody RedLineRecord entity) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
try {
|
||||||
|
if (entity.getId() == null || entity.getId().trim().isEmpty()) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "ID不能为空");
|
||||||
|
return ResponseEntity.badRequest().body(result);
|
||||||
|
}
|
||||||
|
entity.setUpdateTime(LocalDateTime.now());
|
||||||
|
boolean ok = redLineRecordService.updateById(entity);
|
||||||
|
if (ok) {
|
||||||
|
result.put("success", true);
|
||||||
|
result.put("message", "更新成功");
|
||||||
|
result.put("data", redLineRecordService.getById(entity.getId()));
|
||||||
|
return ResponseEntity.ok(result);
|
||||||
|
}
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "更新失败");
|
||||||
|
return ResponseEntity.badRequest().body(result);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("red_line_record update error", e);
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "更新异常:" + e.getMessage());
|
||||||
|
return ResponseEntity.internalServerError().body(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete/{id}")
|
||||||
|
@Operation(summary = "删除")
|
||||||
|
public ResponseEntity<Map<String, Object>> delete(@PathVariable String id) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
try {
|
||||||
|
boolean ok = redLineRecordService.removeById(id);
|
||||||
|
if (ok) {
|
||||||
|
result.put("success", true);
|
||||||
|
result.put("message", "删除成功");
|
||||||
|
return ResponseEntity.ok(result);
|
||||||
|
}
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "删除失败");
|
||||||
|
return ResponseEntity.badRequest().body(result);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("red_line_record delete error", e);
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "删除异常:" + e.getMessage());
|
||||||
|
return ResponseEntity.internalServerError().body(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
53
src/main/java/com/rj/entity/RedLineRecord.java
Normal file
53
src/main/java/com/rj/entity/RedLineRecord.java
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package com.rj.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 触及红线记录(表 red_line_record)
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("red_line_record")
|
||||||
|
@Schema(description = "触及红线记录(red_line_record)")
|
||||||
|
public class RedLineRecord implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Schema(description = "主键,UUID")
|
||||||
|
@TableId("id")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Schema(description = "租户ID")
|
||||||
|
private String tenantId;
|
||||||
|
|
||||||
|
@Schema(description = "音频主表ID(audio_management.id)")
|
||||||
|
private String audioManagementId;
|
||||||
|
|
||||||
|
@Schema(description = "音频分段表ID(audio_management_segments.id)")
|
||||||
|
private String audioManagementSegmentsId;
|
||||||
|
|
||||||
|
@Schema(description = "触及的红线类型")
|
||||||
|
private String redLineType;
|
||||||
|
|
||||||
|
@Schema(description = "检查时使用的阈值(数值、比例或规则描述等)")
|
||||||
|
private String checkThreshold;
|
||||||
|
|
||||||
|
@Schema(description = "触发时对应的原始文本")
|
||||||
|
private String reasonText;
|
||||||
|
|
||||||
|
@Schema(description = "备注")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
@Schema(description = "修改时间")
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
}
|
||||||
12
src/main/java/com/rj/mapper/RedLineRecordMapper.java
Normal file
12
src/main/java/com/rj/mapper/RedLineRecordMapper.java
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package com.rj.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.rj.entity.RedLineRecord;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 触及红线记录表 Mapper
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface RedLineRecordMapper extends BaseMapper<RedLineRecord> {
|
||||||
|
}
|
||||||
10
src/main/java/com/rj/service/IRedLineRecordService.java
Normal file
10
src/main/java/com/rj/service/IRedLineRecordService.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package com.rj.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.rj.entity.RedLineRecord;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 触及红线记录服务;CRUD 与分页见 {@link IService}。
|
||||||
|
*/
|
||||||
|
public interface IRedLineRecordService extends IService<RedLineRecord> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.rj.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.rj.entity.RedLineRecord;
|
||||||
|
import com.rj.mapper.RedLineRecordMapper;
|
||||||
|
import com.rj.service.IRedLineRecordService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 触及红线记录服务实现
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class RedLineRecordServiceImpl extends ServiceImpl<RedLineRecordMapper, RedLineRecord>
|
||||||
|
implements IRedLineRecordService {
|
||||||
|
}
|
||||||
30
src/main/sql/touch_red_line.sql
Normal file
30
src/main/sql/touch_red_line.sql
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
SET NAMES utf8mb4;
|
||||||
|
SET FOREIGN_KEY_CHECKS = 0;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for red_line_record
|
||||||
|
-- 触及红线记录:关联录音主表与分段,记录类型、阈值与当时文本
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `red_line_record`;
|
||||||
|
CREATE TABLE `red_line_record` (
|
||||||
|
`id` char(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '主键,UUID',
|
||||||
|
`tenant_id` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '租户ID',
|
||||||
|
`audio_management_id` char(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '音频主表ID(audio_management.id)',
|
||||||
|
`audio_management_segments_id` char(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '音频分段表ID(audio_management_segments.id)',
|
||||||
|
`red_line_type` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '触及的红线类型',
|
||||||
|
`check_threshold` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '检查时使用的阈值(数值、比例或规则描述等)',
|
||||||
|
`reason_text` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '触发时对应的原始文本',
|
||||||
|
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注',
|
||||||
|
`create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
|
KEY `idx_tenant_id` (`tenant_id`) USING BTREE,
|
||||||
|
KEY `idx_touch_red_line_audio_id` (`audio_management_id`) USING BTREE,
|
||||||
|
KEY `idx_touch_red_line_segment_id` (`audio_management_segments_id`) USING BTREE,
|
||||||
|
KEY `idx_touch_red_line_type` (`red_line_type`) USING BTREE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='触及红线记录表' ROW_FORMAT=DYNAMIC;
|
||||||
|
|
||||||
|
SET FOREIGN_KEY_CHECKS = 1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user