|
@@ -4,7 +4,7 @@ import java.util.Comparator;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Optional;
|
|
import java.util.Optional;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
-import java.util.stream.IntStream;
|
|
|
|
|
|
+import java.util.stream.DoubleStream;
|
|
import java.util.stream.Stream;
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -12,7 +12,9 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import cn.com.qmth.stmms.ms.core.domain.Level;
|
|
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.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.LevelRepo;
|
|
|
|
+import cn.com.qmth.stmms.ms.core.repository.MarkUserRepo;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 定档
|
|
* 定档
|
|
@@ -34,23 +36,27 @@ public class DetermineLevelService {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private LevelRepo levelRepo;
|
|
private LevelRepo levelRepo;
|
|
|
|
+ @Autowired
|
|
|
|
+ private MarkUserRepo markUserRepo;
|
|
|
|
|
|
- public DeterResult determine(MarkTask...tasks){
|
|
|
|
- //如果相同的数量大于半数,直接定档
|
|
|
|
- Stream<MarkTask> taskStream = Stream.of(tasks);
|
|
|
|
- Optional<Map.Entry<String,Long>> optional = taskStream
|
|
|
|
- .collect(Collectors.groupingBy(i -> i.getResult().toString(), Collectors.counting()))
|
|
|
|
- .entrySet()
|
|
|
|
- .stream()
|
|
|
|
- .max(Comparator.comparing(Map.Entry::getValue));
|
|
|
|
- if(optional.isPresent()){
|
|
|
|
- Map.Entry<String,Long> entry = optional.get();
|
|
|
|
- if(entry.getValue() > tasks.length/2){
|
|
|
|
- return new DeterResult(entry.getKey(),DeterType.MAJORITY);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ public DeterResult determine(boolean majority,MarkTask...tasks){
|
|
|
|
+ if(majority){
|
|
|
|
+ //如果相同的数量大于半数,直接定档
|
|
|
|
+ Stream<MarkTask> taskStream = Stream.of(tasks);
|
|
|
|
+ Optional<Map.Entry<String,Long>> optional = taskStream
|
|
|
|
+ .collect(Collectors.groupingBy(i -> i.getResult().toString(), Collectors.counting()))
|
|
|
|
+ .entrySet()
|
|
|
|
+ .stream()
|
|
|
|
+ .max(Comparator.comparing(Map.Entry::getValue));
|
|
|
|
+ if(optional.isPresent()){
|
|
|
|
+ Map.Entry<String,Long> entry = optional.get();
|
|
|
|
+ if(entry.getValue() > tasks.length/2){
|
|
|
|
+ return new DeterResult(entry.getKey(),DeterType.MAJORITY);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
//通过权重计算,平均值四舍五入
|
|
//通过权重计算,平均值四舍五入
|
|
- int[] values = new int[tasks.length];
|
|
|
|
|
|
+ double[] values = new double[tasks.length];
|
|
Long workId = null;
|
|
Long workId = null;
|
|
for (int i = 0; i < tasks.length; i++) {
|
|
for (int i = 0; i < tasks.length; i++) {
|
|
workId = tasks[i].getWorkId();
|
|
workId = tasks[i].getWorkId();
|
|
@@ -58,9 +64,11 @@ public class DetermineLevelService {
|
|
if(level == null){
|
|
if(level == null){
|
|
throw new RuntimeException("无此档位");
|
|
throw new RuntimeException("无此档位");
|
|
}
|
|
}
|
|
- values[i] = level.getWeight();
|
|
|
|
|
|
+ MarkUser marker = markUserRepo.findOne(tasks[i].getMarkerId());
|
|
|
|
+ double maekerWeight = marker.getWeight();
|
|
|
|
+ values[i] = level.getWeight()*maekerWeight;
|
|
}
|
|
}
|
|
- int avg = (int)Math.round(IntStream.of(values).average().orElse(0));
|
|
|
|
|
|
+ int avg = (int)Math.round(DoubleStream.of(values).average().orElse(0));
|
|
Optional<Level> levelOptional = levelRepo.findByWorkId(workId).stream().filter(o -> o.getMaxScore() >= avg && o.getMinScore() <= avg).findFirst();
|
|
Optional<Level> levelOptional = levelRepo.findByWorkId(workId).stream().filter(o -> o.getMaxScore() >= avg && o.getMinScore() <= avg).findFirst();
|
|
Level level = levelOptional.orElseThrow(null);
|
|
Level level = levelOptional.orElseThrow(null);
|
|
return new DeterResult(level.getCode(),DeterType.WEIGHT);
|
|
return new DeterResult(level.getCode(),DeterType.WEIGHT);
|