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;
|
}
|
}
|