Browse Source

#曲线分析

zhongwei
yang_shj 5 months ago
parent
commit
7f5fbd9d2c
  1. 29
      hzims-service/equipment/src/main/java/com/hnac/hzims/history/service/impl/HistoryDeviceServiceImpl.java

29
hzims-service/equipment/src/main/java/com/hnac/hzims/history/service/impl/HistoryDeviceServiceImpl.java

@ -2,6 +2,7 @@ package com.hnac.hzims.history.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.hnac.hzims.common.logs.utils.StringUtils;
import com.hnac.hzims.history.entity.HistoryPointRecordEntity;
import com.hnac.hzims.history.service.IHistoryDeviceService;
@ -24,12 +25,14 @@ import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.*;
import java.util.stream.Collectors;
/**
@ -39,6 +42,7 @@ import java.util.stream.Collectors;
@AllArgsConstructor
public class HistoryDeviceServiceImpl implements IHistoryDeviceService {
private final IHistoryPointRecordService pointRecordService;
private final HzFacClient hzFacClient;
@ -47,6 +51,8 @@ public class HistoryDeviceServiceImpl implements IHistoryDeviceService {
private final DeviceDataClient deviceDataClient;
private static final ExecutorService pool = new ThreadPoolExecutor(2, 2, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(10), new ThreadFactoryBuilder().setNameFormat("history-point-save-%d").build() , new ThreadPoolExecutor.CallerRunsPolicy());
/**
* 项目设备列表
* @param projectId
@ -199,7 +205,7 @@ public class HistoryDeviceServiceImpl implements IHistoryDeviceService {
return new ArrayList<>();
}
// 异步线程保存常用查询
CompletableFuture.runAsync(() -> this.commonUserSave(param));
this.commonUserSave(param);
// 返回结构
return result.getData().entrySet().stream().map(entry->{
@ -310,6 +316,8 @@ public class HistoryDeviceServiceImpl implements IHistoryDeviceService {
* 异步保存常用记录
* @param param
*/
@Async
@Transactional
private void commonUserSave(HistoryDataParamVo param) {
// 当前用户Id
Long userId = AuthUtil.getUserId();
@ -320,16 +328,16 @@ public class HistoryDeviceServiceImpl implements IHistoryDeviceService {
points.add(param.getFirstAttrId());
}
if(StringUtils.isNotEmpty(param.getSecondAttrId())){
points.add(param.getFirstAttrId());
points.add(param.getSecondAttrId());
}
if(StringUtils.isNotEmpty(param.getThirdlyAttrId())){
points.add(param.getFirstAttrId());
points.add(param.getThirdlyAttrId());
}
if(StringUtils.isNotEmpty(param.getFourthAttrId())){
points.add(param.getFirstAttrId());
points.add(param.getFourthAttrId());
}
if(StringUtils.isNotEmpty(param.getFifthAttrId())){
points.add(param.getFirstAttrId());
points.add(param.getFifthAttrId());
}
// 查询历史保存数据
List<HistoryPointRecordEntity> records = pointRecordService.list(Wrappers.<HistoryPointRecordEntity>lambdaQuery()
@ -343,13 +351,13 @@ public class HistoryDeviceServiceImpl implements IHistoryDeviceService {
entity.setStationId(param.getStationId());
entity.setStationName(param.getStationName());
entity.setHistoryPoint(point);
if("firstAttr".equals(point)){
if(param.getFirstAttrId().equals(point)){
entity.setHistoryPointName(param.getFirstAttrName());
}else if("secondAttr".equals(point)){
}else if(param.getSecondAttrId().equals(point)){
entity.setHistoryPointName(param.getSecondAttrName());
}else if("thirdlyAttr".equals(point)){
}else if(param.getThirdlyAttrId().equals(point)){
entity.setHistoryPointName(param.getThirdlyAttrName());
}else if("fourthAttr".equals(point)){
}else if(param.getFourthAttrId().equals(point)){
entity.setHistoryPointName(param.getFourthAttrName());
}else{
entity.setHistoryPointName(param.getFifthAttrName());
@ -361,6 +369,7 @@ public class HistoryDeviceServiceImpl implements IHistoryDeviceService {
if(records.stream().map(HistoryPointRecordEntity::getHistoryPoint).collect(Collectors.toList()).contains(point)){
Optional<HistoryPointRecordEntity> optional = records.stream().filter(o->o.getHistoryPoint().equals(point)).findFirst();
if(optional.isPresent()){
entity.setId(optional.get().getId());
entity.setNumber(optional.get().getNumber() + 1);
}else{
entity.setNumber(1);

Loading…
Cancel
Save