| | |
| | | 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.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 { |
| | |
| | | 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.setType(stock.getStockType()); |
| | | stockVO.setId(stock.getId().intValue()); |
| | |
| | | /*股票日线-K线*/ |
| | | @Override |
| | | public Object getKData(String pid, String interval, String stockType) { |
| | | EStockType eStockType = null; |
| | | if(stockType.equals("US")){ |
| | | eStockType = EStockType.US; |
| | | EStockType eStockType = EStockType.getEStockTypeByCode(stockType); |
| | | String string; |
| | | if(eStockType == EStockType.SZHB){ |
| | | |
| | | if(interval.equals("D")){ |
| | | interval = "1day"; |
| | | }else if(interval.equals("W")) { |
| | | interval = "1week"; |
| | | }else if(interval.equals("M")){ |
| | | interval = "1mon"; |
| | | }else{ |
| | | interval =interval+ "min"; |
| | | } |
| | | string = HttpUtil.get(eStockType.stockUrl + "market/history/kline?period="+interval+"&size=600&symbol="+pid); |
| | | |
| | | }else{ |
| | | eStockType = EStockType.IN; |
| | | string = HttpUtil.get(eStockType.stockUrl + "kline?pid=" + pid + "&interval=" + interval + "&key=" + eStockType.stockKey); |
| | | } |
| | | String string = HttpUtil.get(eStockType.stockUrl + "kline?pid=" + pid + "&interval=" + interval + "&key=" + eStockType.stockKey); |
| | | return string; |
| | | } |
| | | |