|
|
|
|
@ -12,8 +12,11 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.time.LocalTime;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.iot.controller.admin.deviceoperationrecord.vo.*;
|
|
|
|
|
import cn.iocoder.yudao.module.iot.dal.dataobject.deviceoperationrecord.DeviceOperationRecordDO;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
|
|
@ -95,6 +98,65 @@ public class DeviceOperationRecordServiceImpl implements DeviceOperationRecordSe
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<DeviceTotalTimeRecordRespVO> deviceOperationList(DeviceTotalTimeRecordReqVO deviceTotalTimeRecordReqVO) {
|
|
|
|
|
|
|
|
|
|
// 1 查询产线设备
|
|
|
|
|
List<DeviceTotalTimeRecordRespVO> lineList = deviceOperationRecordMapper.selectLine();
|
|
|
|
|
|
|
|
|
|
// 2 提取 deviceId
|
|
|
|
|
String ids = lineList.stream()
|
|
|
|
|
.map(DeviceTotalTimeRecordRespVO::getId)
|
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
.distinct()
|
|
|
|
|
.map(String::valueOf)
|
|
|
|
|
.collect(Collectors.joining(","));
|
|
|
|
|
|
|
|
|
|
// 3 设置时间
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
deviceTotalTimeRecordReqVO.setStartTime(LocalDateTime.now().with(LocalTime.MIN).format(formatter));
|
|
|
|
|
deviceTotalTimeRecordReqVO.setEndTime(LocalDateTime.now().format(formatter));
|
|
|
|
|
deviceTotalTimeRecordReqVO.setIds(ids);
|
|
|
|
|
|
|
|
|
|
// 4 查询统计数据
|
|
|
|
|
List<DeviceTotalTimeRecordRespVO> list =
|
|
|
|
|
deviceOperationRecordMapper.deviceOperationList(deviceTotalTimeRecordReqVO);
|
|
|
|
|
|
|
|
|
|
if (list != null && !list.isEmpty()) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 5 计算转换
|
|
|
|
|
calculateAndSetConvertedValues(list, deviceTotalTimeRecordReqVO);
|
|
|
|
|
|
|
|
|
|
// 6 转成 map (deviceId -> 统计数据)
|
|
|
|
|
Map<Long, DeviceTotalTimeRecordRespVO> recordMap =
|
|
|
|
|
list.stream().collect(Collectors.toMap(
|
|
|
|
|
DeviceTotalTimeRecordRespVO::getId,
|
|
|
|
|
v -> v,
|
|
|
|
|
(a, b) -> a
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
// 7 回填到 lineList
|
|
|
|
|
for (DeviceTotalTimeRecordRespVO line : lineList) {
|
|
|
|
|
|
|
|
|
|
DeviceTotalTimeRecordRespVO record = recordMap.get(line.getId());
|
|
|
|
|
|
|
|
|
|
if (record != null) {
|
|
|
|
|
line.setTotalOfflineTime(record.getTotalOfflineTime());
|
|
|
|
|
line.setTotalRunningTime(record.getTotalRunningTime());
|
|
|
|
|
line.setTotalStandbyTime(record.getTotalStandbyTime());
|
|
|
|
|
line.setTotalFaultTime(record.getTotalFaultTime());
|
|
|
|
|
line.setPowerOnRate(record.getPowerOnRate());
|
|
|
|
|
line.setUtilizationRate(record.getUtilizationRate());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 8 返回产线设备
|
|
|
|
|
return lineList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void calculateAndSetConvertedValues(
|
|
|
|
|
List<DeviceTotalTimeRecordRespVO> records,
|
|
|
|
|
DeviceTotalTimeRecordReqVO reqVO) {
|
|
|
|
|
|