From db761cbe2496cd35675429f4de99bf9c3ea63b4b Mon Sep 17 00:00:00 2001 From: zhonghua1 Date: Sat, 27 Dec 2025 17:17:35 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=AA=E7=BB=83=E4=BB=A3=E7=A0=81=E6=A1=86?= =?UTF-8?q?=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rj/controller/TrainingItemController.java | 380 ++++++++++++++++ .../rj/controller/TrainingMainController.java | 412 ++++++++++++++++++ src/main/java/com/rj/entity/TrainingItem.java | 52 +++ src/main/java/com/rj/entity/TrainingMain.java | 60 +++ .../com/rj/mapper/TrainingItemMapper.java | 17 + .../com/rj/mapper/TrainingMainMapper.java | 17 + .../com/rj/service/ITrainingItemService.java | 17 + .../com/rj/service/ITrainingMainService.java | 17 + .../service/impl/TrainingItemServiceImpl.java | 21 + .../service/impl/TrainingMainServiceImpl.java | 21 + src/main/sql/training_item.sql | 33 ++ src/main/sql/training_main.sql | 35 ++ src/main/sql/陪练.log | 2 +- 13 files changed, 1083 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/rj/controller/TrainingItemController.java create mode 100644 src/main/java/com/rj/controller/TrainingMainController.java create mode 100644 src/main/java/com/rj/entity/TrainingItem.java create mode 100644 src/main/java/com/rj/entity/TrainingMain.java create mode 100644 src/main/java/com/rj/mapper/TrainingItemMapper.java create mode 100644 src/main/java/com/rj/mapper/TrainingMainMapper.java create mode 100644 src/main/java/com/rj/service/ITrainingItemService.java create mode 100644 src/main/java/com/rj/service/ITrainingMainService.java create mode 100644 src/main/java/com/rj/service/impl/TrainingItemServiceImpl.java create mode 100644 src/main/java/com/rj/service/impl/TrainingMainServiceImpl.java create mode 100644 src/main/sql/training_item.sql create mode 100644 src/main/sql/training_main.sql diff --git a/src/main/java/com/rj/controller/TrainingItemController.java b/src/main/java/com/rj/controller/TrainingItemController.java new file mode 100644 index 0000000..f6e6897 --- /dev/null +++ b/src/main/java/com/rj/controller/TrainingItemController.java @@ -0,0 +1,380 @@ +package com.rj.controller; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.rj.entity.TrainingItem; +import com.rj.service.ITrainingItemService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +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.List; +import java.util.Map; +import java.util.UUID; + +/** + *

+ * 陪练子表 前端控制器 + *

+ * + * @author system + * @since 2025-01-XX + */ +@RestController +@RequestMapping("/api/trainingItem") +@Tag(name = "陪练子表管理", description = "陪练子表相关接口") +public class TrainingItemController { + + @Autowired + private ITrainingItemService trainingItemService; + + /** + * 新增陪练子表记录 + */ + @PostMapping("/add") + @Operation(summary = "新增陪练子表记录", description = "添加新的陪练子表记录") + public ResponseEntity> addTrainingItem( + @Parameter(description = "陪练子表信息", required = true) + @RequestBody TrainingItem trainingItem) { + Map result = new HashMap<>(); + try { + if (trainingItem.getId() == null || trainingItem.getId().trim().isEmpty()) { + trainingItem.setId(UUID.randomUUID().toString()); + } + trainingItem.setCreateTime(LocalDateTime.now()); + boolean success = trainingItemService.save(trainingItem); + if (success) { + result.put("success", true); + result.put("message", "陪练子表记录添加成功"); + result.put("data", trainingItem); + return ResponseEntity.ok(result); + } else { + result.put("success", false); + result.put("message", "陪练子表记录添加失败"); + return ResponseEntity.badRequest().body(result); + } + } catch (Exception 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> getTrainingItemById( + @Parameter(description = "陪练子表ID", required = true) + @PathVariable String id) { + Map result = new HashMap<>(); + try { + TrainingItem trainingItem = trainingItemService.getById(id); + if (trainingItem != null) { + result.put("success", true); + result.put("message", "查询成功"); + result.put("data", trainingItem); + return ResponseEntity.ok(result); + } else { + result.put("success", false); + result.put("message", "陪练子表记录不存在"); + return ResponseEntity.notFound().build(); + } + } catch (Exception e) { + result.put("success", false); + result.put("message", "查询异常:" + e.getMessage()); + return ResponseEntity.internalServerError().body(result); + } + } + + /** + * 根据父ID查询陪练子表列表 + */ + @GetMapping("/getByParentId") + @Operation(summary = "根据父ID查询陪练子表", description = "根据父ID查询子陪练子表列表") + public ResponseEntity> getTrainingItemsByParentId( + @Parameter(description = "父ID", required = true) + @RequestParam String parentId) { + Map result = new HashMap<>(); + try { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(TrainingItem::getParentId, parentId); + queryWrapper.orderByDesc(TrainingItem::getCreateTime); + List trainingItems = trainingItemService.list(queryWrapper); + result.put("success", true); + result.put("message", "查询成功"); + result.put("data", trainingItems); + result.put("count", trainingItems.size()); + return ResponseEntity.ok(result); + } catch (Exception e) { + result.put("success", false); + result.put("message", "查询异常:" + e.getMessage()); + return ResponseEntity.internalServerError().body(result); + } + } + + /** + * 分页查询陪练子表列表 + */ + @GetMapping("/list") + @Operation(summary = "分页查询陪练子表列表", description = "分页查询陪练子表信息列表") + public ResponseEntity> getTrainingItemList( + @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 question, + @Parameter(description = "题目答案(模糊查询)") + @RequestParam(required = false) String answer, + @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) { + Map result = new HashMap<>(); + try { + Page page = new Page<>(current, size); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + + // 添加查询条件 + if (parentId != null && !parentId.trim().isEmpty()) { + queryWrapper.eq(TrainingItem::getParentId, parentId); + } + if (tenantId != null && !tenantId.trim().isEmpty()) { + queryWrapper.eq(TrainingItem::getTenantId, tenantId); + } + if (question != null && !question.trim().isEmpty()) { + queryWrapper.like(TrainingItem::getQuestion, question); + } + if (answer != null && !answer.trim().isEmpty()) { + queryWrapper.like(TrainingItem::getAnswer, answer); + } + + // 添加时间范围查询条件 + 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(TrainingItem::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(TrainingItem::getCreateTime, endTime); + } catch (Exception e) { + result.put("success", false); + result.put("message", "创建结束时间格式错误,请使用格式:yyyy-MM-dd HH:mm:ss"); + return ResponseEntity.badRequest().body(result); + } + } + + // 按创建时间倒序排列 + queryWrapper.orderByDesc(TrainingItem::getCreateTime); + + Page trainingItemPage = trainingItemService.page(page, queryWrapper); + + result.put("success", true); + result.put("message", "查询成功"); + result.put("data", trainingItemPage.getRecords()); + result.put("total", trainingItemPage.getTotal()); + result.put("current", trainingItemPage.getCurrent()); + result.put("size", trainingItemPage.getSize()); + result.put("pages", trainingItemPage.getPages()); + + return ResponseEntity.ok(result); + } catch (Exception e) { + result.put("success", false); + result.put("message", "查询异常:" + e.getMessage()); + return ResponseEntity.internalServerError().body(result); + } + } + + /** + * 按条件不分页查询陪练子表列表 + */ + @GetMapping("/listAll") + @Operation(summary = "按条件不分页查询陪练子表列表", description = "按条件查询所有陪练子表信息列表(不分页)") + public ResponseEntity> getAllTrainingItemList( + @Parameter(description = "父ID(精确查询)") + @RequestParam(required = false) String parentId, + @Parameter(description = "租户ID(精确查询)") + @RequestParam(required = false) String tenantId, + @Parameter(description = "题目(模糊查询)") + @RequestParam(required = false) String question, + @Parameter(description = "题目答案(模糊查询)") + @RequestParam(required = false) String answer, + @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) { + Map result = new HashMap<>(); + try { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + + // 添加查询条件 + if (parentId != null && !parentId.trim().isEmpty()) { + queryWrapper.eq(TrainingItem::getParentId, parentId); + } + if (tenantId != null && !tenantId.trim().isEmpty()) { + queryWrapper.eq(TrainingItem::getTenantId, tenantId); + } + if (question != null && !question.trim().isEmpty()) { + queryWrapper.like(TrainingItem::getQuestion, question); + } + if (answer != null && !answer.trim().isEmpty()) { + queryWrapper.like(TrainingItem::getAnswer, answer); + } + + // 添加时间范围查询条件 + 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(TrainingItem::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(TrainingItem::getCreateTime, endTime); + } catch (Exception e) { + result.put("success", false); + result.put("message", "创建结束时间格式错误,请使用格式:yyyy-MM-dd HH:mm:ss"); + return ResponseEntity.badRequest().body(result); + } + } + + // 按创建时间倒序排列 + queryWrapper.orderByDesc(TrainingItem::getCreateTime); + + List trainingItemList = trainingItemService.list(queryWrapper); + + result.put("success", true); + result.put("message", "查询成功"); + result.put("data", trainingItemList); + result.put("count", trainingItemList.size()); + + return ResponseEntity.ok(result); + } catch (Exception e) { + result.put("success", false); + result.put("message", "查询异常:" + e.getMessage()); + return ResponseEntity.internalServerError().body(result); + } + } + + /** + * 更新陪练子表信息 + */ + @PutMapping("/update") + @Operation(summary = "更新陪练子表信息", description = "更新陪练子表详细信息") + public ResponseEntity> updateTrainingItem( + @Parameter(description = "陪练子表信息", required = true) + @RequestBody TrainingItem trainingItem) { + Map result = new HashMap<>(); + try { + if (trainingItem.getId() == null || trainingItem.getId().trim().isEmpty()) { + result.put("success", false); + result.put("message", "陪练子表ID不能为空"); + return ResponseEntity.badRequest().body(result); + } + + boolean success = trainingItemService.updateById(trainingItem); + + if (success) { + result.put("success", true); + result.put("message", "陪练子表信息更新成功"); + result.put("data", trainingItem); + return ResponseEntity.ok(result); + } else { + result.put("success", false); + result.put("message", "陪练子表信息更新失败"); + return ResponseEntity.badRequest().body(result); + } + } catch (Exception 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> deleteTrainingItem( + @Parameter(description = "陪练子表ID", required = true) + @PathVariable String id) { + Map result = new HashMap<>(); + try { + boolean success = trainingItemService.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) { + result.put("success", false); + result.put("message", "删除异常:" + e.getMessage()); + return ResponseEntity.internalServerError().body(result); + } + } + + /** + * 批量删除陪练子表记录 + */ + @DeleteMapping("/batchDelete") + @Operation(summary = "批量删除陪练子表记录", description = "根据陪练子表ID列表批量删除陪练子表信息") + public ResponseEntity> batchDeleteTrainingItems( + @Parameter(description = "陪练子表ID列表", required = true) + @RequestBody List ids) { + Map result = new HashMap<>(); + try { + if (ids == null || ids.isEmpty()) { + result.put("success", false); + result.put("message", "陪练子表ID列表不能为空"); + return ResponseEntity.badRequest().body(result); + } + + boolean success = trainingItemService.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) { + result.put("success", false); + result.put("message", "批量删除异常:" + e.getMessage()); + return ResponseEntity.internalServerError().body(result); + } + } +} + diff --git a/src/main/java/com/rj/controller/TrainingMainController.java b/src/main/java/com/rj/controller/TrainingMainController.java new file mode 100644 index 0000000..3de154b --- /dev/null +++ b/src/main/java/com/rj/controller/TrainingMainController.java @@ -0,0 +1,412 @@ +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.ITrainingMainService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +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.List; +import java.util.Map; +import java.util.UUID; + +/** + *

+ * 陪练主表 前端控制器 + *

+ * + * @author system + * @since 2025-01-XX + */ +@RestController +@RequestMapping("/api/trainingMain") +@Tag(name = "陪练主表管理", description = "陪练主表相关接口") +public class TrainingMainController { + + @Autowired + private ITrainingMainService trainingMainService; + + /** + * 新增陪练主表记录 + */ + @PostMapping("/add") + @Operation(summary = "新增陪练主表记录", description = "添加新的陪练主表记录") + public ResponseEntity> addTrainingMain( + @Parameter(description = "陪练主表信息", required = true) + @RequestBody TrainingMain trainingMain) { + Map result = new HashMap<>(); + try { + if (trainingMain.getId() == null || trainingMain.getId().trim().isEmpty()) { + trainingMain.setId(UUID.randomUUID().toString()); + } + trainingMain.setCreateTime(LocalDateTime.now()); + boolean success = trainingMainService.save(trainingMain); + if (success) { + result.put("success", true); + result.put("message", "陪练主表记录添加成功"); + result.put("data", trainingMain); + return ResponseEntity.ok(result); + } else { + result.put("success", false); + result.put("message", "陪练主表记录添加失败"); + return ResponseEntity.badRequest().body(result); + } + } catch (Exception 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> getTrainingMainById( + @Parameter(description = "陪练主表ID", required = true) + @PathVariable String id) { + Map result = new HashMap<>(); + try { + TrainingMain trainingMain = trainingMainService.getById(id); + if (trainingMain != null) { + result.put("success", true); + result.put("message", "查询成功"); + result.put("data", trainingMain); + return ResponseEntity.ok(result); + } else { + result.put("success", false); + result.put("message", "陪练主表记录不存在"); + return ResponseEntity.notFound().build(); + } + } catch (Exception e) { + result.put("success", false); + result.put("message", "查询异常:" + e.getMessage()); + return ResponseEntity.internalServerError().body(result); + } + } + + /** + * 分页查询陪练主表列表 + */ + @GetMapping("/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, + @Parameter(description = "陪练的场景(模糊查询)") + @RequestParam(required = false) String scenario, + @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) { + Map result = new HashMap<>(); + try { + Page page = new Page<>(current, size); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + + // 添加查询条件 + if (tenantId != null && !tenantId.trim().isEmpty()) { + queryWrapper.eq(TrainingMain::getTenantId, tenantId); + } + if (title != null && !title.trim().isEmpty()) { + queryWrapper.like(TrainingMain::getTitle, title); + } + if (scenario != null && !scenario.trim().isEmpty()) { + queryWrapper.like(TrainingMain::getScenario, scenario); + } + if (participantName != null && !participantName.trim().isEmpty()) { + queryWrapper.like(TrainingMain::getParticipantName, participantName); + } + 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); + + result.put("success", true); + result.put("message", "查询成功"); + result.put("data", trainingMainPage.getRecords()); + result.put("total", trainingMainPage.getTotal()); + result.put("current", trainingMainPage.getCurrent()); + result.put("size", trainingMainPage.getSize()); + result.put("pages", trainingMainPage.getPages()); + + return ResponseEntity.ok(result); + } catch (Exception e) { + result.put("success", false); + result.put("message", "查询异常:" + e.getMessage()); + return ResponseEntity.internalServerError().body(result); + } + } + + /** + * 按条件不分页查询陪练主表列表 + */ + @GetMapping("/listAll") + @Operation(summary = "按条件不分页查询陪练主表列表", description = "按条件查询所有陪练主表信息列表(不分页)") + public ResponseEntity> getAllTrainingMainList( + @Parameter(description = "租户ID(精确查询)") + @RequestParam(required = false) String tenantId, + @Parameter(description = "陪练标题(模糊查询)") + @RequestParam(required = false) String title, + @Parameter(description = "陪练的场景(模糊查询)") + @RequestParam(required = false) String scenario, + @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) { + Map result = new HashMap<>(); + try { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + + // 添加查询条件 + if (tenantId != null && !tenantId.trim().isEmpty()) { + queryWrapper.eq(TrainingMain::getTenantId, tenantId); + } + if (title != null && !title.trim().isEmpty()) { + queryWrapper.like(TrainingMain::getTitle, title); + } + if (scenario != null && !scenario.trim().isEmpty()) { + queryWrapper.like(TrainingMain::getScenario, scenario); + } + if (participantName != null && !participantName.trim().isEmpty()) { + queryWrapper.like(TrainingMain::getParticipantName, participantName); + } + 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); + + List trainingMainList = trainingMainService.list(queryWrapper); + + result.put("success", true); + result.put("message", "查询成功"); + result.put("data", trainingMainList); + result.put("count", trainingMainList.size()); + + return ResponseEntity.ok(result); + } catch (Exception e) { + result.put("success", false); + result.put("message", "查询异常:" + e.getMessage()); + return ResponseEntity.internalServerError().body(result); + } + } + + /** + * 更新陪练主表信息 + */ + @PutMapping("/update") + @Operation(summary = "更新陪练主表信息", description = "更新陪练主表详细信息") + public ResponseEntity> updateTrainingMain( + @Parameter(description = "陪练主表信息", required = true) + @RequestBody TrainingMain trainingMain) { + Map result = new HashMap<>(); + try { + if (trainingMain.getId() == null || trainingMain.getId().trim().isEmpty()) { + result.put("success", false); + result.put("message", "陪练主表ID不能为空"); + return ResponseEntity.badRequest().body(result); + } + + boolean success = trainingMainService.updateById(trainingMain); + + if (success) { + result.put("success", true); + result.put("message", "陪练主表信息更新成功"); + result.put("data", trainingMain); + return ResponseEntity.ok(result); + } else { + result.put("success", false); + result.put("message", "陪练主表信息更新失败"); + return ResponseEntity.badRequest().body(result); + } + } catch (Exception 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> deleteTrainingMain( + @Parameter(description = "陪练主表ID", required = true) + @PathVariable String id) { + Map result = new HashMap<>(); + try { + boolean success = trainingMainService.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) { + result.put("success", false); + result.put("message", "删除异常:" + e.getMessage()); + return ResponseEntity.internalServerError().body(result); + } + } + + /** + * 批量删除陪练主表记录 + */ + @DeleteMapping("/batchDelete") + @Operation(summary = "批量删除陪练主表记录", description = "根据陪练主表ID列表批量删除陪练主表信息") + public ResponseEntity> batchDeleteTrainingMains( + @Parameter(description = "陪练主表ID列表", required = true) + @RequestBody List ids) { + Map result = new HashMap<>(); + try { + if (ids == null || ids.isEmpty()) { + result.put("success", false); + result.put("message", "陪练主表ID列表不能为空"); + return ResponseEntity.badRequest().body(result); + } + + boolean success = trainingMainService.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) { + result.put("success", false); + result.put("message", "批量删除异常:" + e.getMessage()); + return ResponseEntity.internalServerError().body(result); + } + } +} + diff --git a/src/main/java/com/rj/entity/TrainingItem.java b/src/main/java/com/rj/entity/TrainingItem.java new file mode 100644 index 0000000..fadc568 --- /dev/null +++ b/src/main/java/com/rj/entity/TrainingItem.java @@ -0,0 +1,52 @@ +package com.rj.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableField; +import java.time.LocalDateTime; +import java.io.Serializable; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + *

+ * 陪练子表 + *

+ * + * @author system + * @since 2025-01-XX + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("training_item") +@Schema(description = "陪练子表") +public class TrainingItem implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "主键,UUID") + @TableId("id") + private String id; + + @Schema(description = "父ID,关联陪练主表ID") + @TableField("parent_id") + private String parentId; + + @Schema(description = "租户ID") + @TableField("tenant_id") + private String tenantId; + + @Schema(description = "题目") + @TableField("question") + private String question; + + @Schema(description = "题目答案") + @TableField("answer") + private String answer; + + @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 new file mode 100644 index 0000000..ac50f16 --- /dev/null +++ b/src/main/java/com/rj/entity/TrainingMain.java @@ -0,0 +1,60 @@ +package com.rj.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableField; +import java.time.LocalDateTime; +import java.io.Serializable; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + *

+ * 陪练主表 + *

+ * + * @author system + * @since 2025-01-XX + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("training_main") +@Schema(description = "陪练主表") +public class TrainingMain implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "主键,UUID") + @TableId("id") + private String id; + + @Schema(description = "租户ID") + @TableField("tenant_id") + private String tenantId; + + @Schema(description = "陪练标题") + @TableField("title") + private String title; + + @Schema(description = "陪练的场景") + @TableField("scenario") + private String scenario; + + @Schema(description = "参与人姓名") + @TableField("participant_name") + private String participantName; + + @Schema(description = "参与人电话") + @TableField("participant_phone") + private String participantPhone; + + @Schema(description = "结束时间") + @TableField("end_time") + private LocalDateTime endTime; + + @Schema(description = "创建时间") + @TableField("create_time") + private LocalDateTime createTime; +} + diff --git a/src/main/java/com/rj/mapper/TrainingItemMapper.java b/src/main/java/com/rj/mapper/TrainingItemMapper.java new file mode 100644 index 0000000..e80519f --- /dev/null +++ b/src/main/java/com/rj/mapper/TrainingItemMapper.java @@ -0,0 +1,17 @@ +package com.rj.mapper; + +import com.rj.entity.TrainingItem; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 陪练子表 Mapper 接口 + *

+ * + * @author system + * @since 2025-01-XX + */ +public interface TrainingItemMapper extends BaseMapper { + +} + diff --git a/src/main/java/com/rj/mapper/TrainingMainMapper.java b/src/main/java/com/rj/mapper/TrainingMainMapper.java new file mode 100644 index 0000000..20eef68 --- /dev/null +++ b/src/main/java/com/rj/mapper/TrainingMainMapper.java @@ -0,0 +1,17 @@ +package com.rj.mapper; + +import com.rj.entity.TrainingMain; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 陪练主表 Mapper 接口 + *

+ * + * @author system + * @since 2025-01-XX + */ +public interface TrainingMainMapper extends BaseMapper { + +} + diff --git a/src/main/java/com/rj/service/ITrainingItemService.java b/src/main/java/com/rj/service/ITrainingItemService.java new file mode 100644 index 0000000..5726489 --- /dev/null +++ b/src/main/java/com/rj/service/ITrainingItemService.java @@ -0,0 +1,17 @@ +package com.rj.service; + +import com.rj.entity.TrainingItem; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 陪练子表 服务类 + *

+ * + * @author system + * @since 2025-01-XX + */ +public interface ITrainingItemService extends IService { + +} + diff --git a/src/main/java/com/rj/service/ITrainingMainService.java b/src/main/java/com/rj/service/ITrainingMainService.java new file mode 100644 index 0000000..932be6c --- /dev/null +++ b/src/main/java/com/rj/service/ITrainingMainService.java @@ -0,0 +1,17 @@ +package com.rj.service; + +import com.rj.entity.TrainingMain; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 陪练主表 服务类 + *

+ * + * @author system + * @since 2025-01-XX + */ +public interface ITrainingMainService extends IService { + +} + diff --git a/src/main/java/com/rj/service/impl/TrainingItemServiceImpl.java b/src/main/java/com/rj/service/impl/TrainingItemServiceImpl.java new file mode 100644 index 0000000..6958504 --- /dev/null +++ b/src/main/java/com/rj/service/impl/TrainingItemServiceImpl.java @@ -0,0 +1,21 @@ +package com.rj.service.impl; + +import com.rj.entity.TrainingItem; +import com.rj.mapper.TrainingItemMapper; +import com.rj.service.ITrainingItemService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 陪练子表 服务实现类 + *

+ * + * @author system + * @since 2025-01-XX + */ +@Service +public class TrainingItemServiceImpl extends ServiceImpl implements ITrainingItemService { + +} + diff --git a/src/main/java/com/rj/service/impl/TrainingMainServiceImpl.java b/src/main/java/com/rj/service/impl/TrainingMainServiceImpl.java new file mode 100644 index 0000000..7c276ae --- /dev/null +++ b/src/main/java/com/rj/service/impl/TrainingMainServiceImpl.java @@ -0,0 +1,21 @@ +package com.rj.service.impl; + +import com.rj.entity.TrainingMain; +import com.rj.mapper.TrainingMainMapper; +import com.rj.service.ITrainingMainService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 陪练主表 服务实现类 + *

+ * + * @author system + * @since 2025-01-XX + */ +@Service +public class TrainingMainServiceImpl extends ServiceImpl implements ITrainingMainService { + +} + diff --git a/src/main/sql/training_item.sql b/src/main/sql/training_item.sql new file mode 100644 index 0000000..078e63a --- /dev/null +++ b/src/main/sql/training_item.sql @@ -0,0 +1,33 @@ +/* + Navicat Premium Data Transfer + + Source Server Type : MySQL + Source Server Version : 80042 + Target Server Type : MySQL + Target Server Version : 80042 + File Encoding : 65001 + + Date: 2025-01-XX +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for training_item +-- ---------------------------- +DROP TABLE IF EXISTS `training_item`; +CREATE TABLE `training_item` ( + `id` char(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '主键,UUID', + `parent_id` char(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '父ID,关联陪练主表ID', + `tenant_id` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '租户ID', + `question` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '题目', + `answer` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '题目答案', + `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + PRIMARY KEY (`id`) USING BTREE, + INDEX `idx_parent_id`(`parent_id`) USING BTREE COMMENT '父ID索引', + INDEX `idx_tenant_id`(`tenant_id`) USING BTREE COMMENT '租户ID索引' +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '陪练子表' ROW_FORMAT = Dynamic; + +SET FOREIGN_KEY_CHECKS = 1; + diff --git a/src/main/sql/training_main.sql b/src/main/sql/training_main.sql new file mode 100644 index 0000000..56d2a5b --- /dev/null +++ b/src/main/sql/training_main.sql @@ -0,0 +1,35 @@ +/* + Navicat Premium Data Transfer + + Source Server Type : MySQL + Source Server Version : 80042 + Target Server Type : MySQL + Target Server Version : 80042 + File Encoding : 65001 + + Date: 2025-01-XX +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for training_main +-- ---------------------------- +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', + `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 '陪练的场景', + `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 '结束时间', + `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + PRIMARY KEY (`id`) USING BTREE, + INDEX `idx_tenant_id`(`tenant_id`) USING BTREE COMMENT '租户ID索引', + INDEX `idx_practice_date`(`end_time`) USING BTREE COMMENT '日期索引' +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '陪练主表' ROW_FORMAT = Dynamic; + +SET FOREIGN_KEY_CHECKS = 1; + diff --git a/src/main/sql/陪练.log b/src/main/sql/陪练.log index 11b6391..d986b56 100644 --- a/src/main/sql/陪练.log +++ b/src/main/sql/陪练.log @@ -13,7 +13,7 @@ 陪练主表包括的字段: -id(uuid)主键, 租户id,陪练标题,陪练的场景,参与人姓名, 参与人电话, 日期,创建时间 +id(uuid)主键, 租户id,陪练标题,陪练的场景,参与人姓名, 参与人电话, 结束时间,创建时间 陪练子表包括的字段: id(uuid)主键,父id(uuid), 租户id,题目,题目答案 ,创建时间