From ade808e926b4ac0284756ee62d5f3fa90aabe814 Mon Sep 17 00:00:00 2001 From: yangbin <yangbin@qq.com> Date: 星期四, 20 二月 2025 15:13:40 +0800 Subject: [PATCH] 大屏看板3 --- lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/subcontrol/service/impl/MdcBigScreenServiceImpl.java | 58 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 44 insertions(+), 14 deletions(-) diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/subcontrol/service/impl/MdcBigScreenServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/subcontrol/service/impl/MdcBigScreenServiceImpl.java index 376bd55..0ace697 100644 --- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/subcontrol/service/impl/MdcBigScreenServiceImpl.java +++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/subcontrol/service/impl/MdcBigScreenServiceImpl.java @@ -1,17 +1,20 @@ package org.jeecg.modules.mdc.subcontrol.service.impl; import org.apache.commons.lang.StringUtils; +import org.checkerframework.checker.units.qual.A; import org.jeecg.modules.mdc.entity.EquipmentLog; import org.jeecg.modules.mdc.service.*; import org.jeecg.modules.mdc.subcontrol.service.MdcBigScreenService; import org.jeecg.modules.mdc.subcontrol.vo.LastWeekDataRankingVo; import org.jeecg.modules.mdc.subcontrol.vo.LastWeekDataVo; import org.jeecg.modules.mdc.subcontrol.vo.MdcEquipmentOpVo; +import org.jeecg.modules.mdc.util.DateUtils; import org.jeecg.modules.mdc.vo.MdcEquipmentVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import javax.xml.crypto.Data; import java.math.BigDecimal; import java.time.DayOfWeek; import java.time.LocalDate; @@ -34,6 +37,8 @@ private IEquipmentStatisticalInfoService equipmentStatisticalInfoService; @Autowired private IMdcEquipmentStatisticalShiftInfoService mdcEquipmentStatisticalShiftInfoService; + @Autowired + private IMdcEquipmentStatisticalInfoService mdcEquipmentStatisticalInfoService; @Resource @@ -50,9 +55,9 @@ List<BigDecimal> processingRateList = new ArrayList<>(); List<BigDecimal> shiftRateList = new ArrayList<>(); //鑾峰彇涓婂懆鍛ㄤ竴鏃ユ湡鍜屽懆鍏棩鏈� - LocalDate today = LocalDate.now(); - LocalDate monday = today.minusDays(7); - LocalDate saturday = today.minusDays(1); + LocalDate today = LocalDate.now().minusDays(7L); + LocalDate monday = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)); + LocalDate saturday = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SATURDAY)); List<String> dates = getMiddleDate(monday, saturday); List<String> equipmentIdList = new ArrayList<>(); //鏍规嵁鍘傚尯id鑾峰彇鍘傚尯璁惧淇℃伅 @@ -78,24 +83,35 @@ } //涓婂懆鐝鍒╃敤鐜囨暟鎹� - List<LastWeekDataVo> lastWeekDataList = mdcEquipmentStatisticalShiftInfoService.findDataForBigScreen(equipmentIdList, monday.toString(), saturday.toString()); + List<LastWeekDataVo> lastWeekDataList = mdcEquipmentStatisticalShiftInfoService. + findDataForBigScreen(equipmentIdList, monday.toString(), saturday.toString()); List<String> middleDates = getMiddleDates(monday, saturday); + if (lastWeekDataList.isEmpty()) { for (int i = 0; i < middleDates.size(); i++) { shiftRateList.add(new BigDecimal("0")); } } else { + Map<String,LastWeekDataVo> map = new HashMap<>(); + for (LastWeekDataVo s : lastWeekDataList) { + map.put(s.getTheDate(),s); + } for (int i = 0; i < middleDates.size(); i++) { if (i < lastWeekDataList.size()) { - if (middleDates.get(i).equals(lastWeekDataList.get(i).getTheDate()) - && !"0".equals(lastWeekDataList.get(i).getTotalLong())) { - shiftRateList.add(new BigDecimal(lastWeekDataList.get(i).getProcessingLong()). - divide(new BigDecimal(lastWeekDataList.get(i).getTotalLong()), - 6, BigDecimal.ROUND_HALF_UP) - .setScale(6, BigDecimal.ROUND_HALF_UP)); + if ( map.containsKey(middleDates.get(i))) { + LastWeekDataVo vo = map.get(middleDates.get(i)); + if (!"0".equals(vo.getTotalLong())) { + shiftRateList.add(new BigDecimal(vo.getProcessingLong()). + divide(new BigDecimal(vo.getTotalLong()), + 4, BigDecimal.ROUND_HALF_UP) + .setScale(4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100))); + } else { + shiftRateList.add(new BigDecimal("0")); + } } else { shiftRateList.add(new BigDecimal("0")); } + } else { shiftRateList.add(new BigDecimal("0")); @@ -126,13 +142,26 @@ List<LastWeekDataVo> lastWeekDataVos = equipmentStatisticalInfoService.findDataRankingForBigScreen(equipmentIdList, monday, saturday); if (!lastWeekDataVos.isEmpty()) { for (LastWeekDataVo lastWeekDataVo : lastWeekDataVos) { - Long size = equipmentStatisticalInfoService.selectSize(lastWeekDataVo.getEquipment(), monday, saturday); - lastWeekDataVo.setUtilization(new BigDecimal(String.format("%.2f", (Float.parseFloat(lastWeekDataVo.getProcessingLong()) / (86400 * size) * 100)))); + Long size = mdcEquipmentStatisticalInfoService.selectSize(lastWeekDataVo.getEquipment(), monday, saturday); + if (StringUtils.isNotEmpty(lastWeekDataVo.getProcessingLong()) && Float.parseFloat(lastWeekDataVo.getProcessingLong()) >0) { + lastWeekDataVo.setUtilization(new BigDecimal(String.format("%.2f", + (Float.parseFloat(lastWeekDataVo.getProcessingLong()) / (86400 * size) * 100)))); + } else { + lastWeekDataVo.setUtilization(new BigDecimal(0)); + } + } List<LastWeekDataVo> collect = lastWeekDataVos.stream().sorted(Comparator.comparing(LastWeekDataVo::getUtilization).reversed()).collect(Collectors.toList()); - if (collect.size() > 3) { + if (collect.size() > 6) { List<LastWeekDataVo> topList = collect.subList(0, 6); for (LastWeekDataVo vo : topList) { + LastWeekDataRankingVo rankingVo = new LastWeekDataRankingVo(); + rankingVo.setTopName(vo.getEquipment()); + rankingVo.setTopRate(vo.getUtilization().toString()); + voList.add(rankingVo); + } + } else { + for (LastWeekDataVo vo : collect) { LastWeekDataRankingVo rankingVo = new LastWeekDataRankingVo(); rankingVo.setTopName(vo.getEquipment()); rankingVo.setTopRate(vo.getUtilization().toString()); @@ -280,7 +309,8 @@ List<String> localDateList = new ArrayList<>(); long length = end.toEpochDay() - begin.toEpochDay(); for (long i = length; i >= 0; i--) { - localDateList.add(end.minusDays(i).toString()); + String date = end.minusDays(i).toString().replace("-",""); + localDateList.add(date); } return localDateList; } -- Gitblit v1.9.3