|
|
|
@ -1,12 +1,16 @@
|
|
|
|
|
package com.hnac.hzims.history.service.impl; |
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.hnac.hzims.common.logs.utils.StringUtils; |
|
|
|
|
import com.hnac.hzims.history.entity.HistoryPointRecordEntity; |
|
|
|
|
import com.hnac.hzims.history.service.IHistoryDeviceService; |
|
|
|
|
import com.hnac.hzims.history.vo.HistoryDataParamVo; |
|
|
|
|
import com.hnac.hzims.history.vo.HistoryDevicePointVo; |
|
|
|
|
import com.hnac.hzims.history.vo.HistoryFactoryPointVo; |
|
|
|
|
import com.hnac.hzims.history.service.IHistoryPointRecordService; |
|
|
|
|
import com.hnac.hzims.history.vo.*; |
|
|
|
|
import com.hnac.hzinfo.sdk.core.response.Result; |
|
|
|
|
import com.hnac.hzinfo.sdk.v5.device.DeviceDataClient; |
|
|
|
|
import com.hnac.hzinfo.sdk.v5.device.client.DeviceClient; |
|
|
|
|
import com.hnac.hzinfo.sdk.v5.device.source.dto.HisFacSourceDataDTO; |
|
|
|
|
import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceAttrVO; |
|
|
|
|
import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceVO; |
|
|
|
|
import com.hnac.hzinfo.sdk.v5.hzfac.HzFacClient; |
|
|
|
@ -14,14 +18,18 @@ import com.hnac.hzinfo.sdk.v5.hzfac.vo.FacDeviceAttrVO;
|
|
|
|
|
import com.hnac.hzinfo.sdk.v5.hzfac.vo.FacDeviceVO; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
|
import org.springblade.core.secure.utils.AuthUtil; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
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.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.time.ZoneOffset; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -31,6 +39,8 @@ import java.util.stream.Collectors;
|
|
|
|
|
@AllArgsConstructor |
|
|
|
|
public class HistoryDeviceServiceImpl implements IHistoryDeviceService { |
|
|
|
|
|
|
|
|
|
private final IHistoryPointRecordService pointRecordService; |
|
|
|
|
|
|
|
|
|
private final HzFacClient hzFacClient; |
|
|
|
|
|
|
|
|
|
private final DeviceClient deviceClient; |
|
|
|
@ -163,7 +173,7 @@ public class HistoryDeviceServiceImpl implements IHistoryDeviceService {
|
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Map<String, Object> historyCurve(HistoryDataParamVo param) { |
|
|
|
|
public List<HistoryDataVo> historyCurve(HistoryDataParamVo param) { |
|
|
|
|
// 计算查询数据维度 : 0-10秒 、 1-1分钟 、2-5分钟 .....
|
|
|
|
|
Integer intervalType = this.computeInterval(param.getStartTime(),param.getEndTime()); |
|
|
|
|
// 查询数据
|
|
|
|
@ -186,19 +196,83 @@ public class HistoryDeviceServiceImpl implements IHistoryDeviceService {
|
|
|
|
|
throw new ServiceException(result.getMsg()); |
|
|
|
|
} |
|
|
|
|
if(CollectionUtil.isEmpty(result.getData())){ |
|
|
|
|
return new HashMap<>(); |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
} |
|
|
|
|
return result.getData(); |
|
|
|
|
// 异步线程保存常用查询
|
|
|
|
|
CompletableFuture.runAsync(() -> this.commonUserSave(param)); |
|
|
|
|
|
|
|
|
|
// 返回结构
|
|
|
|
|
return result.getData().entrySet().stream().map(entry->{ |
|
|
|
|
HistoryDataVo history = new HistoryDataVo(); |
|
|
|
|
if("firstAttr".equals(entry.getKey())){ |
|
|
|
|
history.setAttrIndex(param.getFirstAttrId()); |
|
|
|
|
history.setAttrIndexName(param.getFirstAttrName()); |
|
|
|
|
}else if("secondAttr".equals(entry.getKey())){ |
|
|
|
|
history.setAttrIndex(param.getSecondAttrId()); |
|
|
|
|
history.setAttrIndexName(param.getSecondAttrName()); |
|
|
|
|
}else if("thirdlyAttr".equals(entry.getKey())){ |
|
|
|
|
history.setAttrIndex(param.getThirdlyAttrId()); |
|
|
|
|
history.setAttrIndexName(param.getThirdlyAttrName()); |
|
|
|
|
}else if("fourthAttr".equals(entry.getKey())){ |
|
|
|
|
history.setAttrIndex(param.getFourthAttrId()); |
|
|
|
|
history.setAttrIndexName(param.getFourthAttrName()); |
|
|
|
|
}else{ |
|
|
|
|
history.setAttrIndex(param.getFifthAttrName()); |
|
|
|
|
history.setAttrIndexName(param.getFifthAttrName()); |
|
|
|
|
} |
|
|
|
|
HistoryDetailVo historyDetail = JSONObject.parseObject(JSONObject.toJSONString(entry.getValue()),HistoryDetailVo.class); |
|
|
|
|
Date start = null; |
|
|
|
|
String val = null; |
|
|
|
|
List<HistoryDetailDataVo> detailRecords = new ArrayList<>(); |
|
|
|
|
for(HistoryDetailDataVo data : historyDetail.getData()) { |
|
|
|
|
HistoryDetailDataVo detail = new HistoryDetailDataVo(); |
|
|
|
|
detail.setTs(data.getTs()); |
|
|
|
|
if(ObjectUtil.isEmpty(val)){ |
|
|
|
|
start = DateUtil.parse(data.getTs(),DateUtil.PATTERN_DATETIME); |
|
|
|
|
val = data.getVal(); |
|
|
|
|
detail.setVal(val); |
|
|
|
|
}else{ |
|
|
|
|
Date end = DateUtil.parse(data.getTs(),DateUtil.PATTERN_DATETIME); |
|
|
|
|
if(StringUtils.isEmpty(data.getVal())){ |
|
|
|
|
if(end.getTime() - start.getTime() <= 5 * 60 * 1000L){ |
|
|
|
|
detail.setVal(val); |
|
|
|
|
}else{ |
|
|
|
|
detail.setVal(data.getVal()); |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
detail.setVal(data.getVal()); |
|
|
|
|
start = DateUtil.parse(data.getTs(),DateUtil.PATTERN_DATETIME); |
|
|
|
|
val = data.getVal(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
detailRecords.add(detail); |
|
|
|
|
} |
|
|
|
|
history.setData(detailRecords); |
|
|
|
|
return history; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取设备历史数据列表 |
|
|
|
|
* @param param |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Map<String, Object> historyTabulation(HistoryDataParamVo param) { |
|
|
|
|
return null; |
|
|
|
|
public List<Map<String, Object>> historyTabulation(HistoryTabulationParamVo param) { |
|
|
|
|
HisFacSourceDataDTO source = new HisFacSourceDataDTO(); |
|
|
|
|
source.setProjectId(param.getProjectId()); |
|
|
|
|
source.setFacDeivceAttrIds(param.getFacDeivceAttrIds()); |
|
|
|
|
source.setBeginTime(param.getStartTime()); |
|
|
|
|
source.setFinishTime(param.getEndTime()); |
|
|
|
|
source.setIsPage(true); |
|
|
|
|
source.setCurrent(param.getCurrent()); |
|
|
|
|
source.setPageSize(param.getPageSize()); |
|
|
|
|
Result<List<Map<String, Object>>> tabulations = deviceDataClient.hisFacSourceData(source); |
|
|
|
|
if(!tabulations.isSuccess() || CollectionUtil.isEmpty(tabulations.getData())){ |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
} |
|
|
|
|
return tabulations.getData(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -231,4 +305,71 @@ public class HistoryDeviceServiceImpl implements IHistoryDeviceService {
|
|
|
|
|
} |
|
|
|
|
return 5; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 异步保存常用记录 |
|
|
|
|
* @param param |
|
|
|
|
*/ |
|
|
|
|
private void commonUserSave(HistoryDataParamVo param) { |
|
|
|
|
// 当前用户Id
|
|
|
|
|
Long userId = AuthUtil.getUserId(); |
|
|
|
|
|
|
|
|
|
// 点位Id
|
|
|
|
|
List<String> points = new ArrayList<>(); |
|
|
|
|
if(StringUtils.isNotEmpty(param.getFirstAttrId())){ |
|
|
|
|
points.add(param.getFirstAttrId()); |
|
|
|
|
} |
|
|
|
|
if(StringUtils.isNotEmpty(param.getSecondAttrId())){ |
|
|
|
|
points.add(param.getFirstAttrId()); |
|
|
|
|
} |
|
|
|
|
if(StringUtils.isNotEmpty(param.getThirdlyAttrId())){ |
|
|
|
|
points.add(param.getFirstAttrId()); |
|
|
|
|
} |
|
|
|
|
if(StringUtils.isNotEmpty(param.getFourthAttrId())){ |
|
|
|
|
points.add(param.getFirstAttrId()); |
|
|
|
|
} |
|
|
|
|
if(StringUtils.isNotEmpty(param.getFifthAttrId())){ |
|
|
|
|
points.add(param.getFirstAttrId()); |
|
|
|
|
} |
|
|
|
|
// 查询历史保存数据
|
|
|
|
|
List<HistoryPointRecordEntity> records = pointRecordService.list(Wrappers.<HistoryPointRecordEntity>lambdaQuery() |
|
|
|
|
.in(HistoryPointRecordEntity::getHistoryPoint,points) |
|
|
|
|
.eq(HistoryPointRecordEntity::getCreateUser,userId) |
|
|
|
|
.eq(HistoryPointRecordEntity::getStationId,param.getStationId()) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
pointRecordService.saveOrUpdateBatch(points.stream().map(point->{ |
|
|
|
|
HistoryPointRecordEntity entity = new HistoryPointRecordEntity(); |
|
|
|
|
entity.setStationId(param.getStationId()); |
|
|
|
|
entity.setStationName(param.getStationName()); |
|
|
|
|
entity.setHistoryPoint(point); |
|
|
|
|
if("firstAttr".equals(point)){ |
|
|
|
|
entity.setHistoryPointName(param.getFirstAttrName()); |
|
|
|
|
}else if("secondAttr".equals(point)){ |
|
|
|
|
entity.setHistoryPointName(param.getSecondAttrName()); |
|
|
|
|
}else if("thirdlyAttr".equals(point)){ |
|
|
|
|
entity.setHistoryPointName(param.getThirdlyAttrName()); |
|
|
|
|
}else if("fourthAttr".equals(point)){ |
|
|
|
|
entity.setHistoryPointName(param.getFourthAttrName()); |
|
|
|
|
}else{ |
|
|
|
|
entity.setHistoryPointName(param.getFifthAttrName()); |
|
|
|
|
} |
|
|
|
|
if(CollectionUtil.isEmpty(records)){ |
|
|
|
|
entity.setNumber(1); |
|
|
|
|
}else{ |
|
|
|
|
// 包含
|
|
|
|
|
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.setNumber(optional.get().getNumber() + 1); |
|
|
|
|
}else{ |
|
|
|
|
entity.setNumber(1); |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
entity.setNumber(1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return entity; |
|
|
|
|
}).collect(Collectors.toList())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|