理论试题管理代码调整

This commit is contained in:
tiger_zhou 2022-09-22 17:27:05 +08:00
parent 8536894aaa
commit a6ccd7dc81
3 changed files with 44 additions and 31 deletions

View File

@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
@ -75,23 +75,24 @@ public class PagerQuestionBankController {
/** /**
* 根据companyId 查询所有的标签 * 根据companyId 查询所有的标签
* @param companyId *
* @return * @return
*/ */
@GetMapping(path="/lable/{companyId}") @GetMapping(path="/lable")
public Collection<String> findAllLable(@PathVariable Long companyId){ public Collection<String> findAllLable(@RequestAttribute LoginUserInfoVO loginInfo /*@PathVariable Long companyId*/){
return this.questionBankService.findAllLable(companyId); return this.questionBankService.findAllLable(loginInfo.getProject().name());
} }
/** /**
* 根据标签查询所有的题型 * 根据标签查询所有的题型
* @param companyId
* @param queryVO * @param queryVO
* @return * @return
*/ */
@PostMapping(path="/{companyId}/question") // @PostMapping(path="/{companyId}/question")
public List<PaperQuestionVO> findByLable(@PathVariable Long companyId, @RequestBody PagerLableQueryVO queryVO){ @PostMapping(path="/lable/question")
return this.questionBankService.queryQuestionsForRaceLable(companyId,queryVO,false); public List<PaperQuestionVO> findByLable(@RequestAttribute LoginUserInfoVO loginInfo, @RequestBody PagerLableQueryVO queryVO){
return this.questionBankService.queryQuestionsForRaceLable(loginInfo.getProject().name(),queryVO,false);
} }

View File

@ -1,11 +1,9 @@
package club.joylink.rtss.dao; package club.joylink.rtss.dao;
import club.joylink.rtss.constants.BusinessConsts;
import club.joylink.rtss.entity.question.PaperQuestion; import club.joylink.rtss.entity.question.PaperQuestion;
import club.joylink.rtss.entity.question.PaperQuestionExample; import club.joylink.rtss.entity.question.PaperQuestionExample;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@ -14,20 +12,27 @@ import java.util.List;
@Repository @Repository
public interface PagerQuestionDAO extends MyBatisBaseDao<PaperQuestion, Long, PaperQuestionExample>{ public interface PagerQuestionDAO extends MyBatisBaseDao<PaperQuestion, Long, PaperQuestionExample>{
@Select("<script>" + @Select("<script>" +
"select race_lable from paper_question where company_id = #{companyId,jdbcType=BIGINT} group by race_lable" + "select * from paper_question where 1 = 1 " +
"</script>") "<choose>" +
List<String> findAllLableByCompanyId(Long companyId); "<when test=\"projectCode == 'DEFAULT'\">"+
" and project_code is null" +
@Select("<script>" + "</when>"+
"select * from paper_question where company_id = #{companyId,jdbcType=BIGINT} and is_del= #{isDelete,jdbcType=INTEGER}" + " <otherwise>"+
" and project_code = #{projectCode} "+
" </otherwise>" +
"</choose>" +
// "/*company_id = #{companyId,jdbcType=BIGINT}*/ " +
" and is_del= #{isDelete,jdbcType=INTEGER} " +
"<if test=\"types != null and types.size > 0\">"+ "<if test=\"types != null and types.size > 0\">"+
"<foreach collection=\"types\" open=\"and type in (\" close=\")\" item=\"d\" separator=\",\">"+ "<foreach collection=\"types\" open=\" and type in (\" close=\")\" item=\"d\" separator=\",\">"+
"#{d}"+ " #{d} "+
"</foreach></if>"+ "</foreach></if>"+
" <if test=\"lable != null and lable.size > 0\"> and <foreach collection=\"lable\" open=\"(\" close=\")\" item=\"d\" separator=\"or\"> "+ "<if test=\"lable != null and lable.size > 0\"> " +
" find_in_set(#{d},race_lable) > 0 "+ " <foreach collection=\"lable\" open=\" and (\" close=\")\" item=\"d\" separator=\" or \"> "+
"</foreach></if>" + " find_in_set(#{d},race_lable) > 0 "+
" </foreach>" +
"</if>" +
"</script>") "</script>")
List<PaperQuestion> findByCompanyIdAndRaceLable(Long companyId,int isDelete, List<String> lable,List<String> types); List<PaperQuestion> findByCompanyIdAndRaceLable(String projectCode,int isDelete, List<String> lable,List<String> types);
} }

View File

@ -49,9 +49,9 @@ public class PagerQuestionService {
criteria.andProjectCodeIsNull(); criteria.andProjectCodeIsNull();
if (Objects.nonNull(queryVO.getCompanyId())) { if (Objects.nonNull(queryVO.getCompanyId())) {
criteria.andCompanyIdEqualTo(queryVO.getCompanyId()); criteria.andCompanyIdEqualTo(queryVO.getCompanyId());
} else { } /*else {
criteria.andCompanyIdIsNull(); criteria.andCompanyIdIsNull();
} }*/
} else { } else {
criteria.andProjectCodeEqualTo(queryVO.getProjectCode()); criteria.andProjectCodeEqualTo(queryVO.getProjectCode());
} }
@ -97,12 +97,18 @@ public class PagerQuestionService {
/** /**
* 获取所有公司组织下的标签 * 获取所有公司组织下的标签
* @param companyId *
*/ */
public Collection<String> findAllLable(Long companyId){ public Collection<String> findAllLable(String projectCode){
PaperQuestionExample example = new PaperQuestionExample(); PaperQuestionExample example = new PaperQuestionExample();
PaperQuestionExample.Criteria criteria = example.createCriteria(); PaperQuestionExample.Criteria criteria = example.createCriteria();
criteria.andCompanyIdEqualTo(companyId); boolean isDefault = Project.isDefault(Project.valueOf(projectCode));
// criteria.andCompanyIdEqualTo(companyId);
if(isDefault){
criteria.andProjectCodeIsNull();
}else{
criteria.andProjectCodeEqualTo(projectCode);
}
criteria.andIsDelEqualTo(BusinessConsts.DBLogicDelete.NORMAL.ordinal()); criteria.andIsDelEqualTo(BusinessConsts.DBLogicDelete.NORMAL.ordinal());
List<PaperQuestion> lableList = this.questionDAO.selectByExample(example); List<PaperQuestion> lableList = this.questionDAO.selectByExample(example);
if(CollectionUtils.isEmpty(lableList)){ if(CollectionUtils.isEmpty(lableList)){
@ -115,15 +121,16 @@ public class PagerQuestionService {
/** /**
* 根据公司id和标签或类型查询 * 根据公司id和标签或类型查询
* @param companyId *
* @param queryVO * @param queryVO
* @param random * @param random
* @return * @return
*/ */
public List<PaperQuestionVO> queryQuestionsForRaceLable(Long companyId, PagerLableQueryVO queryVO,boolean random) { public List<PaperQuestionVO> queryQuestionsForRaceLable(String projectCode, PagerLableQueryVO queryVO,boolean random) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(queryVO.allNotNullOrEmpty(),"查询内容不能为空"); BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(queryVO.allNotNullOrEmpty(),"查询内容不能为空");
int isDel = BusinessConsts.DBLogicDelete.NORMAL.ordinal(); int isDel = BusinessConsts.DBLogicDelete.NORMAL.ordinal();
List<PaperQuestion> list = this.questionDAO.findByCompanyIdAndRaceLable(companyId,isDel,queryVO.getLables(),queryVO.getTypes());
List<PaperQuestion> list = this.questionDAO.findByCompanyIdAndRaceLable(projectCode,isDel,queryVO.getLables(),queryVO.getTypes());
List<PaperQuestionVO> questionVOS = PaperQuestionVO.convert2VOList(list); List<PaperQuestionVO> questionVOS = PaperQuestionVO.convert2VOList(list);
return questionVOS; return questionVOS;
} }