| | |
| | | import com.google.common.collect.Maps; |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.config.StockPoll; |
| | | import com.nq.constant.StockConstant; |
| | | import com.nq.dao.*; |
| | | import com.nq.enums.EStockType; |
| | | import com.nq.pojo.*; |
| | | import com.nq.pojo.reponse.RPageInfo; |
| | | import com.nq.service.*; |
| | | import com.nq.utils.HttpClientRequest; |
| | | import com.nq.utils.http.HttpClientRequest; |
| | | import com.nq.utils.PropertiesUtil; |
| | | import com.nq.utils.redis.RedisShardedPoolUtils; |
| | | import com.nq.utils.stock.pinyin.GetPyByChinese; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import static com.nq.utils.DateTimeUtil.getWeekDay; |
| | | import static com.nq.utils.timeutil.DateTimeUtil.getWeekDay; |
| | | |
| | | @Service("iStockService") |
| | | public class StockServiceImpl implements IStockService { |
| | |
| | | |
| | | @Resource |
| | | StockDzMapper stockDzMapper; |
| | | |
| | | |
| | | @Autowired |
| | | IPriceServices iPriceServices; |
| | | |
| | | public ServerResponse getMarket() { |
| | | String market_url = PropertiesUtil.getProperty("sina.market.url"); |
| | |
| | | if (stockList.size() > 0){ |
| | | stockListVOS.addAll(Objects.requireNonNull(StockApi.getStockReailTimes(stockList))); |
| | | } |
| | | PageInfo pageInfo = new PageInfo(stockList); |
| | | for (int i = 0; i <stockListVOS.size() ; i++) { |
| | | stockListVOS.get(i).setNowPrice(iPriceServices.getNowPrice(stockListVOS.get(i).getCode()).toString()); |
| | | } |
| | | RPageInfo pageInfo = new RPageInfo(); |
| | | pageInfo.setList(stockListVOS); |
| | | pageInfo.setStockType(stockType); |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | } |
| | | |
| | |
| | | public ServerResponse getSingleStock(String code, HttpServletRequest request) { |
| | | if (StringUtils.isBlank(code)) |
| | | return ServerResponse.createByErrorMsg(""); |
| | | Stock stock = new Stock(); |
| | | Stock stock = stockMapper.findStockByCode(code); |
| | | Integer depositAmt = 0; |
| | | String introduction = null; |
| | | String result = null; |
| | | com.alibaba.fastjson2.JSONObject json = null; |
| | | //期货 |
| | | String url = null; |
| | | if (code.contains("hf")) { |
| | | StockFutures futmodel = stockFuturesMapper.selectFuturesByCode(code.replace("hf_", "")); |
| | | stock.setStockGid(futmodel.getFuturesGid()); |
| | | stock.setStockCode(futmodel.getFuturesCode()); |
| | | stock.setStockName(futmodel.getFuturesName()); |
| | | stock.setAddTime(futmodel.getAddTime()); |
| | | stock.setId(futmodel.getId()); |
| | | stock.setStockSpell("0"); |
| | | depositAmt = futmodel.getDepositAmt(); |
| | | url = PropertiesUtil.getProperty("sina.single.futures.introduction.url") + futmodel.getFuturesCode() + "&app=source&type=1"; |
| | | } else if (code.contains("sh") || code.contains("sz") || code.contains("hk") || code.contains("us")) { //指数 |
| | | StockIndex model = stockIndexMapper.selectIndexByCode(code.replace("sh", "").replace("sz", "").replace("hk", "").replace("us", "")); |
| | | stock.setStockGid(model.getIndexGid()); |
| | | stock.setStockCode(model.getIndexCode()); |
| | | stock.setStockName(model.getIndexName()); |
| | | stock.setAddTime(model.getAddTime()); |
| | | stock.setId(model.getId()); |
| | | stock.setStockSpell("0"); |
| | | depositAmt = model.getDepositAmt(); |
| | | introduction = model.getIntroduction(); |
| | | } else {//股票 |
| | | stock = this.stockMapper.findStockByCode(code); |
| | | if (stock == null) |
| | | return ServerResponse.createByErrorMsg(""); |
| | | //简介 |
| | | if (stock.getStockGid().contains("hk")) { |
| | | url = PropertiesUtil.getProperty("hk.stock.introduction.url") + "%22" + stock.getStockCode() + ".HK%22)"; |
| | | result = HttpClientRequest.doGet(url); |
| | | if (result.length() < 20) { |
| | | introduction = "暂无数据"; |
| | | } else { |
| | | json = com.alibaba.fastjson2.JSONObject.parseObject(result); |
| | | introduction = json.getJSONObject("result") |
| | | .getJSONArray("data") |
| | | .getJSONObject(0) |
| | | .getString("ORG_PROFILE"); |
| | | if (request.getHeader("lang") != null && !request.getHeader("lang").equals("zh-CN") && !request.getHeader("lang").equals("tww") && !request.getHeader("lang").equals("")) { |
| | | GoogleTranslateUtil googleTranslateUtil = new GoogleTranslateUtil(); |
| | | try { |
| | | introduction = googleTranslateUtil.translate(introduction, request.getHeader("lang")); |
| | | } catch (Exception e) { |
| | | log.error("翻译失败"); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | try { |
| | | url = PropertiesUtil.getProperty("sina.single.stock.introduction.url") + stock.getStockGid(); |
| | | result = HttpClientRequest.doGet(url); |
| | | json = com.alibaba.fastjson2.JSONObject.parseObject(result); |
| | | //取json里result里的data里的introduction |
| | | introduction = json.getJSONObject("result").getJSONObject("data").getString("introduction"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | String gid = stock.getStockGid(); |
| | | //股票数据 |
| | | StockVO stockVO = new StockVO(); |
| | | |
| | | if (gid.contains("hk") && "hk".equals(stock.getStockType())) { |
| | | String hkStock = RedisShardedPoolUtils.get(stock.getStockGid(), 1); |
| | | stockVO = StockApi.otherStockVO(hkStock); |
| | | |
| | | } else if (gid.contains("hk") || gid.contains("us")) { |
| | | String index = RedisShardedPoolUtils.get(stock.getStockGid(), 3); |
| | | stockVO = StockApi.otherStockVO(index); |
| | | } else { |
| | | stockVO = StockApi.assembleInStockVO(stock); |
| | | } |
| | | StockVO stockVO = StockApi.assembleInStockVO(stock); |
| | | stockVO.setDepositAmt(depositAmt); |
| | | stockVO.setNowPrice(iPriceServices.getNowPrice(stock.getStockCode()).toString()); |
| | | stockVO.setType(stock.getStockType()); |
| | | stockVO.setId(stock.getId().intValue()); |
| | | stockVO.setCode(stock.getStockCode()); |
| | | stockVO.setName(stock.getStockName()); |
| | | stockVO.setSpell(stock.getStockSpell()); |
| | | stockVO.setGid(stock.getStockGid().toUpperCase()); |
| | | Map map = Maps.newHashMap(); |
| | |
| | | /*股票日线-K线*/ |
| | | @Override |
| | | public Object getKData(String pid, String interval, String stockType) { |
| | | EStockType eStockType = null; |
| | | if(stockType.equals("US")){ |
| | | eStockType = EStockType.US; |
| | | }else{ |
| | | eStockType = EStockType.IN; |
| | | } |
| | | String string = HttpUtil.get(eStockType.stockUrl + "kline?pid=" + pid + "&interval=" + interval + "&key=" + eStockType.stockKey); |
| | | return string; |
| | | EStockType eStockType = EStockType.getEStockTypeByCode(stockType); |
| | | return HttpUtil.get(eStockType.stockUrl + "kline?pid=" + pid + "&interval=" + interval + "&key=" + eStockType.stockKey); |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (user == null) { |
| | | return ServerResponse.createByErrorMsg("Please log in"); |
| | | } |
| | | |
| | | return ServerResponse.createBySuccess(); |
| | | // List<Stock> stockList = stockMapper.findOptions(user.getId() + ""); |
| | | //// List<Stock> stockList = stockMapper.findOptions("485"); |
| | | // List<StockListVO> stockListVOS = Lists.newArrayList(); |
| | | // if (stockList.size() > 0) |
| | | // for (Stock stock : stockList) { |
| | | // StockListVO stockListVO = new StockListVO(); |
| | | // QueryWrapper<InStockBean> queryWrapper = new QueryWrapper<>(); |
| | | // queryWrapper.eq("id", stock.getStockCode()); |
| | | // InStockBean inStockBean = inStockMapper.selectOne(queryWrapper); |
| | | // if (inStockBean == null) { |
| | | // continue; |
| | | // } |
| | | // stockListVO.setNowPrice(inStockBean.getLast()); |
| | | // stockListVO.setToday_max(inStockBean.getHigh()); |
| | | // stockListVO.setToday_min(inStockBean.getLow()); |
| | | // stockListVO.setHcrate(BigDecimal.valueOf(Double.parseDouble(inStockBean.getChgPct()))); |
| | | // stockListVO.setBusiness_amount(inStockBean.getVolume()); |
| | | // stockListVO.setBusiness_balance(inStockBean.getAvgVolume()); |
| | | // stockListVO.setPreclose_px(inStockBean.getPrevClose()); |
| | | // stockListVO.setOpen_px(inStockBean.getOpen()); |
| | | // stockListVO.setName(stock.getStockName()); |
| | | // stockListVO.setCode(stock.getStockCode()); |
| | | // stockListVO.setSpell(stock.getStockSpell()); |
| | | // stockListVO.setGid(stock.getStockGid()); |
| | | // BigDecimal day3Rate = (BigDecimal) selectRateByDaysAndStockCode(stock.getStockCode(), 3).getData(); |
| | | // stockListVO.setDay3Rate(day3Rate); |
| | | // stockListVO.setStock_plate(stock.getStockPlate()); |
| | | // stockListVO.setStock_type(stock.getStockType()); |
| | | // stockListVOS.add(stockListVO); |
| | | // } |
| | | // PageInfo pageInfo = new PageInfo(stockList); |
| | | // pageInfo.setList(stockListVOS); |
| | | |
| | | } |
| | | |
| | | public ServerResponse<Stock> findStockByName(String name) { |