| | |
| | | import com.google.common.collect.Maps; |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.config.StockPoll; |
| | | import com.nq.config.StockType; |
| | | import com.nq.dao.RealTimeMapper; |
| | | import com.nq.dao.StockFuturesMapper; |
| | | import com.nq.dao.StockIndexMapper; |
| | |
| | | import java.io.IOException; |
| | | import java.io.InputStreamReader; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.text.SimpleDateFormat; |
| | |
| | | return ServerResponse.createBySuccess(echartsDataVO); |
| | | } |
| | | |
| | | public ServerResponse getSingleStock(String code,HttpServletRequest request) { |
| | | public ServerResponse getSingleStock(String stockType,String code,HttpServletRequest request) { |
| | | if (StringUtils.isBlank(code)) |
| | | return ServerResponse.createByErrorMsg(""); |
| | | Stock stock = new Stock(); |
| | |
| | | |
| | | // |
| | | } else {//股票 |
| | | |
| | | stock = this.stockMapper.findStockByCode(code); |
| | | if(StockType.HK.getCode().equals(stockType)){ |
| | | stock = this.stockMapper.findStockByCodeAndType(stockType,code); |
| | | }else { |
| | | stock = this.stockMapper.findStockByCode(code); |
| | | } |
| | | if (stock == null) |
| | | return ServerResponse.createByErrorMsg(""); |
| | | if (request.getHeader("lang") != null && !request.getHeader("lang").equals("zh-CN") && !request.getHeader("lang").equals("tww") && !request.getHeader("lang").equals("")) { |
| | |
| | | //股票数据 |
| | | StockVO stockVO = new StockVO(); |
| | | |
| | | String sinaResult = SinaStockApi.getSinaStock(gid); |
| | | // String sinaResult = SinaStockApi.getSinaStock(gid); |
| | | |
| | | stockVO= SinaStockApi.assembleLideStockVO(LiDeDataUtils.getStock(stock.getStockCode())); |
| | | if(ObjectUtils.isEmpty(stockVO)){ |
| | | stockVO = SinaStockApi.assembleStockVO(SinaStockApi.getSinaStock(stock.getStockGid())); |
| | | if (code.contains("hf")) { |
| | | stockVO = SinaStockApi.assembleStockFuturesVO(sinaResult); |
| | | if(StockType.HK.getCode().equals(stockType)){ |
| | | stockVO = SinaStockApi.otherStockVO(SinaStockApi.getSinaStock(StockType.HK.getCode()+stock.getStockGid())); |
| | | }else { |
| | | stockVO = SinaStockApi.assembleStockVO(SinaStockApi.getSinaStock(stock.getStockGid())); |
| | | } |
| | | |
| | | // if (code.contains("hf")) { |
| | | // stockVO = SinaStockApi.assembleStockFuturesVO(sinaResult); |
| | | // } |
| | | } |
| | | |
| | | // if (code.contains("hf")) { |
| | |
| | | |
| | | public ServerResponse selectRateByDaysAndStockCode(String stockCode, int days) { |
| | | Stock stock = this.stockMapper.findStockByCode(stockCode); |
| | | if (stock == null) |
| | | return ServerResponse.createByErrorMsg("没有该股票"); |
| | | if (stock == null) { |
| | | //再查港股 |
| | | stock = this.stockMapper.findStockByCodeAndType(StockType.HK.getCode(),stockCode); |
| | | if (stock == null) |
| | | return ServerResponse.createByErrorMsg("没有该股票"); |
| | | } |
| | | BigDecimal daysRate = this.iStockMarketsDayService.selectRateByDaysAndStockCode(stock.getId(), days); |
| | | return ServerResponse.createBySuccess(daysRate); |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ServerResponse getStockSort(Integer pageNo, Integer pageSize, String sort, Integer asc, String node) { |
| | | // String market_url = PropertiesUtil.getProperty("sina.market.zdf.url"); |
| | | String result = null; |
| | | String param="page="+pageNo+"&num="+pageSize+"&sort="+sort+"&asc="+asc+"&node="+node+"&symbol=&_s_r_a=sort"; |
| | | // String url=market_url+param; |
| | | // result = HttpClientRequest.doGet(url); |
| | | // |
| | | result = HttpClientRequest.doGet("http://111.170.140.248:7001/crypto/getStockSort.do?" + param); |
| | | com.alibaba.fastjson.JSONArray jsonArray = JSON.parseArray(result); |
| | | return ServerResponse.createBySuccess(jsonArray); |
| | | public ServerResponse getStockSort(Integer pageNo, Integer pageSize, String sort, Integer asc, String node,String stockType) { |
| | | String market_url = ""; |
| | | String param = ""; |
| | | if(StockType.A.getCode().equals(stockType)){ |
| | | market_url = PropertiesUtil.getProperty("sina.market.zdf.url"); |
| | | param="page="+pageNo+"&num="+pageSize+"&sort="+sort+"&asc="+asc+"&node="+node+"&symbol=&_s_r_a=sort"; |
| | | String result = null; |
| | | String url=market_url+param; |
| | | result = HttpClientRequest.doGet(url); |
| | | com.alibaba.fastjson.JSONArray jsonArray = JSON.parseArray(result); |
| | | return ServerResponse.createBySuccess(jsonArray); |
| | | }else { |
| | | market_url = PropertiesUtil.getProperty("sina.market.zdf.urlhk"); |
| | | param="page="+pageNo+"&num="+pageSize+"&sort="+sort+"&asc="+asc+"&node="+node+"&symbol=&_s_r_a=sort"; |
| | | String result = null; |
| | | String url=market_url+param; |
| | | result = HttpClientRequest.doGet(url); |
| | | com.alibaba.fastjson.JSONArray jsonArray = JSON.parseArray(result); |
| | | for (int i = 0; i < jsonArray.size(); i++) { |
| | | com.alibaba.fastjson.JSONObject obj = jsonArray.getJSONObject(i); |
| | | obj.put("buy",obj.get("lasttrade")); |
| | | obj.put("stock_type","hk"); |
| | | for (String key : obj.keySet()) { |
| | | if(key.equals("symbol")){ |
| | | continue; |
| | | } |
| | | Object value = obj.get(key); |
| | | if (value instanceof String) { |
| | | try { |
| | | BigDecimal bd = new BigDecimal((String) value); |
| | | obj.put(key, bd.setScale(3, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString()); |
| | | } catch (NumberFormatException e) { |
| | | // 非数字值保持原样 |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return ServerResponse.createBySuccess(jsonArray); |
| | | } |
| | | } |
| | | |
| | | /** |