소스 검색

Merge remote-tracking branch 'origin/stock2coin' into stock2coin

qlm 4 년 전
부모
커밋
c7fc4d2539

+ 1 - 0
src/main/java/com/xc/pojo/IndexInfo.java

@@ -36,4 +36,5 @@ public class IndexInfo {
     private String transPmBegin; // 下午交易开始时间
     private String transPmEnd; // 下午交易结束时间
     private Integer siteLever;
+    private Integer spread;
 }

+ 1 - 1
src/main/java/com/xc/service/IUserPositionService.java

@@ -56,7 +56,7 @@ public interface IUserPositionService {
 
     ServerResponse revoke(Integer positionId, HttpServletRequest paramHttpServletRequest) throws Exception;
 
-    boolean fulfill(String code, BigDecimal buyOrderPrice);
+    boolean fulfill();
 
     ServerResponse stopProfitTarget(int id, BigDecimal targetprofit, BigDecimal stoploss, HttpServletRequest request);
 

+ 11 - 2
src/main/java/com/xc/service/impl/DbStockServiceImpl.java

@@ -65,7 +65,11 @@ public class DbStockServiceImpl implements DbStockService {
         StockVO stockVO = new StockVO();
         BeanUtils.copyProperties(stockDbVO, stockVO);
         String nowPrice =  stockVO.getNowPrice() == null ? "0" : stockVO.getNowPrice();
-        stockVO.setNowPrice(new BigDecimal(nowPrice).setScale(2,4).toString());
+        if(nowPrice.indexOf(".") < 3){
+            stockVO.setNowPrice(new BigDecimal(nowPrice).setScale(4,4).toString());
+        }else{
+            stockVO.setNowPrice(new BigDecimal(nowPrice).setScale(2,4).toString());
+        }
         return stockVO;
     }
 
@@ -76,10 +80,15 @@ public class DbStockServiceImpl implements DbStockService {
         StockListVO stockListVO = new StockListVO();
         BeanUtils.copyProperties(stockDbVO, stockListVO);
         String nowPrice =  stockListVO.getNowPrice() == null ? "0" : stockListVO.getNowPrice();
-        stockListVO.setNowPrice(new BigDecimal(nowPrice).setScale(2,4).toString());
+        if(nowPrice.indexOf(".") < 3){
+            stockListVO.setNowPrice(new BigDecimal(nowPrice).setScale(4,4).toString());
+        }else{
+            stockListVO.setNowPrice(new BigDecimal(nowPrice).setScale(2,4).toString());
+        }
         return stockListVO;
     }
 
 
+
 }
 

+ 26 - 17
src/main/java/com/xc/service/impl/UserPositionServiceImpl.java

@@ -50,22 +50,16 @@ public class UserPositionServiceImpl implements IUserPositionService {
     private static final Logger log = LoggerFactory.getLogger(UserPositionServiceImpl.class);
     @Resource
     IUserPositionService iUserPositionService;
-
     @Autowired
     UserPositionMapper userPositionMapper;
-
     @Autowired
     IUserService iUserService;
-
     @Autowired
     ISiteSettingService iSiteSettingService;
-
     @Autowired
     IStockService iStockService;
-
     @Autowired
     UserMapper userMapper;
-
     @Autowired
     UserCashDetailMapper userCashDetailMapper;
     @Autowired
@@ -82,28 +76,43 @@ public class UserPositionServiceImpl implements IUserPositionService {
 
     /**
      * 判断当前货币当前价格可成交挂单
-     * @param code 货币code
-     * @param buyOrderPrice 当前价格
      * @return
      */
     @Override
     @Transactional
-    public boolean fulfill(String code, BigDecimal buyOrderPrice){
-        Stock stock = (Stock)this.iStockService.findStockByCode(code).getData();
-        List<UserPosition> userPositions = this.userPositionMapper.listByCodeAndState(code,2,null);
+    public boolean fulfill(){
+        List<IndexInfo> indexInfoList = stockMapper.selectStockList();
+        Map<String, BigDecimal> indexMap = new HashMap<>();
+        Map<String, Integer> spreadMap = new HashMap<>();
+        BigDecimal nowPrice;
+        for (IndexInfo indexInfo : indexInfoList) {
+                try {
+                    //每支code获取现价
+                    StockListVO stockListVO = dbStockService.getStockListVO(indexInfo.getCode());
+                    nowPrice = new BigDecimal(stockListVO.getNowPrice());
+                    indexMap.put(indexInfo.getCnName(), nowPrice);
+                    spreadMap.put(indexInfo.getCnName() , indexInfo.getSpread());
+                } catch (Exception e) {
+                    // 数据库不存在
+                    log.info("数据库不存在");
+                }
+        }
+        List<UserPosition> userPositions = this.userPositionMapper.listByCodeAndState(null,2,null);
         log.info("挂单="+userPositions.size());
         for(UserPosition userPosition : userPositions){
+            nowPrice = indexMap.get(userPosition.getStockName());
+            BigDecimal spread = new BigDecimal(spreadMap.get(userPosition.getStockName()));
             if("做多".equals(userPosition.getOrderDirection())){
                 // 现价小于等于委托价
-                if (buyOrderPrice.compareTo(userPosition.getBuyOrderPrice()) < 1){
-                    buyOrderPrice = buyOrderPrice.add(stock.getSpread());
-                    toFulfill(userPosition, buyOrderPrice);
+                if (nowPrice.compareTo(userPosition.getBuyOrderPrice()) < 1){
+                    nowPrice = userPosition.getBuyOrderPrice().add(spread);
+                    toFulfill(userPosition, nowPrice);
                 }
             }else{
                 // 现价大于等于委托价
-                if (buyOrderPrice.compareTo(userPosition.getBuyOrderPrice()) > -1){
-                    buyOrderPrice = buyOrderPrice.subtract(stock.getSpread());
-                    toFulfill(userPosition, buyOrderPrice);
+                if (nowPrice.compareTo(userPosition.getBuyOrderPrice()) > -1){
+                    nowPrice = userPosition.getBuyOrderPrice().subtract(spread);
+                    toFulfill(userPosition, nowPrice);
                 }
             }
         }

+ 7 - 16
src/main/java/com/xc/utils/task/index/EntrustTask.java

@@ -65,22 +65,13 @@ public class EntrustTask {
     }
 
     private void doTask() {
-        List<IndexInfo> indexInfoList = stockMapper.selectStockList();
-        BigDecimal nowPrice;
-        for (IndexInfo indexInfo : indexInfoList) {
-            if (StringUtils.isNotEmpty(indexInfo.getDataDbName())) {
-                try {
-                    StockListVO stockListVO = dbStockService.getStockListVO(indexInfo.getCode());
-                    nowPrice = new BigDecimal(stockListVO.getNowPrice());
-                    BigDecimal finalNowPrice = nowPrice;
-                    ThreadUtil.executeInThread(obj -> {
-                        iUserPositionService.fulfill(indexInfo.getCode(), finalNowPrice);
-                    });
-                } catch (Exception e) {
-                    // 数据库不存在
-                    log.info("数据库不存在");
-                }
-            }
+        try {
+            ThreadUtil.executeInThread(obj -> {
+                iUserPositionService.fulfill();
+            });
+        } catch (Exception e) {
+            // 数据库不存在
+            log.info("数据库不存在");
         }
     }
 }

+ 2 - 1
src/main/java/mappers/StockMapper.xml

@@ -606,7 +606,8 @@
             transAmEnd transAmEnd,
             transPmBegin transPmBegin,
             transPmEnd transPmEnd,
-            site_lever siteLever
+            site_lever siteLever,
+            spread spread
         FROM stock
     </select>