From 9b857ed9a9c6e07cc656622b0664109e61638041 Mon Sep 17 00:00:00 2001
From: jack <zengjieli93@163.com>
Date: Wed, 27 Mar 2024 19:34:10 +0800
Subject: [PATCH] 分支1

---
 src/main/java/com/nq/service/impl/UserServiceImpl.java |  920 +++++++++++----------------------------------------------
 1 files changed, 179 insertions(+), 741 deletions(-)

diff --git a/src/main/java/com/nq/service/impl/UserServiceImpl.java b/src/main/java/com/nq/service/impl/UserServiceImpl.java
index 1d420ca..9dfc106 100644
--- a/src/main/java/com/nq/service/impl/UserServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/UserServiceImpl.java
@@ -8,9 +8,11 @@
 import com.nq.config.StockPoll;
 import com.nq.dao.*;
 import com.nq.enums.EStockType;
+import com.nq.enums.EUserAssets;
 import com.nq.pojo.*;
+import com.nq.pojo.reponse.RUserAssets;
 import com.nq.service.*;
-import com.nq.utils.DateTimeUtil;
+import com.nq.utils.timeutil.DateTimeUtil;
 import com.nq.utils.PropertiesUtil;
 import com.nq.utils.SymmetricCryptoUtil;
 import com.nq.utils.ip.IpUtils;
@@ -29,6 +31,7 @@
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
@@ -46,7 +49,7 @@
 public class UserServiceImpl implements IUserService {
     private static final Logger log = LoggerFactory.getLogger(UserServiceImpl.class);
 
-    @Autowired
+    @Resource
     UserMapper userMapper;
 
     @Autowired
@@ -55,8 +58,15 @@
     @Autowired
     ISiteLoginLogService iSiteLoginLogService;
 
-    @Autowired
+    @Resource
     StockOptionMapper stockOptionMapper;
+
+
+    @Autowired
+    IUserService userService;
+
+    @Autowired
+    IUserAssetsServices userAssetsServices;
 
     @Autowired
     StockMapper stockMapper;
@@ -64,9 +74,9 @@
     IUserPositionService iUserPositionService;
     @Autowired
     IUserBankService iUserBankService;
-    @Autowired
+    @Resource
     AgentUserMapper agentUserMapper;
-    @Autowired
+    @Resource
     SiteTaskLogMapper siteTaskLogMapper;
     @Autowired
     IStockOptionService iStockOptionService;
@@ -84,6 +94,10 @@
     ISiteIndexSettingService iSiteIndexSettingService;
     @Autowired
     StockPoll stockPoll;
+
+
+    @Resource
+    UserPositionMapper userPositionMapper;
     @Resource
     SiteAmtTransLogMapper siteAmtTransLogMapper;
     @Autowired
@@ -92,12 +106,11 @@
     ISiteFuturesSettingService iSiteFuturesSettingService;
     @Autowired
     IStockFuturesService iStockFuturesService;
-    @Resource
-    StockFuturesMapper stockFuturesMapper;
-    @Resource
-    StockIndexMapper stockIndexMapper;
+
     @Autowired
     ISiteMessageService iSiteMessageService;
+
+
 
     public ServerResponse reg(String yzmCode, String agentCode, String phone, String userPwd, HttpServletRequest request) {
         if (StringUtils.isBlank(agentCode) || StringUtils.isBlank(phone) ||
@@ -149,19 +162,6 @@
 
         user.setIsLogin(Integer.valueOf(0));
 
-        user.setUserAmt(new BigDecimal("0"));
-        user.setEnableAmt(new BigDecimal("0"));
-
-        user.setUserIndexAmt(new BigDecimal("0"));
-        user.setEnableIndexAmt(new BigDecimal("0"));
-
-        user.setUserFutAmt(new BigDecimal("0"));
-        user.setEnableFutAmt(new BigDecimal("0"));
-
-        user.setSumBuyAmt(new BigDecimal("0"));
-        user.setSumChargeAmt(new BigDecimal("0"));
-        user.setDjzj(new BigDecimal("0"));
-
         int insertCount = this.userMapper.insert(user);
 
         if (insertCount > 0) {
@@ -185,6 +185,7 @@
 
             log.info("用户{}登陆成功, 登陆状态{} ,交易状态{}", new Object[]{user.getId(), user.getIsLogin(), user.getIsLock()});
 
+            userAssetsServices.assetsByTypeAndUserId(EStockType.HG.getCode(),user.getId());
             this.iSiteLoginLogService.saveLog(user, request);
             return ServerResponse.createBySuccess(user);
         }
@@ -217,7 +218,7 @@
         if (user == null) {
             return null;
         } else {
-            return this.userMapper.selectByPrimaryKey(user.getId());
+            return this.userMapper.selectById(user.getId());
         }
     }
 
@@ -297,7 +298,7 @@
         String loginToken = request.getHeader(cookie_name);
         String userJson = RedisShardedPoolUtils.get(loginToken);
         User user = (User) JsonUtil.string2Obj(userJson, User.class);
-        User dbuser = this.userMapper.selectByPrimaryKey(user.getId());
+        User dbuser = this.userMapper.selectById(user.getId());
         SiteSetting siteSetting = iSiteSettingService.getSiteSetting();
         UserInfoVO userInfoVO = assembleUserInfoVO(dbuser, siteSetting);
         return ServerResponse.createBySuccess(userInfoVO);
@@ -319,7 +320,7 @@
         }
 
         user.setUserPwd(SymmetricCryptoUtil.encryptPassword(newPwd));
-        int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
+        int updateCount = this.userMapper.updateById(user);
         if (updateCount > 0) {
             return ServerResponse.createBySuccessMsg("Modified successfully");
         }
@@ -358,7 +359,7 @@
         }
 
         user.setUserPwd(SymmetricCryptoUtil.encryptPassword(newPwd));
-        int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
+        int updateCount = this.userMapper.updateById(user);
         if (updateCount > 0) {
             return ServerResponse.createBySuccess("Password changed successfully!");
         }
@@ -367,10 +368,6 @@
 
 
     public ServerResponse update(User user) {
-        log.info("#####修改用户信息####,用户总资金 = {} 可用资金 = {}", user
-                .getUserAmt(), user.getEnableAmt());
-        log.info("#####修改用户信息####,用户index总资金 = {} index可用资金 = {}", user
-                .getUserIndexAmt(), user.getEnableIndexAmt());
         if (user.getAgentId() != null) {
             AgentUser agentUser = this.agentUserMapper.selectByPrimaryKey(user.getAgentId());
             if (agentUser != null) {
@@ -380,7 +377,7 @@
         if (user.getUserPwd() != null && !user.getUserPwd().equals("")) {
             user.setUserPwd(SymmetricCryptoUtil.encryptPassword(user.getUserPwd()));
         }
-        int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
+        int updateCount = this.userMapper.updateById(user);
         if (updateCount > 0) {
             return ServerResponse.createBySuccessMsg("Modified successfully");
         }
@@ -411,10 +408,8 @@
 
         user.setIsActive(Integer.valueOf(1));
 
-        log.info("##### 用户认证 ####,用户总资金 = {} 可用资金 = {}", user
-                .getUserAmt(), user.getEnableAmt());
 
-        int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
+        int updateCount = this.userMapper.updateById(user);
         if (updateCount > 0) {
             return ServerResponse.createBySuccessMsg("Real name authentication");
         }
@@ -440,37 +435,142 @@
 
         BigDecimal exranRate = iSiteSettingService.getSiteSetting().getExchangeRate();
         if (type == 1) {
-            if (user.getUserIndexAmt().compareTo(new BigDecimal(amt)) == -1) {
-                return ServerResponse.createByErrorMsg("US available in the financing account");
-            }
-            userIndexAmt = user.getUserAmt().subtract(new BigDecimal(amt));
-            enableIndexAmt = user.getEnableAmt().subtract(new BigDecimal(amt));
 
             BigDecimal usdt = new BigDecimal(amt).multiply(exranRate).setScale(2, RoundingMode.UP);
-            userAmt = user.getUserIndexAmt().add(usdt);
-            enableAmt = user.getEnableIndexAmt().add(usdt);
 
         } else if (2 == type) {
-            if (user.getEnableAmt().compareTo(new BigDecimal(amt)) == -1) {
-                return ServerResponse.createByErrorMsg("US available in the financing account");
-            }
-            userAmt = user.getUserAmt().subtract(new BigDecimal(amt));
-            enableAmt = user.getEnableAmt().subtract(new BigDecimal(amt));
 
             BigDecimal usdt = new BigDecimal(amt).divide(exranRate).setScale(2, RoundingMode.UP);
-            userIndexAmt = user.getUserIndexAmt().add(usdt);
-            enableIndexAmt = user.getEnableIndexAmt().add(usdt);
         }
-        user.setUserAmt(userAmt);
-        user.setEnableAmt(enableAmt);
-        user.setUserIndexAmt(userIndexAmt);
-        user.setEnableIndexAmt(enableIndexAmt);
-        int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
+        int updateCount = this.userMapper.updateById(user);
         if (updateCount > 0) {
             saveAmtTransLog(user, type, amt);
             return ServerResponse.createBySuccessMsg("Transfer successful");
         }
         return ServerResponse.createByErrorMsg("Transfer failure");
+    }
+
+    @Override
+    public ServerResponse getMoney(HttpServletRequest request) {
+
+        BigDecimal exchangeRate =  iSiteSettingService.getSiteSetting().getExchangeRate();
+      List<UserAssets>  userAssetsList =   userAssetsServices.assetsByUserId(getCurrentUser(request).getId());
+      List<RUserAssets>  rUserAssetsList = new ArrayList<>();
+
+      /**
+       *  浮动盈亏
+       * */
+      BigDecimal AllProfitAndLose = BigDecimal.ZERO;
+        /**
+         *  总资产
+         * */
+      BigDecimal allTotalAssets = BigDecimal.ZERO;
+        /**
+         *  总可用余额
+         * */
+      BigDecimal allAmt = BigDecimal.ZERO;
+        /**
+         *  累计盈亏
+         * */
+      BigDecimal AllHProfitAndLose = BigDecimal.ZERO;
+        /**
+         *  总冻结资产
+         * */
+      BigDecimal allFreeMoney = BigDecimal.ZERO;
+        /**
+         *  总手续费
+         * */
+      BigDecimal allHMoney = BigDecimal.ZERO;
+
+        for (int i = 0; i <userAssetsList.size() ; i++) {
+            RUserAssets rUserAssets  = new RUserAssets();
+            UserAssets userAssets = userAssetsList.get(i);
+            // 浮动盈亏
+            BigDecimal profitAndLose = userAssets.getProfitAndLoss();
+            BigDecimal amt = userAssets.getAvailableBalance();
+            BigDecimal totalAssets = userAssets.getAvailableBalance().add(userAssets.getFreezeMoney());
+            BigDecimal freeMoney = userAssets.getFreezeMoney();
+            BigDecimal hMoney = userAssets.getHandlingCharge();
+            BigDecimal hProfitAndLose = userAssets.getCumulativeProfitAndLoss();
+
+            rUserAssets.setTotalMoney((totalAssets.setScale(2).toString()));
+            rUserAssets.setAccectType(userAssets.getAccectType());
+            rUserAssets.setAvailableBalance(amt.setScale(2).toString());
+            rUserAssets.setFreezeMoney(freeMoney.setScale(2).toString());
+            rUserAssets.setCumulativeProfitAndLoss(hProfitAndLose.setScale(2).toString());
+            rUserAssets.setHandlingCharge(hMoney.setScale(2).toString());
+            rUserAssets.setProfitAndLoss(profitAndLose.setScale(2).toString());
+            if(userAssets.getAccectType().equals("US")){
+                rUserAssets.setSymbol("$");
+                rUserAssets.setSymbolCode("USD");
+                AllProfitAndLose = AllProfitAndLose.add(profitAndLose);
+                allTotalAssets = allTotalAssets.add(totalAssets);
+                allAmt = allAmt.add(amt);
+                AllHProfitAndLose = AllHProfitAndLose.add(hProfitAndLose);
+                allFreeMoney = allFreeMoney.add(freeMoney);
+                allHMoney = allHMoney.add(hMoney);
+                rUserAssets.setAvailableBalanceUSD(rUserAssets.getAvailableBalance());
+                rUserAssets.setFreezeMoneyUSD(rUserAssets.getFreezeMoney());
+                rUserAssets.setTotalMoneyUSD(rUserAssets.getTotalMoney());
+                rUserAssets.setCumulativeProfitAndLossUSD(hProfitAndLose.setScale(2).toString());
+                rUserAssets.setHandlingChargeUSD(hMoney.setScale(2).toString());
+                rUserAssets.setProfitAndLossUSD(hProfitAndLose.setScale(2).toString());
+
+            }else{
+                rUserAssets.setAvailableBalanceUSD(userAssets.getAvailableBalance().divide(exchangeRate,BigDecimal.ROUND_CEILING).toString());
+                rUserAssets.setFreezeMoneyUSD(userAssets.getFreezeMoney().divide(exchangeRate,BigDecimal.ROUND_CEILING).toString());
+                rUserAssets.setTotalMoneyUSD(userAssets.getTotleAssets().divide(exchangeRate,BigDecimal.ROUND_CEILING).toString());
+                rUserAssets.setSymbol("RM");
+                rUserAssets.setSymbolCode("MYR");
+                rUserAssets.setCumulativeProfitAndLossUSD(hProfitAndLose.divide(exchangeRate,BigDecimal.ROUND_CEILING).toString());
+                rUserAssets.setHandlingChargeUSD(hMoney.divide(exchangeRate,BigDecimal.ROUND_CEILING).toString());
+                rUserAssets.setProfitAndLossUSD(hProfitAndLose.divide(exchangeRate,BigDecimal.ROUND_CEILING).toString());
+
+                AllProfitAndLose = AllProfitAndLose.add(profitAndLose.divide(exchangeRate,BigDecimal.ROUND_CEILING));
+                allTotalAssets = allTotalAssets.add(totalAssets.divide(exchangeRate,BigDecimal.ROUND_CEILING));
+                allAmt = allAmt.add(amt.divide(exchangeRate,BigDecimal.ROUND_CEILING));
+                AllHProfitAndLose = AllHProfitAndLose.add(hProfitAndLose.divide(exchangeRate,BigDecimal.ROUND_CEILING));
+                allFreeMoney = allFreeMoney.add(freeMoney.divide(exchangeRate,BigDecimal.ROUND_CEILING));
+                allHMoney = allHMoney.add(hMoney.divide(exchangeRate,BigDecimal.ROUND_CEILING));
+            }
+            rUserAssetsList.add(rUserAssets);
+        }
+
+
+
+        RUserAssets rUserAssets  = new RUserAssets();
+        rUserAssets.setAccectType("ALL");
+        rUserAssets.setProfitAndLoss(AllProfitAndLose.setScale(2).toString());
+        rUserAssets.setProfitAndLossUSD(AllProfitAndLose.setScale(2).toString());
+        rUserAssets.setHandlingCharge(allHMoney.setScale(2).toString());
+        rUserAssets.setHandlingChargeUSD(allHMoney.setScale(2).toString());
+        rUserAssets.setCumulativeProfitAndLoss(AllHProfitAndLose.setScale(2).toString());
+        rUserAssets.setCumulativeProfitAndLossUSD(AllHProfitAndLose.setScale(2).toString());
+        rUserAssets.setTotalMoney(allTotalAssets.setScale(2).toString());
+        rUserAssets.setTotalMoneyUSD(allTotalAssets.setScale(2).toString());
+        rUserAssets.setAvailableBalance(allAmt.setScale(2).toString());
+        rUserAssets.setAvailableBalanceUSD(allAmt.setScale(2).toString());
+        rUserAssets.setFreezeMoney(allFreeMoney.setScale(2).toString());
+        rUserAssets.setFreezeMoneyUSD(allFreeMoney.setScale(2).toString());
+        rUserAssets.setSymbol("$");
+        rUserAssets.setSymbolCode("USD");
+        rUserAssetsList.add(rUserAssets);
+
+        return ServerResponse.createBySuccess(rUserAssetsList);
+    }
+
+    @Override
+    public ServerResponse transfer(String fromType, String toType, String amt,HttpServletRequest paramHttpServletRequest) {
+
+        User user =  userService.getCurrentUser(paramHttpServletRequest);
+        UserAssets formAssets = userAssetsServices.assetsByTypeAndUserId(fromType,user.getId());
+        BigDecimal amtBig = new BigDecimal(amt);
+        if(formAssets.getAvailableBalance().compareTo(amtBig)<0){
+            return ServerResponse.createByErrorMsg("Insufficient amount");
+        }
+        userAssetsServices.availablebalanceChange(fromType,user.getId(), EUserAssets.TRANSFER,amtBig.negate(),"","");
+        userAssetsServices.availablebalanceChange(toType,user.getId(),EUserAssets.TRANSFER,amtBig,"","");
+        return ServerResponse.createBySuccess();
     }
 
 
@@ -504,614 +604,44 @@
 
 
     public void ForceSellTask() {
-        List<Integer> userIdList = this.iUserPositionService.findDistinctUserIdList();
 
-        log.info("当前有持仓单的用户数量 为 {}", Integer.valueOf(userIdList.size()));
-
-        for (int i = 0; i < userIdList.size(); i++) {
-            log.info("=====================");
-            Integer userId = (Integer) userIdList.get(i);
-            User user = this.userMapper.selectByPrimaryKey(userId);
-            if (user == null) {
-                continue;
-            }
-
-
-            List<UserPosition> userPositions = this.iUserPositionService.findPositionByUserIdAndSellIdIsNull(userId);
-
-            log.info("用户id = {} 姓名 = {} 持仓中订单数: {}", new Object[]{userId, user.getRealName(), Integer.valueOf(userPositions.size())});
-
-
-            BigDecimal enable_user_amt = user.getEnableAmt();
-
-
-            BigDecimal all_freez_amt = new BigDecimal("0");
-            for (UserPosition position : userPositions) {
-
-                BigDecimal actual_amt = position.getOrderTotalPrice().divide(new BigDecimal(position
-                        .getOrderLever().intValue()), 2, 4);
-
-
-                all_freez_amt = all_freez_amt.add(actual_amt);
-            }
-
-
-            BigDecimal all_profit_and_lose = new BigDecimal("0");
-            PositionVO positionVO = this.iUserPositionService.findUserPositionAllProfitAndLose(userId);
-            all_profit_and_lose = positionVO.getAllProfitAndLose();
-            SiteSetting siteSetting = this.iSiteSettingService.getSiteSetting();
-            BigDecimal force_stop_percent = siteSetting.getForceStopPercent();
-            BigDecimal force_stop_amt = enable_user_amt.add(all_freez_amt);
-
-            //(沪深)强制平仓线 = (账户可用资金 + 冻结保证金) *  0.8
-            BigDecimal user_force_amt = force_stop_percent.multiply(force_stop_amt);
-            BigDecimal fu_user_force_amt = user_force_amt.negate(); //负平仓线
-            log.info("用户强制平仓线金额 = {}", user_force_amt);
-
-            boolean isProfit = false;
-
-            //总盈亏<=0  并且  强制负平仓线>=总盈亏
-            isProfit = (all_profit_and_lose.compareTo(new BigDecimal("0")) < 1 && fu_user_force_amt.compareTo(all_profit_and_lose) > -1);
-            if (isProfit) {
-                log.info("强制平仓该用户所有的持仓单");
-
-                int[] arrs = new int[userPositions.size()];
-                for (int k = 0; k < userPositions.size(); k++) {
-                    UserPosition position = (UserPosition) userPositions.get(k);
-                    arrs[k] = position.getId().intValue();
-                    try {
-                        if (!DateTimeUtil.sameDate(DateTimeUtil.getCurrentDate(), position.getBuyOrderTime())) {
-                            this.iUserPositionService.sell(position.getPositionSn(), 0);
-                        }
-
-                    } catch (Exception e) {
-                        log.error("[盈亏达到最大亏损]强制平仓失败...");
-                    }
-                }
-
-
-                SiteTaskLog siteTaskLog = new SiteTaskLog();
-                siteTaskLog.setTaskType("强平任务-股票持仓");
-                String accountType = (user.getAccountType().intValue() == 0) ? "正式用户" : "模拟用户";
-                String taskcnt = accountType + "-" + user.getRealName() + "被强平[两融盈亏达到最大亏损] 用户id = " + user.getId() + ", 可用资金 = " + enable_user_amt + "冻结保证金 = " + all_freez_amt + ", 强平比例 = " + force_stop_percent + ", 总盈亏" + all_profit_and_lose + ", 强平线:" + user_force_amt;
-
-
-                siteTaskLog.setTaskCnt(taskcnt);
-                String tasktarget = "此次强平" + userPositions.size() + "条股票持仓订单, 订单号为" + Arrays.toString(arrs);
-                siteTaskLog.setTaskTarget(tasktarget);
-                siteTaskLog.setAddTime(new Date());
-                siteTaskLog.setIsSuccess(Integer.valueOf(0));
-                siteTaskLog.setErrorMsg("");
-                int insertTaskCount = this.siteTaskLogMapper.insert(siteTaskLog);
-                if (insertTaskCount > 0) {
-                    log.info("[盈亏达到最大亏损]保存强制平仓task任务成功");
-                } else {
-                    log.info("[盈亏达到最大亏损]保存强制平仓task任务失败");
-                }
-            } else {
-                log.info("用户未达到强制平仓线,不做强平处理...");
-            }
-
-            log.info("=====================");
-        }
     }
 
-    /*用户持仓单-单支股票盈亏-强平定时*/
+    @Override
     public void ForceSellOneStockTask() {
-        List<Integer> userIdList = this.iUserPositionService.findDistinctUserIdList();
-        log.info("当前有持仓单的用户数量 为 {}", Integer.valueOf(userIdList.size()));
-        SiteSetting siteSetting = this.iSiteSettingService.getSiteSetting();
-        BigDecimal force_stop_percent = siteSetting.getForceStopPercent();
-        for (int i = 0; i < userIdList.size(); i++) {
-            log.info("=====================");
-            Integer userId = (Integer) userIdList.get(i);
-            User user = this.userMapper.selectByPrimaryKey(userId);
-            if (user == null) {
-                continue;
-            }
-            List<UserPosition> userPositions = this.iUserPositionService.findPositionByUserIdAndSellIdIsNull(userId);
-            log.info("用户id = {} 姓名 = {} 持仓中订单数: {}", new Object[]{userId, user.getRealName(), Integer.valueOf(userPositions.size())});
 
-            BigDecimal enable_user_amt = user.getEnableAmt();
-            BigDecimal all_freez_amt = new BigDecimal("0");
-            for (UserPosition position : userPositions) {
-                PositionProfitVO positionProfitVO = iUserPositionService.getPositionProfitVO(position);
-
-                //(沪深)单支股票强制平仓线 = (下单总金额 / 杠杆 + 追加保证金) *  0.8
-                BigDecimal user_force_amt = position.getOrderTotalPrice().divide(new BigDecimal(position.getOrderLever())).add(position.getMarginAdd()).multiply(force_stop_percent);
-                BigDecimal fu_user_force_amt = user_force_amt.negate(); //负平仓线
-                log.info("用户强制平仓线金额 = {}", user_force_amt);
-                /*if("1601344387923698".equals( position.getPositionSn())){
-                    log.info("test = {}", position.getPositionSn());
-                }*/
-                boolean isProfit = false;
-                //总盈亏<=0  并且  强制负平仓线>=总盈亏
-                isProfit = (positionProfitVO.getAllProfitAndLose().compareTo(new BigDecimal("0")) < 1 && fu_user_force_amt.compareTo(positionProfitVO.getAllProfitAndLose()) > -1);
-                if (isProfit && !DateTimeUtil.sameDate(DateTimeUtil.getCurrentDate(), position.getBuyOrderTime())) {
-                    try {
-                        this.iUserPositionService.sell(position.getPositionSn(), 0);
-                        SiteTaskLog siteTaskLog = new SiteTaskLog();
-                        siteTaskLog.setTaskType("单股强平任务-股票持仓");
-                        String accountType = (user.getAccountType().intValue() == 0) ? "正式用户" : "模拟用户";
-                        String taskcnt = accountType + "-" + user.getRealName() + "被强平[两融盈亏达到最大亏损] 用户id = " + user.getId() + ", 可用资金 = " + enable_user_amt + "冻结保证金 = " + all_freez_amt + ", 强平比例 = " + force_stop_percent + ", 总盈亏" + positionProfitVO.getAllProfitAndLose() + ", 强平线:" + user_force_amt;
-                        siteTaskLog.setTaskCnt(taskcnt);
-                        String tasktarget = "此次强平订单号为:" + position.getPositionSn();
-                        siteTaskLog.setTaskTarget(tasktarget);
-                        siteTaskLog.setAddTime(new Date());
-                        siteTaskLog.setIsSuccess(Integer.valueOf(0));
-                        siteTaskLog.setErrorMsg("");
-                        int insertTaskCount = this.siteTaskLogMapper.insert(siteTaskLog);
-                        if (insertTaskCount > 0) {
-                            log.info("[盈亏达到最大亏损]保存强制平仓task任务成功");
-                        } else {
-                            log.info("[盈亏达到最大亏损]保存强制平仓task任务失败");
-                        }
-                    } catch (Exception e) {
-                        log.error("[盈亏达到最大亏损]强制平仓失败...");
-                    }
-                }
-
-            }
-            log.info("=====================");
-        }
     }
 
-    /*用户持仓单-单支股票/止损止盈-强平定时*/
+    @Override
     public void ForceSellOneStockTaskV2() {
-        List<Integer> userIdList = this.iUserPositionService.findDistinctUserIdList();
-        log.info("当前有持仓单的用户数量 为 {}", Integer.valueOf(userIdList.size()));
-        SiteSetting siteSetting = this.iSiteSettingService.getSiteSetting();
-        BigDecimal force_stop_percent = siteSetting.getForceStopPercent();
-        for (int i = 0; i < userIdList.size(); i++) {
-            log.info("=====================");
-            Integer userId = (Integer) userIdList.get(i);
-            User user = this.userMapper.selectByPrimaryKey(userId);
-            if (user == null) {
-                continue;
-            }
-            List<UserPosition> userPositions = this.iUserPositionService.findPositionByUserIdAndSellIdIsNull(userId);
-            log.info("用户id = {} 姓名 = {} 持仓中订单数: {}", new Object[]{userId, user.getRealName(), Integer.valueOf(userPositions.size())});
 
-            BigDecimal enable_user_amt = user.getEnableAmt();
-            BigDecimal all_freez_amt = new BigDecimal("0");
-            for (UserPosition position : userPositions) {
-                StockListVO stockListVO = new StockListVO();
-                if (position.getStockGid().contains("hk")) {
-                    String hk = RedisShardedPoolUtils.get(position.getStockGid(), 1);
-                    stockListVO = StockApi.otherStockListVO(hk);
-                } else if (position.getStockGid().contains("us")) {
-                    String us = RedisShardedPoolUtils.get(position.getStockGid(), 2);
-                    stockListVO = StockApi.otherStockListVO(us);
-                } else {
-                    Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code", position.getStockCode()));
-                    stockListVO = StockApi.getStockRealTime(stock);
-                }
-                if (stockListVO == null) {
-                    continue;
-                }
-                if (position.getProfitTargetPrice() != null && position.getProfitTargetPrice().compareTo(new BigDecimal(stockListVO.getNowPrice())) <= 0 || position.getStopTargetPrice() != null && position.getStopTargetPrice().compareTo(new BigDecimal(stockListVO.getNowPrice())) >= 0) {
-                    try {
-                        this.iUserPositionService.sell(position.getPositionSn(), 0);
-                        SiteTaskLog siteTaskLog = new SiteTaskLog();
-                        siteTaskLog.setTaskType("单股止盈止损强平任务-股票持仓");
-                        String accountType = (user.getAccountType().intValue() == 0) ? "正式用户" : "模拟用户";
-                        String taskcnt = accountType + "-" + user.getRealName() + "被强平[达到目标盈亏] 用户id = " + user.getId() + ", 可用资金 = " + enable_user_amt + "冻结保证金 = " + all_freez_amt + ", 强平比例 = " + force_stop_percent + ",现价" + stockListVO.getNowPrice() + ", 目标止盈价格:" + position.getProfitTargetPrice() + ", 目标止损价格:" + position.getStopTargetPrice();
-                        siteTaskLog.setTaskCnt(taskcnt);
-                        String tasktarget = "此次强平订单号为:" + position.getPositionSn();
-                        siteTaskLog.setTaskTarget(tasktarget);
-                        siteTaskLog.setAddTime(new Date());
-                        siteTaskLog.setIsSuccess(Integer.valueOf(0));
-                        siteTaskLog.setErrorMsg("");
-                        int insertTaskCount = this.siteTaskLogMapper.insert(siteTaskLog);
-                        if (insertTaskCount > 0) {
-                            log.info("[盈利达到目标盈利]保存强制平仓task任务成功");
-                        } else {
-                            log.info("[盈利达到目标盈利]保存强制平仓task任务失败");
-                        }
-                    } catch (Exception e) {
-                        log.error("[盈利达到目标盈利]强制平仓失败...");
-                    }
-
-                }
-
-            }
-            log.info("=========止盈止损定时任务============");
-        }
     }
 
-    /*用户股票持仓单-强平提醒推送消息定时*/
+    @Override
     public void ForceSellMessageTask() {
-        List<Integer> userIdList = this.iUserPositionService.findDistinctUserIdList();
 
-        log.info("当前有持仓单的用户数量 为 {}", Integer.valueOf(userIdList.size()));
-
-        for (int i = 0; i < userIdList.size(); i++) {
-            log.info("=====================");
-            Integer userId = (Integer) userIdList.get(i);
-            User user = this.userMapper.selectByPrimaryKey(userId);
-            if (user == null) {
-                continue;
-            }
-
-
-            List<UserPosition> userPositions = this.iUserPositionService.findPositionByUserIdAndSellIdIsNull(userId);
-
-            log.info("用户id = {} 姓名 = {} 持仓中订单数: {}", new Object[]{userId, user.getRealName(), Integer.valueOf(userPositions.size())});
-
-
-            BigDecimal enable_user_amt = user.getEnableAmt();
-
-
-            BigDecimal all_freez_amt = new BigDecimal("0");
-            for (UserPosition position : userPositions) {
-
-                BigDecimal actual_amt = position.getOrderTotalPrice().divide(new BigDecimal(position
-                        .getOrderLever().intValue()), 2, 4);
-
-
-                all_freez_amt = all_freez_amt.add(actual_amt);
-            }
-
-
-            BigDecimal all_profit_and_lose = new BigDecimal("0");
-            PositionVO positionVO = this.iUserPositionService.findUserPositionAllProfitAndLose(userId);
-            all_profit_and_lose = positionVO.getAllProfitAndLose();
-            SiteSetting siteSetting = this.iSiteSettingService.getSiteSetting();
-            BigDecimal force_stop_percent = siteSetting.getForceStopRemindRatio();
-            /*BigDecimal force_stop_amt = force_stop_percent.multiply(all_freez_amt);
-            BigDecimal user_force_amt = enable_user_amt.add(force_stop_amt);
-            boolean isProfit = false;
-            isProfit = (all_profit_and_lose.compareTo(new BigDecimal("0")) == -1 && user_force_amt.compareTo(all_profit_and_lose.negate()) != 1);
-            */
-            BigDecimal force_stop_amt = enable_user_amt.add(all_freez_amt);
-
-            //(沪深)强制平仓线 = (账户可用资金 + 冻结保证金) *  0.8
-            BigDecimal user_force_amt = force_stop_percent.multiply(force_stop_amt);
-            BigDecimal fu_user_force_amt = user_force_amt.negate(); //负平仓线
-            log.info("用户强制平仓线金额 = {}", user_force_amt);
-
-            boolean isProfit = false;
-
-            //总盈亏<=0  并且  强制负平仓线>=总盈亏
-            isProfit = (all_profit_and_lose.compareTo(new BigDecimal("0")) < 1 && fu_user_force_amt.compareTo(all_profit_and_lose) > -1);
-            if (isProfit) {
-                log.info("强制平仓该用户所有的持仓单");
-                int count = iSiteMessageService.getIsDayCount(userId, "股票预警");
-                if (count == 0) {
-                    //给达到消息强平提醒用户推送消息
-                    SiteMessage siteMessage = new SiteMessage();
-                    siteMessage.setUserId(userId);
-                    siteMessage.setUserName(user.getRealName());
-                    siteMessage.setTypeName("股票预警");
-                    siteMessage.setStatus(1);
-                    siteMessage.setContent("【股票预警】提醒您,用户id = " + user.getId() + ", 可用资金 = " + enable_user_amt + "冻结保证金 = " + all_freez_amt + ", 强平比例 = " + force_stop_percent + ", 总盈亏" + all_profit_and_lose + ", 提醒线:" + user_force_amt + ",请及时关注哦。");
-                    siteMessage.setAddTime(DateTimeUtil.getCurrentDate());
-                    iSiteMessageService.insert(siteMessage);
-                }
-
-            } else {
-                log.info("用户未达到强制平仓线,不做强平处理...");
-            }
-
-            log.info("=====================");
-        }
     }
 
-
+    @Override
     public void ForceSellIndexTask() {
-        List<Integer> userIdList = this.iUserIndexPositionService.findDistinctUserIdList();
 
-        log.info("当前有 指数持仓 的用户数量 为 {}", Integer.valueOf(userIdList.size()));
-
-        for (int i = 0; i < userIdList.size(); i++) {
-            log.info("=====================");
-            Integer userId = (Integer) userIdList.get(i);
-            User user = this.userMapper.selectByPrimaryKey(userId);
-            if (user == null) {
-                continue;
-            }
-
-
-            List<UserIndexPosition> userIndexPositions = this.iUserIndexPositionService.findIndexPositionByUserIdAndSellPriceIsNull(userId);
-
-            log.info("用户id = {} 姓名 = {} 持仓中订单数: {}", new Object[]{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});
-
-
-            SiteIndexSetting siteIndexSetting = this.iSiteIndexSettingService.getSiteIndexSetting();
-            BigDecimal force_stop_percent = siteIndexSetting.getForceSellPercent();
-            BigDecimal force_stop_amt = enable_index_amt.add(all_freez_amt);
-
-            //(指数)强制平仓线 = (账户可用资金 + 冻结保证金) *  0.8
-            BigDecimal user_force_amt = force_stop_percent.multiply(force_stop_amt);
-            BigDecimal fu_user_force_amt = user_force_amt.negate(); //负平仓线
-            log.info("用户强制平仓线金额 = {}", user_force_amt);
-            boolean isProfit = false;
-            //总盈亏<=0  并且  强制负平仓线>=总盈亏
-            isProfit = (all_profit_and_lose.compareTo(new BigDecimal("0")) < 1 && fu_user_force_amt.compareTo(all_profit_and_lose) > -1);
-
-            if (isProfit) {
-                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();
-                    try {
-                        this.iUserIndexPositionService.sellIndex(userIndexPosition.getPositionSn(), 0);
-                    } catch (Exception e) {
-                        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.setTaskCnt(taskcnt);
-
-                String tasktarget = "此次强平" + userIndexPositions.size() + "条指数持仓订单, 订单号为" + Arrays.toString(arrs);
-                siteTaskLog.setTaskTarget(tasktarget);
-                siteTaskLog.setAddTime(new Date());
-                siteTaskLog.setIsSuccess(Integer.valueOf(0));
-                siteTaskLog.setErrorMsg("");
-                int insertTaskCount = this.siteTaskLogMapper.insert(siteTaskLog);
-                if (insertTaskCount > 0) {
-                    log.info("[盈亏达到最大亏损] 保存强制平仓 指数 task任务成功");
-                } else {
-                    log.info("[盈亏达到最大亏损] 保存强制平仓 指数 task任务失败");
-                }
-            } else {
-                log.info("用户指数持仓未达到强制平仓线, 不做强平处理...");
-            }
-
-            log.info("=====================");
-        }
     }
 
-    /*指数强平提醒推送消息,每分钟检测一次*/
+    @Override
     public void ForceSellIndexsMessageTask() {
-        List<Integer> userIdList = this.iUserIndexPositionService.findDistinctUserIdList();
 
-        log.info("当前有 指数持仓 的用户数量 为 {}", Integer.valueOf(userIdList.size()));
-
-        for (int i = 0; i < userIdList.size(); i++) {
-            log.info("=====================");
-            Integer userId = (Integer) userIdList.get(i);
-            User user = this.userMapper.selectByPrimaryKey(userId);
-            if (user == null) {
-                continue;
-            }
-
-
-            List<UserIndexPosition> userIndexPositions = this.iUserIndexPositionService.findIndexPositionByUserIdAndSellPriceIsNull(userId);
-
-            log.info("用户id = {} 姓名 = {} 持仓中订单数: {}", new Object[]{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});
-
-
-            SiteIndexSetting siteIndexSetting = this.iSiteIndexSettingService.getSiteIndexSetting();
-            BigDecimal force_stop_percent = siteIndexSetting.getForceStopRemindRatio();
-            BigDecimal force_stop_amt = enable_index_amt.add(all_freez_amt);
-
-            //(指数)强制平仓线 = (账户可用资金 + 冻结保证金) *  0.8
-            BigDecimal user_force_amt = force_stop_percent.multiply(force_stop_amt);
-            BigDecimal fu_user_force_amt = user_force_amt.negate(); //负平仓线
-            log.info("用户强制平仓线金额 = {}", user_force_amt);
-            boolean isProfit = false;
-            //总盈亏<=0  并且  强制负平仓线>=总盈亏
-            isProfit = (all_profit_and_lose.compareTo(new BigDecimal("0")) < 1 && fu_user_force_amt.compareTo(all_profit_and_lose) > -1);
-
-            if (isProfit) {
-                log.info("强制平仓该用户所有的指数持仓单");
-
-                int count = iSiteMessageService.getIsDayCount(userId, "指数预警");
-                if (count == 0) {
-                    //给达到消息强平提醒用户推送消息
-                    SiteMessage siteMessage = new SiteMessage();
-                    siteMessage.setUserId(userId);
-                    siteMessage.setUserName(user.getRealName());
-                    siteMessage.setTypeName("指数预警");
-                    siteMessage.setStatus(1);
-                    siteMessage.setContent("【指数预警】提醒您,用户id = " + user.getId() + ", 可用资金 = " + enable_index_amt + ", 冻结资金 = " + all_freez_amt + ", 强平比例 = " + force_stop_percent + ", 总盈亏 = " + all_profit_and_lose + ", 提醒线 = " + user_force_amt + ",请及时关注哦。");
-                    siteMessage.setAddTime(DateTimeUtil.getCurrentDate());
-                    iSiteMessageService.insert(siteMessage);
-                }
-
-            } else {
-                log.info("用户指数持仓未达到强制平仓线, 不做强平处理...");
-            }
-
-            log.info("=====================");
-        }
     }
 
-//    public void qh1() {
-//        this.stockPoll.qh1();
-//    }
-//
-//    public void zs1() {
-//        this.stockPoll.zs1();
-//    }
-
+    @Override
     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);
-            System.out.println("userId" + userId);
-            User user = this.userMapper.selectByPrimaryKey(userId);
-            if (user == null) {
-                continue;
-            }
-
-            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())});
-
-            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});
-
-
-            SiteFuturesSetting siteFuturesSetting = this.iSiteFuturesSettingService.getSetting();
-            BigDecimal force_stop_percent = siteFuturesSetting.getForceSellPercent();
-            BigDecimal force_stop_amt = enable_Futures_amt.add(all_deposit_amt);
-
-            //(期货)强制平仓线 = (账户可用资金 + 冻结保证金) *  0.8
-            BigDecimal user_force_amt = force_stop_percent.multiply(force_stop_amt);
-            BigDecimal fu_user_force_amt = user_force_amt.negate(); //负平仓线
-            log.info("用户强制平仓线金额 = {}", user_force_amt);
-
-            boolean isProfit = false;
-
-            //总盈亏<=0  并且  强制负平仓线>=总盈亏
-            isProfit = (all_profit_and_lose.compareTo(new BigDecimal("0")) < 1 && fu_user_force_amt.compareTo(all_profit_and_lose) > -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();
-                    try {
-                        this.iUserFuturesPositionService.sellFutures(userFuturesPosition.getPositionSn(), 0);
-                    } catch (Exception e) {
-                        log.error("[盈亏达到最大亏损] 强制平仓 期货 失败...");
-                    }
-                }
-
-                SiteTaskLog siteTaskLog = new SiteTaskLog();
-                siteTaskLog.setTaskType("强平任务-期货持仓");
-                String accountType = (user.getAccountType().intValue() == 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.setErrorMsg("");
-                int insertTaskCount = this.siteTaskLogMapper.insert(siteTaskLog);
-                if (insertTaskCount > 0) {
-                    log.info("[盈亏达到最大亏损]保存强制平仓 期货 task任务成功");
-                } else {
-                    log.info("[盈亏达到最大亏损]保存强制平仓 期货 task任务失败");
-                }
-            } else {
-                log.info("用户期货;持仓未达到强制平仓线,不做强平处理...");
-            }
-            log.info("===================== \n");
-        }
     }
 
+    @Override
     public void ForceSellFuturesMessageTask() {
-        List<Integer> userIdList = this.iUserFuturesPositionService.findDistinctUserIdList();
 
-
-        for (int i = 0; i < userIdList.size(); i++) {
-            log.info("===================== \n");
-            Integer userId = (Integer) userIdList.get(i);
-            System.out.println("userId" + userId);
-            User user = this.userMapper.selectByPrimaryKey(userId);
-            if (user == null) {
-                continue;
-            }
-
-            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())});
-
-            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});
-
-            SiteFuturesSetting siteFuturesSetting = this.iSiteFuturesSettingService.getSetting();
-            BigDecimal force_stop_percent = siteFuturesSetting.getForceStopRemindRatio();
-            BigDecimal force_stop_amt = enable_Futures_amt.add(all_deposit_amt);
-
-            //(期货)强制平仓线 = (账户可用资金 + 冻结保证金) *  0.4
-            BigDecimal user_force_amt = force_stop_percent.multiply(force_stop_amt);
-            BigDecimal fu_user_force_amt = user_force_amt.negate(); //负平仓线
-            log.info("用户消息强制平仓线金额 = {}", user_force_amt);
-
-            boolean isProfit = false;
-
-            //总盈亏<=0  并且  强制负平仓线>=总盈亏
-            isProfit = (all_profit_and_lose.compareTo(new BigDecimal("0")) < 1 && fu_user_force_amt.compareTo(all_profit_and_lose) > -1);
-
-            if (isProfit) {
-                log.info("强制平仓用户 {} 所有的 期货 持仓单", user.getId());
-                int count = iSiteMessageService.getIsDayCount(userId, "期货预警");
-                if (count == 0) {
-                    //给达到消息强平提醒用户推送消息
-                    SiteMessage siteMessage = new SiteMessage();
-                    siteMessage.setUserId(userId);
-                    siteMessage.setUserName(user.getRealName());
-                    siteMessage.setTypeName("期货预警");
-                    siteMessage.setStatus(1);
-                    siteMessage.setContent("【期货预警】提醒您,用户id = " + user.getId() + ", 可用资金 = " + enable_Futures_amt + ", 冻结保证金 = " + all_deposit_amt + ", 强平比例 = " + force_stop_percent + ", 总盈亏" + all_profit_and_lose + ", 提醒线:" + user_force_amt + ",请及时关注哦。");
-                    siteMessage.setAddTime(DateTimeUtil.getCurrentDate());
-                    iSiteMessageService.insert(siteMessage);
-                }
-
-
-            } else {
-                log.info("用户期货;持仓未达到强制平仓线,不做强平处理...");
-            }
-            log.info("===================== \n");
-        }
     }
+
 
     @Override
     public void qh1() {
@@ -1183,11 +713,6 @@
         User user = new User();
         user.setAccountType(accountType);
         user.setPhone(phone);
-        user.setUserPwd(SymmetricCryptoUtil.encryptPassword(pwd));
-        user.setUserAmt(new BigDecimal(amt));
-        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));
@@ -1197,10 +722,6 @@
             user.setNickName("模拟用户");
         }
 
-        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);
@@ -1228,12 +749,12 @@
 
 
     public ServerResponse findByUserId(Integer userId) {
-        return ServerResponse.createBySuccess(this.userMapper.selectByPrimaryKey(userId));
+        return ServerResponse.createBySuccess(this.userMapper.selectById(userId));
     }
 
 
     public ServerResponse updateLock(Integer userId) {
-        User user = this.userMapper.selectByPrimaryKey(userId);
+        User user = this.userMapper.selectById(userId);
         if (user == null) {
             return ServerResponse.createByErrorMsg("User does not exist");
         }
@@ -1244,7 +765,7 @@
             user.setIsLock(Integer.valueOf(1));
         }
 
-        int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
+        int updateCount = this.userMapper.updateById(user);
         if (updateCount > 0) {
             return ServerResponse.createBySuccess("Modified successfully");
         }
@@ -1258,38 +779,11 @@
             return ServerResponse.createByErrorMsg("The parameter cannot be null");
         }
 
-        User user = this.userMapper.selectByPrimaryKey(userId);
+        User user = this.userMapper.selectById(userId);
         if (user == null) {
             return ServerResponse.createByErrorMsg("User does not exist");
         }
-
-        BigDecimal user_amt = user.getUserAmt();
-        BigDecimal user_enable = user.getEnableAmt();
-
-        BigDecimal user_amt_back = new BigDecimal("0");
-        BigDecimal user_enable_back = new BigDecimal("0");
-        if (direction.intValue() == 0) {
-            user_amt_back = user_amt.add(new BigDecimal(amt));
-            user_enable_back = user_enable.add(new BigDecimal(amt));
-        } else if (direction.intValue() == 1) {
-
-            if (user_amt.compareTo(new BigDecimal(amt)) == -1) {
-                return ServerResponse.createByErrorMsg("The deduction failed and the total funds were insufficient");
-            }
-            if (user_enable.compareTo(new BigDecimal(amt)) == -1) {
-                return ServerResponse.createByErrorMsg("Deduction failed, insufficient available funds");
-            }
-
-            user_amt_back = user_amt.subtract(new BigDecimal(amt));
-            user_enable_back = user_enable.subtract(new BigDecimal(amt));
-        } else {
-            return ServerResponse.createByErrorMsg("This operation does not exist");
-        }
-
-
-        user.setUserAmt(user_amt_back);
-        user.setEnableAmt(user_enable_back);
-        this.userMapper.updateByPrimaryKeySelective(user);
+        this.userMapper.updateById(user);
 
 
         SiteTaskLog siteTaskLog = new SiteTaskLog();
@@ -1301,9 +795,6 @@
         siteTaskLog.setTaskCnt(cnt.toString());
 
         StringBuffer target = new StringBuffer();
-        target.append("用户id : ").append(user.getId())
-                .append("修改前 总资金 = ").append(user_amt).append(" 可用 = ").append(user_enable)
-                .append("修改后 总资金 = ").append(user_amt_back).append(" 可用 = ").append(user_enable_back);
         siteTaskLog.setTaskTarget(target.toString());
 
         siteTaskLog.setIsSuccess(Integer.valueOf(0));
@@ -1366,7 +857,7 @@
         }
 
 
-        int delUserCount = this.userMapper.deleteByPrimaryKey(userId);
+        int delUserCount = this.userMapper.deleteById(userId);
         if (delUserCount > 0) {
             return ServerResponse.createBySuccessMsg("Successful operation");
         }
@@ -1394,7 +885,7 @@
             return ServerResponse.createByErrorMsg("id and state cannot be empty");
         }
 
-        User user = this.userMapper.selectByPrimaryKey(userId);
+        User user = this.userMapper.selectById(userId);
         if (user == null) {
             return ServerResponse.createByErrorMsg("This user cannot be found");
         }
@@ -1408,7 +899,7 @@
 
         user.setIsActive(state);
 
-        int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
+        int updateCount = this.userMapper.updateById(user);
         if (updateCount > 0) {
             return ServerResponse.createBySuccessMsg("Successful audit");
         }
@@ -1464,14 +955,7 @@
         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());
@@ -1481,7 +965,6 @@
         agentUserListVO.setAllFreezAmt(allFreezAmt);
 
         BigDecimal forceLine = forcePercent.multiply(allFreezAmt);
-        forceLine = forceLine.add(user.getEnableAmt());
         agentUserListVO.setForceLine(forceLine);
 
 
@@ -1490,7 +973,7 @@
         agentUserListVO.setAllIndexFreezAmt(indexPositionVO.getAllIndexFreezAmt());
 
         BigDecimal indexForceLine = indexForcePercent.multiply(indexPositionVO.getAllIndexFreezAmt());
-        indexForceLine = indexForceLine.add(user.getEnableIndexAmt());
+
         agentUserListVO.setIndexForceLine(indexForceLine);
 
 
@@ -1499,7 +982,7 @@
         agentUserListVO.setAllFuturesProfitAndLose(futuresPositionVO.getAllFuturesProfitAndLose());
 
         BigDecimal futuresForceLine = futuresForcePercent.multiply(futuresPositionVO.getAllFuturesDepositAmt());
-        futuresForceLine = futuresForceLine.add(user.getEnableFutAmt());
+
         agentUserListVO.setFuturesForceLine(futuresForceLine);
 
 
@@ -1535,61 +1018,16 @@
         userInfoVO.setIsActive(user.getIsActive());
         userInfoVO.setAuthMsg(user.getAuthMsg());
         userInfoVO.setVaildNumber(user.getVaildNumber());
+        BigDecimal exchangRate =  iSiteSettingService.getSiteSetting().getExchangeRate();
+        BigDecimal totalUsMoney = userAssetsServices.getAvailableBalance(EStockType.US.getCode(),user.getId());
+        BigDecimal totalMasMoney = userAssetsServices.getAvailableBalance(EStockType.IN.getCode(), user.getId())
+                .divide(exchangRate,BigDecimal.ROUND_CEILING).setScale(2,
+                RoundingMode.UP);
 
 
-        userInfoVO.setTradingAmount(user.getTradingAmount());
-
-        userInfoVO.setEnableAmt(user.getEnableAmt());
-        userInfoVO.setEnableAmtToUsdt(user.getEnableAmt().
-                divide(siteSetting.getExchangeRate()).
-                setScale(2, BigDecimal.ROUND_DOWN).toString());
-
-        PositionVO positionVO = this.iUserPositionService.findUserPositionAllProfitAndLose(user.getId(), EStockType.IN.getCode());
-        userInfoVO.setAllFreezAmt(positionVO.getAllFreezAmt());
-        userInfoVO.setAllFreezAmtToUsdt(positionVO.getAllFreezAmt()
-                .divide(siteSetting.getExchangeRate()).
-                setScale(2, BigDecimal.ROUND_DOWN).toString());
-        BigDecimal allProfitAndLose = positionVO.getAllProfitAndLose();
-
-        // 卢比股票的盈利
-        userInfoVO.setAllProfitAndLose(allProfitAndLose);
-        userInfoVO.setAllProfitAndLoseToUsdt(allProfitAndLose.
-                divide(siteSetting.getExchangeRate()).
-                setScale(2, BigDecimal.ROUND_DOWN).toString());
-
-
-
-        BigDecimal userAllAmt = user.getUserAmt();
-        userAllAmt = userAllAmt.add(allProfitAndLose);
-        userInfoVO.setUserAmt(userAllAmt);
-        userInfoVO.setUserAmtToUsdt(user.getUserAmt().
-                divide(siteSetting.getExchangeRate()).
-                setScale(2, BigDecimal.ROUND_DOWN).toString());
-
-
-        PositionVO usPositionVO = this.iUserPositionService.findUserPositionAllProfitAndLose(user.getId(), EStockType.US.getCode());
-        userInfoVO.setUsAllFreezAmt(usPositionVO.getAllFreezAmt());
-        BigDecimal usAllProfitAndLose = positionVO.getAllProfitAndLose();
-        userInfoVO.setUsAllProfitAndLose(usAllProfitAndLose);
-        userInfoVO.setAllProfitAndLoseToUsdt(usAllProfitAndLose.
-                divide(siteSetting.getExchangeRate()).
-                setScale(2, BigDecimal.ROUND_DOWN).toString());
-
-        BigDecimal userAllIndexAmt = user.getUserIndexAmt();
-        userAllIndexAmt = userAllIndexAmt.add(usAllProfitAndLose);
-        userInfoVO.setUserIndexAmt(userAllIndexAmt);
-        userInfoVO.setEnableIndexAmt(user.getEnableIndexAmt());
-
-        BigDecimal totleAssets = user.getUserAmt().
-                divide(siteSetting.getExchangeRate()).
-                setScale(2, BigDecimal.ROUND_DOWN)
-                .add(user.getUserIndexAmt());
-        userInfoVO.setTotalAssets(totleAssets.setScale(2).toString());
-
-
-
-
-
+        userInfoVO.setMasTotalAssets(totalMasMoney.setScale(2).toString());
+        userInfoVO.setUsTotalAssets(totalUsMoney.setScale(2).toString());
+        userInfoVO.setTotalAssets((totalUsMoney.add(totalMasMoney)).setScale(2).toString());
         return userInfoVO;
     }
 

--
Gitblit v1.9.3