3 changed files with 109 additions and 0 deletions
@ -0,0 +1,23 @@
|
||||
package com.mh.user.service; |
||||
|
||||
import com.mh.user.dto.DataResultDTO; |
||||
import com.mh.user.entity.DataResultChEntity; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project mh_esi |
||||
* @description 处理数据异常 |
||||
* @date 2025-01-17 09:41:48 |
||||
*/ |
||||
public interface DealDataExceptionService { |
||||
|
||||
// 处理15分钟异常的数据
|
||||
void dealFifteenInstantaneousExceptionData(List<DataResultDTO> mergedRecords); |
||||
|
||||
// 处理5分钟异常的数据
|
||||
void dealFiveInstantaneousExceptionData(List<DataResultChEntity> records); |
||||
|
||||
} |
@ -0,0 +1,81 @@
|
||||
package com.mh.user.service.impl; |
||||
|
||||
import com.mh.user.dto.DataResultDTO; |
||||
import com.mh.user.entity.DataResultChEntity; |
||||
import com.mh.user.mapper.chillers.DealDataMapper; |
||||
import com.mh.user.service.DealDataExceptionService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.math.BigDecimal; |
||||
import java.time.LocalDateTime; |
||||
import java.time.format.DateTimeFormatter; |
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project mh_esi |
||||
* @description 处理异常数据 |
||||
* @date 2025-01-17 09:47:03 |
||||
*/ |
||||
@Slf4j |
||||
@Service |
||||
public class DealDataExceptionServiceImpl implements DealDataExceptionService { |
||||
|
||||
@Resource |
||||
private DealDataMapper dealDataMapper; |
||||
|
||||
private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
||||
|
||||
|
||||
@Override |
||||
public void dealFifteenInstantaneousExceptionData(List<DataResultDTO> mergedRecords) { |
||||
new Thread(() -> { |
||||
try { |
||||
// 判断当前集合momentCooling,intTemp,outTemp存在小于0的数据少于10就要重新计算
|
||||
// stream流判断momentCooling的集合中数据小于等于0的数据集合
|
||||
List<DataResultDTO> momentCoolingList = mergedRecords.stream().filter(dataResultDTO -> { |
||||
BigDecimal momentCooling = new BigDecimal(dataResultDTO.getMomentCooling()); |
||||
return momentCooling.compareTo(BigDecimal.ZERO) <= 0; |
||||
}).collect(Collectors.toList()); |
||||
if (momentCoolingList.size() <= 10 && !momentCoolingList.isEmpty()) { |
||||
// 重新计算momentCooling的值
|
||||
for (DataResultDTO dataResultDTO : momentCoolingList) { |
||||
// 将字符串转换为 LocalDateTime
|
||||
LocalDateTime localDateTime = LocalDateTime.parse(dataResultDTO.getTime(), formatter); |
||||
for (int i = 0; i < 5; i++) { |
||||
dealDataMapper.proDataResult(localDateTime.format(formatter), dataResultDTO.getProjectId()); |
||||
localDateTime = localDateTime.plusMinutes(1); |
||||
} |
||||
} |
||||
} |
||||
|
||||
// stream流判断intTemp,outTemp的集合中数据小于等于0的数据集合
|
||||
List<DataResultDTO> intTempList = mergedRecords.stream().filter(dataResultDTO -> { |
||||
BigDecimal intTemp = new BigDecimal(dataResultDTO.getIntTemp()); |
||||
return intTemp.compareTo(BigDecimal.ZERO) <= 0; |
||||
}).collect(Collectors.toList()); |
||||
if (intTempList.size() <= 10 && !intTempList.isEmpty()) { |
||||
// 重新计算intTemp,outTemp的值
|
||||
for (DataResultDTO dataResultDTO : intTempList) { |
||||
// 将字符串转换为 LocalDateTime
|
||||
LocalDateTime localDateTime = LocalDateTime.parse(dataResultDTO.getTime(), formatter); |
||||
for (int i = 0; i < 5; i++) { |
||||
dealDataMapper.proDataResult(localDateTime.format(formatter), dataResultDTO.getProjectId()); |
||||
localDateTime = localDateTime.plusMinutes(1); |
||||
} |
||||
} |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("处理十五分钟异常数据失败", e); |
||||
} |
||||
}).start(); |
||||
} |
||||
|
||||
@Override |
||||
public void dealFiveInstantaneousExceptionData(List<DataResultChEntity> records) { |
||||
} |
||||
} |
Loading…
Reference in new issue