Quellcode durchsuchen

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

qlm vor 4 Jahren
Ursprung
Commit
e7fc610f50

+ 20 - 20
src/main/java/com/xc/common/interceptor/ApiAdminAuthorityInterceptor.java

@@ -23,26 +23,26 @@ public class ApiAdminAuthorityInterceptor implements HandlerInterceptor {
     private static final Logger log = LoggerFactory.getLogger(ApiAdminAuthorityInterceptor.class);
 
     public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object handler) throws Exception {
-//        SiteAdmin siteAdmin = null;
-//        String loginToken = CookieUtils.readLoginToken(httpServletRequest,
-//                PropertiesUtil.getProperty("admin.cookie.name"));
-//        if (StringUtils.isNotEmpty(loginToken)) {
-//            String adminJsonStr = RedisShardedPoolUtils.get(loginToken);
-//            siteAdmin = (SiteAdmin) JsonUtil.string2Obj(adminJsonStr, SiteAdmin.class);
-//        }
-//        if (null == siteAdmin) {
-//            httpServletResponse.reset();
-//            httpServletResponse.setCharacterEncoding("UTF-8");
-//            httpServletResponse.setContentType("application/json;charset=UTF-8");
-//            PrintWriter writer = httpServletResponse.getWriter();
-//            Map map = Maps.newHashMap();
-//            map.put("success", Boolean.valueOf(false));
-//            map.put("msg", "请先登录,无权限访问admin");
-//            writer.print(JsonUtil.obj2String(map));
-//            writer.flush();
-//            writer.close();
-//            return false;
-//        }
+        SiteAdmin siteAdmin = null;
+        String loginToken = CookieUtils.readLoginToken(httpServletRequest,
+                PropertiesUtil.getProperty("admin.cookie.name"));
+        if (StringUtils.isNotEmpty(loginToken)) {
+            String adminJsonStr = RedisShardedPoolUtils.get(loginToken);
+            siteAdmin = (SiteAdmin) JsonUtil.string2Obj(adminJsonStr, SiteAdmin.class);
+        }
+        if (null == siteAdmin) {
+            httpServletResponse.reset();
+            httpServletResponse.setCharacterEncoding("UTF-8");
+            httpServletResponse.setContentType("application/json;charset=UTF-8");
+            PrintWriter writer = httpServletResponse.getWriter();
+            Map map = Maps.newHashMap();
+            map.put("success", Boolean.valueOf(false));
+            map.put("msg", "请先登录,无权限访问admin");
+            writer.print(JsonUtil.obj2String(map));
+            writer.flush();
+            writer.close();
+            return false;
+        }
         return true;
     }
 

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

@@ -17,7 +17,7 @@ public class IndexInfo {
 
     private int depositAmt;
 
-    private int transFee;
+    private BigDecimal transFee;
 
     private BigDecimal entryOrdersAgio;
 
@@ -36,5 +36,5 @@ public class IndexInfo {
     private String transPmBegin; // 下午交易开始时间
     private String transPmEnd; // 下午交易结束时间
     private Integer siteLever;
-    private Integer spread;
+    private BigDecimal spread;
 }

+ 1 - 1
src/main/java/com/xc/pojo/Stock.java

@@ -18,7 +18,7 @@ public class Stock {
     private Date addTime;//添加时间
     //新增参数
     private Integer depositAmt;//一手保证金
-    private Integer transFee;//购买手续费
+    private BigDecimal transFee;//购买手续费
     private Integer buyMinNum;//最小交易手数
     private Integer buyMaxNum;//最大交易手数
     private String transAmBegin;//上午开始交易时间

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

@@ -47,6 +47,7 @@ public class AgentUserServiceImpl implements IAgentUserService {
         String agentJson = RedisShardedPoolUtils.get(loginToken);
         AgentUser agentUser = (AgentUser) JsonUtil.string2Obj(agentJson, AgentUser.class);
         return this.agentUserMapper.selectByPrimaryKey(agentUser.getId());
+//        return this.agentUserMapper.selectByPrimaryKey(1);
     }
 
 

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

@@ -7,6 +7,7 @@ import com.xc.service.DbStockService;
 import com.xc.vo.stock.StockListVO;
 import com.xc.vo.stock.StockVO;
 import com.xc.vo2.StockDbVO;
+import org.apache.commons.lang.ObjectUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -36,15 +37,18 @@ public class DbStockServiceImpl implements DbStockService {
         if(null == stockDbVO){
             return new StockDbVO();
         }
+        //todo
         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));
+        if(!stockDbVO.getBusiness_balance().contains("万")){
+            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());
@@ -75,8 +79,7 @@ public class DbStockServiceImpl implements DbStockService {
 
     @Override
     public StockListVO getStockListVO(String stockGid) {
-        StockDbVO stockDbVO;
-        stockDbVO = getStockDb(stockGid);
+        StockDbVO stockDbVO = getStockDb(stockGid);
         StockListVO stockListVO = new StockListVO();
         BeanUtils.copyProperties(stockDbVO, stockListVO);
         String nowPrice =  stockListVO.getNowPrice() == null ? "0" : stockListVO.getNowPrice();

+ 111 - 109
src/main/java/com/xc/service/impl/UserPositionServiceImpl.java

@@ -76,50 +76,54 @@ public class UserPositionServiceImpl implements IUserPositionService {
 
     /**
      * 判断当前货币当前价格可成交挂单
+     *
      * @return
      */
     @Override
     @Transactional
-    public boolean fulfill(){
-        List<IndexInfo> indexInfoList = stockMapper.selectStockList();
-        Map<String, BigDecimal> indexMap = new HashMap<>();
-        Map<String, Integer> spreadMap = new HashMap<>();
-        BigDecimal nowPrice;
-        for (IndexInfo indexInfo : indexInfoList) {
+    public boolean fulfill() {
+        List<UserPosition> userPositions = this.userPositionMapper.listByCodeAndState(null, 2, null);
+        log.info("挂单=" + userPositions.size());
+        if (userPositions.size() > 0) {
+            List<IndexInfo> indexInfoList = stockMapper.selectStockList();
+            Map<String, BigDecimal> indexMap = new HashMap<>();
+            Map<String, BigDecimal> spreadMap = new HashMap<>();
+            BigDecimal nowPrice;
+            for (IndexInfo indexInfo : indexInfoList) {
                 try {
                     //每支code获取现价
                     StockListVO stockListVO = dbStockService.getStockListVO(indexInfo.getCode());
+                    stockListVO.setId(Integer.parseInt(indexInfo.getId()));
                     nowPrice = new BigDecimal(stockListVO.getNowPrice());
                     indexMap.put(indexInfo.getCnName(), nowPrice);
-                    spreadMap.put(indexInfo.getCnName() , indexInfo.getSpread());
+                    spreadMap.put(indexInfo.getCnName(), indexInfo.getSpread());
                 } catch (Exception e) {
                     // 数据库不存在
                     log.info("数据库不存在");
                 }
-        }
-        List<UserPosition> userPositions = this.userPositionMapper.listByCodeAndState(null,2,null);
-        log.info("挂单="+userPositions.size());
-        for(UserPosition userPosition : userPositions){
-            nowPrice = indexMap.get(userPosition.getStockName());
-            BigDecimal spread = new BigDecimal(spreadMap.get(userPosition.getStockName()));
-            if("做多".equals(userPosition.getOrderDirection())){
-                // 现价小于等于委托价
-                if (nowPrice.compareTo(userPosition.getBuyOrderPrice()) < 1){
-                    nowPrice = userPosition.getBuyOrderPrice().add(spread);
-                    toFulfill(userPosition, nowPrice);
-                }
-            }else{
-                // 现价大于等于委托价
-                if (nowPrice.compareTo(userPosition.getBuyOrderPrice()) > -1){
-                    nowPrice = userPosition.getBuyOrderPrice().subtract(spread);
-                    toFulfill(userPosition, nowPrice);
+            }
+            for (UserPosition userPosition : userPositions) {
+                nowPrice = indexMap.get(userPosition.getStockName());
+                BigDecimal spread = spreadMap.get(userPosition.getStockName());
+                if ("做多".equals(userPosition.getOrderDirection())) {
+                    // 现价小于等于委托价
+                    if (nowPrice.compareTo(userPosition.getBuyOrderPrice()) < 1) {
+                        nowPrice = userPosition.getBuyOrderPrice().add(spread);
+                        toFulfill(userPosition, nowPrice);
+                    }
+                } else {
+                    // 现价大于等于委托价
+                    if (nowPrice.compareTo(userPosition.getBuyOrderPrice()) > -1) {
+                        nowPrice = userPosition.getBuyOrderPrice().subtract(spread);
+                        toFulfill(userPosition, nowPrice);
+                    }
                 }
             }
         }
         return true;
     }
 
-    private void toFulfill(UserPosition userPosition, BigDecimal buyOrderPrice){
+    private void toFulfill(UserPosition userPosition, BigDecimal buyOrderPrice) {
         User user = userMapper.findById(userPosition.getUserId());
         userPositionMapper.updatePositionStatus(userPosition.getId(), buyOrderPrice, buyOrderPrice.multiply(BigDecimal.valueOf(Double.valueOf(userPosition.getOrderNum()))));
         ThreadUtil.executeInThread(obj -> {
@@ -212,10 +216,10 @@ public class UserPositionServiceImpl implements IUserPositionService {
         Integer buyNum;
         if (null != orderNum && orderNum > buyNumAll) {
             return ServerResponse.createByErrorMsg("卖出数量大于购买数量");
-        }else if(null == orderNum || orderNum == buyNumAll){
+        } else if (null == orderNum || orderNum == buyNumAll) {
             buyNum = buyNumAll;
             isAll = true;
-        }else{
+        } else {
             buyNum = orderNum;
         }
         // 购买所使用金额
@@ -252,11 +256,11 @@ public class UserPositionServiceImpl implements IUserPositionService {
         userPosition.setOrderNum(buyNum);
         userPosition.setOrderTotalPrice(userPosition.getBuyOrderPrice().multiply(new BigDecimal(buyNum)));
         // 用原本的手续费计算出单笔的手续费 再得出总体的手续费
-        userPosition.setOrderFee(userPosition.getOrderFee().divide(new BigDecimal(buyNumAll),4,4).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),4,4).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) {
+        if (!isAll) {
             UserPosition userPositionInsert = new UserPosition();
             userPositionInsert.setPositionType(userPosition.getPositionType());
             userPositionInsert.setPositionSn(KeyUtils.getUniqueKey());
@@ -279,13 +283,13 @@ public class UserPositionServiceImpl implements IUserPositionService {
             userPositionInsert.setBuyOrderPrice(userPosition.getBuyOrderPrice());
             userPositionInsert.setOrderTotalPrice(userPosition.getBuyOrderPrice().multiply(new BigDecimal(num)));
             // 用原本的手续费计算出单笔的手续费 再得出总体的手续费
-            userPositionInsert.setOrderFee(userPosition.getOrderFee().divide(new BigDecimal(buyNum),4,4).multiply(new BigDecimal(num)));
+            userPositionInsert.setOrderFee(userPosition.getOrderFee().divide(new BigDecimal(buyNum), 4, 4).multiply(new BigDecimal(num)));
             userPositionInsert.setProfitAndLose(BigDecimal.ZERO);
             userPositionInsert.setOrderStayDays(0);
             userPositionInsert.setOrderStayFee(BigDecimal.ZERO);
             userPositionInsert.setOrderSpread(BigDecimal.ZERO);
             //冻结保证金
-            userPositionInsert.setDepositFreezeAmt(userPosition.getDepositFreezeAmt().divide(new BigDecimal(buyNum),4,4).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);
@@ -339,7 +343,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
 
     @Override
     public ServerResponse closeOutList(List<Integer> list) throws Exception {
-        for (Integer userId:list){
+        for (Integer userId : list) {
             iUserPositionService.closeOut(userId, null);
         }
         return ServerResponse.createBySuccessMsg("平仓成功!");
@@ -348,7 +352,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
     @Override
     public ServerResponse oneKeyCloseOut(HttpServletRequest request) {
         User user = this.iUserService.getCurrentRefreshUser(request);
-        if(iUserService.ForceSellByUserId(user.getId())){
+        if (iUserService.ForceSellByUserId(user.getId())) {
             return ServerResponse.createBySuccessMsg("一键平仓成功!");
         }
         return ServerResponse.createByErrorMsg("平仓失败!!!");
@@ -375,7 +379,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
         // 获取有设置止盈的账号
         UserPosition userPosition = userPositionMapper.selectByPrimaryKey(id);
         nowPrice = indexMap.get(userPosition.getStockName());
-        if(judgeIsCloseOut(userPosition, nowPrice)){
+        if (judgeIsCloseOut(userPosition, nowPrice)) {
             closeOut(userPosition.getId(), null);
         }
     }
@@ -401,31 +405,29 @@ public class UserPositionServiceImpl implements IUserPositionService {
         }
         // 获取有设置止盈的账号
         List<UserPosition> userPositionList = userPositionMapper.selectPositionByStopProfitTarget();
-        for(UserPosition userPosition : userPositionList){
+        for (UserPosition userPosition : userPositionList) {
             nowPrice = indexMap.get(userPosition.getStockName());
-            if(judgeIsCloseOut(userPosition, nowPrice)){
+            if (judgeIsCloseOut(userPosition, nowPrice)) {
                 closeOut(userPosition.getId(), null);
             }
         }
     }
 
-    private boolean judgeIsCloseOut(UserPosition userPosition, BigDecimal nowPrice){
+    private boolean judgeIsCloseOut(UserPosition userPosition, BigDecimal nowPrice) {
         //判断做多 做空
-        if("做多".equals(userPosition.getOrderDirection())){
-            if(!(userPosition.getTargetprofit().compareTo(BigDecimal.ZERO) == 0) && nowPrice.compareTo(userPosition.getTargetprofit()) > -1){
+        if ("做多".equals(userPosition.getOrderDirection())) {
+            if (!(userPosition.getTargetprofit().compareTo(BigDecimal.ZERO) == 0) && nowPrice.compareTo(userPosition.getTargetprofit()) > -1) {
                 //  当前价格 大于等于 止盈价格 进行平仓操作
                 return true;
-            }
-            else if(!(userPosition.getStoploss().compareTo(BigDecimal.ZERO) == 0) && nowPrice.compareTo(userPosition.getStoploss()) < 1){
+            } else if (!(userPosition.getStoploss().compareTo(BigDecimal.ZERO) == 0) && nowPrice.compareTo(userPosition.getStoploss()) < 1) {
                 // 当前价格 小于等于 止损价格 进行平仓操作
                 return true;
             }
-        }else{
-            if(!(userPosition.getStoploss().compareTo(BigDecimal.ZERO) == 0) && nowPrice.compareTo(userPosition.getStoploss()) > -1){
+        } else {
+            if (!(userPosition.getStoploss().compareTo(BigDecimal.ZERO) == 0) && nowPrice.compareTo(userPosition.getStoploss()) > -1) {
                 // 当前价格 大于等于 止损价格 进行平仓操作
                 return true;
-            }
-            else if(!(userPosition.getTargetprofit().compareTo(BigDecimal.ZERO) == 0) && nowPrice.compareTo(userPosition.getTargetprofit()) < 1){
+            } else if (!(userPosition.getTargetprofit().compareTo(BigDecimal.ZERO) == 0) && nowPrice.compareTo(userPosition.getTargetprofit()) < 1) {
                 // 当前价格  小于等于 止盈价格 进行平仓操作
                 return true;
             }
@@ -440,17 +442,17 @@ public class UserPositionServiceImpl implements IUserPositionService {
         // 获取各货币过夜费
         List<IndexInfo> indexInfoList = stockMapper.selectStockList();
         Map<String, Integer> indexMap = new HashMap<>();
-        for (IndexInfo indexInfo : indexInfoList){
+        for (IndexInfo indexInfo : indexInfoList) {
             indexMap.put(indexInfo.getCnName(), indexInfo.getDemurrage());
         }
-        for(Integer userId : userIdList){
+        for (Integer userId : userIdList) {
             // 获取用户余额
             User user = userMapper.selectByPrimaryKey(userId);
             BigDecimal enableAmt = user.getEnableAmt();
             BigDecimal allAmt = user.getUserAmt();
             // 当前用户需要的总过夜费
             int demurrageSum = userPositionMapper.selectUserDemurrageSum(userId);
-            if(-1 == enableAmt.compareTo(new BigDecimal(demurrageSum))){
+            if (-1 == enableAmt.compareTo(new BigDecimal(demurrageSum))) {
                 // 用户余额小于需要扣除的过夜费
                 // 平仓操作
                 iUserService.ForceSellByUserId(userId);
@@ -460,7 +462,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
             List<UserPosition> userPositionList = userPositionMapper.selectPositionByUserId(userId);
             // 计算过夜费修改数据
             BigDecimal orderStayFee;
-            for(UserPosition userPosition : userPositionList){
+            for (UserPosition userPosition : userPositionList) {
                 orderStayFee = new BigDecimal(indexMap.get(userPosition.getStockName())).multiply(BigDecimal.valueOf(userPosition.getOrderNum()));
                 userPosition.setOrderStayFee(userPosition.getOrderStayFee().add(orderStayFee));
                 // 修改持仓表过夜费
@@ -486,21 +488,21 @@ public class UserPositionServiceImpl implements IUserPositionService {
     public ServerResponse revoke(Integer positionId, HttpServletRequest request) throws Exception {
         try {
             User user = this.iUserService.getCurrentRefreshUser(request);
-            if (null == user || null == user.getId()){
+            if (null == user || null == user.getId()) {
                 return ServerResponse.createByErrorMsg("用户未登录!");
             }
-            if (null == positionId || positionId < 0){
+            if (null == positionId || positionId < 0) {
                 return ServerResponse.createByErrorMsg("挂单号错误!");
             }
             UserPosition userPosition = this.userPositionMapper.selectByPrimaryKeyAndStatus(positionId);
-            if (null == userPosition || userPosition.getDepositFreezeAmt()==null){
+            if (null == userPosition || userPosition.getDepositFreezeAmt() == null) {
                 return ServerResponse.createByErrorMsg("挂单不存在!");
             }
             user.setEnableAmt(user.getEnableAmt().add(userPosition.getDepositFreezeAmt()).add(userPosition.getOrderFee()));
-            log.info("冻结保证金 = "+userPosition.getDepositFreezeAmt());
-            log.info("可用余额 = "+user.getEnableAmt());
-    //        user.setUserAmt(user.getUserAmt().add(userPosition.getDepositFreezeAmt()));
-    //        log.info("总资金 = "+user.getUserAmt());
+            log.info("冻结保证金 = " + userPosition.getDepositFreezeAmt());
+            log.info("可用余额 = " + user.getEnableAmt());
+            //        user.setUserAmt(user.getUserAmt().add(userPosition.getDepositFreezeAmt()));
+            //        log.info("总资金 = "+user.getUserAmt());
             user.setUserAmt(user.getUserAmt().add(userPosition.getOrderFee()));
             int updateUserCount = this.userMapper.updateByPrimaryKeySelective(user);
             if (updateUserCount > 0) {
@@ -510,10 +512,10 @@ public class UserPositionServiceImpl implements IUserPositionService {
                 throw new Exception("用户撤单】修改用户金额出错");
             }
             int res = this.userPositionMapper.deleteByPrimaryKey(positionId);
-            if (res>0){
+            if (res > 0) {
                 return ServerResponse.createBySuccess("撤单成功");
             }
-        }catch (Exception e){
+        } catch (Exception e) {
             e.printStackTrace();
             log.error(e.toString());
         }
@@ -551,9 +553,9 @@ public class UserPositionServiceImpl implements IUserPositionService {
             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);
+            Integer userPositionAmt = findUserPositionAmt(user.getId(), stock.getStockCode());
+            if ((userPositionAmt + buyNum) > stock.getPositionsMax()) {
+                return ServerResponse.createByErrorMsg("挂单失败,本次挂单手数:" + buyNum + ",持仓手数大于" + stock.getPositionsMax() + "手,目前持仓手数:" + userPositionAmt);
             }
             //每支code获取现价
             StockListVO stockListVO = dbStockService.getStockListVO(stock.getStockGid());
@@ -561,9 +563,9 @@ public class UserPositionServiceImpl implements IUserPositionService {
             if (now_price.compareTo(new BigDecimal("0")) == 0) {
                 return ServerResponse.createByErrorMsg("报价0,请稍后再试");
             }
-            log.info("挂单现价="+now_price);
-            log.info("挂单价="+buyOrderPrice);
-            log.info("价差="+stock.getEntryOrdersAgio());
+            log.info("挂单现价=" + now_price);
+            log.info("挂单价=" + buyOrderPrice);
+            log.info("价差=" + stock.getEntryOrdersAgio());
             BigDecimal addNowprice = new BigDecimal(0);
 //            BigDecimal subNowprice = new BigDecimal(0);
             addNowprice = now_price.add(stock.getEntryOrdersAgio());
@@ -572,17 +574,17 @@ public class UserPositionServiceImpl implements IUserPositionService {
 //            if(!(buyOrderPrice.compareTo(addNowprice)  > -1 || buyOrderPrice.compareTo(subNowprice) < 1)){
 //                return ServerResponse.createByErrorMsg("挂单价格不在价差范围内");
 //            }
-            if(buyType == 0){
+            if (buyType == 0) {
                 // 做多
                 // 委托价 大于 现价+价格差 才可以设置
-                if(buyOrderPrice.compareTo(addNowprice) == 1){
+                if (buyOrderPrice.compareTo(addNowprice) == 1) {
                     // 不可以设置
                     return ServerResponse.createByErrorMsg("挂单价格不在价差范围内");
                 }
-            }else{
+            } else {
                 // 做空
                 // 委托价 小于 现价+价格差 才可以设置
-                if(buyOrderPrice.compareTo(addNowprice) == -1){
+                if (buyOrderPrice.compareTo(addNowprice) == -1) {
                     return ServerResponse.createByErrorMsg("挂单价格不在价差范围内");
                 }
             }
@@ -592,17 +594,17 @@ public class UserPositionServiceImpl implements IUserPositionService {
             BigDecimal buy_amt_autual = buyOrderPrice.multiply(new BigDecimal(buyNum));
             log.info("用户可用金额 = {}  实际购买金额 =  {}", user_enable_amt, buy_amt_autual);
             // 手续费
-            BigDecimal position_freez = new BigDecimal(buyNum*stock.getTransFee());
+            BigDecimal position_freez = buyOrderPrice.multiply(new BigDecimal(buyNum)).multiply(stock.getTransFee()).multiply(new BigDecimal(stock.getContractSize()));
             //冻结保证金
-            BigDecimal depositFreezeAmt = buyOrderPrice.multiply(new BigDecimal(stock.getContractSize())).multiply(new BigDecimal(buyNum)).divide(new BigDecimal(stock.getSiteLever()),2,4);
-            log.info("冻结保证金 = "+depositFreezeAmt);
+            BigDecimal depositFreezeAmt = buyOrderPrice.multiply(new BigDecimal(stock.getContractSize())).multiply(new BigDecimal(buyNum)).divide(new BigDecimal(stock.getSiteLever()), 2, 4);
+            log.info("冻结保证金 = " + depositFreezeAmt);
             BigDecimal subtractDepositFreezeAmt = user_enable_amt.subtract(depositFreezeAmt).subtract(position_freez);
-            log.info("挂单冻结保证金="+depositFreezeAmt);
+            log.info("挂单冻结保证金=" + depositFreezeAmt);
 //            depositFreezeAmt = depositFreezeAmt.add(position_freez);
-            log.info("挂单冻结手续费="+position_freez);
-            log.info("挂单冻结金额="+depositFreezeAmt);
+            log.info("挂单冻结手续费=" + position_freez);
+            log.info("挂单冻结金额=" + depositFreezeAmt);
             // 保证金和手续费 大于 用户可用资金 挂单失败
-            if ((depositFreezeAmt.add(position_freez)).compareTo(user.getEnableAmt()) > -1){
+            if ((depositFreezeAmt.add(position_freez)).compareTo(user.getEnableAmt()) > -1) {
                 log.info("用户余额不足冻结保证金");
                 return ServerResponse.createByErrorMsg("挂单失败,用户余额不足冻结保证金:" + depositFreezeAmt);
             }
@@ -652,7 +654,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
                 log.error("用户交易挂单】保存持仓记录出错");
                 throw new Exception("用户交易挂单】保存持仓记录出错");
             }
-        }catch (Exception e){
+        } catch (Exception e) {
             log.error(e.toString());
             e.printStackTrace();
             return ServerResponse.createByErrorMsg("挂单失败,请重试!");
@@ -698,9 +700,9 @@ public class UserPositionServiceImpl implements IUserPositionService {
             return ServerResponse.createByErrorMsg("下单失败,购买数量大于" + stock.getBuyMaxNum() + "手");
         }
         // 判断用户持仓数
-        Integer userPositionAmt = findUserPositionAmt(user.getId(),stock.getStockCode());
-        if((userPositionAmt + buyNum) > (stock.getPositionsMax() == null ? 0 : stock.getPositionsMax())){
-            return ServerResponse.createByErrorMsg("下单失败,本次下单手数:"+buyNum+",持仓手数大于" + stock.getPositionsMax() + "手,目前持仓手数:"+ userPositionAmt);
+        Integer userPositionAmt = findUserPositionAmt(user.getId(), stock.getStockCode());
+        if ((userPositionAmt + buyNum) > (stock.getPositionsMax() == null ? 0 : stock.getPositionsMax())) {
+            return ServerResponse.createByErrorMsg("下单失败,本次下单手数:" + buyNum + ",持仓手数大于" + stock.getPositionsMax() + "手,目前持仓手数:" + userPositionAmt);
         }
         // 获取股票最新价格
         StockListVO stockListVO = dbStockService.getStockListVO(stock.getStockGid());
@@ -708,10 +710,10 @@ public class UserPositionServiceImpl implements IUserPositionService {
         if (nowPrice.compareTo(new BigDecimal("0")) == 0) {
             return ServerResponse.createByErrorMsg("报价0,请稍后再试");
         }
-        if(buyType == 0){
+        if (buyType == 0) {
             // 做多
             nowPrice = nowPrice.add(stock.getSpread());
-        }else{
+        } else {
             nowPrice = nowPrice.subtract(stock.getSpread());
         }
         log.info("用户 {} 下单,货币id = {} ,数量 = {} , 方向 = {}", user.getId(), stockId, buyNum, buyType);
@@ -720,17 +722,17 @@ public class UserPositionServiceImpl implements IUserPositionService {
         BigDecimal user_amt = user.getUserAmt();
         // 判断金额是否能够买得起   用 可用金额 > 冻结金额 + 手续费 则标示可以购买
         // 手续费
-        BigDecimal position_freez = new BigDecimal(buyNum * stock.getTransFee());
-        log.info("手续费 = "+position_freez);
+        BigDecimal position_freez = nowPrice.multiply(new BigDecimal(buyNum)).multiply(stock.getTransFee()).multiply(new BigDecimal(stock.getContractSize()));
+        log.info("手续费 = " + position_freez);
         //冻结保证金 = 现价* 合约单位 * 手数 / 杠杆
-        BigDecimal depositFreezeAmt = nowPrice.multiply(new BigDecimal(stock.getContractSize())).multiply(new BigDecimal(buyNum)).divide(new BigDecimal(stock.getSiteLever()),2,4);
-        log.info("冻结保证金 = "+depositFreezeAmt);
+        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){
+        if (user_enable_amt.compareTo(buy_amt) == -1) {
             return ServerResponse.createByErrorMsg("下单失败,余额可用金额小于" + buy_amt + "元");
         }
         user.setEnableAmt(user_enable_amt.subtract(position_freez).subtract(depositFreezeAmt));
-        log.info("可用余额 = "+ user_enable_amt.subtract(position_freez).subtract(depositFreezeAmt));
+        log.info("可用余额 = " + user_enable_amt.subtract(position_freez).subtract(depositFreezeAmt));
         user.setUserAmt(user_amt.subtract(position_freez));
         int updateUserCount = this.userMapper.updateByPrimaryKeySelective(user);
         if (updateUserCount > 0) {
@@ -808,7 +810,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
         userPosition.setOrderStayDays(0);
         userPosition.setOrderStayFee(new BigDecimal("0"));
         userPosition.setOrderSpread(stock.getSpread().multiply(new BigDecimal(buyNum)));
-        log.info("点差"+(stock.getSpread().multiply(new BigDecimal(buyNum))));
+        log.info("点差" + (stock.getSpread().multiply(new BigDecimal(buyNum))));
         //冻结保证金
         userPosition.setDepositFreezeAmt(depositFreezeAmt);
         //是否挂单
@@ -1036,7 +1038,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
             UserPositionVO userPositionVO = assembleUserPositionVO(position);
             IndexInfo indexInfo = indexMap.get(position.getStockName());
             userPositionVO.setNow_price(indexInfo.getNowPrice().toString());
-            if(1 != state) {
+            if (1 != state) {
                 BigDecimal yk = new BigDecimal(0);
                 //盈亏公式 做多 (现价—开仓价)*合约单位*手数   做空 (开仓价-现价)*合约单位*手数
                 if ("做多".equals(position.getOrderDirection())) {
@@ -1072,16 +1074,16 @@ public class UserPositionServiceImpl implements IUserPositionService {
             IndexInfo indexInfo = indexMap.get(position.getStockName());
             BigDecimal yk = new BigDecimal(0);
             //盈亏公式 做多 (现价—开仓价)*合约单位*手数 - 点差   做空 (开仓价-现价)*合约单位*手数 - 点差
-            if("做多".equals(position.getOrderDirection())){
+            if ("做多".equals(position.getOrderDirection())) {
                 yk = indexInfo.getNowPrice().subtract(position.getBuyOrderPrice()).multiply(BigDecimal.valueOf(position.getOrderNum() * indexInfo.getContractSize()));
-            }else {
+            } else {
                 yk = position.getBuyOrderPrice().subtract(indexInfo.getNowPrice()).multiply(BigDecimal.valueOf(position.getOrderNum() * indexInfo.getContractSize()));
             }
 //            yk = yk.subtract(position.getOrderSpread());
             ykSum = ykSum.add(yk);
         }
         BigDecimal hazardRate = new BigDecimal(0);
-        if(0 != userPositionAll.size()) {
+        if (0 != userPositionAll.size()) {
             hazardRate = hazardRate.add(enableAmt).add(depositFreezeAmt).add(ykSum).subtract(sxfSum);
             hazardRate = hazardRate.divide(depositFreezeAmt, 2, BigDecimal.ROUND_HALF_UP);
         }
@@ -1089,7 +1091,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
         for (UserPosition position : userPositionAll) {
             depositFreezeAmt = depositFreezeAmt.add(position.getDepositFreezeAmt());
         }
-        if(hazardRate.compareTo(BigDecimal.ZERO) == -1){
+        if (hazardRate.compareTo(BigDecimal.ZERO) == -1) {
             hazardRate = BigDecimal.ZERO;
         }
         PageInfo pageInfo = new PageInfo(userPositions);
@@ -1129,9 +1131,9 @@ public class UserPositionServiceImpl implements IUserPositionService {
             IndexInfo indexInfo = indexMap.get(position.getStockName());
             BigDecimal yk = new BigDecimal(0);
             //盈亏公式 做多 (现价—开仓价)*合约单位*手数 - 点差   做空 (开仓价-现价)*合约单位*手数 - 点差
-            if("做多".equals(position.getOrderDirection())){
+            if ("做多".equals(position.getOrderDirection())) {
                 yk = indexInfo.getNowPrice().subtract(position.getBuyOrderPrice()).multiply(BigDecimal.valueOf(position.getOrderNum() * indexInfo.getContractSize()));
-            }else {
+            } else {
                 yk = position.getBuyOrderPrice().subtract(indexInfo.getNowPrice()).multiply(BigDecimal.valueOf(position.getOrderNum() * indexInfo.getContractSize()));
             }
 //            yk = yk.subtract(position.getOrderSpread());
@@ -1227,7 +1229,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
         BigDecimal order_profit_and_lose_all = new BigDecimal("0");
         for (UserPosition position : userPositions) {
             // 挂单的不计算
-            if(1 != position.getEntryOrders()) {
+            if (1 != position.getEntryOrders()) {
                 order_fee_amt = order_fee_amt.add(position.getOrderFee()).add(position.getOrderSpread()).add(position.getOrderStayFee());
                 // 平仓的数据 直接用数据库中的数据
                 if (StringUtils.isNotEmpty(position.getSellOrderId())) {
@@ -1514,13 +1516,13 @@ public class UserPositionServiceImpl implements IUserPositionService {
         adminPositionVO.setLockMsg(position.getLockMsg());
         adminPositionVO.setStockPlate(position.getStockPlate());
         // 计算浮动盈亏  如果是平仓的就不需要计算了  直接去数据库中的
-        if(1 != state){
+        if (1 != state) {
             PositionProfitVO positionProfitVO = getPositionProfitVO(position, indexMap);
             adminPositionVO.setProfitAndLose(positionProfitVO.getProfitAndLose());
             adminPositionVO.setAllProfitAndLose(positionProfitVO.getAllProfitAndLose());
             adminPositionVO.setNow_price(positionProfitVO.getNowPrice());
             adminPositionVO.setHazardRate(positionProfitVO.getHazardRate());
-        }else {
+        } else {
             adminPositionVO.setProfitAndLose(position.getProfitAndLose());
             adminPositionVO.setAllProfitAndLose(position.getAllProfitAndLose());
         }
@@ -1560,13 +1562,13 @@ public class UserPositionServiceImpl implements IUserPositionService {
         agentPositionVO.setStockPlate(position.getStockPlate());
 //        PositionProfitVO positionProfitVO = getPositionProfitVO(position, indexMap);
         // 计算浮动盈亏  如果是平仓的就不需要计算了  直接去数据库中的
-        if(1 != state){
+        if (1 != state) {
             PositionProfitVO positionProfitVO = getPositionProfitVO(position, indexMap);
             agentPositionVO.setProfitAndLose(positionProfitVO.getProfitAndLose());
             agentPositionVO.setAllProfitAndLose(positionProfitVO.getAllProfitAndLose());
             agentPositionVO.setNow_price(positionProfitVO.getNowPrice());
             agentPositionVO.setHazardRate(positionProfitVO.getHazardRate());
-        }else {
+        } else {
             agentPositionVO.setProfitAndLose(position.getProfitAndLose());
             agentPositionVO.setAllProfitAndLose(position.getAllProfitAndLose());
         }
@@ -1647,19 +1649,19 @@ public class UserPositionServiceImpl implements IUserPositionService {
             indexInfo = indexMap.get(positionTemp.getStockName());
             yk = new BigDecimal(0);
             //盈亏公式 做多 (现价—开仓价)*合约单位*手数 - 点差   做空 (开仓价-现价)*合约单位*手数 - 点差
-            if("做多".equals(positionTemp.getOrderDirection())){
+            if ("做多".equals(positionTemp.getOrderDirection())) {
                 yk = indexInfo.getNowPrice().subtract(positionTemp.getBuyOrderPrice()).multiply(BigDecimal.valueOf(positionTemp.getOrderNum() * indexInfo.getContractSize()));
-            }else {
+            } else {
                 yk = positionTemp.getBuyOrderPrice().subtract(indexInfo.getNowPrice()).multiply(BigDecimal.valueOf(positionTemp.getOrderNum() * indexInfo.getContractSize()));
             }
 //            yk = yk.subtract(positionTemp.getOrderSpread());
             ykSum = ykSum.add(yk);
         }
         BigDecimal hazardRate = new BigDecimal(0);
-        if(0 != userPositionAll.size()) {
+        if (0 != userPositionAll.size()) {
             hazardRate = hazardRate.add(user.getEnableAmt()).add(depositFreezeAmt).add(ykSum).subtract(sxfSum);
             hazardRate = hazardRate.divide(depositFreezeAmt, 2, BigDecimal.ROUND_HALF_UP);
-            if(hazardRate.compareTo(BigDecimal.ZERO) == -1){
+            if (hazardRate.compareTo(BigDecimal.ZERO) == -1) {
                 hazardRate = BigDecimal.ZERO;
             }
             hazardRate = hazardRate.multiply(new BigDecimal(100));
@@ -1673,8 +1675,8 @@ public class UserPositionServiceImpl implements IUserPositionService {
     }
 
     //获取持仓数
-    public Integer findUserPositionAmt(Integer userId,String stockCode) {
-        List<UserPosition> userPositions = this.userPositionMapper.findPositionAmt(userId,stockCode);
+    public Integer findUserPositionAmt(Integer userId, String stockCode) {
+        List<UserPosition> userPositions = this.userPositionMapper.findPositionAmt(userId, stockCode);
         Integer allPositionAmt = 0;
         for (UserPosition position : userPositions) {
             allPositionAmt += position.getOrderNum();
@@ -1682,7 +1684,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
         return allPositionAmt;
     }
 
-    public void stopProfitTargetTask(int id){
+    public void stopProfitTargetTask(int id) {
         // 开始计算止盈操作
         try {
             toStopProfitTargetById(id);
@@ -1744,7 +1746,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
 //        }
 //    }
 
-    public Integer getTodayOrderNum(String stockName){
+    public Integer getTodayOrderNum(String stockName) {
         return userPositionMapper.selectTodayOrderNum(stockName);
     }
 }

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

@@ -1218,7 +1218,7 @@ public class UserServiceImpl implements IUserService {
         }
         PageHelper.startPage(pageNum, pageSize);
         List<AgentUser> agentUserList = new ArrayList<>();
-        agentUserList.add(currentAgent);
+//        agentUserList.add(currentAgent);
         Set<Integer> pidSet = new HashSet<>();
         pidSet.add(currentAgent.getId());
         List<AgentUser> agentUserListTemp = this.agentUserMapper.selectAgentUserList();
@@ -1228,14 +1228,6 @@ public class UserServiceImpl implements IUserService {
                 pidSet.add(a.getId());
             }
         }
-//        List<User> users = this.userMapper.listByAgent(realName, phone, searchId, accountType);
-//        List<AgentUserListVO> agentUserListVOS = Lists.newArrayList();
-//        for (User user : users) {
-//            AgentUserListVO agentUserListVO = assembleAgentUserListVO(user, siteSetting
-//                    .getForceStopPercent(), siteIndexSetting
-//                    .getForceSellPercent(), siteFuturesSetting.getForceSellPercent());
-//            agentUserListVOS.add(agentUserListVO);
-//        }
         PageInfo pageInfo = new PageInfo(agentUserList);
         pageInfo.setList(agentUserList);
         return ServerResponse.createBySuccess(pageInfo);

+ 1 - 1
src/main/java/com/xc/vo/stock/IndexInfoVo.java

@@ -15,7 +15,7 @@ public class IndexInfoVo {
 
     private int depositAmt;
 
-    private int transFee;
+    private BigDecimal transFee;
 
     private BigDecimal entryOrdersAgio;
 

+ 4 - 4
src/main/java/mappers/StockMapper.xml

@@ -128,7 +128,7 @@
        	  	      	#{isShow,jdbcType=INTEGER},
        	  	      	#{addTime,jdbcType=TIMESTAMP},
        	  	      	#{depositAmt,jdbcType=INTEGER},
-       	  	      	#{transFee,jdbcType=INTEGER},
+       	  	      	#{transFee,jdbcType=DECIMAL},
        	  	      	#{buyMinNum,jdbcType=INTEGER},
        	  	      	#{buyMaxNum,jdbcType=INTEGER},
        	  	      	#{transAmBegin,jdbcType=VARCHAR},
@@ -294,7 +294,7 @@
                 #{depositAmt,jdbcType=INTEGER},
             </if>
             <if test="transFee != null">
-                #{transFee,jdbcType=INTEGER},
+                #{transFee,jdbcType=DECIMAL},
             </if>
             <if test="buyMinNum != null">
                 #{buyMinNum,jdbcType=INTEGER},
@@ -399,7 +399,7 @@
                 depositAmt = #{depositAmt,jdbcType=INTEGER},
             </if>
             <if test="transFee != null">
-                transFee = #{transFee,jdbcType=INTEGER},
+                transFee = #{transFee,jdbcType=DECIMAL},
             </if>
             <if test="buyMinNum != null">
                 buyMinNum = #{buyMinNum,jdbcType=INTEGER},
@@ -495,7 +495,7 @@
                 and stock_type = #{stockType}
             </if>
         </where>
-        ORDER BY id DESC
+        ORDER BY id asc
     </select>
 
     <select id="findStockListByKeyWords2" resultMap="BaseResultMap" parameterType="map">