merge
This commit is contained in:
GoCo 2025-08-22 16:56:26 +08:00
commit 78de817ca9
7 changed files with 169 additions and 45 deletions

View File

@ -1,35 +1,52 @@
package org.jeecg.modules.biz.controller; package org.jeecg.modules.biz.controller;
import org.springframework.beans.factory.annotation.Autowired; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.biz.constant.EntityLinkConst;
import org.jeecg.modules.biz.service.EntityLinkBizService;
import org.jeecg.modules.gen.question.entity.Question;
import org.jeecg.modules.gen.question.service.IQuestionService;
import org.jeecg.modules.gen.questionanswer.entity.QuestionAnswer;
import org.jeecg.modules.gen.questionanswer.service.IQuestionAnswerService;
import org.jeecg.modules.gen.questionoption.entity.QuestionOption;
import org.jeecg.modules.gen.questionoption.service.IQuestionOptionService;
import org.jeecg.modules.gen.questionrepo.service.IQuestionRepoService;
import org.jeecg.modules.gen.repo.entity.Repo;
import org.jeecg.modules.gen.repo.mapper.RepoMapper;
import org.jeecg.modules.gen.repo.service.IRepoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.transaction.Transactional;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.biz.constant.EntityLinkConst;
import org.jeecg.modules.biz.service.EntityLinkBizService;
import org.jeecg.modules.gen.repo.entity.Repo;
import org.jeecg.modules.gen.repo.mapper.RepoMapper;
@RestController @RestController
@RequestMapping("/biz/repo") @RequestMapping("/biz/repo")
@Tag(name = "题库") @Tag(name = "题库")
@Tag(name = "题库题目")
@Slf4j @Slf4j
public class RepoBizController { public class RepoBizController {
@Autowired @Autowired
private RepoMapper repoMapper; private RepoMapper repoMapper;
@Autowired @Autowired
private IRepoService repoService;
@Autowired
private IQuestionRepoService questionRepoService;
@Autowired
private EntityLinkBizService entityLinkBizService; private EntityLinkBizService entityLinkBizService;
@Autowired
private IQuestionService questionService;
@Autowired
private IQuestionOptionService questionOptionService;
@Autowired
private IQuestionAnswerService questionAnswerService;
@PostMapping("course_add") @PostMapping("course_add")
@Operation(summary = "获取课程下的题库") @Operation(summary = "获取课程下的题库")
@ -42,13 +59,27 @@ public class RepoBizController {
Repo repo = new Repo(); Repo repo = new Repo();
repo.setTitle(title); repo.setTitle(title);
repo.setRemark(remark); repo.setRemark(remark);
repoMapper.insert(repo); repoMapper.insert(repo);
entityLinkBizService.save(EntityLinkConst.SourceType.COURSE, courseId, EntityLinkConst.TargetType.REPO, repo.getId()); entityLinkBizService.save(EntityLinkConst.SourceType.COURSE, courseId, EntityLinkConst.TargetType.REPO, repo.getId());
return Result.OK(repo.getId()); return Result.OK(repo.getId());
} }
@PostMapping(value = "/courseAdd")
@Operation(summary = "课程新建题库")
public Result<String> courseAdd(@RequestBody Repo repo) {
return repoService.save(repo)?Result.OK("添加成功!"):Result.error("添加失败!");
}
@GetMapping("/questionList/{repoId}")
@Operation(summary = "查询题库下题目")
public Result<List<Question>> questionList(@PathVariable String repoId) {
List<String> list = questionRepoService.questionList(repoId);
return Result.ok(questionService.listByIds(list));
}
@GetMapping("course_list") @GetMapping("course_list")
@Operation(summary = "获取课程下的题库") @Operation(summary = "获取课程下的题库")
public Result<List<Repo>> courseList(@RequestParam String courseId) { public Result<List<Repo>> courseList(@RequestParam String courseId) {
@ -62,4 +93,37 @@ public class RepoBizController {
} }
} }
@GetMapping("/repoList/{questionId}")
@Operation(summary = "查询题目详情")
public Result<?> questionDetail(@PathVariable String questionId,@RequestParam Integer type) {
if (type == 1 || type == 2 || type == 3) {
return Result.ok(choiceDetail(questionId));
}else if(type == 4 || type == 5) {
return Result.ok(answerDetail(questionId));
}else {
return Result.ok(questionService.list(
new LambdaQueryWrapper<Question>().
eq(Question::getParentId, questionId)
)
);
}
}
public List<QuestionOption> choiceDetail(String questionId) {
return questionOptionService.list(
new LambdaQueryWrapper<QuestionOption>().
eq(QuestionOption::getQuestionId, questionId).
orderByAsc(QuestionOption::getOrderNo)
);
}
public List<QuestionAnswer> answerDetail(String questionId) {
return questionAnswerService.list(
new LambdaQueryWrapper<QuestionAnswer>().
eq(QuestionAnswer::getQuestionId, questionId)
);
}
} }

View File

@ -1,44 +1,40 @@
package org.jeecg.modules.gen.question.controller; package org.jeecg.modules.gen.question.controller;
import java.util.Arrays; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.query.QueryRuleEnum;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.gen.question.entity.Question;
import org.jeecg.modules.gen.question.service.IQuestionService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.gen.question.entity.Question;
import org.jeecg.modules.gen.question.entity.QuestionRequest;
import org.jeecg.modules.gen.question.service.IQuestionService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecg.modules.gen.questionanswer.entity.QuestionAnswer;
import org.jeecgframework.poi.excel.def.NormalExcelConstants; import org.jeecg.modules.gen.questionanswer.service.IQuestionAnswerService;
import org.jeecgframework.poi.excel.entity.ExportParams; import org.jeecg.modules.gen.questionoption.entity.QuestionOption;
import org.jeecgframework.poi.excel.entity.ImportParams; import org.jeecg.modules.gen.questionoption.service.IQuestionOptionService;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; import org.jeecg.modules.gen.questionrepo.entity.QuestionRepo;
import org.jeecg.modules.gen.questionrepo.service.IQuestionRepoService;
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.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import org.jeecg.common.aspect.annotation.AutoLog; import org.jeecg.common.aspect.annotation.AutoLog;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
/** import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @Description: 题目 * @Description: 题目
* @Author: jeecg-boot * @Author: jeecg-boot
* @Date: 2025-08-21 * @Date: 2025-08-21
@ -51,7 +47,14 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
public class QuestionController extends JeecgController<Question, IQuestionService> { public class QuestionController extends JeecgController<Question, IQuestionService> {
@Autowired @Autowired
private IQuestionService questionService; private IQuestionService questionService;
@Autowired
private IQuestionRepoService questionRepoService;
@Autowired
private IQuestionAnswerService questionAnswerService;
@Autowired
private IQuestionOptionService questionOptionService;
/** /**
* 分页列表查询 * 分页列表查询
* *
@ -75,11 +78,10 @@ public class QuestionController extends JeecgController<Question, IQuestionServi
IPage<Question> pageList = questionService.page(page, queryWrapper); IPage<Question> pageList = questionService.page(page, queryWrapper);
return Result.OK(pageList); return Result.OK(pageList);
} }
/** /**
* 添加 * 添加
* *
* @param question
* @return * @return
*/ */
@AutoLog(value = "题目-添加") @AutoLog(value = "题目-添加")
@ -91,7 +93,7 @@ public class QuestionController extends JeecgController<Question, IQuestionServi
return Result.OK("添加成功!"); return Result.OK("添加成功!");
} }
/** /**
* 编辑 * 编辑
* *
@ -118,10 +120,27 @@ public class QuestionController extends JeecgController<Question, IQuestionServi
@RequiresPermissions("gen.question:question:delete") @RequiresPermissions("gen.question:question:delete")
@DeleteMapping(value = "/delete") @DeleteMapping(value = "/delete")
public Result<String> delete(@RequestParam(name="id",required=true) String id) { public Result<String> delete(@RequestParam(name="id",required=true) String id) {
Question question = questionService.getById(id);
questionService.removeById(id); questionService.removeById(id);
questionRepoService.remove(
new LambdaQueryWrapper<QuestionRepo>()
.eq(QuestionRepo::getQuestionId,id)
);
//选择题
if( question.getType() >= 0 && question.getType() <= 2){
questionOptionService.remove(
new LambdaQueryWrapper<QuestionOption>()
.eq(QuestionOption::getQuestionId,id)
);
}else {
questionAnswerService.remove(
new LambdaQueryWrapper<QuestionAnswer>()
.eq(QuestionAnswer::getQuestionId,id)
);
}
return Result.OK("删除成功!"); return Result.OK("删除成功!");
} }
/** /**
* 批量删除 * 批量删除
* *
@ -136,7 +155,7 @@ public class QuestionController extends JeecgController<Question, IQuestionServi
this.questionService.removeByIds(Arrays.asList(ids.split(","))); this.questionService.removeByIds(Arrays.asList(ids.split(",")));
return Result.OK("批量删除成功!"); return Result.OK("批量删除成功!");
} }
/** /**
* 通过id查询 * 通过id查询
* *

View File

@ -0,0 +1,16 @@
package org.jeecg.modules.gen.question.entity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Data
public class QuestionRequest {
/**题目*/
Question question;
/**题库id*/
@Schema(description = "题库id")
List<String> repoIds = new ArrayList<>();
}

View File

@ -2,6 +2,7 @@ package org.jeecg.modules.gen.questionrepo.mapper;
import java.util.List; import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.gen.questionrepo.entity.QuestionRepo; import org.jeecg.modules.gen.questionrepo.entity.QuestionRepo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@ -12,6 +13,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @Date: 2025-08-21 * @Date: 2025-08-21
* @Version: V1.0 * @Version: V1.0
*/ */
@Mapper
public interface QuestionRepoMapper extends BaseMapper<QuestionRepo> { public interface QuestionRepoMapper extends BaseMapper<QuestionRepo> {
} }

View File

@ -1,8 +1,11 @@
package org.jeecg.modules.gen.questionrepo.service; package org.jeecg.modules.gen.questionrepo.service;
import org.jeecg.modules.gen.question.entity.Question;
import org.jeecg.modules.gen.questionrepo.entity.QuestionRepo; import org.jeecg.modules.gen.questionrepo.entity.QuestionRepo;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/** /**
* @Description: 题库题目 * @Description: 题库题目
* @Author: jeecg-boot * @Author: jeecg-boot
@ -11,4 +14,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/ */
public interface IQuestionRepoService extends IService<QuestionRepo> { public interface IQuestionRepoService extends IService<QuestionRepo> {
List<String> questionList(String repoId);
} }

View File

@ -1,12 +1,18 @@
package org.jeecg.modules.gen.questionrepo.service.impl; package org.jeecg.modules.gen.questionrepo.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.modules.gen.question.entity.Question;
import org.jeecg.modules.gen.questionrepo.entity.QuestionRepo; import org.jeecg.modules.gen.questionrepo.entity.QuestionRepo;
import org.jeecg.modules.gen.questionrepo.mapper.QuestionRepoMapper; import org.jeecg.modules.gen.questionrepo.mapper.QuestionRepoMapper;
import org.jeecg.modules.gen.questionrepo.service.IQuestionRepoService; import org.jeecg.modules.gen.questionrepo.service.IQuestionRepoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* @Description: 题库题目 * @Description: 题库题目
* @Author: jeecg-boot * @Author: jeecg-boot
@ -16,4 +22,13 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@Service @Service
public class QuestionRepoServiceImpl extends ServiceImpl<QuestionRepoMapper, QuestionRepo> implements IQuestionRepoService { public class QuestionRepoServiceImpl extends ServiceImpl<QuestionRepoMapper, QuestionRepo> implements IQuestionRepoService {
@Autowired
private QuestionRepoMapper questionRepoMapper;
@Override
public List<String> questionList(String repoId) {
List<QuestionRepo> questionRepos = questionRepoMapper.selectList(
new LambdaQueryWrapper<QuestionRepo>().eq(QuestionRepo::getRepoId, repoId));
return questionRepos.stream().map(QuestionRepo::getQuestionId).collect(Collectors.toList());
}
} }

View File

@ -2,16 +2,20 @@ package org.jeecg.modules.gen.repo.mapper;
import java.util.List; import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.gen.repo.entity.Repo; import org.jeecg.modules.gen.repo.entity.Repo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import javax.mail.MailSessionDefinition;
/** /**
* @Description: 题库 * @Description: 题库
* @Author: jeecg-boot * @Author: jeecg-boot
* @Date: 2025-08-21 * @Date: 2025-08-21
* @Version: V1.0 * @Version: V1.0
*/ */
@Mapper
public interface RepoMapper extends BaseMapper<Repo> { public interface RepoMapper extends BaseMapper<Repo> {
} }