liuchaojie 4 роки тому
батько
коміт
41328d7a13

+ 17 - 19
src/main/java/com/xc/controller/index/IndexApiController.java

@@ -6,7 +6,6 @@ import com.xc.common.ServerResponse;
 import com.xc.pojo.HistoryIndex;
 import com.xc.pojo.Quote;
 import com.xc.service.IndexApiService;
-import com.xc.utils.enumUtil.IndexEnum;
 import com.xc.vo.index.*;
 import net.sf.json.JSONObject;
 import org.slf4j.Logger;
@@ -19,7 +18,6 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 
 /**
@@ -65,7 +63,7 @@ public class IndexApiController {
                              @RequestParam String resolution,
                              @RequestParam Long from,
                              @RequestParam Long to) {
-        HistoryIndex historyIndex = indexApiService.getHistoryNew(symbol, resolution, from, to);
+        HistoryIndex historyIndex = indexApiService.getHistoryNew(symbol.toLowerCase(), resolution, from, to);
         return historyIndex;
     }
 
@@ -87,22 +85,22 @@ public class IndexApiController {
     }
 
 
-    @RequestMapping({"getSearch.do"})
-    @ResponseBody
-    public Object getSearch(@RequestParam String query,
-                            @RequestParam String exchange,
-                            @RequestParam String type,
-                            @RequestParam Long limit) {
-
-        List<SymbolVo> symbolVos = new ArrayList<>();
-        SymbolVo symbolVo = new SymbolVo();
-        symbolVo.setSymbol(IndexEnum.getDbNameByCode(query));
-        symbolVo.setFull_name(String.format("NYSE:%s", IndexEnum.getDbNameByCode(query)));
-        symbolVo.setExchange("NYSE");
-        symbolVo.setTicker("");
-        symbolVos.add(symbolVo);
-        return symbolVos;
-    }
+//    @RequestMapping({"getSearch.do"})
+//    @ResponseBody
+//    public Object getSearch(@RequestParam String query,
+//                            @RequestParam String exchange,
+//                            @RequestParam String type,
+//                            @RequestParam Long limit) {
+//
+//        List<SymbolVo> symbolVos = new ArrayList<>();
+//        SymbolVo symbolVo = new SymbolVo();
+//        symbolVo.setSymbol(IndexEnum.getDbNameByCode(query));
+//        symbolVo.setFull_name(String.format("NYSE:%s", IndexEnum.getDbNameByCode(query)));
+//        symbolVo.setExchange("NYSE");
+//        symbolVo.setTicker("");
+//        symbolVos.add(symbolVo);
+//        return symbolVos;
+//    }
 
 
     @RequestMapping({"getMarks.do"})

+ 1 - 1
src/main/java/com/xc/dao/UserPositionMapper.java

@@ -51,7 +51,7 @@ public interface UserPositionMapper {
 
   List findPositionAmt(@Param("userId")Integer userId,@Param("stockCode")String stockCode);
 
-  List listByCodeAndState(@Param("stockCode") String stockCode, @Param("state") Integer state,@Param("userId") Integer userId);
+  List<UserPosition> listByCodeAndState(@Param("stockCode") String stockCode, @Param("state") Integer state,@Param("userId") Integer userId);
 
   void updateStopProfitTarget(@Param("id")int id, @Param("targetprofit") BigDecimal targetprofit, @Param("stoploss") BigDecimal stoploss);
 

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

@@ -61,7 +61,7 @@ public interface IUserPositionService {
     ServerResponse stopProfitTarget(int id, BigDecimal targetprofit, BigDecimal stoploss, HttpServletRequest request);
 
     ServerResponse closeOut(int id, Integer orderNum) throws Exception;
-	
+
     ServerResponse closeOutList(List<Integer> list) throws Exception;
 
     ServerResponse oneKeyCloseOut(HttpServletRequest request);
@@ -70,9 +70,9 @@ public interface IUserPositionService {
 
     void toStopProfitTarget() throws Exception;
 
-    StockIndexDF getStockIndexDFByDbName(String dbName);
+//    StockIndexDF getStockIndexDFByDbName(String dbName);
 
-    String getNowPriceStrByDbName(String dbName);
+//    String getNowPriceStrByDbName(String dbName);
 
     Integer getTodayOrderNum(String stockName);
 }

+ 2 - 2
src/main/java/com/xc/service/IndexApiService.java

@@ -37,7 +37,7 @@ public interface IndexApiService {
      * @param time
      * @return
      */
-    RealTimeIndex getRealTimeData(String indexCode, Date time);
+//    RealTimeIndex getRealTimeData(String indexCode, Date time);
 
     /**
      * 根据货币类型和时间查找数据
@@ -46,7 +46,7 @@ public interface IndexApiService {
      * @param time
      * @return
      */
-    List<RealTimeIndex> getHistData(String indexCode, Date time);
+//    List<RealTimeIndex> getHistData(String indexCode, Date time);
 
 
     /**

+ 52 - 114
src/main/java/com/xc/service/impl/IndexApiServiceImpl.java

@@ -3,16 +3,13 @@ package com.xc.service.impl;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.xc.dao.IndexApiMapper;
+import com.xc.dao2.KLinkStockMapper;
 import com.xc.pojo.HistoryIndex;
 import com.xc.pojo.Quote;
-import com.xc.pojo.RealTimeIndex;
+import com.xc.vo2.HistoryVo;
 import com.xc.pub.redismessage.util.RedisUtil;
 import com.xc.service.IndexApiService;
-import com.xc.utils.IndexDbCreatedUtil;
-import com.xc.utils.enumUtil.IndexEnum;
 import com.xc.utils.enumUtil.ResolutionEnum;
-import com.xc.utils.stock.BuyAndSellUtils;
-import com.xc.vo.index.HistoryVo;
 import com.xc.vo.index.IndexConfigVo;
 import com.xc.vo.index.SymbolInfoVo;
 import com.xc.vo.index.SymbolVo;
@@ -39,6 +36,9 @@ public class IndexApiServiceImpl implements IndexApiService {
     @Autowired
     private RedisUtil redisUtil;
 
+    @Autowired
+    private KLinkStockMapper kLinkStockMapper;
+
     @Override
     public IndexConfigVo getConfig() {
         IndexConfigVo indexConfigVo = new IndexConfigVo();
@@ -68,25 +68,12 @@ public class IndexApiServiceImpl implements IndexApiService {
     @Override
     public SymbolInfoVo getSymbolInfo() {
         SymbolInfoVo symbolInfoVo = new SymbolInfoVo();
-        symbolInfoVo.setSymbol(IndexEnum.getNameList(2));
-        symbolInfoVo.setDescription(IndexEnum.getNameList(2));
         symbolInfoVo.setExchange_listed("NYSE");
         symbolInfoVo.setExchange_traded("NYSE");
         symbolInfoVo.setMinmov(1);
         symbolInfoVo.setMinmov2(0);
-
-//        symbolInfoVo.setHas_seconds(true);
         symbolInfoVo.setHas_intraday(true);
-
-//        symbolInfoVo.setIntraday_multipliers(Arrays.asList(new String[]{"5"}));
-        symbolInfoVo.setIntraday_multipliers(Arrays.asList(new String[]{"1", "5", "15", "30", "60", "240", "1D", "1W", "1M", "6M", "12M"}));
-//        symbolInfoVo.setIntraday_multipliers(Arrays.asList(new String[]{"5", "15", "30"}));
-
-//        List<String> list = new ArrayList<>();
-//        list.add("1");
-//        symbolInfoVo.setSeconds_multipliers(list);
-        symbolInfoVo.setType(IndexEnum.getNameList(3));
-        symbolInfoVo.setTicker(IndexEnum.getNameList(1));
+        symbolInfoVo.setIntraday_multipliers(Arrays.asList("1", "5", "15", "30", "60", "240", "1D", "1W", "1M", "6M", "12M"));
         symbolInfoVo.setTimezone("Asia/Shanghai");
         symbolInfoVo.setSession_regular("0900-1600");
         return symbolInfoVo;
@@ -95,8 +82,8 @@ public class IndexApiServiceImpl implements IndexApiService {
     @Override
     public SymbolVo getSymbols(String symbol) {
         SymbolVo symbolVo = new SymbolVo();
-        symbolVo.setSymbol(IndexEnum.getEnumList(symbol).getEnName());
-        symbolVo.setDescription(IndexEnum.getEnumList(symbol).getEnName());
+        symbolVo.setSymbol(symbol);
+        symbolVo.setDescription(symbol);
         symbolVo.setExchange_listed("NYSE");
         symbolVo.setExchange_traded("NYSE");
         symbolVo.setMinmov(1);
@@ -104,18 +91,11 @@ public class IndexApiServiceImpl implements IndexApiService {
         symbolVo.setPricescale(100);
         symbolVo.setPointvalue(1);
         symbolVo.setHas_intraday(true);
-
-//        symbolVo.setIntraday_multipliers(Arrays.asList(new String[]{"5", "15", "30", "1H", "4H", "1D", "1W", "1M", "6M", "12M"}));
-        symbolVo.setIntraday_multipliers(Arrays.asList(new String[]{"1", "5", "15", "30", "60"}));
-//        symbolVo.setIntraday_multipliers(Arrays.asList(new String[]{"5", "15", "30"}));
-
-//        symbolVo.setHas_seconds(true);
-//        symbolVo.setSeconds_multipliers(Arrays.asList(new String[]{"10"}));
-
+        symbolVo.setIntraday_multipliers(Arrays.asList("1", "5", "15", "30", "60"));
         symbolVo.setHas_daily(true);
         symbolVo.setHas_weekly_and_monthly(true);
-        symbolVo.setType(IndexEnum.getEnumList(symbol).getType());
-        symbolVo.setTicker(String.valueOf(IndexEnum.getEnumList(symbol).getCode()));
+        symbolVo.setType(symbol);
+        symbolVo.setTicker(symbol);
         symbolVo.setTimezone("Asia/Shanghai");
         symbolVo.setSession_regular("0900-1600");
         symbolVo.setSupported_resolutions(ResolutionEnum.getNameList());
@@ -123,17 +103,17 @@ public class IndexApiServiceImpl implements IndexApiService {
         return symbolVo;
     }
 
-    @Override
-    public RealTimeIndex getRealTimeData(String indexCode, Date time) {
-        String dbTableName = IndexDbCreatedUtil.createdDbTableName(indexCode, time);
-        return indexApiMapper.getRealTimeData(dbTableName);
-    }
-
-    @Override
-    public List<RealTimeIndex> getHistData(String indexCode, Date time) {
-        String dbTableName = IndexDbCreatedUtil.createdHistDbTableName(indexCode);
-        return indexApiMapper.getHistData(dbTableName, time);
-    }
+//    @Override
+//    public RealTimeIndex getRealTimeData(String indexCode, Date time) {
+//        String dbTableName = IndexDbCreatedUtil.createdDbTableName(indexCode, time);
+//        return indexApiMapper.getRealTimeData(dbTableName);
+//    }
+//
+//    @Override
+//    public List<RealTimeIndex> getHistData(String indexCode, Date time) {
+//        String dbTableName = IndexDbCreatedUtil.createdHistDbTableName(indexCode);
+//        return indexApiMapper.getHistData(dbTableName, time);
+//    }
 
     @Override
     public List<Quote> getQuotes(String symbols) {
@@ -192,13 +172,8 @@ public class IndexApiServiceImpl implements IndexApiService {
 
     private void getDate(String symbol, String resolution, Long from, Long to, List<HistoryVo> historyVoList, List<HistoryVo> historyVoDays){
         if(isIntraday(resolution)){
-//            int minuteFrom = getMinute(new Date(from * 1000));
             int minuteTo = getMinute(new Date(to * 1000));
             int resolutionInt = Integer.valueOf(resolution);
-//            if(0 != minuteFrom%resolutionInt) {
-//                // 当前时间 + 还差多少时间到整点
-//                from = getDate(from * 1000, 1) - (minuteFrom%resolutionInt * 60);
-//            }
             if(0 != minuteTo%resolutionInt){
                 to = getDate(to * 1000, 1) + ((resolutionInt - minuteTo%resolutionInt) * 60);
             }
@@ -207,7 +182,7 @@ public class IndexApiServiceImpl implements IndexApiService {
         Integer fromX = Integer.valueOf(sdf.format(from));
         Integer newX = Integer.valueOf(sdf.format(new Date()));
         String dbTableName;
-        String redisKey = String.format("data_division_%s_%s", IndexEnum.getDbNameByCode(symbol), resolution);
+        String redisKey = String.format("data_division_%s_%s", symbol, resolution);
 //        String redisData = redisUtil.getItem(redisKey);
         String redisData = null;
         if (StringUtils.isNotEmpty(redisData) && !("[]".equals(redisData))) {
@@ -215,7 +190,7 @@ public class IndexApiServiceImpl implements IndexApiService {
             List<HistoryVo> historyVoRedis = JSONArray.parseArray(redisData, HistoryVo.class);
             if (!CollectionUtils.isEmpty(historyVoRedis)) {
                 // redis里面肯定没有最新的数据 所以还需要去数据库取
-                Collections.sort(historyVoRedis); // 按时间倒序排序
+//                Collections.sort(historyVoRedis); // 按时间倒序排序
                 // 取第一条 判断时间是否在请求from的时间之前 如果在时间之后表示redis中的数据不覆盖实际需要的数据
                 Long startTime = historyVoRedis.get(0).getTime();
                 Long entTime = historyVoRedis.get(historyVoRedis.size() - 1).getTime();
@@ -223,11 +198,11 @@ public class IndexApiServiceImpl implements IndexApiService {
                     // 表示只包含开始的 没有包含结束的 所以要去取后面的数据
                     Long realTime = historyVoRedis.get(historyVoRedis.size() - 1).getTime();
                     if(isIntraday(resolution)) {
-                        dbTableName = String.format("data_rt_%s_%s", IndexEnum.getDbNameByCode(symbol), newX);
-                        historyVoRedis.addAll(indexApiMapper.getDataByRt(dbTableName, realTime, to, resolution));
+                        dbTableName = String.format("data_rt_%s", symbol);
+                        historyVoRedis.addAll(kLinkStockMapper.getDataByRt(dbTableName, realTime, to, resolution));
                     }else{
-                        dbTableName = String.format("data_hist_%s", IndexEnum.getDbNameByCode(symbol));
-                        historyVoRedis.addAll(indexApiMapper.getDataByHist(dbTableName, realTime, to, resolution));
+                        dbTableName = String.format("data_hist_%s", symbol);
+                        historyVoRedis.addAll(kLinkStockMapper.getDataByHist(dbTableName, realTime, to, resolution));
                     }
                 } else if(from < startTime && to > entTime){
                     // 全部不包含
@@ -235,11 +210,11 @@ public class IndexApiServiceImpl implements IndexApiService {
                         // 表示在同一年
                         if (fromX >= 2020) {
                             if(isIntraday(resolution)) {
-                                dbTableName = String.format("data_rt_%s_%s", IndexEnum.getDbNameByCode(symbol), fromX);
-                                historyVoRedis.addAll(indexApiMapper.getDataByRt(dbTableName, from, to, resolution));
+                                dbTableName = String.format("data_rt_%s", symbol);
+                                historyVoRedis.addAll(kLinkStockMapper.getDataByRt(dbTableName, from, to, resolution));
                             }else{
-                                dbTableName = String.format("data_hist_%s", IndexEnum.getDbNameByCode(symbol));
-                                historyVoRedis.addAll(indexApiMapper.getDataByHist(dbTableName, from, to, resolution));
+                                dbTableName = String.format("data_hist_%s", symbol);
+                                historyVoRedis.addAll(kLinkStockMapper.getDataByHist(dbTableName, from, to, resolution));
                             }
                         }
                     } else {
@@ -247,13 +222,13 @@ public class IndexApiServiceImpl implements IndexApiService {
                         if(isIntraday(resolution)) {
                             for (int i = fromX; i <= newX; i++) {
                                 if (i >= 2020) {
-                                    dbTableName = String.format("data_rt_%s_%s", IndexEnum.getDbNameByCode(symbol), i);
-                                    historyVoRedis.addAll(indexApiMapper.getDataByRt(dbTableName, from, to, resolution));
+                                    dbTableName = String.format("data_rt_%s",symbol);
+                                    historyVoRedis.addAll(kLinkStockMapper.getDataByRt(dbTableName, from, to, resolution));
                                 }
                             }
                         }else{
-                            dbTableName = String.format("data_hist_%s", IndexEnum.getDbNameByCode(symbol));
-                            historyVoRedis.addAll(indexApiMapper.getDataByHist(dbTableName, from, to, resolution));
+                            dbTableName = String.format("data_hist_%s", symbol);
+                            historyVoRedis.addAll(kLinkStockMapper.getDataByHist(dbTableName, from, to, resolution));
                         }
                     }
                 }
@@ -266,7 +241,7 @@ public class IndexApiServiceImpl implements IndexApiService {
                     historyVoList.add(historyVo);
                 }
             }
-            Collections.sort(historyVoList); // 按时间倒序排序
+//            Collections.sort(historyVoList); // 按时间倒序排序
 //            redisUtil.deleteItem(redisKey);
             redisUtil.saveItem(redisKey, JSON.toJSONString(historyVoRedis), 5400, TimeUnit.SECONDS);
         }
@@ -276,34 +251,34 @@ public class IndexApiServiceImpl implements IndexApiService {
                 if (fromX.equals(newX)) {
                     // 表示在同一年
                     if (fromX >= 2020) {
-                        dbTableName = String.format("data_rt_%s_%s", IndexEnum.getDbNameByCode(symbol), fromX);
-                        historyVoList.addAll(indexApiMapper.getDataByRt(dbTableName, from, to, resolution));
+                        dbTableName = String.format("data_rt_%s", symbol);
+                        historyVoList.addAll(kLinkStockMapper.getDataByRt(dbTableName, from, to, resolution));
                     }
                 } else {
                     // 将跨度内的都取出来
                     for (int i = fromX; i <= newX; i++) {
                         if (i >= 2020) {
-                            dbTableName = String.format("data_rt_%s_%s", IndexEnum.getDbNameByCode(symbol), i);
-                            historyVoList.addAll(indexApiMapper.getDataByRt(dbTableName, from, to, resolution));
+                            dbTableName = String.format("data_rt_%s", symbol);
+                            historyVoList.addAll(kLinkStockMapper.getDataByRt(dbTableName, from, to, resolution));
                         }
                     }
                 }
             } else {
-                dbTableName = String.format("data_hist_%s", IndexEnum.getDbNameByCode(symbol));
-                historyVoList.addAll(indexApiMapper.getDataByHist(dbTableName, from, to, resolution));
+                dbTableName = String.format("data_hist_%s", symbol);
+                historyVoList.addAll(kLinkStockMapper.getDataByHist(dbTableName, from, to, resolution));
             }
         }
         historyVoList = remove(historyVoList);
-        Collections.sort(historyVoList); // 按时间倒序排序
+//        Collections.sort(historyVoList); // 按时间倒序排序
 //        redisUtil.deleteItem(redisKey);
         redisUtil.saveItem(redisKey, JSON.toJSONString(historyVoList), 5400, TimeUnit.SECONDS);
         // 日表中取最后一天的数据 最后一天的数据历史表中要到第二天才有 所以取实时表的数据
         if(!CollectionUtils.isEmpty(historyVoList) || getDate(new Date().getTime() / 1000, 0, resolution).equals(getDate(new Date().getTime() / 1000, 0, resolution))) {
             if (resolution.equals("1D")) {
                 if (newX >= 2020) {
-                    dbTableName = String.format("data_rt_%s_%s", IndexEnum.getDbNameByCode(symbol), newX);
+                    dbTableName = String.format("data_rt_%s", symbol);
                     String time = getDate(new Date().getTime() / 1000, 0, resolution);
-                    historyVoDays.addAll(indexApiMapper.getHistoryNew(dbTableName, Long.valueOf(time), Long.valueOf(getDate(to, 1, resolution))));
+                    historyVoDays.addAll(kLinkStockMapper.getHistoryNew(dbTableName, Long.valueOf(time), Long.valueOf(getDate(to, 1, resolution))));
                 }
             }
         }
@@ -311,49 +286,13 @@ public class IndexApiServiceImpl implements IndexApiService {
 
     @Override
     public HistoryIndex getHistoryNew(String symbol, String resolution, Long from, Long to) {
-//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
-//        Integer fromX = Integer.valueOf(sdf.format(from));
-//        Integer newX = Integer.valueOf(sdf.format(new Date()));
-//        String dbTableName;
+        if(from > to){
+            to = new Date().getTime() / 1000;
+        }
         List<HistoryVo> historyVoList = new ArrayList<>();
-        List<HistoryVo> historyVoDays = new ArrayList<>();;
+        List<HistoryVo> historyVoDays = new ArrayList<>();
         getDate(symbol, resolution, from, to, historyVoList, historyVoDays);
-        Collections.sort(historyVoList); // 按时间倒序排序
-//        if (isIntraday(resolution)) {
-//            if (fromX.equals(newX)) {
-//                // 表示在同一年
-//                if (fromX >= 2020) {
-//                    dbTableName = String.format("data_rt_%s_%s", IndexEnum.getDbNameByCode(symbol), fromX);
-//                    historyVoList = indexApiMapper.getDataByRt(dbTableName, from, to, resolution);
-//                }
-//            } else {
-//                // 将跨度内的都取出来
-//                historyVoList = new ArrayList<>();
-//                for (int i = fromX; i <= newX; i++) {
-//                    if (i >= 2020) {
-//                        dbTableName = String.format("data_rt_%s_%s", IndexEnum.getDbNameByCode(symbol), i);
-//                        historyVoList.addAll(indexApiMapper.getDataByRt(dbTableName, from, to, resolution));
-//                    }
-//                }
-//            }
-//        } else {
-//            dbTableName = String.format("data_hist_%s", IndexEnum.getDbNameByCode(symbol));
-//            if("1Y".equals(resolution) || "1M".equals(resolution) || "M".equals(resolution)){
-//                historyVoList = indexApiMapper.getDataByHist(dbTableName, from, to, resolution);
-//            }else {
-//                historyVoList = indexApiMapper.getDataByHist(dbTableName, from, to, resolution);
-//            }
-//            // 日表中取最后一天的数据 最后一天的数据历史表中要到第二天才有 所以取实时表的数据
-//            if (resolution.equals("1D") && !BuyAndSellUtils.belongCalendar(historyVoList.get(historyVoList.size() - 1).getRealTime(), from, to)) {
-//                if (newX >= 2020) {
-//                    dbTableName = String.format("data_rt_%s_%s", IndexEnum.getDbNameByCode(symbol), newX);
-//                    String time = getDate(historyVoList.get(historyVoList.size() - 1).getRealTime(), 1, resolution);
-//                    historyVoDays = indexApiMapper.getHistoryNew(dbTableName, Long.valueOf(time), Long.valueOf(getDate(to, 1, resolution)));
-//                } else {
-//                    historyVoDays = new ArrayList<>();
-//                }
-//            }
-//        }
+//        Collections.sort(historyVoList); // 按时间倒序排序
         HistoryIndex historyIndex = new HistoryIndex();
         if (CollectionUtils.isEmpty(historyVoList) && CollectionUtils.isEmpty(historyVoDays)) {
             historyIndex.setS("no_data");
@@ -361,8 +300,7 @@ public class IndexApiServiceImpl implements IndexApiService {
             Calendar cal = Calendar.getInstance();
             cal.setTime(new Date(from * 1000));
             int year = cal.get(Calendar.YEAR);
-            if (!isIntraday(resolution) && ((symbol.equals(IndexEnum.CHA50CFD.getCode()) && 2016 < year)
-                    || !symbol.equals(IndexEnum.CHA50CFD.getCode()) && 1990 < year)) {
+            if (!isIntraday(resolution)&& 1990 < year) {
                 historyIndex.setNextTime(System.currentTimeMillis() / 1000);
             } else if (isIntraday(resolution)) {
                 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

+ 5 - 50
src/main/java/com/xc/service/impl/StockMarketsDayServiceImpl.java

@@ -1,40 +1,21 @@
 package com.xc.service.impl;
 
-
 import com.xc.dao.StockMapper;
 import com.xc.dao.StockMarketsDayMapper;
-
 import com.xc.pojo.Stock;
-
-import com.xc.pojo.StockIndexDF;
 import com.xc.pojo.StockMarketsDay;
-
+import com.xc.service.DbStockService;
 import com.xc.service.IStockMarketsDayService;
-
 import com.xc.service.IStockService;
-
-
 import com.xc.service.IUserPositionService;
 import com.xc.utils.DateTimeUtil;
-
-import com.xc.utils.IndexDbCreatedUtil;
-import com.xc.utils.stock.sina.SinaStockApi;
-
 import com.xc.vo.stock.StockListVO;
-
 import java.math.BigDecimal;
-
-import java.util.Calendar;
 import java.util.Date;
-
 import java.util.List;
-
 import org.slf4j.Logger;
-
 import org.slf4j.LoggerFactory;
-
 import org.springframework.beans.factory.annotation.Autowired;
-
 import org.springframework.stereotype.Service;
 
 @Service("iStockMarketsDayService")
@@ -54,63 +35,37 @@ public class StockMarketsDayServiceImpl implements IStockMarketsDayService {
     @Autowired
     private IUserPositionService userPositionService;
 
+    @Autowired
+    DbStockService dbStockService;
+
     public void saveStockMarketDay() {
         log.info("【保存货币日内行情 定时任务】 开始保存 ... ");
-
         List<Stock> stockList = this.iStockService.findStockList();
-
         for (Stock stock : stockList) {
-            StockIndexDF stockIndexDF = userPositionService.getStockIndexDFByDbName(stock.getDataDbName());
-            StockListVO stockListVO = SinaStockApi.assembleStockListVO(stockIndexDF);
-
+            StockListVO stockListVO = dbStockService.getStockListVO(stock.getStockGid());
             Date nowDate = new Date();
-
             String ymd_date = DateTimeUtil.dateToStr(nowDate, "yyyy-MM-dd");
-
             String hm_date = DateTimeUtil.dateToStr(nowDate, "HH:mm");
-
-
             StockMarketsDay stockMarketsDay = new StockMarketsDay();
-
             stockMarketsDay.setStockId(stock.getId());
-
             stockMarketsDay.setStockName(stock.getStockName());
-
             stockMarketsDay.setStockCode(stock.getStockCode());
-
             stockMarketsDay.setStockGid(stock.getStockGid());
-
             stockMarketsDay.setYmd(ymd_date);
-
             stockMarketsDay.setHms(hm_date);
-
             stockMarketsDay.setNowPrice(new BigDecimal(stockListVO.getNowPrice()));
-
             stockMarketsDay.setCreaseRate(new BigDecimal(stockListVO.getHcrate().toString()));
-
             stockMarketsDay.setOpenPx(stockListVO.getOpen_px());
-
             stockMarketsDay.setClosePx(stockListVO.getPreclose_px());
-
             stockMarketsDay.setBusinessBalance(stockListVO.getBusiness_balance());
-
             stockMarketsDay.setBusinessAmount(stockListVO.getBusiness_amount());
-
             stockMarketsDay.setAddTime(nowDate);
-
             stockMarketsDay.setAddTimeStr(DateTimeUtil.dateToStr(nowDate));
-
-
             int insertCount = this.stockMarketsDayMapper.insert(stockMarketsDay);
-
             if (insertCount > 0) {
-
                 continue;
-
             }
-
             log.error("保存货币 {} 失败, 时间 = {}", stock.getStockName(), ymd_date);
-
         }
 
     }

+ 3 - 8
src/main/java/com/xc/service/impl/StockServiceImpl.java

@@ -14,9 +14,7 @@ import com.xc.service.IStockMarketsDayService;
 import com.xc.service.IStockService;
 import com.xc.service.IUserPositionService;
 import com.xc.utils.HttpClientRequest;
-import com.xc.utils.IndexDbCreatedUtil;
 import com.xc.utils.PropertiesUtil;
-import com.xc.utils.enumUtil.IndexEnum;
 import com.xc.utils.stock.BuyAndSellUtils;
 import com.xc.utils.stock.pinyin.GetPyByChinese;
 import com.xc.utils.stock.sina.SinaStockApi;
@@ -341,10 +339,7 @@ public class StockServiceImpl implements IStockService {
         stockAdminListVO.setIsLock(stock.getIsLock());
         stockAdminListVO.setIsShow(stock.getIsShow());
         stockAdminListVO.setAddTime(stock.getAddTime());
-
-        StockIndexDF stockIndexDF = userPositionService.getStockIndexDFByDbName(stock.getDataDbName());
-        StockListVO stockListVO = SinaStockApi.assembleStockListVO(stockIndexDF);
-//        StockListVO stockListVO = SinaStockApi.assembleStockListVO(SinaStockApi.getSinaStock(stock.getStockGid()));
+        StockListVO stockListVO = dbStockService.getStockListVO(stock.getStockGid());
         stockAdminListVO.setNowPrice(stockListVO.getNowPrice());
         stockAdminListVO.setHcrate(stockListVO.getHcrate());
         ServerResponse serverResponse = selectRateByDaysAndStockCode(stock.getStockCode(), 3);
@@ -475,8 +470,8 @@ public class StockServiceImpl implements IStockService {
             BeanUtils.copyProperties(indexInfo, indexInfoVo);
             if (StringUtils.isNotEmpty(indexInfo.getDataDbName())) {
                 try {
-                    String nowPriceStr = userPositionService.getNowPriceStrByDbName(indexInfo.getDataDbName());
-                    nowPrice = BigDecimal.valueOf(Double.valueOf(nowPriceStr));
+                    StockListVO stockListVO = dbStockService.getStockListVO(indexInfo.getCode());
+                    nowPrice = new BigDecimal(stockListVO.getNowPrice());
                 } catch (Exception e) {
                     // 数据库不存在
                     log.info("数据库不存在");

+ 75 - 310
src/main/java/com/xc/service/impl/UserPositionServiceImpl.java

@@ -1,6 +1,5 @@
 package com.xc.service.impl;
 
-import com.qiniu.util.Json;
 import com.xc.dao.*;
 import com.xc.pojo.*;
 import com.xc.service.*;
@@ -10,7 +9,6 @@ import com.google.common.collect.Lists;
 import com.xc.common.ServerResponse;
 import com.xc.service.*;
 import com.xc.utils.DateTimeUtil;
-import com.xc.utils.IndexDbCreatedUtil;
 import com.xc.utils.KeyUtils;
 import com.xc.utils.stock.BuyAndSellUtils;
 import com.xc.utils.stock.GeneratePosition;
@@ -109,19 +107,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
                 }
             }
         }
-//        userPositions.stream().forEach(userPosition -> {
-//            if("做多".equals(userPosition.getOrderDirection())){
-//                // 现价大于等于委托价
-//                if (buyOrderPrice.compareTo(userPosition.getBuyOrderPrice()) > -1){
-//                    toFulfill(userPosition, buyOrderPrice);
-//                }
-//            }else{
-//                // 现价小于或者等于委托价
-//                if (buyOrderPrice.compareTo(userPosition.getBuyOrderPrice()) < 1){
-//                    toFulfill(userPosition, buyOrderPrice);
-//                }
-//            }
-//        });
         return true;
     }
 
@@ -367,8 +352,9 @@ public class UserPositionServiceImpl implements IUserPositionService {
         for (IndexInfo indexInfo : indexInfoList) {
             if (StringUtils.isNotEmpty(indexInfo.getDataDbName())) {
                 try {
-                    String nowPriceStr = getNowPriceStrByDbName(indexInfo.getDataDbName());
-                    nowPrice = BigDecimal.valueOf(Double.valueOf(nowPriceStr));
+                    //每支code获取现价
+                    StockListVO stockListVO = dbStockService.getStockListVO(indexInfo.getCode());
+                    nowPrice = new BigDecimal(stockListVO.getNowPrice());
                     indexMap.put(indexInfo.getCnName(), nowPrice);
                 } catch (Exception e) {
                     // 数据库不存在
@@ -382,25 +368,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
         if(judgeIsCloseOut(userPosition, nowPrice)){
             closeOut(userPosition.getId(), null);
         }
-//        if("做多".equals(userPosition.getOrderDirection())){
-//            if(nowPrice.compareTo(userPosition.getTargetprofit()) > -1){
-//                //  当前价格 大于等于 止盈价格 进行平仓操作
-//                closeOut(userPosition.getId());
-//            }
-//            else if(nowPrice.compareTo(userPosition.getStoploss()) < 1){
-//                // 当前价格 小于等于 止损价格 进行平仓操作
-//                closeOut(userPosition.getId());
-//            }
-//        }else{
-//            if(nowPrice.compareTo(userPosition.getStoploss()) > -1){
-//                // 当前价格 大于等于 止损价格 进行平仓操作
-//                closeOut(userPosition.getId());
-//            }
-//            else if(nowPrice.compareTo(userPosition.getTargetprofit()) < 1){
-//                // 当前价格  小于等于 止盈价格 进行平仓操作
-//                closeOut(userPosition.getId());
-//            }
-//        }
     }
 
     @Override
@@ -412,8 +379,9 @@ public class UserPositionServiceImpl implements IUserPositionService {
         for (IndexInfo indexInfo : indexInfoList) {
             if (StringUtils.isNotEmpty(indexInfo.getDataDbName())) {
                 try {
-                    String nowPriceStr = getNowPriceStrByDbName(indexInfo.getDataDbName());
-                    nowPrice = BigDecimal.valueOf(Double.valueOf(nowPriceStr));
+                    //每支code获取现价
+                    StockListVO stockListVO = dbStockService.getStockListVO(indexInfo.getCode());
+                    nowPrice = new BigDecimal(stockListVO.getNowPrice());
                     indexMap.put(indexInfo.getCnName(), nowPrice);
                 } catch (Exception e) {
                     // 数据库不存在
@@ -421,7 +389,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
                 }
             }
         }
-
         // 获取有设置止盈的账号
         List<UserPosition> userPositionList = userPositionMapper.selectPositionByStopProfitTarget();
         for(UserPosition userPosition : userPositionList){
@@ -429,26 +396,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
             if(judgeIsCloseOut(userPosition, nowPrice)){
                 closeOut(userPosition.getId(), null);
             }
-//            //判断做多 做空
-//            if("做多".equals(userPosition.getOrderDirection())){
-//                if(nowPrice.compareTo(userPosition.getTargetprofit()) > -1){
-//                    //  当前价格 大于等于 止盈价格 进行平仓操作
-//                    closeOut(userPosition.getId());
-//                }
-//                else if(nowPrice.compareTo(userPosition.getStoploss()) < 1){
-//                    // 当前价格 小于等于 止损价格 进行平仓操作
-//                    closeOut(userPosition.getId());
-//                }
-//            }else{
-//                if(nowPrice.compareTo(userPosition.getStoploss()) > -1){
-//                    // 当前价格 大于等于 止损价格 进行平仓操作
-//                    closeOut(userPosition.getId());
-//                }
-//                else if(nowPrice.compareTo(userPosition.getTargetprofit()) < 1){
-//                    // 当前价格  小于等于 止盈价格 进行平仓操作
-//                    closeOut(userPosition.getId());
-//                }
-//            }
         }
     }
 
@@ -491,7 +438,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
             User user = userMapper.selectByPrimaryKey(userId);
             BigDecimal enableAmt = user.getEnableAmt();
             BigDecimal allAmt = user.getUserAmt();
-
             // 当前用户需要的总过夜费
             int demurrageSum = userPositionMapper.selectUserDemurrageSum(userId);
             if(-1 == enableAmt.compareTo(new BigDecimal(demurrageSum))){
@@ -507,41 +453,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
             for(UserPosition userPosition : userPositionList){
                 orderStayFee = new BigDecimal(indexMap.get(userPosition.getStockName())).multiply(BigDecimal.valueOf(userPosition.getOrderNum()));
                 userPosition.setOrderStayFee(userPosition.getOrderStayFee().add(orderStayFee));
-                // 修改用户资金
-//                UserCashDetail ucd = new UserCashDetail();
-//                ucd.setPositionId(userPosition.getId());
-//                ucd.setAgentId(user.getAgentId());
-//                ucd.setAgentName(user.getAgentName());
-//                ucd.setUserId(user.getId());
-//                ucd.setUserName(user.getRealName());
-//                ucd.setDeType("留仓费");
-//                ucd.setDeAmt(new BigDecimal(-demurrageSum));
-//                ucd.setDeSummary("货币," + userPosition.getStockCode() + "/" + userPosition.getStockName() + ",扣过夜费:-" + orderStayFee);
-//                ucd.setAddTime(new Date());
-//                ucd.setIsRead(Integer.valueOf(0));
-//                int insertSxfCount = this.userCashDetailMapper.insert(ucd);
-
-//                UserCapitalDetail userCapitalDetail = new UserCapitalDetail();
-//                userCapitalDetail.setAgentId(user.getAgentId());
-//                userCapitalDetail.setAgentName(user.getAgentName());
-//                userCapitalDetail.setUserId(user.getId());
-//                userCapitalDetail.setUserName(user.getRealName());
-//                userCapitalDetail.setPositionId(userPosition.getId());
-//                userCapitalDetail.setDeType(3);
-//                userCapitalDetail.setIsRead(Integer.valueOf(0));
-//                userCapitalDetail.setOrderNum(userPosition.getOrderNum());
-//                userCapitalDetail.setBuyFeeAmt(new BigDecimal(0));
-//                userCapitalDetail.setOrderSpread(new BigDecimal(0));
-//                userCapitalDetail.setOrderStayFee(orderStayFee);
-//                userCapitalDetail.setAllProfit(new BigDecimal(0));
-//                userCapitalDetail.setStockName(userPosition.getStockName());
-//                userCapitalDetail.setStockCode(userPosition.getStockCode());
-//                int insertSxfCount = this.userCashDetailMapper.insertUserCapitalDetail(userCapitalDetail);
-//                if (insertSxfCount > 0) {
-//                    log.info("【过夜费】保存明细记录成功");
-//                } else {
-//                    log.error("过夜费】保存明细记录出错");
-//                }
                 // 修改持仓表过夜费
                 userPositionMapper.updateOrderStayFee(userPosition);
             }
@@ -588,7 +499,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
                 log.error("用户撤单】修改用户金额出错");
                 throw new Exception("用户撤单】修改用户金额出错");
             }
-
             int res = this.userPositionMapper.deleteByPrimaryKey(positionId);
             if (res>0){
                 return ServerResponse.createBySuccess("撤单成功");
@@ -666,26 +576,20 @@ public class UserPositionServiceImpl implements IUserPositionService {
                     return ServerResponse.createByErrorMsg("挂单价格不在价差范围内");
                 }
             }
-
             // 用户可用资金
             BigDecimal user_enable_amt = user.getEnableAmt();
-
             // 委托价 * 购买手数
             BigDecimal buy_amt_autual = buyOrderPrice.multiply(new BigDecimal(buyNum));
             log.info("用户可用金额 = {}  实际购买金额 =  {}", user_enable_amt, buy_amt_autual);
-
             // 手续费
             BigDecimal position_freez = new BigDecimal(buyNum*stock.getTransFee());
-
             //冻结保证金
             BigDecimal depositFreezeAmt = new BigDecimal(buyNum*stock.getDepositAmt());
             BigDecimal subtractDepositFreezeAmt = user_enable_amt.subtract(depositFreezeAmt).subtract(position_freez);
-
             log.info("挂单冻结保证金="+depositFreezeAmt);
 //            depositFreezeAmt = depositFreezeAmt.add(position_freez);
             log.info("挂单冻结手续费="+position_freez);
             log.info("挂单冻结金额="+depositFreezeAmt);
-
             // 保证金和手续费 大于 用户可用资金 挂单失败
             if ((depositFreezeAmt.add(position_freez)).compareTo(user.getEnableAmt()) > -1){
                 log.info("用户余额不足冻结保证金");
@@ -700,7 +604,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
                 log.error("用户交易挂单】修改用户金额出错");
                 throw new Exception("用户交易挂单】修改用户金额出错");
             }
-
             UserPosition userPosition = new UserPosition();
             userPosition.setPositionType(user.getAccountType());
             userPosition.setPositionSn(KeyUtils.getUniqueKey());
@@ -715,7 +618,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
             userPosition.setBuyOrderTime(new Date());
             userPosition.setBuyOrderPrice(buyOrderPrice);
             userPosition.setOrderDirection((buyType == 0) ? "做多" : "做空");
-
             userPosition.setOrderNum(buyNum);
             if (stock.getStockPlate() != null) {
                 userPosition.setStockPlate(stock.getStockPlate());
@@ -732,7 +634,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
             userPosition.setDepositFreezeAmt(depositFreezeAmt);
             userPosition.setEntryOrders(1);
             int insertPositionCount = this.userPositionMapper.insertSelective(userPosition);
-
 //            UserCapitalDetail userCapitalDetail = new UserCapitalDetail();
 //            userCapitalDetail.setAgentId(user.getAgentId());
 //            userCapitalDetail.setAgentName(user.getAgentName());
@@ -748,7 +649,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
 //            userCapitalDetail.setStockName(stock.getStockName());
 //            userCapitalDetail.setStockCode(stock.getStockCode());
 //            int insertSxfCount = this.userCashDetailMapper.insertUserCapitalDetail(userCapitalDetail);
-
             if (insertPositionCount > 0) {
                 log.info("【用户交易挂单】保存持仓记录成功");
             } else {
@@ -929,19 +829,15 @@ public class UserPositionServiceImpl implements IUserPositionService {
 
     public ServerResponse sell(String positionSn, int doType) throws Exception {
         log.info("【用户交易平仓】 positionSn = {} , dotype = {}", positionSn, Integer.valueOf(doType));
-
         SiteSetting siteSetting = this.iSiteSettingService.getSiteSetting();
-
         UserPosition userPosition = this.userPositionMapper.findPositionBySn(positionSn);
         if (userPosition == null) {
             return ServerResponse.createByErrorMsg("平仓失败,订单不存在");
         }
-
         if (siteSetting == null) {
             log.error("平仓出错,网站设置表不存在");
             return ServerResponse.createByErrorMsg("下单失败,系统设置错误");
         }
-
         if (doType != 0) {
             // 交易时间
             String am_begin = siteSetting.getTransAmBegin();
@@ -955,94 +851,69 @@ public class UserPositionServiceImpl implements IUserPositionService {
                 return ServerResponse.createByErrorMsg("平仓失败,不在交易时段内");
             }
         }
-
         User user = this.userMapper.selectByPrimaryKey(userPosition.getUserId());
         if (user.getIsLock().intValue() == 1) {
             return ServerResponse.createByErrorMsg("平仓失败,用户已被锁定");
         }
-
         if (userPosition.getSellOrderId() != null) {
             return ServerResponse.createByErrorMsg("平仓失败,此订单已平仓");
         }
-
         if (1 == userPosition.getIsLock().intValue()) {
             return ServerResponse.createByErrorMsg("平仓失败 " + userPosition.getLockMsg());
         }
-
         Stock stock = stockMapper.findStockByName(userPosition.getStockName());
-        StockIndexDF stockIndexDF = getStockIndexDFByDbName(stock.getDataDbName());
-        StockListVO stockListVO = SinaStockApi.assembleStockListVO(stockIndexDF);
-
+        // 获取股票最新价格
+        StockListVO stockListVO = dbStockService.getStockListVO(stock.getStockGid());
         BigDecimal now_price = new BigDecimal(stockListVO.getNowPrice());
         if (now_price.compareTo(new BigDecimal("0")) != 1) {
             log.error("货币 = {} 收到报价 = {}", userPosition.getStockName(), now_price);
             return ServerResponse.createByErrorMsg("报价0,平仓失败,请稍后再试");
         }
-
         double stock_crease = stockListVO.getHcrate().doubleValue();
-
         BigDecimal zsPrice = new BigDecimal(stockListVO.getPreclose_px());
-
         BigDecimal ztPrice = zsPrice.multiply(new BigDecimal("0.1")).add(zsPrice);
         ztPrice = ztPrice.setScale(2, 4);
         BigDecimal chaPrice = ztPrice.subtract(zsPrice);
-
         BigDecimal ztRate = chaPrice.multiply(new BigDecimal("100")).divide(zsPrice, 2, RoundingMode.HALF_UP);
-
         ztRate = ztRate.negate();
         log.info("货币当前涨跌幅 = {} 跌停幅度 = {}", Double.valueOf(stock_crease), ztRate);
         if ((new BigDecimal(String.valueOf(stock_crease))).compareTo(ztRate) == 0 && "做多"
                 .equals(userPosition.getOrderDirection())) {
             return ServerResponse.createByErrorMsg("当前货币已跌停不能卖出");
         }
-
         Integer buy_num = userPosition.getOrderNum();
-
         BigDecimal all_buy_amt = userPosition.getOrderTotalPrice();
         BigDecimal all_sell_amt = now_price.multiply(new BigDecimal(buy_num.intValue()));
-
         BigDecimal profitLoss = new BigDecimal("0");
         if ("做多".equals(userPosition.getOrderDirection())) {
             log.info("买卖方向:{}", "涨");
-
             profitLoss = all_sell_amt.subtract(all_buy_amt);
         } else {
             log.info("买卖方向:{}", "跌");
             profitLoss = all_buy_amt.subtract(all_sell_amt);
         }
         log.info("买入总金额 = {} , 卖出总金额 = {} , 盈亏 = {}", new Object[]{all_buy_amt, all_sell_amt, profitLoss});
-
         BigDecimal user_all_amt = user.getUserAmt();
         BigDecimal user_enable_amt = user.getEnableAmt();
         log.info("用户原本总资金 = {} , 可用 = {}", user_all_amt, user_enable_amt);
-
         BigDecimal buy_fee_amt = userPosition.getOrderFee();
         log.info("买入手续费 = {}", buy_fee_amt);
-
         BigDecimal orderSpread = userPosition.getOrderSpread();
         log.info("点差 = {}", orderSpread);
-
         BigDecimal orderStayFee = userPosition.getOrderStayFee();
         log.info("留仓费 = {}", orderStayFee);
-
         BigDecimal sell_fee_amt = all_sell_amt.multiply(siteSetting.getSellFee()).setScale(2, 4);
         log.info("卖出手续费 = {}", sell_fee_amt);
-
         BigDecimal all_fee_amt = buy_fee_amt.add(sell_fee_amt).add(orderSpread).add(orderStayFee);
         log.info("总的手续费费用 = {}", all_fee_amt);
-
         userPosition.setSellOrderId(GeneratePosition.getPositionId());
         userPosition.setSellOrderPrice(now_price);
         userPosition.setSellOrderTime(new Date());
-
         BigDecimal order_fee_all = buy_fee_amt.add(sell_fee_amt);
         userPosition.setOrderFee(order_fee_all);
-
         userPosition.setProfitAndLose(profitLoss);
-
         BigDecimal all_profit = profitLoss.subtract(all_fee_amt);
         userPosition.setAllProfitAndLose(all_profit);
-
         int updatePositionCount = this.userPositionMapper.updateByPrimaryKeySelective(userPosition);
         if (updatePositionCount > 0) {
             log.info("【用户平仓】修改浮动盈亏记录成功");
@@ -1050,12 +921,9 @@ public class UserPositionServiceImpl implements IUserPositionService {
             log.error("用户平仓】修改浮动盈亏记录出错");
             throw new Exception("用户平仓】修改浮动盈亏记录出错");
         }
-
         BigDecimal freez_amt = all_buy_amt.divide(new BigDecimal(userPosition.getOrderLever().intValue()), 2, 4);
-
         BigDecimal reckon_all = user_all_amt.add(all_profit);
         BigDecimal reckon_enable = user_enable_amt.add(all_profit).add(freez_amt);
-
         log.info("用户平仓后的总资金  = {} , 可用资金 = {}", reckon_all, reckon_enable);
         user.setUserAmt(reckon_all);
         user.setEnableAmt(reckon_enable);
@@ -1066,20 +934,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
             log.error("用户平仓】修改用户金额出错");
             throw new Exception("用户平仓】修改用户金额出错");
         }
-
-//        UserCashDetail ucd = new UserCashDetail();
-//        ucd.setPositionId(userPosition.getId());
-//        ucd.setAgentId(user.getAgentId());
-//        ucd.setAgentName(user.getAgentName());
-//        ucd.setUserId(user.getId());
-//        ucd.setUserName(user.getRealName());
-//        ucd.setDeType("总盈亏");
-//        ucd.setDeAmt(all_profit);
-//        ucd.setDeSummary("卖出货币," + userPosition.getStockCode() + "/" + userPosition.getStockName() + ",手续费:" + buy_fee_amt + ",盈亏:" + all_profit + ",点差:" + orderSpread + ",留仓费:" + orderStayFee);
-//        ucd.setAddTime(new Date());
-//        ucd.setIsRead(Integer.valueOf(0));
-//        int insertSxfCount = this.userCashDetailMapper.insert(ucd);
-
         UserCapitalDetail userCapitalDetail = new UserCapitalDetail();
         userCapitalDetail.setAgentId(user.getAgentId());
         userCapitalDetail.setAgentName(user.getAgentName());
@@ -1102,7 +956,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
             log.error("用户平仓】保存明细记录出错");
             throw new Exception("用户平仓】保存明细记录出错");
         }
-
         return ServerResponse.createBySuccessMsg("平仓成功!");
     }
 
@@ -1313,23 +1166,18 @@ public class UserPositionServiceImpl implements IUserPositionService {
 
     public ServerResponse listByAgent(Integer positionType, Integer state, Integer userId, Integer agentId, String positionSn, String beginTime, String endTime, HttpServletRequest request, int pageNum, int pageSize) {
         AgentUser currentAgent = this.iAgentUserService.getCurrentAgent(request);
-
-
         if (agentId != null) {
             AgentUser agentUser = this.agentUserMapper.selectByPrimaryKey(agentId);
             if (agentUser.getParentId() != currentAgent.getId()) {
                 return ServerResponse.createByErrorMsg("不能查询非下级代理用户持仓");
             }
         }
-
         Integer searchId = null;
         if (agentId == null) {
             searchId = currentAgent.getId();
         } else {
             searchId = agentId;
         }
-
-
         Timestamp begin_time = null;
         if (StringUtils.isNotBlank(beginTime)) {
             begin_time = DateTimeUtil.searchStrToTimestamp(beginTime);
@@ -1338,16 +1186,14 @@ public class UserPositionServiceImpl implements IUserPositionService {
         if (StringUtils.isNotBlank(endTime)) {
             end_time = DateTimeUtil.searchStrToTimestamp(endTime);
         }
-
         PageHelper.startPage(pageNum, pageSize);
-
         Map<String, IndexInfo> indexMap = new HashMap<>();
         List<IndexInfo> indexInfoList = stockMapper.selectStockList();
         for (IndexInfo indexInfo : indexInfoList) {
             if (StringUtils.isNotEmpty(indexInfo.getDataDbName())) {
                 try {
-                    String nowPriceStr = getNowPriceStrByDbName(indexInfo.getDataDbName());
-                    BigDecimal nowPrice = BigDecimal.valueOf(Double.valueOf(nowPriceStr));
+                    StockListVO stockListVO = dbStockService.getStockListVO(indexInfo.getCode());
+                    BigDecimal nowPrice = new BigDecimal(stockListVO.getNowPrice());
                     indexInfo.setNowPrice(nowPrice);
                 } catch (Exception e) {
                     // 数据库不存在
@@ -1357,24 +1203,17 @@ public class UserPositionServiceImpl implements IUserPositionService {
             indexMap.put(indexInfo.getCnName(), indexInfo);
         }
         List<UserPosition> userPositions = this.userPositionMapper.listByAgent(positionType, state, userId, searchId, positionSn, begin_time, end_time);
-
         List<AgentPositionVO> agentPositionVOS = Lists.newArrayList();
         for (UserPosition position : userPositions) {
             AgentPositionVO agentPositionVO = assembleAgentPositionVO(position, state, indexMap);
             agentPositionVOS.add(agentPositionVO);
         }
-
         PageInfo pageInfo = new PageInfo(userPositions);
         pageInfo.setList(agentPositionVOS);
-
         return ServerResponse.createBySuccess(pageInfo);
     }
 
     public ServerResponse getIncome(Integer agentId, Integer positionType, String beginTime, String endTime) {
-//        if (StringUtils.isBlank(beginTime) || StringUtils.isBlank(endTime)) {
-//            return ServerResponse.createByErrorMsg("时间不能为空");
-//        }
-
         Timestamp begin_time = null;
         if (StringUtils.isNotBlank(beginTime)) {
             begin_time = DateTimeUtil.searchStrToTimestamp(beginTime);
@@ -1405,8 +1244,8 @@ public class UserPositionServiceImpl implements IUserPositionService {
                     for (IndexInfo indexInfo : indexInfoList) {
                         if (StringUtils.isNotEmpty(indexInfo.getDataDbName())) {
                             try {
-                                String nowPriceStr = getNowPriceStrByDbName(indexInfo.getDataDbName());
-                                nowPrice = BigDecimal.valueOf(Double.valueOf(nowPriceStr));
+                                StockListVO stockListVO = dbStockService.getStockListVO(indexInfo.getCode());
+                                nowPrice = new BigDecimal(stockListVO.getNowPrice());
                                 indexInfo.setNowPrice(nowPrice);
                             } catch (Exception e) {
                                 // 数据库不存在
@@ -1440,8 +1279,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
 
     public ServerResponse listByAdmin(Integer agentId, Integer positionType, Integer state, Integer userId, String positionSn, String beginTime, String endTime, int pageNum, int pageSize) {
         PageHelper.startPage(pageNum, pageSize);
-
-
         Timestamp begin_time = null;
         if (StringUtils.isNotBlank(beginTime)) {
             begin_time = DateTimeUtil.searchStrToTimestamp(beginTime);
@@ -1450,17 +1287,14 @@ public class UserPositionServiceImpl implements IUserPositionService {
         if (StringUtils.isNotBlank(endTime)) {
             end_time = DateTimeUtil.searchStrToTimestamp(endTime);
         }
-
-
         List<UserPosition> userPositions = this.userPositionMapper.listByAgent(positionType, state, userId, agentId, positionSn, begin_time, end_time);
-
         Map<String, IndexInfo> indexMap = new HashMap<>();
         List<IndexInfo> indexInfoList = stockMapper.selectStockList();
         for (IndexInfo indexInfo : indexInfoList) {
             if (StringUtils.isNotEmpty(indexInfo.getDataDbName())) {
                 try {
-                    String nowPriceStr = getNowPriceStrByDbName(indexInfo.getDataDbName());
-                    BigDecimal nowPrice = BigDecimal.valueOf(Double.valueOf(nowPriceStr));
+                    StockListVO stockListVO = dbStockService.getStockListVO(indexInfo.getCode());
+                    BigDecimal nowPrice = new BigDecimal(stockListVO.getNowPrice());
                     indexInfo.setNowPrice(nowPrice);
                 } catch (Exception e) {
                     // 数据库不存在
@@ -1469,17 +1303,14 @@ public class UserPositionServiceImpl implements IUserPositionService {
             }
             indexMap.put(indexInfo.getCnName(), indexInfo);
         }
-
         List<AdminPositionVO> adminPositionVOS = Lists.newArrayList();
         for (UserPosition position : userPositions) {
             IndexInfo indexInfo = indexMap.get(position.getStockName());
             AdminPositionVO adminPositionVO = assembleAdminPositionVO(position, state, indexMap);
             adminPositionVOS.add(adminPositionVO);
         }
-
         PageInfo pageInfo = new PageInfo(userPositions);
         pageInfo.setList(adminPositionVOS);
-
         return ServerResponse.createBySuccess(pageInfo);
     }
 
@@ -1501,7 +1332,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
 
             return ServerResponse.createByErrorMsg("参数不能为空");
         }
-
         User user = this.userMapper.selectByPrimaryKey(userId);
         if (user == null) {
             return ServerResponse.createByErrorMsg("用户不存在");
@@ -1509,34 +1339,24 @@ public class UserPositionServiceImpl implements IUserPositionService {
         if (user.getAccountType().intValue() != 1) {
             return ServerResponse.createByErrorMsg("正式用户不能生成持仓单");
         }
-
         Stock stock = (Stock) this.iStockService.findStockByCode(stockCode).getData();
         if (stock == null) {
             return ServerResponse.createByErrorMsg("货币不存在");
         }
-
-
         SiteSetting siteSetting = this.iSiteSettingService.getSiteSetting();
         if (siteSetting == null) {
             log.error("下单出错,网站设置表不存在");
             return ServerResponse.createByErrorMsg("下单失败,系统设置错误");
         }
-
-
         BigDecimal user_enable_amt = user.getEnableAmt();
-
         BigDecimal buy_amt = (new BigDecimal(buyPrice)).multiply(new BigDecimal(buyNum.intValue()));
         BigDecimal buy_amt_autual = buy_amt.divide(new BigDecimal(lever.intValue()), 2, 4);
-
-
         int compareUserAmtInt = user_enable_amt.compareTo(buy_amt_autual);
         log.info("用户可用金额 = {}  实际购买金额 =  {}", user_enable_amt, buy_amt_autual);
         log.info("比较 用户金额 和 实际 购买金额 =  {}", Integer.valueOf(compareUserAmtInt));
         if (compareUserAmtInt == -1) {
             return ServerResponse.createByErrorMsg("下单失败,用户可用金额小于" + buy_amt_autual + "元");
         }
-
-
         BigDecimal reckon_enable = user_enable_amt.subtract(buy_amt_autual);
         user.setEnableAmt(reckon_enable);
         int updateUserCount = this.userMapper.updateByPrimaryKeySelective(user);
@@ -1545,8 +1365,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
         } else {
             log.error("用户交易下单】修改用户金额出错");
         }
-
-
         UserPosition userPosition = new UserPosition();
         userPosition.setPositionType(Integer.valueOf(1));
         userPosition.setPositionSn(KeyUtils.getUniqueKey());
@@ -1560,48 +1378,29 @@ public class UserPositionServiceImpl implements IUserPositionService {
         userPosition.setBuyOrderId(GeneratePosition.getPositionId());
         userPosition.setBuyOrderTime(DateTimeUtil.strToDate(buyTime));
         userPosition.setBuyOrderPrice(new BigDecimal(buyPrice));
-        userPosition.setOrderDirection((buyType.intValue() == 0) ? "做多" : "做空");
-
+        userPosition.setOrderDirection((buyType == 0) ? "做多" : "做空");
         userPosition.setOrderNum(buyNum);
-
-
-        userPosition.setIsLock(Integer.valueOf(0));
-
-
+        userPosition.setIsLock(0);
         userPosition.setOrderLever(lever);
-
-
         userPosition.setOrderTotalPrice(buy_amt);
-
-
         BigDecimal buy_fee_amt = buy_amt.multiply(siteSetting.getBuyFee()).setScale(2, 4);
         log.info("创建模拟持仓 手续费(配资后总资金 * 百分比) = {}", buy_fee_amt);
         userPosition.setOrderFee(buy_fee_amt);
-
-
         BigDecimal buy_yhs_amt = buy_amt.multiply(siteSetting.getDutyFee()).setScale(2, 4);
         log.info("创建模拟持仓 点差(配资后总资金 * 百分比) = {}", buy_yhs_amt);
         userPosition.setOrderSpread(buy_yhs_amt);
-
-
         BigDecimal profit_and_lose = new BigDecimal("0");
         userPosition.setProfitAndLose(profit_and_lose);
-
-
         BigDecimal all_profit_and_lose = profit_and_lose.subtract(buy_fee_amt).subtract(buy_yhs_amt);
         userPosition.setAllProfitAndLose(all_profit_and_lose);
-
-
-        userPosition.setOrderStayDays(Integer.valueOf(0));
+        userPosition.setOrderStayDays(0);
         userPosition.setOrderStayFee(new BigDecimal("0"));
-
         int insertPositionCount = this.userPositionMapper.insert(userPosition);
         if (insertPositionCount > 0) {
             log.info("【创建模拟持仓】保存记录成功");
         } else {
             log.error("【创建模拟持仓】保存记录出错");
         }
-
         return ServerResponse.createBySuccess("生成模拟持仓成功");
     }
 
@@ -1611,22 +1410,18 @@ public class UserPositionServiceImpl implements IUserPositionService {
 
     public void doClosingStayTask() {
         List<UserPosition> userPositions = this.userPositionMapper.findAllStayPosition();
-
-
         if (userPositions.size() > 0) {
-            log.info("查询到正在持仓的订单数量 = {}", Integer.valueOf(userPositions.size()));
-
+            log.info("查询到正在持仓的订单数量 = {}", userPositions.size());
             for (UserPosition position : userPositions) {
                 int stayDays = GetStayDays.getDays(GetStayDays.getBeginDate(position.getBuyOrderTime()));
-
                 log.info("");
-                log.info("开始处理 持仓订单id = {} 订单号 = {} 用户id = {} realName = {} 留仓天数 = {}", new Object[]{position
+                log.info("开始处理 持仓订单id = {} 订单号 = {} 用户id = {} realName = {} 留仓天数 = {}", position
                         .getId(), position.getPositionSn(), position.getUserId(), position
-                        .getNickName(), Integer.valueOf(stayDays)});
+                        .getNickName(), stayDays);
                 if (stayDays != 0) {
-                    log.info(" 开始收取 {} 天 留仓费", Integer.valueOf(stayDays));
+                    log.info(" 开始收取 {} 天 留仓费", stayDays);
                     try {
-                        closingStayTask(position, Integer.valueOf(stayDays));
+                        closingStayTask(position, stayDays);
                     } catch (Exception e) {
                         log.error("doClosingStayTask = ", e);
                     }
@@ -1634,14 +1429,11 @@ public class UserPositionServiceImpl implements IUserPositionService {
                     log.info("持仓订单 = {} ,持仓天数0天,不需要处理...", position.getId());
                 }
                 log.info("修改留仓费 处理结束。");
-
-
             }
-
             SiteTaskLog stl = new SiteTaskLog();
             stl.setTaskType("扣除留仓费");
             stl.setAddTime(new Date());
-            stl.setIsSuccess(Integer.valueOf(0));
+            stl.setIsSuccess(0);
             stl.setTaskTarget("扣除留仓费,订单数量为" + userPositions.size());
             this.siteTaskLogMapper.insert(stl);
         } else {
@@ -1659,24 +1451,15 @@ public class UserPositionServiceImpl implements IUserPositionService {
             log.error("修改留仓费出错,网站设置表不存在");
             return ServerResponse.createByErrorMsg("修改留仓费出错,网站设置表不存在");
         }
-
-
         BigDecimal stayFee = position.getOrderTotalPrice().multiply(siteSetting.getStayFee());
-
         BigDecimal allStayFee = stayFee.multiply(new BigDecimal(stayDays.intValue()));
-
         log.info("总留仓费 = {}", allStayFee);
-
-
         position.setOrderStayFee(allStayFee);
         position.setOrderStayDays(stayDays);
-
         BigDecimal all_profit = position.getAllProfitAndLose().subtract(allStayFee);
         position.setAllProfitAndLose(all_profit);
-
         int updateCount = this.userPositionMapper.updateByPrimaryKeySelective(position);
         if (updateCount > 0) {
-
             User user = this.userMapper.selectByPrimaryKey(position.getUserId());
             UserCashDetail ucd = new UserCashDetail();
             ucd.setPositionId(position.getId());
@@ -1695,8 +1478,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
             log.error("【closingStayTask收持仓费】修改持仓记录出错");
             throw new Exception("【closingStayTask收持仓费】修改持仓记录出错");
         }
-
-
         log.info("=======================================================");
         return ServerResponse.createBySuccess();
     }
@@ -1707,9 +1488,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
 
     private AdminPositionVO assembleAdminPositionVO(UserPosition position, Integer state, Map<String, IndexInfo> indexMap) {
         AdminPositionVO adminPositionVO = new AdminPositionVO();
-
         adminPositionVO.setId(position.getId());
-
         adminPositionVO.setPositionSn(position.getPositionSn());
         adminPositionVO.setPositionType(position.getPositionType());
         adminPositionVO.setUserId(position.getUserId());
@@ -1733,12 +1512,9 @@ public class UserPositionServiceImpl implements IUserPositionService {
         adminPositionVO.setOrderSpread(position.getOrderSpread());
         adminPositionVO.setOrderStayFee(position.getOrderStayFee());
         adminPositionVO.setOrderStayDays(position.getOrderStayDays());
-
         adminPositionVO.setIsLock(position.getIsLock());
         adminPositionVO.setLockMsg(position.getLockMsg());
-
         adminPositionVO.setStockPlate(position.getStockPlate());
-
         // 计算浮动盈亏  如果是平仓的就不需要计算了  直接去数据库中的
         if(1 != state){
             PositionProfitVO positionProfitVO = getPositionProfitVO(position, indexMap);
@@ -1757,7 +1533,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
 
     private AgentPositionVO assembleAgentPositionVO(UserPosition position, Integer state, Map<String, IndexInfo> indexMap) {
         AgentPositionVO agentPositionVO = new AgentPositionVO();
-
         agentPositionVO.setId(position.getId());
         agentPositionVO.setPositionSn(position.getPositionSn());
         agentPositionVO.setPositionType(position.getPositionType());
@@ -1782,14 +1557,10 @@ public class UserPositionServiceImpl implements IUserPositionService {
         agentPositionVO.setOrderSpread(position.getOrderSpread());
         agentPositionVO.setOrderStayFee(position.getOrderStayFee());
         agentPositionVO.setOrderStayDays(position.getOrderStayDays());
-
         agentPositionVO.setIsLock(position.getIsLock());
         agentPositionVO.setLockMsg(position.getLockMsg());
-
         agentPositionVO.setStockPlate(position.getStockPlate());
-
 //        PositionProfitVO positionProfitVO = getPositionProfitVO(position, indexMap);
-
         // 计算浮动盈亏  如果是平仓的就不需要计算了  直接去数据库中的
         if(1 != state){
             PositionProfitVO positionProfitVO = getPositionProfitVO(position, indexMap);
@@ -1801,8 +1572,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
             agentPositionVO.setProfitAndLose(position.getProfitAndLose());
             agentPositionVO.setAllProfitAndLose(position.getAllProfitAndLose());
         }
-
-
 //        agentPositionVO.setProfitAndLose(positionProfitVO.getProfitAndLose());
 //        agentPositionVO.setAllProfitAndLose(positionProfitVO.getAllProfitAndLose());
 //        agentPositionVO.setNow_price(positionProfitVO.getNowPrice());
@@ -1812,7 +1581,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
 
     private UserPositionVO assembleUserPositionVO(UserPosition position) {
         UserPositionVO userPositionVO = new UserPositionVO();
-
         userPositionVO.setId(position.getId());
         userPositionVO.setPositionType(position.getPositionType());
         userPositionVO.setPositionSn(position.getPositionSn());
@@ -1839,11 +1607,9 @@ public class UserPositionServiceImpl implements IUserPositionService {
         userPositionVO.setOrderSpread(position.getOrderSpread());
         userPositionVO.setOrderStayFee(position.getOrderStayFee());
         userPositionVO.setOrderStayDays(position.getOrderStayDays());
-
         userPositionVO.setStoploss(position.getStoploss());
         userPositionVO.setTargetprofit(position.getTargetprofit());
         userPositionVO.setStockPlate(position.getStockPlate());
-
 //        PositionProfitVO positionProfitVO = getPositionProfitVO(position);
         userPositionVO.setProfitAndLose(position.getProfitAndLose());
         userPositionVO.setAllProfitAndLose(position.getAllProfitAndLose());
@@ -1870,7 +1636,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
 //        allProfitAndLose = yk.add(position.getOrderFee());
         allProfitAndLose = yk;
         profitAndLose = yk;
-
         // 计算风险率
         User user = userMapper.selectByPrimaryKey(position.getUserId());
         List<UserPosition> userPositionAll = this.userPositionMapper.findMyPositionByCodeAndSpell(user.getId(), null, null, 0);
@@ -1928,58 +1693,58 @@ public class UserPositionServiceImpl implements IUserPositionService {
         }
     }
 
-    public StockIndexDF getStockIndexDFByDbName(String dbName){
-        String dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, new Date());
-        StockIndexDF stockIndexDF;
-        try {
-            stockIndexDF = stockMapper.selectStockDateByDf(dbTableName);
-            if(null == stockIndexDF){
-                // 当月数据还没有 先获取上个月的
-                Calendar c = Calendar.getInstance();
-                c.setTime(new Date());
-                c.add(Calendar.MONTH, -1);
-                Date lastMonth = c.getTime();
-                dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, lastMonth);
-                stockIndexDF = stockMapper.selectStockDateByDf(dbTableName);
-            }
-            return stockIndexDF;
-        }catch (Exception e){
-            // 当月数据还没有 先获取上个月的
-            Calendar c = Calendar.getInstance();
-            c.setTime(new Date());
-            c.add(Calendar.MONTH, -1);
-            Date lastMonth = c.getTime();
-            dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, lastMonth);
-            stockIndexDF = stockMapper.selectStockDateByDf(dbTableName);
-            return stockIndexDF;
-        }
-    }
-
-    public String getNowPriceStrByDbName(String dbName){
-        String dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, new Date());
-        String nowPriceStr;
-        try {
-            nowPriceStr = stockMapper.selectNowPrice(dbTableName);
-            if(null == nowPriceStr){
-                // 当月数据还没有 先获取上个月的
-                Calendar c = Calendar.getInstance();
-                c.setTime(new Date());
-                c.add(Calendar.MONTH, -1);
-                Date lastMonth = c.getTime();
-                dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, lastMonth);
-                nowPriceStr = stockMapper.selectNowPrice(dbTableName);
-            }
-            return nowPriceStr;
-        }catch (Exception e){
-            Calendar c = Calendar.getInstance();
-            c.setTime(new Date());
-            c.add(Calendar.MONTH, -1);
-            Date lastMonth = c.getTime();
-            dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, lastMonth);
-            nowPriceStr = stockMapper.selectNowPrice(dbTableName);
-            return nowPriceStr;
-        }
-    }
+//    public StockIndexDF getStockIndexDFByDbName(String dbName){
+//        String dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, new Date());
+//        StockIndexDF stockIndexDF;
+//        try {
+//            stockIndexDF = stockMapper.selectStockDateByDf(dbTableName);
+//            if(null == stockIndexDF){
+//                // 当月数据还没有 先获取上个月的
+//                Calendar c = Calendar.getInstance();
+//                c.setTime(new Date());
+//                c.add(Calendar.MONTH, -1);
+//                Date lastMonth = c.getTime();
+//                dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, lastMonth);
+//                stockIndexDF = stockMapper.selectStockDateByDf(dbTableName);
+//            }
+//            return stockIndexDF;
+//        }catch (Exception e){
+//            // 当月数据还没有 先获取上个月的
+//            Calendar c = Calendar.getInstance();
+//            c.setTime(new Date());
+//            c.add(Calendar.MONTH, -1);
+//            Date lastMonth = c.getTime();
+//            dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, lastMonth);
+//            stockIndexDF = stockMapper.selectStockDateByDf(dbTableName);
+//            return stockIndexDF;
+//        }
+//    }
+//
+//    public String getNowPriceStrByDbName(String dbName){
+//        String dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, new Date());
+//        String nowPriceStr;
+//        try {
+//            nowPriceStr = stockMapper.selectNowPrice(dbTableName);
+//            if(null == nowPriceStr){
+//                // 当月数据还没有 先获取上个月的
+//                Calendar c = Calendar.getInstance();
+//                c.setTime(new Date());
+//                c.add(Calendar.MONTH, -1);
+//                Date lastMonth = c.getTime();
+//                dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, lastMonth);
+//                nowPriceStr = stockMapper.selectNowPrice(dbTableName);
+//            }
+//            return nowPriceStr;
+//        }catch (Exception e){
+//            Calendar c = Calendar.getInstance();
+//            c.setTime(new Date());
+//            c.add(Calendar.MONTH, -1);
+//            Date lastMonth = c.getTime();
+//            dbTableName = IndexDbCreatedUtil.createdDbTableNameByTime(dbName, lastMonth);
+//            nowPriceStr = stockMapper.selectNowPrice(dbTableName);
+//            return nowPriceStr;
+//        }
+//    }
 
     public Integer getTodayOrderNum(String stockName){
         return userPositionMapper.selectTodayOrderNum(stockName);

+ 0 - 1
src/main/java/com/xc/service/impl/UserServiceImpl.java

@@ -7,7 +7,6 @@ import com.xc.common.ServerResponse;
 import com.xc.dao.*;
 import com.xc.pojo.*;
 import com.xc.service.*;
-import com.xc.utils.IndexDbCreatedUtil;
 import com.xc.utils.PropertiesUtil;
 import com.xc.utils.TokenUtils;
 import com.xc.utils.ip.IpUtils;

+ 0 - 54
src/main/java/com/xc/utils/IndexDbCreatedUtil.java

@@ -1,54 +0,0 @@
-package com.xc.utils;
-
-import com.xc.utils.enumUtil.IndexEnum;
-import com.xc.utils.enumUtil.ResolutionEnum;
-
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-
-public class IndexDbCreatedUtil {
-
-    private static final String decollator = "_";
-
-    public static String createdDbTableName(String indexCode, String yearMonth, String resolution){
-        StringBuilder sb = new StringBuilder("data").append(decollator).append(ResolutionEnum.getDbNameByCode(resolution)).append(decollator);
-        String dbName = IndexEnum.getDbNameByCode(indexCode);
-        sb.append(dbName).append(decollator).append(yearMonth);
-        return sb.toString();
-    }
-
-    public static String createdDbTableNameByTime(String dbName, Date time){
-        StringBuilder sb = new StringBuilder("data").append(decollator).append("rt").append(decollator);
-        sb.append(dbName).append(decollator).append(getTimeString(time));
-        return sb.toString();
-    }
-
-    public static String createdDbTableName(String indexCode, Date time){
-        StringBuilder sb = new StringBuilder("data").append(decollator).append("rt").append(decollator);
-        String dbName = IndexEnum.getDbNameByCode(indexCode);
-        sb.append(dbName).append(decollator).append(getTimeString(time));
-        return sb.toString();
-    }
-
-    public static String createdHistDbTableName(String indexCode){
-        StringBuilder sb = new StringBuilder("data").append(decollator).append("hist").append(decollator);
-        String dbName = IndexEnum.getDbNameByCode(indexCode);
-        sb.append(dbName);
-        return sb.toString();
-    }
-
-    // 获取年月
-    public static int getYearMonth(Date time){
-        return Integer.valueOf(getTimeString(time));
-    }
-
-    private static String getTimeString(Date time){
-        String str = "yyyy";
-        SimpleDateFormat sdf = new SimpleDateFormat(str);
-        if(null != time){
-            return sdf.format(time);
-        }
-        return sdf.format(new Date());
-    }
-}

+ 0 - 142
src/main/java/com/xc/utils/enumUtil/IndexEnum.java

@@ -1,142 +0,0 @@
-package com.xc.utils.enumUtil;
-
-
-import com.xc.pojo.IndexInfo;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public enum IndexEnum {
-    /**
-     *
-     */
-    HSI_HI("HSI.HI", "HSI.HI", "恒生货币", "HSI_HI", "index"),
-    GDAXI_GI("GDAXI.GI", "GDAXI.GI", "德国DAX", "GDAXI_GI", "index"),
-    DJIA_GI("DJIA_GI", "DJIA_GI", "道琼斯工业平均", "DJIA_GI", "index"),
-    IXIC_GI("IXIC.GI", "IXIC.GI", "纳斯达克", "IXIC_GI", "index"),
-    CHA50CFD("CHA50CFD", "CHA50CFD", "富时A50", "CHA50CFD", "index"),
-    SH000001("000001.SH", "000001.SH", "上证货币", "000001_sh", "index"),
-    SZ399001("399001.SZ", "399001.SZ", "深证成指", "399001_sz", "index"),
-    SZ399006("399006.SZ", "399006.SZ", "创业扳指", "399006_sz", "index");
-
-    private String code;
-
-    private String enName;
-
-    private String cnName;
-
-    private String dbName;
-
-    // 股票"stock",  货币"index"
-    private String type;
-
-    IndexEnum(String code, String enName, String cnName, String dbName, String type) {
-        this.code = code;
-        this.enName = enName;
-        this.cnName = cnName;
-        this.dbName = dbName;
-        this.type = type;
-    }
-
-    public String getCode() {
-        return code;
-    }
-
-    public void setCode(String code) {
-        this.code = code;
-    }
-
-    public String getEnName() {
-        return enName;
-    }
-
-    public void setEnName(String enName) {
-        this.enName = enName;
-    }
-
-    public String getCnName() {
-        return cnName;
-    }
-
-    public void setCnName(String cnName) {
-        this.cnName = cnName;
-    }
-
-    public String getDbName() {
-        return dbName;
-    }
-
-    public void setDbName(String dbName) {
-        this.dbName = dbName;
-    }
-
-    public String getType() {
-        return type;
-    }
-
-    public void setType(String type) {
-        this.type = type;
-    }
-
-    public static String getDbNameByCode(String code) {
-        String dbName = null;
-        for (IndexEnum e : IndexEnum.values()) {
-            if (code.equals(e.getCode())) {
-                dbName = e.getDbName();
-                break;
-            }
-        }
-        return dbName;
-    }
-
-    // 根据类型返回列表
-    public static List<String> getNameList(int type) {
-        List<String> list = new ArrayList<>();
-        for (IndexEnum e : IndexEnum.values()) {
-            if (1 == type) {
-                // 返回ID
-                list.add(String.valueOf(e.getCode()));
-            } else if (2 == type) {
-                // 返回英文名
-                list.add(e.getEnName());
-            } else if (3 == type) {
-                // 返回返回类型
-                list.add(e.getType());
-            }
-        }
-        return list;
-    }
-
-    // 根据类型返回列表
-    public static IndexEnum getEnumList(String code) {
-        IndexEnum indexEnum = null;
-        for (IndexEnum e : IndexEnum.values()) {
-            if (code.equals(String.valueOf(e.getCode()))) {
-                indexEnum = e;
-                return indexEnum;
-            }
-        }
-        for (IndexEnum e : IndexEnum.values()) {
-            if (code.equals(e.getEnName())) {
-                indexEnum = e;
-                return indexEnum;
-            }
-        }
-        return indexEnum;
-    }
-
-    // 根据类型返回列表
-    public static List<IndexInfo> getList() {
-        List<IndexInfo> list = new ArrayList<>();
-        for (IndexEnum e : IndexEnum.values()) {
-            IndexInfo indexInfo = new IndexInfo();
-            indexInfo.setId(e.getCode());
-            indexInfo.setEnName(e.getEnName());
-            indexInfo.setCnName(e.getCnName());
-            indexInfo.setDepositAmt(1000);
-            indexInfo.setTransFee(50);
-            list.add(indexInfo);
-        }
-        return list;
-    }
-}

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

@@ -3,10 +3,12 @@ package com.xc.utils.task.index;
 
 import com.xc.dao.StockMapper;
 import com.xc.pojo.IndexInfo;
+import com.xc.service.DbStockService;
 import com.xc.service.IUserPositionService;
 import com.xc.utils.DateTimeUtil;
 import com.xc.utils.stock.BuyAndSellUtils;
 import com.xc.utils.thread.ThreadUtil;
+import com.xc.vo.stock.StockListVO;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -37,6 +39,9 @@ public class EntrustTask {
     @Autowired
     private StockMapper stockMapper;
 
+    @Autowired
+    DbStockService dbStockService;
+
     // 星期一到星期五的每天9点到15点触发 每3分钟触发一次
 //    @Scheduled(cron = "*/3 * * * * ?")
     public void toEntrust() {
@@ -65,8 +70,8 @@ public class EntrustTask {
         for (IndexInfo indexInfo : indexInfoList) {
             if (StringUtils.isNotEmpty(indexInfo.getDataDbName())) {
                 try {
-                    String nowPriceStr = iUserPositionService.getNowPriceStrByDbName(indexInfo.getDataDbName());
-                    nowPrice = BigDecimal.valueOf(Double.valueOf(nowPriceStr));
+                    StockListVO stockListVO = dbStockService.getStockListVO(indexInfo.getCode());
+                    nowPrice = new BigDecimal(stockListVO.getNowPrice());
                     BigDecimal finalNowPrice = nowPrice;
                     ThreadUtil.executeInThread(obj -> {
                         iUserPositionService.fulfill(indexInfo.getCode(), finalNowPrice);

+ 0 - 26
src/main/java/com/xc/utils/task/index/ForceSellTask.java

@@ -1,26 +1,14 @@
 package com.xc.utils.task.index;
 
-
 import com.xc.service.IUserService;
-
 import com.xc.utils.DateTimeUtil;
-
-import com.xc.utils.stock.BuyAndSellUtils;
-
 import java.util.Date;
-
 import com.xc.utils.thread.ThreadUtil;
 import org.slf4j.Logger;
-
 import org.slf4j.LoggerFactory;
-
 import org.springframework.beans.factory.annotation.Autowired;
-
-import org.springframework.scheduling.annotation.Scheduled;
-
 import org.springframework.stereotype.Component;
 
-
 @Component
 public class ForceSellTask {
 
@@ -29,26 +17,12 @@ public class ForceSellTask {
     @Autowired
     IUserService iUserService;
 
-//    private static final String am_begin = "9:30";
-//
-//    private static final String am_end = "11:30";
-//
-//    private static final String pm_begin = "13:00";
-//
-//    private static final String pm_end = "23:00";
-
     /*用户持仓单定时*/
 //    @Scheduled(cron = "0 0/3 9-23 ? * MON-FRI")
 //    @Scheduled(cron = "*/3 * * * * ?")
     public void banlanceUserPositionTaskV1() {
         boolean am = true;
         boolean pm = true;
-//        try {
-//            am = BuyAndSellUtils.isTransTime(am_begin, am_end);
-//            pm = BuyAndSellUtils.isTransTime(pm_begin, pm_end);
-//        } catch (Exception e) {
-//            log.error("执行定时任务出错,e = {}", e);
-//        }
         if (am || pm) {
             log.info("=====扫描爆仓任务,当前时间 {} =====", DateTimeUtil.dateToStr(new Date()));
             dotask();