|
@@ -44,740 +44,746 @@ import cn.com.qmth.mps.vo.paper.*;
|
|
|
|
|
|
@Service
|
|
|
public class PaperServiceImpl extends ServiceImpl<PaperDao, PaperEntity> implements PaperService {
|
|
|
- private static final String[] SUBJECT_EXCEL_HEADER = new String[] {"科目代码", "科目名称"};
|
|
|
-
|
|
|
- private static final String[] SUBJECT_STRUCT_EXCEL_HEADER = new String[] {"科目代码*","科目名称","大题名称*","题目昵称","大题号(只能用小写数字)*","小题号(只能用小写数字)*","小题满分*","间隔分*","评卷分组(只能用小写数字)*","图片序号(用英文逗号分割)","仲裁方式(0-分组,1-小题)","双评比例(0~1)","仲裁阀值","合分策略(1-平均,2-最高,3-最低)","评卷模式(common-普通,track-轨迹)","试评数量(0-跳过试评)","选做题数量"};
|
|
|
-
|
|
|
- @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) {
|
|
|
- throw new StatusException("未找到考试批次");
|
|
|
- }
|
|
|
- if(!ExamStatus.EDIT.equals(exam.getExamStatus())) {
|
|
|
- throw new StatusException("考试未开放上报,不能设置结构信息或分组信息");
|
|
|
- }
|
|
|
- if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(exam.getSchoolId())) {
|
|
|
- throw new StatusException("没有权限");
|
|
|
- }
|
|
|
- InputStream inputStream = null;
|
|
|
- try {
|
|
|
- inputStream = file.getInputStream();
|
|
|
- ExcelReader reader=ExcelReader.create(ExcelType.XLSX, inputStream, 0);
|
|
|
- List<DataMap> lineList = reader.getDataMapList();
|
|
|
- if(!Arrays.equals(SUBJECT_EXCEL_HEADER,reader.getColumnNames())) {
|
|
|
- throw new StatusException("Excel表头错误");
|
|
|
- }
|
|
|
- if (CollectionUtils.isEmpty(lineList)) {
|
|
|
- throw new StatusException("Excel无内容");
|
|
|
- }
|
|
|
- if (1001 < lineList.size()) {
|
|
|
- throw new StatusException("数据行数不能超过1000");
|
|
|
- }
|
|
|
- List<String> failRecords = new ArrayList<>();
|
|
|
- List<PaperEntity> 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.setStructFinish(false);
|
|
|
- imp.setExamId(examId);
|
|
|
- String code = trimAndNullIfBlank(line.get(SUBJECT_EXCEL_HEADER[0]));
|
|
|
- if (StringUtils.isBlank(code)) {
|
|
|
- msg.append(" 科目代码不能为空");
|
|
|
- } else if (code.length() > 50) {
|
|
|
- msg.append(" 科目代码不能超过50个字符");
|
|
|
- }
|
|
|
-
|
|
|
- String name = trimAndNullIfBlank(line.get(SUBJECT_EXCEL_HEADER[1]));
|
|
|
- if (StringUtils.isBlank(name)) {
|
|
|
- msg.append(" 科目名称不能为空");
|
|
|
- } else if (name.length() > 50) {
|
|
|
- msg.append(" 科目名称不能超过50个字符");
|
|
|
- }
|
|
|
- if (msg.length() == 0) {
|
|
|
- CourseEntity course = courseService.saveOrGet(exam.getSchoolId(), code, name);
|
|
|
- imp.setCourseId(course.getId());
|
|
|
- }
|
|
|
-
|
|
|
- if (msg.length() > 0) {
|
|
|
- failRecords.add(newError(i + 1, msg.toString()));
|
|
|
- } else {
|
|
|
- ret.add(imp);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
- }
|
|
|
- return failRecords;
|
|
|
- } catch (StatusException e) {
|
|
|
- throw e;
|
|
|
- } catch (Exception e) {
|
|
|
- throw new RuntimeException("系统错误", e);
|
|
|
- } finally {
|
|
|
- if (inputStream != null) {
|
|
|
- try {
|
|
|
- inputStream.close();
|
|
|
- } catch (IOException e) {
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private String trimAndNullIfBlank(String s) {
|
|
|
- if (StringUtils.isBlank(s)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- return s.trim();
|
|
|
- }
|
|
|
-
|
|
|
- private String newError(int lineNum, String msg) {
|
|
|
- return "第" + lineNum + "行" + msg;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<ExamPaperCountVo> findPaperCount(List<Long> examIds) {
|
|
|
- return this.baseMapper.findPaperCount(examIds);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Integer findPaperCount(Long examId) {
|
|
|
- QueryWrapper<PaperEntity> wrapper = new QueryWrapper<>();
|
|
|
- LambdaQueryWrapper<PaperEntity> lw = wrapper.lambda();
|
|
|
- lw.eq(PaperEntity::getExamId, examId);
|
|
|
- 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) {
|
|
|
- throw new StatusException("学校不能为空");
|
|
|
- }
|
|
|
- if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(query.getSchoolId())) {
|
|
|
- throw new StatusException("没有权限");
|
|
|
- }
|
|
|
- IPage<PaperVo> iPage = this.baseMapper.page(new Page<>(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(PaperVo::getId).distinct()
|
|
|
- .collect(Collectors.toList());
|
|
|
- List<GroupCountVo> ret = paperGroupService.findGroupCount(paperIds);
|
|
|
- if (ret != null && ret.size() > 0) {
|
|
|
- Map<Long, Integer> countMap = new HashMap<>();
|
|
|
- Map<Long, Boolean> doubleEnableMap = new HashMap<>();
|
|
|
- for (GroupCountVo item : ret) {
|
|
|
- countMap.put(item.getPaperId(), item.getGroupCount());
|
|
|
- doubleEnableMap.put(item.getPaperId(), item.getDoubleEnable());
|
|
|
- }
|
|
|
- for (PaperVo vo : dataList) {
|
|
|
- vo.setGroupCount(countMap.get(vo.getId()));
|
|
|
- vo.setDoubleEnable(doubleEnableMap.get(vo.getId()));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }.setDataForBatch(iPage.getRecords(), 20);
|
|
|
- for (PaperVo vo : iPage.getRecords()) {
|
|
|
- if (vo.getGroupCount() == null) {
|
|
|
- vo.setGroupCount(0);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return PageUtil.of(iPage);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<PaperVo> list(Long examId, User user) {
|
|
|
- ExamEntity exam = examService.getById(examId);
|
|
|
- if (exam == null) {
|
|
|
- throw new StatusException("未找到考试批次");
|
|
|
- }
|
|
|
- if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(exam.getSchoolId())) {
|
|
|
- throw new StatusException("没有权限");
|
|
|
- }
|
|
|
- List<PaperVo> ret=this.baseMapper.myPaperlist(examId,user.getId());
|
|
|
- if (CollectionUtils.isNotEmpty(ret)) {
|
|
|
- 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(ret, 20);
|
|
|
- }
|
|
|
- return ret;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public PaperInfoVo info(Long id, User user) {
|
|
|
- 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();
|
|
|
- BeanUtils.copyProperties(paper, vo);
|
|
|
- CourseEntity course = courseService.getById(vo.getCourseId());
|
|
|
- vo.setCourseCode(course.getCode());
|
|
|
- vo.setCourseName(course.getName());
|
|
|
- vo.setStructInfo(paperDetailService.getStructInfo(vo.getId()));
|
|
|
- vo.setGroupInfo(paperGroupService.getGroupInfo(vo.getId()));
|
|
|
-
|
|
|
- String defaultDoubleSetStr = paper.getDefaultDoubleSet();
|
|
|
- if (!StringUtils.isBlank(defaultDoubleSetStr)) {
|
|
|
- vo.setDefaultDoubleSet(JSON.parseObject(defaultDoubleSetStr, DefaultDoubleSet.class));
|
|
|
- }
|
|
|
- return vo;
|
|
|
- }
|
|
|
-
|
|
|
- @Transactional
|
|
|
- @Override
|
|
|
- public List<String> importSubjectStruct(Long examId, User user, MultipartFile file) {
|
|
|
- ExamEntity exam = examService.getById(examId);
|
|
|
- if (exam == null) {
|
|
|
- throw new StatusException("未找到考试批次");
|
|
|
- }
|
|
|
- if(!ExamStatus.EDIT.equals(exam.getExamStatus())) {
|
|
|
- throw new StatusException("考试未开放上报,不能设置结构信息或分组信息");
|
|
|
- }
|
|
|
- if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(exam.getSchoolId())) {
|
|
|
- throw new StatusException("没有权限");
|
|
|
- }
|
|
|
- InputStream inputStream = null;
|
|
|
- try {
|
|
|
- inputStream = file.getInputStream();
|
|
|
- ExcelReader reader=ExcelReader.create(ExcelType.XLSX, inputStream, 1);
|
|
|
- List<DataMap> lineList = reader.getDataMapList();
|
|
|
- if(!Arrays.equals(SUBJECT_STRUCT_EXCEL_HEADER,reader.getColumnNames())) {
|
|
|
- throw new StatusException("Excel表头错误");
|
|
|
- }
|
|
|
- if (CollectionUtils.isEmpty(lineList)) {
|
|
|
- throw new StatusException("Excel无内容");
|
|
|
- }
|
|
|
- if (10001 < lineList.size()) {
|
|
|
- throw new StatusException("数据行数不能超过10000");
|
|
|
- }
|
|
|
- List<String> failRecords = new ArrayList<>();
|
|
|
- List<PaperStructInfoVo> ret = new ArrayList<>();
|
|
|
- // 双评设置
|
|
|
- Map<String, DoubleMarkImportParam> doubleMarkSettingMap = new HashMap<>();
|
|
|
- for (int i = 0; i < lineList.size(); i++) {
|
|
|
- DataMap line = lineList.get(i);
|
|
|
-
|
|
|
- StringBuilder msg = new StringBuilder();
|
|
|
-
|
|
|
- PaperStructInfoVo imp = new PaperStructInfoVo();
|
|
|
- String code = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[0]));
|
|
|
- if (StringUtils.isBlank(code)) {
|
|
|
- msg.append(" 科目代码不能为空");
|
|
|
- } else if (code.length() > 50) {
|
|
|
- msg.append(" 科目代码不能超过50个字符");
|
|
|
- }
|
|
|
- imp.setCourseCode(code);
|
|
|
-
|
|
|
- String name = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[1]));
|
|
|
- if (StringUtils.isBlank(name)) {
|
|
|
- msg.append(" 科目名称不能为空");
|
|
|
- } else if (name.length() > 50) {
|
|
|
- msg.append(" 科目名称不能超过50个字符");
|
|
|
- }
|
|
|
- if (msg.length() == 0) {
|
|
|
- CourseEntity course = courseService.saveOrGet(exam.getSchoolId(), code, name);
|
|
|
- PaperEntity paper = saveOrGet(exam.getSchoolId(), examId, course.getId());
|
|
|
- imp.setPaperId(paper.getId());
|
|
|
- }
|
|
|
-
|
|
|
- String detailName = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[2]));
|
|
|
- if (StringUtils.isBlank(detailName)) {
|
|
|
- msg.append(" 大题名称不能为空");
|
|
|
- } else if (detailName.length() > 50) {
|
|
|
- msg.append(" 大题名称不能超过50个字符");
|
|
|
- }
|
|
|
- imp.setDetailName(detailName);
|
|
|
- //第4列不处理
|
|
|
- String detailNumber = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[4]));
|
|
|
- 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.get(SUBJECT_STRUCT_EXCEL_HEADER[5]));
|
|
|
- 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.get(SUBJECT_STRUCT_EXCEL_HEADER[6]));
|
|
|
- if (StringUtils.isBlank(score)) {
|
|
|
- msg.append(" 小题满分不能为空");
|
|
|
- } else {
|
|
|
- try {
|
|
|
- Double n = Double.valueOf(score);
|
|
|
- if (n <= 0) {
|
|
|
- msg.append(" 小题满分不能小于0");
|
|
|
- } else {
|
|
|
- if (score.indexOf(".")>=0&&score.indexOf(".") < score.length() - 2) {
|
|
|
- msg.append("小题满分只能有一位小数");
|
|
|
- } else {
|
|
|
- imp.setScore(n);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- msg.append(" 小题满分格式错误");
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- String scoreStep = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[7]));
|
|
|
- if (StringUtils.isBlank(scoreStep)) {
|
|
|
- msg.append(" 间隔分不能为空");
|
|
|
- } else {
|
|
|
- try {
|
|
|
- Double n = Double.valueOf(scoreStep);
|
|
|
- if (n <= 0) {
|
|
|
- msg.append(" 间隔分不能小于0");
|
|
|
- } else {
|
|
|
- if (scoreStep.indexOf(".")>=0&&scoreStep.indexOf(".") < scoreStep.length() - 2) {
|
|
|
- msg.append("小间隔分只能有一位小数");
|
|
|
- } else {
|
|
|
- imp.setScoreStep(n);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- msg.append(" 间隔分格式错误");
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- String groupNumberStr = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[8]));
|
|
|
- if (StringUtils.isNotBlank(groupNumberStr)) {
|
|
|
- try {
|
|
|
- Integer n = Integer.valueOf(groupNumberStr);
|
|
|
- if (n <= 0) {
|
|
|
- msg.append(" 评卷分组不能小于0");
|
|
|
- } else {
|
|
|
- imp.setGroupNumber(n);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- msg.append(" 评卷分组格式错误");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Long paperId = imp.getPaperId();
|
|
|
- Integer groupNumber = imp.getGroupNumber();
|
|
|
- Double questionScore = imp.getScore();
|
|
|
- if (Objects.nonNull(paperId) && Objects.nonNull(groupNumber) && Objects.nonNull(questionScore)) {
|
|
|
- // 有分组信息才解析双评信息
|
|
|
- String groupKey = paperId + "-" + groupNumber;
|
|
|
- ArbitrateMethod arbitrateMethod = null;
|
|
|
- Double doubleRate = null;
|
|
|
- Double arbitrateThreshold = null;
|
|
|
-
|
|
|
- if (doubleMarkSettingMap.containsKey(groupKey)) {
|
|
|
- DoubleMarkImportParam doubleMarkImportParam = doubleMarkSettingMap.get(groupKey);
|
|
|
- arbitrateMethod = doubleMarkImportParam.getArbitrateMethod();
|
|
|
- doubleRate = doubleMarkImportParam.getDoubleRate();
|
|
|
- arbitrateThreshold = doubleMarkImportParam.getArbitrateThreshold();
|
|
|
- }
|
|
|
-
|
|
|
- String arbitrateMethodStr = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[10]));
|
|
|
- String doubleRateStr = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[11]));
|
|
|
- String arbitrateThresholdStr = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[12]));
|
|
|
-
|
|
|
- // 双评比例
|
|
|
- if (StringUtils.isNotBlank(doubleRateStr)) {
|
|
|
- try {
|
|
|
- double n = Double.parseDouble(doubleRateStr);
|
|
|
-
|
|
|
- if (n < 0 || n > 1) {
|
|
|
- msg.append(" 双评比例只能在(0~1)");
|
|
|
- } else {
|
|
|
- if (Objects.nonNull(doubleRate) && !doubleRate.equals(n)) {
|
|
|
- msg.append(" 同分组的双评比例必须相同");
|
|
|
- } else {
|
|
|
- doubleRate = n;
|
|
|
- imp.setDoubleRate(doubleRate);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- msg.append(" 双评比例格式错误");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (Objects.nonNull(doubleRate) && doubleRate > 0) {
|
|
|
- // 开启双评才继续解析 仲裁方式和仲裁值
|
|
|
- // 仲裁方式(0-分组,1-小题)
|
|
|
- if (StringUtils.isNotBlank(arbitrateMethodStr)) {
|
|
|
- try {
|
|
|
- int n = Integer.parseInt(arbitrateMethodStr);
|
|
|
- List<ArbitrateMethod> arbitrateMethodList = Arrays.stream(ArbitrateMethod.values())
|
|
|
- .filter(e -> e.getValue().equals(n)).collect(Collectors.toList());
|
|
|
- if (arbitrateMethodList.size() != 1) {
|
|
|
- msg.append(" 仲裁方式只能选择0或1");
|
|
|
- } else {
|
|
|
- if (Objects.nonNull(arbitrateMethod) && !arbitrateMethod.equals(
|
|
|
- arbitrateMethodList.get(0))) {
|
|
|
- msg.append(" 同分组的仲裁方式必须相同");
|
|
|
- } else {
|
|
|
- arbitrateMethod = arbitrateMethodList.get(0);
|
|
|
- imp.setArbitrateMethod(arbitrateMethod);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- msg.append(" 仲裁方式格式错误");
|
|
|
- }
|
|
|
- } else {
|
|
|
- msg.append(" 仲裁方式不能为空");
|
|
|
- }
|
|
|
-
|
|
|
- if (Objects.nonNull(arbitrateMethod)) {
|
|
|
- // 仲裁方式不为空才解析
|
|
|
- // 仲裁阀值
|
|
|
- if (StringUtils.isNotBlank(arbitrateThresholdStr)) {
|
|
|
- try {
|
|
|
- double n = Double.parseDouble(arbitrateThresholdStr);
|
|
|
- if (n < 0) {
|
|
|
- msg.append(" 仲裁阀值不能小于0");
|
|
|
- }
|
|
|
- if (ArbitrateMethod.QUESTION_ARBITRATE.equals(arbitrateMethod)) {
|
|
|
- if (n > questionScore) {
|
|
|
- msg.append(" 仲裁阀值不能超过小题满分");
|
|
|
- }
|
|
|
- } else if (ArbitrateMethod.GROUP_ARBITRATE.equals(arbitrateMethod)) {
|
|
|
- if (Objects.nonNull(arbitrateThreshold) && !arbitrateThreshold.equals(n)) {
|
|
|
- msg.append(" 同分组的仲裁阀值必须相同");
|
|
|
- }
|
|
|
- }
|
|
|
- arbitrateThreshold = n;
|
|
|
- imp.setArbitrateThreshold(n);
|
|
|
- } catch (Exception e) {
|
|
|
- msg.append(" 仲裁阀值格式错误");
|
|
|
- }
|
|
|
- } else {
|
|
|
- msg.append(" 仲裁阀值不能为空");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (!doubleMarkSettingMap.containsKey(groupKey)) {
|
|
|
- List<Integer> indexList = new ArrayList<>();
|
|
|
- indexList.add(i + 3);
|
|
|
- doubleMarkSettingMap.put(groupKey,
|
|
|
- new DoubleMarkImportParam(arbitrateMethod, doubleRate, arbitrateThreshold, indexList,
|
|
|
- questionScore));
|
|
|
- } else {
|
|
|
- DoubleMarkImportParam cellMap = doubleMarkSettingMap.get(groupKey);
|
|
|
- cellMap.getIndexes().add(i + 3);
|
|
|
- cellMap.setTotalScore(cellMap.getTotalScore() + questionScore);
|
|
|
- }
|
|
|
- }
|
|
|
- if (msg.length() > 0) {
|
|
|
- failRecords.add(newError(i + 3, msg.toString()));
|
|
|
- } else {
|
|
|
- ret.add(imp);
|
|
|
- }
|
|
|
- }
|
|
|
- // 检测分组仲裁的分组 分组阈值设置是否超过整组分数
|
|
|
- doubleMarkSettingMap.forEach((k, v) -> {
|
|
|
- if (v.getArbitrateMethod() != null && v.getArbitrateMethod().equals(ArbitrateMethod.GROUP_ARBITRATE)) {
|
|
|
- if (v.getArbitrateThreshold() > v.getTotalScore()) {
|
|
|
- failRecords.add(newError(v.getIndexes().get(0), " 分组仲裁阀值不能超过分组满分"));
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
- return failRecords;
|
|
|
- }
|
|
|
- this.saveStruct(ret, user, failRecords);
|
|
|
- if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
- }
|
|
|
- return failRecords;
|
|
|
- } catch (StatusException e) {
|
|
|
- throw e;
|
|
|
- } catch (Exception e) {
|
|
|
- throw new RuntimeException("系统错误", e);
|
|
|
- } finally {
|
|
|
- if (inputStream != null) {
|
|
|
- try {
|
|
|
- inputStream.close();
|
|
|
- } catch (IOException e) {
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void saveStruct(List<PaperStructInfoVo> cards, User user, List<String> failRecords) {
|
|
|
- Map<Long,String> map=new HashMap<>();
|
|
|
- for(PaperStructInfoVo vo:cards) {
|
|
|
- map.put(vo.getPaperId(), vo.getCourseCode());
|
|
|
- }
|
|
|
- List<StructDomain> ces = getBeans(cards);
|
|
|
-// checkStruct(ces, failRecords,map);
|
|
|
- if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- for (StructDomain domain : ces) {
|
|
|
- try {
|
|
|
- paperDetailService.structImport(domain, user);
|
|
|
- } catch (StatusException e) {
|
|
|
- failRecords.add("科目:"+map.get(domain.getPaperId())+" "+e.getMessage());
|
|
|
- } catch (Exception e) {
|
|
|
- throw new RuntimeException("系统错误", e);
|
|
|
- }
|
|
|
- }
|
|
|
- List<PaperGroupDomain> list = getPaperGroups(cards);
|
|
|
- for (PaperGroupDomain domain : list) {
|
|
|
- try {
|
|
|
- paperGroupService.groupSave(domain, user);
|
|
|
- } catch (StatusException e) {
|
|
|
- failRecords.add("科目:"+map.get(domain.getPaperId())+" "+e.getMessage());
|
|
|
- } catch (Exception e) {
|
|
|
- throw new RuntimeException("系统错误", e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private List<PaperGroupDomain> getPaperGroups(List<PaperStructInfoVo> cards) {
|
|
|
- Map<String,PaperGroupDomain> map = new HashMap<>();
|
|
|
- for (PaperStructInfoVo info : cards) {
|
|
|
- if(info.getGroupNumber()!=null){
|
|
|
- PaperGroupDomain curGroup =map.get(getKey(info));
|
|
|
- if(curGroup==null){
|
|
|
- curGroup = new PaperGroupDomain();
|
|
|
- curGroup.setPaperId(info.getPaperId());
|
|
|
- curGroup.setNumber(info.getGroupNumber());
|
|
|
- if (Objects.nonNull(info.getDoubleRate()) && info.getDoubleRate()>0){
|
|
|
- curGroup.setDoubleEnable(true);
|
|
|
- curGroup.setDoubleRate(info.getDoubleRate());
|
|
|
- if (Objects.nonNull(info.getArbitrateMethod())){
|
|
|
- curGroup.setArbitrateMethod(info.getArbitrateMethod());
|
|
|
- }
|
|
|
- if (Objects.nonNull(info.getArbitrateThreshold())){
|
|
|
- curGroup.setArbitrateThreshold(info.getArbitrateThreshold());
|
|
|
- }
|
|
|
- } else {
|
|
|
- curGroup.setDoubleEnable(false);
|
|
|
- }
|
|
|
- curGroup.setGroupUnits(new ArrayList<>());
|
|
|
- }
|
|
|
- PaperGroupUnit unit = new PaperGroupUnit();
|
|
|
- unit.setDetailNumber(info.getDetailNumber());
|
|
|
- unit.setDetailUnitNumber(info.getUnitNumber());
|
|
|
- if (Objects.equals(ArbitrateMethod.QUESTION_ARBITRATE, info.getArbitrateMethod()) && Objects.nonNull(info.getArbitrateThreshold())){
|
|
|
- unit.setArbitrateThreshold(info.getArbitrateThreshold());
|
|
|
- }
|
|
|
- curGroup.getGroupUnits().add(unit);
|
|
|
- map.put(getKey(info),curGroup);
|
|
|
- }
|
|
|
- }
|
|
|
- List<PaperGroupDomain> list = map.values().stream().collect(Collectors.toList());
|
|
|
- return list;
|
|
|
- }
|
|
|
- private String getKey(PaperStructInfoVo p) {
|
|
|
- return p.getPaperId()+"-"+p.getCourseCode()+"-"+p.getGroupNumber();
|
|
|
- }
|
|
|
-// private void checkStruct(List<StructDomain> ces, List<String> failRecords,Map<Long,String> courseMap) {
|
|
|
-// for (StructDomain card : ces) {
|
|
|
-// int lastDetailNum = 0;
|
|
|
-// for (PaperDetail detail : card.getStructInfo()) {
|
|
|
-// if (detail.getNumber() - lastDetailNum != 1) {
|
|
|
-// failRecords.add(
|
|
|
-// "科目:" + courseMap.get(card.getPaperId()) + ",大题号" + detail.getNumber() + "错误");
|
|
|
-// }
|
|
|
-// lastDetailNum = detail.getNumber();
|
|
|
-// int lastUnitNum = 0;
|
|
|
-// for (PaperDetailUnit unit : detail.getUnits()) {
|
|
|
-// if (unit.getNumber() - lastUnitNum != 1) {
|
|
|
-// failRecords.add("科目:" + courseMap.get(card.getPaperId()) + ",大题号:"
|
|
|
-// + detail.getNumber() + ",小题号" + unit.getNumber() + "错误");
|
|
|
-// }
|
|
|
-// lastUnitNum = unit.getNumber();
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
- 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);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<PaperStructInfoVo> subjectiveList(PaperQuery query, User user) {
|
|
|
- if (query.getSchoolId() == null) {
|
|
|
- throw new StatusException("学校不能为空");
|
|
|
- }
|
|
|
- if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(query.getSchoolId())) {
|
|
|
- throw new StatusException("没有权限");
|
|
|
- }
|
|
|
- return this.baseMapper.subjectiveList(query,ArbitrateMethod.GROUP_ARBITRATE);
|
|
|
- }
|
|
|
+
|
|
|
+ private static final String[] SUBJECT_EXCEL_HEADER = new String[] { "科目代码", "科目名称" };
|
|
|
+
|
|
|
+ private static final String[] SUBJECT_STRUCT_EXCEL_HEADER = new String[] { "科目代码*", "科目名称", "大题名称*", "题目昵称",
|
|
|
+ "大题号(只能用小写数字)*", "小题号(只能用小写数字)*", "小题满分*", "间隔分*", "评卷分组(只能用小写数字)*", "图片序号(用英文逗号分割)", "仲裁方式(0-分组,1-小题)",
|
|
|
+ "双评比例(0~1)", "仲裁阀值", "合分策略(1-平均,2-最高,3-最低)", "评卷模式(common-普通,track-轨迹)", "试评数量(0-跳过试评)", "选做题数量" };
|
|
|
+
|
|
|
+ @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) {
|
|
|
+ throw new StatusException("未找到考试批次");
|
|
|
+ }
|
|
|
+ if (!ExamStatus.EDIT.equals(exam.getExamStatus())) {
|
|
|
+ throw new StatusException("考试未开放上报,不能设置结构信息或分组信息");
|
|
|
+ }
|
|
|
+ if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(exam.getSchoolId())) {
|
|
|
+ throw new StatusException("没有权限");
|
|
|
+ }
|
|
|
+ InputStream inputStream = null;
|
|
|
+ try {
|
|
|
+ inputStream = file.getInputStream();
|
|
|
+ ExcelReader reader = ExcelReader.create(ExcelType.XLSX, inputStream, 0);
|
|
|
+ List<DataMap> lineList = reader.getDataMapList();
|
|
|
+ if (!Arrays.equals(SUBJECT_EXCEL_HEADER, reader.getColumnNames())) {
|
|
|
+ throw new StatusException("Excel表头错误");
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(lineList)) {
|
|
|
+ throw new StatusException("Excel无内容");
|
|
|
+ }
|
|
|
+ if (1001 < lineList.size()) {
|
|
|
+ throw new StatusException("数据行数不能超过1000");
|
|
|
+ }
|
|
|
+ List<String> failRecords = new ArrayList<>();
|
|
|
+ List<PaperEntity> 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.setStructFinish(false);
|
|
|
+ imp.setExamId(examId);
|
|
|
+ String code = trimAndNullIfBlank(line.get(SUBJECT_EXCEL_HEADER[0]));
|
|
|
+ if (StringUtils.isBlank(code)) {
|
|
|
+ msg.append(" 科目代码不能为空");
|
|
|
+ } else if (code.length() > 50) {
|
|
|
+ msg.append(" 科目代码不能超过50个字符");
|
|
|
+ }
|
|
|
+
|
|
|
+ String name = trimAndNullIfBlank(line.get(SUBJECT_EXCEL_HEADER[1]));
|
|
|
+ if (StringUtils.isBlank(name)) {
|
|
|
+ msg.append(" 科目名称不能为空");
|
|
|
+ } else if (name.length() > 50) {
|
|
|
+ msg.append(" 科目名称不能超过50个字符");
|
|
|
+ }
|
|
|
+ if (msg.length() == 0) {
|
|
|
+ CourseEntity course = courseService.saveOrGet(exam.getSchoolId(), code, name);
|
|
|
+ imp.setCourseId(course.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (msg.length() > 0) {
|
|
|
+ failRecords.add(newError(i + 1, msg.toString()));
|
|
|
+ } else {
|
|
|
+ ret.add(imp);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ }
|
|
|
+ return failRecords;
|
|
|
+ } catch (StatusException e) {
|
|
|
+ throw e;
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("系统错误", e);
|
|
|
+ } finally {
|
|
|
+ if (inputStream != null) {
|
|
|
+ try {
|
|
|
+ inputStream.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String trimAndNullIfBlank(String s) {
|
|
|
+ if (StringUtils.isBlank(s)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return s.trim();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String newError(int lineNum, String msg) {
|
|
|
+ return "第" + lineNum + "行" + msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ExamPaperCountVo> findPaperCount(List<Long> examIds) {
|
|
|
+ return this.baseMapper.findPaperCount(examIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer findPaperCount(Long examId) {
|
|
|
+ QueryWrapper<PaperEntity> wrapper = new QueryWrapper<>();
|
|
|
+ LambdaQueryWrapper<PaperEntity> lw = wrapper.lambda();
|
|
|
+ lw.eq(PaperEntity::getExamId, examId);
|
|
|
+ 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) {
|
|
|
+ throw new StatusException("学校不能为空");
|
|
|
+ }
|
|
|
+ if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(query.getSchoolId())) {
|
|
|
+ throw new StatusException("没有权限");
|
|
|
+ }
|
|
|
+ IPage<PaperVo> iPage = this.baseMapper.page(new Page<>(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(PaperVo::getId).distinct().collect(Collectors.toList());
|
|
|
+ List<GroupCountVo> ret = paperGroupService.findGroupCount(paperIds);
|
|
|
+ if (ret != null && ret.size() > 0) {
|
|
|
+ Map<Long, Integer> countMap = new HashMap<>();
|
|
|
+ Map<Long, Boolean> doubleEnableMap = new HashMap<>();
|
|
|
+ for (GroupCountVo item : ret) {
|
|
|
+ countMap.put(item.getPaperId(), item.getGroupCount());
|
|
|
+ doubleEnableMap.put(item.getPaperId(), item.getDoubleEnable());
|
|
|
+ }
|
|
|
+ for (PaperVo vo : dataList) {
|
|
|
+ vo.setGroupCount(countMap.get(vo.getId()));
|
|
|
+ vo.setDoubleEnable(doubleEnableMap.get(vo.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }.setDataForBatch(iPage.getRecords(), 20);
|
|
|
+ for (PaperVo vo : iPage.getRecords()) {
|
|
|
+ if (vo.getGroupCount() == null) {
|
|
|
+ vo.setGroupCount(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return PageUtil.of(iPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PaperVo> list(Long examId, User user) {
|
|
|
+ ExamEntity exam = examService.getById(examId);
|
|
|
+ if (exam == null) {
|
|
|
+ throw new StatusException("未找到考试批次");
|
|
|
+ }
|
|
|
+ if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(exam.getSchoolId())) {
|
|
|
+ throw new StatusException("没有权限");
|
|
|
+ }
|
|
|
+ List<PaperVo> ret = this.baseMapper.myPaperlist(examId, user.getId());
|
|
|
+ if (CollectionUtils.isNotEmpty(ret)) {
|
|
|
+ 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(ret, 20);
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PaperInfoVo info(Long id, User user) {
|
|
|
+ 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();
|
|
|
+ BeanUtils.copyProperties(paper, vo);
|
|
|
+ CourseEntity course = courseService.getById(vo.getCourseId());
|
|
|
+ vo.setCourseCode(course.getCode());
|
|
|
+ vo.setCourseName(course.getName());
|
|
|
+ vo.setStructInfo(paperDetailService.getStructInfo(vo.getId()));
|
|
|
+ vo.setGroupInfo(paperGroupService.getGroupInfo(vo.getId()));
|
|
|
+
|
|
|
+ String defaultDoubleSetStr = paper.getDefaultDoubleSet();
|
|
|
+ if (!StringUtils.isBlank(defaultDoubleSetStr)) {
|
|
|
+ vo.setDefaultDoubleSet(JSON.parseObject(defaultDoubleSetStr, DefaultDoubleSet.class));
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public List<String> importSubjectStruct(Long examId, User user, MultipartFile file) {
|
|
|
+ ExamEntity exam = examService.getById(examId);
|
|
|
+ if (exam == null) {
|
|
|
+ throw new StatusException("未找到考试批次");
|
|
|
+ }
|
|
|
+ if (!ExamStatus.EDIT.equals(exam.getExamStatus())) {
|
|
|
+ throw new StatusException("考试未开放上报,不能设置结构信息或分组信息");
|
|
|
+ }
|
|
|
+ if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(exam.getSchoolId())) {
|
|
|
+ throw new StatusException("没有权限");
|
|
|
+ }
|
|
|
+ InputStream inputStream = null;
|
|
|
+ try {
|
|
|
+ inputStream = file.getInputStream();
|
|
|
+ ExcelReader reader = ExcelReader.create(ExcelType.XLSX, inputStream, 1);
|
|
|
+ List<DataMap> lineList = reader.getDataMapList();
|
|
|
+ if (!Arrays.equals(SUBJECT_STRUCT_EXCEL_HEADER, reader.getColumnNames())) {
|
|
|
+ throw new StatusException("Excel表头错误");
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(lineList)) {
|
|
|
+ throw new StatusException("Excel无内容");
|
|
|
+ }
|
|
|
+ if (10001 < lineList.size()) {
|
|
|
+ throw new StatusException("数据行数不能超过10000");
|
|
|
+ }
|
|
|
+ List<String> failRecords = new ArrayList<>();
|
|
|
+ List<PaperStructInfoVo> ret = new ArrayList<>();
|
|
|
+ // 双评设置
|
|
|
+ Map<String, DoubleMarkImportParam> doubleMarkSettingMap = new HashMap<>();
|
|
|
+ for (int i = 0; i < lineList.size(); i++) {
|
|
|
+ DataMap line = lineList.get(i);
|
|
|
+
|
|
|
+ StringBuilder msg = new StringBuilder();
|
|
|
+
|
|
|
+ PaperStructInfoVo imp = new PaperStructInfoVo();
|
|
|
+ String code = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[0]));
|
|
|
+ if (StringUtils.isBlank(code)) {
|
|
|
+ msg.append(" 科目代码不能为空");
|
|
|
+ } else if (code.length() > 50) {
|
|
|
+ msg.append(" 科目代码不能超过50个字符");
|
|
|
+ }
|
|
|
+ imp.setCourseCode(code);
|
|
|
+
|
|
|
+ String name = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[1]));
|
|
|
+ if (StringUtils.isBlank(name)) {
|
|
|
+ msg.append(" 科目名称不能为空");
|
|
|
+ } else if (name.length() > 50) {
|
|
|
+ msg.append(" 科目名称不能超过50个字符");
|
|
|
+ }
|
|
|
+ if (msg.length() == 0) {
|
|
|
+ CourseEntity course = courseService.saveOrGet(exam.getSchoolId(), code, name);
|
|
|
+ PaperEntity paper = saveOrGet(exam.getSchoolId(), examId, course.getId());
|
|
|
+ imp.setPaperId(paper.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ String detailName = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[2]));
|
|
|
+ if (StringUtils.isBlank(detailName)) {
|
|
|
+ msg.append(" 大题名称不能为空");
|
|
|
+ } else if (detailName.length() > 50) {
|
|
|
+ msg.append(" 大题名称不能超过50个字符");
|
|
|
+ }
|
|
|
+ imp.setDetailName(detailName);
|
|
|
+ // 第4列不处理
|
|
|
+ String detailNumber = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[4]));
|
|
|
+ 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.get(SUBJECT_STRUCT_EXCEL_HEADER[5]));
|
|
|
+ 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.get(SUBJECT_STRUCT_EXCEL_HEADER[6]));
|
|
|
+ if (StringUtils.isBlank(score)) {
|
|
|
+ msg.append(" 小题满分不能为空");
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ Double n = Double.valueOf(score);
|
|
|
+ if (n <= 0) {
|
|
|
+ msg.append(" 小题满分不能小于0");
|
|
|
+ } else {
|
|
|
+ if (score.indexOf(".") >= 0 && score.indexOf(".") < score.length() - 2) {
|
|
|
+ msg.append("小题满分只能有一位小数");
|
|
|
+ } else {
|
|
|
+ imp.setScore(n);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ msg.append(" 小题满分格式错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ String scoreStep = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[7]));
|
|
|
+ if (StringUtils.isBlank(scoreStep)) {
|
|
|
+ msg.append(" 间隔分不能为空");
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ Double n = Double.valueOf(scoreStep);
|
|
|
+ if (n <= 0) {
|
|
|
+ msg.append(" 间隔分不能小于0");
|
|
|
+ } else {
|
|
|
+ if (scoreStep.indexOf(".") >= 0 && scoreStep.indexOf(".") < scoreStep.length() - 2) {
|
|
|
+ msg.append("小间隔分只能有一位小数");
|
|
|
+ } else {
|
|
|
+ imp.setScoreStep(n);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ msg.append(" 间隔分格式错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ String groupNumberStr = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[8]));
|
|
|
+ if (StringUtils.isNotBlank(groupNumberStr)) {
|
|
|
+ try {
|
|
|
+ Integer n = Integer.valueOf(groupNumberStr);
|
|
|
+ if (n <= 0) {
|
|
|
+ msg.append(" 评卷分组不能小于0");
|
|
|
+ } else {
|
|
|
+ imp.setGroupNumber(n);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ msg.append(" 评卷分组格式错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Long paperId = imp.getPaperId();
|
|
|
+ Integer groupNumber = imp.getGroupNumber();
|
|
|
+ Double questionScore = imp.getScore();
|
|
|
+ if (Objects.nonNull(paperId) && Objects.nonNull(groupNumber) && Objects.nonNull(questionScore)) {
|
|
|
+ // 有分组信息才解析双评信息
|
|
|
+ String groupKey = paperId + "-" + groupNumber;
|
|
|
+ ArbitrateMethod arbitrateMethod = null;
|
|
|
+ Double doubleRate = null;
|
|
|
+ Double arbitrateThreshold = null;
|
|
|
+
|
|
|
+ if (doubleMarkSettingMap.containsKey(groupKey)) {
|
|
|
+ DoubleMarkImportParam doubleMarkImportParam = doubleMarkSettingMap.get(groupKey);
|
|
|
+ arbitrateMethod = doubleMarkImportParam.getArbitrateMethod();
|
|
|
+ doubleRate = doubleMarkImportParam.getDoubleRate();
|
|
|
+ arbitrateThreshold = doubleMarkImportParam.getArbitrateThreshold();
|
|
|
+ }
|
|
|
+
|
|
|
+ String arbitrateMethodStr = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[10]));
|
|
|
+ String doubleRateStr = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[11]));
|
|
|
+ String arbitrateThresholdStr = trimAndNullIfBlank(line.get(SUBJECT_STRUCT_EXCEL_HEADER[12]));
|
|
|
+
|
|
|
+ // 双评比例
|
|
|
+ if (StringUtils.isNotBlank(doubleRateStr)) {
|
|
|
+ try {
|
|
|
+ double n = Double.parseDouble(doubleRateStr);
|
|
|
+
|
|
|
+ if (n < 0 || n > 1) {
|
|
|
+ msg.append(" 双评比例只能在(0~1)");
|
|
|
+ } else {
|
|
|
+ if (Objects.nonNull(doubleRate) && !doubleRate.equals(n)) {
|
|
|
+ msg.append(" 同分组的双评比例必须相同");
|
|
|
+ } else {
|
|
|
+ doubleRate = n;
|
|
|
+ imp.setDoubleRate(doubleRate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ msg.append(" 双评比例格式错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Objects.nonNull(doubleRate) && doubleRate > 0) {
|
|
|
+ // 开启双评才继续解析 仲裁方式和仲裁值
|
|
|
+ // 仲裁方式(0-分组,1-小题)
|
|
|
+ if (StringUtils.isNotBlank(arbitrateMethodStr)) {
|
|
|
+ try {
|
|
|
+ int n = Integer.parseInt(arbitrateMethodStr);
|
|
|
+ List<ArbitrateMethod> arbitrateMethodList = Arrays.stream(ArbitrateMethod.values())
|
|
|
+ .filter(e -> e.getValue().equals(n)).collect(Collectors.toList());
|
|
|
+ if (arbitrateMethodList.size() != 1) {
|
|
|
+ msg.append(" 仲裁方式只能选择0或1");
|
|
|
+ } else {
|
|
|
+ if (Objects.nonNull(arbitrateMethod)
|
|
|
+ && !arbitrateMethod.equals(arbitrateMethodList.get(0))) {
|
|
|
+ msg.append(" 同分组的仲裁方式必须相同");
|
|
|
+ } else {
|
|
|
+ arbitrateMethod = arbitrateMethodList.get(0);
|
|
|
+ imp.setArbitrateMethod(arbitrateMethod);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ msg.append(" 仲裁方式格式错误");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ msg.append(" 仲裁方式不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Objects.nonNull(arbitrateMethod)) {
|
|
|
+ // 仲裁方式不为空才解析
|
|
|
+ // 仲裁阀值
|
|
|
+ if (StringUtils.isNotBlank(arbitrateThresholdStr)) {
|
|
|
+ try {
|
|
|
+ double n = Double.parseDouble(arbitrateThresholdStr);
|
|
|
+ if (n < 0) {
|
|
|
+ msg.append(" 仲裁阀值不能小于0");
|
|
|
+ }
|
|
|
+ if (ArbitrateMethod.QUESTION_ARBITRATE.equals(arbitrateMethod)) {
|
|
|
+ if (n > questionScore) {
|
|
|
+ msg.append(" 仲裁阀值不能超过小题满分");
|
|
|
+ }
|
|
|
+ } else if (ArbitrateMethod.GROUP_ARBITRATE.equals(arbitrateMethod)) {
|
|
|
+ if (Objects.nonNull(arbitrateThreshold) && !arbitrateThreshold.equals(n)) {
|
|
|
+ msg.append(" 同分组的仲裁阀值必须相同");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ arbitrateThreshold = n;
|
|
|
+ imp.setArbitrateThreshold(n);
|
|
|
+ } catch (Exception e) {
|
|
|
+ msg.append(" 仲裁阀值格式错误");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ msg.append(" 仲裁阀值不能为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!doubleMarkSettingMap.containsKey(groupKey)) {
|
|
|
+ List<Integer> indexList = new ArrayList<>();
|
|
|
+ indexList.add(i + 3);
|
|
|
+ doubleMarkSettingMap.put(groupKey, new DoubleMarkImportParam(arbitrateMethod, doubleRate,
|
|
|
+ arbitrateThreshold, indexList, questionScore));
|
|
|
+ } else {
|
|
|
+ DoubleMarkImportParam cellMap = doubleMarkSettingMap.get(groupKey);
|
|
|
+ cellMap.getIndexes().add(i + 3);
|
|
|
+ cellMap.setTotalScore(cellMap.getTotalScore() + questionScore);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (msg.length() > 0) {
|
|
|
+ failRecords.add(newError(i + 3, msg.toString()));
|
|
|
+ } else {
|
|
|
+ ret.add(imp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 检测分组仲裁的分组 分组阈值设置是否超过整组分数
|
|
|
+ doubleMarkSettingMap.forEach((k, v) -> {
|
|
|
+ if (v.getArbitrateMethod() != null && v.getArbitrateMethod().equals(ArbitrateMethod.GROUP_ARBITRATE)) {
|
|
|
+ if (v.getArbitrateThreshold() > v.getTotalScore()) {
|
|
|
+ failRecords.add(newError(v.getIndexes().get(0), " 分组仲裁阀值不能超过分组满分"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return failRecords;
|
|
|
+ }
|
|
|
+ this.saveStruct(ret, user, failRecords);
|
|
|
+ if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ }
|
|
|
+ return failRecords;
|
|
|
+ } catch (StatusException e) {
|
|
|
+ throw e;
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("系统错误", e);
|
|
|
+ } finally {
|
|
|
+ if (inputStream != null) {
|
|
|
+ try {
|
|
|
+ inputStream.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveStruct(List<PaperStructInfoVo> cards, User user, List<String> failRecords) {
|
|
|
+ Map<Long, String> map = new HashMap<>();
|
|
|
+ for (PaperStructInfoVo vo : cards) {
|
|
|
+ map.put(vo.getPaperId(), vo.getCourseCode());
|
|
|
+ }
|
|
|
+ List<StructDomain> ces = getBeans(cards);
|
|
|
+ // checkStruct(ces, failRecords,map);
|
|
|
+ if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (StructDomain domain : ces) {
|
|
|
+ try {
|
|
|
+ paperDetailService.structImport(domain, user);
|
|
|
+ } catch (StatusException e) {
|
|
|
+ failRecords.add("科目:" + map.get(domain.getPaperId()) + " " + e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("系统错误", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<PaperGroupDomain> list = getPaperGroups(cards);
|
|
|
+ for (PaperGroupDomain domain : list) {
|
|
|
+ try {
|
|
|
+ paperGroupService.groupSave(domain, user);
|
|
|
+ } catch (StatusException e) {
|
|
|
+ failRecords.add("科目:" + map.get(domain.getPaperId()) + " " + e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("系统错误", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<PaperGroupDomain> getPaperGroups(List<PaperStructInfoVo> cards) {
|
|
|
+ Map<String, PaperGroupDomain> map = new HashMap<>();
|
|
|
+ for (PaperStructInfoVo info : cards) {
|
|
|
+ if (info.getGroupNumber() != null) {
|
|
|
+ PaperGroupDomain curGroup = map.get(getKey(info));
|
|
|
+ if (curGroup == null) {
|
|
|
+ curGroup = new PaperGroupDomain();
|
|
|
+ curGroup.setPaperId(info.getPaperId());
|
|
|
+ curGroup.setNumber(info.getGroupNumber());
|
|
|
+ if (Objects.nonNull(info.getDoubleRate()) && info.getDoubleRate() > 0) {
|
|
|
+ curGroup.setDoubleEnable(true);
|
|
|
+ curGroup.setDoubleRate(info.getDoubleRate());
|
|
|
+ if (Objects.nonNull(info.getArbitrateMethod())) {
|
|
|
+ curGroup.setArbitrateMethod(info.getArbitrateMethod());
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(info.getArbitrateThreshold())) {
|
|
|
+ curGroup.setArbitrateThreshold(info.getArbitrateThreshold());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ curGroup.setDoubleEnable(false);
|
|
|
+ }
|
|
|
+ curGroup.setGroupUnits(new ArrayList<>());
|
|
|
+ }
|
|
|
+ PaperGroupUnit unit = new PaperGroupUnit();
|
|
|
+ unit.setDetailNumber(info.getDetailNumber());
|
|
|
+ unit.setDetailUnitNumber(info.getUnitNumber());
|
|
|
+ if (Objects.equals(ArbitrateMethod.QUESTION_ARBITRATE, info.getArbitrateMethod())
|
|
|
+ && Objects.nonNull(info.getArbitrateThreshold())) {
|
|
|
+ unit.setArbitrateThreshold(info.getArbitrateThreshold());
|
|
|
+ }
|
|
|
+ curGroup.getGroupUnits().add(unit);
|
|
|
+ map.put(getKey(info), curGroup);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<PaperGroupDomain> list = map.values().stream().collect(Collectors.toList());
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getKey(PaperStructInfoVo p) {
|
|
|
+ return p.getPaperId() + "-" + p.getCourseCode() + "-" + p.getGroupNumber();
|
|
|
+ }
|
|
|
+ // private void checkStruct(List<StructDomain> ces, List<String>
|
|
|
+ // failRecords,Map<Long,String> courseMap) {
|
|
|
+ // for (StructDomain card : ces) {
|
|
|
+ // int lastDetailNum = 0;
|
|
|
+ // for (PaperDetail detail : card.getStructInfo()) {
|
|
|
+ // if (detail.getNumber() - lastDetailNum != 1) {
|
|
|
+ // failRecords.add(
|
|
|
+ // "科目:" + courseMap.get(card.getPaperId()) + ",大题号" + detail.getNumber() +
|
|
|
+ // "错误");
|
|
|
+ // }
|
|
|
+ // lastDetailNum = detail.getNumber();
|
|
|
+ // int lastUnitNum = 0;
|
|
|
+ // for (PaperDetailUnit unit : detail.getUnits()) {
|
|
|
+ // if (unit.getNumber() - lastUnitNum != 1) {
|
|
|
+ // failRecords.add("科目:" + courseMap.get(card.getPaperId()) + ",大题号:"
|
|
|
+ // + detail.getNumber() + ",小题号" + unit.getNumber() + "错误");
|
|
|
+ // }
|
|
|
+ // lastUnitNum = unit.getNumber();
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PaperStructInfoVo> subjectiveList(PaperQuery query, User user) {
|
|
|
+ if (query.getSchoolId() == null) {
|
|
|
+ throw new StatusException("学校不能为空");
|
|
|
+ }
|
|
|
+ if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(query.getSchoolId())) {
|
|
|
+ throw new StatusException("没有权限");
|
|
|
+ }
|
|
|
+ return this.baseMapper.subjectiveList(query, ArbitrateMethod.GROUP_ARBITRATE);
|
|
|
+ }
|
|
|
|
|
|
}
|