|
@@ -4,21 +4,19 @@ import cn.hutool.core.bean.BeanUtil;
|
|
import com.alibaba.excel.EasyExcel;
|
|
import com.alibaba.excel.EasyExcel;
|
|
import com.alibaba.excel.ExcelWriter;
|
|
import com.alibaba.excel.ExcelWriter;
|
|
import com.alibaba.excel.write.metadata.WriteSheet;
|
|
import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
|
+import com.googlecode.aviator.AviatorEvaluator;
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
import com.qmth.eds.bean.dto.ExamSyncStudentDto;
|
|
import com.qmth.eds.bean.dto.ExamSyncStudentDto;
|
|
import com.qmth.eds.common.contant.SystemConstant;
|
|
import com.qmth.eds.common.contant.SystemConstant;
|
|
import com.qmth.eds.common.entity.*;
|
|
import com.qmth.eds.common.entity.*;
|
|
-import com.qmth.eds.common.enums.ExamAssignStatusEnum;
|
|
|
|
-import com.qmth.eds.common.enums.ExceptionResultEnum;
|
|
|
|
-import com.qmth.eds.common.enums.TaskResultEnum;
|
|
|
|
-import com.qmth.eds.common.enums.TaskStatusEnum;
|
|
|
|
|
|
+import com.qmth.eds.common.enums.*;
|
|
import com.qmth.eds.common.tools.CloudMarkingUtils;
|
|
import com.qmth.eds.common.tools.CloudMarkingUtils;
|
|
import com.qmth.eds.common.tools.WhuUtils;
|
|
import com.qmth.eds.common.tools.WhuUtils;
|
|
import com.qmth.eds.common.util.FileUtil;
|
|
import com.qmth.eds.common.util.FileUtil;
|
|
-import com.qmth.eds.common.util.ServletUtil;
|
|
|
|
import com.qmth.eds.service.*;
|
|
import com.qmth.eds.service.*;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -27,11 +25,14 @@ import org.slf4j.LoggerFactory;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.math.RoundingMode;
|
|
import java.time.Instant;
|
|
import java.time.Instant;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
import java.time.ZoneId;
|
|
import java.time.ZoneId;
|
|
@@ -276,27 +277,114 @@ public class WhuDataSyncServiceImpl implements WhuDataSyncService {
|
|
public void calcAssignScore(ExamAssign examAssign) {
|
|
public void calcAssignScore(ExamAssign examAssign) {
|
|
examAssign.setStatus(ExamAssignStatusEnum.RUNNING);
|
|
examAssign.setStatus(ExamAssignStatusEnum.RUNNING);
|
|
examAssignService.updateById(examAssign);
|
|
examAssignService.updateById(examAssign);
|
|
|
|
+ String errorMsg = null;
|
|
try {
|
|
try {
|
|
// 选模式
|
|
// 选模式
|
|
-
|
|
|
|
// 解析计算参数
|
|
// 解析计算参数
|
|
|
|
+ JSONObject object = JSON.parseObject(examAssign.getCoefficient());
|
|
|
|
+ Boolean all = object.getBoolean("all");
|
|
|
|
+ Double allValue = object.getDoubleValue("value");
|
|
|
|
|
|
|
|
+ List<ExamSyncStudentDto> finalList = new ArrayList<>();
|
|
List<ExamSyncStudentDto> examSyncStudentDtoList = cloudMarkingScoreService.listExamSyncStudentDtos(examAssign.getSchoolId(), examAssign.getSemesterId(), examAssign.getExamTypeId(), examAssign.getCourseCode(), examAssign.getOpenCollege());
|
|
List<ExamSyncStudentDto> examSyncStudentDtoList = cloudMarkingScoreService.listExamSyncStudentDtos(examAssign.getSchoolId(), examAssign.getSemesterId(), examAssign.getExamTypeId(), examAssign.getCourseCode(), examAssign.getOpenCollege());
|
|
- Map<String, List<ExamSyncStudentDto>> collect = examSyncStudentDtoList.stream().collect(Collectors.groupingBy(ExamSyncStudentDto::getJgmc));
|
|
|
|
- for (Map.Entry<String, List<ExamSyncStudentDto>> entry : collect.entrySet()) {
|
|
|
|
-
|
|
|
|
|
|
+ // 初始卷面最高分
|
|
|
|
+ Double maxTotalScore = examSyncStudentDtoList.stream().map(m -> Double.parseDouble(m.getTotalScore())).max(Comparator.comparingDouble(x -> x)).get();
|
|
|
|
+ if (all) {
|
|
|
|
+ // 卷面最高分
|
|
|
|
+ calcProgress(examAssign.getFormula(), allValue, examSyncStudentDtoList, maxTotalScore, finalList);
|
|
|
|
+ } else {
|
|
|
|
+ Map<String, List<ExamSyncStudentDto>> collect = examSyncStudentDtoList.stream().collect(Collectors.groupingBy(ExamSyncStudentDto::getJgmc));
|
|
|
|
+ for (Map.Entry<String, List<ExamSyncStudentDto>> entry : collect.entrySet()) {
|
|
|
|
+ String college = entry.getKey();
|
|
|
|
+ List<JSONObject> details = JSON.parseArray(object.getString("detail"), JSONObject.class);
|
|
|
|
+ Optional<JSONObject> objectOptional = details.stream().filter(m -> m.getString("college").equals(college)).findFirst();
|
|
|
|
+ if (!objectOptional.isPresent()) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(String.format("开课学院[%s]未设置的参数值", college));
|
|
|
|
+ }
|
|
|
|
+ double collegeValue = objectOptional.get().getDoubleValue("value");
|
|
|
|
+ calcProgress(examAssign.getFormula(), collegeValue, entry.getValue(), maxTotalScore, finalList);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// 更新云阅卷同步表中的赋分值
|
|
// 更新云阅卷同步表中的赋分值
|
|
|
|
+ if (CollectionUtils.isEmpty(finalList)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("赋分值计算失败,请联系管理员");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (ExamSyncStudentDto studentDto : finalList) {
|
|
|
|
+ UpdateWrapper<CloudMarkingScore> updateWrapper = new UpdateWrapper<>();
|
|
|
|
+ updateWrapper.lambda().set(CloudMarkingScore::getAssignScore, studentDto.getAssignScore())
|
|
|
|
+ .eq(CloudMarkingScore::getId, studentDto.getCloudMarkingScoreId());
|
|
|
|
+ cloudMarkingScoreService.update(updateWrapper);
|
|
|
|
+ }
|
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- throw new RuntimeException(e);
|
|
|
|
|
|
+ errorMsg = e.getMessage();
|
|
} finally {
|
|
} finally {
|
|
examAssign.setStatus(ExamAssignStatusEnum.FINISH);
|
|
examAssign.setStatus(ExamAssignStatusEnum.FINISH);
|
|
|
|
+ examAssign.setErrorMsg(errorMsg);
|
|
examAssignService.updateById(examAssign);
|
|
examAssignService.updateById(examAssign);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 计算公共方法
|
|
|
|
+ *
|
|
|
|
+ * @param formula 公式
|
|
|
|
+ * @param value 系数
|
|
|
|
+ * @param examSyncStudentDtoList 源数据
|
|
|
|
+ * @param finalList 计算后数据
|
|
|
|
+ */
|
|
|
|
+ private void calcProgress(FormulaEnum formula, Double value, List<ExamSyncStudentDto> examSyncStudentDtoList, Double maxTotalScore, List<ExamSyncStudentDto> finalList) {
|
|
|
|
+ // 公式1(赋值分=卷面成绩+ (100- 卷面成绩)/赋分系数)
|
|
|
|
+ if (FormulaEnum.FORMULA1.equals(formula)) {
|
|
|
|
+ // x为卷面成绩,y为赋分系数
|
|
|
|
+ String formula1 = "a+(100-x)/b";
|
|
|
|
+ Map<String, Object> paramMap = new HashMap<>();
|
|
|
|
+ paramMap.put("b", value);
|
|
|
|
+ for (ExamSyncStudentDto studentDto : examSyncStudentDtoList) {
|
|
|
|
+ paramMap.put("a", studentDto.getTotalScore());
|
|
|
|
+ String assignScore = AviatorEvaluator.compile(formula1).execute(paramMap).toString();
|
|
|
|
+ studentDto.setAssignScore(assignScore);
|
|
|
|
+ finalList.add(studentDto);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 公式2
|
|
|
|
+ /*
|
|
|
|
+ * 赋值分=ROUND(IF(初始卷面>=参数,55+(初始卷面-参数)/(初始卷面最高分-参数)*(x-55),初始卷面*50/参数)*2,0)/2
|
|
|
|
+ 说明:1.如果初始卷面最高的大于99时,则x=100,否则x=99;
|
|
|
|
+ 2.参数根据每次总体初始成绩的不及格率进行调整。
|
|
|
|
+ */
|
|
|
|
+ else if (FormulaEnum.FORMULA2.equals(formula)) {
|
|
|
|
+ int x = maxTotalScore.doubleValue() > 99 ? 100 : 99;
|
|
|
|
+ // a:初始卷面,b:参数,c:初始卷面最高分,x:说明1中参数
|
|
|
|
+ String formula2_1 = "(55+(a-b)/(c-b)*(x-55))*2";
|
|
|
|
+ String formula2_2 = "(a*50/b)*2";
|
|
|
|
+
|
|
|
|
+ for (ExamSyncStudentDto studentDto : examSyncStudentDtoList) {
|
|
|
|
+ Map<String, Object> paramMap = new HashMap<>();
|
|
|
|
+ Double totalScore = Double.valueOf(studentDto.getTotalScore());
|
|
|
|
+ String tempAssignScore;
|
|
|
|
+ if (totalScore >= value) {
|
|
|
|
+ paramMap.put("a", totalScore.doubleValue());
|
|
|
|
+ paramMap.put("b", value);
|
|
|
|
+ paramMap.put("c", maxTotalScore.doubleValue());
|
|
|
|
+ paramMap.put("x", maxTotalScore.doubleValue());
|
|
|
|
+ tempAssignScore = AviatorEvaluator.compile(formula2_1).execute(paramMap).toString();
|
|
|
|
+ } else {
|
|
|
|
+ paramMap.put("a", totalScore.doubleValue());
|
|
|
|
+ paramMap.put("b", value.doubleValue());
|
|
|
|
+ tempAssignScore = AviatorEvaluator.compile(formula2_2).execute(paramMap).toString();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(tempAssignScore).setScale(0, RoundingMode.HALF_UP);
|
|
|
|
+ String assignScore = bigDecimal.divide(new BigDecimal("2")).toString();
|
|
|
|
+ studentDto.setAssignScore(assignScore);
|
|
|
|
+ finalList.add(studentDto);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
@Transactional
|
|
@Transactional
|
|
public void saveScoreData(Long schoolId, Long collegeId, Long semesterId, Long examTypeId, Integer examId, List<CloudMarkingScore> cloudMarkingScoreList) {
|
|
public void saveScoreData(Long schoolId, Long collegeId, Long semesterId, Long examTypeId, Integer examId, List<CloudMarkingScore> cloudMarkingScoreList) {
|
|
// 删除旧数据
|
|
// 删除旧数据
|
|
@@ -317,34 +405,24 @@ public class WhuDataSyncServiceImpl implements WhuDataSyncService {
|
|
}
|
|
}
|
|
|
|
|
|
// 查询对外数据
|
|
// 查询对外数据
|
|
- QueryWrapper<ExamSyncTotal> totalQueryWrapper = new QueryWrapper<>();
|
|
|
|
- totalQueryWrapper.lambda().eq(ExamSyncTotal::getSchoolId, schoolId)
|
|
|
|
- .eq(ExamSyncTotal::getSemesterId, semesterId)
|
|
|
|
- .eq(ExamSyncTotal::getExamTypeId, examTypeId)
|
|
|
|
- .eq(ExamSyncTotal::getDownloadStatus, true)
|
|
|
|
- .orderByDesc(ExamSyncTotal::getSyncDate);
|
|
|
|
- List<ExamSyncTotal> examSyncTotalList = examSyncTotalService.list(totalQueryWrapper);
|
|
|
|
|
|
+ ExamSyncTotal examSyncTotal = examSyncTotalService.getBySemesterIdAndExamTypeIdAndUseFile(schoolId, semesterId, examTypeId, true);
|
|
|
|
+ if (examSyncTotal == null) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("未设置使用数据文件,请联系管理员处理");
|
|
|
|
+ }
|
|
List<CloudMarkingScoreForeign> cloudMarkingScoreForeigns = new ArrayList<>();
|
|
List<CloudMarkingScoreForeign> cloudMarkingScoreForeigns = new ArrayList<>();
|
|
- if (!examSyncTotalList.isEmpty()) {
|
|
|
|
- ExamSyncTotal examSyncTotal = examSyncTotalList.get(0);
|
|
|
|
- List<ExamSyncStudent> examSyncStudents = examSyncStudentService.listByExamSyncTotalId(examSyncTotal);
|
|
|
|
- for (CloudMarkingScore cloudMarkingScore : cloudMarkingScoreList) {
|
|
|
|
- Optional<ExamSyncStudent> optional = examSyncStudents.stream()
|
|
|
|
- .filter(s -> s.getJxbmc().equals(cloudMarkingScore.getClassName())
|
|
|
|
- && ((StringUtils.isBlank(s.getCloudMarkingCourseCode()) && s.getKch().equals(cloudMarkingScore.getSubjectCode())) || (StringUtils.isNotBlank(s.getCloudMarkingCourseCode()) && s.getCloudMarkingCourseCode().equals(cloudMarkingScore.getSubjectCode())))
|
|
|
|
- && s.getXh().equals(cloudMarkingScore.getStudentCode())).findFirst();
|
|
|
|
- if (!optional.isPresent()) {
|
|
|
|
- cloudMarkingScoreForeigns.add(new CloudMarkingScoreForeign(collegeId, semesterId, examTypeId, examId, null, null, null, cloudMarkingScore.getSubjectCode(), cloudMarkingScore.getSubjectName(), cloudMarkingScore.getStudentCode(), cloudMarkingScore.getTotalScore()));
|
|
|
|
- } else {
|
|
|
|
- ExamSyncStudent examSyncStudent = optional.get();
|
|
|
|
- // 匹配上,保存考务数据表ID
|
|
|
|
- cloudMarkingScore.setExamSyncStudentId(examSyncStudent.getId());
|
|
|
|
- cloudMarkingScoreForeigns.add(new CloudMarkingScoreForeign(collegeId, semesterId, examTypeId, examId, examSyncStudent.getXnm(), examSyncStudent.getXqm(), examSyncStudent.getJxbId(), examSyncStudent.getKch(), examSyncStudent.getKcmc(), examSyncStudent.getXh(), cloudMarkingScore.getTotalScore()));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- for (CloudMarkingScore cloudMarkingScore : cloudMarkingScoreList) {
|
|
|
|
|
|
+ List<ExamSyncStudent> examSyncStudents = examSyncStudentService.listByExamSyncTotalId(examSyncTotal);
|
|
|
|
+ for (CloudMarkingScore cloudMarkingScore : cloudMarkingScoreList) {
|
|
|
|
+ Optional<ExamSyncStudent> optional = examSyncStudents.stream()
|
|
|
|
+ .filter(s -> s.getJxbmc().equals(cloudMarkingScore.getClassName())
|
|
|
|
+ && ((StringUtils.isBlank(s.getCloudMarkingCourseCode()) && s.getKch().equals(cloudMarkingScore.getSubjectCode())) || (StringUtils.isNotBlank(s.getCloudMarkingCourseCode()) && s.getCloudMarkingCourseCode().equals(cloudMarkingScore.getSubjectCode())))
|
|
|
|
+ && s.getXh().equals(cloudMarkingScore.getStudentCode())).findFirst();
|
|
|
|
+ if (!optional.isPresent()) {
|
|
cloudMarkingScoreForeigns.add(new CloudMarkingScoreForeign(collegeId, semesterId, examTypeId, examId, null, null, null, cloudMarkingScore.getSubjectCode(), cloudMarkingScore.getSubjectName(), cloudMarkingScore.getStudentCode(), cloudMarkingScore.getTotalScore()));
|
|
cloudMarkingScoreForeigns.add(new CloudMarkingScoreForeign(collegeId, semesterId, examTypeId, examId, null, null, null, cloudMarkingScore.getSubjectCode(), cloudMarkingScore.getSubjectName(), cloudMarkingScore.getStudentCode(), cloudMarkingScore.getTotalScore()));
|
|
|
|
+ } else {
|
|
|
|
+ ExamSyncStudent examSyncStudent = optional.get();
|
|
|
|
+ // 匹配上,保存考务数据表ID
|
|
|
|
+ cloudMarkingScore.setExamSyncStudentId(examSyncStudent.getId());
|
|
|
|
+ cloudMarkingScoreForeigns.add(new CloudMarkingScoreForeign(collegeId, semesterId, examTypeId, examId, examSyncStudent.getXnm(), examSyncStudent.getXqm(), examSyncStudent.getJxbId(), examSyncStudent.getKch(), examSyncStudent.getKcmc(), examSyncStudent.getXh(), cloudMarkingScore.getTotalScore()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|