|
@@ -2,29 +2,52 @@ package cn.com.qmth.mps.service.impl;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
+import java.util.LinkedHashSet;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.Set;
|
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
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 com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.qmth.boot.core.exception.StatusException;
|
|
|
|
|
|
|
|
+import cn.com.qmth.mps.bean.PaperDetail;
|
|
|
|
+import cn.com.qmth.mps.bean.PaperDetailUnit;
|
|
import cn.com.qmth.mps.bean.PaperGroup;
|
|
import cn.com.qmth.mps.bean.PaperGroup;
|
|
import cn.com.qmth.mps.bean.PaperGroupUnit;
|
|
import cn.com.qmth.mps.bean.PaperGroupUnit;
|
|
|
|
+import cn.com.qmth.mps.bean.User;
|
|
import cn.com.qmth.mps.dao.PaperGroupDao;
|
|
import cn.com.qmth.mps.dao.PaperGroupDao;
|
|
|
|
+import cn.com.qmth.mps.entity.PaperDetailEntity;
|
|
|
|
+import cn.com.qmth.mps.entity.PaperEntity;
|
|
import cn.com.qmth.mps.entity.PaperGroupEntity;
|
|
import cn.com.qmth.mps.entity.PaperGroupEntity;
|
|
|
|
+import cn.com.qmth.mps.enums.Role;
|
|
|
|
+import cn.com.qmth.mps.service.PaperDetailService;
|
|
|
|
+import cn.com.qmth.mps.service.PaperDetailUnitService;
|
|
import cn.com.qmth.mps.service.PaperGroupService;
|
|
import cn.com.qmth.mps.service.PaperGroupService;
|
|
import cn.com.qmth.mps.service.PaperGroupUnitService;
|
|
import cn.com.qmth.mps.service.PaperGroupUnitService;
|
|
|
|
+import cn.com.qmth.mps.service.PaperService;
|
|
import cn.com.qmth.mps.vo.paper.GroupCountVo;
|
|
import cn.com.qmth.mps.vo.paper.GroupCountVo;
|
|
|
|
+import cn.com.qmth.mps.vo.paper.GroupInfoVo;
|
|
|
|
+import cn.com.qmth.mps.vo.paper.GroupVo;
|
|
|
|
+import cn.com.qmth.mps.vo.paper.PaperGroupDomain;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class PaperGroupServiceImpl extends ServiceImpl<PaperGroupDao, PaperGroupEntity> implements PaperGroupService {
|
|
public class PaperGroupServiceImpl extends ServiceImpl<PaperGroupDao, PaperGroupEntity> implements PaperGroupService {
|
|
@Autowired
|
|
@Autowired
|
|
private PaperGroupUnitService paperGroupUnitService;
|
|
private PaperGroupUnitService paperGroupUnitService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaperService paperService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaperDetailService paperDetailService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaperDetailUnitService paperDetailUnitService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public List<GroupCountVo> findGroupCount(List<Long> paperIds) {
|
|
public List<GroupCountVo> findGroupCount(List<Long> paperIds) {
|
|
return this.baseMapper.findGroupCount(paperIds);
|
|
return this.baseMapper.findGroupCount(paperIds);
|
|
@@ -37,22 +60,23 @@ public class PaperGroupServiceImpl extends ServiceImpl<PaperGroupDao, PaperGroup
|
|
if (CollectionUtils.isEmpty(es)) {
|
|
if (CollectionUtils.isEmpty(es)) {
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
- Map<Long,PaperGroup> map=new HashMap<>();
|
|
|
|
- for(PaperGroupEntity e:es) {
|
|
|
|
- PaperGroup vo=new PaperGroup();
|
|
|
|
|
|
+ Map<Long, PaperGroup> map = new HashMap<>();
|
|
|
|
+ for (PaperGroupEntity e : es) {
|
|
|
|
+ PaperGroup vo = new PaperGroup();
|
|
vo.setNumber(e.getNumber());
|
|
vo.setNumber(e.getNumber());
|
|
map.put(e.getId(), vo);
|
|
map.put(e.getId(), vo);
|
|
ret.add(vo);
|
|
ret.add(vo);
|
|
}
|
|
}
|
|
- Map<Long,List<PaperGroupUnit>> units=paperGroupUnitService.getGroupInfo(paperId);
|
|
|
|
- if (units==null||units.size()==0) {
|
|
|
|
|
|
+ Map<Long, List<PaperGroupUnit>> units = paperGroupUnitService.getGroupInfo(paperId);
|
|
|
|
+ if (units == null || units.size() == 0) {
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
- for(Long key:units.keySet()) {
|
|
|
|
|
|
+ for (Long key : units.keySet()) {
|
|
map.get(key).setGroupUnits(units.get(key));
|
|
map.get(key).setGroupUnits(units.get(key));
|
|
}
|
|
}
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
+
|
|
private List<PaperGroupEntity> getByPaperId(Long paperId) {
|
|
private List<PaperGroupEntity> getByPaperId(Long paperId) {
|
|
QueryWrapper<PaperGroupEntity> wrapper = new QueryWrapper<>();
|
|
QueryWrapper<PaperGroupEntity> wrapper = new QueryWrapper<>();
|
|
LambdaQueryWrapper<PaperGroupEntity> lw = wrapper.lambda();
|
|
LambdaQueryWrapper<PaperGroupEntity> lw = wrapper.lambda();
|
|
@@ -60,4 +84,174 @@ public class PaperGroupServiceImpl extends ServiceImpl<PaperGroupDao, PaperGroup
|
|
return this.list(wrapper);
|
|
return this.list(wrapper);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public List<GroupVo> groupList(Long paperId, User user) {
|
|
|
|
+ PaperEntity paper = paperService.getById(paperId);
|
|
|
|
+ if (paper == null) {
|
|
|
|
+ throw new StatusException("未找到试卷结构");
|
|
|
|
+ }
|
|
|
|
+ if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(paper.getSchoolId())) {
|
|
|
|
+ throw new StatusException("没有权限");
|
|
|
|
+ }
|
|
|
|
+ List<GroupVo> ret = new ArrayList<>();
|
|
|
|
+ List<PaperGroupEntity> es = getByPaperId(paperId);
|
|
|
|
+ if (CollectionUtils.isEmpty(es)) {
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+ Map<Long, GroupVo> map = new HashMap<>();
|
|
|
|
+ for (PaperGroupEntity e : es) {
|
|
|
|
+ GroupVo vo = new GroupVo();
|
|
|
|
+ vo.setNumber(e.getNumber());
|
|
|
|
+ vo.setGroupId(e.getId());
|
|
|
|
+ map.put(e.getId(), vo);
|
|
|
|
+ ret.add(vo);
|
|
|
|
+ }
|
|
|
|
+ Map<Long, List<PaperGroupUnit>> units = paperGroupUnitService.getGroupInfo(paperId);
|
|
|
|
+ List<PaperDetailEntity> des = paperDetailService.getByPaperId(paperId);
|
|
|
|
+ Map<Integer, PaperDetailEntity> detailMap = new HashMap<>();
|
|
|
|
+ for (PaperDetailEntity de : des) {
|
|
|
|
+ detailMap.put(de.getNumber(), de);
|
|
|
|
+ }
|
|
|
|
+ for (GroupVo vo : ret) {
|
|
|
|
+ List<PaperGroupUnit> unit = units.get(vo.getGroupId());
|
|
|
|
+ if (CollectionUtils.isNotEmpty(unit)) {
|
|
|
|
+ Set<Integer> set = new LinkedHashSet<>();
|
|
|
|
+ for (PaperGroupUnit u : unit) {
|
|
|
|
+ set.add(u.getDeatailNumber());
|
|
|
|
+ }
|
|
|
|
+ StringBuilder numSb = new StringBuilder();
|
|
|
|
+ StringBuilder nameSb = new StringBuilder();
|
|
|
|
+ for (Integer num : set) {
|
|
|
|
+ numSb.append(num).append(",");
|
|
|
|
+ nameSb.append(detailMap.get(num)).append(",");
|
|
|
|
+ }
|
|
|
|
+ vo.setDetailNumbers(numSb.substring(0, numSb.length() - 1));
|
|
|
|
+ vo.setDetailNames(nameSb.substring(0, nameSb.length() - 1));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public GroupInfoVo groupInfo(Long paperId, Integer groupNumber, User user) {
|
|
|
|
+ PaperEntity paper = paperService.getById(paperId);
|
|
|
|
+ if (paper == null) {
|
|
|
|
+ throw new StatusException("未找到试卷结构");
|
|
|
|
+ }
|
|
|
|
+ if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(paper.getSchoolId())) {
|
|
|
|
+ throw new StatusException("没有权限");
|
|
|
|
+ }
|
|
|
|
+ PaperGroupEntity e = this.getByPaperIdAndNumber(paperId, groupNumber);
|
|
|
|
+ if (e == null) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ GroupInfoVo vo = new GroupInfoVo();
|
|
|
|
+ vo.setNumber(e.getNumber());
|
|
|
|
+ Map<Long, List<PaperGroupUnit>> units = paperGroupUnitService.getGroupInfo(paperId);
|
|
|
|
+ vo.setGroupUnit(units.get(e.getId()));
|
|
|
|
+ return vo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private PaperGroupEntity getByPaperIdAndNumber(Long paperId, Integer groupNumber) {
|
|
|
|
+ QueryWrapper<PaperGroupEntity> wrapper = new QueryWrapper<>();
|
|
|
|
+ LambdaQueryWrapper<PaperGroupEntity> lw = wrapper.lambda();
|
|
|
|
+ lw.eq(PaperGroupEntity::getPaperId, paperId);
|
|
|
|
+ lw.eq(PaperGroupEntity::getNumber, groupNumber);
|
|
|
|
+ return this.getOne(wrapper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional
|
|
|
|
+ @Override
|
|
|
|
+ public void groupSave(PaperGroupDomain domain, User user) {
|
|
|
|
+
|
|
|
|
+ if (domain.getPaperId() == null) {
|
|
|
|
+ throw new StatusException("试卷结构ID不能为空");
|
|
|
|
+ }
|
|
|
|
+ if (domain.getNumber() == null) {
|
|
|
|
+ throw new StatusException("分组号不能为空");
|
|
|
|
+ }
|
|
|
|
+ if (CollectionUtils.isEmpty(domain.getGroupUnits())) {
|
|
|
|
+ throw new StatusException("分组信息不能为空");
|
|
|
|
+ }
|
|
|
|
+ for (PaperGroupUnit u : domain.getGroupUnits()) {
|
|
|
|
+ if (u.getDeatailNumber() == null || u.getDetailUnitNumber() == null) {
|
|
|
|
+ throw new StatusException("大题号、小题号不能为空");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ PaperEntity paper = paperService.getById(domain.getPaperId());
|
|
|
|
+ if (paper == null) {
|
|
|
|
+ throw new StatusException("未找到试卷结构");
|
|
|
|
+ }
|
|
|
|
+ if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(paper.getSchoolId())) {
|
|
|
|
+ throw new StatusException("没有权限");
|
|
|
|
+ }
|
|
|
|
+ if (!paper.getStructFinish()) {
|
|
|
|
+ throw new StatusException("试卷结构未提交,不能设置分组");
|
|
|
|
+ }
|
|
|
|
+ groupDelete(domain.getPaperId(), domain.getNumber(), user);
|
|
|
|
+ PaperGroupEntity g = new PaperGroupEntity();
|
|
|
|
+ g.setNumber(domain.getNumber());
|
|
|
|
+ g.setPaperId(domain.getPaperId());
|
|
|
|
+ this.save(g);
|
|
|
|
+ List<PaperDetail> pds = paperDetailService.getStructInfo(domain.getPaperId());
|
|
|
|
+ if (CollectionUtils.isEmpty(pds)) {
|
|
|
|
+ throw new StatusException("试卷结构小题信息为空");
|
|
|
|
+ }
|
|
|
|
+ checkStruct(pds, domain.getGroupUnits());
|
|
|
|
+ paperGroupUnitService.saveUnit(g, domain.getGroupUnits());
|
|
|
|
+ if (paperGroupUnitService.countByPaperId(domain.getPaperId())
|
|
|
|
+ .equals(paperDetailUnitService.countByPaperId(domain.getPaperId()))) {
|
|
|
|
+ paper.setGroupFinish(true);
|
|
|
|
+ paperService.updateById(paper);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void checkStruct(List<PaperDetail> pds, List<PaperGroupUnit> groupUnits) {
|
|
|
|
+ for (PaperGroupUnit groupUnit : groupUnits) {
|
|
|
|
+ checkStructExists(pds, groupUnit);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void checkStructExists(List<PaperDetail> pds, PaperGroupUnit groupUnit) {
|
|
|
|
+ for (PaperDetail pd : pds) {
|
|
|
|
+ if (pd.getNumber().equals(groupUnit.getDeatailNumber())) {
|
|
|
|
+ for (PaperDetailUnit u : pd.getUnits()) {
|
|
|
|
+ if (u.getNumber().equals(groupUnit.getDetailUnitNumber())) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ throw new StatusException(
|
|
|
|
+ "试卷结构中大题号:" + groupUnit.getDeatailNumber() + " 小题号:" + groupUnit.getDetailUnitNumber() + "不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional
|
|
|
|
+ @Override
|
|
|
|
+ public void groupDelete(Long paperId, Integer groupNumber, User user) {
|
|
|
|
+ PaperEntity paper = paperService.getById(paperId);
|
|
|
|
+ if (paper == null) {
|
|
|
|
+ throw new StatusException("未找到试卷结构");
|
|
|
|
+ }
|
|
|
|
+ if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(paper.getSchoolId())) {
|
|
|
|
+ throw new StatusException("没有权限");
|
|
|
|
+ }
|
|
|
|
+ PaperGroupEntity old = getByPaperIdAndNumber(paperId, groupNumber);
|
|
|
|
+ if (old == null) {
|
|
|
|
+ throw new StatusException("未找到分组信息");
|
|
|
|
+ }
|
|
|
|
+ this.removeById(old.getId());
|
|
|
|
+ paperGroupUnitService.removeByPaperIdAndGroup(paperId, old.getId());
|
|
|
|
+ paper.setGroupFinish(false);
|
|
|
|
+ paperService.updateById(paper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean existsGroup(Long paperId) {
|
|
|
|
+ QueryWrapper<PaperGroupEntity> wrapper = new QueryWrapper<>();
|
|
|
|
+ LambdaQueryWrapper<PaperGroupEntity> lw = wrapper.lambda();
|
|
|
|
+ lw.eq(PaperGroupEntity::getPaperId, paperId);
|
|
|
|
+ return this.count(wrapper)>0;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|