【新增】试卷创建者信息查询接口;查询试卷增加按创建人筛选

This commit is contained in:
thesai 2024-04-10 14:53:34 +08:00
parent 346a265164
commit 2416d21a4f
3 changed files with 492 additions and 441 deletions

View File

@ -9,6 +9,7 @@ import club.joylink.rtss.vo.paper.CreatePaperCompositionRspVo;
import club.joylink.rtss.vo.paper.FindPaperCompositionByAccountReqVo; import club.joylink.rtss.vo.paper.FindPaperCompositionByAccountReqVo;
import club.joylink.rtss.vo.paper.FindPaperCompositionPageReqVo; import club.joylink.rtss.vo.paper.FindPaperCompositionPageReqVo;
import club.joylink.rtss.vo.paper.PaperCompositionWithRuleVo; import club.joylink.rtss.vo.paper.PaperCompositionWithRuleVo;
import club.joylink.rtss.vo.paper.PaperCompositionWithRuleVo.CreatorBasic;
import java.util.List; import java.util.List;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -109,6 +110,14 @@ public class PaperCompositionController {
return this.compositionService.findPaperCompositionByPage(req); return this.compositionService.findPaperCompositionByPage(req);
} }
/**
* 查询试卷的创建者的信息
*/
@GetMapping("/list/creatorInfo")
public List<CreatorBasic> queryCreatorList(FindPaperCompositionPageReqVo req) {
return compositionService.queryCreatorList(req);
}
/** /**
* 根据mapId查询蓝图的基本信息 * 根据mapId查询蓝图的基本信息
* *

View File

@ -15,6 +15,7 @@ import club.joylink.rtss.exception.PaperExceptionAssert;
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.*;
import club.joylink.rtss.vo.paper.PaperCompositionWithRuleVo.CreatorBasic;
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 club.joylink.rtss.vo.paper.convertor.PaperRuleConvertor;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
@ -37,139 +38,170 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
@Service @Service
public class PaperCompositionService { public class PaperCompositionService {
@Autowired
private PaperCompositionDAO compositionDAO;
@Autowired
private PaperRuleDAO ruleDAO;
@Autowired
private SysAccountDAO sysAccountDAO;
/** @Autowired
* 创建试卷蓝图包括规则定义 private PaperCompositionDAO compositionDAO;
*/ @Autowired
@Transactional(rollbackFor = Exception.class) private PaperRuleDAO ruleDAO;
public CreatePaperCompositionRspVo createPaperCompositionWithRule(PaperCompositionWithRuleVo req, AccountVO user) { @Autowired
//根据项目和名称来查如果存在则结束 private SysAccountDAO sysAccountDAO;
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(), "试卷规则-单操缺少客户端的定义"); /**
PaperComposition newPc = PaperCompositionConvertor.convertToBean(req); * 创建试卷蓝图包括规则定义
*/
@Transactional(rollbackFor = Exception.class)
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();
newPc.setCreateTime(LocalDateTime.now()); PaperExceptionAssert.PcNotHavePr.assertTrue(optionalRule.isEmpty(),
newPc.setUpdateTime(LocalDateTime.now()); "试卷规则-单操缺少客户端的定义");
newPc.setCreatorId(user.getId()); PaperComposition newPc = PaperCompositionConvertor.convertToBean(req);
newPc.setUpdateId(user.getId());
newPc.setState(PaperCompositionState.Editing.getValue());
compositionDAO.insertSelective(newPc);
if (!CollectionUtils.isEmpty(req.getRuleList())) { newPc.setCreateTime(LocalDateTime.now());
final Long pcId = newPc.getId(); newPc.setUpdateTime(LocalDateTime.now());
this.createPaperCompositionRule(pcId, req.getRuleList()); newPc.setCreatorId(user.getId());
} newPc.setUpdateId(user.getId());
// newPc.setState(PaperCompositionState.Editing.getValue());
CreatePaperCompositionRspVo rsp = new CreatePaperCompositionRspVo(); compositionDAO.insertSelective(newPc);
rsp.setId(newPc.getId());
rsp.setName(newPc.getName()); if (!CollectionUtils.isEmpty(req.getRuleList())) {
rsp.setProfile(newPc.getProfile()); final Long pcId = newPc.getId();
rsp.setOrgId(newPc.getOrgId()); this.createPaperCompositionRule(pcId, req.getRuleList());
return rsp;
} }
//
CreatePaperCompositionRspVo rsp = new CreatePaperCompositionRspVo();
rsp.setId(newPc.getId());
rsp.setName(newPc.getName());
rsp.setProfile(newPc.getProfile());
rsp.setOrgId(newPc.getOrgId());
return rsp;
}
private String ruleMapKey(PaperCompositionWithRuleVo.PaperRuleVo vo){ 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(),
return key; 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));
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()));
PaperRule rule = PaperRuleConvertor.convert(req);
ruleDAO.insertSelective(rule);
} }
}
/** /**
* 试卷蓝图添加规则 * 更新试卷蓝图包括规则定义
*/ */
private void createPaperCompositionRule(Long pcId, List<PaperCompositionWithRuleVo.PaperRuleVo> reqList) { @Transactional(rollbackFor = Exception.class)
Map<String,List<PaperCompositionWithRuleVo.PaperRuleVo>> tmpList = reqList.stream().collect(Collectors.groupingBy(this::ruleMapKey)); 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(),
"试卷规则-单操缺少客户端的定义");
for (PaperCompositionWithRuleVo.PaperRuleVo req : reqList) { PaperComposition curPc = compositionDAO.selectByPrimaryKey(req.getId());
req.setPcId(pcId); assertPaperCompositionCanModify(curPc);
PaperQType.assertPaperSubTypeMatchGroupType(req.getSubtype(), req.getType()); //
String key = this.ruleMapKey(req); List<PaperComposition> pcList = this.findCompositionByCompanyIdAndName(req.getOrgId(),
List<PaperCompositionWithRuleVo.PaperRuleVo> voList = tmpList.get(key); req.getName());
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!CollectionUtils.isEmpty(voList) && voList.size() <= 1 ,String.format("试题规则类型[%s],规则类型[%s] 规则只能有一个", PaperQType.GroupType.getTypeName(req.getType()), PaperQType.SubType.getItemName(req.getSubtype()))); if (!CollectionUtils.isEmpty(pcList)) {
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())); boolean exist = pcList.stream().anyMatch(c -> c.getId().compareTo(curPc.getId()) != 0);
PaperRule rule = PaperRuleConvertor.convert(req); PaperExceptionAssert.PcExisted.assertNotTrue(exist,
ruleDAO.insertSelective(rule); "试卷定义已经存在orgId=" + req.getOrgId() + " name=" + req.getName());
}
} }
PaperComposition newPc = PaperCompositionConvertor.convertToBean(req);
newPc.setId(curPc.getId());
newPc.setUpdateTime(LocalDateTime.now());
curPc.setUpdateId(user.getId());
compositionDAO.updateByPrimaryKeySelective(newPc);
// 更新规则
this.updateCompositionRule(req.getRuleList(), req.getId());
}
/** private void updateCompositionRule(List<PaperCompositionWithRuleVo.PaperRuleVo> updateRuleList,
* 更新试卷蓝图包括规则定义 Long pcId) {
*/ PaperRuleExample ruleExample = new PaperRuleExample();
@Transactional(rollbackFor = Exception.class) ruleExample.createCriteria().andPcIdEqualTo(pcId);
public void updatePaperCompositionWithRule(PaperCompositionWithRuleVo req, AccountVO user) { this.ruleDAO.deleteByExample(ruleExample);
PaperExceptionAssert.PcNotExisted.assertTrue(Objects.nonNull(req.getMapId()), "请选择对应的线路"); this.createPaperCompositionRule(pcId, updateRuleList);
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()); @Transactional(rollbackFor = Exception.class)
if (!CollectionUtils.isEmpty(pcList)) { public void lockPaperComposition(Long pcId, AccountVO user) {
boolean exist = pcList.stream().anyMatch(c ->c.getId().compareTo(curPc.getId()) != 0); PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId);
PaperExceptionAssert.PcExisted.assertNotTrue(exist, "试卷定义已经存在orgId=" + req.getOrgId() + " name=" + req.getName()); PaperExceptionAssert.PcCanModify.assertTrue(
} null != curPc && PaperCompositionState.Editing.equals(
PaperComposition newPc = PaperCompositionConvertor.convertToBean(req); PaperCompositionState.getItem(curPc.getState())), "试卷定义不存在或非编辑中");
newPc.setId(curPc.getId()); PaperExceptionAssert.PcScore.assertTrue(this.checkRulesScoreEqualFull(curPc.getId()),
newPc.setUpdateTime(LocalDateTime.now()); "规则总分值不等于试卷总分值");
curPc.setUpdateId(user.getId()); //
compositionDAO.updateByPrimaryKeySelective(newPc); PaperComposition nPc = new PaperComposition();
// 更新规则 nPc.setId(curPc.getId());
this.updateCompositionRule(req.getRuleList(), req.getId()); nPc.setState(PaperCompositionState.Locked.getValue());
} compositionDAO.updateByPrimaryKeySelective(nPc);
// 封存试卷时校验总分值与规则总分值是否相等
}
private void updateCompositionRule(List<PaperCompositionWithRuleVo.PaperRuleVo> updateRuleList, Long pcId) { /**
PaperRuleExample ruleExample = new PaperRuleExample(); * 将封存的试卷蓝图设置失效
ruleExample.createCriteria().andPcIdEqualTo(pcId); */
this.ruleDAO.deleteByExample(ruleExample); @Transactional(rollbackFor = Exception.class)
this.createPaperCompositionRule(pcId,updateRuleList); public void unlockPaperComposition(Long pcId, AccountVO user) {
} PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId);
PaperExceptionAssert.PcCanModify.assertTrue(
null != curPc && PaperCompositionState.Locked.equals(
PaperCompositionState.getItem(curPc.getState())), "试卷定义不存在或非封存中");
//
PaperComposition nPc = new PaperComposition();
nPc.setId(curPc.getId());
nPc.setState(PaperCompositionState.Invalid.getValue());
nPc.setUpdateId(user.getId());
compositionDAO.updateByPrimaryKeySelective(nPc);
}
/** /**
* 将编辑好的试卷蓝图封存 * 标记已封存的试卷已使用
*/ */
@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()), "规则总分值不等于试卷总分值");
//
PaperComposition nPc = new PaperComposition();
nPc.setId(curPc.getId());
nPc.setState(PaperCompositionState.Locked.getValue());
compositionDAO.updateByPrimaryKeySelective(nPc);
// 封存试卷时校验总分值与规则总分值是否相等
}
/**
* 将封存的试卷蓝图设置失效
*/
@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())), "试卷定义不存在或非封存中");
//
PaperComposition nPc = new PaperComposition();
nPc.setId(curPc.getId());
nPc.setState(PaperCompositionState.Invalid.getValue());
nPc.setUpdateId(user.getId());
compositionDAO.updateByPrimaryKeySelective(nPc);
}
/**
* 标记已封存的试卷已使用
*/
/* @Transactional(rollbackFor = Exception.class) /* @Transactional(rollbackFor = Exception.class)
public void usePaperComposition(Long pcId) { public void usePaperComposition(Long pcId) {
PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId); PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId);
@ -181,289 +213,299 @@ public class PaperCompositionService {
} }
}*/ }*/
/** /**
* 删除试卷蓝图(只能删除处于编辑状态的) * 删除试卷蓝图(只能删除处于编辑状态的)
* *
* @param pcId 试卷蓝图id * @param pcId 试卷蓝图id
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void deletePaperComposition(Long pcId, AccountVO user) { public void deletePaperComposition(Long pcId, AccountVO user) {
PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId); PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId);
if (null != curPc) { if (null != curPc) {
assertPaperCompositionCanModify(curPc); assertPaperCompositionCanModify(curPc);
//先删除试卷定义中的规则 //先删除试卷定义中的规则
PaperRuleExample ruleExample = new PaperRuleExample(); PaperRuleExample ruleExample = new PaperRuleExample();
ruleExample.createCriteria().andPcIdEqualTo(pcId); ruleExample.createCriteria().andPcIdEqualTo(pcId);
ruleDAO.deleteByExample(ruleExample); ruleDAO.deleteByExample(ruleExample);
//删除试卷定义 //删除试卷定义
compositionDAO.deleteByPrimaryKey(pcId); compositionDAO.deleteByPrimaryKey(pcId);
}
} }
}
/** /**
* 断言试卷蓝图可以修改 * 断言试卷蓝图可以修改
*/ */
@Transactional(readOnly = true) @Transactional(readOnly = true)
public void assertPaperCompositionCanModify(Long pcId) { public void assertPaperCompositionCanModify(Long pcId) {
PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId); PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId);
this.assertPaperCompositionCanModify(curPc); this.assertPaperCompositionCanModify(curPc);
} }
/** /**
* 断言试卷蓝图可以修改 * 断言试卷蓝图可以修改
*/ */
public void assertPaperCompositionCanModify(PaperComposition curPc) { 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) @Transactional(readOnly = true)
public PageVO<PaperCompositionWithRuleVo> findPaperCompositionByPageForAccount(FindPaperCompositionByAccountReqVo req) { public PageVO<PaperCompositionWithRuleVo> findPaperCompositionByPageForAccount(
PaperExceptionAssert.PpValid.assertTrue(null != req.getAccount() || null != req.getUserId(), "账号和用户id不能同时为空"); FindPaperCompositionByAccountReqVo req) {
Long userId = req.getUserId(); PaperExceptionAssert.PpValid.assertTrue(null != req.getAccount() || null != req.getUserId(),
if (null == userId) { "账号和用户id不能同时为空");
SysAccountExample accountExample = new SysAccountExample(); Long userId = req.getUserId();
// if (null == userId) {
SysAccountExample.Criteria mobileC = accountExample.or(); SysAccountExample accountExample = new SysAccountExample();
mobileC.andMobileEqualTo(req.getAccount()); //
if (null != req.getPwd()) { SysAccountExample.Criteria mobileC = accountExample.or();
mobileC.andPasswordEqualTo(req.getPwd()); mobileC.andMobileEqualTo(req.getAccount());
} if (null != req.getPwd()) {
// mobileC.andPasswordEqualTo(req.getPwd());
SysAccountExample.Criteria emailC = accountExample.or(); }
emailC.andEmailEqualTo(req.getAccount()); //
if (null != req.getPwd()) { SysAccountExample.Criteria emailC = accountExample.or();
emailC.andPasswordEqualTo(req.getPwd()); emailC.andEmailEqualTo(req.getAccount());
} if (null != req.getPwd()) {
// emailC.andPasswordEqualTo(req.getPwd());
SysAccountExample.Criteria accountC = accountExample.or(); }
accountC.andAccountEqualTo(req.getAccount()); //
if (null != req.getPwd()) { SysAccountExample.Criteria accountC = accountExample.or();
accountC.andPasswordEqualTo(req.getPwd()); accountC.andAccountEqualTo(req.getAccount());
} if (null != req.getPwd()) {
// accountC.andPasswordEqualTo(req.getPwd());
List<SysAccount> users = this.sysAccountDAO.selectByExample(accountExample); }
PaperExceptionAssert.PdValid.assertTrue(null != users && users.size() == 1, "用户不存在或根据账户信息匹配了多个"); //
userId = users.get(0).getId(); List<SysAccount> users = this.sysAccountDAO.selectByExample(accountExample);
} PaperExceptionAssert.PdValid.assertTrue(null != users && users.size() == 1,
// "用户不存在或根据账户信息匹配了多个");
PaperCompositionExample pcEx = new PaperCompositionExample(); userId = users.get(0).getId();
PaperCompositionExample.Criteria pcExCriteria = pcEx.createCriteria();
pcExCriteria.andCreatorIdEqualTo(userId);
List<PaperCompositionState> findStates = req.stateList();
pcExCriteria.andStateIn(findStates.stream().map(pcState -> {
return pcState.getValue();
}).collect(Collectors.toList()));
//
//1--创建时间 2--更新时间 3--名称默认值为1
String orderBy = "create_time";
switch (req.getOrderBy()) {
case 1:
orderBy = "create_time";
break;
case 2:
orderBy = "update_time";
break;
case 3:
orderBy = "name";
break;
}
orderBy+=(req.getDesc()?" desc":"");
//
PageHelper.clearPage();
PageHelper.startPage(req.getPageNum(),req.getPageSize(),orderBy);
Page<PaperComposition> sqlPage = (Page<PaperComposition>) compositionDAO.selectByExample(pcEx);
//
final List<PaperCompositionWithRuleVo> rtList = new ArrayList<>();
if(!CollectionUtils.isEmpty(sqlPage.getResult())){
sqlPage.getResult().forEach(pc->{
List<PaperRule> prList = this.findRuleByPcId(pc.getId());
rtList.add(PaperCompositionConvertor.convert(pc, prList));
});
}
//
PageVO<PaperCompositionWithRuleVo> page = PageVO.convert(sqlPage,rtList);
//
if (!CollectionUtils.isEmpty(page.getList())) {
page.getList().forEach(pc -> {
pc.setCreatorInfo(this.findCreatorInfo(pc.getCreatorId()));
});
}
//
return page;
} }
//
PaperCompositionExample pcEx = new PaperCompositionExample();
PaperCompositionExample.Criteria pcExCriteria = pcEx.createCriteria();
pcExCriteria.andCreatorIdEqualTo(userId);
List<PaperCompositionState> findStates = req.stateList();
pcExCriteria.andStateIn(findStates.stream().map(pcState -> {
return pcState.getValue();
}).collect(Collectors.toList()));
//
//1--创建时间 2--更新时间 3--名称默认值为1
String orderBy = "create_time";
switch (req.getOrderBy()) {
case 1:
orderBy = "create_time";
break;
case 2:
orderBy = "update_time";
break;
case 3:
orderBy = "name";
break;
}
orderBy += (req.getDesc() ? " desc" : "");
//
PageHelper.clearPage();
PageHelper.startPage(req.getPageNum(), req.getPageSize(), orderBy);
Page<PaperComposition> sqlPage = (Page<PaperComposition>) compositionDAO.selectByExample(pcEx);
//
final List<PaperCompositionWithRuleVo> rtList = new ArrayList<>();
if (!CollectionUtils.isEmpty(sqlPage.getResult())) {
sqlPage.getResult().forEach(pc -> {
List<PaperRule> prList = this.findRuleByPcId(pc.getId());
rtList.add(PaperCompositionConvertor.convert(pc, prList));
});
}
//
PageVO<PaperCompositionWithRuleVo> page = PageVO.convert(sqlPage, rtList);
//
if (!CollectionUtils.isEmpty(page.getList())) {
page.getList().forEach(pc -> {
pc.setCreatorInfo(this.findCreatorInfo(pc.getCreatorId()));
});
}
//
return page;
}
/** /**
* 返回蓝图的列表基本信息 * 返回蓝图的列表基本信息
*/ */
public List<PaperCompositionWithRuleVo> findPaperCompositionList(FindPaperCompositionPageReqVo req){ public List<PaperCompositionWithRuleVo> findPaperCompositionList(
PaperCompositionExample pcEx = this.queryExample(req); FindPaperCompositionPageReqVo req) {
pcEx.setOrderByClause(" create_time desc "); PaperCompositionExample pcEx = this.queryExample(req);
List<PaperComposition> sqlPage = compositionDAO.selectByExample(pcEx); pcEx.setOrderByClause(" create_time desc ");
// List<PaperComposition> sqlPage = compositionDAO.selectByExample(pcEx);
final List<PaperCompositionWithRuleVo> rtList = new ArrayList<>(); //
for (PaperComposition pc : sqlPage) { final List<PaperCompositionWithRuleVo> rtList = new ArrayList<>();
rtList.add(PaperCompositionConvertor.convert(pc,null)); for (PaperComposition pc : sqlPage) {
} rtList.add(PaperCompositionConvertor.convert(pc, null));
return rtList;
} }
return rtList;
}
private PaperCompositionExample queryExample(FindPaperCompositionPageReqVo req){ private PaperCompositionExample queryExample(FindPaperCompositionPageReqVo req) {
PaperCompositionExample pcEx = new PaperCompositionExample(); PaperCompositionExample pcEx = new PaperCompositionExample();
PaperCompositionExample.Criteria pcExCriteria = pcEx.createCriteria(); PaperCompositionExample.Criteria pcExCriteria = pcEx.createCriteria();
if (Objects.nonNull(req.getOrgId())) { if (Objects.nonNull(req.getOrgId())) {
pcExCriteria.andOrgIdEqualTo(req.getOrgId()); pcExCriteria.andOrgIdEqualTo(req.getOrgId());
}
if(Objects.nonNull(req.getMapId())){
pcExCriteria.andMapIdEqualTo(req.getMapId());
}
if (StringUtils.hasText(req.getName())) {
if (req.getNameLike()) {
pcExCriteria.andNameLike(String.format("%%%s%%", req.getName()));
} else {
pcExCriteria.andNameEqualTo(req.getName());
}
}
if (StringUtils.hasText(req.getProfile())) {
if (req.getProfileLike()) {
pcExCriteria.andProfileLike(String.format("%%%s%%", req.getProfile()));
} else {
pcExCriteria.andProfileEqualTo(req.getProfile());
}
}
List<PaperCompositionState> findStates = req.stateList();
pcExCriteria.andStateIn(findStates.stream().map(pcState -> {
return pcState.getValue();
}).collect(Collectors.toList()));
return pcEx;
} }
/** if (Objects.nonNull(req.getMapId())) {
* 分页查找试卷蓝图 pcExCriteria.andMapIdEqualTo(req.getMapId());
*/
@Transactional(readOnly = true)
public PageVO<PaperCompositionWithRuleVo> findPaperCompositionByPage(FindPaperCompositionPageReqVo req) {
PaperCompositionExample pcEx = this.queryExample(req);
//
//1--创建时间 2--更新时间 3--名称默认值为1
String orderBy = "create_time";
switch (req.getOrderBy()) {
case 1:
orderBy = "create_time";
break;
case 2:
orderBy = "update_time";
break;
case 3:
orderBy = "name";
break;
}
orderBy+=(req.getDesc()?" desc":"");
//
PageHelper.clearPage();
PageHelper.startPage(req.getPageNum(),req.getPageSize(),orderBy);
Page<PaperComposition> sqlPage = (Page<PaperComposition>) compositionDAO.selectByExample(pcEx);
//
final List<PaperCompositionWithRuleVo> rtList = new ArrayList<>();
if(!CollectionUtils.isEmpty(sqlPage.getResult())){
for (PaperComposition pc : sqlPage.getResult()) {
List<PaperRule> prList = this.findRuleByPcId(pc.getId());
rtList.add(PaperCompositionConvertor.convert(pc, prList));
}
}
//
PageVO<PaperCompositionWithRuleVo> page = PageVO.convert(sqlPage,rtList);
//
if (!CollectionUtils.isEmpty(page.getList())) {
page.getList().forEach(pc -> {
pc.setCreatorInfo(this.findCreatorInfo(pc.getCreatorId()));
});
}
//
return page;
} }
if (StringUtils.hasText(req.getName())) {
if (req.getNameLike()) {
pcExCriteria.andNameLike(String.format("%%%s%%", req.getName()));
} else {
pcExCriteria.andNameEqualTo(req.getName());
}
}
if (StringUtils.hasText(req.getProfile())) {
if (req.getProfileLike()) {
pcExCriteria.andProfileLike(String.format("%%%s%%", req.getProfile()));
} else {
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;
}
private PaperCompositionWithRuleVo.CreatorBasic findCreatorInfo(Long creatorId) { /**
SysAccount sa = this.sysAccountDAO.selectByPrimaryKey(creatorId); * 分页查找试卷蓝图
if (null != sa) { */
PaperCompositionWithRuleVo.CreatorBasic rt = new PaperCompositionWithRuleVo.CreatorBasic(); @Transactional(readOnly = true)
rt.setId(sa.getId()); public PageVO<PaperCompositionWithRuleVo> findPaperCompositionByPage(
rt.setName(sa.getName()); FindPaperCompositionPageReqVo req) {
rt.setAccount(sa.getAccount()); PaperCompositionExample pcEx = this.queryExample(req);
rt.setMobile(sa.getMobile()); //
rt.setEmail(sa.getEmail()); //1--创建时间 2--更新时间 3--名称默认值为1
return rt; String orderBy = "create_time";
} switch (req.getOrderBy()) {
return null; case 1:
orderBy = "create_time";
break;
case 2:
orderBy = "update_time";
break;
case 3:
orderBy = "name";
break;
} }
orderBy += (req.getDesc() ? " desc" : "");
//
PageHelper.clearPage();
PageHelper.startPage(req.getPageNum(), req.getPageSize(), orderBy);
Page<PaperComposition> sqlPage = (Page<PaperComposition>) compositionDAO.selectByExample(pcEx);
//
final List<PaperCompositionWithRuleVo> rtList = new ArrayList<>();
if (!CollectionUtils.isEmpty(sqlPage.getResult())) {
for (PaperComposition pc : sqlPage.getResult()) {
List<PaperRule> prList = this.findRuleByPcId(pc.getId());
rtList.add(PaperCompositionConvertor.convert(pc, prList));
}
}
//
PageVO<PaperCompositionWithRuleVo> page = PageVO.convert(sqlPage, rtList);
//
if (!CollectionUtils.isEmpty(page.getList())) {
page.getList().forEach(pc -> {
pc.setCreatorInfo(this.findCreatorInfo(pc.getCreatorId()));
});
}
//
return page;
}
/** private PaperCompositionWithRuleVo.CreatorBasic findCreatorInfo(Long creatorId) {
* 获取试卷完整的蓝图包括规则 SysAccount sa = this.sysAccountDAO.selectByPrimaryKey(creatorId);
* if (null != sa) {
* @param pcId 试卷蓝图id PaperCompositionWithRuleVo.CreatorBasic rt = new PaperCompositionWithRuleVo.CreatorBasic();
*/ rt.setId(sa.getId());
@Transactional(readOnly = true) if (StringUtils.hasText(sa.getName())) {
public PaperCompositionWithRuleVo findPaperComposition(Long pcId, AccountVO user) { rt.setName(sa.getName());
PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId); } else {
PaperExceptionAssert.PcExisted.assertTrue(null != curPc, "试卷定义不存在id=" + pcId); rt.setName("昵称:" + sa.getNickname());
List<PaperRule> paperRuleList = this.findRuleByPcId(pcId); }
// rt.setAccount(sa.getAccount());
PaperCompositionWithRuleVo rt = PaperCompositionConvertor.convert(curPc, paperRuleList); rt.setMobile(sa.getMobile());
rt.setCreatorInfo(this.findCreatorInfo(rt.getCreatorId())); rt.setEmail(sa.getEmail());
return rt; return rt;
} }
return null;
}
/** /**
* 根据试卷蓝图的项目和名称查找项目 * 获取试卷完整的蓝图包括规则
*/ *
@Transactional(readOnly = true) * @param pcId 试卷蓝图id
public List<PaperComposition> findCompositionByCompanyIdAndName(Long orgId, String name) { */
PaperCompositionExample example = new PaperCompositionExample(); @Transactional(readOnly = true)
example.createCriteria().andOrgIdEqualTo(orgId).andNameEqualTo(name); public PaperCompositionWithRuleVo findPaperComposition(Long pcId, AccountVO user) {
List<PaperComposition> list = compositionDAO.selectByExample(example); PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId);
return list; PaperExceptionAssert.PcExisted.assertTrue(null != curPc, "试卷定义不存在id=" + pcId);
} List<PaperRule> paperRuleList = this.findRuleByPcId(pcId);
//
PaperCompositionWithRuleVo rt = PaperCompositionConvertor.convert(curPc, paperRuleList);
rt.setCreatorInfo(this.findCreatorInfo(rt.getCreatorId()));
return rt;
}
/** /**
* 查询试卷蓝图的所有规则 * 根据试卷蓝图的项目和名称查找项目
* */
* @param pcId 试卷蓝图的id @Transactional(readOnly = true)
*/ public List<PaperComposition> findCompositionByCompanyIdAndName(Long orgId, String name) {
@Transactional(readOnly = true) PaperCompositionExample example = new PaperCompositionExample();
public List<PaperRule> findRuleByPcId(Long pcId) { example.createCriteria().andOrgIdEqualTo(orgId).andNameEqualTo(name);
PaperRuleExample example = new PaperRuleExample(); List<PaperComposition> list = compositionDAO.selectByExample(example);
example.createCriteria().andPcIdEqualTo(pcId); return list;
return ruleDAO.selectByExample(example); }
}
/** /**
* 校验规则当前规定的总分值是否小于等于试卷蓝图中的满分 * 查询试卷蓝图的所有规则
*/ *
private boolean checkRulesScoreLessOrEqualFull(Long pcId) { * @param pcId 试卷蓝图的id
PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId); */
PaperExceptionAssert.PcExisted.assertTrue(null != curPc, String.format("试卷定义[id = %s]不存在", pcId)); @Transactional(readOnly = true)
List<PaperRule> ruleList = findRuleByPcId(pcId); public List<PaperRule> findRuleByPcId(Long pcId) {
int ruleScore = 0; PaperRuleExample example = new PaperRuleExample();
if (!CollectionUtils.isEmpty(ruleList)) { example.createCriteria().andPcIdEqualTo(pcId);
ruleScore = ruleList.stream().mapToInt(rule -> { return ruleDAO.selectByExample(example);
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);
private boolean checkRulesScoreEqualFull(Long pcId) { rules.stream().map(PaperCompositionWithRuleVo::getCreatorId)
PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId); .distinct()
PaperExceptionAssert.PcExisted.assertTrue(null != curPc, String.format("试卷定义[id = %s]不存在", pcId)); .forEach(creatorId -> creators.add(this.findCreatorInfo(creatorId)));
List<PaperRule> ruleList = findRuleByPcId(pcId); return creators;
int ruleScore = 0; }
if (!CollectionUtils.isEmpty(ruleList)) {
ruleScore = ruleList.stream().mapToInt(rule -> { /**
return rule.getScore() * rule.getAmount(); * 校验规则当前规定的总分值是否等于试卷蓝图中的满分
}).sum(); */
} private boolean checkRulesScoreEqualFull(Long pcId) {
return ruleScore == curPc.getFullScore(); 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();
}
} }

View File

@ -21,63 +21,63 @@ import java.util.Map;
@Setter @Setter
@NoArgsConstructor @NoArgsConstructor
public class FindPaperCompositionPageReqVo extends PageQueryVO { public class FindPaperCompositionPageReqVo extends PageQueryVO {
/**
* 组织id<br>
* 选填<br>
*/
@JsonSerialize(using = ToStringSerializer.class)
private Long orgId;
/**
* 线路id
*/
private Long mapId;
/**
* 试卷蓝图名称<br>
* 选填<br>
*/
private String name;
/**
* 试卷蓝图名称--是否模糊查询默认true<br>
* 选填<br>
*/
private Boolean nameLike = true;
/**
* 试卷蓝图简介<br>
* 选填<br>
*/
private String profile;
/**
* 试卷蓝图简介--是否模糊查询,默认true<br>
* 选填<br>
*/
private Boolean profileLike = true;
/**
* 根据试卷蓝图的状态查找,默认值FindPcType.All<br>
* All(1)-所有,Editing(2)-正在编辑的,CanUse(3)-可以用于生成试卷的,Locked(4)-封存,Used(5)-已经被使用过<br>
* 选填<br>
*/
private FindPcType findState = FindPcType.All;
/**
* 以什么来排序
* <p>
* 1--创建时间 2--更新时间 3--名称默认值为1
* <p>
* 选填
*/
private Integer orderBy = 1;
/** /**
* 是否降序true-降序false-升序默认值为true; * 组织id<br> 选填<br>
* <p> */
* 选填 @JsonSerialize(using = ToStringSerializer.class)
*/ private Long orgId;
private Boolean desc = true; /**
/** * 线路id
* 试卷蓝图状态1-正在编辑2-封存(不能修改)3-已经被使用(不能修改删除)<br> */
* 选填<br> private Long mapId;
*/ /**
public List<PaperCompositionState> stateList(){ * 试卷蓝图名称<br> 选填<br>
return FindPcType.stateList(findState); */
} private String name;
/**
* 试卷蓝图名称--是否模糊查询默认true<br> 选填<br>
*/
private Boolean nameLike = true;
/**
* 试卷蓝图简介<br> 选填<br>
*/
private String profile;
/**
* 试卷蓝图简介--是否模糊查询,默认true<br> 选填<br>
*/
private Boolean profileLike = true;
/**
* 根据试卷蓝图的状态查找,默认值FindPcType.All<br>
* All(1)-所有,Editing(2)-正在编辑的,CanUse(3)-可以用于生成试卷的,Locked(4)-封存,Used(5)-已经被使用过<br> 选填<br>
*/
private FindPcType findState = FindPcType.All;
/**
* 以什么来排序
* <p>
* 1--创建时间 2--更新时间 3--名称默认值为1
* <p>
* 选填
*/
private Integer orderBy = 1;
/**
* 是否降序true-降序false-升序默认值为true;
* <p>
* 选填
*/
private Boolean desc = true;
/**
* 试卷创建者的ID
*/
private Long creatorId;
/**
* 试卷蓝图状态1-正在编辑2-封存(不能修改)3-已经被使用(不能修改删除)<br> 选填<br>
*/
public List<PaperCompositionState> stateList() {
return FindPcType.stateList(findState);
}
} }