| | |
| | | import com.nq.service.IStockConfigServices; |
| | | import com.nq.utils.PropertiesUtil; |
| | | import com.nq.utils.http.HttpClientRequest; |
| | | import com.nq.utils.redis.RedisKeyConstant; |
| | | import com.nq.utils.redis.RedisKeyUtil; |
| | | import com.nq.utils.redis.RedisShardedPoolUtils; |
| | | import com.nq.utils.timeutil.TimeUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | |
| | | public String doPost(String pid) { |
| | | // 从配置中获取 API URL,并拼接 key |
| | | String apiUrl = PropertiesUtil.getProperty("JS_IN_HTTP_URL") + "stock?key=" + PropertiesUtil.getProperty("JS_IN_KEY"); |
| | | String apiUrl = PropertiesUtil.getProperty("JP_HTTP_API") + "stock?key=" + PropertiesUtil.getProperty("JP_KEY"); |
| | | String result = null; |
| | | try { |
| | | URL url = new URL(apiUrl); |
| | |
| | | result = response.toString(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | // 发生异常时尝试从Redis获取数据 |
| | | String cacheBaseData = RedisShardedPoolUtils.get("price:"+pid); |
| | | if (!cacheBaseData.isEmpty()) { |
| | | return cacheBaseData; |
| | | } |
| | | } |
| | | RedisShardedPoolUtils.set("price:"+pid,result); |
| | | return result; |
| | | } |
| | | |