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