yangys
2024-09-27 26f8e5990686bdba2119024a260d986266506757
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
package com.qianwen.mdc.collect.utils;
 
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import com.qianwen.core.tool.utils.BeanUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.mdc.collect.entity.iotdb.AggregateStateWithFeedback;
import com.qianwen.mdc.collect.entity.iotdb.DeviceState;
import com.qianwen.mdc.collect.enums.FeedbackTimePointEnum;
 
public class WorkstationStateAggregateCancelFeedbackUtils {
    private static List<DeviceState> rebuildNotSyncWorkstationStates(List<DeviceState> originalWorkstationStates) {
        List<DeviceState> stateList = new ArrayList<>();
        if (Func.isNotEmpty(originalWorkstationStates)) {
            List<DeviceState> notSyncWorkstationStates = originalWorkstationStates.stream().sorted(Comparator.comparing(DeviceState::getTime)).collect(Collectors.toList());
            
            notSyncWorkstationStates.forEach(x -> {
                if (x.getIsFixPoint().booleanValue() && FeedbackTimePointEnum.NO_FEED_BACK_POINT.isEqual(x.getFeedbackPointType())) {
                    List<DeviceState> collect = notSyncWorkstationStates.stream().filter(y -> {
                        return !y.getIsFixPoint().booleanValue() && y.getTime().longValue() <= x.getTime().longValue();
                    }).collect(Collectors.toList());
                    if (Func.isNotEmpty(collect)) {
                        DeviceState temp = BeanUtil.copy(x, DeviceState.class);
                        temp.setValueCollect(collect.get(collect.size() - 1).getValueCollect());
                        temp.setWcs(collect.get(collect.size() - 1).getWcs());
                        temp.setRps(collect.get(collect.size() - 1).getRps());
                        temp.setIsPlan(collect.get(collect.size() - 1).getIsPlan());
                        stateList.add(temp);
                        return;
                    }
                    stateList.add(x);
                    return;
                }
                stateList.add(x);
            });
        }
        return stateList;
    }
 
    public static List<AggregateStateWithFeedback> buildAggregateList(List<DeviceState> notSyncWorkstationStates, DeviceState preStartState) {
        List<AggregateStateWithFeedback> workstationAggregateStateList = new ArrayList<>();
        List<DeviceState> notSyncWorkstationStates2 = rebuildNotSyncWorkstationStates(notSyncWorkstationStates);
        if (Func.isNotEmpty(notSyncWorkstationStates2)) {
            notSyncWorkstationStates2.size();
            for (int i = 0; i < notSyncWorkstationStates2.size() - 1; i++) {
                DeviceState current = notSyncWorkstationStates2.get(i);
                DeviceState nextState = notSyncWorkstationStates2.get(i + 1);
                if (i == 0) {
                    if (Func.isNotEmpty(preStartState)) {
                        current.setValueCollect(preStartState.getValueCollect());
                        current.setWcs(preStartState.getWcs());
                        current.setRps(preStartState.getRps());
                        current.setIsPlan(preStartState.getIsPlan());
                    } else {
                        current.setValueCollect(0);
                        current.setWcs(0);
                        current.setRps(0);
                        current.setIsPlan(0);
                    }
                }
                workstationAggregateStateList.add(AggregateStateWithFeedback.builder().time(current.getTime()).workstationId(current.getWorkstationId()).isDeleted(false).feedbackId(current.getFeedbackId()).valueCollect(current.getValueCollect()).rps(current.getRps()).wcs(current.getWcs()).isPlan(current.getIsPlan()).shiftIndex(current.getShiftIndex()).shiftTimeType(current.getShiftTimeType()).calendarCode(current.getCalendarCode()).factoryDate(current.getFactoryDate()).factoryMonth(current.getFactoryMonth()).factoryWeek(current.getFactoryWeek()).factoryYear(current.getFactoryYear()).durationCollect(TimeUnit.MILLISECONDS.toSeconds(nextState.getTime() - current.getTime())).endTime(nextState.getTime()).build());
            }
        }
        return workstationAggregateStateList;
    }
}