| | |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.google.common.collect.Lists; |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.config.StockType; |
| | | import com.nq.dao.StockIndexMapper; |
| | | import com.nq.pojo.StockIndex; |
| | | import com.nq.pojo.User; |
| | |
| | | List<StockIndex> stockIndexList = this.stockIndexMapper.listByAdmin(homeShow, listShow, transState, indexCode, indexName); |
| | | List<StockIndexVO> stockIndexVOS = Lists.newArrayList(); |
| | | for (StockIndex stockIndex : stockIndexList) { |
| | | StockIndexVO stockIndexVO = assembleStockIndexVO(stockIndex); |
| | | StockIndexVO stockIndexVO = assembleStockIndexVO(stockIndex,null); |
| | | stockIndexVOS.add(stockIndexVO); |
| | | } |
| | | PageInfo pageInfo = new PageInfo(stockIndexList); |
| | |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | } |
| | | |
| | | private StockIndexVO assembleStockIndexVO(StockIndex stockIndex) { |
| | | private StockIndexVO assembleStockIndexVO(StockIndex stockIndex,String stockType) { |
| | | StockIndexVO stockIndexVO = new StockIndexVO(); |
| | | |
| | | stockIndexVO.setId(stockIndex.getId()); |
| | |
| | | stockIndexVO.setAddTime(stockIndex.getAddTime()); |
| | | stockIndexVO.setTDesc(stockIndex.getTDesc()); |
| | | |
| | | MarketVO marketVO = querySingleIndex(stockIndex.getIndexGid()); |
| | | MarketVO marketVO = null; |
| | | if(StockType.A.getCode().equals(stockType)){ |
| | | marketVO = querySingleIndex(stockIndex.getIndexGid()); |
| | | }else { |
| | | marketVO = querySingleIndexHk(stockIndex.getIndexGid()); |
| | | } |
| | | |
| | | stockIndexVO.setCurrentPoint(marketVO.getNowPrice()); |
| | | stockIndexVO.setFloatPoint(marketVO.getIncrease()); |
| | | stockIndexVO.setFloatRate(marketVO.getIncreaseRate()); |
| | | stockIndexVO.setType(marketVO.getType()); |
| | | return stockIndexVO; |
| | | } |
| | | |
| | | public MarketVO querySingleIndexHk(String indexCode) { |
| | | MarketVO marketVO = null; |
| | | |
| | | String market_url = PropertiesUtil.getProperty("sina.single.market.hkurl"); |
| | | |
| | | String result = null; |
| | | try { |
| | | market_url = market_url + indexCode; |
| | | //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | //System.out.print("指数请求开始,时间:"+sdf.format(new Date())+",market_url:"+market_url + "\n"); |
| | | |
| | | result = HttpClientRequest.doGet(market_url); |
| | | //System.out.print("指数请求结束,时间:"+sdf.format(new Date())+",result:"+result + "\n"); |
| | | } catch (Exception e) { |
| | | log.error("获取 大盘指数 出错 e = {}", e); |
| | | } |
| | | try { |
| | | if (StringUtils.isNotBlank(result)) { |
| | | result = result.substring(result.indexOf("\"") + 1, result.lastIndexOf("\"")); |
| | | |
| | | marketVO = new MarketVO(); |
| | | if (result.contains(",")) { |
| | | String[] sh01_arr = result.split(","); |
| | | marketVO.setName(sh01_arr[0]); |
| | | marketVO.setNowPrice(sh01_arr[6]); |
| | | marketVO.setIncrease(sh01_arr[7]); |
| | | marketVO.setIncreaseRate(sh01_arr[8]); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("转换大盘指数出错 str = {} , e = {}", result, e); |
| | | } |
| | | |
| | | return marketVO; |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | public ServerResponse queryListIndex(HttpServletRequest request) { |
| | | List<StockIndex> list = this.stockIndexMapper.queryListIndex(); |
| | | List<StockIndexVO> stockIndexVOS = Lists.newArrayList(); |
| | | String stockType = request.getParameter("stockType"); |
| | | List<StockIndex> list = this.stockIndexMapper.queryListIndexType(stockType); |
| | | User user = iUserService.getCurrentUser(request); |
| | | for (StockIndex stockIndex : list) { |
| | | StockIndexVO stockIndexVO = assembleStockIndexVO(stockIndex); |
| | | StockIndexVO stockIndexVO = assembleStockIndexVO(stockIndex,stockType); |
| | | //是否添加自選 |
| | | if (user == null) { |
| | | stockIndexVO.setIsOption("0"); |