| | |
| | | package com.nq.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.google.gson.Gson; |
| | |
| | | import com.nq.pojo.*; |
| | | import com.nq.service.IPriceServices; |
| | | import com.nq.service.IStockConfigServices; |
| | | import com.nq.utils.PropertiesUtil; |
| | | import com.nq.utils.http.HttpClientRequest; |
| | | import com.nq.utils.redis.RedisKeyUtil; |
| | | import com.nq.utils.timeutil.TimeUtil; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.BufferedReader; |
| | | import java.io.InputStreamReader; |
| | | import java.io.*; |
| | | import java.lang.reflect.Type; |
| | | import java.math.BigDecimal; |
| | | import java.io.BufferedReader; |
| | |
| | | if(stockSetting.getType().equals("0")){ |
| | | return new BigDecimal(stockSetting.getPrice()); |
| | | }else{ |
| | | String s = doGet(stock.getStockCode()); |
| | | String s = doPost(stock.getStockCode()); |
| | | if(null != s){ |
| | | Map<String, Object> stringObjectMap = jsonToMap(s); |
| | | return new BigDecimal(stringObjectMap.get("last").toString()).multiply(new BigDecimal(stockSetting.getPrice())); |
| | |
| | | } |
| | | } |
| | | |
| | | String s = doGet(stock.getStockCode()); |
| | | String s = doPost(stock.getStockCode()); |
| | | if(null != s) { |
| | | Map<String, Object> stringObjectMap = jsonToMap(s); |
| | | return new BigDecimal(stringObjectMap.get("last").toString()); |
| | | return new BigDecimal(stringObjectMap.get("Last").toString()); |
| | | } |
| | | return BigDecimal.ZERO; |
| | | } |
| | |
| | | @Override |
| | | public Map<String, Object> getNewStock(String stockCode) { |
| | | Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code",stockCode)); |
| | | String s = doGet(stock.getStockCode()); |
| | | String s = doPost(stock.getStockCode()); |
| | | if(null != s){ |
| | | Map<String, Object> stringObjectMap = jsonToMap(s); |
| | | return stringObjectMap; |
| | |
| | | } |
| | | } |
| | | |
| | | public String doGet(String pid){ |
| | | String apiUrl = "http://api-in-2.js-stock.top/stock?pid="+pid+"&key=eVKtHt7aG4m6ozwWL9qG"; |
| | | public String doPost(String pid){ |
| | | String apiUrl = PropertiesUtil.getProperty("MAS_HTTP_API")+"stock?key="+PropertiesUtil.getProperty("MAS_KEY"); |
| | | try { |
| | | URL url = new URL(apiUrl); |
| | | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
| | | connection.setRequestMethod("GET"); |
| | | connection.setRequestMethod("POST"); |
| | | connection.setRequestProperty("Content-Type", "application/json"); |
| | | connection.setDoOutput(true); |
| | | |
| | | BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); |
| | | String json = JSON.toJSONString(new HashMap<String, String>() {{ |
| | | put("pid", pid); |
| | | }}); |
| | | try(OutputStream os = connection.getOutputStream()) { |
| | | byte[] input = json.getBytes("utf-8"); |
| | | os.write(input, 0, input.length); |
| | | } |
| | | |
| | | BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); |
| | | String inputLine; |
| | | StringBuffer response = new StringBuffer(); |
| | | |