| | |
| | | package com.nq.service.impl; |
| | | |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.google.gson.Gson; |
| | | import com.nq.dao.StockDzMapper; |
| | | import com.nq.dao.StockMapper; |
| | | import com.nq.dao.StockSettingMapper; |
| | |
| | | import com.nq.service.IPriceServices; |
| | | import com.nq.service.IStockConfigServices; |
| | | import com.nq.utils.redis.RedisKeyUtil; |
| | | import com.nq.utils.timeutil.TimeUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | |
| | | @Service |
| | | public class PriceServicesImpl implements IPriceServices { |
| | |
| | | @Autowired |
| | | IStockConfigServices iStockConfigServices; |
| | | |
| | | @Resource |
| | | StockDzMapper stockDZMapper; |
| | | |
| | | @Override |
| | | public BigDecimal getNowPrice(String stockCode) { |
| | | Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code",stockCode)); |
| | | if(null == stock){ |
| | | return BigDecimal.ZERO; |
| | | } |
| | | StockSetting stockSetting = stockSettingMapper.selectOne(new QueryWrapper<StockSetting>().eq("stock_code",stockCode)); |
| | | if(stockSetting != null){ |
| | | if(TimeUtil.isTradingHour(stockSetting.getStartTime(),stockSetting.getEndTime())){ |
| | | Date newDate = new Date(); |
| | | DateTime startTime = DateUtil.parseDateTime(stockSetting.getStartTime()); |
| | | DateTime endTime = DateUtil.parseDateTime(stockSetting.getEndTime()); |
| | | if(newDate.after(startTime) && newDate.before(endTime)){ |
| | | // if(TimeUtil.isTradingHour(stockSetting.getStartTime(),stockSetting.getEndTime())){ |
| | | if(stockSetting.getType().equals("0")){ |
| | | return new BigDecimal(stockSetting.getPrice()); |
| | | }else{ |
| | | StockRealTimeBean stockRealTimeBean = RedisKeyUtil.getCacheRealTimeStock(stock); |
| | | return new BigDecimal(stockRealTimeBean.getLast()).multiply(new BigDecimal(stockSetting.getPrice())); |
| | | String s = RedisKeyUtil.doPost(stock.getStockCode(), stock.getStockType()); |
| | | if(null != s){ |
| | | Map<String, Object> stringObjectMap = jsonToMap(s); |
| | | return new BigDecimal(stringObjectMap.get("Last").toString()).multiply(new BigDecimal(stockSetting.getPrice())); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | StockRealTimeBean stockRealTimeBean = RedisKeyUtil.getCacheRealTimeStock(stock); |
| | | return new BigDecimal(stockRealTimeBean.getLast()); |
| | | String s = RedisKeyUtil.doPost(stock.getStockCode(), stock.getStockType()); |
| | | if(null != s) { |
| | | Map<String, Object> stringObjectMap = jsonToMap(s); |
| | | return new BigDecimal(stringObjectMap.get("Last").toString()); |
| | | } |
| | | return BigDecimal.ZERO; |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal getNowPrice(String stockCode, String stockType) { |
| | | BigDecimal nowPrice = getNowPrice(stockCode); |
| | | if (!stockType.equals("DZ")){ |
| | | return nowPrice; |
| | | } |
| | | QueryWrapper queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("stock_code",stockCode); |
| | | StockDz stockDz = stockDZMapper.selectOne(queryWrapper); |
| | | if(stockDz == null){ |
| | | return nowPrice;} |
| | | return nowPrice.multiply(stockDz.getDiscount()); |
| | | public Map<String, Object> getNewStock(String stockCode) { |
| | | Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code",stockCode)); |
| | | String s = RedisKeyUtil.doPost(stock.getStockCode(), stock.getStockType()); |
| | | if(null != s){ |
| | | Map<String, Object> stringObjectMap = jsonToMap(s); |
| | | return stringObjectMap; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | |
| | | public static Map<String, Object> jsonToMap(String json) { |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | try { |
| | | Object[] array = objectMapper.readValue(json, Object[].class); |
| | | if (array.length == 0) { |
| | | return Collections.emptyMap(); |
| | | } |
| | | Gson gson = new Gson(); |
| | | String s = gson.toJson(array[0]); |
| | | Map<String, Object> map = objectMapper.readValue(s, Map.class); |
| | | return map; |
| | | } catch (JsonProcessingException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public boolean isLimitUpBuy(String stockCode) { |
| | |
| | | return true; |
| | | } |
| | | |
| | | if(new BigDecimal(stockConfig.getCValue()).compareTo(pcp)<0){ |
| | | if(new BigDecimal(stockConfig.getCValue()).compareTo(pcp)<=0){ |
| | | StockConfig limitConfig = iStockConfigServices.queryByKey(EConfigKey.LIMIT_UP_IS_BUY.getCode()); |
| | | if(limitConfig.getCValue().equals("1")){ |
| | | return true; |
| | |
| | | if(stockConfig == null){ |
| | | return true; |
| | | } |
| | | |
| | | if(new BigDecimal(stockConfig.getCValue()).compareTo(pcp)<=0){ |
| | | if(pcp.compareTo(new BigDecimal(stockConfig.getCValue()))<=0){ |
| | | StockConfig limitConfig = iStockConfigServices.queryByKey(EConfigKey.LIMIT_DOWN_IS_SELL.getCode()); |
| | | if(limitConfig.getCValue().equals("1")){ |
| | | return true; |
| | | if(!limitConfig.getCValue().equals("1")){ |
| | | return false; |
| | | } |
| | | } |
| | | return false; |
| | | return true; |
| | | } |
| | | } |
| | | } |