【新增】试卷创建者信息查询接口;查询试卷增加按创建人筛选
This commit is contained in:
parent
346a265164
commit
2416d21a4f
@ -9,6 +9,7 @@ import club.joylink.rtss.vo.paper.CreatePaperCompositionRspVo;
|
||||
import club.joylink.rtss.vo.paper.FindPaperCompositionByAccountReqVo;
|
||||
import club.joylink.rtss.vo.paper.FindPaperCompositionPageReqVo;
|
||||
import club.joylink.rtss.vo.paper.PaperCompositionWithRuleVo;
|
||||
import club.joylink.rtss.vo.paper.PaperCompositionWithRuleVo.CreatorBasic;
|
||||
import java.util.List;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -109,6 +110,14 @@ public class PaperCompositionController {
|
||||
return this.compositionService.findPaperCompositionByPage(req);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询试卷的创建者的信息
|
||||
*/
|
||||
@GetMapping("/list/creatorInfo")
|
||||
public List<CreatorBasic> queryCreatorList(FindPaperCompositionPageReqVo req) {
|
||||
return compositionService.queryCreatorList(req);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据mapId查询蓝图的基本信息
|
||||
*
|
||||
|
@ -15,6 +15,7 @@ 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.*;
|
||||
import club.joylink.rtss.vo.paper.PaperCompositionWithRuleVo.CreatorBasic;
|
||||
import club.joylink.rtss.vo.paper.convertor.PaperCompositionConvertor;
|
||||
import club.joylink.rtss.vo.paper.convertor.PaperRuleConvertor;
|
||||
import com.github.pagehelper.Page;
|
||||
@ -37,6 +38,7 @@ import java.util.stream.Collectors;
|
||||
@Slf4j
|
||||
@Service
|
||||
public class PaperCompositionService {
|
||||
|
||||
@Autowired
|
||||
private PaperCompositionDAO compositionDAO;
|
||||
@Autowired
|
||||
@ -48,15 +50,22 @@ public class PaperCompositionService {
|
||||
* 创建试卷蓝图包括规则定义
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public CreatePaperCompositionRspVo createPaperCompositionWithRule(PaperCompositionWithRuleVo req, AccountVO user) {
|
||||
public CreatePaperCompositionRspVo createPaperCompositionWithRule(PaperCompositionWithRuleVo req,
|
||||
AccountVO user) {
|
||||
//根据项目和名称来查,如果存在则结束
|
||||
PaperExceptionAssert.PcNotExisted.assertTrue(Objects.nonNull(req.getMapId()), "请选择对应的线路");
|
||||
List<PaperComposition> pcList = this.findCompositionByCompanyIdAndName(req.getOrgId(), req.getName());
|
||||
PaperExceptionAssert.PcNotExisted.assertTrue(CollectionUtils.isEmpty(pcList), "试卷定义已经存在:orgId=" + req.getOrgId() + " name=" + req.getName());
|
||||
Optional<PaperCompositionWithRuleVo.PaperRuleVo> optionalRule = req.getRuleList().stream().filter(d->d.getSubtype() == PaperQType.SubType.Single
|
||||
&& (Objects.isNull(d.getSubTypeParam()) || Objects.isNull(d.getSubTypeParam().getClient()))).findAny();
|
||||
PaperExceptionAssert.PcNotExisted.assertTrue(Objects.nonNull(req.getMapId()),
|
||||
"请选择对应的线路");
|
||||
List<PaperComposition> pcList = this.findCompositionByCompanyIdAndName(req.getOrgId(),
|
||||
req.getName());
|
||||
PaperExceptionAssert.PcNotExisted.assertTrue(CollectionUtils.isEmpty(pcList),
|
||||
"试卷定义已经存在:orgId=" + req.getOrgId() + " name=" + req.getName());
|
||||
Optional<PaperCompositionWithRuleVo.PaperRuleVo> optionalRule = req.getRuleList().stream()
|
||||
.filter(d -> d.getSubtype() == PaperQType.SubType.Single
|
||||
&& (Objects.isNull(d.getSubTypeParam()) || Objects.isNull(
|
||||
d.getSubTypeParam().getClient()))).findAny();
|
||||
|
||||
PaperExceptionAssert.PcNotHavePr.assertTrue(optionalRule.isEmpty(), "试卷规则-单操缺少客户端的定义");
|
||||
PaperExceptionAssert.PcNotHavePr.assertTrue(optionalRule.isEmpty(),
|
||||
"试卷规则-单操缺少客户端的定义");
|
||||
PaperComposition newPc = PaperCompositionConvertor.convertToBean(req);
|
||||
|
||||
newPc.setCreateTime(LocalDateTime.now());
|
||||
@ -80,23 +89,34 @@ public class PaperCompositionService {
|
||||
}
|
||||
|
||||
private String ruleMapKey(PaperCompositionWithRuleVo.PaperRuleVo vo) {
|
||||
String key = String.format("%s-%s-%s",vo.getType(),vo.getSubtype(), CollectionUtils.isEmpty(vo.getTags())? "" : Joiner.on(",").join(vo.getTags()));
|
||||
String key = String.format("%s-%s-%s", vo.getType(), vo.getSubtype(),
|
||||
CollectionUtils.isEmpty(vo.getTags()) ? "" : Joiner.on(",").join(vo.getTags()));
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* 试卷蓝图添加规则
|
||||
*/
|
||||
private void createPaperCompositionRule(Long pcId, List<PaperCompositionWithRuleVo.PaperRuleVo> reqList) {
|
||||
Map<String,List<PaperCompositionWithRuleVo.PaperRuleVo>> tmpList = reqList.stream().collect(Collectors.groupingBy(this::ruleMapKey));
|
||||
private void createPaperCompositionRule(Long pcId,
|
||||
List<PaperCompositionWithRuleVo.PaperRuleVo> reqList) {
|
||||
Map<String, List<PaperCompositionWithRuleVo.PaperRuleVo>> tmpList = reqList.stream()
|
||||
.collect(Collectors.groupingBy(this::ruleMapKey));
|
||||
|
||||
for (PaperCompositionWithRuleVo.PaperRuleVo req : reqList) {
|
||||
req.setPcId(pcId);
|
||||
PaperQType.assertPaperSubTypeMatchGroupType(req.getSubtype(), req.getType());
|
||||
String key = this.ruleMapKey(req);
|
||||
List<PaperCompositionWithRuleVo.PaperRuleVo> voList = tmpList.get(key);
|
||||
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!CollectionUtils.isEmpty(voList) && voList.size() <= 1 ,String.format("试题规则类型[%s],规则类型[%s] 规则只能有一个", PaperQType.GroupType.getTypeName(req.getType()), PaperQType.SubType.getItemName(req.getSubtype())));
|
||||
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!CollectionUtils.isEmpty(req.getTags()) && req.getTags().size() <= 1 ,String.format("试题规则类型[%s],规则类型[%s],分类%s最多只能有一个", PaperQType.GroupType.getTypeName(req.getType()), PaperQType.SubType.getItemName(req.getSubtype()),req.getTags()));
|
||||
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(
|
||||
!CollectionUtils.isEmpty(voList) && voList.size() <= 1,
|
||||
String.format("试题规则类型[%s],规则类型[%s] 规则只能有一个",
|
||||
PaperQType.GroupType.getTypeName(req.getType()),
|
||||
PaperQType.SubType.getItemName(req.getSubtype())));
|
||||
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(
|
||||
!CollectionUtils.isEmpty(req.getTags()) && req.getTags().size() <= 1,
|
||||
String.format("试题规则类型[%s],规则类型[%s],分类%s最多只能有一个",
|
||||
PaperQType.GroupType.getTypeName(req.getType()),
|
||||
PaperQType.SubType.getItemName(req.getSubtype()), req.getTags()));
|
||||
PaperRule rule = PaperRuleConvertor.convert(req);
|
||||
ruleDAO.insertSelective(rule);
|
||||
}
|
||||
@ -107,18 +127,24 @@ public class PaperCompositionService {
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updatePaperCompositionWithRule(PaperCompositionWithRuleVo req, AccountVO user) {
|
||||
PaperExceptionAssert.PcNotExisted.assertTrue(Objects.nonNull(req.getMapId()), "请选择对应的线路");
|
||||
Optional<PaperCompositionWithRuleVo.PaperRuleVo> optionalRule = req.getRuleList().stream().filter(d->d.getSubtype() == PaperQType.SubType.Single
|
||||
&& (Objects.isNull(d.getSubTypeParam()) || Objects.isNull(d.getSubTypeParam().getClient()))).findAny();
|
||||
PaperExceptionAssert.PcNotHavePr.assertTrue(optionalRule.isEmpty(), "试卷规则-单操缺少客户端的定义");
|
||||
PaperExceptionAssert.PcNotExisted.assertTrue(Objects.nonNull(req.getMapId()),
|
||||
"请选择对应的线路");
|
||||
Optional<PaperCompositionWithRuleVo.PaperRuleVo> optionalRule = req.getRuleList().stream()
|
||||
.filter(d -> d.getSubtype() == PaperQType.SubType.Single
|
||||
&& (Objects.isNull(d.getSubTypeParam()) || Objects.isNull(
|
||||
d.getSubTypeParam().getClient()))).findAny();
|
||||
PaperExceptionAssert.PcNotHavePr.assertTrue(optionalRule.isEmpty(),
|
||||
"试卷规则-单操缺少客户端的定义");
|
||||
|
||||
PaperComposition curPc = compositionDAO.selectByPrimaryKey(req.getId());
|
||||
assertPaperCompositionCanModify(curPc);
|
||||
//
|
||||
List<PaperComposition> pcList = this.findCompositionByCompanyIdAndName(req.getOrgId(), req.getName());
|
||||
List<PaperComposition> pcList = this.findCompositionByCompanyIdAndName(req.getOrgId(),
|
||||
req.getName());
|
||||
if (!CollectionUtils.isEmpty(pcList)) {
|
||||
boolean exist = pcList.stream().anyMatch(c -> c.getId().compareTo(curPc.getId()) != 0);
|
||||
PaperExceptionAssert.PcExisted.assertNotTrue(exist, "试卷定义已经存在:orgId=" + req.getOrgId() + " name=" + req.getName());
|
||||
PaperExceptionAssert.PcExisted.assertNotTrue(exist,
|
||||
"试卷定义已经存在:orgId=" + req.getOrgId() + " name=" + req.getName());
|
||||
}
|
||||
PaperComposition newPc = PaperCompositionConvertor.convertToBean(req);
|
||||
newPc.setId(curPc.getId());
|
||||
@ -129,7 +155,8 @@ public class PaperCompositionService {
|
||||
this.updateCompositionRule(req.getRuleList(), req.getId());
|
||||
}
|
||||
|
||||
private void updateCompositionRule(List<PaperCompositionWithRuleVo.PaperRuleVo> updateRuleList, Long pcId) {
|
||||
private void updateCompositionRule(List<PaperCompositionWithRuleVo.PaperRuleVo> updateRuleList,
|
||||
Long pcId) {
|
||||
PaperRuleExample ruleExample = new PaperRuleExample();
|
||||
ruleExample.createCriteria().andPcIdEqualTo(pcId);
|
||||
this.ruleDAO.deleteByExample(ruleExample);
|
||||
@ -142,8 +169,11 @@ public class PaperCompositionService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void lockPaperComposition(Long pcId, AccountVO user) {
|
||||
PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId);
|
||||
PaperExceptionAssert.PcCanModify.assertTrue(null != curPc && PaperCompositionState.Editing.equals(PaperCompositionState.getItem(curPc.getState())), "试卷定义不存在或非编辑中");
|
||||
PaperExceptionAssert.PcScore.assertTrue(this.checkRulesScoreEqualFull(curPc.getId()), "规则总分值不等于试卷总分值");
|
||||
PaperExceptionAssert.PcCanModify.assertTrue(
|
||||
null != curPc && PaperCompositionState.Editing.equals(
|
||||
PaperCompositionState.getItem(curPc.getState())), "试卷定义不存在或非编辑中");
|
||||
PaperExceptionAssert.PcScore.assertTrue(this.checkRulesScoreEqualFull(curPc.getId()),
|
||||
"规则总分值不等于试卷总分值");
|
||||
//
|
||||
PaperComposition nPc = new PaperComposition();
|
||||
nPc.setId(curPc.getId());
|
||||
@ -158,7 +188,9 @@ public class PaperCompositionService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void unlockPaperComposition(Long pcId, AccountVO user) {
|
||||
PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId);
|
||||
PaperExceptionAssert.PcCanModify.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());
|
||||
@ -213,12 +245,17 @@ public class PaperCompositionService {
|
||||
* 断言试卷蓝图可以修改
|
||||
*/
|
||||
public void assertPaperCompositionCanModify(PaperComposition curPc) {
|
||||
PaperExceptionAssert.PcCanModify.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());
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public PageVO<PaperCompositionWithRuleVo> findPaperCompositionByPageForAccount(FindPaperCompositionByAccountReqVo req) {
|
||||
PaperExceptionAssert.PpValid.assertTrue(null != req.getAccount() || null != req.getUserId(), "账号和用户id不能同时为空");
|
||||
public PageVO<PaperCompositionWithRuleVo> findPaperCompositionByPageForAccount(
|
||||
FindPaperCompositionByAccountReqVo req) {
|
||||
PaperExceptionAssert.PpValid.assertTrue(null != req.getAccount() || null != req.getUserId(),
|
||||
"账号和用户id不能同时为空");
|
||||
Long userId = req.getUserId();
|
||||
if (null == userId) {
|
||||
SysAccountExample accountExample = new SysAccountExample();
|
||||
@ -242,7 +279,8 @@ public class PaperCompositionService {
|
||||
}
|
||||
//
|
||||
List<SysAccount> users = this.sysAccountDAO.selectByExample(accountExample);
|
||||
PaperExceptionAssert.PdValid.assertTrue(null != users && users.size() == 1, "用户不存在或根据账户信息匹配了多个");
|
||||
PaperExceptionAssert.PdValid.assertTrue(null != users && users.size() == 1,
|
||||
"用户不存在或根据账户信息匹配了多个");
|
||||
userId = users.get(0).getId();
|
||||
}
|
||||
//
|
||||
@ -296,7 +334,8 @@ public class PaperCompositionService {
|
||||
/**
|
||||
* 返回蓝图的列表基本信息
|
||||
*/
|
||||
public List<PaperCompositionWithRuleVo> findPaperCompositionList(FindPaperCompositionPageReqVo req){
|
||||
public List<PaperCompositionWithRuleVo> findPaperCompositionList(
|
||||
FindPaperCompositionPageReqVo req) {
|
||||
PaperCompositionExample pcEx = this.queryExample(req);
|
||||
pcEx.setOrderByClause(" create_time desc ");
|
||||
List<PaperComposition> sqlPage = compositionDAO.selectByExample(pcEx);
|
||||
@ -331,17 +370,22 @@ public class PaperCompositionService {
|
||||
pcExCriteria.andProfileEqualTo(req.getProfile());
|
||||
}
|
||||
}
|
||||
if (req.getCreatorId() != null) {
|
||||
pcExCriteria.andCreatorIdEqualTo(req.getCreatorId());
|
||||
}
|
||||
List<PaperCompositionState> findStates = req.stateList();
|
||||
pcExCriteria.andStateIn(findStates.stream().map(pcState -> {
|
||||
return pcState.getValue();
|
||||
}).collect(Collectors.toList()));
|
||||
return pcEx;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查找试卷蓝图
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public PageVO<PaperCompositionWithRuleVo> findPaperCompositionByPage(FindPaperCompositionPageReqVo req) {
|
||||
public PageVO<PaperCompositionWithRuleVo> findPaperCompositionByPage(
|
||||
FindPaperCompositionPageReqVo req) {
|
||||
PaperCompositionExample pcEx = this.queryExample(req);
|
||||
//
|
||||
//1--创建时间 2--更新时间 3--名称;默认值为1;
|
||||
@ -387,7 +431,11 @@ public class PaperCompositionService {
|
||||
if (null != sa) {
|
||||
PaperCompositionWithRuleVo.CreatorBasic rt = new PaperCompositionWithRuleVo.CreatorBasic();
|
||||
rt.setId(sa.getId());
|
||||
if (StringUtils.hasText(sa.getName())) {
|
||||
rt.setName(sa.getName());
|
||||
} else {
|
||||
rt.setName("昵称:" + sa.getNickname());
|
||||
}
|
||||
rt.setAccount(sa.getAccount());
|
||||
rt.setMobile(sa.getMobile());
|
||||
rt.setEmail(sa.getEmail());
|
||||
@ -435,20 +483,13 @@ public class PaperCompositionService {
|
||||
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();
|
||||
public List<CreatorBasic> queryCreatorList(FindPaperCompositionPageReqVo req) {
|
||||
List<CreatorBasic> creators = new ArrayList<>();
|
||||
List<PaperCompositionWithRuleVo> rules = findPaperCompositionList(req);
|
||||
rules.stream().map(PaperCompositionWithRuleVo::getCreatorId)
|
||||
.distinct()
|
||||
.forEach(creatorId -> creators.add(this.findCreatorInfo(creatorId)));
|
||||
return creators;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -456,7 +497,8 @@ public class PaperCompositionService {
|
||||
*/
|
||||
private boolean checkRulesScoreEqualFull(Long pcId) {
|
||||
PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId);
|
||||
PaperExceptionAssert.PcExisted.assertTrue(null != curPc, String.format("试卷定义[id = %s]不存在", pcId));
|
||||
PaperExceptionAssert.PcExisted.assertTrue(null != curPc,
|
||||
String.format("试卷定义[id = %s]不存在", pcId));
|
||||
List<PaperRule> ruleList = findRuleByPcId(pcId);
|
||||
int ruleScore = 0;
|
||||
if (!CollectionUtils.isEmpty(ruleList)) {
|
||||
|
@ -21,9 +21,9 @@ import java.util.Map;
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class FindPaperCompositionPageReqVo extends PageQueryVO {
|
||||
|
||||
/**
|
||||
* 组织id<br>
|
||||
* 选填<br>
|
||||
* 组织id<br> 选填<br>
|
||||
*/
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long orgId;
|
||||
@ -32,29 +32,24 @@ public class FindPaperCompositionPageReqVo extends PageQueryVO {
|
||||
*/
|
||||
private Long mapId;
|
||||
/**
|
||||
* 试卷蓝图名称<br>
|
||||
* 选填<br>
|
||||
* 试卷蓝图名称<br> 选填<br>
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 试卷蓝图名称--是否模糊查询,默认true<br>
|
||||
* 选填<br>
|
||||
* 试卷蓝图名称--是否模糊查询,默认true<br> 选填<br>
|
||||
*/
|
||||
private Boolean nameLike = true;
|
||||
/**
|
||||
* 试卷蓝图简介<br>
|
||||
* 选填<br>
|
||||
* 试卷蓝图简介<br> 选填<br>
|
||||
*/
|
||||
private String profile;
|
||||
/**
|
||||
* 试卷蓝图简介--是否模糊查询,默认true<br>
|
||||
* 选填<br>
|
||||
* 试卷蓝图简介--是否模糊查询,默认true<br> 选填<br>
|
||||
*/
|
||||
private Boolean profileLike = true;
|
||||
/**
|
||||
* 根据试卷蓝图的状态查找,默认值FindPcType.All<br>
|
||||
* All(1)-所有,Editing(2)-正在编辑的,CanUse(3)-可以用于生成试卷的,Locked(4)-封存,Used(5)-已经被使用过<br>
|
||||
* 选填<br>
|
||||
* All(1)-所有,Editing(2)-正在编辑的,CanUse(3)-可以用于生成试卷的,Locked(4)-封存,Used(5)-已经被使用过<br> 选填<br>
|
||||
*/
|
||||
private FindPcType findState = FindPcType.All;
|
||||
/**
|
||||
@ -72,9 +67,14 @@ public class FindPaperCompositionPageReqVo extends PageQueryVO {
|
||||
* 选填
|
||||
*/
|
||||
private Boolean desc = true;
|
||||
|
||||
/**
|
||||
* 试卷蓝图状态:1-正在编辑,2-封存(不能修改),3-已经被使用(不能修改删除)<br>
|
||||
* 选填<br>
|
||||
* 试卷创建者的ID
|
||||
*/
|
||||
private Long creatorId;
|
||||
|
||||
/**
|
||||
* 试卷蓝图状态:1-正在编辑,2-封存(不能修改),3-已经被使用(不能修改删除)<br> 选填<br>
|
||||
*/
|
||||
public List<PaperCompositionState> stateList() {
|
||||
return FindPcType.stateList(findState);
|
||||
|
Loading…
Reference in New Issue
Block a user