|
@@ -136,14 +136,16 @@ public class TwinEmpCalcServiceImpl implements ITwinEmpCalcService {
|
|
|
Map<String, List<TwinCalcHourSpec>> specHourMap = specHourList.stream().collect(Collectors.groupingBy(o -> o.getDeviceId() + "-" + o.getTeam(), LinkedHashMap::new, Collectors.toList()));
|
|
Map<String, List<TwinCalcHourSpec>> specHourMap = specHourList.stream().collect(Collectors.groupingBy(o -> o.getDeviceId() + "-" + o.getTeam(), LinkedHashMap::new, Collectors.toList()));
|
|
|
List<TwinCalcDay> twinCalcDays = twinCalcDayService.selectTwinCalcDayListByTime(date, date);
|
|
List<TwinCalcDay> twinCalcDays = twinCalcDayService.selectTwinCalcDayListByTime(date, date);
|
|
|
Map<Long, TwinCalcDay> calcMap = twinCalcDays.stream().collect(Collectors.toMap(TwinCalcDay::getDeviceId, o -> o));
|
|
Map<Long, TwinCalcDay> calcMap = twinCalcDays.stream().collect(Collectors.toMap(TwinCalcDay::getDeviceId, o -> o));
|
|
|
|
|
+ Map<Long, BigDecimal> effMap = twinCalcDays.stream().collect(Collectors.toMap(TwinCalcDay::getDeviceId, TwinCalcDay::getEfficiency));
|
|
|
TwinEmp emp = empService.selectTwinEmpByDate(date);
|
|
TwinEmp emp = empService.selectTwinEmpByDate(date);
|
|
|
|
|
|
|
|
List<TwinEmpConfig> configs = empConfigService.selectTwinEmpConfigList(new TwinEmpConfig());
|
|
List<TwinEmpConfig> configs = empConfigService.selectTwinEmpConfigList(new TwinEmpConfig());
|
|
|
Map<BigDecimal, BigDecimal> configMap = configs.stream().collect(Collectors.toMap(o -> o.getDensity().setScale(2, RoundingMode.HALF_UP), TwinEmpConfig::getPrice));
|
|
Map<BigDecimal, BigDecimal> configMap = configs.stream().collect(Collectors.toMap(o -> o.getDensity().setScale(2, RoundingMode.HALF_UP), TwinEmpConfig::getPrice));
|
|
|
|
|
|
|
|
- List<TwinEmpCalc> calcList = new ArrayList<>();
|
|
|
|
|
- process(true, emp, calcMap, configMap, calcList, specHourMap);
|
|
|
|
|
- process(false, emp, calcMap, configMap, calcList, specHourMap);
|
|
|
|
|
|
|
+// List<TwinEmpCalc> calcList = new ArrayList<>();
|
|
|
|
|
+// process(true, emp, calcMap, configMap, calcList, specHourMap);
|
|
|
|
|
+// process(false, emp, calcMap, configMap, calcList, specHourMap);
|
|
|
|
|
+ List<TwinEmpCalc> calcList = process(emp, effMap, configMap, specHourList);
|
|
|
if (calcList.size() > 0) {
|
|
if (calcList.size() > 0) {
|
|
|
try (SqlSession sqlSession = factory.openSession(ExecutorType.BATCH, false)) {
|
|
try (SqlSession sqlSession = factory.openSession(ExecutorType.BATCH, false)) {
|
|
|
TwinEmpCalcMapper mapper = sqlSession.getMapper(TwinEmpCalcMapper.class);
|
|
TwinEmpCalcMapper mapper = sqlSession.getMapper(TwinEmpCalcMapper.class);
|
|
@@ -158,6 +160,7 @@ public class TwinEmpCalcServiceImpl implements ITwinEmpCalcService {
|
|
|
/**
|
|
/**
|
|
|
* @param flag true为A班false为B班
|
|
* @param flag true为A班false为B班
|
|
|
*/
|
|
*/
|
|
|
|
|
+ @Deprecated
|
|
|
private void process(boolean flag, TwinEmp emp, Map<Long, TwinCalcDay> calcMap, Map<BigDecimal, BigDecimal> configMap, List<TwinEmpCalc> calcList, Map<String, List<TwinCalcHourSpec>> specHourMap) {
|
|
private void process(boolean flag, TwinEmp emp, Map<Long, TwinCalcDay> calcMap, Map<BigDecimal, BigDecimal> configMap, List<TwinEmpCalc> calcList, Map<String, List<TwinCalcHourSpec>> specHourMap) {
|
|
|
List<TwinEmpDetail> list = emp.getTwinEmpDetailListA();
|
|
List<TwinEmpDetail> list = emp.getTwinEmpDetailListA();
|
|
|
String team = "A";
|
|
String team = "A";
|
|
@@ -166,7 +169,7 @@ public class TwinEmpCalcServiceImpl implements ITwinEmpCalcService {
|
|
|
list = emp.getTwinEmpDetailListB();
|
|
list = emp.getTwinEmpDetailListB();
|
|
|
}
|
|
}
|
|
|
for (TwinEmpDetail d : list) {
|
|
for (TwinEmpDetail d : list) {
|
|
|
- Long[] devices = getDevices(d.getDevices());
|
|
|
|
|
|
|
+ Long[] devices = Tools.parseDevices(d.getDevices());
|
|
|
for (int i = 0; i < devices.length; i++) {
|
|
for (int i = 0; i < devices.length; i++) {
|
|
|
Long deviceId = devices[i];
|
|
Long deviceId = devices[i];
|
|
|
List<TwinCalcHourSpec> specs = specHourMap.get(deviceId + "-" + team);
|
|
List<TwinCalcHourSpec> specs = specHourMap.get(deviceId + "-" + team);
|
|
@@ -212,24 +215,65 @@ public class TwinEmpCalcServiceImpl implements ITwinEmpCalcService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private Long[] getDevices(String d) {
|
|
|
|
|
- String[] temp = d.split(",");
|
|
|
|
|
- Set<Long> set = new HashSet<>();
|
|
|
|
|
- for (String s : temp) {
|
|
|
|
|
- String[] ss = s.split("-");
|
|
|
|
|
- if (ss.length > 1) {
|
|
|
|
|
- Long st = Long.parseLong(ss[0]);
|
|
|
|
|
- Long ed = Long.parseLong(ss[1]);
|
|
|
|
|
- for (long i = st; i <= ed; i++) {
|
|
|
|
|
- set.add(i);
|
|
|
|
|
|
|
+ private List<TwinEmpCalc> process(TwinEmp emp, Map<Long, BigDecimal> effMap, Map<BigDecimal, BigDecimal> configMap, List<TwinCalcHourSpec> specHourList) {
|
|
|
|
|
+ List<TwinEmpDetail> empList = emp.getTwinEmpDetailList();
|
|
|
|
|
+ List<TwinEmpCalc> resultList = new ArrayList<>();
|
|
|
|
|
+ //按设备ID分组
|
|
|
|
|
+ Map<Long, List<TwinCalcHourSpec>> specHourMap = specHourList.stream().collect(Collectors.groupingBy(TwinCalcHourSpec::getDeviceId, LinkedHashMap::new, Collectors.toList()));
|
|
|
|
|
+ for (TwinEmpDetail d : empList) {
|
|
|
|
|
+ Long[] devices = Tools.parseDevices(d.getDevices());
|
|
|
|
|
+ int startHour = DateUtils.toLocalDateTime(d.getInTime()).getHour();
|
|
|
|
|
+ int endHour = DateUtils.toLocalDateTime(d.getOutTime()).getHour();
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < devices.length; i++) {
|
|
|
|
|
+ Long deviceId = devices[i];
|
|
|
|
|
+ List<TwinCalcHourSpec> specs = specHourMap.get(deviceId);
|
|
|
|
|
+ if (specs == null || specs.size() == 0) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<TwinCalcHourSpec> hourList = specs.stream().filter(t -> t.getHour() >= startHour && t.getHour() < endHour).collect(Collectors.toList());
|
|
|
|
|
+ if (endHour < startHour) {
|
|
|
|
|
+ hourList.addAll(specs.stream().filter(t -> t.getHour() >= startHour || t.getHour() < endHour).collect(Collectors.toList()));
|
|
|
|
|
+ }
|
|
|
|
|
+// for (int h = startHour; h < endHour; h++) {
|
|
|
|
|
+// //上班时间包含当前小时,下班时间不包含当前小时
|
|
|
|
|
+// int hour = h;
|
|
|
|
|
+// List<TwinCalcHourSpec> hourList = specs.stream().filter(t -> t.getHour() == hour).collect(Collectors.toList());
|
|
|
|
|
+// }
|
|
|
|
|
+ //按密度和米克重、毛高分组统计
|
|
|
|
|
+ Map<String, BigDecimal> resultMap = hourList.stream().collect(Collectors.groupingBy(t -> t.getDensity() + "-" + t.getMick() + "-" + t.getHeight(), Collectors.reducing(BigDecimal.ZERO, TwinCalcHourSpec::getLength, BigDecimal::add)));
|
|
|
|
|
+ for (String ss : resultMap.keySet()) {
|
|
|
|
|
+ String[] temp = ss.split("-");
|
|
|
|
|
+ BigDecimal density = new BigDecimal(temp[0]).setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
+ Integer mick = Integer.parseInt(temp[1]);
|
|
|
|
|
+ TwinEmpCalc calc = new TwinEmpCalc();
|
|
|
|
|
+ calc.setDeviceId(deviceId);
|
|
|
|
|
+ if (StringUtils.isNotEmpty(temp[2]) && !"null".equals(temp[2])) {
|
|
|
|
|
+ BigDecimal height = new BigDecimal(temp[2]).setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
+ calc.setHeight(height);
|
|
|
|
|
+ }
|
|
|
|
|
+ calc.setEfficiency(effMap.get(deviceId));
|
|
|
|
|
+ calc.setEmpDate(emp.getEmpDate());
|
|
|
|
|
+ BigDecimal length = resultMap.get(ss);
|
|
|
|
|
+ if (length.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ calc.setLength(length);
|
|
|
|
|
+ calc.setEmpTeam(d.getEmpTeam());
|
|
|
|
|
+ calc.setEmpName(d.getEmpName());
|
|
|
|
|
+ calc.setMick(mick);
|
|
|
|
|
+ calc.setDensity(density);
|
|
|
|
|
+ BigDecimal price = configMap.get(Tools.density(density));
|
|
|
|
|
+ calc.setPrice(price);
|
|
|
|
|
+ if (price != null) {
|
|
|
|
|
+ BigDecimal total = length.multiply(price);
|
|
|
|
|
+ calc.setTotalPrice(total);
|
|
|
|
|
+ }
|
|
|
|
|
+ resultList.add(calc);
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- set.add(Long.parseLong(s));
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- Long[] devices = new Long[set.size()];
|
|
|
|
|
- set.toArray(devices);
|
|
|
|
|
- return devices;
|
|
|
|
|
|
|
+ return resultList;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|