yangys
2024-04-04 ed4a5236bab800094be4a8378f5098eebe3de6ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
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<SuperAggregateState> 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<SuperAggregateState> superAggregateStates, ProductivityTypeEnum productivityTypeEnum) {
        ChartNameValueDataVO vo = new ChartNameValueDataVO();
        Map<Long, List<SuperAggregateState>> collect = superAggregateStates.stream().collect(Collectors.groupingBy((v0) -> {
            return v0.getWorkstationId();
        }));
        AtomicReference<Double> 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<Workstation> workstations, List<SuperAggregateState> superAggregateStateList) {
        Map<Long, List<SuperAggregateState>> map = new HashMap<>(32);
        if (Func.isNotEmpty(superAggregateStateList)) {
            map = superAggregateStateList.stream().collect(Collectors.groupingBy((v0) -> {
                return v0.getWorkstationId();
            }));
        }
        ChartGanttStatusDataVO chartGanttStatusDataVO = new ChartGanttStatusDataVO();
        List<SeriesItem<GanttStatusVO>> series = new ArrayList<>();
        List<ChartGanttStatusDataVO.ColorStatus> 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<SuperAggregateState> superAggregateStates = map.getOrDefault(workstation.getId(), new ArrayList<>());
            List<GanttStatusVO> 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<SuperAggregateState> data) {
        ChartNameValueDataVO vo = new ChartNameValueDataVO();
        List<GlobalWcs> defaultWcs = WorkstationCache.getDefaultWcs();
        Map<Integer, GlobalWcs> wcsMap =  defaultWcs.stream().collect(Collectors.toMap(k -> {
            return Integer.valueOf(Integer.parseInt(k.getCode()));
        }, v -> {
            return v;
        }));
        Map<Integer, Long> 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<Integer, Long> 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<SuperAggregateState> data) {
        List<SuperAggregateState> 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<SuperAggregateState> data) {
        List<SuperAggregateState> 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<SuperAggregateState> data) {
        List<SuperAggregateState> 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<SuperAggregateState> statusByCondition, ProductivityTypeEnum productivityTypeEnum, Integer top, List<Workstation> workstations, String name) {
        Map<Long, Workstation> workstationMap =  workstations.stream().collect(Collectors.toMap((v0) -> {
            return v0.getId();
        }, Function.identity()));
        Map<Long, List<SuperAggregateState>> collect =  statusByCondition.stream().collect(Collectors.groupingBy((v0) -> {
            return v0.getWorkstationId();
        }));
        Map<Long, Double> 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<Long, Double> 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<Object> data = new ArrayList<>();
        SeriesItem seriesItem = new SeriesItem();
        seriesItem.setName(name);
        List<Workstation> 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<StatusTimeTopVO> 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<SuperAggregateState> superAggregateStates, List<Workstation> workstations, ProductivityTypeEnum productivityTypeEnum) {
        ChartNameValueDataVO vo = new ChartNameValueDataVO();
        Map<Long, String> workstationIdToName = workstations.stream().collect(Collectors.toMap((v0) -> {
            return v0.getId();
        }, (v0) -> {
            return v0.getName();
        }));
        Map<Long, List<SuperAggregateState>> 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;
    }
}