| | |
| | | import com.iailab.module.data.channel.http.service.HttpApiService; |
| | | import com.iailab.module.data.common.enums.DataSourceType; |
| | | import com.iailab.module.data.common.utils.TagUtils; |
| | | import com.iailab.module.data.point.common.MeasurePointValueType; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | |
| | | @Slf4j |
| | | @Component |
| | | public class HttpCollectorForAsdb { |
| | | private static Map<String, HttpApiEntity> apiMap = new HashMap<>(); |
| | | |
| | | @Autowired |
| | | private HttpApiService httpApiService; |
| | |
| | | @Autowired |
| | | private RedisTemplate redisTemplate; |
| | | |
| | | @Autowired |
| | | private HttpCollectorForAsag httpCollectorForAsag; |
| | | |
| | | public static final long offset = 10; |
| | | |
| | | private HttpApiEntity getHttpApi(String id) { |
| | | if (apiMap.containsKey(id)) { |
| | | return apiMap.get(id); |
| | | } |
| | | HttpApiEntity httpApi = httpApiService.info(id); |
| | | apiMap.put(id, httpApi); |
| | | return httpApi; |
| | | return httpApiService.getFromCatch(id); |
| | | } |
| | | |
| | | public BigDecimal getTagValue(String sourceId, String tagNo) { |
| | |
| | | List<HttpAsdbRespDataVO> dataList = JSON.parseArray(responseStr, HttpAsdbRespDataVO.class); |
| | | log.info("存入IailabData缓存: " + catchKey); |
| | | dataList.forEach(item -> { |
| | | redisTemplate.opsForValue().set(catchKey, item.getValue().toString(), offset, TimeUnit.SECONDS); |
| | | redisTemplate.opsForValue().set("IailabData:" + httpApi.getCode() + ":" + item.getPoint(), item.getValue().toString(), offset, TimeUnit.SECONDS); |
| | | }); |
| | | for (HttpAsdbRespDataVO data : dataList){ |
| | | if (tagNo.equals(data.getPoint())){ |
| | |
| | | return new HashMap<>(); |
| | | } |
| | | try { |
| | | HttpApiEntity httpApi = this.getHttpApi(params.get(0)[0].toString()); |
| | | this.getByHtp(httpApi.getUrl(), httpApi.getCode(), result, params); |
| | | List<Object[]> paramsSim = new ArrayList<>(); |
| | | List<Object[]> paramsDig = new ArrayList<>(); |
| | | for (Object[] param : params) { |
| | | if (((String) param[3]).equals(MeasurePointValueType.DIGITAL.getCode()) || (Integer) param[2] == 0) { |
| | | paramsDig.add(param); |
| | | } else { |
| | | paramsSim.add(param); |
| | | } |
| | | } |
| | | if (!CollectionUtils.isEmpty(paramsDig)) { |
| | | log.info("查询数字量,paramsDig.size(): " + paramsDig.size()); |
| | | HttpApiEntity httpApi = this.getHttpApi(params.get(0)[0].toString()); |
| | | this.getByHtp(httpApi.getUrl(), httpApi.getCode(), result, params); |
| | | } |
| | | if (!CollectionUtils.isEmpty(paramsSim)) { |
| | | log.info("查询模拟量,paramsSim.size(): " + paramsSim.size()); |
| | | httpCollectorForAsag.getTagValues(paramsSim, collectTime, result); |
| | | } |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | } |