题库的题目数量

This commit is contained in:
Lqc 2025-09-05 11:29:02 +08:00
parent 27dabcce7a
commit 918514a6ec

View File

@ -15,6 +15,7 @@ import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.query.QueryRuleEnum; import org.jeecg.common.system.query.QueryRuleEnum;
import org.jeecg.common.util.oConvertUtils; import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.aiol.entity.AiolQuestionRepo; import org.jeecg.modules.aiol.entity.AiolQuestionRepo;
import org.jeecg.modules.aiol.entity.AiolRepo;
import org.jeecg.modules.aiol.service.IAiolQuestionRepoService; import org.jeecg.modules.aiol.service.IAiolQuestionRepoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 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 com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.aiol.service.IAiolRepoService;
import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants; import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams; 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.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jeecg.common.system.base.controller.JeecgController; import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.multipart.MultipartHttpServletRequest;
@ -51,6 +54,8 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
public class AiolQuestionRepoController extends JeecgController<AiolQuestionRepo, IAiolQuestionRepoService> { public class AiolQuestionRepoController extends JeecgController<AiolQuestionRepo, IAiolQuestionRepoService> {
@Autowired @Autowired
private IAiolQuestionRepoService aiolQuestionRepoService; private IAiolQuestionRepoService aiolQuestionRepoService;
@Autowired
private IAiolRepoService aiolRepoService;
/** /**
* 分页列表查询 * 分页列表查询
@ -86,9 +91,25 @@ public class AiolQuestionRepoController extends JeecgController<AiolQuestionRepo
@Operation(summary="题库题目-添加") @Operation(summary="题库题目-添加")
@RequiresPermissions("aiol:aiol_question_repo:add") @RequiresPermissions("aiol:aiol_question_repo:add")
@PostMapping(value = "/add") @PostMapping(value = "/add")
@Transactional
public Result<String> add(@RequestBody AiolQuestionRepo aiolQuestionRepo) { public Result<String> add(@RequestBody AiolQuestionRepo aiolQuestionRepo) {
aiolQuestionRepoService.save(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<String> questionIds = aiolQuestionRepoService.questionList(repoId);
int questionCount = questionIds.size();
// 更新题库的题目数量
repo.setQuestionCount(questionCount);
}
aiolRepoService.updateById(repo);
}
return Result.OK("添加成功!"); return Result.OK("添加成功!");
} }
@ -117,8 +138,25 @@ public class AiolQuestionRepoController extends JeecgController<AiolQuestionRepo
@Operation(summary="题库题目-通过id删除") @Operation(summary="题库题目-通过id删除")
@RequiresPermissions("aiol:aiol_question_repo:delete") @RequiresPermissions("aiol:aiol_question_repo:delete")
@DeleteMapping(value = "/delete") @DeleteMapping(value = "/delete")
@Transactional
public Result<String> delete(@RequestParam(name="id",required=true) String id) { public Result<String> delete(@RequestParam(name="id",required=true) String id) {
// 获取题库ID
String repoId = aiolQuestionRepoService.getById(id).getRepoId();
aiolQuestionRepoService.removeById(id); aiolQuestionRepoService.removeById(id);
// 查询该题库
AiolRepo repo = aiolRepoService.getById(repoId);
if (repo != null) {
if(repo.getQuestionCount() != null){
repo.setQuestionCount(repo.getQuestionCount() - 1);
}else {
// 查询当前题库中的题目数量
List<String> questionIds = aiolQuestionRepoService.questionList(repoId);
int questionCount = questionIds.size() - 1;
// 更新题库的题目数量
repo.setQuestionCount(questionCount);
}
aiolRepoService.updateById(repo);
}
return Result.OK("删除成功!"); return Result.OK("删除成功!");
} }