From 918514a6ecca5c0af4ff6fe65dd933680f27f9c2 Mon Sep 17 00:00:00 2001 From: Lqc Date: Fri, 5 Sep 2025 11:29:02 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=98=E5=BA=93=E7=9A=84=E9=A2=98=E7=9B=AE?= =?UTF-8?q?=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AiolQuestionRepoController.java | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolQuestionRepoController.java b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolQuestionRepoController.java index 1f63a884..0b38fe0f 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolQuestionRepoController.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolQuestionRepoController.java @@ -15,6 +15,7 @@ import org.jeecg.common.system.query.QueryGenerator; import org.jeecg.common.system.query.QueryRuleEnum; import org.jeecg.common.util.oConvertUtils; import org.jeecg.modules.aiol.entity.AiolQuestionRepo; +import org.jeecg.modules.aiol.entity.AiolRepo; import org.jeecg.modules.aiol.service.IAiolQuestionRepoService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -22,6 +23,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import lombok.extern.slf4j.Slf4j; +import org.jeecg.modules.aiol.service.IAiolRepoService; import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.def.NormalExcelConstants; import org.jeecgframework.poi.excel.entity.ExportParams; @@ -29,6 +31,7 @@ import org.jeecgframework.poi.excel.entity.ImportParams; import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; import org.jeecg.common.system.base.controller.JeecgController; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; @@ -51,6 +54,8 @@ import org.apache.shiro.authz.annotation.RequiresPermissions; public class AiolQuestionRepoController extends JeecgController { @Autowired private IAiolQuestionRepoService aiolQuestionRepoService; + @Autowired + private IAiolRepoService aiolRepoService; /** * 分页列表查询 @@ -86,9 +91,25 @@ public class AiolQuestionRepoController extends JeecgController add(@RequestBody AiolQuestionRepo aiolQuestionRepo) { aiolQuestionRepoService.save(aiolQuestionRepo); - + // 2. 获取题库ID + String repoId = aiolQuestionRepo.getRepoId(); + // 3. 查询该题库 + AiolRepo repo = aiolRepoService.getById(repoId); + if (repo != null) { + if(repo.getQuestionCount() != null){ + repo.setQuestionCount(repo.getQuestionCount() + 1); + }else { + // 查询当前题库中的题目数量 + List questionIds = aiolQuestionRepoService.questionList(repoId); + int questionCount = questionIds.size(); + // 更新题库的题目数量 + repo.setQuestionCount(questionCount); + } + aiolRepoService.updateById(repo); + } return Result.OK("添加成功!"); } @@ -117,8 +138,25 @@ public class AiolQuestionRepoController extends JeecgController delete(@RequestParam(name="id",required=true) String id) { + // 获取题库ID + String repoId = aiolQuestionRepoService.getById(id).getRepoId(); aiolQuestionRepoService.removeById(id); + // 查询该题库 + AiolRepo repo = aiolRepoService.getById(repoId); + if (repo != null) { + if(repo.getQuestionCount() != null){ + repo.setQuestionCount(repo.getQuestionCount() - 1); + }else { + // 查询当前题库中的题目数量 + List questionIds = aiolQuestionRepoService.questionList(repoId); + int questionCount = questionIds.size() - 1; + // 更新题库的题目数量 + repo.setQuestionCount(questionCount); + } + aiolRepoService.updateById(repo); + } return Result.OK("删除成功!"); }