|
|
@ -2,12 +2,24 @@ package com.hnac.hzims.operational.census.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
|
|
|
|
|
import com.esotericsoftware.minlog.Log; |
|
|
|
import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; |
|
|
|
import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; |
|
|
|
import com.hnac.hzims.operational.census.service.DeviceDataService; |
|
|
|
import com.hnac.hzims.operational.census.service.DeviceDataService; |
|
|
|
import com.hnac.hzims.operational.census.vo.RealVo; |
|
|
|
import com.hnac.hzims.operational.census.vo.RealVo; |
|
|
|
|
|
|
|
import com.hnac.hzinfo.datasearch.PointData; |
|
|
|
|
|
|
|
import com.hnac.hzinfo.datasearch.analyse.domain.AnalyzeDataCondition; |
|
|
|
|
|
|
|
import com.hnac.hzinfo.datasearch.analyse.domain.AnalyzeDataList; |
|
|
|
|
|
|
|
import com.hnac.hzinfo.datasearch.analyse.domain.FieldsData; |
|
|
|
|
|
|
|
import com.hnac.hzinfo.datasearch.real.IRealDataSearchClient; |
|
|
|
|
|
|
|
import com.hnac.hzinfo.datasearch.real.po.RealDataSearchPO; |
|
|
|
|
|
|
|
import com.hnac.hzinfo.sdk.analyse.AnalyseDataSearchClient; |
|
|
|
|
|
|
|
import com.hnac.hzinfo.sdk.core.response.HzPage; |
|
|
|
|
|
|
|
import com.hnac.hzinfo.sdk.core.response.Result; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
import org.springblade.core.tool.utils.StringUtil; |
|
|
|
import org.springblade.core.tool.utils.StringUtil; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
@ -21,55 +33,37 @@ import java.util.stream.Collectors; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author ysj |
|
|
|
* @author ysj |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
@Service |
|
|
|
@RequiredArgsConstructor |
|
|
|
@RequiredArgsConstructor |
|
|
|
public class DeviceDataServiceImpl implements DeviceDataService { |
|
|
|
public class DeviceDataServiceImpl implements DeviceDataService { |
|
|
|
|
|
|
|
|
|
|
|
private final RedisTemplate redisTemplate; |
|
|
|
private final IRealDataSearchClient realDataSearchClient; |
|
|
|
|
|
|
|
|
|
|
|
@Value("${hzims.operation.realIdKey}") |
|
|
|
private final AnalyseDataSearchClient analyseDataSearchClient; |
|
|
|
public String real_id_cofig_final; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String device_cache_cofig_final = "hzims:equipment:emInfo:deviceCode.emInfoList"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 实时数据 |
|
|
|
|
|
|
|
* @param search |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public RealVo real(String code, String signages) { |
|
|
|
public R<List<FieldsData>> real(RealDataSearchPO search) { |
|
|
|
// 缓存设备数据
|
|
|
|
try{ |
|
|
|
List<EminfoAndEmParamVo> devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), new TypeReference<List<EminfoAndEmParamVo>>() { |
|
|
|
return realDataSearchClient.getRealDataByAnalyzeCode(search); |
|
|
|
}); |
|
|
|
}catch (Exception exception){ |
|
|
|
if(CollectionUtil.isEmpty(devices)){ |
|
|
|
throw new ServiceException("系统异常!"); |
|
|
|
throw new ServiceException("不存在设备!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<EminfoAndEmParamVo> filters = devices.stream().filter(device->device.getEmCode().equals(code)).collect(Collectors.toList()); |
|
|
|
|
|
|
|
if(CollectionUtil.isEmpty(filters)){ |
|
|
|
|
|
|
|
throw new ServiceException("不存在设备!"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// 设备标识
|
|
|
|
|
|
|
|
Map<String,String> point = filters.get(0).getPoint(); |
|
|
|
|
|
|
|
if(MapUtils.isEmpty(point)){ |
|
|
|
|
|
|
|
throw new ServiceException("设备未绑定模型实列监测点位!"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if(!point.containsKey(signages)){ |
|
|
|
|
|
|
|
throw new ServiceException("设备未绑定模型实列监测点位!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 查找realId数据
|
|
|
|
|
|
|
|
RealVo real = new RealVo(); |
|
|
|
|
|
|
|
real.setRealId(point.get(signages)); |
|
|
|
|
|
|
|
real.setValue(this.getRealMap().get(real.getRealId())); |
|
|
|
|
|
|
|
real.setQuality("0"); |
|
|
|
|
|
|
|
return real; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获取实时数据 |
|
|
|
* 历史数据 |
|
|
|
|
|
|
|
* @param analyzeDataCondition |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private Map<String, String> getRealMap() { |
|
|
|
@Override |
|
|
|
String json = (String) redisTemplate.opsForValue().get(real_id_cofig_final); |
|
|
|
public R<HzPage<AnalyzeDataList>> history(AnalyzeDataCondition analyzeDataCondition) { |
|
|
|
if(StringUtil.isBlank(json)){ |
|
|
|
Result<HzPage<AnalyzeDataList>> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCode(analyzeDataCondition); |
|
|
|
return null; |
|
|
|
return R.data(result.getData()); |
|
|
|
} |
|
|
|
|
|
|
|
return JSONObject.parseObject(json, new TypeReference<Map<String, String>>() {}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |