diff --git a/HikariCP连接池问题分析.md b/HikariCP连接池问题分析.md index 8e16890..a01df0d 100644 --- a/HikariCP连接池问题分析.md +++ b/HikariCP连接池问题分析.md @@ -126,3 +126,6 @@ hikari: + + + diff --git a/src/main/java/com/rj/controller/TrainingItemController.java b/src/main/java/com/rj/controller/TrainingItemController.java index f6e6897..40d8d5b 100644 --- a/src/main/java/com/rj/controller/TrainingItemController.java +++ b/src/main/java/com/rj/controller/TrainingItemController.java @@ -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> getAllTrainingItemList( @Parameter(description = "父ID(精确查询)") @@ -225,20 +235,17 @@ public class TrainingItemController { @RequestParam(required = false) String createEndTime) { Map result = new HashMap<>(); try { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + LambdaQueryWrapper 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,10 +272,33 @@ public class TrainingItemController { } // 按创建时间倒序排列 - queryWrapper.orderByDesc(TrainingItem::getCreateTime); - - List trainingItemList = trainingItemService.list(queryWrapper); + queryTrainingItemWrapper.orderByDesc(TrainingItem::getCreateTime); + List trainingItemList = trainingItemService.list(queryTrainingItemWrapper); + + if (trainingItemList.size()==0){ + LambdaQueryWrapper queryMainWrapper = new LambdaQueryWrapper<>(); + queryMainWrapper.eq(TrainingMain::getId, parentId); + TrainingMain trainingMain = trainingMainService.getOne(queryMainWrapper); + + LambdaQueryWrapper 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", "查询成功"); result.put("data", trainingItemList); diff --git a/src/main/java/com/rj/controller/TrainingMainController.java b/src/main/java/com/rj/controller/TrainingMainController.java index 3de154b..22698d5 100644 --- a/src/main/java/com/rj/controller/TrainingMainController.java +++ b/src/main/java/com/rj/controller/TrainingMainController.java @@ -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> 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 result = new HashMap<>(); try { Page page = new Page<>(current, size); @@ -143,55 +135,16 @@ public class TrainingMainController { if (participantPhone != null && !participantPhone.trim().isEmpty()) { 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 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 trainingMainList = trainingMainService.list(queryWrapper); + // 隐藏场景内容,不返回给前端 + trainingMainList.forEach(item -> item.setScenario(null)); + result.put("success", true); result.put("message", "查询成功"); result.put("data", trainingMainList); diff --git a/src/main/java/com/rj/entity/TrainingItem.java b/src/main/java/com/rj/entity/TrainingItem.java index fadc568..24322f1 100644 --- a/src/main/java/com/rj/entity/TrainingItem.java +++ b/src/main/java/com/rj/entity/TrainingItem.java @@ -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; diff --git a/src/main/java/com/rj/entity/TrainingMain.java b/src/main/java/com/rj/entity/TrainingMain.java index ac50f16..42df63f 100644 --- a/src/main/java/com/rj/entity/TrainingMain.java +++ b/src/main/java/com/rj/entity/TrainingMain.java @@ -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; diff --git a/src/main/sql/training_main.sql b/src/main/sql/training_main.sql index 56d2a5b..9bb5f5f 100644 --- a/src/main/sql/training_main.sql +++ b/src/main/sql/training_main.sql @@ -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 '结束时间',