From 2416d21a4fccdf4d636f520c199c1dd59c9cd407 Mon Sep 17 00:00:00 2001 From: thesai <1021828630@qq.com> Date: Wed, 10 Apr 2024 14:53:34 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=E8=AF=95?= =?UTF-8?q?=E5=8D=B7=E5=88=9B=E5=BB=BA=E8=80=85=E4=BF=A1=E6=81=AF=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=8E=A5=E5=8F=A3=EF=BC=9B=E6=9F=A5=E8=AF=A2=E8=AF=95?= =?UTF-8?q?=E5=8D=B7=E5=A2=9E=E5=8A=A0=E6=8C=89=E5=88=9B=E5=BB=BA=E4=BA=BA?= =?UTF-8?q?=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../paper/PaperCompositionController.java | 9 + .../paper/PaperCompositionService.java | 810 +++++++++--------- .../paper/FindPaperCompositionPageReqVo.java | 114 +-- 3 files changed, 492 insertions(+), 441 deletions(-) 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 d1c30722f..063ffa2d6 100644 --- a/src/main/java/club/joylink/rtss/controller/paper/PaperCompositionController.java +++ b/src/main/java/club/joylink/rtss/controller/paper/PaperCompositionController.java @@ -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 queryCreatorList(FindPaperCompositionPageReqVo req) { + return compositionService.queryCreatorList(req); + } + /** * 根据mapId查询蓝图的基本信息 * 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 d4c0347c4..60a3e587f 100644 --- a/src/main/java/club/joylink/rtss/services/paper/PaperCompositionService.java +++ b/src/main/java/club/joylink/rtss/services/paper/PaperCompositionService.java @@ -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,139 +38,170 @@ import java.util.stream.Collectors; @Slf4j @Service public class PaperCompositionService { - @Autowired - private PaperCompositionDAO compositionDAO; - @Autowired - private PaperRuleDAO ruleDAO; - @Autowired - private SysAccountDAO sysAccountDAO; - /** - * 创建试卷蓝图包括规则定义 - */ - @Transactional(rollbackFor = Exception.class) - public CreatePaperCompositionRspVo createPaperCompositionWithRule(PaperCompositionWithRuleVo req, AccountVO user) { - //根据项目和名称来查,如果存在则结束 - PaperExceptionAssert.PcNotExisted.assertTrue(Objects.nonNull(req.getMapId()), "请选择对应的线路"); - List pcList = this.findCompositionByCompanyIdAndName(req.getOrgId(), req.getName()); - PaperExceptionAssert.PcNotExisted.assertTrue(CollectionUtils.isEmpty(pcList), "试卷定义已经存在:orgId=" + req.getOrgId() + " name=" + req.getName()); - Optional optionalRule = req.getRuleList().stream().filter(d->d.getSubtype() == PaperQType.SubType.Single - && (Objects.isNull(d.getSubTypeParam()) || Objects.isNull(d.getSubTypeParam().getClient()))).findAny(); + @Autowired + private PaperCompositionDAO compositionDAO; + @Autowired + private PaperRuleDAO ruleDAO; + @Autowired + private SysAccountDAO sysAccountDAO; - 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 pcList = this.findCompositionByCompanyIdAndName(req.getOrgId(), + req.getName()); + PaperExceptionAssert.PcNotExisted.assertTrue(CollectionUtils.isEmpty(pcList), + "试卷定义已经存在:orgId=" + req.getOrgId() + " name=" + req.getName()); + Optional 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()); - newPc.setUpdateTime(LocalDateTime.now()); - newPc.setCreatorId(user.getId()); - newPc.setUpdateId(user.getId()); - newPc.setState(PaperCompositionState.Editing.getValue()); - compositionDAO.insertSelective(newPc); + PaperExceptionAssert.PcNotHavePr.assertTrue(optionalRule.isEmpty(), + "试卷规则-单操缺少客户端的定义"); + PaperComposition newPc = PaperCompositionConvertor.convertToBean(req); - 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()); - rsp.setProfile(newPc.getProfile()); - rsp.setOrgId(newPc.getOrgId()); - return rsp; + newPc.setCreateTime(LocalDateTime.now()); + newPc.setUpdateTime(LocalDateTime.now()); + newPc.setCreatorId(user.getId()); + newPc.setUpdateId(user.getId()); + newPc.setState(PaperCompositionState.Editing.getValue()); + compositionDAO.insertSelective(newPc); + + 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()); + rsp.setProfile(newPc.getProfile()); + rsp.setOrgId(newPc.getOrgId()); + return rsp; + } - 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())); - return key; + 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())); + return key; + } + + /** + * 试卷蓝图添加规则 + */ + private void createPaperCompositionRule(Long pcId, + List reqList) { + Map> 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 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 reqList) { - Map> tmpList = reqList.stream().collect(Collectors.groupingBy(this::ruleMapKey)); + /** + * 更新试卷蓝图包括规则定义 + */ + @Transactional(rollbackFor = Exception.class) + public void updatePaperCompositionWithRule(PaperCompositionWithRuleVo req, AccountVO user) { + PaperExceptionAssert.PcNotExisted.assertTrue(Objects.nonNull(req.getMapId()), + "请选择对应的线路"); + Optional 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) { - req.setPcId(pcId); - PaperQType.assertPaperSubTypeMatchGroupType(req.getSubtype(), req.getType()); - String key = this.ruleMapKey(req); - List 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); - } + PaperComposition curPc = compositionDAO.selectByPrimaryKey(req.getId()); + assertPaperCompositionCanModify(curPc); + // + List 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()); } + 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()); + } - /** - * 更新试卷蓝图包括规则定义 - */ - @Transactional(rollbackFor = Exception.class) - public void updatePaperCompositionWithRule(PaperCompositionWithRuleVo req, AccountVO user) { - PaperExceptionAssert.PcNotExisted.assertTrue(Objects.nonNull(req.getMapId()), "请选择对应的线路"); - Optional 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(), "试卷规则-单操缺少客户端的定义"); + private void updateCompositionRule(List updateRuleList, + Long pcId) { + PaperRuleExample ruleExample = new PaperRuleExample(); + ruleExample.createCriteria().andPcIdEqualTo(pcId); + this.ruleDAO.deleteByExample(ruleExample); + this.createPaperCompositionRule(pcId, updateRuleList); + } - PaperComposition curPc = compositionDAO.selectByPrimaryKey(req.getId()); - assertPaperCompositionCanModify(curPc); - // - List 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()); - } - 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()); - } + /** + * 将编辑好的试卷蓝图封存 + */ + @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); + // 封存试卷时校验总分值与规则总分值是否相等 + } - private void updateCompositionRule(List updateRuleList, Long pcId) { - PaperRuleExample ruleExample = new PaperRuleExample(); - ruleExample.createCriteria().andPcIdEqualTo(pcId); - this.ruleDAO.deleteByExample(ruleExample); - this.createPaperCompositionRule(pcId,updateRuleList); - } + /** + * 将封存的试卷蓝图设置失效 + */ + @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) - 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) public void usePaperComposition(Long pcId) { PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId); @@ -181,289 +213,299 @@ public class PaperCompositionService { } }*/ - /** - * 删除试卷蓝图(只能删除处于编辑状态的) - * - * @param pcId 试卷蓝图id - */ - @Transactional(rollbackFor = Exception.class) - public void deletePaperComposition(Long pcId, AccountVO user) { - PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId); - if (null != curPc) { - assertPaperCompositionCanModify(curPc); - //先删除试卷定义中的规则 - PaperRuleExample ruleExample = new PaperRuleExample(); - ruleExample.createCriteria().andPcIdEqualTo(pcId); - ruleDAO.deleteByExample(ruleExample); - //删除试卷定义 - compositionDAO.deleteByPrimaryKey(pcId); - } + /** + * 删除试卷蓝图(只能删除处于编辑状态的) + * + * @param pcId 试卷蓝图id + */ + @Transactional(rollbackFor = Exception.class) + public void deletePaperComposition(Long pcId, AccountVO user) { + PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId); + if (null != curPc) { + assertPaperCompositionCanModify(curPc); + //先删除试卷定义中的规则 + PaperRuleExample ruleExample = new PaperRuleExample(); + ruleExample.createCriteria().andPcIdEqualTo(pcId); + ruleDAO.deleteByExample(ruleExample); + //删除试卷定义 + compositionDAO.deleteByPrimaryKey(pcId); } + } - /** - * 断言试卷蓝图可以修改 - */ - @Transactional(readOnly = true) - public void assertPaperCompositionCanModify(Long pcId) { - PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId); - this.assertPaperCompositionCanModify(curPc); - } + /** + * 断言试卷蓝图可以修改 + */ + @Transactional(readOnly = true) + public void assertPaperCompositionCanModify(Long pcId) { + PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId); + this.assertPaperCompositionCanModify(curPc); + } - /** - * 断言试卷蓝图可以修改 - */ - public void assertPaperCompositionCanModify(PaperComposition curPc) { - PaperExceptionAssert.PcCanModify.assertTrue(null != curPc && PaperCompositionState.Editing.equals(PaperCompositionState.getItem(curPc.getState())), "试卷定义不存在或状态非编辑中,不能修改,pcId = " + curPc.getId()); - } + /** + * 断言试卷蓝图可以修改 + */ + public void assertPaperCompositionCanModify(PaperComposition curPc) { + PaperExceptionAssert.PcCanModify.assertTrue( + null != curPc && PaperCompositionState.Editing.equals( + PaperCompositionState.getItem(curPc.getState())), + "试卷定义不存在或状态非编辑中,不能修改,pcId = " + curPc.getId()); + } - @Transactional(readOnly = true) - public PageVO findPaperCompositionByPageForAccount(FindPaperCompositionByAccountReqVo req) { - PaperExceptionAssert.PpValid.assertTrue(null != req.getAccount() || null != req.getUserId(), "账号和用户id不能同时为空"); - Long userId = req.getUserId(); - if (null == userId) { - SysAccountExample accountExample = new SysAccountExample(); - // - SysAccountExample.Criteria mobileC = accountExample.or(); - 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()) { - emailC.andPasswordEqualTo(req.getPwd()); - } - // - SysAccountExample.Criteria accountC = accountExample.or(); - accountC.andAccountEqualTo(req.getAccount()); - if (null != req.getPwd()) { - accountC.andPasswordEqualTo(req.getPwd()); - } - // - List users = this.sysAccountDAO.selectByExample(accountExample); - PaperExceptionAssert.PdValid.assertTrue(null != users && users.size() == 1, "用户不存在或根据账户信息匹配了多个"); - userId = users.get(0).getId(); - } - // - PaperCompositionExample pcEx = new PaperCompositionExample(); - PaperCompositionExample.Criteria pcExCriteria = pcEx.createCriteria(); - pcExCriteria.andCreatorIdEqualTo(userId); - List 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 sqlPage = (Page) compositionDAO.selectByExample(pcEx); - // - final List rtList = new ArrayList<>(); - if(!CollectionUtils.isEmpty(sqlPage.getResult())){ - sqlPage.getResult().forEach(pc->{ - List prList = this.findRuleByPcId(pc.getId()); - rtList.add(PaperCompositionConvertor.convert(pc, prList)); - }); - } - // - PageVO page = PageVO.convert(sqlPage,rtList); - // - if (!CollectionUtils.isEmpty(page.getList())) { - page.getList().forEach(pc -> { - pc.setCreatorInfo(this.findCreatorInfo(pc.getCreatorId())); - }); - } - // - return page; + @Transactional(readOnly = true) + public PageVO findPaperCompositionByPageForAccount( + FindPaperCompositionByAccountReqVo req) { + PaperExceptionAssert.PpValid.assertTrue(null != req.getAccount() || null != req.getUserId(), + "账号和用户id不能同时为空"); + Long userId = req.getUserId(); + if (null == userId) { + SysAccountExample accountExample = new SysAccountExample(); + // + SysAccountExample.Criteria mobileC = accountExample.or(); + 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()) { + emailC.andPasswordEqualTo(req.getPwd()); + } + // + SysAccountExample.Criteria accountC = accountExample.or(); + accountC.andAccountEqualTo(req.getAccount()); + if (null != req.getPwd()) { + accountC.andPasswordEqualTo(req.getPwd()); + } + // + List users = this.sysAccountDAO.selectByExample(accountExample); + PaperExceptionAssert.PdValid.assertTrue(null != users && users.size() == 1, + "用户不存在或根据账户信息匹配了多个"); + userId = users.get(0).getId(); } + // + PaperCompositionExample pcEx = new PaperCompositionExample(); + PaperCompositionExample.Criteria pcExCriteria = pcEx.createCriteria(); + pcExCriteria.andCreatorIdEqualTo(userId); + List 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 sqlPage = (Page) compositionDAO.selectByExample(pcEx); + // + final List rtList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(sqlPage.getResult())) { + sqlPage.getResult().forEach(pc -> { + List prList = this.findRuleByPcId(pc.getId()); + rtList.add(PaperCompositionConvertor.convert(pc, prList)); + }); + } + // + PageVO page = PageVO.convert(sqlPage, rtList); + // + if (!CollectionUtils.isEmpty(page.getList())) { + page.getList().forEach(pc -> { + pc.setCreatorInfo(this.findCreatorInfo(pc.getCreatorId())); + }); + } + // + return page; + } - /** - * 返回蓝图的列表基本信息 - */ - public List findPaperCompositionList(FindPaperCompositionPageReqVo req){ - PaperCompositionExample pcEx = this.queryExample(req); - pcEx.setOrderByClause(" create_time desc "); - List sqlPage = compositionDAO.selectByExample(pcEx); - // - final List rtList = new ArrayList<>(); - for (PaperComposition pc : sqlPage) { - rtList.add(PaperCompositionConvertor.convert(pc,null)); - } - return rtList; + /** + * 返回蓝图的列表基本信息 + */ + public List findPaperCompositionList( + FindPaperCompositionPageReqVo req) { + PaperCompositionExample pcEx = this.queryExample(req); + pcEx.setOrderByClause(" create_time desc "); + List sqlPage = compositionDAO.selectByExample(pcEx); + // + final List rtList = new ArrayList<>(); + for (PaperComposition pc : sqlPage) { + rtList.add(PaperCompositionConvertor.convert(pc, null)); } + return rtList; + } - private PaperCompositionExample queryExample(FindPaperCompositionPageReqVo req){ - PaperCompositionExample pcEx = new PaperCompositionExample(); - PaperCompositionExample.Criteria pcExCriteria = pcEx.createCriteria(); - if (Objects.nonNull(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 findStates = req.stateList(); - pcExCriteria.andStateIn(findStates.stream().map(pcState -> { - return pcState.getValue(); - }).collect(Collectors.toList())); - return pcEx; + private PaperCompositionExample queryExample(FindPaperCompositionPageReqVo req) { + PaperCompositionExample pcEx = new PaperCompositionExample(); + PaperCompositionExample.Criteria pcExCriteria = pcEx.createCriteria(); + if (Objects.nonNull(req.getOrgId())) { + pcExCriteria.andOrgIdEqualTo(req.getOrgId()); } - /** - * 分页查找试卷蓝图 - */ - @Transactional(readOnly = true) - public PageVO 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 sqlPage = (Page) compositionDAO.selectByExample(pcEx); - // - final List rtList = new ArrayList<>(); - if(!CollectionUtils.isEmpty(sqlPage.getResult())){ - for (PaperComposition pc : sqlPage.getResult()) { - List prList = this.findRuleByPcId(pc.getId()); - rtList.add(PaperCompositionConvertor.convert(pc, prList)); - } - } - // - PageVO page = PageVO.convert(sqlPage,rtList); - // - if (!CollectionUtils.isEmpty(page.getList())) { - page.getList().forEach(pc -> { - pc.setCreatorInfo(this.findCreatorInfo(pc.getCreatorId())); - }); - } - // - return page; + 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()); + } + } + if (req.getCreatorId() != null) { + pcExCriteria.andCreatorIdEqualTo(req.getCreatorId()); + } + List 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(); - rt.setId(sa.getId()); - rt.setName(sa.getName()); - rt.setAccount(sa.getAccount()); - rt.setMobile(sa.getMobile()); - rt.setEmail(sa.getEmail()); - return rt; - } - return null; + /** + * 分页查找试卷蓝图 + */ + @Transactional(readOnly = true) + public PageVO 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 sqlPage = (Page) compositionDAO.selectByExample(pcEx); + // + final List rtList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(sqlPage.getResult())) { + for (PaperComposition pc : sqlPage.getResult()) { + List prList = this.findRuleByPcId(pc.getId()); + rtList.add(PaperCompositionConvertor.convert(pc, prList)); + } + } + // + PageVO page = PageVO.convert(sqlPage, rtList); + // + if (!CollectionUtils.isEmpty(page.getList())) { + page.getList().forEach(pc -> { + pc.setCreatorInfo(this.findCreatorInfo(pc.getCreatorId())); + }); + } + // + return page; + } - /** - * 获取试卷完整的蓝图,包括规则 - * - * @param pcId 试卷蓝图id - */ - @Transactional(readOnly = true) - public PaperCompositionWithRuleVo findPaperComposition(Long pcId, AccountVO user) { - PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId); - PaperExceptionAssert.PcExisted.assertTrue(null != curPc, "试卷定义不存在:id=" + pcId); - List paperRuleList = this.findRuleByPcId(pcId); - // - PaperCompositionWithRuleVo rt = PaperCompositionConvertor.convert(curPc, paperRuleList); - rt.setCreatorInfo(this.findCreatorInfo(rt.getCreatorId())); - return rt; + private PaperCompositionWithRuleVo.CreatorBasic findCreatorInfo(Long creatorId) { + SysAccount sa = this.sysAccountDAO.selectByPrimaryKey(creatorId); + 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()); + return rt; } + return null; + } - /** - * 根据试卷蓝图的项目和名称查找项目 - */ - @Transactional(readOnly = true) - public List findCompositionByCompanyIdAndName(Long orgId, String name) { - PaperCompositionExample example = new PaperCompositionExample(); - example.createCriteria().andOrgIdEqualTo(orgId).andNameEqualTo(name); - List list = compositionDAO.selectByExample(example); - return list; - } + /** + * 获取试卷完整的蓝图,包括规则 + * + * @param pcId 试卷蓝图id + */ + @Transactional(readOnly = true) + public PaperCompositionWithRuleVo findPaperComposition(Long pcId, AccountVO user) { + PaperComposition curPc = compositionDAO.selectByPrimaryKey(pcId); + PaperExceptionAssert.PcExisted.assertTrue(null != curPc, "试卷定义不存在:id=" + pcId); + List 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 findRuleByPcId(Long pcId) { - PaperRuleExample example = new PaperRuleExample(); - example.createCriteria().andPcIdEqualTo(pcId); - return ruleDAO.selectByExample(example); - } + /** + * 根据试卷蓝图的项目和名称查找项目 + */ + @Transactional(readOnly = true) + public List findCompositionByCompanyIdAndName(Long orgId, String name) { + PaperCompositionExample example = new PaperCompositionExample(); + example.createCriteria().andOrgIdEqualTo(orgId).andNameEqualTo(name); + List list = compositionDAO.selectByExample(example); + return list; + } - /** - * 校验规则当前规定的总分值是否小于等于试卷蓝图中的满分 - */ - 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(); - } + /** + * 查询试卷蓝图的所有规则 + * + * @param pcId 试卷蓝图的id + */ + @Transactional(readOnly = true) + public List findRuleByPcId(Long pcId) { + PaperRuleExample example = new PaperRuleExample(); + example.createCriteria().andPcIdEqualTo(pcId); + return ruleDAO.selectByExample(example); + } - /** - * 校验规则当前规定的总分值是否等于试卷蓝图中的满分 - */ - 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(); + public List queryCreatorList(FindPaperCompositionPageReqVo req) { + List creators = new ArrayList<>(); + List rules = findPaperCompositionList(req); + rules.stream().map(PaperCompositionWithRuleVo::getCreatorId) + .distinct() + .forEach(creatorId -> creators.add(this.findCreatorInfo(creatorId))); + return creators; + } + + /** + * 校验规则当前规定的总分值是否等于试卷蓝图中的满分 + */ + 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/vo/paper/FindPaperCompositionPageReqVo.java b/src/main/java/club/joylink/rtss/vo/paper/FindPaperCompositionPageReqVo.java index 63ad82d92..757be4233 100644 --- a/src/main/java/club/joylink/rtss/vo/paper/FindPaperCompositionPageReqVo.java +++ b/src/main/java/club/joylink/rtss/vo/paper/FindPaperCompositionPageReqVo.java @@ -21,63 +21,63 @@ import java.util.Map; @Setter @NoArgsConstructor public class FindPaperCompositionPageReqVo extends PageQueryVO { - /** - * 组织id
- * 选填
- */ - @JsonSerialize(using = ToStringSerializer.class) - private Long orgId; - /** - * 线路id - */ - private Long mapId; - /** - * 试卷蓝图名称
- * 选填
- */ - private String name; - /** - * 试卷蓝图名称--是否模糊查询,默认true
- * 选填
- */ - private Boolean nameLike = true; - /** - * 试卷蓝图简介
- * 选填
- */ - private String profile; - /** - * 试卷蓝图简介--是否模糊查询,默认true
- * 选填
- */ - private Boolean profileLike = true; - /** - * 根据试卷蓝图的状态查找,默认值FindPcType.All
- * All(1)-所有,Editing(2)-正在编辑的,CanUse(3)-可以用于生成试卷的,Locked(4)-封存,Used(5)-已经被使用过
- * 选填
- */ - private FindPcType findState = FindPcType.All; - /** - * 以什么来排序 - *

- * 1--创建时间 2--更新时间 3--名称;默认值为1; - *

- * 选填 - */ - private Integer orderBy = 1; - /** - * 是否降序,true-降序,false-升序,默认值为true; - *

- * 选填 - */ - private Boolean desc = true; - /** - * 试卷蓝图状态:1-正在编辑,2-封存(不能修改),3-已经被使用(不能修改删除)
- * 选填
- */ - public List stateList(){ - return FindPcType.stateList(findState); - } + /** + * 组织id
选填
+ */ + @JsonSerialize(using = ToStringSerializer.class) + private Long orgId; + /** + * 线路id + */ + private Long mapId; + /** + * 试卷蓝图名称
选填
+ */ + private String name; + /** + * 试卷蓝图名称--是否模糊查询,默认true
选填
+ */ + private Boolean nameLike = true; + /** + * 试卷蓝图简介
选填
+ */ + private String profile; + /** + * 试卷蓝图简介--是否模糊查询,默认true
选填
+ */ + private Boolean profileLike = true; + /** + * 根据试卷蓝图的状态查找,默认值FindPcType.All
+ * All(1)-所有,Editing(2)-正在编辑的,CanUse(3)-可以用于生成试卷的,Locked(4)-封存,Used(5)-已经被使用过
选填
+ */ + private FindPcType findState = FindPcType.All; + /** + * 以什么来排序 + *

+ * 1--创建时间 2--更新时间 3--名称;默认值为1; + *

+ * 选填 + */ + private Integer orderBy = 1; + + /** + * 是否降序,true-降序,false-升序,默认值为true; + *

+ * 选填 + */ + private Boolean desc = true; + + /** + * 试卷创建者的ID + */ + private Long creatorId; + + /** + * 试卷蓝图状态:1-正在编辑,2-封存(不能修改),3-已经被使用(不能修改删除)
选填
+ */ + public List stateList() { + return FindPcType.stateList(findState); + } }