yangbin
2025-02-20 ec077979f2d55b2a54e893085f4b845b729e69c3
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,33 @@
        }
        //上周班次利用率数据
        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));
                    } else {
                        shiftRateList.add(new BigDecimal("0"));
                    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"));
@@ -126,13 +140,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 +307,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;
    }