package com.qianwen.smartman.modules.visual.wrapper; import cn.hutool.core.util.NumberUtil; import com.google.common.collect.Lists; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.qianwen.smartman.common.cache.cps.WorkstationCache; import com.qianwen.smartman.common.constant.ChartNameConstant; import com.qianwen.smartman.common.constant.MdcConstant; import com.qianwen.core.tool.utils.Func; import com.qianwen.smartman.modules.cps.entity.GlobalWcs; import com.qianwen.smartman.modules.cps.entity.Workstation; import com.qianwen.smartman.modules.mdc.entity.SuperAggregateState; import com.qianwen.smartman.modules.mdc.enums.OpenTypeEnums; import com.qianwen.smartman.modules.mdc.enums.ProductivityTypeEnum; import com.qianwen.smartman.modules.mdc.utils.EifficiencyUtils; import com.qianwen.smartman.modules.mdc.utils.FilterOffUtils; import com.qianwen.smartman.modules.mdc.vo.StatusTimeTopVO; import com.qianwen.smartman.modules.system.entity.SeriesItem; import com.qianwen.smartman.modules.system.vo.ChartGanttStatusDataVO; import com.qianwen.smartman.modules.system.vo.ChartNameValueDataVO; import com.qianwen.smartman.modules.system.vo.ChartSeriesDataVO; import com.qianwen.smartman.modules.system.vo.GanttStatusVO; import com.qianwen.smartman.modules.system.vo.WorkstationChartSeriesDataVO; import org.springframework.stereotype.Component; @Component /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/visual/wrapper/StatusWrapper.class */ public class StatusWrapper { private static final Logger log = LoggerFactory.getLogger(StatusWrapper.class); public ChartNameValueDataVO entityToGroupRunning(List superAggregateStates, Integer size) { long sum = superAggregateStates.stream().mapToLong((v0) -> { return v0.getDurationCollect(); }).sum(); String result = sum != 0 ? secondToHour(Double.valueOf((sum * 1.0d) / size.intValue())) : ""; return new ChartNameValueDataVO().addValue(MdcConstant.GROUP_RUNNING, result); } private String secondToHour(Number second) { if (second instanceof Double) { double s = second.doubleValue(); log.info("second:{},s{}", second, Double.valueOf(s)); return NumberUtil.decimalFormat(MdcConstant.NORMAL_FORMAT, s / 3600000.0d); } return ""; } public ChartNameValueDataVO entityToEfficiencyAverageVo(List superAggregateStates, ProductivityTypeEnum productivityTypeEnum) { ChartNameValueDataVO vo = new ChartNameValueDataVO(); Map> collect = superAggregateStates.stream().collect(Collectors.groupingBy((v0) -> { return v0.getWorkstationId(); })); AtomicReference allValue = new AtomicReference<>(Double.valueOf(0.0d)); collect.forEach((workstationId, superAggregateStateList) -> { Double value = EifficiencyUtils.calculationResults(superAggregateStateList, productivityTypeEnum); allValue.updateAndGet(v -> { return Double.valueOf(v.doubleValue() + value.doubleValue()); }); }); double v = BigDecimal.valueOf(allValue.get().doubleValue()).divide(BigDecimal.valueOf(collect.keySet().size()), 4, 4).multiply(BigDecimal.valueOf(100L)).doubleValue(); switch (productivityTypeEnum) { case ALARM: vo.addValue("平均报警率", Double.valueOf(v)); break; case RUNNING: vo.addValue("平均运行率", Double.valueOf(v)); break; default: vo.addValue("平均稼动率", Double.valueOf(v)); break; } return vo; } /* JADX WARN: Multi-variable type inference failed */ public ChartGanttStatusDataVO entityVO(List workstations, List superAggregateStateList) { Map> map = new HashMap<>(32); if (Func.isNotEmpty(superAggregateStateList)) { map = superAggregateStateList.stream().collect(Collectors.groupingBy((v0) -> { return v0.getWorkstationId(); })); } ChartGanttStatusDataVO chartGanttStatusDataVO = new ChartGanttStatusDataVO(); List> series = new ArrayList<>(); List colorStatusList = WorkstationCache.getDefaultWcs().stream().map(globalWcs -> { return new ChartGanttStatusDataVO.ColorStatus(globalWcs.getColor(), Integer.valueOf(globalWcs.getCode()), globalWcs.getName()); }).collect(Collectors.toList()); for (Workstation workstation : workstations) { List superAggregateStates = map.getOrDefault(workstation.getId(), new ArrayList<>()); List list = superAggregateStates.stream().map(superAggregateState -> { return GanttStatusVO.builder().startTime(superAggregateState.getStartTime()).endTime(superAggregateState.getEndTime()).status(superAggregateState.getWcs()).build(); }).collect(Collectors.toList()); SeriesItem seriesItem = new SeriesItem(workstation.getName(), list); series.add(seriesItem); } chartGanttStatusDataVO.setColorStatusInfo(colorStatusList); chartGanttStatusDataVO.setSeries(series); return chartGanttStatusDataVO; } public ChartNameValueDataVO entityToChartName(List data) { ChartNameValueDataVO vo = new ChartNameValueDataVO(); List defaultWcs = WorkstationCache.getDefaultWcs(); Map wcsMap = defaultWcs.stream().collect(Collectors.toMap(k -> { return Integer.valueOf(Integer.parseInt(k.getCode())); }, v -> { return v; })); Map durationMap = data.stream().filter(c -> { return wcsMap.containsKey(c.getValueCollect()); }).collect(Collectors.groupingBy((v0) -> { return v0.getWcs(); }, Collectors.summingLong((v0) -> { return v0.getDurationCollect(); }))); double sum = durationMap.values().stream().mapToDouble(c2 -> { return c2.longValue(); }).sum(); for (Map.Entry entry : durationMap.entrySet()) { double result = !new Double(sum).equals(Double.valueOf(0.0d)) ? Double.parseDouble(NumberUtil.decimalFormat(MdcConstant.NORMAL_FORMAT, (entry.getValue().longValue() / sum) * 100.0d)) : 0.0d; vo.addValue(wcsMap.get(entry.getKey()).getName(), Double.valueOf(result), "", wcsMap.get(entry.getKey()).getColor()); } return vo; } public ChartNameValueDataVO entityToOee(List data) { List data2 = FilterOffUtils.filterOffDay(data, OpenTypeEnums.OEE); ChartNameValueDataVO vo = new ChartNameValueDataVO(); Double oee = EifficiencyUtils.calculationOee(data2); vo.addValue(MdcConstant.OEE_NAME, NumberUtil.decimalFormat(MdcConstant.NORMAL_FORMAT, oee.doubleValue() * 100.0d)); return vo; } public ChartNameValueDataVO entityToMonthOee(List data) { List data2 = FilterOffUtils.filterOffDay(data, OpenTypeEnums.OEE); ChartNameValueDataVO vo = new ChartNameValueDataVO(); Double oee = EifficiencyUtils.calculationOee(data2); vo.addValue(MdcConstant.MONTH_OEE_NAME, NumberUtil.decimalFormat(MdcConstant.NORMAL_FORMAT, oee.doubleValue() * 100.0d)); return vo; } public ChartNameValueDataVO entityToMonthRunning(List data) { List data2 = FilterOffUtils.filterOffDay(data, OpenTypeEnums.RUNNING); ChartNameValueDataVO vo = new ChartNameValueDataVO(); Double oee = EifficiencyUtils.calculationRunning(data2); vo.addValue(MdcConstant.MONTH_RUNNING_NAME, NumberUtil.decimalFormat(MdcConstant.NORMAL_FORMAT, oee.doubleValue() * 100.0d)); return vo; } public ChartSeriesDataVO entityToEfficiencyTopVo(List statusByCondition, ProductivityTypeEnum productivityTypeEnum, Integer top, List workstations, String name) { Map workstationMap = workstations.stream().collect(Collectors.toMap((v0) -> { return v0.getId(); }, Function.identity())); Map> collect = statusByCondition.stream().collect(Collectors.groupingBy((v0) -> { return v0.getWorkstationId(); })); Map idToValue = new HashMap<>(); collect.forEach((workstationId, statusByConditionList) -> { Double value = EifficiencyUtils.calculationResults(statusByConditionList, productivityTypeEnum); double v = BigDecimal.valueOf(value.doubleValue()).multiply(BigDecimal.valueOf(100L)).doubleValue(); idToValue.put(workstationId, Double.valueOf(v)); }); LinkedHashMap collectSorted = idToValue.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).limit(top.intValue()).collect(Collectors.toMap((v0) -> { return v0.getKey(); }, (v0) -> { return v0.getValue(); }, (oldValue, newValue) -> { return oldValue; }, LinkedHashMap::new)); WorkstationChartSeriesDataVO chartSeriesDataVO = new WorkstationChartSeriesDataVO(); ArrayList data = new ArrayList<>(); SeriesItem seriesItem = new SeriesItem(); seriesItem.setName(name); List categories = new ArrayList<>(); collectSorted.forEach((workstationId2, value) -> { data.add(value); categories.add(workstationMap.get(workstationId2)); }); seriesItem.setData(data); chartSeriesDataVO.setSeries(Lists.newArrayList(new SeriesItem[]{seriesItem})); chartSeriesDataVO.generateCategories(categories); return chartSeriesDataVO; } public ChartSeriesDataVO deviceStatusDuration(List statusTimeByWcs, Integer status, Integer top) { WorkstationChartSeriesDataVO chartSeriesDataVO = new WorkstationChartSeriesDataVO(); ArrayList arrayList = new ArrayList(); ArrayList arrayList2 = new ArrayList(); if (Func.isNotEmpty(statusTimeByWcs)) { SeriesItem seriesItem = new SeriesItem(); if (ChartNameConstant.DEVICE_RUN_STATUS.equals(status)) { seriesItem.setName(ChartNameConstant.DEVICE_RUN_DURATION + top); } if (ChartNameConstant.DEVICE_WAIT_STATUS.equals(status)) { seriesItem.setName(ChartNameConstant.DEVICE_WAIT_DURATION + top); } statusTimeByWcs.forEach(s -> { arrayList2.add(s.getValue()); }); seriesItem.setData(arrayList2); arrayList.add(seriesItem); } chartSeriesDataVO.generateCategories((List) statusTimeByWcs.stream().map((v0) -> { return v0.getWorkstation(); }).collect(Collectors.toList())); chartSeriesDataVO.setSeries(arrayList); return chartSeriesDataVO; } public ChartNameValueDataVO entityToEfficiencyTodayVo(List superAggregateStates, List workstations, ProductivityTypeEnum productivityTypeEnum) { ChartNameValueDataVO vo = new ChartNameValueDataVO(); Map workstationIdToName = workstations.stream().collect(Collectors.toMap((v0) -> { return v0.getId(); }, (v0) -> { return v0.getName(); })); Map> collect = superAggregateStates.stream().collect(Collectors.groupingBy((v0) -> { return v0.getWorkstationId(); })); collect.forEach((workstationId, superAggregateStateList) -> { Double value = EifficiencyUtils.calculationResults(superAggregateStateList, productivityTypeEnum); vo.addValue((String) workstationIdToName.get(workstationId), value); }); return vo; } }