|
@@ -3,6 +3,7 @@ package cn.com.qmth.mps.service.impl;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Comparator;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -29,6 +30,8 @@ import com.qmth.boot.tools.excel.ExcelReader;
|
|
|
import com.qmth.boot.tools.excel.enums.ExcelType;
|
|
|
import com.qmth.boot.tools.excel.model.DataMap;
|
|
|
|
|
|
+import cn.com.qmth.mps.bean.PaperDetail;
|
|
|
+import cn.com.qmth.mps.bean.PaperDetailUnit;
|
|
|
import cn.com.qmth.mps.bean.User;
|
|
|
import cn.com.qmth.mps.dao.PaperDao;
|
|
|
import cn.com.qmth.mps.entity.CourseEntity;
|
|
@@ -41,31 +44,34 @@ import cn.com.qmth.mps.service.PaperDetailService;
|
|
|
import cn.com.qmth.mps.service.PaperGroupService;
|
|
|
import cn.com.qmth.mps.service.PaperService;
|
|
|
import cn.com.qmth.mps.util.BatchSetDataUtil;
|
|
|
+import cn.com.qmth.mps.util.Calculator;
|
|
|
import cn.com.qmth.mps.util.PageUtil;
|
|
|
import cn.com.qmth.mps.vo.exam.ExamPaperCountVo;
|
|
|
import cn.com.qmth.mps.vo.paper.GroupCountVo;
|
|
|
import cn.com.qmth.mps.vo.paper.PaperInfoVo;
|
|
|
import cn.com.qmth.mps.vo.paper.PaperQuery;
|
|
|
+import cn.com.qmth.mps.vo.paper.PaperStructInfoVo;
|
|
|
import cn.com.qmth.mps.vo.paper.PaperVo;
|
|
|
+import cn.com.qmth.mps.vo.paper.StructDomain;
|
|
|
|
|
|
@Service
|
|
|
public class PaperServiceImpl extends ServiceImpl<PaperDao, PaperEntity> implements PaperService {
|
|
|
-
|
|
|
+
|
|
|
@Autowired
|
|
|
private ExamService examService;
|
|
|
-
|
|
|
+
|
|
|
@Autowired
|
|
|
private CourseService courseService;
|
|
|
@Autowired
|
|
|
private PaperGroupService paperGroupService;
|
|
|
@Autowired
|
|
|
private PaperDetailService paperDetailService;
|
|
|
-
|
|
|
+
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public List<String> importPaper(Long examId, User user, MultipartFile file) {
|
|
|
- ExamEntity exam=examService.getById(examId);
|
|
|
- if(exam==null) {
|
|
|
+ ExamEntity exam = examService.getById(examId);
|
|
|
+ if (exam == null) {
|
|
|
throw new StatusException("未找到考试批次");
|
|
|
}
|
|
|
if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(exam.getSchoolId())) {
|
|
@@ -73,7 +79,7 @@ public class PaperServiceImpl extends ServiceImpl<PaperDao, PaperEntity> impleme
|
|
|
}
|
|
|
InputStream inputStream = null;
|
|
|
try {
|
|
|
- inputStream=file.getInputStream();
|
|
|
+ inputStream = file.getInputStream();
|
|
|
List<DataMap> lineList = ExcelReader.create(ExcelType.XLSX, inputStream, 0).getDataMapList();
|
|
|
if (CollectionUtils.isEmpty(lineList)) {
|
|
|
throw new StatusException("Excel无内容");
|
|
@@ -109,7 +115,7 @@ public class PaperServiceImpl extends ServiceImpl<PaperDao, PaperEntity> impleme
|
|
|
msg.append(" 科目名称不能超过20个字符");
|
|
|
}
|
|
|
if (msg.length() == 0) {
|
|
|
- CourseEntity course=courseService.saveOrGet(exam.getSchoolId(), code, name);
|
|
|
+ CourseEntity course = courseService.saveOrGet(exam.getSchoolId(), code, name);
|
|
|
imp.setCourseId(course.getId());
|
|
|
}
|
|
|
|
|
@@ -141,9 +147,9 @@ public class PaperServiceImpl extends ServiceImpl<PaperDao, PaperEntity> impleme
|
|
|
} catch (StatusException e) {
|
|
|
throw e;
|
|
|
} catch (Exception e) {
|
|
|
- throw new StatusException("系统错误",e);
|
|
|
+ throw new RuntimeException("系统错误", e);
|
|
|
} finally {
|
|
|
- if(inputStream!=null) {
|
|
|
+ if (inputStream != null) {
|
|
|
try {
|
|
|
inputStream.close();
|
|
|
} catch (IOException e) {
|
|
@@ -151,13 +157,14 @@ public class PaperServiceImpl extends ServiceImpl<PaperDao, PaperEntity> impleme
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private String trimAndNullIfBlank(String s) {
|
|
|
if (StringUtils.isBlank(s)) {
|
|
|
return null;
|
|
|
}
|
|
|
return s.trim();
|
|
|
}
|
|
|
+
|
|
|
private String newError(int lineNum, String msg) {
|
|
|
return "第" + lineNum + "行" + msg;
|
|
|
}
|
|
@@ -175,6 +182,32 @@ public class PaperServiceImpl extends ServiceImpl<PaperDao, PaperEntity> impleme
|
|
|
return this.count(wrapper);
|
|
|
}
|
|
|
|
|
|
+ private PaperEntity findByExamAndCourse(Long examId, Long courseId) {
|
|
|
+ QueryWrapper<PaperEntity> wrapper = new QueryWrapper<>();
|
|
|
+ LambdaQueryWrapper<PaperEntity> lw = wrapper.lambda();
|
|
|
+ lw.eq(PaperEntity::getExamId, examId);
|
|
|
+ lw.eq(PaperEntity::getCourseId, courseId);
|
|
|
+ return this.getOne(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ private PaperEntity saveOrGet(Long schoolId, Long examId, Long courseId) {
|
|
|
+ PaperEntity ret = findByExamAndCourse(examId, courseId);
|
|
|
+ if (ret != null) {
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ PaperEntity imp = new PaperEntity();
|
|
|
+ imp.setTotalScore(0.0);
|
|
|
+ imp.setObjectiveScore(0.0);
|
|
|
+ imp.setSubjectiveScore(0.0);
|
|
|
+ imp.setSchoolId(schoolId);
|
|
|
+ imp.setGroupFinish(false);
|
|
|
+ imp.setCourseId(courseId);
|
|
|
+ imp.setExamId(examId);
|
|
|
+ imp.setStructFinish(true);
|
|
|
+ this.save(imp);
|
|
|
+ return imp;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public PageResult<PaperVo> page(PaperQuery query, User user) {
|
|
|
if (query.getSchoolId() == null) {
|
|
@@ -183,34 +216,35 @@ public class PaperServiceImpl extends ServiceImpl<PaperDao, PaperEntity> impleme
|
|
|
if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(query.getSchoolId())) {
|
|
|
throw new StatusException("没有权限");
|
|
|
}
|
|
|
- IPage<PaperVo> iPage = this.baseMapper.page(new Page<PaperVo>(query.getPageNumber(), query.getPageSize()), query);
|
|
|
- if(CollectionUtils.isNotEmpty(iPage.getRecords())) {
|
|
|
+ IPage<PaperVo> iPage = this.baseMapper.page(new Page<PaperVo>(query.getPageNumber(), query.getPageSize()),
|
|
|
+ query);
|
|
|
+ if (CollectionUtils.isNotEmpty(iPage.getRecords())) {
|
|
|
new BatchSetDataUtil<PaperVo>() {
|
|
|
|
|
|
- @Override
|
|
|
- protected void setData(List<PaperVo> dataList) {
|
|
|
- List<Long> paperIds = dataList.stream().map(dto -> dto.getId()).distinct()
|
|
|
- .collect(Collectors.toList());
|
|
|
- List<GroupCountVo> ret = paperGroupService.findGroupCount(paperIds);
|
|
|
- if (ret != null && ret.size() > 0) {
|
|
|
- Map<Long, Integer> countMap = new HashMap<>();
|
|
|
- for (GroupCountVo item : ret) {
|
|
|
- countMap.put(item.getPaperId(), item.getGroupCount());
|
|
|
- }
|
|
|
- for (PaperVo vo : dataList) {
|
|
|
- vo.setGroupCount(countMap.get(vo.getId()));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }.setDataForBatch(iPage.getRecords(), 20);
|
|
|
+ @Override
|
|
|
+ protected void setData(List<PaperVo> dataList) {
|
|
|
+ List<Long> paperIds = dataList.stream().map(dto -> dto.getId()).distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<GroupCountVo> ret = paperGroupService.findGroupCount(paperIds);
|
|
|
+ if (ret != null && ret.size() > 0) {
|
|
|
+ Map<Long, Integer> countMap = new HashMap<>();
|
|
|
+ for (GroupCountVo item : ret) {
|
|
|
+ countMap.put(item.getPaperId(), item.getGroupCount());
|
|
|
+ }
|
|
|
+ for (PaperVo vo : dataList) {
|
|
|
+ vo.setGroupCount(countMap.get(vo.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }.setDataForBatch(iPage.getRecords(), 20);
|
|
|
}
|
|
|
return PageUtil.of(iPage);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<PaperVo> list(Long examId, User user) {
|
|
|
- ExamEntity exam=examService.getById(examId);
|
|
|
- if(exam==null) {
|
|
|
+ ExamEntity exam = examService.getById(examId);
|
|
|
+ if (exam == null) {
|
|
|
throw new StatusException("未找到考试批次");
|
|
|
}
|
|
|
if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(exam.getSchoolId())) {
|
|
@@ -221,16 +255,16 @@ public class PaperServiceImpl extends ServiceImpl<PaperDao, PaperEntity> impleme
|
|
|
|
|
|
@Override
|
|
|
public PaperInfoVo info(Long id, User user) {
|
|
|
- PaperEntity paper=this.getById(id);
|
|
|
- if(paper==null) {
|
|
|
+ PaperEntity paper = this.getById(id);
|
|
|
+ if (paper == null) {
|
|
|
throw new StatusException("未找到试卷结构信息");
|
|
|
}
|
|
|
if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(paper.getSchoolId())) {
|
|
|
throw new StatusException("没有权限");
|
|
|
}
|
|
|
- PaperInfoVo vo=new PaperInfoVo();
|
|
|
+ PaperInfoVo vo = new PaperInfoVo();
|
|
|
BeanUtils.copyProperties(paper, vo);
|
|
|
- CourseEntity course=courseService.getById(vo.getCourseId());
|
|
|
+ CourseEntity course = courseService.getById(vo.getCourseId());
|
|
|
vo.setCourseCode(course.getCode());
|
|
|
vo.setCourseName(course.getName());
|
|
|
vo.setStructInfo(paperDetailService.getStructInfo(vo.getId()));
|
|
@@ -241,8 +275,8 @@ public class PaperServiceImpl extends ServiceImpl<PaperDao, PaperEntity> impleme
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public List<String> importSubjectStruct(Long examId, User user, MultipartFile file) {
|
|
|
- ExamEntity exam=examService.getById(examId);
|
|
|
- if(exam==null) {
|
|
|
+ ExamEntity exam = examService.getById(examId);
|
|
|
+ if (exam == null) {
|
|
|
throw new StatusException("未找到考试批次");
|
|
|
}
|
|
|
if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(exam.getSchoolId())) {
|
|
@@ -250,28 +284,22 @@ public class PaperServiceImpl extends ServiceImpl<PaperDao, PaperEntity> impleme
|
|
|
}
|
|
|
InputStream inputStream = null;
|
|
|
try {
|
|
|
- inputStream=file.getInputStream();
|
|
|
+ inputStream = file.getInputStream();
|
|
|
List<DataMap> lineList = ExcelReader.create(ExcelType.XLSX, inputStream, 0).getDataMapList();
|
|
|
if (CollectionUtils.isEmpty(lineList)) {
|
|
|
throw new StatusException("Excel无内容");
|
|
|
}
|
|
|
- if (1001 < lineList.size()) {
|
|
|
- throw new StatusException("数据行数不能超过1000");
|
|
|
+ if (10001 < lineList.size()) {
|
|
|
+ throw new StatusException("数据行数不能超过10000");
|
|
|
}
|
|
|
List<String> failRecords = new ArrayList<>();
|
|
|
- List<PaperEntity> ret = new ArrayList<>();
|
|
|
+ List<PaperStructInfoVo> ret = new ArrayList<>();
|
|
|
for (int i = 0; i < lineList.size(); i++) {
|
|
|
DataMap line = lineList.get(i);
|
|
|
|
|
|
StringBuilder msg = new StringBuilder();
|
|
|
|
|
|
- PaperEntity imp = new PaperEntity();
|
|
|
- imp.setTotalScore(0.0);
|
|
|
- imp.setObjectiveScore(0.0);
|
|
|
- imp.setSubjectiveScore(0.0);
|
|
|
- imp.setSchoolId(exam.getSchoolId());
|
|
|
- imp.setGroupFinish(false);
|
|
|
- imp.setExamId(examId);
|
|
|
+ PaperStructInfoVo imp = new PaperStructInfoVo();
|
|
|
String code = trimAndNullIfBlank(line.getValue(0));
|
|
|
if (StringUtils.isBlank(code)) {
|
|
|
msg.append(" 科目代码不能为空");
|
|
@@ -286,10 +314,96 @@ public class PaperServiceImpl extends ServiceImpl<PaperDao, PaperEntity> impleme
|
|
|
msg.append(" 科目名称不能超过20个字符");
|
|
|
}
|
|
|
if (msg.length() == 0) {
|
|
|
- CourseEntity course=courseService.saveOrGet(exam.getSchoolId(), code, name);
|
|
|
- imp.setCourseId(course.getId());
|
|
|
+ CourseEntity course = courseService.saveOrGet(exam.getSchoolId(), code, name);
|
|
|
+ PaperEntity paper = saveOrGet(exam.getSchoolId(), examId, course.getId());
|
|
|
+ imp.setPaperId(paper.getId());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ String detailName = trimAndNullIfBlank(line.getValue(2));
|
|
|
+ if (StringUtils.isBlank(detailName)) {
|
|
|
+ msg.append(" 大题名称不能为空");
|
|
|
+ } else if (detailName.length() > 50) {
|
|
|
+ msg.append(" 大题名称不能超过50个字符");
|
|
|
+ }
|
|
|
+ imp.setDetailName(detailName);
|
|
|
+
|
|
|
+ String detailNumber = trimAndNullIfBlank(line.getValue(3));
|
|
|
+ if (StringUtils.isBlank(detailNumber)) {
|
|
|
+ msg.append(" 大题号不能为空");
|
|
|
+ } else{
|
|
|
+ try {
|
|
|
+ int n=Integer.valueOf(detailNumber);
|
|
|
+ if (n<=0) {
|
|
|
+ msg.append(" 大题号不能小于0");
|
|
|
+ }else {
|
|
|
+ imp.setDetailNumber(n);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ msg.append(" 大题号只能是整数");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ String unitNumber = trimAndNullIfBlank(line.getValue(4));
|
|
|
+ if (StringUtils.isBlank(unitNumber)) {
|
|
|
+ msg.append(" 小题号不能为空");
|
|
|
+ } else{
|
|
|
+ try {
|
|
|
+ int n=Integer.valueOf(unitNumber);
|
|
|
+ if (n<=0) {
|
|
|
+ msg.append(" 小题号不能小于0");
|
|
|
+ }else {
|
|
|
+ imp.setUnitNumber(n);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ msg.append(" 小题号只能是整数");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ String score = trimAndNullIfBlank(line.getValue(5));
|
|
|
+ if (StringUtils.isBlank(score)) {
|
|
|
+ msg.append(" 小题满分不能为空");
|
|
|
+ } else{
|
|
|
+ try {
|
|
|
+ Double n=Double.valueOf(score);
|
|
|
+ if (n<=0) {
|
|
|
+ msg.append(" 小题满分不能小于0");
|
|
|
+ }else {
|
|
|
+ if (score.indexOf(".")<score.length()-2) {
|
|
|
+ msg.append("小题满分只能有一位小数");
|
|
|
+ }else {
|
|
|
+ imp.setScore(n);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ msg.append(" 小题满分格式错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ String scoreStep = trimAndNullIfBlank(line.getValue(6));
|
|
|
+ if (StringUtils.isBlank(scoreStep)) {
|
|
|
+ msg.append(" 间隔分不能为空");
|
|
|
+ } else{
|
|
|
+ try {
|
|
|
+ Double n=Double.valueOf(scoreStep);
|
|
|
+ if (n<=0) {
|
|
|
+ msg.append(" 间隔分不能小于0");
|
|
|
+ }else {
|
|
|
+ if (scoreStep.indexOf(".")<scoreStep.length()-2) {
|
|
|
+ msg.append("小间隔分只能有一位小数");
|
|
|
+ }else {
|
|
|
+ imp.setScoreStep(n);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ msg.append(" 间隔分格式错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
if (msg.length() > 0) {
|
|
|
failRecords.add(newError(i + 1, msg.toString()));
|
|
|
} else {
|
|
@@ -300,17 +414,7 @@ public class PaperServiceImpl extends ServiceImpl<PaperDao, PaperEntity> impleme
|
|
|
if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
|
return failRecords;
|
|
|
}
|
|
|
- for (int i = 0; i < ret.size(); i++) {
|
|
|
- PaperEntity cur = ret.get(i);
|
|
|
- try {
|
|
|
- this.save(cur);
|
|
|
- } catch (DuplicateKeyException e) {
|
|
|
- failRecords.add(newError(i + 1, "科目已存在"));
|
|
|
- } catch (Exception e) {
|
|
|
- failRecords.add(newError(i + 1, "系统异常"));
|
|
|
- log.error("科目导入系统异常", e);
|
|
|
- }
|
|
|
- }
|
|
|
+ this.saveStruct(ret, user, failRecords);
|
|
|
if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
}
|
|
@@ -318,9 +422,9 @@ public class PaperServiceImpl extends ServiceImpl<PaperDao, PaperEntity> impleme
|
|
|
} catch (StatusException e) {
|
|
|
throw e;
|
|
|
} catch (Exception e) {
|
|
|
- throw new StatusException("系统错误",e);
|
|
|
+ throw new RuntimeException("系统错误", e);
|
|
|
} finally {
|
|
|
- if(inputStream!=null) {
|
|
|
+ if (inputStream != null) {
|
|
|
try {
|
|
|
inputStream.close();
|
|
|
} catch (IOException e) {
|
|
@@ -329,6 +433,123 @@ public class PaperServiceImpl extends ServiceImpl<PaperDao, PaperEntity> impleme
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void saveStruct(List<PaperStructInfoVo> cards, User user, List<String> failRecords) {
|
|
|
+ List<StructDomain> ces = getBeans(cards);
|
|
|
+ checkStruct(ces, failRecords);
|
|
|
+ if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (StructDomain domain : ces) {
|
|
|
+ try {
|
|
|
+ paperDetailService.structSubmit(domain, user);
|
|
|
+ } catch (StatusException e) {
|
|
|
+ failRecords.add(e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("系统错误", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ private void checkStruct(List<StructDomain> ces, List<String> failRecords) {
|
|
|
+ Map<Long, String> courseMap = new HashMap<>();
|
|
|
+ for (StructDomain card : ces) {
|
|
|
+ int lastDetailNum = 0;
|
|
|
+ for (PaperDetail detail : card.getStructInfo()) {
|
|
|
+ if (detail.getNumber() - lastDetailNum != 1) {
|
|
|
+ failRecords.add(
|
|
|
+ "科目:" + getCourseCode(courseMap, card.getPaperId()) + ",大题号" + detail.getNumber() + "错误");
|
|
|
+ }
|
|
|
+ lastDetailNum = detail.getNumber();
|
|
|
+ int lastUnitNum = 0;
|
|
|
+ for (PaperDetailUnit unit : detail.getUnits()) {
|
|
|
+ if (unit.getNumber() - lastUnitNum != 1) {
|
|
|
+ failRecords.add("科目:" + getCourseCode(courseMap, card.getPaperId()) + ",大题号:"
|
|
|
+ + detail.getNumber() + ",小题号" + unit.getNumber() + "错误");
|
|
|
+ }
|
|
|
+ lastUnitNum = unit.getNumber();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getCourseCode(Map<Long, String> courseMap, Long paperId) {
|
|
|
+ if (courseMap.get(paperId) != null) {
|
|
|
+ return courseMap.get(paperId);
|
|
|
+ }
|
|
|
+ String code = courseService.getById(this.getById(paperId).getCourseId()).getCode();
|
|
|
+ courseMap.put(paperId, code);
|
|
|
+ return code;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<StructDomain> getBeans(List<PaperStructInfoVo> cards) {
|
|
|
+ cards.sort(new Comparator<PaperStructInfoVo>() {
|
|
|
+ @Override
|
|
|
+ public int compare(PaperStructInfoVo o1, PaperStructInfoVo o2) {
|
|
|
+ long c1 = o1.getPaperId();
|
|
|
+ long c2 = o2.getPaperId();
|
|
|
+ if (c1 < c2) {
|
|
|
+ return -1;
|
|
|
+ } else if (c1 > c2) {
|
|
|
+ return 1;
|
|
|
+ } else {
|
|
|
+ int indx1 = o1.getDetailNumber();
|
|
|
+ int indx2 = o2.getDetailNumber();
|
|
|
+ if (indx1 < indx2) {
|
|
|
+ return -1;
|
|
|
+ } else if (indx1 > indx2) {
|
|
|
+ return 1;
|
|
|
+ } else {
|
|
|
+ int u1 = o1.getUnitNumber();
|
|
|
+ int u2 = o2.getUnitNumber();
|
|
|
+ if (u1 < u2) {
|
|
|
+ return -1;
|
|
|
+ } else if (u1 > u2) {
|
|
|
+ return 1;
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<StructDomain> ces = new ArrayList<>();
|
|
|
+ StructDomain curCard = null;
|
|
|
+ PaperDetail curDetail = null;
|
|
|
+ for (PaperStructInfoVo info : cards) {
|
|
|
+ if (curCard == null || !info.getPaperId().equals(curCard.getPaperId())) {
|
|
|
+ curCard = new StructDomain();
|
|
|
+ curCard.setPaperId(info.getPaperId());
|
|
|
+ curCard.setStructInfo(new ArrayList<>());
|
|
|
+ ces.add(curCard);
|
|
|
+ curDetail = null;
|
|
|
+ }
|
|
|
+ if (curDetail == null || !info.getDetailNumber().equals(curDetail.getNumber())) {
|
|
|
+ curDetail = new PaperDetail();
|
|
|
+ curDetail.setName(info.getDetailName());
|
|
|
+ curDetail.setNumber(info.getDetailNumber());
|
|
|
+ curDetail.setUnits(new ArrayList<>());
|
|
|
+ curCard.getStructInfo().add(curDetail);
|
|
|
+ }
|
|
|
+ PaperDetailUnit unit = new PaperDetailUnit();
|
|
|
+ curDetail.getUnits().add(unit);
|
|
|
+ unit.setNumber(info.getUnitNumber());
|
|
|
+ unit.setScore(info.getScore());
|
|
|
+ unit.setScoreStep(info.getScoreStep());
|
|
|
+ }
|
|
|
+ for (StructDomain sd : ces) {
|
|
|
+ setTotalScore(sd);
|
|
|
+ }
|
|
|
+ return ces;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setTotalScore(StructDomain domain) {
|
|
|
+ double total = 0.0;
|
|
|
+ for (PaperDetail detial : domain.getStructInfo()) {
|
|
|
+ for (PaperDetailUnit unit : detial.getUnits()) {
|
|
|
+ total = Calculator.add(total, unit.getScore(), 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ domain.setTotalScore(total);
|
|
|
+ }
|
|
|
|
|
|
}
|