| | |
| | | |
| | | private static final String IS_SUCCESS = "isSuccess"; |
| | | |
| | | private static final String RESP_DATA = "data"; |
| | | |
| | | public static final String TIV = "TagIdValue:"; |
| | | |
| | | public static final long offset = 60 * 10L; |
| | |
| | | String responseStr = HttpUtils.sendPost(httpApi.getUrl() + "/" + currentDate, tagSb.toString()); |
| | | JSONObject responseObj = JSON.parseObject(responseStr); |
| | | if (STA_TRUE.equals(responseObj.get(IS_SUCCESS).toString())) { |
| | | JSONArray tagValueList = responseObj.getJSONArray("data"); |
| | | JSONArray tagValueList = responseObj.getJSONArray(RESP_DATA); |
| | | if (!CollectionUtils.isEmpty(tagValueList)) { |
| | | for (int i = 0; i < tagValueList.size(); i++) { |
| | | JSONObject item = tagValueList.getJSONObject(i); |
| | |
| | | return result; |
| | | } |
| | | List<String> noCacheTagNames = new ArrayList<>();//未缓存的tag |
| | | for (int i = 0; i < tagNames.size(); i++) { |
| | | for (String tagName : tagNames) { |
| | | //先查缓存 |
| | | BoundHashOperations<String, String, Object> ops = redisTemplate.boundHashOps("IhdTag:" + tagNames.get(i)); |
| | | BoundHashOperations<String, String, Object> ops = redisTemplate.boundHashOps("IhdTag:" + tagName); |
| | | if (ops.get(V) != null) { |
| | | BigDecimal value = new BigDecimal(ops.get(V).toString()); |
| | | result.put(tagNames.get(i), value.setScale(3, RoundingMode.HALF_UP)); |
| | | result.put(tagName, value.setScale(3, RoundingMode.HALF_UP)); |
| | | } else { |
| | | noCacheTagNames.add(tagNames.get(i)); |
| | | noCacheTagNames.add(tagName); |
| | | } |
| | | } |
| | | if (CollectionUtils.isEmpty(noCacheTagNames)) { |
| | |
| | | String responseStr = ""; |
| | | responseStr = HttpUtils.sendPost(httpApi.getUrl().replace("getPointdatasAvg", "getPointslast") + "/" + currentDate, tagSb); |
| | | JSONObject responseObj = JSON.parseObject(responseStr); |
| | | if (STA_TRUE.equals(responseObj.get(IS_SUCCESS).toString())) { |
| | | JSONArray tagValueList = responseObj.getJSONArray("data"); |
| | | if (!CollectionUtils.isEmpty(tagValueList)) { |
| | | return result; |
| | | if (!STA_TRUE.equals(responseObj.get(IS_SUCCESS).toString())) { |
| | | return result; |
| | | } |
| | | JSONArray tagValueList = responseObj.getJSONArray(RESP_DATA); |
| | | if (CollectionUtils.isEmpty(tagValueList)) { |
| | | return result; |
| | | } |
| | | for (int i = 0; i < tagValueList.size(); i++) { |
| | | JSONObject item = tagValueList.getJSONObject(i); |
| | | if (item.get(V) == null) { |
| | | continue; |
| | | } |
| | | for (int i = 0; i < tagValueList.size(); i++) { |
| | | JSONObject item = tagValueList.getJSONObject(i); |
| | | if (item.get(V) == null) { |
| | | continue; |
| | | } |
| | | //存缓存 |
| | | BoundHashOperations<String, String, Object> ops = redisTemplate.boundHashOps("IhdTag:" + item.get(N).toString()); |
| | | ops.put(V, item.get(V).toString()); |
| | | //设置过期时间 |
| | | redisTemplate.expire(item.get(N).toString(), 10, TimeUnit.SECONDS); |
| | | //把查询到的数据插入结果集 |
| | | BigDecimal value = new BigDecimal(item.get(V).toString()); |
| | | result.put(item.get(N).toString(), value.setScale(3, RoundingMode.HALF_UP)); |
| | | } |
| | | //存缓存 |
| | | BoundHashOperations<String, String, Object> ops = redisTemplate.boundHashOps("IhdTag:" + item.get(N).toString()); |
| | | ops.put(V, item.get(V).toString()); |
| | | //设置过期时间 |
| | | redisTemplate.expire(item.get(N).toString(), 10, TimeUnit.SECONDS); |
| | | //把查询到的数据插入结果集 |
| | | BigDecimal value = new BigDecimal(item.get(V).toString()); |
| | | result.put(item.get(N).toString(), value.setScale(3, RoundingMode.HALF_UP)); |
| | | } |
| | | } catch (Exception ex) { |
| | | log.info("getCurrentValue异常"); |
| | |
| | | JSONObject responseObj = JSON.parseObject(responseStr); |
| | | log.info("responseObj=====" + responseObj.toJSONString()); |
| | | if (STA_TRUE.equals(responseObj.get(IS_SUCCESS).toString())) { |
| | | JSONArray tagValueList = responseObj.getJSONArray("data"); |
| | | JSONArray tagValueList = responseObj.getJSONArray(RESP_DATA); |
| | | if (!CollectionUtils.isEmpty(tagValueList)) { |
| | | for (int i = 0; i < tagValueList.size(); i++) { |
| | | JSONObject item = tagValueList.getJSONObject(i); |
| | |
| | | JSONObject responseObj = JSON.parseObject(responseStr); |
| | | log.info("responseObj=====" + responseObj.toJSONString()); |
| | | if (STA_TRUE.equals(responseObj.get(IS_SUCCESS).toString())) { |
| | | JSONArray tagValueList = responseObj.getJSONArray("data"); |
| | | JSONArray tagValueList = responseObj.getJSONArray(RESP_DATA); |
| | | if (!CollectionUtils.isEmpty(tagValueList)) { |
| | | for (int i = 0; i < tagValueList.size(); i++) { |
| | | JSONObject item = tagValueList.getJSONObject(i); |
| | |
| | | |
| | | private void setOut(String url, String sourceName, Map<String, Object> result, List<Object[]> params, Date collectTime) { |
| | | for (int i = 0; i < params.size(); i++) { |
| | | String tagId = TIV + TagUtils.genTagId(DataSourceType.HTTP.getCode(), sourceName, params.get(i)[1].toString()); |
| | | if(redisTemplate.hasKey(tagId)) { |
| | | String tagId = TIV + TagUtils.genTagId(DataSourceType.HTTP.getCode(), sourceName, params.get(i)[1].toString()); |
| | | if (redisTemplate.hasKey(tagId)) { |
| | | result.put(TagUtils.genTagId(DataSourceType.HTTP.getCode(), sourceName, params.get(i)[1].toString()), redisTemplate.opsForValue().get(tagId)); |
| | | } |
| | | } |