| | |
| | | package org.dromara.eims.service.impl; |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.dromara.common.core.utils.DateUtils; |
| | | import org.dromara.common.core.utils.StringUtils; |
| | | import org.dromara.common.mybatis.core.page.PageQuery; |
| | | import org.dromara.common.mybatis.core.page.TableDataInfo; |
| | |
| | | order -> String.valueOf(order.getPlanTime().toInstant() |
| | | .atZone(ZoneId.systemDefault()) |
| | | .toLocalDate().getMonthValue()), |
| | | // 按月份分组后,判断该月是否全部status=3 |
| | | Collectors.collectingAndThen( |
| | | Collectors.toList(), |
| | | orders -> orders.stream().allMatch(o -> o.getStatus().equals("3")) |
| | | ? "已完成" |
| | | : "未完成" |
| | | orders -> { |
| | | boolean allZero = orders.stream().allMatch(o -> o.getStatus().equals("0")); |
| | | if (allZero) { |
| | | return MAINT_0; // 待保养 |
| | | } |
| | | boolean allGtOne = orders.stream().allMatch(o -> Integer.parseInt(o.getStatus()) > 1); |
| | | if (allGtOne) { |
| | | return MAINT_2; // 待验证 |
| | | } |
| | | boolean allGtTwo = orders.stream().allMatch(o -> Integer.parseInt(o.getStatus()) > 2); |
| | | if (allGtTwo) { |
| | | return MAINT_3; // 已完成 |
| | | } |
| | | return "保养中"; |
| | | } |
| | | ) |
| | | )); |
| | | Map<String, EimsMaintPlan> planMap = equMaintPlanList.stream() |
| | |
| | | for (int month = 1; month <= monthInYear; month++) { |
| | | String monthKey = "month_" + month; |
| | | if (planMap.containsKey(String.valueOf(month))) { |
| | | item.put(monthKey, UNCHECKED); |
| | | item.put(monthKey, MAINT_0); |
| | | } else if (orderMap.containsKey(String.valueOf(month))) { |
| | | String result = orderMap.get(String.valueOf(month)); |
| | | item.put(monthKey, result); |
| | |
| | | |
| | | return item; |
| | | } |
| | | |
| | | @Override |
| | | public TableDataInfo<Map<String, Object>> queryEquEfficiencyList(Map<String, Object> queryParams, PageQuery pageQuery) { |
| | | Integer selectYear = getYearFromParams(queryParams); |
| | | String start = Year.of(selectYear).atDay(1).toString(); // yyyy-MM-dd |
| | | String end = Year.of(selectYear).atDay(Year.of(selectYear).length()).toString(); |
| | | |
| | | List<Map<String, Object>> statList = inspectStMapper.statEquEfficiency(start, end); |
| | | |
| | | // 组装统计结果 |
| | | Map<Integer, Integer> runTimes = new HashMap<>(); |
| | | Map<Integer, Integer> faultTimes = new HashMap<>(); |
| | | Map<Integer, Integer> totalTimes = new HashMap<>(); |
| | | int runTotal = 0, faultTotal = 0, totalTotal = 0; |
| | | |
| | | for (Map<String, Object> row : statList) { |
| | | int month = Integer.parseInt(row.get("month").toString()); |
| | | int run = row.get("runTimes") == null ? 0 : Integer.parseInt(row.get("runTimes").toString()); |
| | | int fault = row.get("faultTimes") == null ? 0 : Integer.parseInt(row.get("faultTimes").toString()); |
| | | int total = run + fault; |
| | | runTimes.put(month, run); |
| | | faultTimes.put(month, fault); |
| | | totalTimes.put(month, total); |
| | | runTotal += run; |
| | | faultTotal += fault; |
| | | totalTotal += total; |
| | | } |
| | | |
| | | // 组装返回数据(同前) |
| | | String targetValue = "98.00%"; |
| | | List<Map<String, Object>> resultList = new ArrayList<>(); |
| | | Map<String, Object> row1 = new LinkedHashMap<>(); // 正常运转时间 |
| | | Map<String, Object> row2 = new LinkedHashMap<>(); // 总运转时间 |
| | | Map<String, Object> row3 = new LinkedHashMap<>(); // 故障时间 |
| | | Map<String, Object> row4 = new LinkedHashMap<>(); // 目标值 |
| | | Map<String, Object> row5 = new LinkedHashMap<>(); // 正常运转率(稼动率) |
| | | |
| | | row1.put("item", "正常运转时间"); |
| | | row2.put("item", "总运转时间"); |
| | | row3.put("item", "故障时间"); |
| | | row4.put("item", "目标值"); |
| | | row5.put("item", "正常运转率(稼动率)"); |
| | | |
| | | for (int m = 1; m <= 12; m++) { |
| | | row1.put(m + "月", runTimes.getOrDefault(m, 0)); |
| | | row2.put(m + "月", totalTimes.getOrDefault(m, 0)); |
| | | row3.put(m + "月", faultTimes.getOrDefault(m, 0)); |
| | | row4.put(m + "月", targetValue); |
| | | int run = runTimes.getOrDefault(m, 0); |
| | | int total = totalTimes.getOrDefault(m, 0); |
| | | String eff = total > 0 ? String.format("%.2f%%", run * 100.0 / total) : "-"; |
| | | row5.put(m + "月", eff); |
| | | } |
| | | row1.put("total", runTotal); |
| | | row2.put("total", totalTotal); |
| | | row3.put("total", faultTotal); |
| | | row4.put("total", targetValue); |
| | | row5.put("total", totalTotal > 0 ? String.format("%.2f%%", runTotal * 100.0 / totalTotal) : "-"); |
| | | |
| | | resultList.add(row1); |
| | | resultList.add(row2); |
| | | resultList.add(row3); |
| | | resultList.add(row4); |
| | | resultList.add(row5); |
| | | |
| | | return TableDataInfo.build(resultList); |
| | | } |
| | | } |