Explorar el Código

add datasource2

liuchaojie hace 4 años
padre
commit
9f8a591b86
Se han modificado 53 ficheros con 1219 adiciones y 736 borrados
  1. 2 2
      src/main/java/com/xc/controller/AdminApiController.java
  2. 7 7
      src/main/java/com/xc/controller/StockApiController.java
  3. 1 1
      src/main/java/com/xc/controller/StockIndexApiController.java
  4. 2 2
      src/main/java/com/xc/controller/agent/AgentController.java
  5. 1 1
      src/main/java/com/xc/controller/agent/AgentIndexPositionController.java
  6. 2 2
      src/main/java/com/xc/controller/backend/AdminAgentController.java
  7. 1 1
      src/main/java/com/xc/controller/backend/AdminController.java
  8. 2 2
      src/main/java/com/xc/controller/backend/AdminIndexPositionController.java
  9. 1 1
      src/main/java/com/xc/controller/backend/AdminSiteIndexSettingController.java
  10. 2 2
      src/main/java/com/xc/controller/backend/AdminSiteSettingController.java
  11. 6 6
      src/main/java/com/xc/controller/backend/AdminStockController.java
  12. 3 3
      src/main/java/com/xc/controller/backend/AdminStockIndexController.java
  13. 1 1
      src/main/java/com/xc/controller/index/IndexApiController.java
  14. 3 8
      src/main/java/com/xc/controller/protol/UserController.java
  15. 1 1
      src/main/java/com/xc/controller/protol/UserOptionController.java
  16. 10 10
      src/main/java/com/xc/dao/StockCoinMapper.java
  17. 2 4
      src/main/java/com/xc/dao/StockMapper.java
  18. 18 18
      src/main/java/com/xc/dao/UserPositionMapper.java
  19. 26 0
      src/main/java/com/xc/dao2/KLinkStockMapper.java
  20. 12 0
      src/main/java/com/xc/dao2/StockRestDataMapper.java
  21. 2 2
      src/main/java/com/xc/pojo/RealTimeIndex.java
  22. 6 15
      src/main/java/com/xc/pojo/Stock.java
  23. 3 3
      src/main/java/com/xc/pojo/UserCapitalDetail.java
  24. 12 0
      src/main/java/com/xc/service/DbStockService.java
  25. 2 2
      src/main/java/com/xc/service/IndexApiService.java
  26. 85 0
      src/main/java/com/xc/service/impl/DbStockServiceImpl.java
  27. 1 1
      src/main/java/com/xc/service/impl/NewsServiceImpl.java
  28. 2 2
      src/main/java/com/xc/service/impl/SiteIndexSettingServiceImpl.java
  29. 2 14
      src/main/java/com/xc/service/impl/StockCoinServiceImpl.java
  30. 4 4
      src/main/java/com/xc/service/impl/StockIndexServiceImpl.java
  31. 2 2
      src/main/java/com/xc/service/impl/StockMarketsDayServiceImpl.java
  32. 21 61
      src/main/java/com/xc/service/impl/StockServiceImpl.java
  33. 2 2
      src/main/java/com/xc/service/impl/UserFuturesPositionServiceImpl.java
  34. 34 34
      src/main/java/com/xc/service/impl/UserIndexPositionServiceImpl.java
  35. 89 150
      src/main/java/com/xc/service/impl/UserPositionServiceImpl.java
  36. 42 243
      src/main/java/com/xc/service/impl/UserServiceImpl.java
  37. 1 1
      src/main/java/com/xc/service/impl/UserWithdrawServiceImpl.java
  38. 3 3
      src/main/java/com/xc/utils/enumUtil/IndexEnum.java
  39. 10 0
      src/main/java/com/xc/utils/stock/StockTableUtils.java
  40. 2 2
      src/main/java/com/xc/utils/stock/sina/SinaStockApi.java
  41. 1 1
      src/main/java/com/xc/vo/index/SymbolInfoVo.java
  42. 1 1
      src/main/java/com/xc/vo/index/SymbolVo.java
  43. 22 0
      src/main/java/com/xc/vo2/HistoryVo.java
  44. 250 0
      src/main/java/com/xc/vo2/StockDbVO.java
  45. 14 0
      src/main/java/com/xc/vo2/StockPriceVo.java
  46. 10 0
      src/main/java/com/xc/vo2/StockVolumeVo.java
  47. 14 104
      src/main/java/mappers/StockMapper.xml
  48. 300 0
      src/main/java/mappers2/KLinkStockMapper.xml
  49. 86 0
      src/main/java/mappers2/StockRestDataMapper.xml
  50. 83 12
      src/main/resources/applicationContext-datasource.xml
  51. 5 0
      src/main/resources/datasource.properties
  52. 1 1
      src/main/resources/logback.xml
  53. 4 4
      src/main/resources/stock2guo.properties

+ 2 - 2
src/main/java/com/xc/controller/AdminApiController.java

@@ -81,14 +81,14 @@ public class AdminApiController {
         return this.iSiteAdminService.authCharge(token, state, orderSn);
     }
 
-    //查询风控设置 指数分控信息
+    //查询风控设置 货币分控信息
     @RequestMapping({"getSetting.do"})
     @ResponseBody
     public ServerResponse getSetting() {
         return ServerResponse.createBySuccess(this.iSiteSettingService.getSiteSetting());
     }
 
-    //查询风控设置 指数风控信息
+    //查询风控设置 货币风控信息
     @RequestMapping({"getIndexSetting.do"})
     @ResponseBody
     public ServerResponse getIndexSetting() {

+ 7 - 7
src/main/java/com/xc/controller/StockApiController.java

@@ -19,21 +19,21 @@ public class StockApiController {
     @Autowired
     IStockService iStockService;
 
-    //获取指数列表
+    //获取货币列表
     @RequestMapping({"getStockInfoList.do"})
     @ResponseBody
     public ServerResponse getStockInfoList() {
         return ServerResponse.createBySuccess(iStockService.getStockInfoList());
     }
 
-    //查询 指数指数、大盘指数信息
+    //查询 货币货币、大盘货币信息
     @RequestMapping({"getMarket.do"})
     @ResponseBody
     public ServerResponse getMarket() {
         return this.iStockService.getMarket();
     }
 
-    //查询官网PC端交易 所有指数信息及指定指数信息
+    //查询官网PC端交易 所有货币信息及指定货币信息
     @RequestMapping({"getStock.do"})
     @ResponseBody
     public ServerResponse getStock(@RequestParam(value = "num", defaultValue = "0") int num,
@@ -45,7 +45,7 @@ public class StockApiController {
         return this.iStockService.getStock(num,pageNum, pageSize, keyWords, stockPlate, stockType);
     }
 
-    //通过指数代码查询指数信息
+    //通过货币代码查询货币信息
     @RequestMapping({"getSingleStock.do"})
     @ResponseBody
     public ServerResponse getSingleStock(@RequestParam("code") String code) {
@@ -58,17 +58,17 @@ public class StockApiController {
         return this.iStockService.getMinK(code, time, ma, size);
     }
 
-    //查询指数历史数据数据
+    //查询货币历史数据数据
     @RequestMapping({"getMinK_Echarts.do"})
     @ResponseBody
     public ServerResponse getMinK_Echarts(@RequestParam("code") String code, @RequestParam("time") Integer time, @RequestParam("ma") Integer ma, @RequestParam("size") Integer size) {
         return this.iStockService.getMinK_Echarts(code, time, ma, size);
     }
 
-    //通过指数代码查询指数信息
+    //通过货币代码查询货币信息
     @RequestMapping({"getSingleStockConfig.do"})
     @ResponseBody
     public ServerResponse getSingleStockConfig(@RequestParam("code") String code) {
         return this.iStockService.getSingleStockConfig(code);
     }
-}
+}

+ 1 - 1
src/main/java/com/xc/controller/StockIndexApiController.java

@@ -21,7 +21,7 @@ public class StockIndexApiController {
     @Autowired
     IStockIndexService iStockIndexService;
 
-    //查询指数信息
+    //查询货币信息
     @RequestMapping({"queryHomeIndex.do"})
     @ResponseBody
     public ServerResponse queryHomeIndex() {

+ 2 - 2
src/main/java/com/xc/controller/agent/AgentController.java

@@ -70,7 +70,7 @@ public class AgentController {
         return this.iUserService.addSimulatedAccount(agentUser.getId(), phone, pwd, amt, accountType, false);
     }
 
-    //查询指数统计指定时间内,代理客户(已平仓)的交易盈亏
+    //查询货币统计指定时间内,代理客户(已平仓)的交易盈亏
     @RequestMapping({"getIncome.do"})
     @ResponseBody
     public ServerResponse getIncome(@RequestParam(value = "agentId", required = false) Integer agentId, @RequestParam(value = "positionType", required = false) Integer positionType, @RequestParam(value = "beginTime", required = false) String beginTime, @RequestParam(value = "endTime", required = false) String endTime, HttpServletRequest request) {
@@ -81,7 +81,7 @@ public class AgentController {
         return this.iUserPositionService.getIncome(agentId, positionType, beginTime, endTime);
     }
 
-    //查询指数统计指定时间内,代理客户(已平仓)的交易盈亏
+    //查询货币统计指定时间内,代理客户(已平仓)的交易盈亏
     @RequestMapping({"getIndexIncome.do"})
     @ResponseBody
     public ServerResponse getIndexIncome(@RequestParam(value = "agentId", required = false) Integer agentId, @RequestParam(value = "positionType", required = false) Integer positionType, @RequestParam(value = "beginTime", required = false) String beginTime, @RequestParam(value = "endTime", required = false) String endTime, HttpServletRequest request) {

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 1 - 1
src/main/java/com/xc/controller/agent/AgentIndexPositionController.java


+ 2 - 2
src/main/java/com/xc/controller/backend/AdminAgentController.java

@@ -58,14 +58,14 @@ public class AdminAgentController {
         return this.iAgentUserService.update(agentUser);
     }
 
-    //查询指数持仓统计信息
+    //查询货币持仓统计信息
     @RequestMapping({"getIncome.do"})
     @ResponseBody
     public ServerResponse getIncome(@RequestParam(value = "agentId", required = false) Integer agentId, @RequestParam(value = "positionType", required = false) Integer positionType, @RequestParam(value = "beginTime", required = false) String beginTime, @RequestParam(value = "endTime", required = false) String endTime, HttpServletRequest request) {
         return this.iUserPositionService.getIncome(agentId, positionType, beginTime, endTime);
     }
 
-    //查询指数持仓统计信息
+    //查询货币持仓统计信息
     @RequestMapping({"getIndexIncome.do"})
     @ResponseBody
     public ServerResponse getIndexIncome(@RequestParam(value = "agentId", required = false) Integer agentId, @RequestParam(value = "positionType", required = false) Integer positionType, @RequestParam(value = "beginTime", required = false) String beginTime, @RequestParam(value = "endTime", required = false) String endTime, HttpServletRequest request) {

+ 1 - 1
src/main/java/com/xc/controller/backend/AdminController.java

@@ -80,7 +80,7 @@ public class AdminController {
         return this.iSiteAdminService.update(siteAdmin);
     }
 
-    //查询首页 资金情况、持仓情况、盈亏信息、提现情况、指数信息、代理信息
+    //查询首页 资金情况、持仓情况、盈亏信息、提现情况、货币信息、代理信息
     @RequestMapping({"count.do"})
     @ResponseBody
     public ServerResponse count() {

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 2 - 2
src/main/java/com/xc/controller/backend/AdminIndexPositionController.java


+ 1 - 1
src/main/java/com/xc/controller/backend/AdminSiteIndexSettingController.java

@@ -19,7 +19,7 @@ public class AdminSiteIndexSettingController {
     @Autowired
     ISiteIndexSettingService iSiteIndexSettingService;
 
-    //修改风控设置 指数风控信息
+    //修改风控设置 货币风控信息
     @RequestMapping({"update.do"})
     @ResponseBody
     public ServerResponse update(SiteIndexSetting siteIndexSetting) {

+ 2 - 2
src/main/java/com/xc/controller/backend/AdminSiteSettingController.java

@@ -20,10 +20,10 @@
      @Autowired
      ISiteSettingService iSiteSettingService;
 
-     //修改风控设置 指数风控信息
+     //修改风控设置 货币风控信息
      @RequestMapping({"update.do"})
      @ResponseBody
      public ServerResponse update(SiteSetting siteSetting) {
          return this.iSiteSettingService.update(siteSetting);
      }
- }
+ }

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 6 - 6
src/main/java/com/xc/controller/backend/AdminStockController.java


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 3 - 3
src/main/java/com/xc/controller/backend/AdminStockIndexController.java


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

@@ -23,7 +23,7 @@ import java.util.Date;
 import java.util.List;
 
 /**
- * 指数
+ * 货币
  */
 @Controller
 @RequestMapping({"/api/index/"})

+ 3 - 8
src/main/java/com/xc/controller/protol/UserController.java

@@ -69,7 +69,7 @@ public class UserController {
         return this.iUserService.isOptionadd(code, request);
     }
 
-    //用户下单买入指数
+    //用户下单买入货币
     @RequestMapping({"buy.do"})
     @ResponseBody
     public ServerResponse buy(@RequestParam("stockId") Integer stockId, @RequestParam("buyNum") Integer buyNum
@@ -121,7 +121,7 @@ public class UserController {
         try {
             serverResponse = this.iUserIndexPositionService.buyIndex(indexId, buyNum, buyType, request);
         } catch (Exception e) {
-            log.error("用户下单指数操作 = {}", e);
+            log.error("用户下单货币操作 = {}", e);
         }
         return serverResponse;
     }
@@ -133,7 +133,7 @@ public class UserController {
         try {
             serverResponse = this.iUserIndexPositionService.sellIndex(positionSn, 1);
         } catch (Exception e) {
-            log.error("用户平仓指数操作 = {}", e);
+            log.error("用户平仓货币操作 = {}", e);
         }
         return serverResponse;
     }
@@ -204,18 +204,13 @@ public class UserController {
     @ResponseBody
     public ServerResponse upload(HttpSession session, @RequestParam(value = "upload_file", required = false) MultipartFile file, HttpServletRequest request) {
         String path = request.getSession().getServletContext().getRealPath("upload");
-
         ServerResponse serverResponse = this.iFileUploadService.upload(file, path);
         if (serverResponse.isSuccess()) {
             String targetFileName = serverResponse.getData().toString();
             String url = PropertiesUtil.getProperty("ftp.server.http.prefix") + targetFileName;
-            System.out.println(targetFileName+"jkl");
-            System.out.println(url+"uzi");
-
             Map fileMap = Maps.newHashMap();
             fileMap.put("uri", targetFileName);
             fileMap.put("url", url);
-
             return ServerResponse.createBySuccess(fileMap);
         }
         return serverResponse;

+ 1 - 1
src/main/java/com/xc/controller/protol/UserOptionController.java

@@ -21,7 +21,7 @@ public class UserOptionController {
     @Autowired
     IStockOptionService iStockOptionService;
 
-    //查询所有自选指数信息及模糊查询
+    //查询所有自选货币信息及模糊查询
     @RequestMapping({"list.do"})
     @ResponseBody
     public ServerResponse list(@RequestParam(value = "typeId",defaultValue = "0")int typeId,@RequestParam(value = "hcrate",defaultValue = "0")int hcrate,HttpServletRequest request, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(value = "pageSize", defaultValue = "10") int pageSize, @RequestParam(value = "keyWords", required = false) String keyWords) {

+ 10 - 10
src/main/java/com/xc/dao/StockCoinMapper.java

@@ -9,23 +9,23 @@ import org.apache.ibatis.annotations.Param;
 
 public interface StockCoinMapper {
   int deleteByPrimaryKey(Integer paramInteger);
-  
+
   int insert(StockCoin paramStockCoin);
-  
+
   int insertSelective(StockCoin paramStockCoin);
-  
+
   StockCoin selectByPrimaryKey(Integer paramInteger);
-  
+
   int updateByPrimaryKeySelective(StockCoin paramStockCoin);
-  
+
   int updateByPrimaryKey(StockCoin paramStockCoin);
-  
-  List listByAdmin(@Param("coinName") String paramString1, @Param("coinCode") String paramString2);
-  
+
+  List<StockCoin> listByAdmin(@Param("coinName") String paramString1, @Param("coinCode") String paramString2);
+
   StockCoin selectCoinByName(String paramString);
-  
+
   StockCoin selectCoinByCode(String paramString);
-  
+
   StockCoin selectCoinByGid(String paramString);
 
   StockCoin getSelectCoin();

+ 2 - 4
src/main/java/com/xc/dao/StockMapper.java

@@ -18,9 +18,7 @@ public interface StockMapper {
 
   int updateByPrimaryKeySelective(Stock paramStock);
 
-  int updateByPrimaryKey(Stock paramStock);
-
-  List findStockListByKeyWords(@Param("keyWords") String paramString1, @Param("stockPlate") String paramString2, @Param("stockType") String paramString3, @Param("show") Integer paramInteger);
+  List<Stock> findStockListByKeyWords(@Param("keyWords") String paramString1, @Param("stockPlate") String paramString2, @Param("stockType") String paramString3, @Param("show") Integer paramInteger);
 
   List findStockListByKeyWords2(@Param("keyWords") String paramString1, @Param("stockType") String paramString3, @Param("show") Integer paramInteger);
 
@@ -48,4 +46,4 @@ public interface StockMapper {
 
   StockIndexDF selectStockDateByDf(@Param("dbTableName") String dbTableName);
 
-}
+}

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

@@ -8,45 +8,45 @@ import org.apache.ibatis.annotations.Param;
 
 public interface UserPositionMapper {
   int deleteByPrimaryKey(Integer paramInteger);
-  
+
   int insert(UserPosition paramUserPosition);
-  
+
   int insertSelective(UserPosition paramUserPosition);
-  
+
   UserPosition selectByPrimaryKey(Integer paramInteger);
 
   UserPosition selectByPrimaryKeyAndStatus(Integer paramInteger);
-  
+
   int updateByPrimaryKeySelective(UserPosition paramUserPosition);
-  
+
   int updateByPrimaryKey(UserPosition paramUserPosition);
-  
+
   UserPosition findPositionBySn(String paramString);
 
   UserPosition findPositionById(int id);
-  
-  List findMyPositionByCodeAndSpell(@Param("uid") Integer paramInteger1, @Param("stockCode") String paramString1, @Param("stockSpell") String paramString2, @Param("state") Integer paramInteger2);
+
+  List<UserPosition> findMyPositionByCodeAndSpell(@Param("uid") Integer paramInteger1, @Param("stockCode") String paramString1, @Param("stockSpell") String paramString2, @Param("state") Integer paramInteger2);
 
   List findMyPositionAll(@Param("uid") Integer paramInteger1);
 
   List findPositionByUserIdAndSellIdIsNull(Integer paramInteger);
-  
+
   List listByAgent(@Param("positionType") Integer positionType, @Param("state") Integer state, @Param("userId") Integer userId, @Param("searchId") Integer searchId, @Param("positionSn") String positionSn, @Param("beginTime") Date beginTime, @Param("endTime") Date endTime);
-  
+
   List findAllStayPosition();
-  
+
   List findDistinctUserIdList();
-  
+
   int CountPositionNum(@Param("state") Integer paramInteger1, @Param("accountType") Integer paramInteger2);
-  
+
   BigDecimal CountPositionProfitAndLose();
-  
+
   BigDecimal CountPositionAllProfitAndLose();
-  
+
   int deleteByUserId(@Param("userId") Integer paramInteger);
-  
+
   List findPositionByStockCodeAndTimes(@Param("minuteTimes") Date paramDate, @Param("stockCode") String paramString, @Param("userId") Integer paramInteger);
-  
+
   Integer findPositionNumByTimes(@Param("beginDate") Date paramDate, @Param("userId") Integer paramInteger);
 
   List findPositionAmt(@Param("userId")Integer userId,@Param("stockCode")String stockCode);
@@ -55,7 +55,7 @@ public interface UserPositionMapper {
 
   void updateStopProfitTarget(@Param("id")int id, @Param("targetprofit") BigDecimal targetprofit, @Param("stoploss") BigDecimal stoploss);
 
-  List selectPositionByUserId(@Param("userId") Integer userId);
+  List<UserPosition> selectPositionByUserId(@Param("userId") Integer userId);
 
   List<Integer> selectPositionUserId();
 

+ 26 - 0
src/main/java/com/xc/dao2/KLinkStockMapper.java

@@ -0,0 +1,26 @@
+package com.xc.dao2;
+
+import com.xc.vo2.HistoryVo;
+import com.xc.vo2.StockPriceVo;
+import com.xc.vo2.StockVolumeVo;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+public interface KLinkStockMapper {
+
+    List<HistoryVo> getHistoryNew(@Param("dbTableName") String dbTableName, @Param("startDate") Long from, @Param("endDate") Long to);
+
+    List<HistoryVo> getDataByRt(@Param("dbTableName") String dbTableName, @Param("startDate") Long from, @Param("endDate") Long to, @Param("resolution") String resolution);
+
+    List<HistoryVo> getDataByHist(@Param("dbTableName") String dbTableName, @Param("startDate") Long from, @Param("endDate") Long to, @Param("resolution") String resolution);
+
+    List<StockPriceVo> selectPriceList(@Param("dbTableName") String tableName, @Param("startTime") Long startTime, @Param("endTime") Long endTime);
+
+    StockVolumeVo selectByDateGroup(@Param("dbTableName") String tableName, @Param("nearTime") Long nearTime, @Param("resolution") String resolution);
+
+    Integer selectDateOneCount(@Param("dbTableName") String tableName);
+
+    List<HistoryVo> selectDateOne(@Param("dbTableName") String dbTableName, @Param("startDate") Long from, @Param("endDate") Long to);
+
+}

+ 12 - 0
src/main/java/com/xc/dao2/StockRestDataMapper.java

@@ -0,0 +1,12 @@
+package com.xc.dao2;
+
+import com.xc.vo2.StockDbVO;
+import org.apache.ibatis.annotations.Param;
+
+public interface StockRestDataMapper {
+
+    StockDbVO selectRestDataByGid(@Param("dbTableName") String dbTableName);
+
+    StockDbVO selectRestDataByGidDateOne(@Param("dbTableName") String dbTableName);
+
+}

+ 2 - 2
src/main/java/com/xc/pojo/RealTimeIndex.java

@@ -3,13 +3,13 @@ package com.xc.pojo;
 import java.util.Date;
 
 /**
- * 实时指数实体类
+ * 实时货币实体类
  */
 public class RealTimeIndex {
 
     private int id;
 
-    private String code; //'指数'
+    private String code; //'货币'
 
     private String date; // '日期'
 

+ 6 - 15
src/main/java/com/xc/pojo/Stock.java

@@ -39,12 +39,12 @@ public class Stock {
     private Integer listShow;//列表显示状态:默认0 不显示 1 显示
     private Integer transState;//交易状态:0 不可交易 1 可交易
     //    private Integer tDesc;//排序
-    // 控制指数
+    // 控制货币
     private BigDecimal riskParam;//风控参数 getSetting.do
     private BigDecimal eachPoint;//最小价格波动
     private Integer floatRate;    //涨跌 1涨 0跌
     private Integer control;    //是否启用控制
-    private String dataDbName;//指数名称
+    private String dataDbName;//货币名称
     //不保存数据
     private String nowPrice;
     private BigDecimal hcrate;
@@ -52,19 +52,10 @@ public class Stock {
 
     private String change; //  '涨跌',
     private String pctChange; // '涨跌幅',
+    private Integer siteLever;//杠杆
+
     public Stock() {}
 
-//    public Stock(Integer id, String stockName, String stockCode, String stockSpell, String stockType, String stockGid, String stockPlate, Integer isLock, Integer isShow, Date addTime) {
-//        this.id = id;
-//        this.stockName = stockName;
-//        this.stockCode = stockCode;
-//        this.stockSpell = stockSpell;
-//        this.stockType = stockType;
-//        this.stockGid = stockGid;
-//        this.stockPlate = stockPlate;
-//        this.isLock = isLock;
-//        this.isShow = isShow;
-//        this.addTime = addTime;
-//    }
 
-}
+
+}

+ 3 - 3
src/main/java/com/xc/pojo/UserCapitalDetail.java

@@ -22,9 +22,9 @@ public class UserCapitalDetail {
 
     private Integer deType; // 类型 1买入 2卖出
 
-    private String stockName; // 持仓指数
+    private String stockName; // 持仓货币
 
-    private String stockCode; // 指数代码
+    private String stockCode; // 货币代码
 
     private Integer orderNum; // 手数
 
@@ -44,4 +44,4 @@ public class UserCapitalDetail {
 
     private Date addTime; // 时间
 
-}
+}

+ 12 - 0
src/main/java/com/xc/service/DbStockService.java

@@ -0,0 +1,12 @@
+package com.xc.service;
+
+import com.xc.vo.stock.StockListVO;
+import com.xc.vo.stock.StockVO;
+
+public interface DbStockService {
+
+    StockVO getStock(String stockGid);
+
+    StockListVO getStockListVO(String stockGid);
+
+}

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

@@ -31,7 +31,7 @@ public interface IndexApiService {
     HistoryIndex getHistoryNew(String symbol, String resolution, Long from, Long to);
 
     /**
-     * 根据指数类型和时间查找数据
+     * 根据货币类型和时间查找数据
      *
      * @param indexCode
      * @param time
@@ -40,7 +40,7 @@ public interface IndexApiService {
     RealTimeIndex getRealTimeData(String indexCode, Date time);
 
     /**
-     * 根据指数类型和时间查找数据
+     * 根据货币类型和时间查找数据
      *
      * @param indexCode
      * @param time

+ 85 - 0
src/main/java/com/xc/service/impl/DbStockServiceImpl.java

@@ -0,0 +1,85 @@
+package com.xc.service.impl;
+
+
+import com.xc.dao2.KLinkStockMapper;
+import com.xc.dao2.StockRestDataMapper;
+import com.xc.service.DbStockService;
+import com.xc.vo.stock.StockListVO;
+import com.xc.vo.stock.StockVO;
+import com.xc.vo2.StockDbVO;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+
+@Service
+public class DbStockServiceImpl implements DbStockService {
+
+    @Autowired
+    private StockRestDataMapper stockRestDataMapper;
+
+    @Autowired
+    private KLinkStockMapper kLinkStockMapper;
+
+    private StockDbVO getStockDb(String stockGid) {
+        String dbTableName = String.format("data_rt_%s",stockGid);
+        StockDbVO stockDbVO;
+        if(kLinkStockMapper.selectDateOneCount(dbTableName) <= 0) {
+            stockDbVO = stockRestDataMapper.selectRestDataByGidDateOne(dbTableName);
+        }else{
+            stockDbVO = stockRestDataMapper.selectRestDataByGid(dbTableName);
+        }
+//        StockDbVO stockDbVO = stockRestDataMapper.selectRestDataByGid(dbTableName);
+        if(null == stockDbVO){
+            return new StockDbVO();
+        }
+        double d = Double.parseDouble(stockDbVO.getBusiness_amount());
+        long businessAmount = (long) d;
+        stockDbVO.setBusiness_amount(businessAmount + "");
+        double balance = Double.parseDouble(stockDbVO.getBusiness_balance());
+        long businessBalance = (long) balance;
+        if (balance > 10000) {
+            stockDbVO.setBusiness_balance((int) (businessBalance / 10000) + "万");
+        } else {
+            stockDbVO.setBusiness_balance(String.valueOf(balance));
+        }
+        stockDbVO.setChange(new BigDecimal(stockDbVO.getNowPrice()).subtract(new BigDecimal(stockDbVO.getPreclose_px())));
+        BigDecimal preClose = new BigDecimal(stockDbVO.getPreclose_px());
+        if(!(preClose.compareTo(BigDecimal.ZERO) == 0)){
+            stockDbVO.setHcrate(stockDbVO.getChange().multiply(new BigDecimal(100).divide(preClose,2, RoundingMode.HALF_UP)));
+        }else{
+            stockDbVO.setHcrate(stockDbVO.getChange().multiply(new BigDecimal(100)));
+        }
+        return stockDbVO;
+    }
+
+
+
+    @Override
+    public StockVO getStock(String stockGid) {
+        StockDbVO stockDbVO;
+        stockDbVO = getStockDb(stockGid);
+        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());
+        return stockVO;
+    }
+
+    @Override
+    public StockListVO getStockListVO(String stockGid) {
+        StockDbVO stockDbVO;
+        stockDbVO = getStockDb(stockGid);
+        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());
+        return stockListVO;
+    }
+
+
+}
+

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

@@ -33,7 +33,7 @@ public class NewsServiceImpl implements NewsService {
     public ServerResponse<News> getApiNews(Integer num, Integer start) {
         String APPKEY = PropertiesUtil.getProperty("jisuapi.appkey");// 你的appkey
         String minUrl = PropertiesUtil.getProperty("jisuapi.news.url");
-        String channel = PropertiesUtil.getProperty("jisuapi.news.channel");// utf8  新闻频道(头条,财经,体育,娱乐,军事,教育,科技,NBA,指数,星座,女性,健康,育儿)
+        String channel = PropertiesUtil.getProperty("jisuapi.news.channel");// utf8  新闻频道(头条,财经,体育,娱乐,军事,教育,科技,NBA,货币,星座,女性,健康,育儿)
         try {
             minUrl = minUrl + "?channel=" + URLEncoder.encode(channel, "utf-8") + "&num=" + num + "&start=" + start + "&appkey=" + APPKEY;
         } catch (UnsupportedEncodingException e) {

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

@@ -64,7 +64,7 @@ public class SiteIndexSettingServiceImpl
 
         if (dbsetting == null) {
 
-            return ServerResponse.createByErrorMsg("不存在该指数");
+            return ServerResponse.createByErrorMsg("不存在该货币");
 
         }
 
@@ -98,4 +98,4 @@ public class SiteIndexSettingServiceImpl
 
     }
 
-}
+}

+ 2 - 14
src/main/java/com/xc/service/impl/StockCoinServiceImpl.java

@@ -44,32 +44,20 @@ public class StockCoinServiceImpl implements IStockCoinService {
 
 
     public ServerResponse<PageInfo> listByAdmin(String coinName, String coinCode, int pageNum, int pageSize) {
-
         PageHelper.startPage(pageNum, pageSize);
-
         List<StockCoin> stockCoins = this.stockCoinMapper.listByAdmin(coinName, coinCode);
-
-
         List<CoinAdminListVO> coinAdminListVOS = Lists.newArrayList();
-
         for (StockCoin stockCoin : stockCoins) {
-
             CoinAdminListVO coinAdminListVO = assembleCoinAdminListVO(stockCoin);
-
             coinAdminListVOS.add(coinAdminListVO);
-
         }
-
-
         PageInfo pageInfo = new PageInfo(stockCoins);
-
         pageInfo.setList(coinAdminListVOS);
-
-
         return ServerResponse.createBySuccess(pageInfo);
-
     }
 
+
+
     private CoinAdminListVO assembleCoinAdminListVO(StockCoin stockCoin) {
 
         CoinAdminListVO coinAdminListVO = new CoinAdminListVO();

+ 4 - 4
src/main/java/com/xc/service/impl/StockIndexServiceImpl.java

@@ -111,11 +111,11 @@ public class StockIndexServiceImpl implements IStockIndexService {
 
         StockIndex nameIndex = this.stockIndexMapper.selectIndexByName(stockIndex.getIndexName());
         if (nameIndex != null) {
-            return ServerResponse.createByErrorMsg("指数名称已存在");
+            return ServerResponse.createByErrorMsg("货币名称已存在");
         }
         StockIndex codeIndex = this.stockIndexMapper.selectIndexByCode(stockIndex.getIndexCode());
         if (codeIndex != null) {
-            return ServerResponse.createByErrorMsg("指数代码已存在");
+            return ServerResponse.createByErrorMsg("货币代码已存在");
         }
 
         stockIndex.setAddTime(new Date());
@@ -184,7 +184,7 @@ public class StockIndexServiceImpl implements IStockIndexService {
             result = HttpClientRequest.doGet(market_url);
 
         } catch (Exception e) {
-            log.error("获取 大盘指数 出错 e = {}", e);
+            log.error("获取 大盘货币 出错 e = {}", e);
         }
 
 
@@ -205,7 +205,7 @@ public class StockIndexServiceImpl implements IStockIndexService {
 
 
         } catch (Exception e) {
-            log.error("转换大盘指数出错 str = {} ,  e = {}", result, e);
+            log.error("转换大盘货币出错 str = {} ,  e = {}", result, e);
         }
 
         return marketVO;

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

@@ -55,7 +55,7 @@ public class StockMarketsDayServiceImpl implements IStockMarketsDayService {
     private IUserPositionService userPositionService;
 
     public void saveStockMarketDay() {
-        log.info("【保存指数日内行情 定时任务】 开始保存 ... ");
+        log.info("【保存货币日内行情 定时任务】 开始保存 ... ");
 
         List<Stock> stockList = this.iStockService.findStockList();
 
@@ -109,7 +109,7 @@ public class StockMarketsDayServiceImpl implements IStockMarketsDayService {
 
             }
 
-            log.error("保存指数 {} 失败, 时间 = {}", stock.getStockName(), ymd_date);
+            log.error("保存货币 {} 失败, 时间 = {}", stock.getStockName(), ymd_date);
 
         }
 

+ 21 - 61
src/main/java/com/xc/service/impl/StockServiceImpl.java

@@ -8,10 +8,8 @@ import com.xc.config.StockPoll;
 import com.xc.dao.RealTimeMapper;
 import com.xc.dao.StockIndexMapper;
 import com.xc.dao.StockMapper;
-import com.xc.pojo.IndexInfo;
-import com.xc.pojo.Stock;
-import com.xc.pojo.StockIndex;
-import com.xc.pojo.StockIndexDF;
+import com.xc.pojo.*;
+import com.xc.service.DbStockService;
 import com.xc.service.IStockMarketsDayService;
 import com.xc.service.IStockService;
 import com.xc.service.IUserPositionService;
@@ -68,6 +66,9 @@ public class StockServiceImpl implements IStockService {
     @Autowired
     private IUserPositionService userPositionService;
 
+    @Autowired
+    DbStockService dbStockService;
+
     public ServerResponse getMarket() {
         String market_url = PropertiesUtil.getProperty("sina.market.url");
         String result = null;
@@ -103,28 +104,12 @@ public class StockServiceImpl implements IStockService {
     public ServerResponse getStock(int num, int pageNum, int pageSize, String keyWords, String stockPlate, String stockType) {
         List<Stock> stockList = null;
         PageHelper.startPage(pageNum, pageSize);
-        if (num == 1) {
-            stockList = this.stockMapper.findStockListByKeyWords2(keyWords, stockType, 0);
-        } else {
-            stockList = this.stockMapper.findStockListByKeyWords(keyWords, stockPlate, stockType, 0);
-        }
-        List<IndexInfo> indexInfoList = stockMapper.selectStockList();
-        Map<String, StockIndexDF> indexMap = new HashMap<>();
-        for (IndexInfo indexInfo : indexInfoList) {
-            if (StringUtils.isNotEmpty(indexInfo.getDataDbName())) {
-                try {
-                    StockIndexDF stockIndexDF =  userPositionService.getStockIndexDFByDbName(indexInfo.getDataDbName());
-                    stockIndexDF.setCnName(indexInfo.getCnName());
-                    indexMap.put(indexInfo.getCnName(), stockIndexDF);
-                } catch (Exception e) {
-                    // 数据库不存在
-                    log.info("数据库不存在");
-                }
-            }
-        }
+        stockList = this.stockMapper.findStockListByKeyWords(keyWords, stockPlate, stockType, 0);
         List<StockListVO> stockListVOS = Lists.newArrayList();
         for (Stock stock : stockList) {
-            StockListVO stockListVO = SinaStockApi.assembleStockListVO(indexMap.get(stock.getStockName()));
+            StockListVO stockListVO = dbStockService.getStockListVO(stock.getStockGid());
+            stockListVO.setName(stock.getStockName());
+//            stockListVO.setId(stock.getId());
             stockListVO.setCode(stock.getStockCode());
             stockListVO.setSpell(stock.getStockSpell());
             stockListVO.setGid(stock.getStockGid());
@@ -132,12 +117,8 @@ public class StockServiceImpl implements IStockService {
             stockListVO.setDay3Rate(day3Rate);
             stockListVO.setStock_plate(stock.getStockPlate());
             stockListVO.setStock_type(stock.getStockType());
-            //判断交易时间
-            if (isTransState(stock)) {
-                stockListVO.setTransState(1);
-            }else{
-                stockListVO.setTransState(0);
-            }
+//            stockListVO.setTransState(isTransState);
+//            stockListVO.setBuyLimit(stock.getBuyLimit());
             stockListVOS.add(stockListVO);
         }
         PageInfo pageInfo = new PageInfo(stockList);
@@ -269,38 +250,19 @@ public class StockServiceImpl implements IStockService {
         if (stock == null) {
             return ServerResponse.createByErrorMsg("");
         }
-//        String gid = stock.getStockGid();
-//        String sinaResult = SinaStockApi.getSinaStock(gid);
         try {
-            Integer orderNum = userPositionService.getTodayOrderNum(stock.getStockName());
-            StockIndexDF stockIndexDF = userPositionService.getStockIndexDFByDbName(stock.getDataDbName());
-            stockIndexDF.setCnName(stock.getStockName());
-            StockVO stockVO = SinaStockApi.assembleStockVO(stockIndexDF, orderNum);
-            stockVO.setId(stock.getId().intValue());
+            String gid = stock.getStockGid();
+            StockVO stockVO = dbStockService.getStock(gid);
+            stockVO.setName(stock.getStockName());
+            stockVO.setId(stock.getId());
             stockVO.setCode(stock.getStockCode());
             stockVO.setSpell(stock.getStockSpell());
-            stockVO.setDepositAmt(stock.getDepositAmt());
-            if (isTransState(stock)) {
-                stockVO.setTransState(1);
-            }else{
-                stockVO.setTransState(0);
-            }
-//            stockVO.setGid(stock.getStockGid());
-//            stockVO.setMinImg(PropertiesUtil.getProperty("sina.single.stock.min.url") + stock.getStockGid() + ".jpg");
-//            stockVO.setDayImg(PropertiesUtil.getProperty("sina.single.stock.day.url") + stock.getStockGid() + ".jpg");
-//            stockVO.setWeekImg(PropertiesUtil.getProperty("sina.single.stock.week.url") + stock.getStockGid() + ".jpg");
-//            stockVO.setMonthImg(PropertiesUtil.getProperty("sina.single.stock.month.url") + stock.getStockGid() + ".jpg");
+            stockVO.setGid(stock.getStockGid());
+//            stockVO.setBuyLimit(stock.getBuyLimit());
+//            stockVO.setStockOrBond(stock.getStockOrBond());
             return ServerResponse.createBySuccess(stockVO);
         } catch (Exception e) {
             StockVO stockVO = new StockVO();
-//            stockVO.setId(stock.getId().intValue());
-//            stockVO.setCode(stock.getStockCode());
-//            stockVO.setSpell(stock.getStockSpell());
-//            stockVO.setGid(stock.getStockGid());
-//            stockVO.setMinImg(PropertiesUtil.getProperty("sina.single.stock.min.url") + stock.getStockGid() + ".jpg");
-//            stockVO.setDayImg(PropertiesUtil.getProperty("sina.single.stock.day.url") + stock.getStockGid() + ".jpg");
-//            stockVO.setWeekImg(PropertiesUtil.getProperty("sina.single.stock.week.url") + stock.getStockGid() + ".jpg");
-//            stockVO.setMonthImg(PropertiesUtil.getProperty("sina.single.stock.month.url") + stock.getStockGid() + ".jpg");
             return ServerResponse.createBySuccess(stockVO);
         }
     }
@@ -351,13 +313,11 @@ public class StockServiceImpl implements IStockService {
         PageHelper.startPage(pageNum, pageSize);
         List<Stock> stockList = this.stockMapper.listByAdmin(showState, lockState, code, name, stockPlate, stockType);
         for (Stock stock : stockList) {
-            StockIndexDF stockIndexDF = userPositionService.getStockIndexDFByDbName(stock.getDataDbName());
-            StockListVO stockListVO = SinaStockApi.assembleStockListVO(stockIndexDF);
+            StockListVO stockListVO = dbStockService.getStockListVO(stock.getStockGid());
             stock.setNowPrice(stockListVO.getNowPrice());
             stock.setHcrate(stockListVO.getHcrate());
-            stock.setChange(stockIndexDF.getChange());
-            stock.setPctChange(stockIndexDF.getPctChange());
-
+//            stock.setChange(stockListVO.getChange());
+//            stock.setPctChange(stockListVO.getPctChange());
             ServerResponse serverResponse = selectRateByDaysAndStockCode(stock.getStockCode(), 3);
             BigDecimal day3Rate = new BigDecimal("0");
             if (serverResponse.isSuccess())

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

@@ -155,7 +155,7 @@ public class UserFuturesPositionServiceImpl implements IUserFuturesPositionServi
             return ServerResponse.createByErrorMsg("失败,融资总资金小于0");
         }
         if (user.getUserIndexAmt().compareTo(new BigDecimal("0")) == -1) {
-            return ServerResponse.createByErrorMsg("失败,指数总资金小于0");
+            return ServerResponse.createByErrorMsg("失败,货币总资金小于0");
         }
 
 
@@ -319,7 +319,7 @@ public class UserFuturesPositionServiceImpl implements IUserFuturesPositionServi
         ucd.setAgentName(user.getAgentName());
         ucd.setUserId(user.getId());
         ucd.setUserName(user.getRealName());
-        ucd.setDeType("指数盈亏");
+        ucd.setDeType("货币盈亏");
         ucd.setDeAmt(all_profit);
         ucd.setDeSummary("卖出期货," + userFuturesPosition.getFuturesName() + "/" + userFuturesPosition
                 .getFuturesCode() + ",总盈亏:" + all_profit);

+ 34 - 34
src/main/java/com/xc/service/impl/UserIndexPositionServiceImpl.java

@@ -78,7 +78,7 @@ public class UserIndexPositionServiceImpl implements IUserIndexPositionService {
             return ServerResponse.createByErrorMsg("下单失败,请先实名认证");
         }
 
-        log.info("用户 {} 下单, 指数id = {} ,数量 = {} 手 , 方向 = {}", new Object[]{user
+        log.info("用户 {} 下单, 货币id = {} ,数量 = {} 手 , 方向 = {}", new Object[]{user
                 .getId(), indexId, buyNum, buyType});
 
         if (user.getIsLock().intValue() == 1) {
@@ -88,7 +88,7 @@ public class UserIndexPositionServiceImpl implements IUserIndexPositionService {
 
         SiteIndexSetting siteIndexSetting = this.iSiteIndexSettingService.getSiteIndexSetting();
         if (siteIndexSetting == null) {
-            log.error("下单出错,指数设置表不存在");
+            log.error("下单出错,货币设置表不存在");
             return ServerResponse.createByErrorMsg("下单失败,系统设置错误");
         }
 
@@ -107,17 +107,17 @@ public class UserIndexPositionServiceImpl implements IUserIndexPositionService {
 
         StockIndex stockIndex = this.iStockIndexService.selectIndexById(indexId);
         if (stockIndex == null) {
-            return ServerResponse.createByErrorMsg("指数不存在");
+            return ServerResponse.createByErrorMsg("货币不存在");
         }
         if (1 != stockIndex.getTransState().intValue()) {
-            return ServerResponse.createByErrorMsg("该指数不能交易");
+            return ServerResponse.createByErrorMsg("该货币不能交易");
         }
 
 
         BigDecimal all_deposit_amt = (new BigDecimal(stockIndex.getDepositAmt().intValue())).multiply(new BigDecimal(buyNum.intValue()));
 
         if (user.getEnableIndexAmt().compareTo(all_deposit_amt) == -1) {
-            return ServerResponse.createByErrorMsg("指数账户资金不足");
+            return ServerResponse.createByErrorMsg("货币账户资金不足");
         }
 
         BigDecimal max_buy_amt = user.getEnableIndexAmt().multiply(siteIndexSetting.getBuyMaxPercent());
@@ -133,7 +133,7 @@ public class UserIndexPositionServiceImpl implements IUserIndexPositionService {
 
 
         MarketVO marketVO = this.iStockIndexService.querySingleIndex(stockIndex.getIndexGid());
-        log.info("当前指数行情 = {}", JsonUtil.obj2StringPretty(marketVO));
+        log.info("当前货币行情 = {}", JsonUtil.obj2StringPretty(marketVO));
 
 
         BigDecimal increaseRate = new BigDecimal(marketVO.getIncreaseRate());
@@ -142,7 +142,7 @@ public class UserIndexPositionServiceImpl implements IUserIndexPositionService {
             if (siteIndexSetting.getRiseLimit().multiply(new BigDecimal("100"))
                     .compareTo(increaseRate) == -1 && buyType
                     .intValue() == 0) {
-                return ServerResponse.createByErrorMsg("当前指数涨幅:" + increaseRate + ",不能做多");
+                return ServerResponse.createByErrorMsg("当前货币涨幅:" + increaseRate + ",不能做多");
             }
         } else {
 
@@ -150,7 +150,7 @@ public class UserIndexPositionServiceImpl implements IUserIndexPositionService {
             if (siteIndexSetting.getRiseLimit().multiply(new BigDecimal("100"))
                     .compareTo(increaseRate) == -1 && buyType
                     .intValue() == 1) {
-                return ServerResponse.createByErrorMsg("当前指数跌幅:" + increaseRate + ",不能做空");
+                return ServerResponse.createByErrorMsg("当前货币跌幅:" + increaseRate + ",不能做空");
             }
         }
 
@@ -159,10 +159,10 @@ public class UserIndexPositionServiceImpl implements IUserIndexPositionService {
         user.setEnableIndexAmt(reckon_enable);
         int updateUserCount = this.userMapper.updateByPrimaryKeySelective(user);
         if (updateUserCount > 0) {
-            log.info("【用户交易指数下单】修改用户金额成功");
+            log.info("【用户交易货币下单】修改用户金额成功");
         } else {
-            log.error("用户交易指数下单】修改用户金额出错");
-            throw new Exception("用户交易指数下单】修改用户金额出错");
+            log.error("用户交易货币下单】修改用户金额出错");
+            throw new Exception("用户交易货币下单】修改用户金额出错");
         }
 
 
@@ -194,10 +194,10 @@ public class UserIndexPositionServiceImpl implements IUserIndexPositionService {
 
         int insertPositionCount = this.userIndexPositionMapper.insert(userIndexPosition);
         if (insertPositionCount > 0) {
-            log.info("【用户交易指数下单】保存持仓记录成功");
+            log.info("【用户交易货币下单】保存持仓记录成功");
         } else {
-            log.error("用户交易指数下单】保存持仓记录出错");
-            throw new Exception("用户交易指数下单】保存持仓记录出错");
+            log.error("用户交易货币下单】保存持仓记录出错");
+            throw new Exception("用户交易货币下单】保存持仓记录出错");
         }
 
         return ServerResponse.createBySuccess("下单成功");
@@ -223,12 +223,12 @@ public class UserIndexPositionServiceImpl implements IUserIndexPositionService {
 
     @Transactional
     public ServerResponse sellIndex(String positionSn, int doType) throws Exception {
-        log.info("【用户交易平仓指数】 positionSn = {} , dotype = {}", positionSn, Integer.valueOf(doType));
+        log.info("【用户交易平仓货币】 positionSn = {} , dotype = {}", positionSn, Integer.valueOf(doType));
 
 
         SiteIndexSetting siteIndexSetting = this.iSiteIndexSettingService.getSiteIndexSetting();
         if (siteIndexSetting == null) {
-            log.error("平仓出错,网站指数设置表不存在");
+            log.error("平仓出错,网站货币设置表不存在");
             return ServerResponse.createByErrorMsg("下单失败,系统设置错误");
         }
 
@@ -240,7 +240,7 @@ public class UserIndexPositionServiceImpl implements IUserIndexPositionService {
             String pm_end = siteIndexSetting.getTransPmEnd();
             boolean am_flag = BuyAndSellUtils.isTransTime(am_begin, am_end);
             boolean pm_flag = BuyAndSellUtils.isTransTime(pm_begin, pm_end);
-            log.info("【指数】是否在上午交易时间 = {} 是否在下午交易时间 = {}", Boolean.valueOf(am_flag), Boolean.valueOf(pm_flag));
+            log.info("【货币】是否在上午交易时间 = {} 是否在下午交易时间 = {}", Boolean.valueOf(am_flag), Boolean.valueOf(pm_flag));
             if (!am_flag && !pm_flag) {
                 return ServerResponse.createByErrorMsg("平仓失败,不在交易时段内");
             }
@@ -249,7 +249,7 @@ public class UserIndexPositionServiceImpl implements IUserIndexPositionService {
 
         UserIndexPosition userIndexPosition = this.userIndexPositionMapper.selectIndexPositionBySn(positionSn);
         if (userIndexPosition == null) {
-            return ServerResponse.createByErrorMsg("平仓失败,指数持仓不存在");
+            return ServerResponse.createByErrorMsg("平仓失败,货币持仓不存在");
         }
 
 
@@ -267,7 +267,7 @@ public class UserIndexPositionServiceImpl implements IUserIndexPositionService {
 
 
         MarketVO marketVO = this.iStockIndexService.querySingleIndex(userIndexPosition.getIndexGid());
-        log.info("当前指数行情 = {}", JsonUtil.obj2StringPretty(marketVO));
+        log.info("当前货币行情 = {}", JsonUtil.obj2StringPretty(marketVO));
 
         BigDecimal increaseRate = new BigDecimal(marketVO.getIncreaseRate());
         if (increaseRate.compareTo(new BigDecimal("0")) == 1) {
@@ -275,7 +275,7 @@ public class UserIndexPositionServiceImpl implements IUserIndexPositionService {
             if (siteIndexSetting.getRiseLimit().multiply(new BigDecimal("100"))
                     .compareTo(increaseRate) != 1 && "做空"
                     .equals(userIndexPosition.getOrderDirection())) {
-                return ServerResponse.createByErrorMsg("当前指数涨幅:" + increaseRate + ",不能卖出");
+                return ServerResponse.createByErrorMsg("当前货币涨幅:" + increaseRate + ",不能卖出");
             }
         } else {
 
@@ -283,7 +283,7 @@ public class UserIndexPositionServiceImpl implements IUserIndexPositionService {
             if (siteIndexSetting.getRiseLimit().multiply(new BigDecimal("100"))
                     .compareTo(increaseRate) == -1 && "做多"
                     .equals(userIndexPosition.getOrderDirection())) {
-                return ServerResponse.createByErrorMsg("当前指数跌幅:" + increaseRate + ",不能卖出");
+                return ServerResponse.createByErrorMsg("当前货币跌幅:" + increaseRate + ",不能卖出");
             }
         }
 
@@ -306,10 +306,10 @@ public class UserIndexPositionServiceImpl implements IUserIndexPositionService {
 
         int updateIndexPositionCount = this.userIndexPositionMapper.updateByPrimaryKeySelective(userIndexPosition);
         if (updateIndexPositionCount > 0) {
-            log.info("【用户平仓指数】修改浮动盈亏记录成功");
+            log.info("【用户平仓货币】修改浮动盈亏记录成功");
         } else {
-            log.error("【用户平仓指数】修改浮动盈亏记录出错");
-            throw new Exception("用户平仓指数】修改浮动盈亏记录出错");
+            log.error("【用户平仓货币】修改浮动盈亏记录出错");
+            throw new Exception("用户平仓货币】修改浮动盈亏记录出错");
         }
 
 
@@ -327,10 +327,10 @@ public class UserIndexPositionServiceImpl implements IUserIndexPositionService {
 
         int updateUserCount = this.userMapper.updateByPrimaryKeySelective(user);
         if (updateUserCount > 0) {
-            log.info("【用户平仓指数】修改用户金额成功");
+            log.info("【用户平仓货币】修改用户金额成功");
         } else {
-            log.error("【用户平仓指数】修改用户金额出错");
-            throw new Exception("【用户平仓指数】修改用户金额出错");
+            log.error("【用户平仓货币】修改用户金额出错");
+            throw new Exception("【用户平仓货币】修改用户金额出错");
         }
 
         UserCashDetail ucd = new UserCashDetail();
@@ -339,9 +339,9 @@ public class UserIndexPositionServiceImpl implements IUserIndexPositionService {
         ucd.setAgentName(user.getAgentName());
         ucd.setUserId(user.getId());
         ucd.setUserName(user.getRealName());
-        ucd.setDeType("指数盈亏");
+        ucd.setDeType("货币盈亏");
         ucd.setDeAmt(all_profit);
-        ucd.setDeSummary("卖出指数," + userIndexPosition.getIndexName() + "/" + userIndexPosition
+        ucd.setDeSummary("卖出货币," + userIndexPosition.getIndexName() + "/" + userIndexPosition
                 .getIndexCode() + ",总盈亏:" + all_profit);
 
 
@@ -350,10 +350,10 @@ public class UserIndexPositionServiceImpl implements IUserIndexPositionService {
 
         int insertSxfCount = this.userCashDetailMapper.insert(ucd);
         if (insertSxfCount > 0) {
-            log.info("【用户平仓指数】保存明细记录成功");
+            log.info("【用户平仓货币】保存明细记录成功");
         } else {
-            log.error("【用户平仓指数】保存明细记录出错");
-            throw new Exception("【用户平仓指数】保存明细记录出错");
+            log.error("【用户平仓货币】保存明细记录出错");
+            throw new Exception("【用户平仓货币】保存明细记录出错");
         }
 
         return ServerResponse.createBySuccessMsg("平仓成功!");
@@ -598,7 +598,7 @@ public class UserIndexPositionServiceImpl implements IUserIndexPositionService {
 
 
             MarketVO marketVO = this.iStockIndexService.querySingleIndex(userIndexPosition.getIndexGid());
-            log.info("IndexPositionVO 当前指数行情 = {}", JsonUtil.obj2StringPretty(marketVO));
+            log.info("IndexPositionVO 当前货币行情 = {}", JsonUtil.obj2StringPretty(marketVO));
 
             BigDecimal nowPrice = new BigDecimal(marketVO.getNowPrice());
 
@@ -613,7 +613,7 @@ public class UserIndexPositionServiceImpl implements IUserIndexPositionService {
                     profit_and_lose = profit_and_lose.negate();
                 }
 
-                log.info("持仓指数 {} ,现价点数 = {} ,买入点数 = {} 差价 = {} 盈亏 = {}", new Object[]{userIndexPosition
+                log.info("持仓货币 {} ,现价点数 = {} ,买入点数 = {} 差价 = {} 盈亏 = {}", new Object[]{userIndexPosition
                         .getIndexName(), nowPrice, buyPrice, subPrice, profit_and_lose});
 
 

+ 89 - 150
src/main/java/com/xc/service/impl/UserPositionServiceImpl.java

@@ -79,9 +79,12 @@ public class UserPositionServiceImpl implements IUserPositionService {
     @Autowired
     StockMapper stockMapper;
 
+    @Autowired
+    DbStockService dbStockService;
+
     /**
-     * 判断当前指数当前价格可成交挂单
-     * @param code 指数code
+     * 判断当前货币当前价格可成交挂单
+     * @param code 货币code
      * @param buyOrderPrice 当前价格
      * @return
      */
@@ -173,43 +176,42 @@ public class UserPositionServiceImpl implements IUserPositionService {
     public ServerResponse closeOut(int id, Integer orderNum) throws Exception {
         log.info("【用户交易平仓】 positionSn = {}", id);
         UserPosition userPosition = this.userPositionMapper.findPositionById(id);
+        if (userPosition == null) {
+            return ServerResponse.createByErrorMsg("平仓失败,订单不存在");
+        }
         // 获取交易时间和交易手续费
         ServerResponse stock_res = this.iStockService.findStockByName(userPosition.getStockName());
         if (!stock_res.isSuccess()) {
-            return ServerResponse.createByErrorMsg("下单失败,指数代码错误");
+            return ServerResponse.createByErrorMsg("下单失败,代码错误");
         }
         Stock stock = (Stock) stock_res.getData();
-        if (stock.getIsLock().intValue() != 0) {
-            return ServerResponse.createByErrorMsg("下单失败,当前指数不能交易");
-        }
         if (stock == null) {
             log.error("下单出错,网站设置表不存在");
             return ServerResponse.createByErrorMsg("下单失败,系统设置错误");
         }
-        if (userPosition == null) {
-            return ServerResponse.createByErrorMsg("平仓失败,订单不存在");
-        }
-        if (!iStockService.isTransState(stock)) {
-            return ServerResponse.createByErrorMsg("平仓失败,不在交易时段内");
+        if (stock.getIsLock() != 0) {
+            return ServerResponse.createByErrorMsg("下单失败,当前货币不能交易");
         }
+//        if (!iStockService.isTransState(stock)) {
+//            return ServerResponse.createByErrorMsg("平仓失败,不在交易时段内");
+//        }
         User user = this.userMapper.selectByPrimaryKey(userPosition.getUserId());
-        if (user.getIsLock().intValue() == 1) {
+        if (user.getIsLock() == 1) {
             return ServerResponse.createByErrorMsg("平仓失败,用户已被锁定");
         }
         if (userPosition.getSellOrderId() != null) {
             return ServerResponse.createByErrorMsg("平仓失败,此订单已平仓");
         }
-        if (1 == userPosition.getIsLock().intValue()) {
+        if (1 == userPosition.getIsLock()) {
             return ServerResponse.createByErrorMsg("平仓失败 " + userPosition.getLockMsg());
         }
-
-        String nowPriceStr = getNowPriceStrByDbName(stock.getDataDbName());
-        BigDecimal now_price = BigDecimal.valueOf(Double.valueOf(nowPriceStr));
+        //每支股票code获取现价
+        StockListVO stockListVO = dbStockService.getStockListVO(userPosition.getStockGid());
+        BigDecimal now_price = new BigDecimal(stockListVO.getNowPrice());
         if (now_price.compareTo(new BigDecimal("0")) != 1) {
-            log.error("指数 = {} 收到报价 = {}", userPosition.getStockName(), now_price);
+            log.error("货币 = {} 收到报价 = {}", userPosition.getStockName(), now_price);
             return ServerResponse.createByErrorMsg("报价0,平仓失败,请稍后再试");
         }
-
         // 实际手数
         boolean isAll = false;
         Integer buyNumAll = userPosition.getOrderNum();
@@ -222,7 +224,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
         }else{
             buyNum = orderNum;
         }
-
         // 购买所使用金额
         BigDecimal all_buy_amt = userPosition.getBuyOrderPrice().multiply(new BigDecimal(buyNum));
         // 现价购买所需的金额
@@ -236,7 +237,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
             log.info("买卖方向:{}", "跌");
             profitLoss = all_buy_amt.subtract(all_sell_amt);
         }
-        log.info("买入总金额 = {} , 卖出总金额 = {} , 盈亏 = {}", new Object[]{all_buy_amt, all_sell_amt, profitLoss});
+        log.info("买入总金额 = {} , 卖出总金额 = {} , 盈亏 = {}", 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);
@@ -246,7 +247,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
         log.info("留仓费 = {}", orderStayFee);
         BigDecimal all_fee_amt = buy_fee_amt.add(orderStayFee);
         log.info("总的手续费费用 = {}", all_fee_amt);
-
         // 设置卖时的订单信息和价格
         userPosition.setSellOrderId(GeneratePosition.getPositionId());
         userPosition.setSellOrderPrice(now_price);
@@ -255,15 +255,13 @@ public class UserPositionServiceImpl implements IUserPositionService {
         BigDecimal all_profit = profitLoss;
         userPosition.setProfitAndLose(all_profit);
         userPosition.setAllProfitAndLose(all_profit);
-
         userPosition.setOrderNum(buyNum);
         userPosition.setOrderTotalPrice(userPosition.getBuyOrderPrice().multiply(new BigDecimal(buyNum)));
         // 用原本的手续费计算出单笔的手续费 再得出总体的手续费
-        userPosition.setOrderFee(userPosition.getOrderFee().divide(new BigDecimal(buyNumAll)).multiply(new BigDecimal(buyNum)));
+        userPosition.setOrderFee(userPosition.getOrderFee().divide(new BigDecimal(buyNumAll),4,4).multiply(new BigDecimal(buyNum)));
         //冻结保证金
-        userPosition.setDepositFreezeAmt(userPosition.getDepositFreezeAmt().divide(new BigDecimal(buyNumAll)).multiply(new BigDecimal(buyNum)));
+        userPosition.setDepositFreezeAmt(userPosition.getDepositFreezeAmt().divide(new BigDecimal(buyNumAll),4,4).multiply(new BigDecimal(buyNum)));
         int updatePositionCount = this.userPositionMapper.updateByPrimaryKeySelective(userPosition);
-
         if(!isAll) {
             UserPosition userPositionInsert = new UserPosition();
             userPositionInsert.setPositionType(userPosition.getPositionType());
@@ -281,38 +279,34 @@ public class UserPositionServiceImpl implements IUserPositionService {
             userPositionInsert.setStockPlate(userPosition.getStockPlate());
             userPositionInsert.setIsLock(userPosition.getIsLock());
             userPositionInsert.setOrderLever(userPosition.getOrderLever());
-
             Integer num = buyNumAll - buyNum;
             userPositionInsert.setOrderNum(num);
             userPositionInsert.setBuyOrderPrice(userPosition.getBuyOrderPrice());
             userPositionInsert.setOrderTotalPrice(userPosition.getBuyOrderPrice().multiply(new BigDecimal(num)));
             // 用原本的手续费计算出单笔的手续费 再得出总体的手续费
-            userPositionInsert.setOrderFee(userPosition.getOrderFee().divide(new BigDecimal(buyNum)).multiply(new BigDecimal(num)));
+            userPositionInsert.setOrderFee(userPosition.getOrderFee().divide(new BigDecimal(buyNum),4,4).multiply(new BigDecimal(num)));
             userPositionInsert.setProfitAndLose(BigDecimal.ZERO);
-            userPositionInsert.setOrderStayDays(Integer.valueOf(0));
+            userPositionInsert.setOrderStayDays(0);
             userPositionInsert.setOrderStayFee(BigDecimal.ZERO);
             userPositionInsert.setOrderSpread(BigDecimal.ZERO);
             //冻结保证金
-            userPositionInsert.setDepositFreezeAmt(userPosition.getDepositFreezeAmt().divide(new BigDecimal(buyNum)).multiply(new BigDecimal(num)));
+            userPositionInsert.setDepositFreezeAmt(userPosition.getDepositFreezeAmt().divide(new BigDecimal(buyNum),4,4).multiply(new BigDecimal(num)));
             //是否挂单
             userPositionInsert.setEntryOrders(0);
             this.userPositionMapper.insertSelective(userPositionInsert);
         }
-
         if (updatePositionCount > 0) {
             log.info("【用户平仓】修改浮动盈亏记录成功");
         } else {
             log.error("用户平仓】修改浮动盈亏记录出错");
             throw new Exception("用户平仓】修改浮动盈亏记录出错");
         }
-
         //修改持仓表记录
 //        BigDecimal freez_amt = all_buy_amt;
 //        BigDecimal reckon_all = user_all_amt.add(all_profit);
 //        BigDecimal reckon_enable = user_enable_amt.add(all_profit).add(freez_amt);
         BigDecimal reckon_all = user.getUserAmt().add(profitLoss);
         BigDecimal reckon_enable = user.getEnableAmt().add(userPosition.getDepositFreezeAmt()).add(profitLoss);
-
         log.info("用户平仓后的总资金  = {} , 可用资金 = {}", reckon_all, reckon_enable);
         user.setUserAmt(reckon_all);
         user.setEnableAmt(reckon_enable);
@@ -330,7 +324,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
         userCapitalDetail.setUserName(user.getRealName());
         userCapitalDetail.setPositionId(userPosition.getId());
         userCapitalDetail.setDeType(2);
-        userCapitalDetail.setIsRead(Integer.valueOf(0));
+        userCapitalDetail.setIsRead(0);
         userCapitalDetail.setOrderNum(buyNum);
         userCapitalDetail.setBuyFeeAmt(buy_fee_amt);
         userCapitalDetail.setOrderSpread(new BigDecimal(0));
@@ -366,7 +360,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
     }
 
     private void toStopProfitTargetById(int id) throws Exception {
-        // 获取指数当前价格
+        // 获取货币当前价格
         List<IndexInfo> indexInfoList = stockMapper.selectStockList();
         Map<String, BigDecimal> indexMap = new HashMap<>();
         BigDecimal nowPrice;
@@ -411,7 +405,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
 
     @Override
     public void toStopProfitTarget() throws Exception {
-        // 获取指数当前价格
+        // 获取货币当前价格
         List<IndexInfo> indexInfoList = stockMapper.selectStockList();
         Map<String, BigDecimal> indexMap = new HashMap<>();
         BigDecimal nowPrice;
@@ -486,7 +480,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
     public void calcDemurrage() {
         // 获取所有正在持仓的用户ID
         List<Integer> userIdList = userPositionMapper.selectPositionUserId();
-        // 获取各指数过夜费
+        // 获取各货币过夜费
         List<IndexInfo> indexInfoList = stockMapper.selectStockList();
         Map<String, Integer> indexMap = new HashMap<>();
         for (IndexInfo indexInfo : indexInfoList){
@@ -522,7 +516,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
 //                ucd.setUserName(user.getRealName());
 //                ucd.setDeType("留仓费");
 //                ucd.setDeAmt(new BigDecimal(-demurrageSum));
-//                ucd.setDeSummary("指数," + userPosition.getStockCode() + "/" + userPosition.getStockName() + ",扣过夜费:-" + orderStayFee);
+//                ucd.setDeSummary("货币," + userPosition.getStockCode() + "/" + userPosition.getStockName() + ",扣过夜费:-" + orderStayFee);
 //                ucd.setAddTime(new Date());
 //                ucd.setIsRead(Integer.valueOf(0));
 //                int insertSxfCount = this.userCashDetailMapper.insert(ucd);
@@ -615,35 +609,35 @@ public class UserPositionServiceImpl implements IUserPositionService {
             if (StringUtils.isBlank(user.getRealName()) || StringUtils.isBlank(user.getIdCard())) {
                 return ServerResponse.createByErrorMsg("挂单失败,请先实名认证");
             }
-            if (user.getIsLock().intValue() == 1) {
+            if (user.getIsLock() == 1) {
                 return ServerResponse.createByErrorMsg("挂单失败,账户已被锁定");
             }
             Stock stock = null;
             ServerResponse stock_res = this.iStockService.findStockById(stockId);
             if (!stock_res.isSuccess()) {
-                return ServerResponse.createByErrorMsg("挂单失败,指数代码错误");
+                return ServerResponse.createByErrorMsg("挂单失败,货币代码错误");
             }
             stock = (Stock) stock_res.getData();
-            if (stock.getIsLock().intValue() != 0) {
-                return ServerResponse.createByErrorMsg("挂单失败,当前指数不能交易");
-            }
             if (stock == null) {
                 log.error("挂单出错,网站设置表不存在");
                 return ServerResponse.createByErrorMsg("挂单失败,系统设置错误");
             }
-            if (buyNum < stock.getBuyMinNum().intValue()) {
+            if (stock.getIsLock() != 0) {
+                return ServerResponse.createByErrorMsg("挂单失败,当前货币不能交易");
+            }
+            if (buyNum < stock.getBuyMinNum()) {
                 return ServerResponse.createByErrorMsg("挂单失败,购买数量小于" + stock.getBuyMinNum() + "手");
             }
-            if (buyNum > stock.getBuyMaxNum().intValue()) {
+            if (buyNum > stock.getBuyMaxNum()) {
                 return ServerResponse.createByErrorMsg("挂单失败,购买数量大于" + stock.getBuyMaxNum() + "手");
             }
             Integer userPositionAmt = findUserPositionAmt(user.getId(),stock.getStockCode());
             if((userPositionAmt+buyNum) > stock.getPositionsMax()){
                 return ServerResponse.createByErrorMsg("挂单失败,本次挂单手数:"+buyNum+",持仓手数大于" + stock.getPositionsMax() + "手,目前持仓手数:"+ userPositionAmt);
             }
-
-            String nowPriceStr = getNowPriceStrByDbName(stock.getDataDbName());
-            BigDecimal now_price = BigDecimal.valueOf(Double.valueOf(nowPriceStr));
+            //每支code获取现价
+            StockListVO stockListVO = dbStockService.getStockListVO(stock.getStockGid());
+            BigDecimal now_price = new BigDecimal(stockListVO.getNowPrice());
             if (now_price.compareTo(new BigDecimal("0")) == 0) {
                 return ServerResponse.createByErrorMsg("报价0,请稍后再试");
             }
@@ -658,7 +652,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
 //            if(!(buyOrderPrice.compareTo(addNowprice)  > -1 || buyOrderPrice.compareTo(subNowprice) < 1)){
 //                return ServerResponse.createByErrorMsg("挂单价格不在价差范围内");
 //            }
-            if(buyType.intValue() == 0){
+            if(buyType == 0){
                 // 做多
                 // 委托价 大于 现价+价格差 才可以设置
                 if(buyOrderPrice.compareTo(addNowprice) == 1){
@@ -677,7 +671,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
             BigDecimal user_enable_amt = user.getEnableAmt();
 
             // 委托价 * 购买手数
-            BigDecimal buy_amt_autual = buyOrderPrice.multiply(new BigDecimal(buyNum.intValue()));
+            BigDecimal buy_amt_autual = buyOrderPrice.multiply(new BigDecimal(buyNum));
             log.info("用户可用金额 = {}  实际购买金额 =  {}", user_enable_amt, buy_amt_autual);
 
             // 手续费
@@ -720,19 +714,19 @@ public class UserPositionServiceImpl implements IUserPositionService {
             userPosition.setBuyOrderId(GeneratePosition.getPositionId());
             userPosition.setBuyOrderTime(new Date());
             userPosition.setBuyOrderPrice(buyOrderPrice);
-            userPosition.setOrderDirection((buyType.intValue() == 0) ? "做多" : "做空");
+            userPosition.setOrderDirection((buyType == 0) ? "做多" : "做空");
 
             userPosition.setOrderNum(buyNum);
             if (stock.getStockPlate() != null) {
                 userPosition.setStockPlate(stock.getStockPlate());
             }
-            userPosition.setIsLock(Integer.valueOf(0));
+            userPosition.setIsLock(0);
             userPosition.setOrderLever(new BigDecimal(0));
             userPosition.setOrderTotalPrice(buy_amt_autual);
             userPosition.setOrderFee(position_freez);
             BigDecimal profit_and_lose = new BigDecimal("0");
             userPosition.setProfitAndLose(profit_and_lose);
-            userPosition.setOrderStayDays(Integer.valueOf(0));
+            userPosition.setOrderStayDays(0);
             userPosition.setOrderStayFee(new BigDecimal("0"));
             userPosition.setOrderSpread(new BigDecimal(stock.getSpread()*buyNum));
             userPosition.setDepositFreezeAmt(depositFreezeAmt);
@@ -777,64 +771,53 @@ public class UserPositionServiceImpl implements IUserPositionService {
         if (StringUtils.isBlank(user.getRealName()) || StringUtils.isBlank(user.getIdCard())) {
             return ServerResponse.createByErrorMsg("下单失败,请先实名认证");
         }
-
-        log.info("用户 {} 下单,指数id = {} ,数量 = {} , 方向 = {} ", new Object[]{user
-                .getId(), stockId, buyNum, buyType});
-        if (user.getIsLock().intValue() == 1) {
+        log.info("用户 {} 下单,货币id = {} ,数量 = {} , 方向 = {} ", user
+                .getId(), stockId, buyNum, buyType);
+        if (user.getIsLock() == 1) {
             return ServerResponse.createByErrorMsg("下单失败,账户已被锁定");
         }
-        //判断指数是否能交易
+        //判断货币是否能交易
         Stock stock = null;
         ServerResponse stock_res = this.iStockService.findStockById(stockId);
         if (!stock_res.isSuccess()) {
-            return ServerResponse.createByErrorMsg("下单失败,指数代码错误");
+            return ServerResponse.createByErrorMsg("下单失败,货币代码错误");
         }
         stock = (Stock) stock_res.getData();
-        if (stock.getIsLock().intValue() != 0) {
-            return ServerResponse.createByErrorMsg("下单失败,当前指数不能交易");
-        }
         if (stock == null) {
             log.error("下单出错,网站设置表不存在");
             return ServerResponse.createByErrorMsg("下单失败,系统设置错误");
         }
-
-        //判断交易时间
-        if (!iStockService.isTransState(stock)) {
-            return ServerResponse.createByErrorMsg("下单失败,不在交易时段内");
+        if (stock.getIsLock() != 0) {
+            return ServerResponse.createByErrorMsg("下单失败,当前货币不能交易");
         }
-        if (buyNum.intValue() < stock.getBuyMinNum().intValue()) {
+        //判断交易时间
+//        if (!iStockService.isTransState(stock)) {
+//            return ServerResponse.createByErrorMsg("下单失败,不在交易时段内");
+//        }
+        if (buyNum < stock.getBuyMinNum()) {
             return ServerResponse.createByErrorMsg("下单失败,购买数量小于" + stock.getBuyMinNum() + "手");
         }
-        if (buyNum.intValue() > stock.getBuyMaxNum().intValue()) {
+        if (buyNum > stock.getBuyMaxNum()) {
             return ServerResponse.createByErrorMsg("下单失败,购买数量大于" + stock.getBuyMaxNum() + "手");
         }
-
         // 判断用户持仓数
         Integer userPositionAmt = findUserPositionAmt(user.getId(),stock.getStockCode());
-        if((userPositionAmt + buyNum) > stock.getPositionsMax()){
+        if((userPositionAmt + buyNum) > (stock.getPositionsMax() == null ? 0 : stock.getPositionsMax())){
             return ServerResponse.createByErrorMsg("下单失败,本次下单手数:"+buyNum+",持仓手数大于" + stock.getPositionsMax() + "手,目前持仓手数:"+ userPositionAmt);
         }
-        // 获取指数行情 设置最新价格
-        String nowPriceStr = getNowPriceStrByDbName(stock.getDataDbName());
-        BigDecimal now_price = BigDecimal.valueOf(Double.valueOf(nowPriceStr));
-        if (now_price.compareTo(new BigDecimal("0")) == 0) {
+        // 获取股票最新价格
+        StockListVO stockListVO = dbStockService.getStockListVO(stock.getStockGid());
+        BigDecimal nowPrice = new BigDecimal(stockListVO.getNowPrice());
+        if (nowPrice.compareTo(new BigDecimal("0")) == 0) {
             return ServerResponse.createByErrorMsg("报价0,请稍后再试");
         }
-
         if(buyType == 0){
             // 做多
-            //BigDecimal temp = new BigDecimal(stock.getSpread()).multiply(new BigDecimal(buyNum));
-            //temp = temp.divide(new BigDecimal(stock.getContractSize() * buyNum), 2,4);
-			
-            now_price = now_price.add(new BigDecimal(stock.getSpread()));
-//            now_price = now_price.add()
+            nowPrice = nowPrice.add(new BigDecimal(stock.getSpread()));
         }else{
-           // BigDecimal temp = new BigDecimal(stock.getSpread()).multiply(new BigDecimal(buyNum));
-           // temp = temp.divide(new BigDecimal(stock.getContractSize() * buyNum), 2,4);
-           // now_price = (temp.subtract(now_price)).negate();
-			now_price = now_price.subtract(new BigDecimal(stock.getSpread()));
+            nowPrice = nowPrice.subtract(new BigDecimal(stock.getSpread()));
         }
-        log.info("用户 {} 下单,指数id = {} ,数量 = {} , 方向 = {}", new Object[]{user.getId(), stockId, buyNum, buyType});
+        log.info("用户 {} 下单,货币id = {} ,数量 = {} , 方向 = {}", user.getId(), stockId, buyNum, buyType);
         // 用户可用金
         BigDecimal user_enable_amt = user.getEnableAmt();
         BigDecimal user_amt = user.getUserAmt();
@@ -842,8 +825,8 @@ public class UserPositionServiceImpl implements IUserPositionService {
         // 手续费
         BigDecimal position_freez = new BigDecimal(buyNum * stock.getTransFee());
         log.info("手续费 = "+position_freez);
-        //冻结保证金
-        BigDecimal depositFreezeAmt = new BigDecimal(buyNum * stock.getDepositAmt());
+        //冻结保证金 = 现价* 合约单位 * 手数 / 杠杆
+        BigDecimal depositFreezeAmt = nowPrice.multiply(new BigDecimal(stock.getContractSize())).multiply(new BigDecimal(buyNum)).divide(new BigDecimal(stock.getSiteLever()),2,4);
         log.info("冻结保证金 = "+depositFreezeAmt);
         BigDecimal buy_amt = position_freez.add(depositFreezeAmt);
         if(user_enable_amt.compareTo(buy_amt) == -1){
@@ -869,7 +852,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
 //            ucd.setUserName(user.getRealName());
 //            ucd.setDeType("手续费");
 //            ucd.setDeAmt(position_freez);
-//            ucd.setDeSummary("买入指数," + finalStock.getStockCode() + "/" + finalStock.getStockName()+",买入手数:"+ buyNum + ",手续费:" + position_freez );
+//            ucd.setDeSummary("买入货币," + finalStock.getStockCode() + "/" + finalStock.getStockName()+",买入手数:"+ buyNum + ",手续费:" + position_freez );
 //            ucd.setAddTime(new Date());
 //            ucd.setIsRead(Integer.valueOf(0));
 //            int insertSxfCount = this.userCashDetailMapper.insert(ucd);
@@ -907,38 +890,33 @@ public class UserPositionServiceImpl implements IUserPositionService {
         userPosition.setStockSpell(stock.getStockSpell());
         userPosition.setBuyOrderId(GeneratePosition.getPositionId());
         userPosition.setBuyOrderTime(new Date());
-        userPosition.setBuyOrderPrice(now_price);
-        userPosition.setOrderDirection((buyType.intValue() == 0) ? "做多" : "做空");
-
+        userPosition.setBuyOrderPrice(nowPrice);
+        userPosition.setOrderDirection((buyType == 0) ? "做多" : "做空");
         userPosition.setOrderNum(buyNum);
         if (stock.getStockPlate() != null) {
             userPosition.setStockPlate(stock.getStockPlate());
         }
-        userPosition.setIsLock(Integer.valueOf(0));
+        userPosition.setIsLock(0);
         userPosition.setOrderLever(new BigDecimal(0));
-        userPosition.setOrderTotalPrice(now_price.multiply(new BigDecimal(buyNum)));
+        userPosition.setOrderTotalPrice(nowPrice.multiply(new BigDecimal(buyNum)));
         // 源计算手续费 手续费直接扣余额 不足提示
 //        BigDecimal buy_fee_amt = buy_amt.multiply(new BigDecimal(stock.getTransFee())).setScale(2, 4);
 //        log.info("用户购买手续费(配资后总资金 * 百分比) = {}", buy_fee_amt);
         userPosition.setOrderFee(position_freez);
-
         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"));
-
         userPosition.setOrderSpread(new BigDecimal(stock.getSpread() * buyNum));
         log.info("点差"+(stock.getSpread() * buyNum));
         //冻结保证金
         userPosition.setDepositFreezeAmt(depositFreezeAmt);
-
         //是否挂单
         userPosition.setEntryOrders(0);
 
-//        int insertPositionCount = this.userPositionMapper.insert(userPosition);
         int insertPositionCount = this.userPositionMapper.insertSelective(userPosition);
         if (insertPositionCount > 0) {
             log.info("【用户交易下单】保存持仓记录成功");
@@ -997,7 +975,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
 
         BigDecimal now_price = new BigDecimal(stockListVO.getNowPrice());
         if (now_price.compareTo(new BigDecimal("0")) != 1) {
-            log.error("指数 = {} 收到报价 = {}", userPosition.getStockName(), now_price);
+            log.error("货币 = {} 收到报价 = {}", userPosition.getStockName(), now_price);
             return ServerResponse.createByErrorMsg("报价0,平仓失败,请稍后再试");
         }
 
@@ -1012,10 +990,10 @@ public class UserPositionServiceImpl implements IUserPositionService {
         BigDecimal ztRate = chaPrice.multiply(new BigDecimal("100")).divide(zsPrice, 2, RoundingMode.HALF_UP);
 
         ztRate = ztRate.negate();
-        log.info("指数当前涨跌幅 = {} 跌停幅度 = {}", Double.valueOf(stock_crease), ztRate);
+        log.info("货币当前涨跌幅 = {} 跌停幅度 = {}", Double.valueOf(stock_crease), ztRate);
         if ((new BigDecimal(String.valueOf(stock_crease))).compareTo(ztRate) == 0 && "做多"
                 .equals(userPosition.getOrderDirection())) {
-            return ServerResponse.createByErrorMsg("当前指数已跌停不能卖出");
+            return ServerResponse.createByErrorMsg("当前货币已跌停不能卖出");
         }
 
         Integer buy_num = userPosition.getOrderNum();
@@ -1097,7 +1075,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
 //        ucd.setUserName(user.getRealName());
 //        ucd.setDeType("总盈亏");
 //        ucd.setDeAmt(all_profit);
-//        ucd.setDeSummary("卖出指数," + userPosition.getStockCode() + "/" + userPosition.getStockName() + ",手续费:" + buy_fee_amt + ",盈亏:" + all_profit + ",点差:" + orderSpread + ",留仓费:" + orderStayFee);
+//        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);
@@ -1181,15 +1159,15 @@ public class UserPositionServiceImpl implements IUserPositionService {
     }
 
     public ServerResponse findMyPositionByCodeAndSpell(String stockCode, String stockSpell, Integer state, HttpServletRequest request, int pageNum, int pageSize) {
-        // 获取指数当前价格
+        // 获取货币当前价格
         List<IndexInfo> indexInfoList = stockMapper.selectStockList();
         Map<String, IndexInfo> indexMap = new HashMap<>();
         BigDecimal nowPrice;
         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) {
                     // 数据库不存在
@@ -1218,11 +1196,11 @@ public class UserPositionServiceImpl implements IUserPositionService {
                 }
 //                ServerResponse stock_res = this.iStockService.findStockByName(position.getStockName());
 //                if (!stock_res.isSuccess()) {
-//                    return ServerResponse.createByErrorMsg("指数代码错误");
+//                    return ServerResponse.createByErrorMsg("货币代码错误");
 //                }
 //                Stock stock = (Stock) stock_res.getData();
 //                if (stock.getIsLock().intValue() != 0) {
-//                    return ServerResponse.createByErrorMsg("当前指数不能交易");
+//                    return ServerResponse.createByErrorMsg("当前货币不能交易");
 //                }
 //                yk = yk.subtract(position.getOrderSpread());
                 userPositionVO.setAllProfitAndLose(yk.add(userPositionVO.getOrderFee()));
@@ -1276,15 +1254,15 @@ public class UserPositionServiceImpl implements IUserPositionService {
     }
 
     public PositionVO findUserPositionAllProfitAndLose(Integer userId) {
-        // 获取指数当前价格
+        // 获取货币当前价格
         List<IndexInfo> indexInfoList = stockMapper.selectStockList();
         Map<String, IndexInfo> indexMap = new HashMap<>();
         BigDecimal nowPrice;
         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) {
                     // 数据库不存在
@@ -1313,45 +1291,6 @@ public class UserPositionServiceImpl implements IUserPositionService {
         positionVO.setAllProfitAndLose(ykSum);
         positionVO.setAllFreezAmt(depositFreezeAmt);
         return positionVO;
-
-//        List<UserPosition> userPositions = this.userPositionMapper.findPositionByUserIdAndSellIdIsNull(userId);
-//        BigDecimal allProfitAndLose = new BigDecimal("0");
-//        BigDecimal allFreezAmt = new BigDecimal("0");
-//        for (UserPosition position : userPositions) {
-//            Stock stock = stockMapper.findStockByName(position.getStockName());
-//            String nowPriceStr = getNowPriceStrByDbName(stock.getDataDbName());
-//            BigDecimal nowPrice = BigDecimal.valueOf(Double.valueOf(nowPriceStr));
-//            if (nowPrice.compareTo(new BigDecimal("0")) != 0) {
-//                //买价
-//                BigDecimal buyPrice = position.getBuyOrderPrice();
-//                //和现价的差价
-//                BigDecimal subPrice = nowPrice.subtract(buyPrice);
-//                //差价 * 买数 = 盈亏
-//                BigDecimal profit_and_lose = subPrice.multiply(new BigDecimal(position.getOrderNum().intValue()));
-//                if ("做空".equals(position.getOrderDirection())) {
-//                    profit_and_lose = profit_and_lose.negate();
-//                }
-//                //手续费不计算盈亏
-//                BigDecimal total_fee = position.getOrderSpread().add(position.getOrderStayFee());
-//
-//                if (position.getEntryOrders() != 1){
-//                    BigDecimal position_profit = profit_and_lose.subtract(total_fee);
-//                    //持仓总盈亏
-//                    log.info("position_profit = "+position_profit);
-//                    allProfitAndLose = allProfitAndLose.add(position_profit);
-//                    log.info("allProfitAndLose = "+allProfitAndLose);
-//                }
-//                // 计算冻结保证金
-//                if (null == position.getDepositFreezeAmt()){
-//                    BigDecimal position_freez = new BigDecimal((position.getOrderNum()/stock.getContractSize())*stock.getDepositAmt());
-//                    allFreezAmt = allFreezAmt.add(position_freez);
-//                }else {
-//                    allFreezAmt = allFreezAmt.add(position.getDepositFreezeAmt());
-//                }
-//                continue;
-//            }
-//            log.info("查询所有持仓单的总盈亏,现价返回0,当前为集合竞价");
-//        }
     }
 
     public List<UserPosition> findPositionByUserIdAndSellIdIsNull(Integer userId) {
@@ -1573,7 +1512,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
 
         Stock stock = (Stock) this.iStockService.findStockByCode(stockCode).getData();
         if (stock == null) {
-            return ServerResponse.createByErrorMsg("指数不存在");
+            return ServerResponse.createByErrorMsg("货币不存在");
         }
 
 
@@ -1747,7 +1686,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
             ucd.setUserName(user.getRealName());
             ucd.setDeType("留仓费");
             ucd.setDeAmt(all_profit);
-            ucd.setDeSummary("指数," + position.getStockCode() + "/" + position.getStockName() + ",扣除留仓费:" + all_profit);
+            ucd.setDeSummary("货币," + position.getStockCode() + "/" + position.getStockName() + ",扣除留仓费:" + all_profit);
             ucd.setAddTime(new Date());
             ucd.setIsRead(Integer.valueOf(0));
             int insertSxfCount = this.userCashDetailMapper.insert(ucd);

+ 42 - 243
src/main/java/com/xc/service/impl/UserServiceImpl.java

@@ -21,6 +21,7 @@ import com.xc.vo.futuresposition.FuturesPositionVO;
 import com.xc.vo.indexposition.IndexPositionVO;
 import com.xc.vo.position.PositionVO;
 import com.xc.vo.position.UserPositionVO;
+import com.xc.vo.stock.StockListVO;
 import com.xc.vo.stock.StockOptionListVO;
 import com.xc.vo.stock.StockVO;
 import com.xc.vo.user.UserInfoVO;
@@ -105,6 +106,8 @@ public class UserServiceImpl implements IUserService {
 
     @Autowired
     UserTokenMapper userTokenMapper;
+    @Autowired
+    DbStockService dbStockService;
 
     public ServerResponse reg(String yzmCode, String agentCode, String phone, String userPwd, HttpServletRequest request) {
         if (StringUtils.isBlank(agentCode) || StringUtils.isBlank(phone) ||
@@ -242,16 +245,13 @@ public class UserServiceImpl implements IUserService {
 
     public ServerResponse addOption(String code, HttpServletRequest request) {
         User user = getCurrentUser(request);
-
         StockOption dboption = this.stockOptionMapper.findMyOptionIsExistByCode(user.getId(), code);
-
         if (dboption != null) {
             return ServerResponse.createByErrorMsg("添加失败,自选股已存在");
         }
-
         Stock stock = this.stockMapper.findStockByCode(code);
         if (stock == null) {
-            return ServerResponse.createByErrorMsg("添加失败,指数不存在");
+            return ServerResponse.createByErrorMsg("添加失败,货币不存在");
         }
         String gid = stock.getStockGid();
         String sinaResult = SinaStockApi.getSinaStock(gid);
@@ -281,13 +281,10 @@ public class UserServiceImpl implements IUserService {
 
     public ServerResponse delOption(String code, HttpServletRequest request) {
         User user = getCurrentUser(request);
-
         StockOption dboption = this.stockOptionMapper.findMyOptionIsExistByCode(user.getId(), code);
-
         if (dboption == null) {
             return ServerResponse.createByErrorMsg("删除失败, 自选股不存在");
         }
-
         int delCount = this.stockOptionMapper.deleteByPrimaryKey(dboption.getId());
         if (delCount > 0) {
             return ServerResponse.createBySuccessMsg("删除自选股成功");
@@ -322,12 +319,10 @@ public class UserServiceImpl implements IUserService {
         if (StringUtils.isBlank(oldPwd) || StringUtils.isBlank(newPwd)) {
             return ServerResponse.createByErrorMsg("参数不能为空");
         }
-
         User user = getCurrentRefreshUser(request);
         if (!oldPwd.equals(user.getUserPwd())) {
             return ServerResponse.createByErrorMsg("密码错误");
         }
-
         user.setUserPwd(newPwd);
         int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
         if (updateCount > 0) {
@@ -346,7 +341,6 @@ public class UserServiceImpl implements IUserService {
             }else {
                 return ServerResponse.createBySuccessMsg("用户不存在");
             }
-
         }else {
             if (user != null) {
                 return ServerResponse.createBySuccessMsg("用户已存在");
@@ -365,22 +359,17 @@ public class UserServiceImpl implements IUserService {
                 StringUtils.isBlank(newPwd)) {
             return ServerResponse.createByErrorMsg("参数不能为空");
         }
-
-
         String keys = "AliyunSmsCode:" + phone;
         String redis_yzm = RedisShardedPoolUtils.get(keys);
-
         log.info("redis_yzm = {} , code = {}", redis_yzm, code);
         //redis_yzm
         if (!code.equals("6666")) {
             return ServerResponse.createByErrorMsg("修改密码失败,验证码错误");
         }
-
         User user = this.userMapper.findByPhone(phone);
         if (user == null) {
             return ServerResponse.createByErrorMsg("用户不存在");
         }
-
         user.setUserPwd(newPwd);
         int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
         if (updateCount > 0) {
@@ -401,7 +390,6 @@ public class UserServiceImpl implements IUserService {
                 user.setAgentName(agentUser.getAgentName());
             }
         }
-
         User userMapperById = this.userMapper.findById(user.getId());
 
         int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
@@ -428,29 +416,23 @@ public class UserServiceImpl implements IUserService {
                 StringUtils.isBlank(img1key) ||
                 StringUtils.isBlank(img2key))
         {
-
             return ServerResponse.createByErrorMsg("参数不能为空");
         }
-
         User user = getCurrentRefreshUser(request);
         if (user == null) {
             return ServerResponse.createByErrorMsg("请登录!");
         }
-
         if (((0 != user.getIsActive().intValue())) & ((3 != user.getIsActive().intValue()) ))
         {
             return ServerResponse.createByErrorMsg("当前状态不能认证");
         }
-
         user.setNickName(realName);
         user.setRealName(realName);
         user.setIdCard(idCard);
-
         user.setImg1Key(img1key);
         user.setImg2Key(img2key);
         user.setImg3Key(img3key);
         user.setIsActive(Integer.valueOf(1));
-
         log.info("##### 用户认证 ####,用户总资金 = {} 可用资金 = {}", user
                 .getUserAmt(), user.getEnableAmt());
 
@@ -468,18 +450,14 @@ public class UserServiceImpl implements IUserService {
         if (amt.intValue() <= 0) {
             return ServerResponse.createByErrorMsg("金额不正确");
         }
-
-
         if (1 == type.intValue()) {
             if (user.getEnableAmt().compareTo(new BigDecimal(amt.intValue())) == -1) {
                 return ServerResponse.createByErrorMsg("融资账户可用资金不足");
             }
-
             BigDecimal userAmt = user.getUserAmt().subtract(new BigDecimal(amt.intValue()));
             BigDecimal enableAmt = user.getEnableAmt().subtract(new BigDecimal(amt.intValue()));
             BigDecimal userIndexAmt = user.getUserIndexAmt().add(new BigDecimal(amt.intValue()));
             BigDecimal enableIndexAmt = user.getEnableIndexAmt().add(new BigDecimal(amt.intValue()));
-
             user.setUserAmt(userAmt);
             user.setEnableAmt(enableAmt);
             user.setUserIndexAmt(userIndexAmt);
@@ -491,19 +469,14 @@ public class UserServiceImpl implements IUserService {
             }
             return ServerResponse.createByErrorMsg("转账失败");
         }
-
-
-
         if (2 == type.intValue()) {
             if (user.getEnableIndexAmt().compareTo(new BigDecimal(amt.intValue())) == -1) {
-                return ServerResponse.createByErrorMsg("指数账户可用资金不足");
+                return ServerResponse.createByErrorMsg("货币账户可用资金不足");
             }
-
             BigDecimal userAmt = user.getUserAmt().add(new BigDecimal(amt.intValue()));
             BigDecimal enableAmt = user.getEnableAmt().add(new BigDecimal(amt.intValue()));
             BigDecimal userIndexAmt = user.getUserIndexAmt().subtract(new BigDecimal(amt.intValue()));
             BigDecimal enableIndexAmt = user.getEnableIndexAmt().subtract(new BigDecimal(amt.intValue()));
-
             user.setUserAmt(userAmt);
             user.setEnableAmt(enableAmt);
             user.setUserIndexAmt(userIndexAmt);
@@ -515,19 +488,14 @@ public class UserServiceImpl implements IUserService {
             }
             return ServerResponse.createByErrorMsg("转账失败");
         }
-
-
-
         if (3 == type.intValue()) {
             if (user.getEnableAmt().compareTo(new BigDecimal(amt.intValue())) == -1) {
-                return ServerResponse.createByErrorMsg("指数账户可用资金不足");
+                return ServerResponse.createByErrorMsg("货币账户可用资金不足");
             }
-
             BigDecimal userAmt = user.getUserAmt().subtract(new BigDecimal(amt.intValue()));
             BigDecimal enableAmt = user.getEnableAmt().subtract(new BigDecimal(amt.intValue()));
             BigDecimal userFutAmt = user.getUserFutAmt().add(new BigDecimal(amt.intValue()));
             BigDecimal enableFutAmt = user.getEnableFutAmt().add(new BigDecimal(amt.intValue()));
-
             user.setUserAmt(userAmt);
             user.setEnableAmt(enableAmt);
             user.setUserFutAmt(userFutAmt);
@@ -539,24 +507,18 @@ public class UserServiceImpl implements IUserService {
             }
             return ServerResponse.createByErrorMsg("转账失败");
         }
-
-
-
         if (4 == type.intValue()) {
             if (user.getEnableFutAmt().compareTo(new BigDecimal(amt.intValue())) == -1) {
                 return ServerResponse.createByErrorMsg("期货账户可用资金不足");
             }
-
             BigDecimal userAmt = user.getUserAmt().add(new BigDecimal(amt.intValue()));
             BigDecimal enableAmt = user.getEnableAmt().add(new BigDecimal(amt.intValue()));
             BigDecimal userFutAmt = user.getUserFutAmt().subtract(new BigDecimal(amt.intValue()));
             BigDecimal enableFutAmt = user.getEnableFutAmt().subtract(new BigDecimal(amt.intValue()));
-
             user.setUserAmt(userAmt);
             user.setEnableAmt(enableAmt);
             user.setUserFutAmt(userFutAmt);
             user.setEnableFutAmt(enableFutAmt);
-
             int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
             if (updateCount > 0) {
                 saveAmtTransLog(user, type, amt);
@@ -564,8 +526,6 @@ public class UserServiceImpl implements IUserService {
             }
             return ServerResponse.createByErrorMsg("转账失败");
         }
-
-
         return ServerResponse.createByErrorMsg("类型错误");
     }
 
@@ -577,10 +537,10 @@ public class UserServiceImpl implements IUserService {
         String amtTo = "";
         if (1 == type.intValue()) {
             amtFrom = "融资";
-            amtTo = "指数";
+            amtTo = "货币";
         }
         else if (2 == type.intValue()) {
-            amtFrom = "指数";
+            amtFrom = "货币";
             amtTo = "融资";
         }
         else if (3 == type.intValue()) {
@@ -621,15 +581,15 @@ public class UserServiceImpl implements IUserService {
     }
 
     public void ForceSellTask() {
-        // 获取指数当前价格
+        // 获取货币当前价格
         List<IndexInfo> indexInfoList = stockMapper.selectStockList();
         Map<String, IndexInfo> indexMap = new HashMap<>();
         BigDecimal nowPrice;
         for (IndexInfo indexInfo : indexInfoList) {
             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());
                     indexInfo.setNowPrice(nowPrice);
                 } catch (Exception e) {
                     // 数据库不存在
@@ -639,17 +599,16 @@ public class UserServiceImpl implements IUserService {
             indexMap.put(indexInfo.getCnName(), indexInfo);
         }
         List<Integer> userIdList = this.iUserPositionService.findDistinctUserIdList();
-        log.info("当前有持仓单的用户数量 为 {}", Integer.valueOf(userIdList.size()));
+        log.info("当前有持仓单的用户数量 为 {}", userIdList.size());
         for (int i = 0; i < userIdList.size(); i++) {
             log.info("=====================");
             Integer userId = userIdList.get(i);
             User user = this.userMapper.selectByPrimaryKey(userId);
-//            List<UserPosition> userPositions = this.iUserPositionService.findPositionByUserIdAndSellIdIsNull(userId);
             List<UserPosition> userPositions = this.userPositionMapper.findMyPositionByCodeAndSpell(user.getId(), null, null, 0);
-            log.info("用户id = {} 姓名 = {} 持仓中订单数: {}", new Object[] { userId, user.getRealName(), Integer.valueOf(userPositions.size()) });
+            log.info("用户id = {} 姓名 = {} 持仓中订单数: {}", userId, user.getRealName(), userPositions.size());
             //可用资金
             BigDecimal enable_user_amt = user.getEnableAmt();
-            // (可用+指数保证金+指数盈亏-手续费) /指数保证金<70%爆仓
+            // (可用+货币保证金+货币盈亏-手续费) /货币保证金<70%爆仓
             // 爆仓率
             BigDecimal bcl = new BigDecimal(0);
             BigDecimal yk = new BigDecimal(0);
@@ -658,7 +617,7 @@ public class UserServiceImpl implements IUserService {
             BigDecimal sxf = new BigDecimal(0);
             BigDecimal forceStopPercent = new BigDecimal(0);
             for (UserPosition position : userPositions) {
-                // 用户持仓指数现价
+                // 用户持仓货币现价
                 IndexInfo indexInfo = indexMap.get(position.getStockName());
                 forceStopPercent = indexInfo.getForceStopPercent();
                 //盈亏公式 做多 (现价—开仓价)*合约单位*手数   做空 (开仓价-现价)*合约单位*手数
@@ -679,14 +638,14 @@ public class UserServiceImpl implements IUserService {
                 ForceSellByUserId(userId);
 //                    iUserPositionService.closeOut(position.getId());
                 SiteTaskLog siteTaskLog = new SiteTaskLog();
-                siteTaskLog.setTaskType("强平任务-指数持仓");
+                siteTaskLog.setTaskType("强平任务-货币持仓");
                 String taskcnt = user.getRealName() + "被强平[两融盈亏达到最大亏损] 用户id = " + user.getId() + ", 可用资金 = " + enable_user_amt + "冻结保证金 = " + bzj +
                         ", 强平比例 = " + forceStopPercent + ", 总盈亏" + yk;
                 siteTaskLog.setTaskCnt(taskcnt);
-                String tasktarget = "此次强平" + userPositions.size() + "条指数持仓订单, 用户ID为" + userId;
+                String tasktarget = "此次强平" + userPositions.size() + "条持仓订单, 用户ID为" + userId;
                 siteTaskLog.setTaskTarget(tasktarget);
                 siteTaskLog.setAddTime(new Date());
-                siteTaskLog.setIsSuccess(Integer.valueOf(0));
+                siteTaskLog.setIsSuccess(0);
                 siteTaskLog.setErrorMsg("");
                 int insertTaskCount = this.siteTaskLogMapper.insert(siteTaskLog);
                 if (insertTaskCount > 0) {
@@ -701,86 +660,57 @@ public class UserServiceImpl implements IUserService {
 
     public void ForceSellIndexTask() {
         List<Integer> userIdList = this.iUserIndexPositionService.findDistinctUserIdList();
-
-        log.info("当前有 指数持仓 的用户数量 为 {}", Integer.valueOf(userIdList.size()));
-
+        log.info("当前有 货币持仓 的用户数量 为 {}", userIdList.size());
         for (int i = 0; i < userIdList.size(); i++) {
             log.info("=====================");
             Integer userId = (Integer)userIdList.get(i);
             User user = this.userMapper.selectByPrimaryKey(userId);
-
-
             List<UserIndexPosition> userIndexPositions = this.iUserIndexPositionService.findIndexPositionByUserIdAndSellPriceIsNull(userId);
-
-            log.info("用户id = {} 姓名 = {} 持仓中订单数: {}", new Object[] { userId, user
-                    .getRealName(), Integer.valueOf(userIndexPositions.size()) });
-
-
+            log.info("用户id = {} 姓名 = {} 持仓中订单数: {}", userId, user
+                    .getRealName(), Integer.valueOf(userIndexPositions.size()));
             IndexPositionVO indexPositionVO = this.iUserIndexPositionService.findUserIndexPositionAllProfitAndLose(userId);
-
-
             BigDecimal enable_index_amt = user.getEnableIndexAmt();
-
-
             BigDecimal all_freez_amt = indexPositionVO.getAllIndexFreezAmt();
-
             BigDecimal all_profit_and_lose = indexPositionVO.getAllIndexProfitAndLose();
-
-            log.info("用户 {} 可用资金 = {} 总冻结保证金 = {} 所有持仓单的总盈亏 = {}", new Object[] { userId, enable_index_amt, all_freez_amt, all_profit_and_lose });
-
-
-
+            log.info("用户 {} 可用资金 = {} 总冻结保证金 = {} 所有持仓单的总盈亏 = {}", userId, enable_index_amt, all_freez_amt, all_profit_and_lose);
             SiteIndexSetting siteIndexSetting = this.iSiteIndexSettingService.getSiteIndexSetting();
             BigDecimal force_stop_percent = siteIndexSetting.getForceSellPercent();
             BigDecimal force_stop_amt = force_stop_percent.multiply(all_freez_amt);
-
-
             BigDecimal user_force_amt = enable_index_amt.add(force_stop_amt);
             log.info("用户强制平仓线金额 = {}", user_force_amt);
-
             boolean isProfit = false;
-
             isProfit = (all_profit_and_lose.compareTo(new BigDecimal("0")) == -1 && user_force_amt.compareTo(all_profit_and_lose.negate()) != 1);
-
             if (isProfit) {
-                log.info("强制平仓该用户所有的指数持仓单");
-
+                log.info("强制平仓该用户所有的货币持仓单");
                 int[] arrs = new int[userIndexPositions.size()];
                 for (int k = 0; k < userIndexPositions.size(); k++) {
                     UserIndexPosition userIndexPosition = (UserIndexPosition)userIndexPositions.get(k);
-                    arrs[k] = userIndexPosition.getId().intValue();
+                    arrs[k] = userIndexPosition.getId();
                     try {
                         this.iUserIndexPositionService.sellIndex(userIndexPosition.getPositionSn(), 0);
                     }
                     catch (Exception e) {
-                        log.error("[盈亏达到最大亏损]强制平仓指数失败...");
+                        log.error("[盈亏达到最大亏损]强制平仓货币失败...");
                     }
                 }
-
-
                 SiteTaskLog siteTaskLog = new SiteTaskLog();
-                siteTaskLog.setTaskType("强平任务-指数持仓");
-                String accountType = (user.getAccountType().intValue() == 0) ? "正式用户" : "模拟用户";
-                String taskcnt = accountType + "-" + user.getRealName() + "被强平 [指数盈亏达到最大亏损] 用户 id = " + user.getId() + ", 可用资金 = " + enable_index_amt + ", 冻结资金 = " + all_freez_amt + ", 强平比例 = " + force_stop_percent + ", 总盈亏 = " + all_profit_and_lose + ", 强平线 = " + user_force_amt;
-
-
-
-
+                siteTaskLog.setTaskType("强平任务-货币持仓");
+                String accountType = (user.getAccountType() == 0) ? "正式用户" : "模拟用户";
+                String taskcnt = accountType + "-" + user.getRealName() + "被强平 [货币盈亏达到最大亏损] 用户 id = " + user.getId() + ", 可用资金 = " + enable_index_amt + ", 冻结资金 = " + all_freez_amt + ", 强平比例 = " + force_stop_percent + ", 总盈亏 = " + all_profit_and_lose + ", 强平线 = " + user_force_amt;
                 siteTaskLog.setTaskCnt(taskcnt);
-
-                String tasktarget = "此次强平" + userIndexPositions.size() + "条指数持仓订单, 订单号为" + Arrays.toString(arrs);
+                String tasktarget = "此次强平" + userIndexPositions.size() + "条货币持仓订单, 订单号为" + Arrays.toString(arrs);
                 siteTaskLog.setTaskTarget(tasktarget);
                 siteTaskLog.setAddTime(new Date());
-                siteTaskLog.setIsSuccess(Integer.valueOf(0));
+                siteTaskLog.setIsSuccess(0);
                 siteTaskLog.setErrorMsg("");
                 int insertTaskCount = this.siteTaskLogMapper.insert(siteTaskLog);
                 if (insertTaskCount > 0) {
-                    log.info("[盈亏达到最大亏损] 保存强制平仓 指数 task任务成功");
+                    log.info("[盈亏达到最大亏损] 保存强制平仓 货币 task任务成功");
                 } else {
-                    log.info("[盈亏达到最大亏损] 保存强制平仓 指数 task任务失败");
+                    log.info("[盈亏达到最大亏损] 保存强制平仓 货币 task任务失败");
                 }
             } else {
-                log.info("用户指数持仓未达到强制平仓线, 不做强平处理...");
+                log.info("用户货币持仓未达到强制平仓线, 不做强平处理...");
             }
 
             log.info("=====================");
@@ -789,8 +719,6 @@ public class UserServiceImpl implements IUserService {
 
     public void ForceSellFuturesTask() {
         List<Integer> userIdList = this.iUserFuturesPositionService.findDistinctUserIdList();
-
-
         for (int i = 0; i < userIdList.size(); i++) {
             log.info("===================== \n");
             Integer userId = (Integer)userIdList.get(i);
@@ -800,38 +728,26 @@ public class UserServiceImpl implements IUserService {
             List<UserFuturesPosition> userFuturesPositions = this.iUserFuturesPositionService.findFuturesPositionByUserIdAndSellPriceIsNull(userId);
             System.out.println("userFuturesPositions"+userFuturesPositions);
             System.out.println("继续");
-            log.info("用户id = {} 姓名 = {} 期货持仓中订单数 {}", new Object[] { userId, user
-                    .getRealName(), Integer.valueOf(userFuturesPositions.size()) });
-
+            log.info("用户id = {} 姓名 = {} 期货持仓中订单数 {}", userId, user
+                    .getRealName(), userFuturesPositions.size());
             FuturesPositionVO futuresPositionVO = this.iUserFuturesPositionService.findUserFuturesPositionAllProfitAndLose(userId);
-
             BigDecimal enable_Futures_amt = user.getEnableFutAmt();
-
             BigDecimal all_deposit_amt = futuresPositionVO.getAllFuturesDepositAmt();
-
             BigDecimal all_profit_and_lose = futuresPositionVO.getAllFuturesProfitAndLose();
-
-            log.info("用户 {} 可用资金 = {} 总冻结保证金 = {} 所有持仓单的总盈亏 = {}", new Object[] { userId, enable_Futures_amt, all_deposit_amt, all_profit_and_lose });
-
-
-
+            log.info("用户 {} 可用资金 = {} 总冻结保证金 = {} 所有持仓单的总盈亏 = {}", userId, enable_Futures_amt, all_deposit_amt, all_profit_and_lose);
             SiteFuturesSetting siteFuturesSetting = this.iSiteFuturesSettingService.getSetting();
             BigDecimal force_stop_percent = siteFuturesSetting.getForceSellPercent();
             BigDecimal force_stop_amt = force_stop_percent.multiply(all_deposit_amt);
             BigDecimal user_force_amt = enable_Futures_amt.add(force_stop_amt);
             log.info("用户强制平仓线金额 = {}", user_force_amt);
-
             boolean isProfit = false;
-
             isProfit = (all_profit_and_lose.compareTo(new BigDecimal("0")) == -1 && user_force_amt.compareTo(all_profit_and_lose.negate()) != 1);
-
             if (isProfit) {
                 log.info("强制平仓用户 {} 所有的 期货 持仓单", user.getId());
-
                 int[] arrs = new int[userFuturesPositions.size()];
                 for (int k = 0; k < userFuturesPositions.size(); k++) {
                     UserFuturesPosition userFuturesPosition = (UserFuturesPosition)userFuturesPositions.get(k);
-                    arrs[k] = userFuturesPosition.getId().intValue();
+                    arrs[k] = userFuturesPosition.getId();
                     try {
                         this.iUserFuturesPositionService.sellFutures(userFuturesPosition.getPositionSn(), 0);
                     }
@@ -839,21 +755,15 @@ public class UserServiceImpl implements IUserService {
                         log.error("[盈亏达到最大亏损] 强制平仓 期货 失败...");
                     }
                 }
-
                 SiteTaskLog siteTaskLog = new SiteTaskLog();
                 siteTaskLog.setTaskType("强平任务-期货持仓");
-                String accountType = (user.getAccountType().intValue() == 0) ? "正式用户" : "模拟用户";
+                String accountType = (user.getAccountType() == 0) ? "正式用户" : "模拟用户";
                 String taskcnt = accountType + "-" + user.getRealName() + "被强平[期货盈亏达到最大亏损]用户id = " + user.getId() + ", 可用资金 = " + enable_Futures_amt + ", 冻结保证金 = " + all_deposit_amt + ", 强平比例 = " + force_stop_percent + ", 总盈亏" + all_profit_and_lose + ", 强平线:" + user_force_amt;
-
-
-
-
                 siteTaskLog.setTaskCnt(taskcnt);
-
                 String tasktarget = "此次强平" + userFuturesPositions.size() + "条期货持仓订单, 订单号为" + Arrays.toString(arrs);
                 siteTaskLog.setTaskTarget(tasktarget);
                 siteTaskLog.setAddTime(new Date());
-                siteTaskLog.setIsSuccess(Integer.valueOf(0));
+                siteTaskLog.setIsSuccess(0);
                 siteTaskLog.setErrorMsg("");
                 int insertTaskCount = this.siteTaskLogMapper.insert(siteTaskLog);
                 if (insertTaskCount > 0) {
@@ -922,11 +832,10 @@ public class UserServiceImpl implements IUserService {
         user.setEnableAmt(new BigDecimal(amt));
         user.setSumChargeAmt(new BigDecimal("0"));
         user.setSumBuyAmt(new BigDecimal("0"));
-        user.setIsLock(Integer.valueOf(0));
-        user.setIsLogin(Integer.valueOf(0));
-        user.setIsActive(Integer.valueOf(0));
+        user.setIsLock(0);
+        user.setIsLogin(0);
+        user.setIsActive(0);
         user.setRegTime(new Date());
-
         if (accountType == 1) {
 //            user.setPhone(phone+"-Active");
 //            if (new BigDecimal(amt).compareTo(new BigDecimal("100000")) == -1){
@@ -937,21 +846,17 @@ public class UserServiceImpl implements IUserService {
             user.setIsActive(2);
 //            user.setIdCard("000000000000000000");
         }
-
         user.setUserIndexAmt(new BigDecimal("0"));
         user.setEnableIndexAmt(new BigDecimal("0"));
         user.setUserFutAmt(new BigDecimal("0"));
         user.setEnableFutAmt(new BigDecimal("0"));
-
         if (agentId != null) {
             AgentUser agentUser = this.agentUserMapper.selectByPrimaryKey(agentId);
             user.setAgentName(agentUser.getAgentName());
             user.setAgentId(agentUser.getId());
         }
-
         int insertCount = this.userMapper.insert(user);
         if (insertCount > 0) {
-
 //            if (accountType != 1){
 ////                user.setUserPwd("123456");
 //                user.setPhone(user.getPhone()+"-Active");
@@ -987,23 +892,16 @@ public class UserServiceImpl implements IUserService {
 //                    return ServerResponse.createBySuccessMsg("模拟用户添加成功。模拟银行卡添加失败,请手动添加");
 //                }
 //            }
-
             return ServerResponse.createBySuccessMsg("用户添加成功");
         }
         return ServerResponse.createByErrorMsg("用户添加失败");
     }
 
 
-
-
-
     public ServerResponse listByAdmin(String realName, String phone, Integer agentId, Integer accountType, int pageNum, int pageSize, HttpServletRequest request) {
         PageHelper.startPage(pageNum, pageSize);
-
         List<User> users = this.userMapper.listByAdmin(realName, phone, agentId, accountType);
-
         PageInfo pageInfo = new PageInfo(users);
-
         return ServerResponse.createBySuccess(pageInfo);
     }
 
@@ -1019,13 +917,11 @@ public class UserServiceImpl implements IUserService {
         if (user == null) {
             return ServerResponse.createByErrorMsg("用户不存在");
         }
-
         if (user.getIsLock().intValue() == 1) {
             user.setIsLock(Integer.valueOf(0));
         } else {
             user.setIsLock(Integer.valueOf(1));
         }
-
         int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
         if (updateCount > 0) {
             return ServerResponse.createBySuccess("修改成功");
@@ -1041,12 +937,10 @@ public class UserServiceImpl implements IUserService {
         if (userId == null || amt == null || direction == null) {
             return ServerResponse.createByErrorMsg("参数不能为空");
         }
-
         User user = this.userMapper.selectByPrimaryKey(userId);
         if (user == null) {
             return ServerResponse.createByErrorMsg("用户不存在");
         }
-
         BigDecimal user_amt = user.getUserAmt();
         BigDecimal user_enable = user.getEnableAmt();
 
@@ -1069,13 +963,9 @@ public class UserServiceImpl implements IUserService {
         } else {
             return ServerResponse.createByErrorMsg("不存在此操作");
         }
-
-
         user.setUserAmt(user_amt_back);
         user.setEnableAmt(user_enable_back);
         this.userMapper.updateByPrimaryKeySelective(user);
-
-
         SiteTaskLog siteTaskLog = new SiteTaskLog();
         siteTaskLog.setTaskType("管理员修改金额");
         StringBuffer cnt = new StringBuffer();
@@ -1090,12 +980,9 @@ public class UserServiceImpl implements IUserService {
                 .append("修改前 总资金 = ").append(user_amt).append(" 可用 = ").append(user_enable)
                 .append("修改后 总资金 = ").append(user_amt_back).append(" 可用 = ").append(user_enable_back);
         target.append(" - 备注:"+info);
-
         siteTaskLog.setTaskTarget(target.toString());
-
         siteTaskLog.setIsSuccess(Integer.valueOf(0));
         siteTaskLog.setAddTime(new Date());
-
         int insertCount = this.siteTaskLogMapper.insert(siteTaskLog);
         if (insertCount > 0) {
             return ServerResponse.createBySuccessMsg("修改资金成功");
@@ -1111,50 +998,37 @@ public class UserServiceImpl implements IUserService {
         String logintoken = CookieUtils.readLoginToken(request, cookie_name);
         String adminJson = RedisShardedPoolUtils.get(logintoken);
         SiteAdmin siteAdmin = (SiteAdmin)JsonUtil.string2Obj(adminJson, SiteAdmin.class);
-
         log.info("管理员 {} 删除用户 {}", siteAdmin.getAdminName(), userId);
-
-
         int delChargeCount = this.iUserRechargeService.deleteByUserId(userId);
         if (delChargeCount > 0) {
             log.info("删除 充值 记录成功");
         } else {
             log.info("删除 充值 记录失败");
         }
-
-
         int delWithdrawCount = this.iUserWithdrawService.deleteByUserId(userId);
         if (delWithdrawCount > 0) {
             log.info("删除 提现 记录成功");
         } else {
             log.info("删除 提现 记录失败");
         }
-
-
         int delCashCount = this.iUserCashDetailService.deleteByUserId(userId);
         if (delCashCount > 0) {
             log.info("删除 资金 记录成功");
         } else {
             log.info("删除 资金 记录成功");
         }
-
-
         int delPositionCount = this.iUserPositionService.deleteByUserId(userId);
         if (delPositionCount > 0) {
             log.info("删除 持仓 记录成功");
         } else {
             log.info("删除 持仓 记录失败");
         }
-
-
         int delLogCount = this.iSiteLoginLogService.deleteByUserId(userId);
         if (delLogCount > 0) {
             log.info("删除 登录 记录成功");
         } else {
             log.info("删除 登录 记录失败");
         }
-
-
         int delUserCount = this.userMapper.deleteByPrimaryKey(userId);
         if (delUserCount > 0) {
             return ServerResponse.createBySuccessMsg("操作成功");
@@ -1162,45 +1036,27 @@ public class UserServiceImpl implements IUserService {
         return ServerResponse.createByErrorMsg("操作失败, 查看日志");
     }
 
-
-
-
-
     public int CountUserSize(Integer accountType) { return this.userMapper.CountUserSize(accountType); }
 
-
-
-
-
     public BigDecimal CountUserAmt(Integer accountType) { return this.userMapper.CountUserAmt(accountType); }
 
-
-
-
     public BigDecimal CountEnableAmt(Integer accountType) { return this.userMapper.CountEnableAmt(accountType); }
 
-
-
-
     public ServerResponse authByAdmin(Integer userId, Integer state, String authMsg) {
         if (state == null || userId == null) {
             return ServerResponse.createByErrorMsg("id和state不能为空");
         }
-
         User user = this.userMapper.selectByPrimaryKey(userId);
         if (user == null) {
             return ServerResponse.createByErrorMsg("查不到此用户");
         }
-
         if (state.intValue() == 3) {
             if (StringUtils.isBlank(authMsg)) {
                 return ServerResponse.createByErrorMsg("审核失败信息必填");
             }
             user.setAuthMsg(authMsg);
         }
-
         user.setIsActive(state);
-
         int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
         if (updateCount > 0) {
             return ServerResponse.createBySuccessMsg("审核成功");
@@ -1211,7 +1067,6 @@ public class UserServiceImpl implements IUserService {
     @Override
     public ServerResponse findIdWithPwd(String phone) {
         String idWithPwd = userMapper.findIdWithPwd(phone);
-
         if (idWithPwd==null){
             return ServerResponse.createByErrorMsg("请设置提现密码!");
         }else {
@@ -1221,17 +1076,13 @@ public class UserServiceImpl implements IUserService {
 
     @Override
     public ServerResponse updateWithPwd(String with_pwd, String phone) {
-
         if (StringUtils.isBlank(with_pwd)||StringUtils.isBlank(phone)){
             return ServerResponse.createByErrorMsg("参数不能为空");
         }
-
         String withPwd = userMapper.findWithPwd(with_pwd);
-
         if (withPwd!=null){
             return ServerResponse.createByErrorMsg("您已经添加了提现密码!");
         }
-
         int i = userMapper.updateWithPwd(with_pwd, phone);
         if (i>0){
             return ServerResponse.createBySuccessMsg("添加成功!");
@@ -1243,7 +1094,6 @@ public class UserServiceImpl implements IUserService {
 
     private AgentUserListVO assembleAgentUserListVO(User user, BigDecimal forcePercent, BigDecimal indexForcePercent, BigDecimal futuresForcePercent) {
         AgentUserListVO agentUserListVO = new AgentUserListVO();
-
         agentUserListVO.setId(user.getId());
         agentUserListVO.setAgentId(user.getAgentId());
         agentUserListVO.setAgentName(user.getAgentName());
@@ -1255,58 +1105,38 @@ public class UserServiceImpl implements IUserService {
         agentUserListVO.setIsLogin(user.getIsLogin());
         agentUserListVO.setRegAddress(user.getRegAddress());
         agentUserListVO.setIsActive(user.getIsActive());
-
-
         agentUserListVO.setUserAmt(user.getUserAmt());
         agentUserListVO.setEnableAmt(user.getEnableAmt());
-
         agentUserListVO.setUserIndexAmt(user.getUserIndexAmt());
         agentUserListVO.setEnableIndexAmt(user.getEnableIndexAmt());
-
         agentUserListVO.setUserFuturesAmt(user.getUserFutAmt());
         agentUserListVO.setEnableFuturesAmt(user.getEnableFutAmt());
-
-
-
         PositionVO positionVO = this.iUserPositionService.findUserPositionAllProfitAndLose(user.getId());
         BigDecimal allProfitAndLose = positionVO.getAllProfitAndLose();
         BigDecimal allFreezAmt = positionVO.getAllFreezAmt();
         agentUserListVO.setAllProfitAndLose(allProfitAndLose);
         agentUserListVO.setAllFreezAmt(allFreezAmt);
-
         BigDecimal forceLine = forcePercent.multiply(allFreezAmt);
         forceLine = forceLine.add(user.getEnableAmt());
         agentUserListVO.setForceLine(forceLine);
-
-
-
         IndexPositionVO indexPositionVO = this.iUserIndexPositionService.findUserIndexPositionAllProfitAndLose(user.getId());
         agentUserListVO.setAllIndexProfitAndLose(indexPositionVO.getAllIndexProfitAndLose());
         agentUserListVO.setAllIndexFreezAmt(indexPositionVO.getAllIndexFreezAmt());
-
         BigDecimal indexForceLine = indexForcePercent.multiply(indexPositionVO.getAllIndexFreezAmt());
         indexForceLine = indexForceLine.add(user.getEnableIndexAmt());
         agentUserListVO.setIndexForceLine(indexForceLine);
-
-
-
         FuturesPositionVO futuresPositionVO = this.iUserFuturesPositionService.findUserFuturesPositionAllProfitAndLose(user.getId());
         agentUserListVO.setAllFuturesFreezAmt(futuresPositionVO.getAllFuturesDepositAmt());
         agentUserListVO.setAllFuturesProfitAndLose(futuresPositionVO.getAllFuturesProfitAndLose());
-
         BigDecimal futuresForceLine = futuresForcePercent.multiply(futuresPositionVO.getAllFuturesDepositAmt());
         futuresForceLine = futuresForceLine.add(user.getEnableFutAmt());
         agentUserListVO.setFuturesForceLine(futuresForceLine);
-
-
-
         UserBank userBank = this.iUserBankService.findUserBankByUserId(user.getId());
         if (userBank != null) {
             agentUserListVO.setBankName(userBank.getBankName());
             agentUserListVO.setBankNo(userBank.getBankNo());
             agentUserListVO.setBankAddress(userBank.getBankAddress());
         }
-
         return agentUserListVO;
     }
 
@@ -1330,43 +1160,31 @@ public class UserServiceImpl implements IUserService {
         userInfoVO.setImg3Key(user.getImg3Key());
         userInfoVO.setIsActive(user.getIsActive());
         userInfoVO.setAuthMsg(user.getAuthMsg());
-
         userInfoVO.setEnableAmt(user.getEnableAmt());
-
         // 冻结保证金  总盈亏
         PositionVO positionVO = this.iUserPositionService.findUserPositionAllProfitAndLose(user.getId());
         userInfoVO.setAllFreezAmt(positionVO.getAllFreezAmt());
         BigDecimal allProfitAndLose = positionVO.getAllProfitAndLose();
         userInfoVO.setAllProfitAndLose(allProfitAndLose);
-
         BigDecimal userAllAmt = user.getUserAmt();
         userAllAmt = userAllAmt.add(allProfitAndLose);
         userInfoVO.setUserAmt(userAllAmt);
-
         userInfoVO.setEnableIndexAmt(user.getEnableIndexAmt());
-
         IndexPositionVO indexPositionVO = this.iUserIndexPositionService.findUserIndexPositionAllProfitAndLose(user.getId());
         BigDecimal allIndexProfitAndLose = indexPositionVO.getAllIndexProfitAndLose();
         userInfoVO.setAllIndexProfitAndLose(allIndexProfitAndLose);
         userInfoVO.setAllIndexFreezAmt(indexPositionVO.getAllIndexFreezAmt());
-
         BigDecimal userAllIndexAmt = user.getUserIndexAmt();
         userAllIndexAmt = userAllIndexAmt.add(allIndexProfitAndLose);
         userInfoVO.setUserIndexAmt(userAllIndexAmt);
-
         userInfoVO.setEnableFuturesAmt(user.getEnableFutAmt());
-
         FuturesPositionVO futuresPositionVO = this.iUserFuturesPositionService.findUserFuturesPositionAllProfitAndLose(user.getId());
-
         userInfoVO.setAllFuturesFreezAmt(futuresPositionVO.getAllFuturesDepositAmt());
-
         BigDecimal allFuturesProfitAndLose = futuresPositionVO.getAllFuturesProfitAndLose();
         userInfoVO.setAllFuturesProfitAndLose(allFuturesProfitAndLose);
-
         BigDecimal userAllFuturesAmt = user.getUserFutAmt();
         userAllFuturesAmt = userAllFuturesAmt.add(allFuturesProfitAndLose);
         userInfoVO.setUserFuturesAmt(userAllFuturesAmt);
-
         // 获取用户是否有绑定银行卡
         if(0 == userMapper.selectHaveBankCardByUserId(userInfoVO.getId())){
             userInfoVO.setHaveBankCard(false);
@@ -1377,24 +1195,6 @@ public class UserServiceImpl implements IUserService {
     }
 
 
-    public static void main(String[] args) {
-        int a = 3;
-
-        System.out.println((a != 0));
-        System.out.println((a != 3));
-
-        System.out.println(((a != 0) ? 1 : 0) & ((a != 3) ? 1 : 0));
-        System.out.println((a != 0 && a != 3));
-
-
-        if (a != 0 && a != 3) {
-            System.out.println("不能认证");
-        } else {
-            System.out.println("可以认证");
-        }
-    }
-
-
     @Override
     public void updateUserAmt(Double amt, Integer user_id) {
         userMapper.updateUserAmt(amt, user_id);
@@ -1429,7 +1229,6 @@ public class UserServiceImpl implements IUserService {
         agentUserList.add(currentAgent);
         Set<Integer> pidSet = new HashSet<>();
         pidSet.add(currentAgent.getId());
-
         List<AgentUser> agentUserListTemp = this.agentUserMapper.selectAgentUserList();
         for(AgentUser a : agentUserListTemp){
             if(pidSet.contains(a.getParentId())){

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

@@ -122,7 +122,7 @@ public class UserWithdrawServiceImpl implements IUserWithdrawService {
             }
             BigDecimal index_user_amt = user.getUserIndexAmt();
             if (index_user_amt.compareTo(new BigDecimal("0")) == -1) {
-                return ServerResponse.createByErrorMsg("指数资金不能小于0");
+                return ServerResponse.createByErrorMsg("货币资金不能小于0");
             }
             BigDecimal futures_user_amt = user.getUserFutAmt();
             if (futures_user_amt.compareTo(new BigDecimal("0")) == -1) {

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

@@ -10,12 +10,12 @@ public enum IndexEnum {
     /**
      *
      */
-    HSI_HI("HSI.HI", "HSI.HI", "恒生指数", "HSI_HI", "index"),
+    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"),
+    SH000001("000001.SH", "000001.SH", "上证货币", "000001_sh", "index"),
     SZ399001("399001.SZ", "399001.SZ", "深证成指", "399001_sz", "index"),
     SZ399006("399006.SZ", "399006.SZ", "创业扳指", "399006_sz", "index");
 
@@ -27,7 +27,7 @@ public enum IndexEnum {
 
     private String dbName;
 
-    // 股票"stock",  指数"index"
+    // 股票"stock",  货币"index"
     private String type;
 
     IndexEnum(String code, String enName, String cnName, String dbName, String type) {

+ 10 - 0
src/main/java/com/xc/utils/stock/StockTableUtils.java

@@ -0,0 +1,10 @@
+package com.xc.utils.stock;
+
+public class StockTableUtils {
+
+    public static String getDbName(String symbol){
+        String szOrSh = symbol.substring(0, 2);
+        symbol = symbol.replace(szOrSh,"") + "_" + szOrSh;
+        return symbol.toLowerCase();
+    }
+}

+ 2 - 2
src/main/java/com/xc/utils/stock/sina/SinaStockApi.java

@@ -36,7 +36,7 @@ public class SinaStockApi {
         try {
             sina_result = HttpClientRequest.doGet(sina_url + stockGid);
         } catch (Exception e) {
-            log.error("获取指数行情出错,错误信息 = {}", e);
+            log.error("获取货币行情出错,错误信息 = {}", e);
         }
         return sina_result.substring(sina_result.indexOf("=") + 2);
     }
@@ -196,7 +196,7 @@ public class SinaStockApi {
         try {
             hqstr = HttpClientRequest.doGet(minUrl);
         } catch (Exception e) {
-            log.error("获取指数K线分时图出错,错误信息 = {}", e);
+            log.error("获取货币K线分时图出错,错误信息 = {}", e);
         }
 
         log.info(" time = {} ma = {} size = {}", new Object[]{Integer.valueOf(time), Integer.valueOf(ma), Integer.valueOf(size)});

+ 1 - 1
src/main/java/com/xc/vo/index/SymbolInfoVo.java

@@ -34,7 +34,7 @@ public class SymbolInfoVo {
 
     // 是否是没有成交量
     private List<Boolean> has_no_volume;
-    // 类型 股票为stock 指数为index
+    // 类型 股票为stock 货币为index
     private List<String> type;
     // 商品唯一ID
     private List<String> ticker;

+ 1 - 1
src/main/java/com/xc/vo/index/SymbolVo.java

@@ -39,7 +39,7 @@ public class SymbolVo {
     //DWM支持的
     private boolean has_daily;
     private boolean has_weekly_and_monthly;
-    // 类型 股票为stock 指数为index
+    // 类型 股票为stock 货币为index
     private String type;
     // 商品唯一ID
     private String ticker;

+ 22 - 0
src/main/java/com/xc/vo2/HistoryVo.java

@@ -0,0 +1,22 @@
+package com.xc.vo2;
+
+import lombok.Data;
+
+@Data
+public class HistoryVo {
+    private Integer id;
+    private Long realTime;
+    private Double close;
+    private Double open;
+    private Double high;
+    private Double low;
+    private Double volume;
+    private Long dateOne;
+    private Long dateFive;
+    private Long dateFifteen;
+    private Long dateThirty;
+    private Long dateSixty;
+    private Long time;
+    private String date;
+
+}

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 250 - 0
src/main/java/com/xc/vo2/StockDbVO.java


+ 14 - 0
src/main/java/com/xc/vo2/StockPriceVo.java

@@ -0,0 +1,14 @@
+package com.xc.vo2;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class StockPriceVo {
+    private Integer id;
+
+    private BigDecimal nowPrice;
+
+    private Long realTime;
+}

+ 10 - 0
src/main/java/com/xc/vo2/StockVolumeVo.java

@@ -0,0 +1,10 @@
+package com.xc.vo2;
+
+import lombok.Data;
+
+@Data
+public class StockVolumeVo {
+
+    private Double volume;
+    private String date;
+}

+ 14 - 104
src/main/java/mappers/StockMapper.xml

@@ -13,6 +13,7 @@
         <result column="is_show" property="isShow"/>
         <result column="add_time" property="addTime"/>
         <result column="data_db_name" property="dataDbName"/>
+        <result column="site_lever" property="siteLever"/>
         <!--    <constructor >-->
         <!--      <idArg column="id" jdbcType="INTEGER" javaType="java.lang.Integer" />-->
         <!--      <arg column="stock_name" jdbcType="VARCHAR" javaType="java.lang.String" />-->
@@ -26,6 +27,7 @@
         <!--      <arg column="add_time" jdbcType="TIMESTAMP" javaType="java.util.Date" />-->
         <!--    </constructor>-->
     </resultMap>
+
     <sql id="Base_Column_List">
         id,
         stock_name,
@@ -61,7 +63,8 @@
         control,
         transElseBegin,
         transElseEnd,
-        data_db_name
+        data_db_name,
+        site_lever
   </sql>
 
     <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
@@ -70,10 +73,12 @@
         from stock
         where id = #{id,jdbcType=INTEGER}
     </select>
+
     <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
     delete from stock
     where id = #{id,jdbcType=INTEGER}
   </delete>
+
     <insert id="insert" parameterType="com.xc.pojo.Stock">
     insert into stock (
       	  	       id,
@@ -157,164 +162,102 @@
             <if test="stockName != null">
                 stock_name,
             </if>
-
-
             <if test="stockCode != null">
                 stock_code,
             </if>
-
-
             <if test="stockSpell != null">
                 stock_spell,
             </if>
-
-
             <if test="stockType != null">
                 stock_type,
             </if>
-
-
             <if test="stockGid != null">
                 stock_gid,
             </if>
-
-
             <if test="stockPlate != null">
                 stock_plate,
             </if>
-
-
             <if test="isLock != null">
                 is_lock,
             </if>
-
-
             <if test="isShow != null">
                 is_show,
             </if>
-
-
             <if test="addTime != null">
                 add_time,
             </if>
-
-
             <if test="depositAmt != null">
                 depositAmt,
             </if>
-
-
             <if test="transFee != null">
                 transFee,
             </if>
-
-
             <if test="buyMinNum != null">
                 buyMinNum,
             </if>
-
-
             <if test="buyMaxNum != null">
                 buyMaxNum,
             </if>
-
-
             <if test="transAmBegin != null">
                 transAmBegin,
             </if>
-
-
             <if test="transAmEnd != null">
                 transAmEnd,
             </if>
-
-
             <if test="transPmBegin != null">
                 transPmBegin,
             </if>
-
-
             <if test="transPmEnd != null">
                 transPmEnd,
             </if>
-
-
             <if test="spread != null">
                 spread,
             </if>
-
-
             <if test="demurrage != null">
                 demurrage,
             </if>
-
-
             <if test="entryOrdersAgio != null">
                 entryOrdersAgio,
             </if>
-
-
             <if test="entryOrdersDate != null">
                 entryOrdersDate,
             </if>
-
-
             <if test="forceStopPercent != null">
                 forceStopPercent,
             </if>
-
-
             <if test="contractSize != null">
                 contractSize,
             </if>
-
-
             <if test="positionsMax != null">
                 positionsMax,
             </if>
-
-
             <if test="homeShow != null">
                 homeShow,
             </if>
-
-
             <if test="listShow != null">
                 listShow,
             </if>
-
-
             <if test="transState != null">
                 transState,
             </if>
-
-
             <if test="riskParam != null">
                 riskParam,
             </if>
-
-
             <if test="eachPoint != null">
                 eachPoint,
             </if>
-
-
             <if test="floatRate != null">
                 floatRate,
             </if>
-
-
             <if test="control != null">
                 control,
             </if>
-
             <if test="transElseBegin != null">
                 transElseBegin,
             </if>
             <if test="transElseEnd != null">
                 transElseEnd,
             </if>
-
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="id != null">
@@ -421,6 +364,7 @@
             </if>
         </trim>
     </insert>
+
     <update id="updateByPrimaryKeySelective" parameterType="com.xc.pojo.Stock">
         update stock
         <set>
@@ -523,48 +467,12 @@
             <if test="transElseEnd != null">
                 transElseEnd = #{transElseEnd,jdbcType=VARCHAR},
             </if>
+            <if test="siteLever != null">
+                site_lever = #{siteLever,jdbcType=INTEGER},
+            </if>
         </set>
         where id = #{id,jdbcType=INTEGER}
     </update>
-    <update id="updateByPrimaryKey" parameterType="com.xc.pojo.Stock">
-    update stock
-    set 
-stock_name = #{stockName,jdbcType=VARCHAR},
-    	         	     	 stock_code = #{stockCode,jdbcType=VARCHAR},
-    	         	     	 stock_spell = #{stockSpell,jdbcType=VARCHAR},
-    	         	     	 stock_type = #{stockType,jdbcType=VARCHAR},
-    	         	     	 stock_gid = #{stockGid,jdbcType=VARCHAR},
-    	         	     	 stock_plate = #{stockPlate,jdbcType=VARCHAR},
-    	         	     	 is_lock = #{isLock,jdbcType=INTEGER},
-    	         	     	 is_show = #{isShow,jdbcType=INTEGER},
-    	         	     	 add_time = #{addTime,jdbcType=TIMESTAMP},
-    	         	     	 depositAmt = #{depositAmt,jdbcType=INTEGER},
-    	         	     	 transFee = #{transFee,jdbcType=INTEGER},
-    	         	     	 buyMinNum = #{buyMinNum,jdbcType=INTEGER},
-    	         	     	 buyMaxNum = #{buyMaxNum,jdbcType=INTEGER},
-    	         	     	 transAmBegin = #{transAmBegin,jdbcType=VARCHAR},
-    	         	     	 transAmEnd = #{transAmEnd,jdbcType=VARCHAR},
-    	         	     	 transPmBegin = #{transPmBegin,jdbcType=VARCHAR},
-    	         	     	 transPmEnd = #{transPmEnd,jdbcType=VARCHAR},
-    	         	     	 spread = #{spread,jdbcType=INTEGER},
-    	         	     	 demurrage = #{demurrage,jdbcType=INTEGER},
-    	         	     	 entryOrdersAgio = #{entryOrdersAgio,jdbcType=DECIMAL},
-    	         	     	 entryOrdersDate = #{entryOrdersDate,jdbcType=VARCHAR},
-    	         	     	 forceStopPercent = #{forceStopPercent,jdbcType=DECIMAL},
-    	         	     	 contractSize = #{contractSize,jdbcType=INTEGER},
-    	         	     	 positionsMax = #{positionsMax,jdbcType=INTEGER},
-    	         	     	 homeShow = #{homeShow,jdbcType=INTEGER},
-    	         	     	 listShow = #{listShow,jdbcType=INTEGER},
-    	         	     	 transState = #{transState,jdbcType=INTEGER},
-    	         	     	 riskParam = #{riskParam,jdbcType=DECIMAL},
-    	         	     	 eachPoint = #{eachPoint,jdbcType=DECIMAL},
-    	         	     	 floatRate = #{floatRate,jdbcType=INTEGER},
-    	         	     	 control = #{control,jdbcType=INTEGER},
-    	         	     	 transElseBegin = #{transElseBegin,jdbcType=VARCHAR},
-    	         	     	 transElseEnd = #{transElseEnd,jdbcType=VARCHAR}
-    where id = #{id,jdbcType=INTEGER}
-  </update>
-
 
     <select id="findStockListByKeyWords" resultMap="BaseResultMap" parameterType="map">
         SELECT
@@ -573,8 +481,9 @@ stock_name = #{stockName,jdbcType=VARCHAR},
         <where>
             is_show = #{show}
             <if test="keyWords != null and keyWords != '' ">
-                and stock_code like CONCAT('%','${keyWords}','%')
+                and (stock_code like CONCAT('%','${keyWords}','%')
                 or stock_name like CONCAT('%',#{keyWords},'%')
+                or stock_spell like CONCAT('%',#{keyWords},'%'))
             </if>
             <if test="stockPlate != null and stockPlate != '' ">
                 and stock_plate = #{stockPlate}
@@ -626,6 +535,7 @@ stock_name = #{stockName,jdbcType=VARCHAR},
             stock
         WHERE
             stock_code = #{code}
+            limit 1
     </select>
     <select id="findStockByName" resultMap="BaseResultMap" parameterType="string">
         SELECT
@@ -732,4 +642,4 @@ stock_name = #{stockName,jdbcType=VARCHAR},
             id desc
         limit 1
     </select>
-</mapper>
+</mapper>

+ 300 - 0
src/main/java/mappers2/KLinkStockMapper.xml

@@ -0,0 +1,300 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.xc.dao2.KLinkStockMapper" >
+
+    <select id="getHistoryNew" resultType="com.xc.vo2.HistoryVo">
+        select
+          id,
+          realTime,
+          `now` as `close`,
+          `open`,
+          high,
+          low,
+          volume,
+          realTime `time`
+        from
+        ${dbTableName}
+        where
+        1=1
+        <![CDATA[ and realTime >= #{startDate,jdbcType=VARCHAR}]]>
+        <![CDATA[ and realTime <= #{endDate,jdbcType=VARCHAR}]]>
+--         <![CDATA[ and ((`time` >= 130001 and `time` <= 150000) or (`time` >= 93001 and `time` <= 113000)) ]]>
+        order by realTime asc
+    </select>
+
+    <select id="getDataByRt" resultType="com.xc.vo2.HistoryVo">
+        select
+            t.id id,
+            t.high high,
+            t.low low,
+            t.`open` `open`,
+            t.`close` `close`,
+            t.realTime realTime,
+            t.volume volume,
+            t.groupTime `time`,
+            t.date `date`
+        from
+            (
+            select
+                min( id ) id,
+                max( now ) high,
+                min( now ) low,
+                substring_index( group_concat( now order by `realtime` ), ',', 1 ) as `open`,
+                substring_index( group_concat( now order by `realtime` desc ), ',', 1 ) as `close`,
+                max( realTime ) realTime,
+                substring_index( group_concat( volume order by `realtime` desc ), ',', 1 ) as `volume`,
+                substring_index( group_concat( `date` ORDER BY `realtime` DESC), ',', 1 ) AS `date`,
+                <if test='"1" == resolution'>
+                    dateOne groupTime
+                </if>
+                <if test='"5" == resolution'>
+                    dateFive groupTime
+                </if>
+                <if test='"15" == resolution'>
+                    dateFifteen groupTime
+                </if>
+                <if test='"30" == resolution'>
+                    dateThirty groupTime
+                </if>
+                <if test='"60" == resolution'>
+                    dateSixty groupTime
+                </if>
+            from
+                ${dbTableName}
+--             where
+--                 <![CDATA[ (`time` >= 130001 and `time` <= 150000) ]]>
+-- 		        <![CDATA[or (`time` >= 93001 and `time` <= 113000) ]]>
+            group by
+                <if test='"1" == resolution'>
+                    dateOne
+                </if>
+                <if test='"5" == resolution'>
+                    dateFive
+                </if>
+                <if test='"15" == resolution'>
+                    dateFifteen
+                </if>
+                <if test='"30" == resolution'>
+                    dateThirty
+                </if>
+                <if test='"60" == resolution'>
+                    dateSixty
+                </if>
+            ) t
+        where
+            1 = 1
+            <![CDATA[ and t.groupTime >= #{startDate,jdbcType=VARCHAR}]]>
+            <![CDATA[ and t.groupTime <= #{endDate,jdbcType=VARCHAR}]]>
+        order by
+            t.realTime asc
+    </select>
+
+    <select id="getDataByHist" resultType="com.xc.vo2.HistoryVo">
+        select
+            t.id id,
+            t.high high,
+            t.low low,
+            t.`open` `open`,
+            t.`close` `close`,
+            t.realTime realTime,
+            t.volume volume,
+            t.groupTime `time`
+        from
+        (
+            select
+                min( id ) id,
+                max( high ) high,
+                min( low ) low,
+                substring_index( group_concat( `open` order by `realtime` ), ',', 1 ) as `open`,
+                substring_index( group_concat( `close` order by `realtime` desc ), ',', 1 ) as `close`,
+--                 max( realtime ) realTime,
+                substring_index( group_concat( volume order by `realtime` desc ), ',', 1 ) as `volume`,
+                <if test='"1D" == resolution'>
+                    realTime groupTime,
+                    realtime realTime
+                </if>
+                <if test='"1W" == resolution'>
+                    date_week groupTime,
+                    date_week realTime
+                </if>
+                <if test='"1M" == resolution'>
+--                     unix_timestamp(str_to_date(concat(dateMonth, '01' ), '%Y%m%d' )) groupTime,
+                    date_month groupTime,
+                    date_month realTime
+                </if>
+                <if test='"1Y" == resolution or "M" == resolution'>
+--                     unix_timestamp(str_to_date(concat(dateYear, '0101' ), '%Y%m%d' )) groupTime,
+                    date_year groupTime,
+                    date_year realTime
+                </if>
+            from
+                ${dbTableName}
+            group by
+                <if test='"1D" == resolution'>
+                    realTime
+                </if>
+                <if test='"1W" == resolution'>
+                    date_week
+                </if>
+                <if test='"1M" == resolution'>
+                    date_month
+                </if>
+                <if test='"1Y" == resolution or "M" == resolution'>
+                    date_year
+                </if>
+        ) t
+        where
+            1 = 1
+            <![CDATA[ and t.groupTime >= #{startDate,jdbcType=VARCHAR}]]>
+            <![CDATA[ and t.groupTime <= #{endDate,jdbcType=VARCHAR}]]>
+        order by
+            t.realTime asc
+    </select>
+
+    <select id="selectPriceList" resultType="com.xc.vo2.StockPriceVo">
+        select
+            substring_index( group_concat( id order by `realtime` desc ), ',', 1 ) as `id`,
+            substring_index( group_concat( now order by `realtime` desc ), ',', 1 ) as `nowPrice`,
+            substring_index( group_concat( realTime order by `realtime` desc ), ',', 1 ) as `realTime`
+        from
+            ${dbTableName}
+        where
+            <![CDATA[ realTime >= #{startTime} and realTime <= #{endTime} ]]>
+        group by
+            dateOne
+    </select>
+
+    <select id="selectByDateGroup" resultType="com.xc.vo2.StockVolumeVo">
+        SELECT
+            `date` , volume
+        FROM
+            ${dbTableName}
+        WHERE
+            <if test='"1" == resolution'>
+                dateOne
+            </if>
+            <if test='"5" == resolution'>
+                dateFive
+            </if>
+            <if test='"15" == resolution'>
+                dateFifteen
+            </if>
+            <if test='"30" == resolution'>
+                dateThirty
+            </if>
+            <if test='"60" == resolution'>
+                dateSixty
+            </if>
+        = (
+            SELECT
+                <if test='"1" == resolution'>
+                    dateOne
+                </if>
+                <if test='"5" == resolution'>
+                    dateFive
+                </if>
+                <if test='"15" == resolution'>
+                    dateFifteen
+                </if>
+                <if test='"30" == resolution'>
+                    dateThirty
+                </if>
+                <if test='"60" == resolution'>
+                    dateSixty
+                </if>
+            FROM
+                ${dbTableName}
+            WHERE
+                ${nearTime} >
+                <if test='"1" == resolution'>
+                    dateOne
+                </if>
+                <if test='"5" == resolution'>
+                    dateFive
+                </if>
+                <if test='"15" == resolution'>
+                    dateFifteen
+                </if>
+                <if test='"30" == resolution'>
+                    dateThirty
+                </if>
+                <if test='"60" == resolution'>
+                    dateSixty
+                </if>
+            GROUP BY
+                <if test='"1" == resolution'>
+                    dateOne
+                </if>
+                <if test='"5" == resolution'>
+                    dateFive
+                </if>
+                <if test='"15" == resolution'>
+                    dateFifteen
+                </if>
+                <if test='"30" == resolution'>
+                    dateThirty
+                </if>
+                <if test='"60" == resolution'>
+                    dateSixty
+                </if>
+            ORDER BY
+                <if test='"1" == resolution'>
+                    dateOne
+                </if>
+                <if test='"5" == resolution'>
+                    dateFive
+                </if>
+                <if test='"15" == resolution'>
+                    dateFifteen
+                </if>
+                <if test='"30" == resolution'>
+                    dateThirty
+                </if>
+                <if test='"60" == resolution'>
+                    dateSixty
+                </if> desc
+            LIMIT 1
+            )
+        ORDER BY
+            realTime DESC
+            LIMIT 1
+    </select>
+
+    <select id="selectDateOneCount" resultType="Integer">
+        select count(1) from (select count(1) s from ${dbTableName} group by dateone having s>1) t
+    </select>
+
+    <select id="selectDateOne" resultType="com.xc.vo2.HistoryVo">
+        select
+            t.id id,
+            t.high high,
+            t.low low,
+            t.`open` `open`,
+            t.`close` `close`,
+            t.realTime realTime,
+            t.volume volume,
+            t.groupTime `time`
+        from
+        (
+            select
+            min( id ) id,
+            max( high ) high,
+            min( low ) low,
+            substring_index( group_concat( `open` order by `realtime` ), ',', 1 ) as `open`,
+            substring_index( group_concat( `now` order by `realtime` desc ), ',', 1 ) as `close`,
+            substring_index( group_concat( volume order by `realtime` desc ), ',', 1 ) as `volume`,
+            dateOne groupTime,
+            dateOne realTime
+        from
+            ${dbTableName}
+        group by
+            dateOne
+        ) t
+        where
+            1 = 1
+            <![CDATA[ and t.groupTime >= #{startDate,jdbcType=VARCHAR}]]>
+            <![CDATA[ and t.groupTime <= #{endDate,jdbcType=VARCHAR}]]>
+        order by
+            t.realTime asc
+    </select>
+</mapper>

+ 86 - 0
src/main/java/mappers2/StockRestDataMapper.xml

@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.xc.dao2.StockRestDataMapper" >
+
+    <select id="selectRestDataByGid" resultType="com.xc.vo2.StockDbVO">
+        select
+            `now` nowPrice,
+            `pctchange` `hcrate`,
+            `change` `change`,
+            `open` `open_px`,
+            `preclose` `preclose_px`,
+            `high` today_max,
+            `low` today_min,
+            `volume` business_amount,
+            `amount` business_balance,
+            `buyprice1` buy1,
+            `buyprice2` buy2,
+            `buyprice3` buy3,
+            `buyprice4` buy4,
+            `buyprice5` buy5,
+            `buyvolume1` buy1_num,
+            `buyvolume2` buy2_num,
+            `buyvolume3` buy3_num,
+            `buyvolume4` buy4_num,
+            `buyvolume5` buy5_num,
+            `sellprice1` sell1,
+            `sellprice2` sell2,
+            `sellprice3` sell3,
+            `sellprice4` sell4,
+            `sellprice5` sell5,
+            `sellvolume1` sell1_num,
+            `sellvolume2` sell2_num,
+            `sellvolume3` sell3_num,
+            `sellvolume4` sell4_num,
+            `sellvolume5` sell5_num
+        from
+            ${dbTableName}
+--         where
+--             <![CDATA[ ((`time` >= 130001 and `time` <= 150000) or (`time` >= 93001 and `time` <= 113000)) ]]>
+        order by
+            realTime desc
+        limit 1
+    </select>
+
+    <select id="selectRestDataByGidDateOne" resultType="com.xc.vo2.StockDbVO">
+        select
+            substring_index( group_concat( `now` order by `realtime` desc ), ',', 1 ) nowPrice,
+            substring_index( group_concat( `pctchange` order by `realtime` desc ), ',', 1 ) `hcrate`,
+            substring_index( group_concat( `change` order by `realtime` desc ), ',', 1 )  `change`,
+            substring_index( group_concat( `now` order by `realtime` asc ), ',', 1 ) as `open_px`,
+            substring_index( group_concat( `preclose` order by `realtime` desc ), ',', 1 )  `preclose_px`,
+            max(`now`) today_max,
+            min(`now`) today_min,
+            sum(`volume`) business_amount,
+            sum(`amount`) business_balance,
+            substring_index( group_concat( `buyprice1` order by `realtime` desc ), ',', 1 ) buy1,
+            substring_index( group_concat( `buyprice2` order by `realtime` desc ), ',', 1 ) buy2,
+            substring_index( group_concat( `buyprice3` order by `realtime` desc ), ',', 1 ) buy3,
+            substring_index( group_concat( `buyprice4` order by `realtime` desc ), ',', 1 )  buy4,
+            substring_index( group_concat( `buyprice5` order by `realtime` desc ), ',', 1 )  buy5,
+            substring_index( group_concat( `buyvolume1` order by `realtime` desc ), ',', 1 ) buy1_num,
+            substring_index( group_concat( `buyvolume2` order by `realtime` desc ), ',', 1 ) buy2_num,
+            substring_index( group_concat( `buyvolume3` order by `realtime` desc ), ',', 1 ) buy3_num,
+            substring_index( group_concat( `buyvolume4` order by `realtime` desc ), ',', 1 ) buy4_num,
+            substring_index( group_concat( `buyvolume5` order by `realtime` desc ), ',', 1 ) buy5_num,
+            substring_index( group_concat( `sellprice1` order by `realtime` desc ), ',', 1 ) sell1,
+            substring_index( group_concat( `sellprice2` order by `realtime` desc ), ',', 1 ) sell2,
+            substring_index( group_concat( `sellprice3` order by `realtime` desc ), ',', 1 ) sell3,
+            substring_index( group_concat( `sellprice4` order by `realtime` desc ), ',', 1 ) sell4,
+            substring_index( group_concat( `sellprice5` order by `realtime` desc ), ',', 1 ) sell5,
+            substring_index( group_concat( `sellvolume1` order by `realtime` desc ), ',', 1 ) sell1_num,
+            substring_index( group_concat( `sellvolume2` order by `realtime` desc ), ',', 1 ) sell2_num,
+            substring_index( group_concat( `sellvolume3` order by `realtime` desc ), ',', 1 ) sell3_num,
+            substring_index( group_concat( `sellvolume4` order by `realtime` desc ), ',', 1 ) sell4_num,
+            substring_index( group_concat( `sellvolume5` order by `realtime` desc ), ',', 1 ) sell5_num
+        from
+            ${dbTableName}
+--         where
+--             <![CDATA[ ((`time` >= 130001 and `time` <= 150000) or (`time` >= 93001 and `time` <= 113000)) ]]>
+        group by
+            date
+        order by
+            date desc
+        limit 1
+    </select>
+</mapper>

+ 83 - 12
src/main/resources/applicationContext-datasource.xml

@@ -9,6 +9,9 @@
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
 
+
+<!--    <context:property-placeholder location="classpath:datasource.properties" />-->
+
     <bean id="propertyConfigurer"
           class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
         <property name="order" value="2"/>
@@ -22,8 +25,8 @@
     </bean>
 
     <!--dbcp datasource-->
-    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
-        <property name="driverClassName" value="${db.driverClassName}"/>
+    <bean id="dataSource1" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
+    <property name="driverClassName" value="${db.driverClassName}"/>
         <property name="url" value="${db.url}"/>
         <property name="username" value="${db.username}"/>
         <property name="password" value="${db.password}"/>
@@ -56,10 +59,9 @@
 
     <!--mybatis pagehelper-->
     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
-        <property name="dataSource" ref="dataSource"/>
+        <property name="dataSource" ref="dataSource1"/>
         <property name="typeAliasesPackage" value="com.xc.vo" />
         <property name="mapperLocations" value="classpath*:mappers/*Mapper.xml"></property>
-
         <!-- 分页插件 , 必须要数据库中查询出来的数据才能进行拦截,构造的数据分页不生效 -->
         <!--https://github.com/pagehelper/Mybatis-PageHelper-->
         <property name="plugins">
@@ -75,20 +77,89 @@
         </property>
     </bean>
 
+    <!-- 事务管理 -->
+    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
+        <property name="dataSource" ref="dataSource1"/>
+        <!--失败是否回滚,true-->
+        <property name="rollbackOnCommitFailure" value="true"/>
+    </bean>
+
+    <!-- 使用@Transactional进行声明式事务管理需要声明下面这行 -->
+    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
+
     <!--mybatis bean config-->
     <bean name="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
         <property name="basePackage" value="com.xc.dao"/>
+        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
     </bean>
 
+    <!-- Enables the use of the @AspectJ style of Spring AOP -->
+    <aop:aspectj-autoproxy/>
 
-    <!-- 使用@Transactional进行声明式事务管理需要声明下面这行 -->
-    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
-    <!-- 事务管理 -->
-    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
-        <property name="dataSource" ref="dataSource"/>
-        <!--失败是否回滚,true-->
-        <property name="rollbackOnCommitFailure" value="true"/>
+
+    <bean id="dataSource2" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
+        <property name="driverClassName" value="${db.driverClassName}"/>
+        <property name="url" value="${db2.url}"/>
+        <property name="username" value="${db2.username}"/>
+        <property name="password" value="${db2.password}"/>
+        <!-- 连接池启动时的初始值 -->
+        <property name="initialSize" value="${db.initialSize}"/>
+        <!-- 连接池的最大值 -->
+        <property name="maxActive" value="${db.maxActive}"/>
+        <!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 -->
+        <property name="maxIdle" value="${db.maxIdle}"/>
+        <!-- 最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->
+        <property name="minIdle" value="${db.minIdle}"/>
+        <!-- 最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示无限制 -->
+        <property name="maxWait" value="${db.maxWait}"/>
+        <!--#给出一条简单的sql语句进行验证 -->
+        <!--<property name="validationQuery" value="select getdate()" />-->
+        <property name="defaultAutoCommit" value="${db.defaultAutoCommit}"/>
+        <!-- 回收被遗弃的(一般是忘了释放的)数据库连接到连接池中 -->
+        <property name="removeAbandoned" value="${db.removeAbandoned}" />
+        <!-- 数据库连接过多长时间不用将被视为被遗弃而收回连接池中 -->
+        <property name="removeAbandonedTimeout" value="${db.removeAbandonedTimeout}" />
+        <!-- #连接的超时时间,默认为半小时。 -->
+        <property name="minEvictableIdleTimeMillis" value="${db.minEvictableIdleTimeMillis}"/>
+        <!--# 失效检查线程运行时间间隔,要小于MySQL默认-->
+        <property name="timeBetweenEvictionRunsMillis" value="40000"/>
+        <!--# 检查连接是否有效-->
+        <property name="testWhileIdle" value="true"/>
+        <!--# 检查连接有效性的SQL语句-->
+        <property name="validationQuery" value="SELECT 1 FROM dual"/>
     </bean>
 
+    <bean id="sqlSessionFactory_slave" class="org.mybatis.spring.SqlSessionFactoryBean">
+        <property name="dataSource" ref="dataSource2" />
+        <property name="typeAliasesPackage" value="com.xc.vo2"/>
+        <property name="mapperLocations" value="classpath*:mappers2/*Mapper.xml"></property>
+        <!-- 分页插件 , 必须要数据库中查询出来的数据才能进行拦截,构造的数据分页不生效 -->
+        <!--https://github.com/pagehelper/Mybatis-PageHelper-->
+        <property name="plugins">
+            <array>
+                <bean class="com.github.pagehelper.PageHelper">
+                    <property name="properties">
+                        <value>
+                            dialect=mysql
+                        </value>
+                    </property>
+                </bean>
+            </array>
+        </property>
+    </bean>
+
+    <!-- Transaction manager for a single JDBC DataSource -->
+    <bean id="transactionManager_2" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
+        <property name="dataSource" ref="dataSource2" />
+    </bean>
+
+    <!-- 使用annotation定义事务 -->
+    <tx:annotation-driven transaction-manager="transactionManager_2" />
+
+    <!--mybatis bean config-->
+    <bean name="mapperScannerConfigurer2" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
+        <property name="basePackage" value="com.xc.dao2" />
+        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory_slave"/>
+    </bean>
 
-</beans>
+</beans>

+ 5 - 0
src/main/resources/datasource.properties

@@ -10,6 +10,11 @@ db.url=jdbc:mysql://101.32.39.134:3306/stock2coin?characterEncoding=utf-8
 db.username=root
 db.password=S5Y2M8MtsRx5RcJG
 
+# 云正式服务器 外网访问
+db2.url=jdbc:mysql://bj-cdb-1j873yci.sql.tencentcdb.com:61196/stock_data_coin?characterEncoding=utf-8
+db2.username=root
+db2.password=TestBicon@123
+
 # 正式服务器
 #db.url=jdbc:mysql://47.74.220.239:3306/stock2chen?characterEncoding=utf-8
 #db.username=stock2chen

+ 1 - 1
src/main/resources/logback.xml

@@ -81,7 +81,7 @@
     </logger>
 
     <!--这里设置成DEBUG显示日志-->
-    <root level="INFO">
+    <root level="DEBUG">
         <appender-ref ref="console"/>
         <appender-ref ref="error"/>
     </root>

+ 4 - 4
src/main/resources/stock2guo.properties

@@ -5,10 +5,10 @@
 #2.	执行ifconfig查看运行vsftpd服务的地址
 #3.	用浏览器 ftp://地址
 
-ftp.server.ip=39.101.149.52
-ftp.user=gssyLink
-ftp.pass=Ki7jBwA6HFf2NCYy
-ftp.server.http.prefix=http://img.jiatuixinxi.com/
+ftp.server.ip=101.32.39.134
+ftp.user=dage
+ftp.pass=3GMRJkbHLS8J3Zr8
+ftp.server.http.prefix=http://qwer16888.vip/public/
 #ftp.server.ip=47.56.200.145
 #ftp.user=ofsuccess
 #ftp.pass=fdymdM34HHsS8iB6