| | |
| | | //原油 |
| | | private static final String crude_oil_API_URL = "http://47.112.169.122/fOption_curr.action?username=Qq112233&password=3ce25a66d5b3a8cd661024fea6c79388&id=@CL0W"; |
| | | |
| | | @Scheduled(cron = "0/10 * * * * ?") // 每6秒执行一次 |
| | | @Scheduled(cron = "0/6 * * * * ?") // 每6秒执行一次 |
| | | public void gold() { |
| | | try { |
| | | // 使用RestTemplate发起HTTP请求 |
| | |
| | | String response = restTemplate.getForObject(gold_API_URL, String.class); |
| | | |
| | | // 解析返回的CSV格式数据,去除可能存在的换行符 |
| | | if (response != null) { |
| | | if (response != null && !response.contains("参数错误")) { |
| | | // 清除换行符并按逗号分割数据 |
| | | String[] parts = response.trim().split(","); |
| | | String price = parts[2].trim(); // "3348.4" |
| | |
| | | } |
| | | } |
| | | |
| | | @Scheduled(cron = "0/15 * * * * ?") // 每6秒执行一次 |
| | | @Scheduled(cron = "0/7 * * * * ?") // 每6秒执行一次 |
| | | public void crudeOil() { |
| | | try { |
| | | // 使用RestTemplate发起HTTP请求 |
| | |
| | | String response = restTemplate.getForObject(crude_oil_API_URL, String.class); |
| | | |
| | | // 解析返回的CSV格式数据,去除可能存在的换行符 |
| | | if (response != null) { |
| | | if (response != null && !response.contains("参数错误")) { |
| | | // 清除换行符并按逗号分割数据 |
| | | String[] parts = response.trim().split(","); |
| | | String price = parts[2].trim(); // "3348.4" |
| | |
| | | String[] arr = {"d", "w", "m", "1", "5", "30"}; |
| | | for (String str : arr) { |
| | | String g = restTemplate.getForObject(k_gold_API_URL+str, String.class); |
| | | if(!g.contains("参数错误")){ |
| | | RedisShardedPoolUtils.set("k_gold_"+str, g); |
| | | Thread.sleep(6000); |
| | | Thread.sleep(10000); |
| | | } |
| | | String c = restTemplate.getForObject(k_crude_oil_API_URL+str, String.class); |
| | | if(!c.contains("参数错误")){ |
| | | RedisShardedPoolUtils.set("k_crude_oil_"+str, c); |
| | | Thread.sleep(6000); |
| | | Thread.sleep(10000); |
| | | } |
| | | } |
| | | } |
| | | /** |