|
@@ -1,21 +1,18 @@
|
|
|
package cn.com.qmth.stmms.ms.marking.service;
|
|
|
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Optional;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-import java.util.stream.DoubleStream;
|
|
|
-import java.util.stream.Stream;
|
|
|
-
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
+import cn.com.qmth.stmms.ms.core.cache.ParamCache;
|
|
|
import cn.com.qmth.stmms.ms.core.domain.Level;
|
|
|
import cn.com.qmth.stmms.ms.core.domain.task.MarkTask;
|
|
|
import cn.com.qmth.stmms.ms.core.domain.user.MarkUser;
|
|
|
-import cn.com.qmth.stmms.ms.core.repository.LevelRepo;
|
|
|
import cn.com.qmth.stmms.ms.core.repository.MarkUserRepo;
|
|
|
+import cn.com.qmth.stmms.ms.marking.service.arbitration.ArbitrationService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.DoubleStream;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* 定档
|
|
@@ -32,11 +29,17 @@ public class DetermineLevelService {
|
|
|
/**
|
|
|
* 权重
|
|
|
*/
|
|
|
- WEIGHT
|
|
|
+ WEIGHT,
|
|
|
+ /**
|
|
|
+ * 仲裁
|
|
|
+ */
|
|
|
+ ARBITRATE,
|
|
|
+ /**
|
|
|
+ * 打回
|
|
|
+ */
|
|
|
+ REJECT
|
|
|
}
|
|
|
|
|
|
- @Autowired
|
|
|
- private LevelRepo levelRepo;
|
|
|
@Autowired
|
|
|
private MarkUserRepo markUserRepo;
|
|
|
|
|
@@ -47,17 +50,22 @@ public class DetermineLevelService {
|
|
|
* @param taskBest 是否取优
|
|
|
* @param tasks 任务集合
|
|
|
*/
|
|
|
- public DeterResult determine(boolean majority, boolean taskBest, List<Level> levels, MarkTask... tasks) {
|
|
|
+ public DeterResult determine(Long workId, List<Level> levels, List<MarkTask> markTasks) {
|
|
|
+ //定档
|
|
|
+ boolean majority = Optional.ofNullable(ParamCache.paramMap.get(workId).getMajority()).orElse(1) == 1;
|
|
|
DeterResult majorityResult = null;
|
|
|
DeterResult weightResult = null;
|
|
|
if (majority) {
|
|
|
+ MarkTask[] tasks = markTasks.toArray(new MarkTask[0]);
|
|
|
majorityResult = calcMajority(tasks);
|
|
|
}
|
|
|
- weightResult = calcWeight(levels, tasks);
|
|
|
-
|
|
|
if (majorityResult != null) {
|
|
|
- if (taskBest) {
|
|
|
+ // 是否取优(过半定档和权重,取最优值)
|
|
|
+ boolean takeBest = Optional.ofNullable(ParamCache.paramMap.get(workId).getTakeBest()).orElse(1) == 1;
|
|
|
+ if (takeBest) {
|
|
|
Map<String, Integer> levelMap = levels.stream().collect(Collectors.toMap(Level::getCode, Level::getLevelValue));
|
|
|
+
|
|
|
+ weightResult = calcWeight(levels, markTasks);
|
|
|
// 取优
|
|
|
int majorityLevelValue = levelMap.get(majorityResult.getResult());
|
|
|
int weightLevelValue = levelMap.get(weightResult.getResult());
|
|
@@ -70,8 +78,29 @@ public class DetermineLevelService {
|
|
|
} else {
|
|
|
return majorityResult;
|
|
|
}
|
|
|
- } else {
|
|
|
- return weightResult;
|
|
|
+ }
|
|
|
+ // 无过半档位或者未开启过半定档
|
|
|
+ else {
|
|
|
+ // 仲裁档位差
|
|
|
+ int deviation = Optional.ofNullable(ParamCache.paramMap.get(workId).getDeviation()).orElse(4);
|
|
|
+ // 超过仲裁档位差
|
|
|
+ Set<Integer> sources = markTasks.stream().map(MarkTask::getLevelValue).collect(Collectors.toSet());
|
|
|
+ if (ArbitrationService.overDeviation(deviation, sources)) {
|
|
|
+ boolean autoCallBack = Optional.ofNullable(ParamCache.paramMap.get(workId).getAutoCallback()).orElse(0) == 1;
|
|
|
+ // 开启自动打回
|
|
|
+ if (autoCallBack) {
|
|
|
+ int cumulateError = Optional.ofNullable(ParamCache.paramMap.get(workId).getCumulativeError()).orElse(9);
|
|
|
+ List<String> markerIds = ArbitrationService.calcCumulate(cumulateError, markTasks);
|
|
|
+ // 不是所有评卷员累计误差都大于累计误差值
|
|
|
+ if (markerIds.size() != markTasks.size()) {
|
|
|
+ return new DeterResult(null, DeterType.REJECT, markerIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 打回科组长
|
|
|
+ return new DeterResult(null, DeterType.ARBITRATE);
|
|
|
+ } else {
|
|
|
+ return calcWeight(levels, markTasks);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -84,10 +113,10 @@ public class DetermineLevelService {
|
|
|
//如果相同的数量大于半数,直接定档
|
|
|
Stream<MarkTask> taskStream = Stream.of(tasks);
|
|
|
Optional<Map.Entry<String, Long>> optional = taskStream
|
|
|
- .collect(Collectors.groupingBy(i -> i.getResult().toString(), Collectors.counting()))
|
|
|
+ .collect(Collectors.groupingBy(MarkTask::getResult, Collectors.counting()))
|
|
|
.entrySet()
|
|
|
.stream()
|
|
|
- .max(Comparator.comparing(Map.Entry::getValue));
|
|
|
+ .max(Map.Entry.comparingByValue());
|
|
|
if (optional.isPresent()) {
|
|
|
Map.Entry<String, Long> entry = optional.get();
|
|
|
if (entry.getValue() > tasks.length / 2) {
|
|
@@ -100,15 +129,16 @@ public class DetermineLevelService {
|
|
|
/**
|
|
|
* 计算权重值
|
|
|
*
|
|
|
- * @param tasks 任务集合
|
|
|
+ * @param markTasks 任务集合
|
|
|
*/
|
|
|
- private DeterResult calcWeight(List<Level> levels, MarkTask[] tasks) {
|
|
|
+ private DeterResult calcWeight(List<Level> levels, List<MarkTask> markTasks) {
|
|
|
+ MarkTask[] tasks = markTasks.toArray(new MarkTask[0]);
|
|
|
//通过权重计算,平均值四舍五入
|
|
|
double[] values = new double[tasks.length];
|
|
|
double[] weights = new double[tasks.length];
|
|
|
for (int i = 0; i < tasks.length; i++) {
|
|
|
String levelResult = tasks[i].getResult();
|
|
|
- Level level = levels.stream().filter(m->m.getCode().equals(levelResult)).findFirst().orElse(null);
|
|
|
+ Level level = levels.stream().filter(m -> m.getCode().equals(levelResult)).findFirst().orElse(null);
|
|
|
if (level == null) {
|
|
|
throw new RuntimeException("无此档位");
|
|
|
}
|
|
@@ -137,12 +167,19 @@ public class DetermineLevelService {
|
|
|
class DeterResult {
|
|
|
private String result;
|
|
|
private DetermineLevelService.DeterType deterType;
|
|
|
+ private List<String> rejectTasks;
|
|
|
|
|
|
public DeterResult(String result, DetermineLevelService.DeterType deterType) {
|
|
|
this.result = result;
|
|
|
this.deterType = deterType;
|
|
|
}
|
|
|
|
|
|
+ public DeterResult(String result, DetermineLevelService.DeterType deterType, List<String> rejectTasks) {
|
|
|
+ this.result = result;
|
|
|
+ this.deterType = deterType;
|
|
|
+ this.rejectTasks = rejectTasks;
|
|
|
+ }
|
|
|
+
|
|
|
public String getResult() {
|
|
|
return result;
|
|
|
}
|
|
@@ -158,4 +195,12 @@ class DeterResult {
|
|
|
public void setDeterType(DetermineLevelService.DeterType deterType) {
|
|
|
this.deterType = deterType;
|
|
|
}
|
|
|
+
|
|
|
+ public List<String> getRejectTasks() {
|
|
|
+ return rejectTasks;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setRejectTasks(List<String> rejectTasks) {
|
|
|
+ this.rejectTasks = rejectTasks;
|
|
|
+ }
|
|
|
}
|