package com.iailab.module.data.channel.http.collector.asdb; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.iailab.framework.common.util.http.HttpUtils; import com.iailab.module.data.channel.http.entity.HttpApiEntity; import com.iailab.module.data.channel.http.service.HttpApiService; import com.iailab.module.data.common.enums.DataSourceType; import com.iailab.module.data.common.utils.DateUtils; import com.iailab.module.data.common.utils.TagUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import java.util.*; /** * 鞍信平均值接口 * GET * http://10.50.37.1:8806/batch/xxb/getDagongHistoryPointAvg?point=E1Q00001001&startTime=2025-06-25 09:16:00&endTime=2025-06-25 09:17:00 * { * "E1Q00001001": 16.747500000000002 * } * * @author PanZhibao * @Description * @createTime 2025年06月27日 */ @Slf4j @Component public class HttpCollectorForAsag { @Autowired private HttpApiService httpApiService; @Autowired private RedisTemplate redisTemplate; public static final long offset = 10; private final static String API_CODE = "ASAG"; private static String api_url; private HttpApiEntity getHttpApi(String id) { return httpApiService.getFromCatch(id); } public Map getTagValues(List params, Date collectTime, Map result) { try { this.getByHtp(result, params, collectTime); } catch (Exception ex) { log.info("getCurrentValue异常"); ex.printStackTrace(); throw ex; } return result; } private void getByHtp(Map result, List params, Date collectTime) { if (StringUtils.isBlank(api_url)) { HttpApiEntity apiEntity = httpApiService.getByCode(API_CODE); api_url = apiEntity.getUrl(); } for (Object[] item : params) { HttpApiEntity httpApi = this.getHttpApi(item[0].toString()); String sourceName = httpApi.getCode(); Calendar calendar = Calendar.getInstance(); calendar.setTime(collectTime); Date endTime = calendar.getTime(); calendar.add(Calendar.MINUTE, (Integer) item[2] * -1); Date startTime = calendar.getTime(); Map queryMap = new HashMap<>(); String point = item[1].toString(); queryMap.put("point", point); queryMap.put("startTime", DateUtils.format(startTime, "yyyy-MM-dd HH:mm:ss")); queryMap.put("endTime", DateUtils.format(endTime, "yyyy-MM-dd HH:mm:ss")); String responseStr = HttpUtils.sendGet(api_url, queryMap, ""); JSONObject obj = JSON.parseObject(responseStr); if (obj.containsKey(point)) { Double value = obj.getDouble(point); result.put(TagUtils.genTagId(DataSourceType.HTTP.getCode(), sourceName, point), value); } } } }