| | |
| | | package com.nq.service.impl; |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.http.HttpUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.google.common.collect.Lists; |
| | | import com.google.common.collect.Maps; |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.JsonObject; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.config.StockPoll; |
| | | import com.nq.dao.*; |
| | |
| | | import com.nq.service.*; |
| | | import com.nq.utils.http.HttpClientRequest; |
| | | import com.nq.utils.PropertiesUtil; |
| | | import com.nq.utils.redis.RedisKeyUtil; |
| | | import com.nq.utils.redis.RedisShardedPoolUtils; |
| | | import com.nq.utils.stock.pinyin.GetPyByChinese; |
| | | import com.nq.utils.stock.qq.QqStockApi; |
| | |
| | | import java.net.URL; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.CompletableFuture; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import lombok.Data; |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | |
| | | @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))); |
| | | } |
| | | 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 getDateline(HttpServletResponse response, String code) { |
| | | if (StringUtils.isBlank(code)) |
| | | return ServerResponse.createByErrorMsg(""); |
| | | Stock stock = this.stockMapper.findStockByCode(code); |
| | | if (stock == null) |
| | | return ServerResponse.createByErrorMsg(""); |
| | | response.setHeader("Access-Control-Allow-Origin", "*"); |
| | | Date time = new Date(); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); |
| | | String end = sdf.format(time); |
| | | Calendar c = Calendar.getInstance(); |
| | | c.setTime(new Date()); |
| | | c.add(2, -3); |
| | | Date m = c.getTime(); |
| | | String mon = sdf.format(m); |
| | | String methodUrl = "http://q.stock.sohu.com/hisHq?code=cn_" + code + "+&start=" + mon + "&end=" + end + "&stat=1&order=D"; |
| | | HttpURLConnection connection = null; |
| | | BufferedReader reader = null; |
| | | String line = null; |
| | | EchartsDataVO echartsDataVO = new EchartsDataVO(); |
| | | try { |
| | | URL url = new URL(methodUrl); |
| | | connection = (HttpURLConnection) url.openConnection(); |
| | | connection.setRequestMethod("GET"); |
| | | connection.connect(); |
| | | if (connection.getResponseCode() == 200) { |
| | | reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "gbk")); |
| | | StringBuilder result = new StringBuilder(); |
| | | while ((line = reader.readLine()) != null) |
| | | result.append(line).append(System.getProperty("line.separator")); |
| | | JSONArray jsonArray = JSONArray.fromObject(result.toString()); |
| | | JSONObject json = jsonArray.getJSONObject(0); |
| | | JSONArray jsonArray1 = JSONArray.fromObject(json.get("hq")); |
| | | Collections.reverse((List<?>) jsonArray1); |
| | | double[][] values = (double[][]) null; |
| | | Object[][] volumes = (Object[][]) null; |
| | | String[] date = null; |
| | | values = new double[jsonArray1.size()][5]; |
| | | volumes = new Object[jsonArray1.size()][3]; |
| | | date = new String[jsonArray1.size()]; |
| | | for (int i = 0; i < jsonArray1.size(); i++) { |
| | | JSONArray js = JSONArray.fromObject(jsonArray1.get(i)); |
| | | date[i] = js.get(0).toString(); |
| | | values[i][0] = Double.valueOf(js.get(1).toString()).doubleValue(); |
| | | values[i][1] = Double.valueOf(js.get(2).toString()).doubleValue(); |
| | | values[i][2] = Double.valueOf(js.get(5).toString()).doubleValue(); |
| | | values[i][3] = Double.valueOf(js.get(6).toString()).doubleValue(); |
| | | values[i][4] = Double.valueOf(js.get(7).toString()).doubleValue(); |
| | | volumes[i][0] = Integer.valueOf(i); |
| | | volumes[i][1] = Double.valueOf(js.get(7).toString()); |
| | | volumes[i][2] = Integer.valueOf((Double.valueOf(js.get(3).toString()).doubleValue() > 0.0D) ? 1 : -1); |
| | | } |
| | | echartsDataVO.setDate(date); |
| | | echartsDataVO.setValues(values); |
| | | echartsDataVO.setVolumes(volumes); |
| | | echartsDataVO.setStockCode(stock.getStockCode()); |
| | | echartsDataVO.setStockName(stock.getStockName()); |
| | | ServerResponse.createBySuccess(echartsDataVO); |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | reader.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | connection.disconnect(); |
| | | } |
| | | return ServerResponse.createBySuccess(echartsDataVO); |
| | | @Override |
| | | public ServerResponse getDateline(HttpServletResponse paramHttpServletResponse, String paramString) { |
| | | return null; |
| | | } |
| | | |
| | | |
| | | public ServerResponse getSingleStock(String code, HttpServletRequest request) { |
| | | if (StringUtils.isBlank(code)) |
| | | return ServerResponse.createByErrorMsg(""); |
| | | Stock stock = stockMapper.findStockByCode(code); |
| | | DataStockBean cacheBaseStock = RedisKeyUtil.getCacheBaseStock(stock); |
| | | Integer depositAmt = 0; |
| | | String introduction = null; |
| | | StockVO stockVO = StockApi.assembleInStockVO(stock); |
| | |
| | | stockVO.setName(stock.getStockName()); |
| | | stockVO.setSpell(stock.getStockSpell()); |
| | | stockVO.setGid(stock.getStockGid().toUpperCase()); |
| | | Map<String, Object> newStock = iPriceServices.getNewStock(stock.getStockCode()); |
| | | stockVO.setHcrate(newStock.get("ChgPct").toString().replaceAll("%", "")); |
| | | stockVO.setToday_max(newStock.get("High").toString()); |
| | | stockVO.setToday_min(newStock.get("Low").toString()); |
| | | if(null != cacheBaseStock){ |
| | | stockVO.setOpen_px(cacheBaseStock.getOpen()); |
| | | stockVO.setPreclose_px(cacheBaseStock.getPrevClose()); |
| | | } |
| | | Map map = Maps.newHashMap(); |
| | | map.put("introduction", introduction); |
| | | map.put("stock", stockVO); |
| | | return ServerResponse.createBySuccess(map); |
| | | } |
| | | |
| | | public Map getSingleStock(String code) { |
| | | if (StringUtils.isBlank(code)) |
| | | return null; |
| | | Stock stock = stockMapper.findStockByCode(code); |
| | | DataStockBean cacheBaseStock = RedisKeyUtil.getCacheBaseStock(stock); |
| | | Integer depositAmt = 0; |
| | | String introduction = null; |
| | | 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()); |
| | | if(null != cacheBaseStock){ |
| | | stockVO.setOpen_px(cacheBaseStock.getOpen()); |
| | | stockVO.setPreclose_px(cacheBaseStock.getPrevClose()); |
| | | } |
| | | Map map = Maps.newHashMap(); |
| | | map.put("introduction", introduction); |
| | | map.put("stock", stockVO); |
| | | return map; |
| | | } |
| | | |
| | | |
| | |
| | | EchartsDataVO echartsDataVO = StockApi.assembleEchartsDataVO(minDataVO); |
| | | return ServerResponse.createBySuccess(echartsDataVO); |
| | | } |
| | | @lombok.Data |
| | | class kData { |
| | | long t; |
| | | String c; |
| | | String o; |
| | | String h; |
| | | String l; |
| | | String v; |
| | | String vo; |
| | | } |
| | | |
| | | /*股票日线-K线*/ |
| | | |
| | | /*股票日线-K线*/ |
| | | @Override |
| | | public Object getKData(String pid, String interval, String stockType) { |
| | | EStockType eStockType = EStockType.getEStockTypeByCode(stockType); |
| | | return HttpUtil.get(eStockType.stockUrl + "kline?pid=" + pid + "&interval=" + interval + "&key=" + eStockType.stockKey); |
| | | Object object = HttpUtil.get(eStockType.stockUrl + "kline?pid=" + pid + "&interval=" + interval + "&key=" + eStockType.stockKey); |
| | | Gson gson = new Gson(); |
| | | List<kData> dataList = gson.fromJson(object.toString(), new TypeToken<List<kData>>(){}.getType()); |
| | | |
| | | Stock stock = stockMapper.selectOne(new LambdaQueryWrapper<Stock>().eq(Stock::getStockCode, pid).eq(Stock::getStockType, "IN")); |
| | | BigDecimal nowPrice = iPriceServices.getNowPrice(stock.getStockCode()); |
| | | Map singleStock = getSingleStock(stock.getStockCode()); |
| | | StockVO stockVO = (StockVO)singleStock.get("stock"); |
| | | // 修改 List 中的最后一条数据 |
| | | kData lastData = dataList.get(dataList.size() - 1); |
| | | lastData.setC(nowPrice.toString()); |
| | | lastData.setO(stockVO.getOpen_px()); |
| | | lastData.setH(stockVO.getToday_max()); |
| | | lastData.setL(stockVO.getToday_min()); |
| | | return gson.toJson(dataList); |
| | | } |
| | | |
| | | @Override |
| | |
| | | return ServerResponse.createBySuccess(this.stockMapper.selectByPrimaryKey(stockId)); |
| | | } |
| | | |
| | | public ServerResponse<PageInfo> listByAdmin(Integer showState, Integer lockState, String code, String name, String stockPlate, String stockType, int pageNum, int pageSize, HttpServletRequest request) { |
| | | public ServerResponse<PageInfo> listByAdmin(String stockGid,Integer showState, Integer lockState, String code, String name, String stockPlate, String stockType, int pageNum, int pageSize, HttpServletRequest request) { |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | List<Stock> stockList = this.stockMapper.listByAdmin(showState, lockState, code, name, stockPlate, stockType); |
| | | List<Stock> stockList = this.stockMapper.listByAdmin(stockGid,showState, lockState, code, name, stockPlate, stockType); |
| | | List<StockAdminListVO> stockAdminListVOS = Lists.newArrayList(); |
| | | for (Stock stock : stockList) { |
| | | StockAdminListVO stockAdminListVO = assembleStockAdminListVO(stock); |