| | |
| | | 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"); |
| | |
| | | @Override |
| | | public ServerResponse getStockByType(int pageNum, int pageSize, String orderBy, String keyWords, String stockType, HttpServletRequest request) { |
| | | List<Stock> stockList = new ArrayList<>(); |
| | | if(stockType.equals(EStockType.IN.getCode())){ |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | stockList.addAll(stockMapper.findStockByType(orderBy,stockType,keyWords)); |
| | | }else{ |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | stockList.addAll(stockMapper.findStockTypeDz(orderBy,EStockType.IN.getCode(), keyWords)); |
| | | } |
| | | |
| | | |
| | | |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | stockList.addAll(stockMapper.findStockByType(orderBy,stockType,keyWords)); |
| | | List<StockListVO> stockListVOS = Lists.newArrayList(); |
| | | 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(),stockType).toString()); |
| | | } |
| | | RPageInfo pageInfo = new RPageInfo(); |
| | | pageInfo.setList(stockListVOS); |
| | |
| | | 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); |
| | | if(eStockType == EStockType.IN){ |
| | | return HttpUtil.get(eStockType.stockUrl+"api/all/getKData.do?pid="+pid+"&interval="+interval+"&stockType=in"); |
| | | } |
| | | 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); |