diff --git a/src/main/java/club/joylink/rtss/controller/paper/PaperCompositionController.java b/src/main/java/club/joylink/rtss/controller/paper/PaperCompositionController.java
index efe32b438..fe37a58f9 100644
--- a/src/main/java/club/joylink/rtss/controller/paper/PaperCompositionController.java
+++ b/src/main/java/club/joylink/rtss/controller/paper/PaperCompositionController.java
@@ -1,7 +1,6 @@
package club.joylink.rtss.controller.paper;
import club.joylink.rtss.services.paper.PaperCompositionService;
-import club.joylink.rtss.services.paper.PaperRuleService;
import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.paper.*;
@@ -9,8 +8,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
-import java.util.List;
-
/**
* 试卷蓝图业务接口
*
@@ -23,24 +20,27 @@ import java.util.List;
public class PaperCompositionController {
@Autowired
private PaperCompositionService compositionService;
- @Autowired
- private PaperRuleService ruleService;
/**
- * 创建试卷蓝图
+ * 创建试卷蓝图包括规则定义
+ *
+ * @param orgId 组织id
*/
- @PostMapping
- public CreatePaperCompositionRspVo createPaperComposition(@RequestBody CreatePaperCompositionReqVo req, @RequestAttribute AccountVO user) {
- return compositionService.createPaperComposition(req, user);
+ @PostMapping("/{orgId}")
+ public CreatePaperCompositionRspVo createPaperCompositionWithRuleForOrg(@PathVariable("orgId") Long orgId, @RequestBody PaperCompositionWithRuleVo req, @RequestAttribute AccountVO user) {
+ req.setOrgId(orgId);
+ return this.compositionService.createPaperCompositionWithRule(req, user);
}
+
/**
- * 修改试卷蓝图基础信息
+ * 更新试卷蓝图包括规则定义
*/
- @PutMapping("/basic")
- public void updatePaperCompositionProfile(@RequestBody PaperCompositionBasicVo req, @RequestAttribute AccountVO user) {
- compositionService.updatePaperCompositionBasic(req, user);
+ @PutMapping
+ public void updatePaperCompositionWithRule(@RequestBody PaperCompositionWithRuleVo req, @RequestAttribute AccountVO user) {
+ this.compositionService.updatePaperCompositionWithRule(req, user);
}
+
/**
* 将编辑好的试卷蓝图封存
*/
@@ -71,71 +71,34 @@ public class PaperCompositionController {
* 根据(组织id、试卷蓝图名称简介)分页查找试卷蓝图
*/
@PostMapping("/find/page")
- public PageVO findPaperCompositionByPage(@RequestBody FindPaperCompositionPageReqVo req) {
-
+ public PageVO findPaperCompositionByPage(@RequestBody FindPaperCompositionPageReqVo req) {
return this.compositionService.findPaperCompositionByPage(req);
}
+
/**
* 根据试卷蓝图名称简介分页查找某个组织的试卷蓝图
*/
@PostMapping("/find/page/for/{orgId}")
- public PageVO findPaperCompositionForOrgByPage(@PathVariable("orgId") Long orgId, @RequestBody FindPaperCompositionPageReqVo req) {
+ public PageVO findPaperCompositionForOrgByPage(@PathVariable("orgId") Long orgId, @RequestBody FindPaperCompositionPageReqVo req) {
req.setOrgId(orgId);
return this.compositionService.findPaperCompositionByPage(req);
}
+
/**
* 根据账户分页查找试卷蓝图
*/
@PostMapping("/find/page/by/account")
- public PageVO findAccountPaperCompositionByPage(@RequestBody FindPaperCompositionByAccountReqVo req) {
-
+ public PageVO findAccountPaperCompositionByPage(@RequestBody FindPaperCompositionByAccountReqVo req) {
return this.compositionService.findPaperCompositionByPageForAccount(req);
}
+
/**
* 获取试卷完整的蓝图,包括规则
*
* @param pcId 试卷蓝图id
*/
@GetMapping("/{pcId}")
- public PaperCompositionVo findPaperComposition(@PathVariable("pcId") Long pcId, @RequestAttribute AccountVO user) {
- return this.compositionService.findPaperComposition(pcId, user);
+ public PaperCompositionWithRuleVo findPaperComposition(@PathVariable("pcId") Long pcId, @RequestAttribute AccountVO user) {
+ return this.compositionService.findPaperComposition(pcId,user);
}
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
- /**
- * 试卷蓝图添加规则
- */
- @PostMapping("/rule")
- public void createPaperCompositionRule(@RequestBody CreatePaperRuleReqVo req, @RequestAttribute AccountVO user) {
- this.ruleService.createPaperCompositionRule(req, user);
- }
-
- /**
- * 更新(保存)试卷蓝图的规则
- */
- @PutMapping("/rule")
- public void updatePaperCompositionRule(@RequestBody PaperRuleVo req, @RequestAttribute AccountVO user) {
- this.ruleService.updatePaperCompositionRule(req, user);
- }
-
- /**
- * 删除试卷蓝图的规则
- *
- * @param ruleId 规则id
- */
- @DeleteMapping("/rule/{ruleId}")
- public void deletePaperCompositionRule(@PathVariable("ruleId") Long ruleId, @RequestAttribute AccountVO user) {
- this.ruleService.deletePaperCompositionRule(ruleId, user);
- }
-
- /**
- * 查询试卷蓝图的所有规则
- *
- * @param pcId 试卷蓝图的id
- */
- @GetMapping("/rule/all")
- public List findAllPaperCompositionRule(@RequestParam("pcId") Long pcId, @RequestAttribute AccountVO user) {
- return this.ruleService.findAllPaperCompositionRule(pcId, user);
- }
-
}
diff --git a/src/main/java/club/joylink/rtss/controller/paper/PaperCompositionWithRuleVo.java b/src/main/java/club/joylink/rtss/controller/paper/PaperCompositionWithRuleVo.java
new file mode 100644
index 000000000..4f01362d4
--- /dev/null
+++ b/src/main/java/club/joylink/rtss/controller/paper/PaperCompositionWithRuleVo.java
@@ -0,0 +1,121 @@
+package club.joylink.rtss.controller.paper;
+
+import club.joylink.rtss.vo.paper.PaperCompositionState;
+import club.joylink.rtss.vo.paper.PaperQType;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.time.LocalDateTime;
+import java.util.List;
+
+@Data
+public class PaperCompositionWithRuleVo {
+ /**
+ * 试卷蓝图id
+ */
+ @NotNull
+ @JsonSerialize(using = ToStringSerializer.class)
+ private Long id;
+
+ /**
+ * 试卷蓝图名称
+ */
+ private String name;
+
+ /**
+ * 试卷蓝图简介
+ */
+ private String profile;
+
+ /**
+ * 组织id
+ */
+ @JsonSerialize(using = ToStringSerializer.class)
+ private Long orgId;
+
+ /**
+ * 启用起始时间
+ */
+ private LocalDateTime startTime;
+
+ /**
+ * 启用截止时间
+ */
+ private LocalDateTime endTime;
+
+ /**
+ * 完成考试有效最长时长,单位min
+ */
+ private Integer validDuration;
+
+ /**
+ * 及格分
+ */
+ private Integer passScore;
+ /**
+ * 满分
+ */
+ private Integer fullScore;
+
+ /**
+ * 创建者id
+ */
+ private Long creatorId;
+
+ /**
+ * 创建时间
+ */
+ private LocalDateTime createTime;
+
+ /**
+ * 更新时间
+ */
+ private LocalDateTime updateTime;
+
+ /**
+ * 试卷蓝图状态:1-正在编辑,2-封存(不能修改),3-已经被使用(不能修改删除)
+ */
+ private PaperCompositionState state;
+
+ private List ruleList;
+
+ @Data
+ public static class PaperRuleVo {
+ /**
+ * 试卷规则定义id
+ */
+ @JsonSerialize(using = ToStringSerializer.class)
+ private Long id;
+ /**
+ * 试卷蓝图的id
+ */
+ @JsonSerialize(using = ToStringSerializer.class)
+ private Long pcId;
+ /**
+ * 试题类型:1-理论题,2-实训题
+ */
+ private PaperQType.GroupType type;
+
+ /**
+ * 规则类型:理论题(1-单选题,2-多选题,3-判断题);实训题(4-单操实训,5-场景实训)
+ */
+ private PaperQType.SubType subtype;
+
+ /**
+ * 筛选题目的标签,即根据标签来筛选题目
+ */
+ private List tags;
+
+ /**
+ * 该类型题目数量
+ */
+ private Integer amount;
+
+ /**
+ * 每题分值
+ */
+ private Integer score;
+ }
+}
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 d692ee690..83ae582ed 100644
--- a/src/main/java/club/joylink/rtss/services/paper/PaperCompositionService.java
+++ b/src/main/java/club/joylink/rtss/services/paper/PaperCompositionService.java
@@ -1,5 +1,6 @@
package club.joylink.rtss.services.paper;
+import club.joylink.rtss.controller.paper.PaperCompositionWithRuleVo;
import club.joylink.rtss.dao.SysAccountDAO;
import club.joylink.rtss.dao.paper.PaperCompositionDAO;
import club.joylink.rtss.dao.paper.PaperRuleDAO;
@@ -14,15 +15,16 @@ import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.paper.*;
import club.joylink.rtss.vo.paper.convertor.PaperCompositionConvertor;
+import club.joylink.rtss.vo.paper.convertor.PaperRuleConvertor;
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 org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
import java.util.stream.Collectors;
/**
@@ -37,14 +39,12 @@ public class PaperCompositionService {
private PaperRuleDAO ruleDAO;
@Autowired
private SysAccountDAO sysAccountDAO;
- @Autowired
- private PaperRuleService paperRuleService;
/**
- * 创建试卷蓝图
+ * 创建试卷蓝图包括规则定义
*/
@Transactional(rollbackFor = Exception.class)
- public CreatePaperCompositionRspVo createPaperComposition(CreatePaperCompositionReqVo req, AccountVO user) {
+ public CreatePaperCompositionRspVo createPaperCompositionWithRule(PaperCompositionWithRuleVo req, AccountVO user) {
//根据项目和名称来查,如果存在则结束
List pcList = this.findCompositionByCompanyIdAndName(req.getOrgId(), req.getName());
PaperExceptionAssert.PcNotExisted.assertTrue(CollectionUtils.isEmpty(pcList), "试卷定义已经存在:orgId=" + req.getOrgId() + " name=" + req.getName());
@@ -68,6 +68,11 @@ public class PaperCompositionService {
pcList = this.findCompositionByCompanyIdAndName(req.getOrgId(), req.getName());
newPc = pcList.get(0);
//
+ if (!CollectionUtils.isEmpty(req.getRuleList())) {
+ final Long pcId = newPc.getId();
+ this.createPaperCompositionRule(pcId, req.getRuleList());
+ }
+ //
CreatePaperCompositionRspVo rsp = new CreatePaperCompositionRspVo();
rsp.setId(newPc.getId());
rsp.setName(newPc.getName());
@@ -77,10 +82,25 @@ public class PaperCompositionService {
}
/**
- * 修改试卷蓝图基础信息(名称、项目、简介)
+ * 试卷蓝图添加规则
+ */
+ private void createPaperCompositionRule(Long pcId, List reqList) {
+ reqList.forEach(req -> {
+ req.setPcId(pcId);
+ //
+ PaperQType.assertPaperSubTypeMatchGroupType(req.getSubtype(), req.getType());
+ //
+ PaperRule rule = PaperRuleConvertor.convert(req);
+ //
+ ruleDAO.insertSelective(rule);
+ });
+ }
+
+ /**
+ * 更新试卷蓝图包括规则定义
*/
@Transactional(rollbackFor = Exception.class)
- public void updatePaperCompositionBasic(PaperCompositionBasicVo req, AccountVO user) {
+ public void updatePaperCompositionWithRule(PaperCompositionWithRuleVo req, AccountVO user) {
PaperComposition curPc = compositionDAO.selectByPrimaryKey(req.getId());
assertPaperCompositionCanModify(curPc);
//
@@ -93,17 +113,56 @@ public class PaperCompositionService {
}
//
curPc.setName(req.getName());
- curPc.setProfile(req.getProfile());
curPc.setOrgId(req.getOrgId());
- curPc.setUpdateTime(LocalDateTime.now());
+ curPc.setProfile(req.getProfile());
curPc.setStartTime(req.getStartTime());
curPc.setEndTime(req.getEndTime());
curPc.setValidDuration(req.getValidDuration());
curPc.setPassScore(req.getPassScore());
curPc.setFullScore(req.getFullScore());
+ curPc.setCreateTime(LocalDateTime.now());
+ curPc.setUpdateTime(LocalDateTime.now());
+ curPc.setCreatorId(user.getId());
+ curPc.setState(PaperCompositionState.Editing.getValue());
compositionDAO.updateByPrimaryKeySelective(curPc);
- //校验分值
- PaperExceptionAssert.PcScore.assertTrue(paperRuleService.checkRulesScoreLessOrEqualFull(curPc.getId()),"规则总分值大于试卷总分值");
+ // 更新规则
+ this.updateCompositionRule(req.getRuleList(), req.getId());
+ }
+
+ private void updateCompositionRule(List updateRuleList, Long pcId) {
+ List oldRuleList = this.findRuleByPcId(pcId);
+ Set oldRuleIdSet = new HashSet<>();
+ if (!CollectionUtils.isEmpty(oldRuleList)) {
+ oldRuleIdSet = oldRuleList.stream().map(PaperRule::getId).collect(Collectors.toSet());
+ }
+ //
+ List needUpdate = new ArrayList<>();
+ List needNew = new ArrayList<>();
+ for(PaperCompositionWithRuleVo.PaperRuleVo ur:updateRuleList){
+ if(null == ur.getId()){
+ needNew.add(ur);
+ }else{
+ PaperExceptionAssert.PdValid.assertTrue(oldRuleIdSet.contains(ur.getId()),String.format("试卷定义[id = %s]要更新的规则[id = %s]不存在",pcId,ur.getId()));
+ needUpdate.add(ur);
+ }
+ }
+ oldRuleIdSet.removeAll(needUpdate.stream().map(PaperCompositionWithRuleVo.PaperRuleVo::getId).collect(Collectors.toSet()));
+ Set neeDelete = oldRuleIdSet;
+ //
+ if(!CollectionUtils.isEmpty(needNew)){
+ this.createPaperCompositionRule(pcId,needNew);
+ }
+ if(!CollectionUtils.isEmpty(needUpdate)){
+ needUpdate.forEach(nu->{
+ PaperRule paperRule = PaperRuleConvertor.convert(nu);
+ this.ruleDAO.updateByPrimaryKeySelective(paperRule);
+ });
+ }
+ if(!CollectionUtils.isEmpty(neeDelete)){
+ neeDelete.forEach(nd->{
+ this.ruleDAO.deleteByPrimaryKey(nd);
+ });
+ }
}
/**
@@ -119,7 +178,7 @@ public class PaperCompositionService {
nPc.setState(PaperCompositionState.Locked.getValue());
compositionDAO.updateByPrimaryKeySelective(nPc);
// 封存试卷时校验总分值与规则总分值是否相等
- PaperExceptionAssert.PcScore.assertTrue(paperRuleService.checkRulesScoreEqualFull(curPc.getId()),"规则总分值不等于试卷总分值");
+ PaperExceptionAssert.PcScore.assertTrue(this.checkRulesScoreEqualFull(curPc.getId()), "规则总分值不等于试卷总分值");
}
/**
@@ -186,7 +245,7 @@ public class PaperCompositionService {
}
@Transactional(readOnly = true)
- public PageVO findPaperCompositionByPageForAccount(FindPaperCompositionByAccountReqVo req) {
+ public PageVO findPaperCompositionByPageForAccount(FindPaperCompositionByAccountReqVo req) {
PaperExceptionAssert.PpValid.assertTrue(null != req.getAccount() || null != req.getUserId(), "账号和用户id不能同时为空");
Long userId = req.getUserId();
if (null == userId) {
@@ -223,7 +282,7 @@ public class PaperCompositionService {
return pcState.getValue();
}).collect(Collectors.toList()));
//
- PageVO page = new PageVO<>();
+ PageVO page = new PageVO<>();
//
long sum = compositionDAO.countByExample(pcEx);
page.setTotal(sum);
@@ -269,7 +328,7 @@ public class PaperCompositionService {
* 分页查找试卷蓝图
*/
@Transactional(readOnly = true)
- public PageVO findPaperCompositionByPage(FindPaperCompositionPageReqVo req) {
+ public PageVO findPaperCompositionByPage(FindPaperCompositionPageReqVo req) {
PaperCompositionExample pcEx = new PaperCompositionExample();
PaperCompositionExample.Criteria pcExCriteria = pcEx.createCriteria();
if (null != req.getOrgId()) {
@@ -294,7 +353,7 @@ public class PaperCompositionService {
return pcState.getValue();
}).collect(Collectors.toList()));
//
- PageVO page = new PageVO<>();
+ PageVO page = new PageVO<>();
long sum = compositionDAO.countByExample(pcEx);
page.setTotal(sum);
page.setPageNum(req.getPageNum());
@@ -341,12 +400,12 @@ public class PaperCompositionService {
* @param pcId 试卷蓝图id
*/
@Transactional(readOnly = true)
- public PaperCompositionVo findPaperComposition(Long pcId, AccountVO user) {
+ public PaperCompositionWithRuleVo findPaperComposition(Long pcId, AccountVO user) {
PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId);
PaperExceptionAssert.PcExisted.assertTrue(null != curPc, "试卷定义不存在:id=" + pcId);
List paperRuleList = this.findRuleByPcId(pcId);
//
- PaperCompositionVo rt = PaperCompositionConvertor.convert(curPc, paperRuleList);
+ PaperCompositionWithRuleVo rt = PaperCompositionConvertor.convert(curPc, paperRuleList);
return rt;
}
@@ -372,5 +431,35 @@ public class PaperCompositionService {
example.createCriteria().andPcIdEqualTo(pcId);
return ruleDAO.selectByExample(example);
}
+ /**
+ * 校验规则当前规定的总分值是否小于等于试卷蓝图中的满分
+ */
+ private boolean checkRulesScoreLessOrEqualFull(Long pcId) {
+ PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId);
+ PaperExceptionAssert.PcExisted.assertTrue(null != curPc, String.format("试卷定义[id = %s]不存在", pcId));
+ List ruleList = findRuleByPcId(pcId);
+ int ruleScore = 0;
+ if (!CollectionUtils.isEmpty(ruleList)) {
+ ruleScore = ruleList.stream().mapToInt(rule -> {
+ return rule.getScore() * rule.getAmount();
+ }).sum();
+ }
+ return ruleScore <= curPc.getFullScore();
+ }
+ /**
+ * 校验规则当前规定的总分值是否等于试卷蓝图中的满分
+ */
+ private boolean checkRulesScoreEqualFull(Long pcId) {
+ PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId);
+ PaperExceptionAssert.PcExisted.assertTrue(null != curPc, String.format("试卷定义[id = %s]不存在", pcId));
+ List ruleList = findRuleByPcId(pcId);
+ int ruleScore = 0;
+ if (!CollectionUtils.isEmpty(ruleList)) {
+ ruleScore = ruleList.stream().mapToInt(rule -> {
+ return rule.getScore() * rule.getAmount();
+ }).sum();
+ }
+ return ruleScore == curPc.getFullScore();
+ }
}
diff --git a/src/main/java/club/joylink/rtss/services/paper/PaperRuleService.java b/src/main/java/club/joylink/rtss/services/paper/PaperRuleService.java
deleted file mode 100644
index 00908a22b..000000000
--- a/src/main/java/club/joylink/rtss/services/paper/PaperRuleService.java
+++ /dev/null
@@ -1,169 +0,0 @@
-package club.joylink.rtss.services.paper;
-
-import club.joylink.rtss.dao.paper.PaperCompositionDAO;
-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.PaperExceptionAssert;
-import club.joylink.rtss.vo.AccountVO;
-import club.joylink.rtss.vo.paper.CreatePaperRuleReqVo;
-import club.joylink.rtss.vo.paper.PaperQType;
-import club.joylink.rtss.vo.paper.PaperRuleVo;
-import club.joylink.rtss.vo.paper.convertor.PaperRuleConvertor;
-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.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
-
-@Service
-public class PaperRuleService {
- @Autowired
- private PaperCompositionDAO compositionDAO;
- @Autowired
- private PaperRuleDAO ruleDAO;
- @Autowired
- private PaperCompositionService compositionService;
-
- /**
- * 检测是否可以修改或更新规则
- */
- @Transactional(readOnly = true)
- private void assertPaperCompositionRuleCanModify(Long ruleId) {
- PaperRule rule = ruleDAO.selectByPrimaryKey(ruleId);
- PaperExceptionAssert.PrExisted.assertNotNull(rule);
- //
- compositionService.assertPaperCompositionCanModify(rule.getPcId());
- }
-
- /**
- * 试卷蓝图添加规则
- */
- @Transactional(rollbackFor = Exception.class)
- public void createPaperCompositionRule(CreatePaperRuleReqVo req, AccountVO user) {
- //
- PaperQType.assertPaperSubTypeMatchGroupType(req.getSubtype(), req.getType());
- //
- assertPaperCompositionRuleNotExist(req.getPcId(), req.getSubtype());
- compositionService.assertPaperCompositionCanModify(req.getPcId());
- //
- PaperRule rule = PaperRuleConvertor.convert(req);
- //
- ruleDAO.insertSelective(rule);
- //校验分值
- PaperExceptionAssert.PcScore.assertTrue(this.checkRulesScoreLessOrEqualFull(req.getPcId()),"规则总分值大于试卷总分值");
- }
-
- /**
- * 断言试卷蓝图某类型的规则不存在
- */
- @Transactional(readOnly = true)
- private void assertPaperCompositionRuleNotExist(Long pcId, PaperQType.SubType ruleType) {
- PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId);
- PaperRuleExample example = new PaperRuleExample();
- example.createCriteria().andPcIdEqualTo(pcId).andSubtypeEqualTo(ruleType.getValue());
- List list = ruleDAO.selectByExample(example);
- PaperExceptionAssert.PrNotExisted.assertTrue(CollectionUtils.isEmpty(list), String.format("试卷定义(pcId=%s)的规则(%s)已经存在", pcId, ruleType.name()));
- }
-
- /**
- * 更新(保存)试卷蓝图的规则
- */
- @Transactional(rollbackFor = Exception.class)
- public void updatePaperCompositionRule(PaperRuleVo req, AccountVO user) {
- //
- PaperQType.assertPaperSubTypeMatchGroupType(req.getSubtype(), req.getType());
- //
- assertPaperCompositionRuleCanModify(req.getId());
- //
- PaperComposition curPc = compositionDAO.selectByPrimaryKey(req.getPcId());
- PaperExceptionAssert.PcExisted.assertNotNull(curPc, "试卷定义不存在:id=" + req.getPcId());
- //
- PaperRule updateRule = ruleDAO.selectByPrimaryKey(req.getId());//需要更新的规则
- PaperRuleExample findRuleEx = new PaperRuleExample();
- findRuleEx.createCriteria().andPcIdEqualTo(req.getPcId()).andTypeEqualTo(req.getType().getValue()).andSubtypeEqualTo(req.getSubtype().getValue());
- List findRuleList = ruleDAO.selectByExample(findRuleEx);
- PaperRule rule = PaperRuleConvertor.convert(req);
- if (CollectionUtils.isEmpty(findRuleList)) {//新类型,直接更新
- ruleDAO.updateByPrimaryKeySelective(rule);
- } else {//类型不变,更新
- PaperRule findRule = findRuleList.get(0);
- 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);
- }
- //校验分值
- PaperExceptionAssert.PcScore.assertTrue(this.checkRulesScoreLessOrEqualFull(req.getPcId()),"规则总分值大于试卷总分值");
- }
-
- /**
- * 删除试卷蓝图的规则
- *
- * @param ruleId 规则id
- */
- @Transactional(rollbackFor = Exception.class)
- public void deletePaperCompositionRule(Long ruleId, AccountVO user) {
- //
- assertPaperCompositionRuleCanModify(ruleId);
- //
- ruleDAO.deleteByPrimaryKey(ruleId);
- }
-
- /**
- * 查询试卷蓝图的所有规则
- *
- * @param pcId 试卷蓝图的id
- */
- @Transactional(readOnly = true)
- public List findAllPaperCompositionRule(Long pcId, AccountVO user) {
- List list = findAllByPcId(pcId);
- if (CollectionUtils.isEmpty(list)) return new ArrayList<>();
- return list.stream().map(pr -> {
- return PaperRuleConvertor.convert(pr);
- }).collect(Collectors.toList());
- }
-
- @Transactional(readOnly = true)
- public List findAllByPcId(Long pcId) {
- PaperRuleExample example = new PaperRuleExample();
- example.createCriteria().andPcIdEqualTo(pcId);
- return ruleDAO.selectByExample(example);
- }
-
- /**
- * 校验规则当前规定的总分值是否小于等于试卷蓝图中的满分
- */
- @Transactional(readOnly = true)
- public boolean checkRulesScoreLessOrEqualFull(Long pcId) {
- PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId);
- PaperExceptionAssert.PcExisted.assertTrue(null != curPc, String.format("试卷定义[id = %s]不存在", pcId));
- List ruleList = findAllByPcId(pcId);
- int ruleScore = 0;
- if (!CollectionUtils.isEmpty(ruleList)) {
- ruleScore = ruleList.stream().mapToInt(rule -> {
- return rule.getScore() * rule.getAmount();
- }).sum();
- }
- return ruleScore <= curPc.getFullScore();
- }
-
- /**
- * 校验规则当前规定的总分值是否等于试卷蓝图中的满分
- */
- @Transactional(readOnly = true)
- public boolean checkRulesScoreEqualFull(Long pcId) {
- PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId);
- PaperExceptionAssert.PcExisted.assertTrue(null != curPc, String.format("试卷定义[id = %s]不存在", pcId));
- List ruleList = findAllByPcId(pcId);
- int ruleScore = 0;
- if (!CollectionUtils.isEmpty(ruleList)) {
- ruleScore = ruleList.stream().mapToInt(rule -> {
- return rule.getScore() * rule.getAmount();
- }).sum();
- }
- return ruleScore == curPc.getFullScore();
- }
-}
diff --git a/src/main/java/club/joylink/rtss/vo/paper/PaperUserWholeVo.java b/src/main/java/club/joylink/rtss/vo/paper/PaperUserWholeVo.java
index 5346d6237..b20dcc6e8 100644
--- a/src/main/java/club/joylink/rtss/vo/paper/PaperUserWholeVo.java
+++ b/src/main/java/club/joylink/rtss/vo/paper/PaperUserWholeVo.java
@@ -1,5 +1,6 @@
package club.joylink.rtss.vo.paper;
+import club.joylink.rtss.controller.paper.PaperCompositionWithRuleVo;
import lombok.Data;
import java.util.List;
@@ -12,7 +13,7 @@ public class PaperUserWholeVo {
/**
* 试卷蓝图
*/
- private PaperCompositionVo composition;
+ private PaperCompositionWithRuleVo composition;
/**
* 用户试卷
*/
diff --git a/src/main/java/club/joylink/rtss/vo/paper/convertor/PaperCompositionConvertor.java b/src/main/java/club/joylink/rtss/vo/paper/convertor/PaperCompositionConvertor.java
index 0f2a9f15a..428938249 100644
--- a/src/main/java/club/joylink/rtss/vo/paper/convertor/PaperCompositionConvertor.java
+++ b/src/main/java/club/joylink/rtss/vo/paper/convertor/PaperCompositionConvertor.java
@@ -1,5 +1,6 @@
package club.joylink.rtss.vo.paper.convertor;
+import club.joylink.rtss.controller.paper.PaperCompositionWithRuleVo;
import club.joylink.rtss.entity.paper.PaperComposition;
import club.joylink.rtss.entity.paper.PaperRule;
import club.joylink.rtss.vo.paper.PaperCompositionState;
@@ -9,8 +10,8 @@ import java.util.ArrayList;
import java.util.List;
public class PaperCompositionConvertor {
- public static PaperCompositionVo convert(PaperComposition from, List ruleList){
- PaperCompositionVo to = new PaperCompositionVo();
+ public static PaperCompositionWithRuleVo convert(PaperComposition from, List ruleList){
+ PaperCompositionWithRuleVo to = new PaperCompositionWithRuleVo();
to.setId(from.getId());
to.setName(from.getName());
to.setProfile(from.getProfile());
diff --git a/src/main/java/club/joylink/rtss/vo/paper/convertor/PaperRuleConvertor.java b/src/main/java/club/joylink/rtss/vo/paper/convertor/PaperRuleConvertor.java
index c75304f30..ee5d22433 100644
--- a/src/main/java/club/joylink/rtss/vo/paper/convertor/PaperRuleConvertor.java
+++ b/src/main/java/club/joylink/rtss/vo/paper/convertor/PaperRuleConvertor.java
@@ -1,5 +1,6 @@
package club.joylink.rtss.vo.paper.convertor;
+import club.joylink.rtss.controller.paper.PaperCompositionWithRuleVo;
import club.joylink.rtss.entity.paper.PaperRule;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.paper.CreatePaperRuleReqVo;
@@ -11,8 +12,8 @@ import java.util.ArrayList;
public class PaperRuleConvertor {
- public static PaperRuleVo convert(PaperRule from) {
- PaperRuleVo to = new PaperRuleVo();
+ public static PaperCompositionWithRuleVo.PaperRuleVo convert(PaperRule from) {
+ PaperCompositionWithRuleVo.PaperRuleVo to = new PaperCompositionWithRuleVo.PaperRuleVo();
to.setId(from.getId());
to.setPcId(from.getPcId());
to.setType(PaperQType.GroupType.getItem(from.getType()));
@@ -23,6 +24,21 @@ public class PaperRuleConvertor {
return to;
}
+ public static PaperRule convert(PaperCompositionWithRuleVo.PaperRuleVo from) {
+ PaperRule to = new PaperRule();
+ to.setId(from.getId());
+ to.setPcId(from.getPcId());
+ to.setType(from.getType().getValue());
+ to.setSubtype(from.getSubtype().getValue());
+ if (!CollectionUtils.isEmpty(from.getTags())) {
+ to.setTags(JsonUtils.writeValueAsString(from.getTags()));
+ } else {
+ to.setTags(JsonUtils.writeValueAsString(new ArrayList()));
+ }
+ to.setScore(from.getScore());
+ to.setAmount(from.getAmount());
+ return to;
+ }
public static PaperRule convert(PaperRuleVo from) {
PaperRule to = new PaperRule();
to.setId(from.getId());