package com.qianwen.smartman.modules.perf.wrapper;
|
|
import cn.hutool.core.util.NumberUtil;
|
import java.time.LocalDate;
|
import java.util.Comparator;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Set;
|
import java.util.stream.Collectors;
|
import org.apache.commons.compress.utils.Lists;
|
import com.qianwen.smartman.common.cache.cps.WorkstationCache;
|
import com.qianwen.smartman.common.constant.MdcConstant;
|
import com.qianwen.core.tool.support.Kv;
|
import com.qianwen.core.tool.utils.DateUtil;
|
import com.qianwen.core.tool.utils.Func;
|
import com.qianwen.smartman.modules.cps.dto.EmployeeDTO;
|
import com.qianwen.smartman.modules.cps.dto.WorkstationDTO;
|
import com.qianwen.smartman.modules.cps.entity.GlobalWcs;
|
import com.qianwen.smartman.modules.mdc.entity.SuperAggregateOutput;
|
import com.qianwen.smartman.modules.mdc.entity.SuperAggregateState;
|
import com.qianwen.smartman.modules.perf.dto.EmployeePerfDTO;
|
|
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/perf/wrapper/PerfWrapper.class */
|
public class PerfWrapper {
|
private static final String X = "x";
|
private static final String OUTPUT_KEY = "11";
|
|
private PerfWrapper() {
|
}
|
|
public static PerfWrapper build() {
|
return new PerfWrapper();
|
}
|
|
private Map<String, GlobalWcs> wcsMap() {
|
List<GlobalWcs> defaultWcs = WorkstationCache.getDefaultWcs();
|
return (Map) defaultWcs.stream().collect(Collectors.toMap((v0) -> {
|
return v0.getCode();
|
}, v -> {
|
return v;
|
}));
|
}
|
|
public List<Map<String, Object>> ewDay(EmployeePerfDTO entity, LocalDate startTime, LocalDate endTime) {
|
List<String> times = Lists.newArrayList();
|
while (!startTime.isEqual(endTime)) {
|
times.add(DateUtil.formatDate(startTime));
|
startTime = startTime.plusDays(1L);
|
}
|
times.add(DateUtil.formatDate(endTime));
|
times.sort(Comparator.reverseOrder());
|
List<SuperAggregateState> states = entity.getStates();
|
Map<String, Map<String, Long>> stateMap = (Map) states.stream().collect(Collectors.groupingBy(c -> {
|
return String.valueOf(c.getFactoryDate());
|
}, Collectors.groupingBy(c2 -> {
|
return String.valueOf(c2.getWcs());
|
}, Collectors.summingLong((v0) -> {
|
return v0.getDurationCollect();
|
}))));
|
List<SuperAggregateOutput> outputs = entity.getOutputs();
|
Map<String, Long> outputMap = (Map) outputs.stream().collect(Collectors.groupingBy(c3 -> {
|
return String.valueOf(c3.getFactoryDate());
|
}, Collectors.summingLong((v0) -> {
|
return v0.getOutput();
|
})));
|
List<Map<String, Object>> data = Lists.newArrayList();
|
for (String time : times) {
|
Map<String, Object> kv = Kv.newMap();
|
kv.put(X, time);
|
String time2 = time.replaceAll("-", "");
|
Map<String, Long> statesKv = stateMap.get(time2);
|
Set<String> codeSet = wcsMap().keySet();
|
if (Func.isEmpty(statesKv)) {
|
codeSet.forEach(c4 -> {
|
kv.put(c4, 0);
|
});
|
} else {
|
Map<String, Long> stateRatio = Kv.newMap();
|
codeSet.forEach(c5 -> {
|
Long l = (Long) stateRatio.put(c5, statesKv.getOrDefault(c5, 0L));
|
});
|
long sum = stateRatio.values().stream().mapToLong(c6 -> {
|
return c6.longValue();
|
}).sum();
|
if (sum == 0) {
|
kv.putAll(stateRatio);
|
} else {
|
stateRatio.forEach((k, v) -> kv.put(k, NumberUtil.decimalFormat(MdcConstant.RATE_FORMAT, v.longValue() / (sum * 1.0d))));
|
}
|
}
|
kv.put(OUTPUT_KEY, outputMap.getOrDefault(time2, 0L));
|
data.add(kv);
|
}
|
return data;
|
}
|
|
public List<Map<String, Object>> ewWeek(EmployeePerfDTO entity, List<Integer> weeks) {
|
List<SuperAggregateState> states = entity.getStates();
|
Map<Integer, Map<String, Long>> stateMap = (Map) states.stream().collect(Collectors.groupingBy((v0) -> {
|
return v0.getFactoryWeek();
|
}, Collectors.groupingBy(c -> {
|
return String.valueOf(c.getWcs());
|
}, Collectors.summingLong((v0) -> {
|
return v0.getDurationCollect();
|
}))));
|
List<SuperAggregateOutput> outputs = entity.getOutputs();
|
Map<Integer, Long> outputMap = (Map) outputs.stream().collect(Collectors.groupingBy((v0) -> {
|
return v0.getFactoryWeek();
|
}, Collectors.summingLong((v0) -> {
|
return v0.getOutput();
|
})));
|
return getEmployeePerfVO(weeks, stateMap, outputMap);
|
}
|
|
public List<Map<String, Object>> ewMonth(EmployeePerfDTO entity, List<Integer> months) {
|
List<SuperAggregateState> states = entity.getStates();
|
Map<Integer, Map<String, Long>> stateMap = (Map) states.stream().collect(Collectors.groupingBy((v0) -> {
|
return v0.getFactoryMonth();
|
}, Collectors.groupingBy(c -> {
|
return String.valueOf(c.getWcs());
|
}, Collectors.summingLong((v0) -> {
|
return v0.getDurationCollect();
|
}))));
|
List<SuperAggregateOutput> outputs = entity.getOutputs();
|
Map<Integer, Long> outputMap = (Map) outputs.stream().collect(Collectors.groupingBy((v0) -> {
|
return v0.getFactoryMonth();
|
}, Collectors.summingLong((v0) -> {
|
return v0.getOutput();
|
})));
|
return getEmployeePerfVO(months, stateMap, outputMap);
|
}
|
|
private List<Map<String, Object>> getEmployeePerfVO(List<Integer> days, Map<Integer, Map<String, Long>> stateMap, Map<Integer, Long> outputMap) {
|
List<Map<String, Object>> data = Lists.newArrayList();
|
days.sort(Comparator.reverseOrder());
|
for (Integer day : days) {
|
Map<String, Object> kv = Kv.newMap();
|
kv.put(X, day);
|
Map<String, Long> statesKv = stateMap.get(day);
|
Set<String> codeSet = wcsMap().keySet();
|
if (Func.isEmpty(statesKv)) {
|
codeSet.forEach(c -> {
|
kv.put(c, 0);
|
});
|
} else {
|
Map<String, Long> stateRatio = Kv.newMap();
|
codeSet.forEach(c2 -> {
|
Long l = (Long) stateRatio.put(c2, statesKv.getOrDefault(c2, 0L));
|
});
|
long sum = stateRatio.values().stream().mapToLong(c3 -> {
|
return c3.longValue();
|
}).sum();
|
if (sum == 0) {
|
kv.putAll(stateRatio);
|
} else {
|
stateRatio.forEach((k, v) ->kv.put(k, NumberUtil.decimalFormat(MdcConstant.RATE_FORMAT, v.longValue() / (sum * 1.0d))));
|
}
|
}
|
kv.put(OUTPUT_KEY, outputMap.getOrDefault(day, 0L));
|
data.add(kv);
|
}
|
return data;
|
}
|
|
public List<Map<String, Object>> etBuild(EmployeePerfDTO entity) {
|
Map<String, WorkstationDTO> works = entity.getWorks();
|
List<SuperAggregateState> states = entity.getStates();
|
Map<Long, Map<String, Long>> stateMap = (Map) states.stream().collect(Collectors.groupingBy((v0) -> {
|
return v0.getWorkstationId();
|
}, Collectors.groupingBy(c -> {
|
return String.valueOf(c.getWcs());
|
}, Collectors.summingLong((v0) -> {
|
return v0.getDurationCollect();
|
}))));
|
List<SuperAggregateOutput> outputs = entity.getOutputs();
|
Map<Long, Long> outputMap = (Map) outputs.stream().collect(Collectors.groupingBy((v0) -> {
|
return v0.getWorkstationId();
|
}, Collectors.summingLong((v0) -> {
|
return v0.getOutput();
|
})));
|
Set<Long> wIdSet = stateMap.keySet();
|
List<Map<String, Object>> data = Lists.newArrayList();
|
for (Long wId : wIdSet) {
|
String name = works.getOrDefault(String.valueOf(wId), new WorkstationDTO()).getName();
|
Map<String, Object> kv = Kv.newMap();
|
kv.put(X, name);
|
Map<String, Long> statesKv = stateMap.get(wId);
|
Set<String> codeSet = wcsMap().keySet();
|
if (Func.isEmpty(statesKv)) {
|
codeSet.forEach(c2 -> {
|
kv.put(c2, 0);
|
});
|
} else {
|
Map<String, Long> stateRatio = Kv.newMap();
|
codeSet.forEach(c3 -> {
|
Long l = (Long) stateRatio.put(c3, statesKv.getOrDefault(c3, 0L));
|
});
|
long sum = stateRatio.values().stream().mapToLong(c4 -> {
|
return c4.longValue();
|
}).sum();
|
if (sum == 0) {
|
kv.putAll(stateRatio);
|
} else {
|
stateRatio.forEach((k, v) ->kv.put(k, NumberUtil.decimalFormat(MdcConstant.RATE_FORMAT, v.longValue() / (sum * 1.0d))));
|
}
|
}
|
kv.put(OUTPUT_KEY, outputMap.getOrDefault(wId, 0L));
|
data.add(kv);
|
}
|
return data;
|
}
|
|
public List<Map<String, Object>> wtBuild(EmployeePerfDTO entity) {
|
Map<String, EmployeeDTO> employees = entity.getEmployees();
|
List<SuperAggregateState> states = entity.getStates();
|
Map<Long, Map<String, Long>> stateMap = (Map) states.stream().collect(Collectors.groupingBy((v0) -> {
|
return v0.getEmployeeId();
|
}, Collectors.groupingBy(c -> {
|
return String.valueOf(c.getWcs());
|
}, Collectors.summingLong((v0) -> {
|
return v0.getDurationCollect();
|
}))));
|
List<SuperAggregateOutput> outputs = entity.getOutputs();
|
Map<Long, Long> outputMap = (Map) outputs.stream().collect(Collectors.groupingBy((v0) -> {
|
return v0.getEmployeeId();
|
}, Collectors.summingLong((v0) -> {
|
return v0.getOutput();
|
})));
|
Set<Long> eIdSet = stateMap.keySet();
|
List<Map<String, Object>> data = Lists.newArrayList();
|
for (Long eId : eIdSet) {
|
String name = employees.getOrDefault(String.valueOf(eId), new EmployeeDTO()).getName();
|
Map<String, Object> kv = Kv.newMap();
|
kv.put(X, name);
|
Map<String, Long> statesKv = stateMap.get(eId);
|
Set<String> codeSet = wcsMap().keySet();
|
if (Func.isEmpty(statesKv)) {
|
codeSet.forEach(c2 -> {
|
kv.put(c2, 0);
|
});
|
} else {
|
Map<String, Long> stateRatio = Kv.newMap();
|
codeSet.forEach(c3 -> {
|
Long l = (Long) stateRatio.put(c3, statesKv.getOrDefault(c3, 0L));
|
});
|
long sum = stateRatio.values().stream().mapToLong(c4 -> {
|
return c4.longValue();
|
}).sum();
|
if (sum == 0) {
|
kv.putAll(stateRatio);
|
} else {
|
stateRatio.forEach((k, v) ->kv.put(k, NumberUtil.decimalFormat(MdcConstant.RATE_FORMAT, v.longValue() / (sum * 1.0d))));
|
}
|
}
|
kv.put(OUTPUT_KEY, outputMap.getOrDefault(eId, 0L));
|
data.add(kv);
|
}
|
return data;
|
}
|
}
|