|
@@ -2,8 +2,10 @@ package cn.com.qmth.mps.service.impl;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -22,10 +24,12 @@ import cn.com.qmth.mps.bean.User;
|
|
|
import cn.com.qmth.mps.dao.PaperDetailDao;
|
|
|
import cn.com.qmth.mps.entity.PaperDetailEntity;
|
|
|
import cn.com.qmth.mps.entity.PaperEntity;
|
|
|
+import cn.com.qmth.mps.entity.PaperGroupUnitEntity;
|
|
|
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.PaperGroupUnitService;
|
|
|
import cn.com.qmth.mps.service.PaperService;
|
|
|
import cn.com.qmth.mps.util.Calculator;
|
|
|
import cn.com.qmth.mps.vo.paper.StructDomain;
|
|
@@ -35,7 +39,8 @@ public class PaperDetailServiceImpl extends ServiceImpl<PaperDetailDao, PaperDet
|
|
|
implements PaperDetailService {
|
|
|
@Autowired
|
|
|
private PaperGroupService paperGroupService;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private PaperGroupUnitService paperGroupUnitService;
|
|
|
@Autowired
|
|
|
private PaperDetailUnitService paperDetailUnitService;
|
|
|
@Autowired
|
|
@@ -48,21 +53,35 @@ public class PaperDetailServiceImpl extends ServiceImpl<PaperDetailDao, PaperDet
|
|
|
if (CollectionUtils.isEmpty(es)) {
|
|
|
return ret;
|
|
|
}
|
|
|
- Map<Long,PaperDetail> map=new HashMap<>();
|
|
|
- for(PaperDetailEntity e:es) {
|
|
|
- PaperDetail vo=new PaperDetail();
|
|
|
+ Map<Long, PaperDetail> map = new HashMap<>();
|
|
|
+ for (PaperDetailEntity e : es) {
|
|
|
+ PaperDetail vo = new PaperDetail();
|
|
|
vo.setName(e.getName());
|
|
|
vo.setNumber(e.getNumber());
|
|
|
map.put(e.getId(), vo);
|
|
|
ret.add(vo);
|
|
|
}
|
|
|
- Map<Long,List<PaperDetailUnit>> units=paperDetailUnitService.getStructInfo(paperId);
|
|
|
- if (units==null||units.size()==0) {
|
|
|
+ Map<Long, List<PaperDetailUnit>> units = paperDetailUnitService.getStructInfo(paperId);
|
|
|
+ if (units == null || units.size() == 0) {
|
|
|
return ret;
|
|
|
}
|
|
|
- for(Long key:units.keySet()) {
|
|
|
+ for (Long key : units.keySet()) {
|
|
|
map.get(key).setUnits(units.get(key));
|
|
|
}
|
|
|
+ List<PaperGroupUnitEntity> gs = paperGroupUnitService.getByPaperId(paperId);
|
|
|
+ Set<String> unitSet = new HashSet<>();
|
|
|
+ for (PaperGroupUnitEntity u : gs) {
|
|
|
+ unitSet.add(u.getDetailNumber() + "-" + u.getDetailUnitNumber());
|
|
|
+ }
|
|
|
+ for (PaperDetail pd : ret) {
|
|
|
+ for (PaperDetailUnit u : pd.getUnits()) {
|
|
|
+ if (unitSet.contains(pd.getNumber() + "-" + u.getNumber())) {
|
|
|
+ u.setInGroup(true);
|
|
|
+ } else {
|
|
|
+ u.setInGroup(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -83,11 +102,11 @@ public class PaperDetailServiceImpl extends ServiceImpl<PaperDetailDao, PaperDet
|
|
|
if (domain.getTotalScore() == null) {
|
|
|
throw new StatusException("试卷满分不能为空");
|
|
|
}
|
|
|
- if (domain.getTotalScore()<=0) {
|
|
|
+ if (domain.getTotalScore() <= 0) {
|
|
|
throw new StatusException("试卷满分必须大于0");
|
|
|
}
|
|
|
- String total=domain.getTotalScore().toString();
|
|
|
- if (total.indexOf(".")<total.length()-2) {
|
|
|
+ String total = domain.getTotalScore().toString();
|
|
|
+ if (total.indexOf(".") < total.length() - 2) {
|
|
|
throw new StatusException("试卷满分只能有一位小数");
|
|
|
}
|
|
|
if (CollectionUtils.isEmpty(domain.getStructInfo())) {
|
|
@@ -97,25 +116,25 @@ public class PaperDetailServiceImpl extends ServiceImpl<PaperDetailDao, PaperDet
|
|
|
if (u.getNumber() == null || StringUtils.isBlank(u.getName())) {
|
|
|
throw new StatusException("大题号、大题名称不能为空");
|
|
|
}
|
|
|
- if (u.getNumber()<=0) {
|
|
|
+ if (u.getNumber() <= 0) {
|
|
|
throw new StatusException("大题号必须大于0");
|
|
|
}
|
|
|
if (CollectionUtils.isEmpty(u.getUnits())) {
|
|
|
throw new StatusException("小题信息不能为空");
|
|
|
}
|
|
|
for (PaperDetailUnit unit : u.getUnits()) {
|
|
|
- if (unit.getNumber()== null ||unit.getScore()==null||unit.getScoreStep()==null) {
|
|
|
+ if (unit.getNumber() == null || unit.getScore() == null || unit.getScoreStep() == null) {
|
|
|
throw new StatusException("小题号、小题满分、给分间隔不能为空");
|
|
|
}
|
|
|
- if (unit.getNumber()<=0) {
|
|
|
+ if (unit.getNumber() <= 0) {
|
|
|
throw new StatusException("小题号必须大于0");
|
|
|
}
|
|
|
- String score=unit.getScore().toString();
|
|
|
- if (score.indexOf(".")<score.length()-2) {
|
|
|
+ String score = unit.getScore().toString();
|
|
|
+ if (score.indexOf(".") < score.length() - 2) {
|
|
|
throw new StatusException("小题满分只能有一位小数");
|
|
|
}
|
|
|
- String scoreStep=unit.getScoreStep().toString();
|
|
|
- if (scoreStep.indexOf(".")<scoreStep.length()-2) {
|
|
|
+ String scoreStep = unit.getScoreStep().toString();
|
|
|
+ if (scoreStep.indexOf(".") < scoreStep.length() - 2) {
|
|
|
throw new StatusException("给分间隔只能有一位小数");
|
|
|
}
|
|
|
}
|
|
@@ -134,28 +153,28 @@ public class PaperDetailServiceImpl extends ServiceImpl<PaperDetailDao, PaperDet
|
|
|
paper.setTotalScore(domain.getTotalScore());
|
|
|
paper.setSubjectiveScore(domain.getTotalScore());
|
|
|
paperService.updateById(paper);
|
|
|
- for(PaperDetail pd:domain.getStructInfo()) {
|
|
|
- PaperDetailEntity e=new PaperDetailEntity();
|
|
|
+ for (PaperDetail pd : domain.getStructInfo()) {
|
|
|
+ PaperDetailEntity e = new PaperDetailEntity();
|
|
|
e.setName(pd.getName());
|
|
|
e.setNumber(pd.getNumber());
|
|
|
e.setPaperId(domain.getPaperId());
|
|
|
this.save(e);
|
|
|
- paperDetailUnitService.saveUnit(e,pd.getUnits());
|
|
|
+ paperDetailUnitService.saveUnit(e, pd.getUnits());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private void clearPaperSruct(Long paperId) {
|
|
|
clearByPaperId(paperId);
|
|
|
paperDetailUnitService.clearByPaperId(paperId);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private void clearByPaperId(Long paperId) {
|
|
|
QueryWrapper<PaperDetailEntity> wrapper = new QueryWrapper<>();
|
|
|
LambdaQueryWrapper<PaperDetailEntity> lw = wrapper.lambda();
|
|
|
lw.eq(PaperDetailEntity::getPaperId, paperId);
|
|
|
this.remove(wrapper);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public void structSubmit(StructDomain domain, User user) {
|
|
@@ -165,11 +184,11 @@ public class PaperDetailServiceImpl extends ServiceImpl<PaperDetailDao, PaperDet
|
|
|
if (domain.getTotalScore() == null) {
|
|
|
throw new StatusException("试卷满分不能为空");
|
|
|
}
|
|
|
- if (domain.getTotalScore()<=0) {
|
|
|
+ if (domain.getTotalScore() <= 0) {
|
|
|
throw new StatusException("试卷满分必须大于0");
|
|
|
}
|
|
|
- String total=domain.getTotalScore().toString();
|
|
|
- if (total.indexOf(".")<total.length()-2) {
|
|
|
+ String total = domain.getTotalScore().toString();
|
|
|
+ if (total.indexOf(".") < total.length() - 2) {
|
|
|
throw new StatusException("试卷满分只能有一位小数");
|
|
|
}
|
|
|
if (CollectionUtils.isEmpty(domain.getStructInfo())) {
|
|
@@ -183,18 +202,18 @@ public class PaperDetailServiceImpl extends ServiceImpl<PaperDetailDao, PaperDet
|
|
|
throw new StatusException("小题信息不能为空");
|
|
|
}
|
|
|
for (PaperDetailUnit unit : u.getUnits()) {
|
|
|
- if (unit.getNumber()== null ||unit.getScore()==null||unit.getScoreStep()==null) {
|
|
|
+ if (unit.getNumber() == null || unit.getScore() == null || unit.getScoreStep() == null) {
|
|
|
throw new StatusException("小题号、小题满分、给分间隔不能为空");
|
|
|
}
|
|
|
- if (unit.getNumber()<=0) {
|
|
|
+ if (unit.getNumber() <= 0) {
|
|
|
throw new StatusException("小题号必须大于0");
|
|
|
}
|
|
|
- String score=unit.getScore().toString();
|
|
|
- if (score.indexOf(".")<score.length()-2) {
|
|
|
+ String score = unit.getScore().toString();
|
|
|
+ if (score.indexOf(".") < score.length() - 2) {
|
|
|
throw new StatusException("小题满分只能有一位小数");
|
|
|
}
|
|
|
- String scoreStep=unit.getScoreStep().toString();
|
|
|
- if (scoreStep.indexOf(".")<scoreStep.length()-2) {
|
|
|
+ String scoreStep = unit.getScoreStep().toString();
|
|
|
+ if (scoreStep.indexOf(".") < scoreStep.length() - 2) {
|
|
|
throw new StatusException("给分间隔只能有一位小数");
|
|
|
}
|
|
|
}
|
|
@@ -215,24 +234,24 @@ public class PaperDetailServiceImpl extends ServiceImpl<PaperDetailDao, PaperDet
|
|
|
paper.setSubjectiveScore(domain.getTotalScore());
|
|
|
paper.setStructFinish(true);
|
|
|
paperService.updateById(paper);
|
|
|
- for(PaperDetail pd:domain.getStructInfo()) {
|
|
|
- PaperDetailEntity e=new PaperDetailEntity();
|
|
|
+ for (PaperDetail pd : domain.getStructInfo()) {
|
|
|
+ PaperDetailEntity e = new PaperDetailEntity();
|
|
|
e.setName(pd.getName());
|
|
|
e.setNumber(pd.getNumber());
|
|
|
e.setPaperId(domain.getPaperId());
|
|
|
this.save(e);
|
|
|
- paperDetailUnitService.saveUnit(e,pd.getUnits());
|
|
|
+ paperDetailUnitService.saveUnit(e, pd.getUnits());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private void checkTotalScore(StructDomain domain) {
|
|
|
- double total=0.0;
|
|
|
- for(PaperDetail detial:domain.getStructInfo()) {
|
|
|
- for(PaperDetailUnit unit:detial.getUnits()) {
|
|
|
- total=Calculator.add(total, unit.getScore(),1);
|
|
|
+ double total = 0.0;
|
|
|
+ for (PaperDetail detial : domain.getStructInfo()) {
|
|
|
+ for (PaperDetailUnit unit : detial.getUnits()) {
|
|
|
+ total = Calculator.add(total, unit.getScore(), 1);
|
|
|
}
|
|
|
}
|
|
|
- if(total!=domain.getTotalScore()) {
|
|
|
+ if (total != domain.getTotalScore()) {
|
|
|
throw new StatusException("试卷满分与小题分不一致");
|
|
|
}
|
|
|
}
|