diff --git a/src/main/java/club/joylink/rtss/constants/BusinessConsts.java b/src/main/java/club/joylink/rtss/constants/BusinessConsts.java index acbfec5e8..a116c1166 100644 --- a/src/main/java/club/joylink/rtss/constants/BusinessConsts.java +++ b/src/main/java/club/joylink/rtss/constants/BusinessConsts.java @@ -817,4 +817,12 @@ public interface BusinessConsts { /** 关闭自动调度 */ REGULATION_OFF, } + + /** + * 数据库数据逻辑删除标识 + */ + enum DBLogicDelete{ + NORMAL, + DELETE, + } } diff --git a/src/main/java/club/joylink/rtss/controller/competition/question/QuestionBankController2.java b/src/main/java/club/joylink/rtss/controller/competition/question/TheoryQuestionBankController2.java similarity index 70% rename from src/main/java/club/joylink/rtss/controller/competition/question/QuestionBankController2.java rename to src/main/java/club/joylink/rtss/controller/competition/question/TheoryQuestionBankController2.java index 77a09157d..db717080d 100644 --- a/src/main/java/club/joylink/rtss/controller/competition/question/QuestionBankController2.java +++ b/src/main/java/club/joylink/rtss/controller/competition/question/TheoryQuestionBankController2.java @@ -6,24 +6,23 @@ import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.question.QuestionQueryVO; -import club.joylink.rtss.vo.client.question.v2.QuestionVO2; +import club.joylink.rtss.vo.client.question.v2.PaperQuestionVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.Collection; import java.util.List; +import java.util.Map; /** *题库管理接口 */ @RestController -@RequestMapping(path = "/api/questionBank2") -public class QuestionBankController2 { +@RequestMapping(path = "/api/pager_question") +public class TheoryQuestionBankController2 { - /*@Autowired - private IQuestionBankService iQuestionBankService;*/ @Autowired private QuestionBankService2 questionBankService; @@ -31,7 +30,7 @@ public class QuestionBankController2 { *分页查询题目 */ @GetMapping(path = "/questions/paging") - public PageVO pagingQueryQuestions(@RequestAttribute LoginUserInfoVO loginInfo, QuestionQueryVO queryVO) { + public PageVO pagingQueryQuestions(@RequestAttribute LoginUserInfoVO loginInfo, QuestionQueryVO queryVO) { queryVO.setProjectCode(loginInfo.getProject().name()); return questionBankService.pagingQueryQuestions(queryVO); } @@ -40,7 +39,7 @@ public class QuestionBankController2 { *查询题目列表 */ @GetMapping(path = "/questions") - public List queryQuestions(@RequestAttribute LoginUserInfoVO loginInfo,QuestionQueryVO queryVO) { + public List queryQuestions(@RequestAttribute LoginUserInfoVO loginInfo, QuestionQueryVO queryVO) { queryVO.setProjectCode(loginInfo.getProject().name()); return questionBankService.queryQuestions(queryVO); } @@ -49,7 +48,7 @@ public class QuestionBankController2 { *获取题目信息 */ @GetMapping(path = "/questions/{questionId}") - public QuestionVO2 getQuestion(@PathVariable Long questionId) { + public PaperQuestionVO getQuestion(@PathVariable Long questionId) { return questionBankService.getQuestion(questionId); } @@ -57,7 +56,7 @@ public class QuestionBankController2 { *添加题目 */ @PostMapping(path = "/questions") - public void addQuestion(@Validated @RequestBody QuestionVO2 questionVO, @RequestAttribute LoginUserInfoVO loginInfo, + public void addQuestion(@Validated @RequestBody PaperQuestionVO questionVO, @RequestAttribute LoginUserInfoVO loginInfo, @RequestAttribute AccountVO user) { questionVO.setProjectCode(loginInfo.getProject().name()); questionBankService.saveOrUpdate(questionVO, user); @@ -67,7 +66,7 @@ public class QuestionBankController2 { *导入项目或单位试题库 */ @PostMapping(path = "/questions/import") - public void importProjectQuestion(@Validated @RequestBody List questions, @RequestAttribute LoginUserInfoVO loginInfo, + public void importProjectQuestion(@Validated @RequestBody List questions, @RequestAttribute LoginUserInfoVO loginInfo, @RequestAttribute AccountVO user, @RequestParam(required = false, name = "id") Long companyId) { questionBankService.importProjectQuestion(questions, loginInfo.getProject().name(), companyId,user); @@ -84,14 +83,14 @@ public class QuestionBankController2 { } /** - * 根据标签查询所有的题型 + * 根据标签查询所有的题型 * @param companyId - * @param raceLable + * @param raceMap * @return */ - @GetMapping(path="/questions/{companyId}/question") - public List findByLable(@PathVariable Long companyId, @RequestParam(value = "raceLable") String raceLable){ - return this.questionBankService.queryQuestionsForRaceLable(companyId,raceLable); + @PostMapping(path="/questions/{companyId}/question") + public List findByLable(@PathVariable Long companyId, @RequestBody Map raceMap){ + return this.questionBankService.queryQuestionsForRaceLable(companyId,raceMap); } @@ -103,7 +102,7 @@ public class QuestionBankController2 { * @param user */ @PutMapping(path = "/questions/{questionId}") - public void updateQuestion(@PathVariable Long questionId, @RequestAttribute LoginUserInfoVO loginInfo,@RequestBody QuestionVO2 questionVO,@RequestAttribute AccountVO user) { + public void updateQuestion(@PathVariable Long questionId, @RequestAttribute LoginUserInfoVO loginInfo, @RequestBody PaperQuestionVO questionVO, @RequestAttribute AccountVO user) { questionVO.setId(questionId); questionVO.setProjectCode(loginInfo.getProject().name()); questionBankService.saveOrUpdate(questionVO,user); @@ -112,8 +111,8 @@ public class QuestionBankController2 { /** *删除题目 */ - @DeleteMapping(path = "/questions/{questionId}") - public void deleteQuestion(@PathVariable Long questionId) { + @DeleteMapping(path = "/questions") + public void deleteQuestion(@RequestBody List questionId) { questionBankService.deleteQuestion(questionId); } diff --git a/src/main/java/club/joylink/rtss/dao/PagerQuestionDAO.java b/src/main/java/club/joylink/rtss/dao/PagerQuestionDAO.java new file mode 100644 index 000000000..b03398e24 --- /dev/null +++ b/src/main/java/club/joylink/rtss/dao/PagerQuestionDAO.java @@ -0,0 +1,28 @@ +package club.joylink.rtss.dao; + +import club.joylink.rtss.constants.BusinessConsts; +import club.joylink.rtss.entity.question.PaperQuestion; +import club.joylink.rtss.entity.question.PaperQuestionExample; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.type.JdbcType; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Mapper +@Repository +public interface PagerQuestionDAO extends MyBatisBaseDao{ + @Select("") + List findAllLableByCompanyId(Long companyId); + + @Select("") + List findByCompanyIdAndRaceLable(Long companyId,int isDelete, List lable); + +} diff --git a/src/main/java/club/joylink/rtss/dao/RaceQuestion2DAO.java b/src/main/java/club/joylink/rtss/dao/RaceQuestion2DAO.java deleted file mode 100644 index ebeac3216..000000000 --- a/src/main/java/club/joylink/rtss/dao/RaceQuestion2DAO.java +++ /dev/null @@ -1,27 +0,0 @@ -package club.joylink.rtss.dao; - -import club.joylink.rtss.entity.race2.RaceQuestion2; -import club.joylink.rtss.entity.race2.RaceQuestion2Example; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Select; -import org.springframework.stereotype.Repository; - -import java.util.List; - -@Mapper -@Repository -public interface RaceQuestion2DAO extends MyBatisBaseDao{ - @Select(" ") - Long checkExistByPK(Long id); - @Select("") - List findAllLableByCompanyId(Long companyId); - - @Select("") - List findByCompanyIdAndRaceLable(Long companyId,String lable); -} diff --git a/src/main/java/club/joylink/rtss/entity/race2/RaceQuestion2.java b/src/main/java/club/joylink/rtss/entity/question/PaperQuestion.java similarity index 80% rename from src/main/java/club/joylink/rtss/entity/race2/RaceQuestion2.java rename to src/main/java/club/joylink/rtss/entity/question/PaperQuestion.java index 27927bee3..e3ffeea65 100644 --- a/src/main/java/club/joylink/rtss/entity/race2/RaceQuestion2.java +++ b/src/main/java/club/joylink/rtss/entity/question/PaperQuestion.java @@ -1,4 +1,4 @@ -package club.joylink.rtss.entity.race2; +package club.joylink.rtss.entity.question; import java.io.Serializable; import java.time.LocalDateTime; @@ -7,11 +7,10 @@ import lombok.Data; /** * @author - * + * */ @Data -public class RaceQuestion2 implements Serializable { - private static final long serialVersionUID = 1L; +public class PaperQuestion implements Serializable { /** * id */ @@ -46,7 +45,13 @@ public class RaceQuestion2 implements Serializable { * 标签 */ private String raceLable; + + /** + * 是否删除0=否,1=是 + */ + private Integer isDel; private String topic; private String questions; + private static final long serialVersionUID = 1L; } diff --git a/src/main/java/club/joylink/rtss/entity/race2/RaceQuestion2Example.java b/src/main/java/club/joylink/rtss/entity/question/PaperQuestionExample.java similarity index 90% rename from src/main/java/club/joylink/rtss/entity/race2/RaceQuestion2Example.java rename to src/main/java/club/joylink/rtss/entity/question/PaperQuestionExample.java index 43c471dc6..232cce9c8 100644 --- a/src/main/java/club/joylink/rtss/entity/race2/RaceQuestion2Example.java +++ b/src/main/java/club/joylink/rtss/entity/question/PaperQuestionExample.java @@ -1,10 +1,10 @@ -package club.joylink.rtss.entity.race2; +package club.joylink.rtss.entity.question; import java.util.ArrayList; import java.util.Date; import java.util.List; -public class RaceQuestion2Example { +public class PaperQuestionExample { protected String orderByClause; protected boolean distinct; @@ -15,7 +15,7 @@ public class RaceQuestion2Example { private Long offset; - public RaceQuestion2Example() { + public PaperQuestionExample() { oredCriteria = new ArrayList(); } @@ -224,6 +224,7 @@ public class RaceQuestion2Example { addCriterion("`type` <=", value, "type"); return (Criteria) this; } + public Criteria andTopicLike(String value) { addCriterion("`topic` like", value, "topic"); return (Criteria) this; @@ -577,6 +578,66 @@ public class RaceQuestion2Example { addCriterion("race_lable not between", value1, value2, "raceLable"); return (Criteria) this; } + + public Criteria andIsDelIsNull() { + addCriterion("is_del is null"); + return (Criteria) this; + } + + public Criteria andIsDelIsNotNull() { + addCriterion("is_del is not null"); + return (Criteria) this; + } + + public Criteria andIsDelEqualTo(Integer value) { + addCriterion("is_del =", value, "isDel"); + return (Criteria) this; + } + + public Criteria andIsDelNotEqualTo(Integer value) { + addCriterion("is_del <>", value, "isDel"); + return (Criteria) this; + } + + public Criteria andIsDelGreaterThan(Integer value) { + addCriterion("is_del >", value, "isDel"); + return (Criteria) this; + } + + public Criteria andIsDelGreaterThanOrEqualTo(Integer value) { + addCriterion("is_del >=", value, "isDel"); + return (Criteria) this; + } + + public Criteria andIsDelLessThan(Integer value) { + addCriterion("is_del <", value, "isDel"); + return (Criteria) this; + } + + public Criteria andIsDelLessThanOrEqualTo(Integer value) { + addCriterion("is_del <=", value, "isDel"); + return (Criteria) this; + } + + public Criteria andIsDelIn(List values) { + addCriterion("is_del in", values, "isDel"); + return (Criteria) this; + } + + public Criteria andIsDelNotIn(List values) { + addCriterion("is_del not in", values, "isDel"); + return (Criteria) this; + } + + public Criteria andIsDelBetween(Integer value1, Integer value2) { + addCriterion("is_del between", value1, value2, "isDel"); + return (Criteria) this; + } + + public Criteria andIsDelNotBetween(Integer value1, Integer value2) { + addCriterion("is_del not between", value1, value2, "isDel"); + return (Criteria) this; + } } /** diff --git a/src/main/java/club/joylink/rtss/entity/race2/RaceQuestion2WithBLOBs.java b/src/main/java/club/joylink/rtss/entity/question/PaperQuestionWithBLOBs.java similarity index 69% rename from src/main/java/club/joylink/rtss/entity/race2/RaceQuestion2WithBLOBs.java rename to src/main/java/club/joylink/rtss/entity/question/PaperQuestionWithBLOBs.java index 7c6886f87..753e6e870 100644 --- a/src/main/java/club/joylink/rtss/entity/race2/RaceQuestion2WithBLOBs.java +++ b/src/main/java/club/joylink/rtss/entity/question/PaperQuestionWithBLOBs.java @@ -1,4 +1,4 @@ -package club.joylink.rtss.entity.race2; +package club.joylink.rtss.entity.question; import java.io.Serializable; import lombok.Data; @@ -8,7 +8,7 @@ import lombok.Data; * */ @Data -public class RaceQuestion2WithBLOBs extends RaceQuestion2 implements Serializable { +public class PaperQuestionWithBLOBs extends PaperQuestion implements Serializable { /** * 问题内容 */ @@ -17,4 +17,4 @@ public class RaceQuestion2WithBLOBs extends RaceQuestion2 implements Serializabl private String questions; private static final long serialVersionUID = 1L; -} \ No newline at end of file +} diff --git a/src/main/java/club/joylink/rtss/services/completition/question/QuestionBankService2.java b/src/main/java/club/joylink/rtss/services/completition/question/QuestionBankService2.java index bb78dd63c..728735724 100644 --- a/src/main/java/club/joylink/rtss/services/completition/question/QuestionBankService2.java +++ b/src/main/java/club/joylink/rtss/services/completition/question/QuestionBankService2.java @@ -2,17 +2,19 @@ package club.joylink.rtss.services.completition.question; import club.joylink.rtss.constants.BusinessConsts; import club.joylink.rtss.constants.Project; -import club.joylink.rtss.dao.RaceQuestion2DAO; -import club.joylink.rtss.entity.race2.RaceQuestion2; -import club.joylink.rtss.entity.race2.RaceQuestion2Example; +import club.joylink.rtss.dao.PagerQuestionDAO; +import club.joylink.rtss.entity.question.PaperQuestion; +import club.joylink.rtss.entity.question.PaperQuestionExample; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.question.QuestionQueryVO; -import club.joylink.rtss.vo.client.question.v2.QuestionOptionVO2; -import club.joylink.rtss.vo.client.question.v2.QuestionVO2; +import club.joylink.rtss.vo.client.question.v2.PaperQuestionOptionVO2; +import club.joylink.rtss.vo.client.question.v2.PaperQuestionVO; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; +import com.google.common.base.Splitter; +import com.google.common.base.Strings; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; @@ -26,21 +28,21 @@ import java.util.stream.Collectors; @Service public class QuestionBankService2 { @Resource - private RaceQuestion2DAO questionDAO; + private PagerQuestionDAO questionDAO; private Object queryQuestions(QuestionQueryVO queryVO,boolean isPaging){ if(isPaging){ PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); } - RaceQuestion2Example example = new RaceQuestion2Example(); - RaceQuestion2Example.Criteria criteria = example.createCriteria(); + PaperQuestionExample example = new PaperQuestionExample(); + PaperQuestionExample.Criteria criteria = example.createCriteria(); if (StringUtils.hasText(queryVO.getTopic())) { criteria.andTopicLike(String.format("%%%s%%", queryVO.getTopic())); } if (StringUtils.hasText(queryVO.getType())) { criteria.andTypeEqualTo(queryVO.getType()); } - + criteria.andIsDelEqualTo(BusinessConsts.DBLogicDelete.NORMAL.ordinal()); boolean isDefault = Project.isDefault(Project.valueOf(queryVO.getProjectCode())); if (isDefault) { criteria.andProjectCodeIsNull(); @@ -60,9 +62,9 @@ public class QuestionBankService2 { * @param queryVO * @return */ - public PageVO pagingQueryQuestions(QuestionQueryVO queryVO) { - Page page = (Page) this.queryQuestions(queryVO,true); - List questionVOS = QuestionVO2.convert2VOList(page.getResult()); + public PageVO pagingQueryQuestions(QuestionQueryVO queryVO) { + Page page = (Page) this.queryQuestions(queryVO,true); + List questionVOS = PaperQuestionVO.convert2VOList(page.getResult()); return PageVO.convert(page, questionVOS); } @@ -72,9 +74,9 @@ public class QuestionBankService2 { * @param queryVO * @return */ - public List queryQuestions(QuestionQueryVO queryVO) { - List list = (List) this.queryQuestions(queryVO,true); - List questionVOS = QuestionVO2.convert2VOList(list); + public List queryQuestions(QuestionQueryVO queryVO) { + List list = (List) this.queryQuestions(queryVO,true); + List questionVOS = PaperQuestionVO.convert2VOList(list); return questionVOS; } @@ -84,10 +86,11 @@ public class QuestionBankService2 { * @param questionId * @return */ - public QuestionVO2 getQuestion(Long questionId) { - RaceQuestion2 question = questionDAO.selectByPrimaryKey(questionId); - BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(question); - QuestionVO2 questionVO = new QuestionVO2(question); + public PaperQuestionVO getQuestion(Long questionId) { + PaperQuestion question = questionDAO.selectByPrimaryKey(questionId); + + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(question) || question.getIsDel() == BusinessConsts.DBLogicDelete.NORMAL.ordinal()); + PaperQuestionVO questionVO = new PaperQuestionVO(question); return questionVO; } @@ -96,18 +99,26 @@ public class QuestionBankService2 { * @param companyId */ public Collection findAllLable(Long companyId){ - List lableList = this.questionDAO.findAllLableByCompanyId(companyId); + PaperQuestionExample example = new PaperQuestionExample(); + PaperQuestionExample.Criteria criteria = example.createCriteria(); + criteria.andCompanyIdEqualTo(companyId); + criteria.andIsDelEqualTo(BusinessConsts.DBLogicDelete.NORMAL.ordinal()); + List lableList = this.questionDAO.selectByExample(example); if(CollectionUtils.isEmpty(lableList)){ return Collections.emptyList(); } - return lableList.stream().filter(Objects::nonNull).flatMap(d-> Arrays.stream(d.split(","))).collect(Collectors.toSet()); + return lableList.stream().map(PaperQuestion::getRaceLable).filter(Objects::nonNull).flatMap(d-> Splitter.on(",").omitEmptyStrings() + .trimResults().splitToStream(d)).collect(Collectors.toSet()); } - public List queryQuestionsForRaceLable(Long companyId,String raceLable) { - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(raceLable) - ,"查询标签不能为空"); - List list = this.questionDAO.findByCompanyIdAndRaceLable(companyId,raceLable); - List questionVOS = QuestionVO2.convert2VOList(list); + + + public List queryQuestionsForRaceLable(Long companyId, Map raceMap) { + String raceLableStr = Objects.isNull(raceMap) ? null :raceMap.get("raceLable"); + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!Strings.isNullOrEmpty(raceLableStr),"查询标签不能为空"); + List raceLableList = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(raceLableStr); + List list = this.questionDAO.findByCompanyIdAndRaceLable(companyId,BusinessConsts.DBLogicDelete.NORMAL.ordinal(),raceLableList); + List questionVOS = PaperQuestionVO.convert2VOList(list); return questionVOS; } /** @@ -115,7 +126,7 @@ public class QuestionBankService2 { * @param questionVO * @param accountVO */ - public void saveOrUpdate(QuestionVO2 questionVO, AccountVO accountVO) { + public void saveOrUpdate(PaperQuestionVO questionVO, AccountVO accountVO) { BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue((Objects.equals(BusinessConsts.TheoryType.select.name(),questionVO.getType()) || Objects.equals(BusinessConsts.TheoryType.judge.name(),questionVO.getType()) || Objects.equals(BusinessConsts.TheoryType.multi.name(),questionVO.getType())) ,"题库目前只支持单选,多选和判断"); @@ -123,19 +134,23 @@ public class QuestionBankService2 { BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue( (Objects.equals(BusinessConsts.TheoryType.select.name(), questionVO.getType()) || Objects.equals(BusinessConsts.TheoryType.judge.name(), questionVO.getType())) && - questionVO.getOptionList().stream().filter(QuestionOptionVO2::getCorrect).count() == 1, + questionVO.getOptionList().stream().filter(PaperQuestionOptionVO2::getCorrect).count() == 1, "单选或判断题正确答案有且只有一个!"); BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotTrue( (Objects.equals(BusinessConsts.TheoryType.multi.name(), questionVO.getType())) && - questionVO.getOptionList().stream().filter(QuestionOptionVO2::getCorrect).count() <= 1, + questionVO.getOptionList().stream().filter(PaperQuestionOptionVO2::getCorrect).count() <= 1, "多选题正确答案必须是2个以上!"); - RaceQuestion2 question = questionVO.convert2DB(); + PaperQuestion question = questionVO.convert2DB(); question.setCreateUserId(accountVO.getId()); question.setCreateTime(LocalDateTime.now()); - + question.setIsDel(BusinessConsts.DBLogicDelete.NORMAL.ordinal()); if(Objects.nonNull(questionVO.getId())){ - Long exist = this.questionDAO.checkExistByPK(questionVO.getId()); - if(Objects.isNull(exist)){ + PaperQuestionExample example = new PaperQuestionExample(); + PaperQuestionExample.Criteria criteria = example.createCriteria(); + criteria.andIdEqualTo(questionVO.getId()); + criteria.andIsDelEqualTo(BusinessConsts.DBLogicDelete.NORMAL.ordinal()); + Long exist = this.questionDAO.countByExample(example); + if(Objects.isNull(exist) || exist <= 0){ BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotTrue(true, "未找到要修改的数据!"); } @@ -147,9 +162,8 @@ public class QuestionBankService2 { } - @Transactional - public void importProjectQuestion(List questions, String projectCode, Long companyId, AccountVO accountVO) { + public void importProjectQuestion(List questions, String projectCode, Long companyId, AccountVO accountVO) { questions.forEach(questionVO -> { String topic = questionVO.getTopic(); @@ -157,7 +171,7 @@ public class QuestionBankService2 { || Objects.equals(BusinessConsts.TheoryType.judge.name(),questionVO.getType()) || Objects.equals(BusinessConsts.TheoryType.multi.name(),questionVO.getType())) ,String.format("题库目前只支持单选,多选和判断,题序[%s]",questionVO.getId())); - long answerCount = questionVO.getOptionList().stream().filter(QuestionOptionVO2::getCorrect).count(); + long answerCount = questionVO.getOptionList().stream().filter(PaperQuestionOptionVO2::getCorrect).count(); if (questionVO.isSelect() || questionVO.isJudge()) { BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(answerCount == 1, String.format("题序[%s]:单选或判断题[%s]正确答案应当有且只有一个!", questionVO.getId(),topic)); @@ -170,8 +184,8 @@ public class QuestionBankService2 { boolean isDefault = Project.isDefault(Project.valueOf(projectCode)); //默认项目导入题考虑是否有单位关联 if (isDefault) { - RaceQuestion2Example example = new RaceQuestion2Example(); - RaceQuestion2Example.Criteria criteria = example.createCriteria(); + PaperQuestionExample example = new PaperQuestionExample(); + PaperQuestionExample.Criteria criteria = example.createCriteria(); criteria.andProjectCodeIsNull(); if (Objects.nonNull(companyId)) { criteria.andCompanyIdEqualTo(companyId); @@ -181,25 +195,27 @@ public class QuestionBankService2 { questionDAO.deleteByExample(example); questions.forEach(questionVO -> { questionVO.setProjectCode(projectCode); - RaceQuestion2 question = questionVO.convert2DB(); + PaperQuestion question = questionVO.convert2DB(); question.setProjectCode(null); question.setCreateUserId(accountVO.getId()); question.setCreateTime(LocalDateTime.now()); question.setCompanyId(companyId); + question.setIsDel(BusinessConsts.DBLogicDelete.NORMAL.ordinal()); questionDAO.insert(question); }); } else { //非默认项目导入题 - RaceQuestion2Example example = new RaceQuestion2Example(); + PaperQuestionExample example = new PaperQuestionExample(); example.createCriteria().andProjectCodeEqualTo(projectCode); questionDAO.deleteByExample(example); questions.forEach(questionVO -> { questionVO.setProjectCode(projectCode); - RaceQuestion2 question = questionVO.convert2DB(); + PaperQuestion question = questionVO.convert2DB(); question.setProjectCode(projectCode); question.setCreateUserId(accountVO.getId()); question.setCreateTime(LocalDateTime.now()); + question.setIsDel(BusinessConsts.DBLogicDelete.NORMAL.ordinal()); questionDAO.insert(question); }); } @@ -208,7 +224,11 @@ public class QuestionBankService2 { - public void deleteQuestion(Long questionId) { - questionDAO.deleteByPrimaryKey(questionId); + public void deleteQuestion(List questionId) { + PaperQuestionExample example = new PaperQuestionExample(); + example.createCriteria().andIdIn(questionId); + PaperQuestion pq = new PaperQuestion(); + pq.setIsDel(BusinessConsts.DBLogicDelete.DELETE.ordinal()); + questionDAO.updateByExampleSelective(pq,example); } } diff --git a/src/main/java/club/joylink/rtss/vo/client/question/v2/QuestionOptionVO2.java b/src/main/java/club/joylink/rtss/vo/client/question/v2/PaperQuestionOptionVO2.java similarity index 79% rename from src/main/java/club/joylink/rtss/vo/client/question/v2/QuestionOptionVO2.java rename to src/main/java/club/joylink/rtss/vo/client/question/v2/PaperQuestionOptionVO2.java index c72c6df29..2ac63b2a3 100644 --- a/src/main/java/club/joylink/rtss/vo/client/question/v2/QuestionOptionVO2.java +++ b/src/main/java/club/joylink/rtss/vo/client/question/v2/PaperQuestionOptionVO2.java @@ -17,7 +17,7 @@ import java.util.List; @Getter @Setter @NoArgsConstructor -public class QuestionOptionVO2 implements Cloneable { +public class PaperQuestionOptionVO2 implements Cloneable { private Long id; private Long questionId; @@ -32,7 +32,7 @@ public class QuestionOptionVO2 implements Cloneable { @NotNull(message = "题目没有设置正确选项") private Boolean correct; - public QuestionOptionVO2(RaceQuestionOption questionOption) { + public PaperQuestionOptionVO2(RaceQuestionOption questionOption) { this.id = questionOption.getId(); this.questionId = questionOption.getQuestionId(); this.content = questionOption.getContent(); @@ -49,10 +49,10 @@ public class QuestionOptionVO2 implements Cloneable { return questionOption; } - public static List convert2VOList(List options){ - List voList = new ArrayList<>(); + public static List convert2VOList(List options){ + List voList = new ArrayList<>(); if(!CollectionUtils.isEmpty(options)) { - options.forEach(option -> voList.add(new QuestionOptionVO2(option))); + options.forEach(option -> voList.add(new PaperQuestionOptionVO2(option))); } return voList; } diff --git a/src/main/java/club/joylink/rtss/vo/client/question/v2/QuestionVO2.java b/src/main/java/club/joylink/rtss/vo/client/question/v2/PaperQuestionVO.java similarity index 75% rename from src/main/java/club/joylink/rtss/vo/client/question/v2/QuestionVO2.java rename to src/main/java/club/joylink/rtss/vo/client/question/v2/PaperQuestionVO.java index d1f68954e..be941c268 100644 --- a/src/main/java/club/joylink/rtss/vo/client/question/v2/QuestionVO2.java +++ b/src/main/java/club/joylink/rtss/vo/client/question/v2/PaperQuestionVO.java @@ -2,10 +2,8 @@ package club.joylink.rtss.vo.client.question.v2; import club.joylink.rtss.constants.BusinessConsts; import club.joylink.rtss.constants.Project; -import club.joylink.rtss.entity.RaceQuestion; -import club.joylink.rtss.entity.race2.RaceQuestion2; +import club.joylink.rtss.entity.question.PaperQuestion; import club.joylink.rtss.util.JsonUtils; -import club.joylink.rtss.vo.client.question.QuestionOptionVO; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -23,7 +21,7 @@ import java.util.stream.Collectors; @Getter @Setter @NoArgsConstructor -public class QuestionVO2 implements Cloneable { +public class PaperQuestionVO implements Cloneable { private Long id; @@ -43,7 +41,7 @@ public class QuestionVO2 implements Cloneable { /** *选项列表 */ - private List optionList; + private List optionList; private Long createUserId; @@ -57,43 +55,45 @@ public class QuestionVO2 implements Cloneable { */ private Float score = 1f; - public QuestionVO2(RaceQuestion2 question) { + public PaperQuestionVO(PaperQuestion question) { this.id = question.getId(); this.type = question.getType(); this.topic = question.getTopic(); this.projectCode = question.getProjectCode(); this.companyId = question.getCompanyId(); this.raceLable = question.getRaceLable(); - this.optionList = JsonUtils.readCollection(question.getQuestions(),ArrayList.class,QuestionOptionVO2.class); + this.optionList = JsonUtils.readCollection(question.getQuestions(),ArrayList.class, PaperQuestionOptionVO2.class); } - public RaceQuestion2 convert2DB() { - RaceQuestion2 question = new RaceQuestion2(); + public PaperQuestion convert2DB() { + PaperQuestion question = new PaperQuestion(); + question.setId(this.id); question.setType(type); question.setTopic(topic); question.setProjectCode(Project.isDefault(Project.valueOf(projectCode)) ? null : projectCode); question.setCompanyId(companyId); question.setQuestions(JsonUtils.writeValueAsString(this.optionList)); question.setRaceLable(this.raceLable); + return question; } - public static List convert2VOList(List questions){ - List voList = new ArrayList<>(); + public static List convert2VOList(List questions){ + List voList = new ArrayList<>(); if(!CollectionUtils.isEmpty(questions)) { - questions.forEach(e -> voList.add(new QuestionVO2(e))); + questions.forEach(e -> voList.add(new PaperQuestionVO(e))); } return voList; } @Override - public QuestionVO2 clone() throws CloneNotSupportedException { - QuestionVO2 clone = (QuestionVO2) super.clone(); + public PaperQuestionVO clone() throws CloneNotSupportedException { + PaperQuestionVO clone = (PaperQuestionVO) super.clone(); AtomicBoolean error = new AtomicBoolean(false); - List cloneList = optionList.stream().map(questionOption -> { + List cloneList = optionList.stream().map(questionOption -> { try { - return (QuestionOptionVO2) questionOption.clone(); + return (PaperQuestionOptionVO2) questionOption.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } diff --git a/src/main/java/club/joylink/rtss/vo/client/question/v2/RaceQuestion2WithBLOBs.java b/src/main/java/club/joylink/rtss/vo/client/question/v2/RaceQuestion2WithBLOBs.java deleted file mode 100644 index 6a94a610f..000000000 --- a/src/main/java/club/joylink/rtss/vo/client/question/v2/RaceQuestion2WithBLOBs.java +++ /dev/null @@ -1,22 +0,0 @@ -package club.joylink.rtss.vo.client.question.v2; - -import java.io.Serializable; - -import club.joylink.rtss.entity.race2.RaceQuestion2; -import lombok.Data; - -/** - * @author - * - */ -@Data -public class RaceQuestion2WithBLOBs extends RaceQuestion2 implements Serializable { - /** - * 问题内容 - */ - private String topic; - - private String questions; - - private static final long serialVersionUID = 1L; -} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 0c0134bca..7294eb458 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -50,6 +50,8 @@ spring: mybatis: mapper-locations: classpath:mybatis/mapper/*.xml type-aliases-package: club.joylink.rtss.entity + configuration: + map-underscore-to-camel-case: true pagehelper: helper-dialect: mysql diff --git a/src/main/resources/mybatis/mapper/RaceQuestion2DAO.xml b/src/main/resources/mybatis/mapper/PaperQuestionDAO.xml similarity index 70% rename from src/main/resources/mybatis/mapper/RaceQuestion2DAO.xml rename to src/main/resources/mybatis/mapper/PaperQuestionDAO.xml index f3bbfe1be..8b8db5270 100644 --- a/src/main/resources/mybatis/mapper/RaceQuestion2DAO.xml +++ b/src/main/resources/mybatis/mapper/PaperQuestionDAO.xml @@ -1,7 +1,7 @@ - - + + @@ -9,11 +9,13 @@ + - @@ -74,12 +76,12 @@ - id, `type`, create_user_id, create_time, project_code, company_id, race_lable,topic, questions + id, `type`, create_user_id, create_time, project_code, company_id, race_lable, is_del - - - - - select distinct - from race_question2 + , + + from paper_question @@ -128,34 +130,35 @@ - delete from race_question2 + delete from paper_question where id = #{id,jdbcType=BIGINT} - - delete from race_question2 + + delete from paper_question - - insert into race_question2 (id, `type`, create_user_id, - create_time, project_code, company_id, - race_lable, topic, questions - ) - values (#{id,jdbcType=BIGINT}, #{type,jdbcType=VARCHAR}, #{createUserId,jdbcType=BIGINT}, - #{createTime,jdbcType=TIMESTAMP}, #{projectCode,jdbcType=VARCHAR}, #{companyId,jdbcType=BIGINT}, - #{raceLable,jdbcType=VARCHAR}, #{topic,jdbcType=LONGVARCHAR}, #{questions,jdbcType=LONGVARCHAR} - ) + + insert into paper_question (id, `type`, create_user_id, + create_time, project_code, company_id, + race_lable, is_del, topic, + questions) + values (#{id,jdbcType=BIGINT}, #{type,jdbcType=VARCHAR}, #{createUserId,jdbcType=BIGINT}, + #{createTime,jdbcType=TIMESTAMP}, #{projectCode,jdbcType=VARCHAR}, #{companyId,jdbcType=BIGINT}, + #{raceLable,jdbcType=VARCHAR}, #{isDel,jdbcType=INTEGER}, #{topic,jdbcType=LONGVARCHAR}, + #{questions,jdbcType=LONGVARCHAR}) - - insert into race_question2 + + insert into paper_question id, @@ -178,6 +181,9 @@ race_lable, + + is_del, + topic, @@ -207,6 +213,9 @@ #{raceLable,jdbcType=VARCHAR}, + + #{isDel,jdbcType=INTEGER}, + #{topic,jdbcType=LONGVARCHAR}, @@ -215,14 +224,14 @@ - + select count(*) from paper_question - update race_question2 + update paper_question id = #{record.id,jdbcType=BIGINT}, @@ -245,6 +254,9 @@ race_lable = #{record.raceLable,jdbcType=VARCHAR}, + + is_del = #{record.isDel,jdbcType=INTEGER}, + topic = #{record.topic,jdbcType=LONGVARCHAR}, @@ -257,37 +269,40 @@ - - update race_question2 - set id = #{record.id,jdbcType=BIGINT}, - `type` = #{record.type,jdbcType=VARCHAR}, - create_user_id = #{record.createUserId,jdbcType=BIGINT}, - create_time = #{record.createTime,jdbcType=TIMESTAMP}, - project_code = #{record.projectCode,jdbcType=VARCHAR}, - company_id = #{record.companyId,jdbcType=BIGINT}, - race_lable = #{record.raceLable,jdbcType=VARCHAR}, + `type` = #{record.type,jdbcType=VARCHAR}, + create_user_id = #{record.createUserId,jdbcType=BIGINT}, + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + project_code = #{record.projectCode,jdbcType=VARCHAR}, + company_id = #{record.companyId,jdbcType=BIGINT}, + race_lable = #{record.raceLable,jdbcType=VARCHAR}, + is_del = #{record.isDel,jdbcType=INTEGER}, topic = #{record.topic,jdbcType=LONGVARCHAR}, questions = #{record.questions,jdbcType=LONGVARCHAR} + + + + --> + + update paper_question + set id = #{record.id,jdbcType=BIGINT}, + `type` = #{record.type,jdbcType=VARCHAR}, + create_user_id = #{record.createUserId,jdbcType=BIGINT}, + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + project_code = #{record.projectCode,jdbcType=VARCHAR}, + company_id = #{record.companyId,jdbcType=BIGINT}, + race_lable = #{record.raceLable,jdbcType=VARCHAR}, + is_del = #{record.isDel,jdbcType=INTEGER}, + topic = #{record.topic,jdbcType=LONGVARCHAR}, + questions = #{record.questions,jdbcType=LONGVARCHAR} + - - update race_question2 + + update paper_question `type` = #{type,jdbcType=VARCHAR}, @@ -307,6 +322,9 @@ race_lable = #{raceLable,jdbcType=VARCHAR}, + + is_del = #{isDel,jdbcType=INTEGER}, + topic = #{topic,jdbcType=LONGVARCHAR}, @@ -316,26 +334,28 @@ where id = #{id,jdbcType=BIGINT} - - - update race_question2 + + update paper_question set `type` = #{type,jdbcType=VARCHAR}, - create_user_id = #{createUserId,jdbcType=BIGINT}, - create_time = #{createTime,jdbcType=TIMESTAMP}, - project_code = #{projectCode,jdbcType=VARCHAR}, - company_id = #{companyId,jdbcType=BIGINT}, - race_lable = #{raceLable,jdbcType=VARCHAR}, + create_user_id = #{createUserId,jdbcType=BIGINT}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + project_code = #{projectCode,jdbcType=VARCHAR}, + company_id = #{companyId,jdbcType=BIGINT}, + race_lable = #{raceLable,jdbcType=VARCHAR}, + is_del = #{isDel,jdbcType=INTEGER}, topic = #{topic,jdbcType=LONGVARCHAR}, questions = #{questions,jdbcType=LONGVARCHAR} where id = #{id,jdbcType=BIGINT}