diff --git a/src/main/java/club/joylink/rtss/exception/PaperExceptionAssert.java b/src/main/java/club/joylink/rtss/exception/PaperExceptionAssert.java new file mode 100644 index 000000000..f5d68c0de --- /dev/null +++ b/src/main/java/club/joylink/rtss/exception/PaperExceptionAssert.java @@ -0,0 +1,38 @@ +package club.joylink.rtss.exception; + +import lombok.Getter; + +@Getter +public enum PaperExceptionAssert implements BusinessExceptionAssert { + PcExisted(60000,"试卷定义已经存在"), + PcNotExisted(60001,"试卷定义不存在"), + PcCanModify(60002,"试卷定义可以编辑修改"), + PcStoreSuccess(60003,"试卷定义存储成功"), + PrExisted(60004,"试卷规则存在"), + PrNotExisted(60005,"试卷规则不存在"), + PuExisted(60006,"用户试卷已经存在"), + PuNotExisted(60007,"用户试卷不存在"), + PcCanCreatePu(60008,"试卷定义可以生成用户试卷"), + PcCantCreatePu(60008,"试卷定义不可以生成用户试卷"), + PcNotHavePr(60009,"试卷定义没有试卷规则"), + PcHavePr(60010,"试卷定义有试卷规则"), + PqNotEnough(60011,"没有充足的符合试卷定义的试题"), + PqEnough(60012,"有充足的符合试卷定义的试题"), + PuNotStart(60013,"用户未开始答题"), + PuStart(60014,"用户开始答题"), + PuSubmit(60015,"用户已经交卷"), + PuNotSubmit(60016,"用户未交卷"), + PqExisted(60017,"试卷试题存在"), + PuqHaveTime(60018,"用户答题截止时间未到"), + PuqCanSubmit(60019,"用户可以提交试题答案") + ; + + int code; + + String message; + + private PaperExceptionAssert(int code, String message) { + this.code = code; + this.message = message; + } +} diff --git a/src/main/java/club/joylink/rtss/services/paper/PaperCompositionService.java b/src/main/java/club/joylink/rtss/services/paper/PaperCompositionService.java index c8f06fab0..44887b0bd 100644 --- a/src/main/java/club/joylink/rtss/services/paper/PaperCompositionService.java +++ b/src/main/java/club/joylink/rtss/services/paper/PaperCompositionService.java @@ -6,7 +6,7 @@ import club.joylink.rtss.entity.paper.PaperComposition; import club.joylink.rtss.entity.paper.PaperCompositionExample; import club.joylink.rtss.entity.paper.PaperRule; import club.joylink.rtss.entity.paper.PaperRuleExample; -import club.joylink.rtss.exception.BusinessExceptionAssertEnum; +import club.joylink.rtss.exception.PaperExceptionAssert; import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.paper.*; @@ -38,7 +38,7 @@ public class PaperCompositionService { public CreatePaperCompositionRspVo createPaperComposition(CreatePaperCompositionReqVo req, AccountVO user) { //根据项目和名称来查,如果存在则结束 List pcList = this.findCompositionByCompanyIdAndName(req.getCompanyId(), req.getName()); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(CollectionUtils.isEmpty(pcList), "试卷定义已经存在:companyId=" + req.getCompanyId() + " name=" + req.getName()); + PaperExceptionAssert.PcNotExisted.assertTrue(CollectionUtils.isEmpty(pcList), "试卷定义已经存在:companyId=" + req.getCompanyId() + " name=" + req.getName()); // PaperComposition newPc = new PaperComposition(); newPc.setName(req.getName()); @@ -49,7 +49,7 @@ public class PaperCompositionService { newPc.setCreatorId(user.getId()); newPc.setState(PaperCompositionState.Editing.getValue()); int newRt = compositionDAO.insertSelective(newPc); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(newRt > 0, "存储试卷定义失败"); + PaperExceptionAssert.PcStoreSuccess.assertTrue(newRt > 0, "存储试卷定义失败"); // pcList = this.findCompositionByCompanyIdAndName(req.getCompanyId(), req.getName()); newPc = pcList.get(0); @@ -75,7 +75,7 @@ public class PaperCompositionService { boolean exist = pcList.stream().anyMatch(c -> { return c.getId().compareTo(curPc.getId()) != 0; }); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotTrue(exist, "试卷定义已经存在:companyId=" + req.getCompanyId() + " name=" + req.getName()); + PaperExceptionAssert.PcExisted.assertNotTrue(exist, "试卷定义已经存在:companyId=" + req.getCompanyId() + " name=" + req.getName()); } // curPc.setName(req.getName()); @@ -110,7 +110,7 @@ public class PaperCompositionService { @Transactional(rollbackFor = Exception.class) public void lockPaperComposition(Long pcId, AccountVO user) { PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(null != curPc && PaperCompositionState.Editing.equals(PaperCompositionState.getItem(curPc.getState())), "试卷定义存在或非编辑中"); + PaperExceptionAssert.PcCanModify.assertTrue(null != curPc && PaperCompositionState.Editing.equals(PaperCompositionState.getItem(curPc.getState())), "试卷定义不存在或非编辑中"); // PaperComposition nPc = new PaperComposition(); nPc.setId(curPc.getId()); @@ -124,26 +124,28 @@ public class PaperCompositionService { @Transactional(rollbackFor = Exception.class) public void unlockPaperComposition(Long pcId, AccountVO user) { PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(null != curPc && PaperCompositionState.Locked.equals(PaperCompositionState.getItem(curPc.getState())), "试卷定义存在或非封存中"); + PaperExceptionAssert.PcCanModify.assertTrue(null != curPc && PaperCompositionState.Locked.equals(PaperCompositionState.getItem(curPc.getState())), "试卷定义不存在或非封存中"); // PaperComposition nPc = new PaperComposition(); nPc.setId(curPc.getId()); nPc.setState(PaperCompositionState.Editing.getValue()); compositionDAO.updateByPrimaryKeySelective(nPc); } + /** * 标记已封存的试卷已使用 */ @Transactional(rollbackFor = Exception.class) public void usePaperComposition(Long pcId) { PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId); - if(PaperCompositionState.Locked.equals(PaperCompositionState.getItem(curPc.getState()))){ + if (PaperCompositionState.Locked.equals(PaperCompositionState.getItem(curPc.getState()))) { PaperComposition nPc = new PaperComposition(); nPc.setId(curPc.getId()); nPc.setState(PaperCompositionState.Used.getValue()); compositionDAO.updateByPrimaryKeySelective(nPc); } } + /** * 删除试卷蓝图(只能删除处于编辑状态的) * @@ -176,7 +178,7 @@ public class PaperCompositionService { * 断言试卷蓝图可以修改 */ public void assertPaperCompositionCanModify(PaperComposition curPc) { - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(null != curPc && PaperCompositionState.Editing.equals(PaperCompositionState.getItem(curPc.getState())), "试卷定义不存在或状态非编辑中,不能修改,pcId = " + curPc.getId()); + PaperExceptionAssert.PcCanModify.assertTrue(null != curPc && PaperCompositionState.Editing.equals(PaperCompositionState.getItem(curPc.getState())), "试卷定义不存在或状态非编辑中,不能修改,pcId = " + curPc.getId()); } /** @@ -188,14 +190,14 @@ public class PaperCompositionService { PaperCompositionExample.Criteria pcExCriteria = pcEx.createCriteria(); if (null != req.getName()) { if (req.getNameLike()) { - pcExCriteria.andNameLike(String.format("%%%s%%",req.getName())); + pcExCriteria.andNameLike(String.format("%%%s%%", req.getName())); } else { pcExCriteria.andNameEqualTo(req.getName()); } } if (null != req.getProfile()) { if (req.getProfileLike()) { - pcExCriteria.andProfileLike(String.format("%%%s%%",req.getProfile())); + pcExCriteria.andProfileLike(String.format("%%%s%%", req.getProfile())); } else { pcExCriteria.andProfileEqualTo(req.getProfile()); } @@ -254,7 +256,7 @@ public class PaperCompositionService { @Transactional(readOnly = true) public PaperCompositionVo findPaperComposition(Long pcId, AccountVO user) { PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(curPc, "试卷定义不存在:id=" + pcId); + PaperExceptionAssert.PcExisted.assertTrue(null != curPc, "试卷定义不存在:id=" + pcId); List paperRuleList = this.findRuleByPcId(pcId); // PaperCompositionVo rt = PaperCompositionConvertor.convert(curPc, paperRuleList); diff --git a/src/main/java/club/joylink/rtss/services/paper/PaperRuleService.java b/src/main/java/club/joylink/rtss/services/paper/PaperRuleService.java index f3ef8512f..6b53e9fd3 100644 --- a/src/main/java/club/joylink/rtss/services/paper/PaperRuleService.java +++ b/src/main/java/club/joylink/rtss/services/paper/PaperRuleService.java @@ -5,7 +5,7 @@ import club.joylink.rtss.dao.paper.PaperRuleDAO; import club.joylink.rtss.entity.paper.PaperComposition; import club.joylink.rtss.entity.paper.PaperRule; import club.joylink.rtss.entity.paper.PaperRuleExample; -import club.joylink.rtss.exception.BusinessExceptionAssertEnum; +import club.joylink.rtss.exception.PaperExceptionAssert; import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.paper.CreatePaperRuleReqVo; import club.joylink.rtss.vo.paper.PaperQType; @@ -35,7 +35,7 @@ public class PaperRuleService { @Transactional(readOnly = true) private void assertPaperCompositionRuleCanModify(Long ruleId) { PaperRule rule = ruleDAO.selectByPrimaryKey(ruleId); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(rule); + PaperExceptionAssert.PrExisted.assertNotNull(rule); // compositionService.assertPaperCompositionCanModify(rule.getPcId()); } @@ -63,7 +63,7 @@ public class PaperRuleService { PaperRuleExample example = new PaperRuleExample(); example.createCriteria().andPcIdEqualTo(pcId).andSubtypeEqualTo(ruleType.getValue()); List list = ruleDAO.selectByExample(example); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(CollectionUtils.isEmpty(list),String.format("试卷定义(pcId=%s)的规则(%s)已经存在",pcId,ruleType.name())); + PaperExceptionAssert.PrNotExisted.assertTrue(CollectionUtils.isEmpty(list),String.format("试卷定义(pcId=%s)的规则(%s)已经存在",pcId,ruleType.name())); } /** * 更新(保存)试卷蓝图的规则 @@ -76,7 +76,7 @@ public class PaperRuleService { assertPaperCompositionRuleCanModify(req.getId()); // PaperComposition curPc = compositionDAO.selectByPrimaryKey(req.getPcId()); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(curPc, "试卷定义不存在:id=" + req.getPcId()); + PaperExceptionAssert.PcExisted.assertNotNull(curPc, "试卷定义不存在:id=" + req.getPcId()); // PaperRule updateRule = ruleDAO.selectByPrimaryKey(req.getId());//需要更新的规则 PaperRuleExample findRuleEx = new PaperRuleExample(); @@ -87,7 +87,7 @@ public class PaperRuleService { ruleDAO.updateByPrimaryKeySelective(rule); }else{//类型不变,更新 PaperRule findRule = findRuleList.get(0); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(updateRule.getId().compareTo(findRule.getId())==0,String.format("试卷定义规则已经存在,pcId=%s type=%s subType=%s",req.getPcId(),req.getType().name(),req.getSubtype().name())); + PaperExceptionAssert.PrNotExisted.assertTrue(updateRule.getId().compareTo(findRule.getId())==0,String.format("试卷定义规则已经存在,pcId=%s type=%s subType=%s",req.getPcId(),req.getType().name(),req.getSubtype().name())); ruleDAO.updateByPrimaryKeySelective(rule); } } diff --git a/src/main/java/club/joylink/rtss/services/paper/PaperUserCreateService.java b/src/main/java/club/joylink/rtss/services/paper/PaperUserCreateService.java index d2916b862..566242eba 100644 --- a/src/main/java/club/joylink/rtss/services/paper/PaperUserCreateService.java +++ b/src/main/java/club/joylink/rtss/services/paper/PaperUserCreateService.java @@ -10,7 +10,7 @@ import club.joylink.rtss.entity.paper.question.PaperQuestion; import club.joylink.rtss.entity.paper.question.PaperQuestionExample; import club.joylink.rtss.entity.training2.PublishedTraining2; import club.joylink.rtss.entity.training2.PublishedTraining2Example; -import club.joylink.rtss.exception.BusinessExceptionAssertEnum; +import club.joylink.rtss.exception.PaperExceptionAssert; import club.joylink.rtss.util.JsonUtils; import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.paper.CreatePaperRspVo; @@ -21,7 +21,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.CollectionUtils; import java.time.LocalDateTime; import java.util.ArrayList; @@ -59,16 +58,16 @@ public class PaperUserCreateService { public CreatePaperRspVo createPaper(Long pcId, AccountVO user) { // 检测是否创建过试卷 PaperUser oldPu = paperUserService.findByUserIdAndPcId(user.getId(), pcId); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(null == oldPu, "该用户的试卷已经存在,pcId = " + pcId); + PaperExceptionAssert.PcNotExisted.assertTrue(null == oldPu, "该用户的试卷已经存在,pcId = " + pcId); // 校验试卷蓝图 PaperComposition composition = compositionDAO.selectByPrimaryKey(pcId); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(composition, "创建试卷的试卷定义不存在,pcId = " + pcId); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(!PaperCompositionState.Editing.equals(PaperCompositionState.getItem(composition.getState())), "编辑中的试卷定义无法用于生成用户试卷,pcId = " + pcId); + PaperExceptionAssert.PcExisted.assertNotNull(composition, "创建试卷的试卷定义不存在,pcId = " + pcId); + PaperExceptionAssert.PcCanCreatePu.assertTrue(!PaperCompositionState.Editing.equals(PaperCompositionState.getItem(composition.getState())), "编辑中的试卷定义无法用于生成用户试卷,pcId = " + pcId); LocalDateTime now = LocalDateTime.now(); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(now.isAfter(composition.getStartTime()) && now.isBefore(composition.getEndTime()), "当前时间未在试卷启用时间内,不能创建试卷"); + PaperExceptionAssert.PcCanCreatePu.assertTrue(now.isAfter(composition.getStartTime()) && now.isBefore(composition.getEndTime()), "当前时间未在试卷启用时间内,不能创建试卷"); // 试卷蓝图规则 List ruleList = compositionService.findRuleByPcId(pcId); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertCollectionNotEmpty(ruleList, "试卷定义没有规则定义,无法生成用户试卷,pcId = " + pcId); + PaperExceptionAssert.PcHavePr.assertCollectionNotEmpty(ruleList, "试卷定义没有规则定义,无法生成用户试卷,pcId = " + pcId); // String companyId = composition.getCompanyId(); // 标记封存的试卷蓝图已使用 @@ -118,12 +117,12 @@ public class PaperUserCreateService { //符合条件的题目数目 long count = questionDAO.countByExample(questionExample); PaperQType.SubType subType = PaperQType.SubType.getItem(rule.getSubtype()); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(count >= qSum, "符合条件的理论题数目过少:pcId = " + pc.getId() + " pcName = " + pc.getName() + " companyId = " + pc.getCompanyId() + " ruleType = " + subType.name() + " ruleSum = " + qSum); + PaperExceptionAssert.PqEnough.assertTrue(count >= qSum, "符合条件的理论题数目过少:pcId = " + pc.getId() + " pcName = " + pc.getName() + " companyId = " + pc.getCompanyId() + " ruleType = " + subType.name() + " ruleSum = " + qSum); final String orderBy = "rand()"; questionExample.setOrderByClause(String.format("%s limit %s,%s", orderBy, 0, qSum)); List findRand = questionDAO.selectByExample(questionExample); //校验最终查询到的题目数目 - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(findRand.size() == qSum, "没有足够的符合条件的理论题目"); + PaperExceptionAssert.PqEnough.assertTrue(findRand.size() == qSum, "没有足够的符合条件的理论题目"); //将题目与试卷关联 findRand.forEach(q -> { PaperUserQuestion puq = new PaperUserQuestion(); @@ -147,12 +146,12 @@ public class PaperUserCreateService { //符合条件的题目数目 long count = trainingDAO.countByExample(questionExample); PaperQType.SubType subType = PaperQType.SubType.getItem(rule.getSubtype()); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(count >= qSum, "符合条件的实训题数目过少:pcId = " + pc.getId() + " pcName = " + pc.getName() + " companyId = " + pc.getCompanyId() + " ruleType = " + subType.name() + " ruleSum = " + qSum); + PaperExceptionAssert.PqEnough.assertTrue(count >= qSum, "符合条件的实训题数目过少:pcId = " + pc.getId() + " pcName = " + pc.getName() + " companyId = " + pc.getCompanyId() + " ruleType = " + subType.name() + " ruleSum = " + qSum); final String orderBy = "rand()"; questionExample.setOrderByClause(String.format("%s limit %s,%s", orderBy, 0, qSum)); List findRand = trainingDAO.selectByExample(questionExample); //校验最终查询到的题目数目 - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(findRand.size() == qSum, "没有足够的符合条件的实训题目"); + PaperExceptionAssert.PqEnough.assertTrue(findRand.size() == qSum, "没有足够的符合条件的实训题目"); //将题目与试卷关联 findRand.forEach(q -> { PaperUserQuestion puq = new PaperUserQuestion(); diff --git a/src/main/java/club/joylink/rtss/services/paper/PaperUserFindPageService.java b/src/main/java/club/joylink/rtss/services/paper/PaperUserFindPageService.java index 1eec417ff..8880500e9 100644 --- a/src/main/java/club/joylink/rtss/services/paper/PaperUserFindPageService.java +++ b/src/main/java/club/joylink/rtss/services/paper/PaperUserFindPageService.java @@ -5,7 +5,7 @@ import club.joylink.rtss.dao.paper.PaperUserDAO; import club.joylink.rtss.entity.paper.PaperComposition; import club.joylink.rtss.entity.paper.PaperUser; import club.joylink.rtss.entity.paper.PaperUserExample; -import club.joylink.rtss.exception.BusinessExceptionAssertEnum; +import club.joylink.rtss.exception.PaperExceptionAssert; import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.paper.FindPaperUserForCompositionReqVo; @@ -34,7 +34,7 @@ public class PaperUserFindPageService { PageVO page = new PageVO<>(); // PaperComposition pc = paperCompositionDAO.selectByPrimaryKey(req.getPcId()); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(pc); + PaperExceptionAssert.PcExisted.assertNotNull(pc,"试卷定义不存在"); PaperUserExample example = new PaperUserExample(); PaperUserExample.Criteria c = example.createCriteria().andPcIdEqualTo(req.getPcId()); switch (req.getFindType()){ diff --git a/src/main/java/club/joylink/rtss/services/paper/PaperUserService.java b/src/main/java/club/joylink/rtss/services/paper/PaperUserService.java index 9933247c8..fdb4f88bb 100644 --- a/src/main/java/club/joylink/rtss/services/paper/PaperUserService.java +++ b/src/main/java/club/joylink/rtss/services/paper/PaperUserService.java @@ -7,7 +7,7 @@ import club.joylink.rtss.entity.paper.question.PaperQuestion; import club.joylink.rtss.entity.paper.question.PaperQuestionExample; import club.joylink.rtss.entity.training2.PublishedTraining2; import club.joylink.rtss.entity.training2.PublishedTraining2Example; -import club.joylink.rtss.exception.BusinessExceptionAssertEnum; +import club.joylink.rtss.exception.PaperExceptionAssert; import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.paper.PaperQType; import club.joylink.rtss.vo.paper.PaperQuestionState; @@ -20,9 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestAttribute; import java.time.Duration; import java.time.LocalDateTime; @@ -60,7 +57,7 @@ public class PaperUserService { @Transactional(readOnly = true) public PaperUserWholeVo findPaperUser(Long puId, AccountVO user) { PaperUser paper = paperUserDAO.selectByPrimaryKey(puId); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(paper, "用户试卷不存在"); + PaperExceptionAssert.PuExisted.assertNotNull(paper, "用户试卷不存在"); // PaperComposition composition = compositionDAO.selectByPrimaryKey(paper.getPcId()); List ruleList = compositionService.findRuleByPcId(composition.getId()); @@ -98,8 +95,8 @@ public class PaperUserService { @Transactional(rollbackFor = Exception.class) public void paperStart(Long puId, AccountVO user) { PaperUser paper = paperUserDAO.selectByPrimaryKey(puId); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(paper, "该用户的试卷不存在,puId = " + puId); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNull(paper.getStartTime(), "用户已经开始答题"); + PaperExceptionAssert.PuExisted.assertNotNull(paper, "该用户的试卷不存在,puId = " + puId); + PaperExceptionAssert.PuNotStart.assertNull(paper.getStartTime(), "用户已经开始答题"); PaperUser startPaper = new PaperUser(); startPaper.setId(puId); startPaper.setStartTime(LocalDateTime.now()); @@ -114,9 +111,9 @@ public class PaperUserService { @Transactional(rollbackFor = Exception.class) public PaperSubmitRspVo paperSubmit(Long puId, AccountVO user) { PaperUser paper = paperUserDAO.selectByPrimaryKey(puId); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(paper, "该用户的试卷不存在,puId = " + puId); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(paper.getStartTime(), "用户未开始答题"); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNull(paper.getEndTime(), "用户已经交卷"); + PaperExceptionAssert.PuExisted.assertNotNull(paper, "该用户的试卷不存在,puId = " + puId); + PaperExceptionAssert.PuStart.assertNotNull(paper.getStartTime(), "用户未开始答题"); + PaperExceptionAssert.PuNotSubmit.assertNull(paper.getEndTime(), "用户已经交卷"); LocalDateTime now = LocalDateTime.now(); //记录交卷时间 PaperUser endPaper = new PaperUser(); diff --git a/src/main/java/club/joylink/rtss/services/paper/PaperUserSubmitAnswerService.java b/src/main/java/club/joylink/rtss/services/paper/PaperUserSubmitAnswerService.java index 78e61dc34..e6bb989d5 100644 --- a/src/main/java/club/joylink/rtss/services/paper/PaperUserSubmitAnswerService.java +++ b/src/main/java/club/joylink/rtss/services/paper/PaperUserSubmitAnswerService.java @@ -10,7 +10,7 @@ import club.joylink.rtss.entity.paper.PaperUserQuestion; import club.joylink.rtss.entity.paper.PaperUserQuestionExample; import club.joylink.rtss.entity.paper.question.PaperQuestion; import club.joylink.rtss.entity.paper.question.PaperQuestionExample; -import club.joylink.rtss.exception.BusinessExceptionAssertEnum; +import club.joylink.rtss.exception.PaperExceptionAssert; import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.paper.PaperQuestionState; import club.joylink.rtss.vo.paper.PaperSubmitAnswerReqVo; @@ -47,7 +47,7 @@ public class PaperUserSubmitAnswerService { puqExample.createCriteria().andPuIdEqualTo(req.getPuId()).andQuestionIdEqualTo(req.getPqId()); final List paperUserQuestionList = paperUserQuestionDAO.selectByExample(puqExample); final String pqNotExistMsg = String.format("用户试卷题目不存在,题目类型:%s 题目子类型:%s 题目id:%s 试卷id:%s",req.getType().name(),req.getSubType().name(),req.getPqId(),req.getPuId()); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertCollectionNotEmpty(paperUserQuestionList,pqNotExistMsg); + PaperExceptionAssert.PqExisted.assertCollectionNotEmpty(paperUserQuestionList,pqNotExistMsg); // final PaperUserQuestion puq = paperUserQuestionList.get(0); //用户试卷 @@ -88,9 +88,9 @@ public class PaperUserSubmitAnswerService { final LocalDateTime start = pu.getStartTime(); final LocalDateTime dead = start.plusMinutes(pc.getValidDuration()); //校验时间 - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotTrue(now.isAfter(dead), "剩余答题时间为0"); + PaperExceptionAssert.PuqHaveTime.assertTrue(now.isBefore(dead), "剩余答题时间为0"); //校验重复做题 - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(PaperQuestionState.Undo.equals(PaperQuestionState.getItem(puq.getState())), "只有未做的题才能提交答案"); + PaperExceptionAssert.PuqCanSubmit.assertTrue(PaperQuestionState.Undo.equals(PaperQuestionState.getItem(puq.getState())), "只有未做的题才能提交答案"); } /**