paper
This commit is contained in:
parent
b3ecb6c1d2
commit
c9e16545d4
@ -1,7 +1,6 @@
|
|||||||
package club.joylink.rtss.controller.paper;
|
package club.joylink.rtss.controller.paper;
|
||||||
|
|
||||||
import club.joylink.rtss.services.paper.PaperCompositionService;
|
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.AccountVO;
|
||||||
import club.joylink.rtss.vo.client.PageVO;
|
import club.joylink.rtss.vo.client.PageVO;
|
||||||
import club.joylink.rtss.vo.paper.*;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 试卷蓝图业务接口
|
* 试卷蓝图业务接口
|
||||||
* <p>
|
* <p>
|
||||||
@ -23,24 +20,27 @@ import java.util.List;
|
|||||||
public class PaperCompositionController {
|
public class PaperCompositionController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private PaperCompositionService compositionService;
|
private PaperCompositionService compositionService;
|
||||||
@Autowired
|
|
||||||
private PaperRuleService ruleService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建试卷蓝图
|
* 创建试卷蓝图包括规则定义
|
||||||
|
*
|
||||||
|
* @param orgId 组织id
|
||||||
*/
|
*/
|
||||||
@PostMapping
|
@PostMapping("/{orgId}")
|
||||||
public CreatePaperCompositionRspVo createPaperComposition(@RequestBody CreatePaperCompositionReqVo req, @RequestAttribute AccountVO user) {
|
public CreatePaperCompositionRspVo createPaperCompositionWithRuleForOrg(@PathVariable("orgId") Long orgId, @RequestBody PaperCompositionWithRuleVo req, @RequestAttribute AccountVO user) {
|
||||||
return compositionService.createPaperComposition(req, user);
|
req.setOrgId(orgId);
|
||||||
|
return this.compositionService.createPaperCompositionWithRule(req, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改试卷蓝图基础信息
|
* 更新试卷蓝图包括规则定义
|
||||||
*/
|
*/
|
||||||
@PutMapping("/basic")
|
@PutMapping
|
||||||
public void updatePaperCompositionProfile(@RequestBody PaperCompositionBasicVo req, @RequestAttribute AccountVO user) {
|
public void updatePaperCompositionWithRule(@RequestBody PaperCompositionWithRuleVo req, @RequestAttribute AccountVO user) {
|
||||||
compositionService.updatePaperCompositionBasic(req, user);
|
this.compositionService.updatePaperCompositionWithRule(req, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将编辑好的试卷蓝图封存
|
* 将编辑好的试卷蓝图封存
|
||||||
*/
|
*/
|
||||||
@ -71,71 +71,34 @@ public class PaperCompositionController {
|
|||||||
* 根据(组织id、试卷蓝图名称简介)分页查找试卷蓝图
|
* 根据(组织id、试卷蓝图名称简介)分页查找试卷蓝图
|
||||||
*/
|
*/
|
||||||
@PostMapping("/find/page")
|
@PostMapping("/find/page")
|
||||||
public PageVO<PaperCompositionVo> findPaperCompositionByPage(@RequestBody FindPaperCompositionPageReqVo req) {
|
public PageVO<PaperCompositionWithRuleVo> findPaperCompositionByPage(@RequestBody FindPaperCompositionPageReqVo req) {
|
||||||
|
|
||||||
return this.compositionService.findPaperCompositionByPage(req);
|
return this.compositionService.findPaperCompositionByPage(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据试卷蓝图名称简介分页查找某个组织的试卷蓝图
|
* 根据试卷蓝图名称简介分页查找某个组织的试卷蓝图
|
||||||
*/
|
*/
|
||||||
@PostMapping("/find/page/for/{orgId}")
|
@PostMapping("/find/page/for/{orgId}")
|
||||||
public PageVO<PaperCompositionVo> findPaperCompositionForOrgByPage(@PathVariable("orgId") Long orgId, @RequestBody FindPaperCompositionPageReqVo req) {
|
public PageVO<PaperCompositionWithRuleVo> findPaperCompositionForOrgByPage(@PathVariable("orgId") Long orgId, @RequestBody FindPaperCompositionPageReqVo req) {
|
||||||
req.setOrgId(orgId);
|
req.setOrgId(orgId);
|
||||||
return this.compositionService.findPaperCompositionByPage(req);
|
return this.compositionService.findPaperCompositionByPage(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据账户分页查找试卷蓝图
|
* 根据账户分页查找试卷蓝图
|
||||||
*/
|
*/
|
||||||
@PostMapping("/find/page/by/account")
|
@PostMapping("/find/page/by/account")
|
||||||
public PageVO<PaperCompositionVo> findAccountPaperCompositionByPage(@RequestBody FindPaperCompositionByAccountReqVo req) {
|
public PageVO<PaperCompositionWithRuleVo> findAccountPaperCompositionByPage(@RequestBody FindPaperCompositionByAccountReqVo req) {
|
||||||
|
|
||||||
return this.compositionService.findPaperCompositionByPageForAccount(req);
|
return this.compositionService.findPaperCompositionByPageForAccount(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取试卷完整的蓝图,包括规则
|
* 获取试卷完整的蓝图,包括规则
|
||||||
*
|
*
|
||||||
* @param pcId 试卷蓝图id
|
* @param pcId 试卷蓝图id
|
||||||
*/
|
*/
|
||||||
@GetMapping("/{pcId}")
|
@GetMapping("/{pcId}")
|
||||||
public PaperCompositionVo findPaperComposition(@PathVariable("pcId") Long pcId, @RequestAttribute AccountVO user) {
|
public PaperCompositionWithRuleVo findPaperComposition(@PathVariable("pcId") Long pcId, @RequestAttribute AccountVO user) {
|
||||||
return this.compositionService.findPaperComposition(pcId, 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<PaperRuleVo> findAllPaperCompositionRule(@RequestParam("pcId") Long pcId, @RequestAttribute AccountVO user) {
|
|
||||||
return this.ruleService.findAllPaperCompositionRule(pcId, user);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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<PaperRuleVo> 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<String> tags;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 该类型题目数量
|
||||||
|
*/
|
||||||
|
private Integer amount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每题分值
|
||||||
|
*/
|
||||||
|
private Integer score;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package club.joylink.rtss.services.paper;
|
package club.joylink.rtss.services.paper;
|
||||||
|
|
||||||
|
import club.joylink.rtss.controller.paper.PaperCompositionWithRuleVo;
|
||||||
import club.joylink.rtss.dao.SysAccountDAO;
|
import club.joylink.rtss.dao.SysAccountDAO;
|
||||||
import club.joylink.rtss.dao.paper.PaperCompositionDAO;
|
import club.joylink.rtss.dao.paper.PaperCompositionDAO;
|
||||||
import club.joylink.rtss.dao.paper.PaperRuleDAO;
|
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.client.PageVO;
|
||||||
import club.joylink.rtss.vo.paper.*;
|
import club.joylink.rtss.vo.paper.*;
|
||||||
import club.joylink.rtss.vo.paper.convertor.PaperCompositionConvertor;
|
import club.joylink.rtss.vo.paper.convertor.PaperCompositionConvertor;
|
||||||
|
import club.joylink.rtss.vo.paper.convertor.PaperRuleConvertor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,14 +39,12 @@ public class PaperCompositionService {
|
|||||||
private PaperRuleDAO ruleDAO;
|
private PaperRuleDAO ruleDAO;
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysAccountDAO sysAccountDAO;
|
private SysAccountDAO sysAccountDAO;
|
||||||
@Autowired
|
|
||||||
private PaperRuleService paperRuleService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建试卷蓝图
|
* 创建试卷蓝图包括规则定义
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public CreatePaperCompositionRspVo createPaperComposition(CreatePaperCompositionReqVo req, AccountVO user) {
|
public CreatePaperCompositionRspVo createPaperCompositionWithRule(PaperCompositionWithRuleVo req, AccountVO user) {
|
||||||
//根据项目和名称来查,如果存在则结束
|
//根据项目和名称来查,如果存在则结束
|
||||||
List<PaperComposition> pcList = this.findCompositionByCompanyIdAndName(req.getOrgId(), req.getName());
|
List<PaperComposition> pcList = this.findCompositionByCompanyIdAndName(req.getOrgId(), req.getName());
|
||||||
PaperExceptionAssert.PcNotExisted.assertTrue(CollectionUtils.isEmpty(pcList), "试卷定义已经存在:orgId=" + req.getOrgId() + " name=" + 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());
|
pcList = this.findCompositionByCompanyIdAndName(req.getOrgId(), req.getName());
|
||||||
newPc = pcList.get(0);
|
newPc = pcList.get(0);
|
||||||
//
|
//
|
||||||
|
if (!CollectionUtils.isEmpty(req.getRuleList())) {
|
||||||
|
final Long pcId = newPc.getId();
|
||||||
|
this.createPaperCompositionRule(pcId, req.getRuleList());
|
||||||
|
}
|
||||||
|
//
|
||||||
CreatePaperCompositionRspVo rsp = new CreatePaperCompositionRspVo();
|
CreatePaperCompositionRspVo rsp = new CreatePaperCompositionRspVo();
|
||||||
rsp.setId(newPc.getId());
|
rsp.setId(newPc.getId());
|
||||||
rsp.setName(newPc.getName());
|
rsp.setName(newPc.getName());
|
||||||
@ -77,10 +82,25 @@ public class PaperCompositionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改试卷蓝图基础信息(名称、项目、简介)
|
* 试卷蓝图添加规则
|
||||||
|
*/
|
||||||
|
private void createPaperCompositionRule(Long pcId, List<PaperCompositionWithRuleVo.PaperRuleVo> 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)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void updatePaperCompositionBasic(PaperCompositionBasicVo req, AccountVO user) {
|
public void updatePaperCompositionWithRule(PaperCompositionWithRuleVo req, AccountVO user) {
|
||||||
PaperComposition curPc = compositionDAO.selectByPrimaryKey(req.getId());
|
PaperComposition curPc = compositionDAO.selectByPrimaryKey(req.getId());
|
||||||
assertPaperCompositionCanModify(curPc);
|
assertPaperCompositionCanModify(curPc);
|
||||||
//
|
//
|
||||||
@ -93,17 +113,56 @@ public class PaperCompositionService {
|
|||||||
}
|
}
|
||||||
//
|
//
|
||||||
curPc.setName(req.getName());
|
curPc.setName(req.getName());
|
||||||
curPc.setProfile(req.getProfile());
|
|
||||||
curPc.setOrgId(req.getOrgId());
|
curPc.setOrgId(req.getOrgId());
|
||||||
curPc.setUpdateTime(LocalDateTime.now());
|
curPc.setProfile(req.getProfile());
|
||||||
curPc.setStartTime(req.getStartTime());
|
curPc.setStartTime(req.getStartTime());
|
||||||
curPc.setEndTime(req.getEndTime());
|
curPc.setEndTime(req.getEndTime());
|
||||||
curPc.setValidDuration(req.getValidDuration());
|
curPc.setValidDuration(req.getValidDuration());
|
||||||
curPc.setPassScore(req.getPassScore());
|
curPc.setPassScore(req.getPassScore());
|
||||||
curPc.setFullScore(req.getFullScore());
|
curPc.setFullScore(req.getFullScore());
|
||||||
|
curPc.setCreateTime(LocalDateTime.now());
|
||||||
|
curPc.setUpdateTime(LocalDateTime.now());
|
||||||
|
curPc.setCreatorId(user.getId());
|
||||||
|
curPc.setState(PaperCompositionState.Editing.getValue());
|
||||||
compositionDAO.updateByPrimaryKeySelective(curPc);
|
compositionDAO.updateByPrimaryKeySelective(curPc);
|
||||||
//校验分值
|
// 更新规则
|
||||||
PaperExceptionAssert.PcScore.assertTrue(paperRuleService.checkRulesScoreLessOrEqualFull(curPc.getId()),"规则总分值大于试卷总分值");
|
this.updateCompositionRule(req.getRuleList(), req.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateCompositionRule(List<PaperCompositionWithRuleVo.PaperRuleVo> updateRuleList, Long pcId) {
|
||||||
|
List<PaperRule> oldRuleList = this.findRuleByPcId(pcId);
|
||||||
|
Set<Long> oldRuleIdSet = new HashSet<>();
|
||||||
|
if (!CollectionUtils.isEmpty(oldRuleList)) {
|
||||||
|
oldRuleIdSet = oldRuleList.stream().map(PaperRule::getId).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
//
|
||||||
|
List<PaperCompositionWithRuleVo.PaperRuleVo> needUpdate = new ArrayList<>();
|
||||||
|
List<PaperCompositionWithRuleVo.PaperRuleVo> 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<Long> 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());
|
nPc.setState(PaperCompositionState.Locked.getValue());
|
||||||
compositionDAO.updateByPrimaryKeySelective(nPc);
|
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)
|
@Transactional(readOnly = true)
|
||||||
public PageVO<PaperCompositionVo> findPaperCompositionByPageForAccount(FindPaperCompositionByAccountReqVo req) {
|
public PageVO<PaperCompositionWithRuleVo> findPaperCompositionByPageForAccount(FindPaperCompositionByAccountReqVo req) {
|
||||||
PaperExceptionAssert.PpValid.assertTrue(null != req.getAccount() || null != req.getUserId(), "账号和用户id不能同时为空");
|
PaperExceptionAssert.PpValid.assertTrue(null != req.getAccount() || null != req.getUserId(), "账号和用户id不能同时为空");
|
||||||
Long userId = req.getUserId();
|
Long userId = req.getUserId();
|
||||||
if (null == userId) {
|
if (null == userId) {
|
||||||
@ -223,7 +282,7 @@ public class PaperCompositionService {
|
|||||||
return pcState.getValue();
|
return pcState.getValue();
|
||||||
}).collect(Collectors.toList()));
|
}).collect(Collectors.toList()));
|
||||||
//
|
//
|
||||||
PageVO<PaperCompositionVo> page = new PageVO<>();
|
PageVO<PaperCompositionWithRuleVo> page = new PageVO<>();
|
||||||
//
|
//
|
||||||
long sum = compositionDAO.countByExample(pcEx);
|
long sum = compositionDAO.countByExample(pcEx);
|
||||||
page.setTotal(sum);
|
page.setTotal(sum);
|
||||||
@ -269,7 +328,7 @@ public class PaperCompositionService {
|
|||||||
* 分页查找试卷蓝图
|
* 分页查找试卷蓝图
|
||||||
*/
|
*/
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public PageVO<PaperCompositionVo> findPaperCompositionByPage(FindPaperCompositionPageReqVo req) {
|
public PageVO<PaperCompositionWithRuleVo> findPaperCompositionByPage(FindPaperCompositionPageReqVo req) {
|
||||||
PaperCompositionExample pcEx = new PaperCompositionExample();
|
PaperCompositionExample pcEx = new PaperCompositionExample();
|
||||||
PaperCompositionExample.Criteria pcExCriteria = pcEx.createCriteria();
|
PaperCompositionExample.Criteria pcExCriteria = pcEx.createCriteria();
|
||||||
if (null != req.getOrgId()) {
|
if (null != req.getOrgId()) {
|
||||||
@ -294,7 +353,7 @@ public class PaperCompositionService {
|
|||||||
return pcState.getValue();
|
return pcState.getValue();
|
||||||
}).collect(Collectors.toList()));
|
}).collect(Collectors.toList()));
|
||||||
//
|
//
|
||||||
PageVO<PaperCompositionVo> page = new PageVO<>();
|
PageVO<PaperCompositionWithRuleVo> page = new PageVO<>();
|
||||||
long sum = compositionDAO.countByExample(pcEx);
|
long sum = compositionDAO.countByExample(pcEx);
|
||||||
page.setTotal(sum);
|
page.setTotal(sum);
|
||||||
page.setPageNum(req.getPageNum());
|
page.setPageNum(req.getPageNum());
|
||||||
@ -341,12 +400,12 @@ public class PaperCompositionService {
|
|||||||
* @param pcId 试卷蓝图id
|
* @param pcId 试卷蓝图id
|
||||||
*/
|
*/
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public PaperCompositionVo findPaperComposition(Long pcId, AccountVO user) {
|
public PaperCompositionWithRuleVo findPaperComposition(Long pcId, AccountVO user) {
|
||||||
PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId);
|
PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId);
|
||||||
PaperExceptionAssert.PcExisted.assertTrue(null != curPc, "试卷定义不存在:id=" + pcId);
|
PaperExceptionAssert.PcExisted.assertTrue(null != curPc, "试卷定义不存在:id=" + pcId);
|
||||||
List<PaperRule> paperRuleList = this.findRuleByPcId(pcId);
|
List<PaperRule> paperRuleList = this.findRuleByPcId(pcId);
|
||||||
//
|
//
|
||||||
PaperCompositionVo rt = PaperCompositionConvertor.convert(curPc, paperRuleList);
|
PaperCompositionWithRuleVo rt = PaperCompositionConvertor.convert(curPc, paperRuleList);
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -372,5 +431,35 @@ public class PaperCompositionService {
|
|||||||
example.createCriteria().andPcIdEqualTo(pcId);
|
example.createCriteria().andPcIdEqualTo(pcId);
|
||||||
return ruleDAO.selectByExample(example);
|
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<PaperRule> 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<PaperRule> 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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<PaperRule> 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<PaperRule> 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<PaperRuleVo> findAllPaperCompositionRule(Long pcId, AccountVO user) {
|
|
||||||
List<PaperRule> 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<PaperRule> 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<PaperRule> 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<PaperRule> 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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,6 @@
|
|||||||
package club.joylink.rtss.vo.paper;
|
package club.joylink.rtss.vo.paper;
|
||||||
|
|
||||||
|
import club.joylink.rtss.controller.paper.PaperCompositionWithRuleVo;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -12,7 +13,7 @@ public class PaperUserWholeVo {
|
|||||||
/**
|
/**
|
||||||
* 试卷蓝图
|
* 试卷蓝图
|
||||||
*/
|
*/
|
||||||
private PaperCompositionVo composition;
|
private PaperCompositionWithRuleVo composition;
|
||||||
/**
|
/**
|
||||||
* 用户试卷
|
* 用户试卷
|
||||||
*/
|
*/
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package club.joylink.rtss.vo.paper.convertor;
|
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.PaperComposition;
|
||||||
import club.joylink.rtss.entity.paper.PaperRule;
|
import club.joylink.rtss.entity.paper.PaperRule;
|
||||||
import club.joylink.rtss.vo.paper.PaperCompositionState;
|
import club.joylink.rtss.vo.paper.PaperCompositionState;
|
||||||
@ -9,8 +10,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PaperCompositionConvertor {
|
public class PaperCompositionConvertor {
|
||||||
public static PaperCompositionVo convert(PaperComposition from, List<PaperRule> ruleList){
|
public static PaperCompositionWithRuleVo convert(PaperComposition from, List<PaperRule> ruleList){
|
||||||
PaperCompositionVo to = new PaperCompositionVo();
|
PaperCompositionWithRuleVo to = new PaperCompositionWithRuleVo();
|
||||||
to.setId(from.getId());
|
to.setId(from.getId());
|
||||||
to.setName(from.getName());
|
to.setName(from.getName());
|
||||||
to.setProfile(from.getProfile());
|
to.setProfile(from.getProfile());
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package club.joylink.rtss.vo.paper.convertor;
|
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.entity.paper.PaperRule;
|
||||||
import club.joylink.rtss.util.JsonUtils;
|
import club.joylink.rtss.util.JsonUtils;
|
||||||
import club.joylink.rtss.vo.paper.CreatePaperRuleReqVo;
|
import club.joylink.rtss.vo.paper.CreatePaperRuleReqVo;
|
||||||
@ -11,8 +12,8 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class PaperRuleConvertor {
|
public class PaperRuleConvertor {
|
||||||
|
|
||||||
public static PaperRuleVo convert(PaperRule from) {
|
public static PaperCompositionWithRuleVo.PaperRuleVo convert(PaperRule from) {
|
||||||
PaperRuleVo to = new PaperRuleVo();
|
PaperCompositionWithRuleVo.PaperRuleVo to = new PaperCompositionWithRuleVo.PaperRuleVo();
|
||||||
to.setId(from.getId());
|
to.setId(from.getId());
|
||||||
to.setPcId(from.getPcId());
|
to.setPcId(from.getPcId());
|
||||||
to.setType(PaperQType.GroupType.getItem(from.getType()));
|
to.setType(PaperQType.GroupType.getItem(from.getType()));
|
||||||
@ -23,6 +24,21 @@ public class PaperRuleConvertor {
|
|||||||
return to;
|
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<String>()));
|
||||||
|
}
|
||||||
|
to.setScore(from.getScore());
|
||||||
|
to.setAmount(from.getAmount());
|
||||||
|
return to;
|
||||||
|
}
|
||||||
public static PaperRule convert(PaperRuleVo from) {
|
public static PaperRule convert(PaperRuleVo from) {
|
||||||
PaperRule to = new PaperRule();
|
PaperRule to = new PaperRule();
|
||||||
to.setId(from.getId());
|
to.setId(from.getId());
|
||||||
|
Loading…
Reference in New Issue
Block a user