陪练场景下每次只出一道题
This commit is contained in:
@@ -126,3 +126,6 @@ hikari:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,11 +2,16 @@ package com.rj.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.rj.entity.KnowledgeBase;
|
||||
import com.rj.entity.TrainingItem;
|
||||
import com.rj.entity.TrainingMain;
|
||||
import com.rj.service.IKnowledgeBaseService;
|
||||
import com.rj.service.ITrainingItemService;
|
||||
import com.rj.service.ITrainingMainService;
|
||||
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.*;
|
||||
@@ -26,6 +31,7 @@ import java.util.UUID;
|
||||
* @author system
|
||||
* @since 2025-01-XX
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/trainingItem")
|
||||
@Tag(name = "陪练子表管理", description = "陪练子表相关接口")
|
||||
@@ -204,11 +210,15 @@ public class TrainingItemController {
|
||||
return ResponseEntity.internalServerError().body(result);
|
||||
}
|
||||
}
|
||||
@Autowired
|
||||
private IKnowledgeBaseService knowledgeBaseService;
|
||||
@Autowired
|
||||
private ITrainingMainService trainingMainService;
|
||||
|
||||
/**
|
||||
* 按条件不分页查询陪练子表列表
|
||||
*/
|
||||
@GetMapping("/listAll")
|
||||
@PostMapping("/listAll")
|
||||
@Operation(summary = "按条件不分页查询陪练子表列表", description = "按条件查询所有陪练子表信息列表(不分页)")
|
||||
public ResponseEntity<Map<String, Object>> getAllTrainingItemList(
|
||||
@Parameter(description = "父ID(精确查询)")
|
||||
@@ -225,20 +235,17 @@ public class TrainingItemController {
|
||||
@RequestParam(required = false) String createEndTime) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
LambdaQueryWrapper<TrainingItem> queryWrapper = new LambdaQueryWrapper<>();
|
||||
LambdaQueryWrapper<TrainingItem> queryTrainingItemWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
// 添加查询条件
|
||||
if (parentId != null && !parentId.trim().isEmpty()) {
|
||||
queryWrapper.eq(TrainingItem::getParentId, parentId);
|
||||
}
|
||||
if (tenantId != null && !tenantId.trim().isEmpty()) {
|
||||
queryWrapper.eq(TrainingItem::getTenantId, tenantId);
|
||||
queryTrainingItemWrapper.eq(TrainingItem::getParentId, parentId);
|
||||
}
|
||||
if (question != null && !question.trim().isEmpty()) {
|
||||
queryWrapper.like(TrainingItem::getQuestion, question);
|
||||
queryTrainingItemWrapper.like(TrainingItem::getQuestion, question);
|
||||
}
|
||||
if (answer != null && !answer.trim().isEmpty()) {
|
||||
queryWrapper.like(TrainingItem::getAnswer, answer);
|
||||
queryTrainingItemWrapper.like(TrainingItem::getAnswer, answer);
|
||||
}
|
||||
|
||||
// 添加时间范围查询条件
|
||||
@@ -246,7 +253,7 @@ public class TrainingItemController {
|
||||
if (createStartTime != null && !createStartTime.trim().isEmpty()) {
|
||||
try {
|
||||
LocalDateTime startTime = LocalDateTime.parse(createStartTime, formatter);
|
||||
queryWrapper.ge(TrainingItem::getCreateTime, startTime);
|
||||
queryTrainingItemWrapper.ge(TrainingItem::getCreateTime, startTime);
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "创建开始时间格式错误,请使用格式:yyyy-MM-dd HH:mm:ss");
|
||||
@@ -256,7 +263,7 @@ public class TrainingItemController {
|
||||
if (createEndTime != null && !createEndTime.trim().isEmpty()) {
|
||||
try {
|
||||
LocalDateTime endTime = LocalDateTime.parse(createEndTime, formatter);
|
||||
queryWrapper.le(TrainingItem::getCreateTime, endTime);
|
||||
queryTrainingItemWrapper.le(TrainingItem::getCreateTime, endTime);
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "创建结束时间格式错误,请使用格式:yyyy-MM-dd HH:mm:ss");
|
||||
@@ -265,9 +272,32 @@ public class TrainingItemController {
|
||||
}
|
||||
|
||||
// 按创建时间倒序排列
|
||||
queryWrapper.orderByDesc(TrainingItem::getCreateTime);
|
||||
queryTrainingItemWrapper.orderByDesc(TrainingItem::getCreateTime);
|
||||
|
||||
List<TrainingItem> trainingItemList = trainingItemService.list(queryWrapper);
|
||||
List<TrainingItem> trainingItemList = trainingItemService.list(queryTrainingItemWrapper);
|
||||
|
||||
if (trainingItemList.size()==0){
|
||||
LambdaQueryWrapper<TrainingMain> queryMainWrapper = new LambdaQueryWrapper<>();
|
||||
queryMainWrapper.eq(TrainingMain::getId, parentId);
|
||||
TrainingMain trainingMain = trainingMainService.getOne(queryMainWrapper);
|
||||
|
||||
LambdaQueryWrapper<KnowledgeBase> queryScenarioWrapper = new LambdaQueryWrapper<>();
|
||||
queryScenarioWrapper.eq(KnowledgeBase::getId, trainingMain.getScenarioId());
|
||||
KnowledgeBase one1 = knowledgeBaseService.getOne(queryScenarioWrapper);
|
||||
log.info(one1.getRemark());
|
||||
String[] split = one1.getRemark().split(",");
|
||||
for (String s : split) {
|
||||
log.info(s);
|
||||
TrainingItem item = new TrainingItem();
|
||||
item.setQuestion(s);
|
||||
item.setParentId(trainingMain.getId());
|
||||
item.setTenantId(trainingMain.getTenantId());
|
||||
trainingItemService.save(item);
|
||||
}
|
||||
}
|
||||
// 每次只查询一条记录
|
||||
queryTrainingItemWrapper.last("LIMIT 1");
|
||||
trainingItemList = trainingItemService.list(queryTrainingItemWrapper);
|
||||
|
||||
result.put("success", true);
|
||||
result.put("message", "查询成功");
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.rj.controller;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.rj.entity.TrainingMain;
|
||||
import com.rj.service.IKnowledgeBaseService;
|
||||
import com.rj.service.ITrainingMainService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -47,7 +48,7 @@ public class TrainingMainController {
|
||||
if (trainingMain.getId() == null || trainingMain.getId().trim().isEmpty()) {
|
||||
trainingMain.setId(UUID.randomUUID().toString());
|
||||
}
|
||||
trainingMain.setCreateTime(LocalDateTime.now());
|
||||
// trainingMain.setCreateTime(LocalDateTime.now());
|
||||
boolean success = trainingMainService.save(trainingMain);
|
||||
if (success) {
|
||||
result.put("success", true);
|
||||
@@ -97,14 +98,13 @@ public class TrainingMainController {
|
||||
/**
|
||||
* 分页查询陪练主表列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "分页查询陪练主表列表", description = "分页查询陪练主表信息列表")
|
||||
public ResponseEntity<Map<String, Object>> getTrainingMainList(
|
||||
@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 tenantId,
|
||||
@Parameter(description = "陪练标题(模糊查询)")
|
||||
@RequestParam(required = false) String title,
|
||||
@@ -113,15 +113,7 @@ public class TrainingMainController {
|
||||
@Parameter(description = "参与人姓名(模糊查询)")
|
||||
@RequestParam(required = false) String participantName,
|
||||
@Parameter(description = "参与人电话(模糊查询)")
|
||||
@RequestParam(required = false) String participantPhone,
|
||||
@Parameter(description = "创建开始时间", example = "2025-01-01 00:00:00")
|
||||
@RequestParam(required = false) String createStartTime,
|
||||
@Parameter(description = "创建结束时间", example = "2025-12-31 23:59:59")
|
||||
@RequestParam(required = false) String createEndTime,
|
||||
@Parameter(description = "结束开始时间", example = "2025-01-01 00:00:00")
|
||||
@RequestParam(required = false) String endStartTime,
|
||||
@Parameter(description = "结束结束时间", example = "2025-12-31 23:59:59")
|
||||
@RequestParam(required = false) String endEndTime) {
|
||||
@RequestParam(required = false) String participantPhone ) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
Page<TrainingMain> page = new Page<>(current, size);
|
||||
@@ -144,54 +136,15 @@ public class TrainingMainController {
|
||||
queryWrapper.like(TrainingMain::getParticipantPhone, participantPhone);
|
||||
}
|
||||
|
||||
// 添加时间范围查询条件
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
if (createStartTime != null && !createStartTime.trim().isEmpty()) {
|
||||
try {
|
||||
LocalDateTime startTime = LocalDateTime.parse(createStartTime, formatter);
|
||||
queryWrapper.ge(TrainingMain::getCreateTime, startTime);
|
||||
} catch (Exception e) {
|
||||
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 {
|
||||
LocalDateTime endTime = LocalDateTime.parse(createEndTime, formatter);
|
||||
queryWrapper.le(TrainingMain::getCreateTime, endTime);
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "创建结束时间格式错误,请使用格式:yyyy-MM-dd HH:mm:ss");
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
}
|
||||
if (endStartTime != null && !endStartTime.trim().isEmpty()) {
|
||||
try {
|
||||
LocalDateTime startTime = LocalDateTime.parse(endStartTime, formatter);
|
||||
queryWrapper.ge(TrainingMain::getEndTime, startTime);
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "结束开始时间格式错误,请使用格式:yyyy-MM-dd HH:mm:ss");
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
}
|
||||
if (endEndTime != null && !endEndTime.trim().isEmpty()) {
|
||||
try {
|
||||
LocalDateTime endTime = LocalDateTime.parse(endEndTime, formatter);
|
||||
queryWrapper.le(TrainingMain::getEndTime, endTime);
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "结束结束时间格式错误,请使用格式:yyyy-MM-dd HH:mm:ss");
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
}
|
||||
|
||||
// 按创建时间倒序排列
|
||||
queryWrapper.orderByDesc(TrainingMain::getCreateTime);
|
||||
|
||||
Page<TrainingMain> trainingMainPage = trainingMainService.page(page, queryWrapper);
|
||||
|
||||
// 隐藏场景内容,不返回给前端
|
||||
trainingMainPage.getRecords().forEach(item -> item.setScenario(null));
|
||||
|
||||
result.put("success", true);
|
||||
result.put("message", "查询成功");
|
||||
result.put("data", trainingMainPage.getRecords());
|
||||
@@ -301,6 +254,9 @@ public class TrainingMainController {
|
||||
|
||||
List<TrainingMain> trainingMainList = trainingMainService.list(queryWrapper);
|
||||
|
||||
// 隐藏场景内容,不返回给前端
|
||||
trainingMainList.forEach(item -> item.setScenario(null));
|
||||
|
||||
result.put("success", true);
|
||||
result.put("message", "查询成功");
|
||||
result.put("data", trainingMainList);
|
||||
|
||||
@@ -45,6 +45,11 @@ public class TrainingItem implements Serializable {
|
||||
@TableField("answer")
|
||||
private String answer;
|
||||
|
||||
@Schema(description = "AI答案")
|
||||
@TableField("ai_answer")
|
||||
private String AiAnswer;
|
||||
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@TableField("create_time")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@@ -33,6 +33,10 @@ public class TrainingMain implements Serializable {
|
||||
@TableField("tenant_id")
|
||||
private String tenantId;
|
||||
|
||||
@Schema(description = "场景ID")
|
||||
@TableField("scenario_id")
|
||||
private String scenarioId;
|
||||
|
||||
@Schema(description = "陪练标题")
|
||||
@TableField("title")
|
||||
private String title;
|
||||
|
||||
@@ -20,8 +20,9 @@ DROP TABLE IF EXISTS `training_main`;
|
||||
CREATE TABLE `training_main` (
|
||||
`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',
|
||||
`scenario_id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '场景ID',
|
||||
`title` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '陪练标题',
|
||||
`scenario` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '陪练的场景',
|
||||
`scenario` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '陪练的场景',
|
||||
`participant_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '参与人姓名',
|
||||
`participant_phone` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '参与人电话',
|
||||
`end_time` datetime NULL DEFAULT NULL COMMENT '结束时间',
|
||||
|
||||
Reference in New Issue
Block a user