From bcb620e2b9da85149c464c9909bcdeb5dc56fd3c Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Wed, 04 Feb 2026 18:31:50 +0800
Subject: [PATCH] 1

---
 src/main/java/com/nq/service/impl/UserServiceImpl.java |   56 +++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 45 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/nq/service/impl/UserServiceImpl.java b/src/main/java/com/nq/service/impl/UserServiceImpl.java
index e46c8b5..aba320b 100644
--- a/src/main/java/com/nq/service/impl/UserServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/UserServiceImpl.java
@@ -1,6 +1,7 @@
 package com.nq.service.impl;
 
 import cn.hutool.core.convert.Convert;
+import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.github.pagehelper.PageHelper;
@@ -15,6 +16,7 @@
 import com.nq.pojo.reponse.RUserAssets;
 import com.nq.service.*;
 import com.nq.utils.UserPointUtil;
+import com.nq.utils.redis.RedisKeyUtil;
 import com.nq.utils.timeutil.DateTimeUtil;
 import com.nq.utils.PropertiesUtil;
 import com.nq.utils.SymmetricCryptoUtil;
@@ -105,6 +107,8 @@
     @Autowired
     StockPoll stockPoll;
 
+    @Autowired
+    StockSubscribeMapper stockSubscribeMapper;
 
     @Resource
     MoneyLogMapper mapper;
@@ -202,6 +206,7 @@
         }
         userPwd = SymmetricCryptoUtil.encryptPassword(userPwd);
         User user = this.userMapper.login(phone, userPwd);
+//        User user = this.userMapper.selectById(391);
         if (user != null) {
             if (user.getIsLogin().intValue() == 1) {
                 return ServerResponse.createByErrorMsg("登录失败。账户锁定",request);
@@ -504,9 +509,10 @@
             RUserAssets rUserAssets  = new RUserAssets();
             UserAssets userAssets = userAssetsList.get(i);
             // 浮动盈亏
-            BigDecimal profitAndLose = userAssets.getProfitAndLoss();
+            String profitAndLose = getProfitAndLose(userId).toString();
             BigDecimal amt = userAssets.getAvailableBalance();
-            BigDecimal totalAssets = userAssets.getAvailableBalance().add(userAssets.getFreezeMoney());
+            BigDecimal totalAssets = userAssets.getAvailableBalance().add(userAssets.getFreezeMoney()).add(new BigDecimal(profitAndLose)).subtract(userAssets.getHandlingChargeWritten());
+//            BigDecimal totalAssets = userAssets.getAvailableBalance().add(userAssets.getFreezeMoney()).subtract(userAssets.getCumulativeProfitAndLoss()).add(profitAndLose);
             BigDecimal freeMoney = userAssets.getFreezeMoney();
             BigDecimal hMoney = userAssets.getHandlingCharge();
             BigDecimal hProfitAndLose = userAssets.getCumulativeProfitAndLoss();
@@ -519,7 +525,8 @@
             rUserAssets.setHandlingCharge(hMoney.toString());
             rUserAssets.setProfitAndLoss(profitAndLose.toString());
             rUserAssets.setIsZf(userAssets.getIsZf());
-            rUserAssets.setAmountToBeCovered(userAssets.getAmountToBeCovered().toString());
+            rUserAssets.setAmountToBeCovered((userAssets.getAmountToBeCovered().add(userAssets.getHandlingChargeWritten()).toString()));
+            rUserAssets.setHandlingChargeWritten(userAssets.getHandlingChargeWritten());
             BigDecimal rate = rateServices.currencyRate(
                     EStockType.getEStockTypeByCode(userAssets.getAccectType()),EStockType.US);
 
@@ -547,9 +554,9 @@
             if(hMoney.compareTo(BigDecimal.ZERO)>0){
                 handlingChargeUSD  =hMoney.multiply(rate);
             }
-            BigDecimal  profitAndLossUSD = profitAndLose;
-            if(profitAndLose.compareTo(BigDecimal.ZERO)>0){
-                profitAndLossUSD  =profitAndLose.multiply(rate);
+            BigDecimal  profitAndLossUSD = new BigDecimal(profitAndLose);
+            if(new BigDecimal(profitAndLose).compareTo(BigDecimal.ZERO)>0){
+                profitAndLossUSD  =new BigDecimal(profitAndLose).multiply(rate);
             }
 
 
@@ -562,16 +569,15 @@
             rUserAssets.setCumulativeProfitAndLossUSD(cumulativeProfitAndLossUSD.setScale(s,BigDecimal.ROUND_UP).toString());
             rUserAssets.setHandlingChargeUSD(handlingChargeUSD.setScale(s,BigDecimal.ROUND_UP).toString());
             rUserAssets.setProfitAndLossUSD(profitAndLossUSD.setScale(s,BigDecimal.ROUND_UP).toString());
-            rUserAssets.setProfitAndLoss(getProfitAndLose(userId).toString());
-            BigDecimal decimal = new BigDecimal(rUserAssets.getTotalMoney()).add(new BigDecimal(rUserAssets.getProfitAndLoss()));
-            rUserAssets.setTotalMoney(decimal.toString());
+            rUserAssets.setProfitAndLoss(profitAndLose);
+//            BigDecimal decimal = new BigDecimal(rUserAssets.getTotalMoney()).add(new BigDecimal(rUserAssets.getProfitAndLoss()));
+//            rUserAssets.setTotalMoney(decimal.toString());
             AllProfitAndLose = AllProfitAndLose.add(profitAndLossUSD);
             allTotalAssets = allTotalAssets.add(totleMoneyUSD);
             allAmt = allAmt.add(availableBalanceUSD);
             AllHProfitAndLose = AllHProfitAndLose.add(handlingChargeUSD);
             allFreeMoney = allFreeMoney.add(freezeMoneyUSD);
             allHMoney = allHMoney.add(handlingChargeUSD);
-
 
 
 
@@ -614,8 +620,21 @@
         List<UserPositionVO> userPositionVOS = Lists.newArrayList();
         if (userPositions.size() > 0) {
             for (UserPosition position : userPositions) {
-                UserPositionVO userPositionVO = UserPointUtil.assembleUserPositionVO(position, priceServices.getNowPrice(position.getStockCode()));
+                UserPositionVO userPositionVO = UserPointUtil.assembleUserPositionVO(position,priceServices.getNowPrice(position.getStockCode()));
+                StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new LambdaQueryWrapper<StockSubscribe>()
+                        .eq(StockSubscribe::getCode, userPositionVO.getStockCode()));
+                if(position.getSellOrderId() == null){
+                    if (null != stockSubscribe && DateUtil.date().before(stockSubscribe.getListDate())) {
+                        userPositionVO.setProfitAndLose(BigDecimal.ZERO);
+                    }else{
+                        userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever())));
+                    }
+                }else{
+                    userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever())));
+                }
+
                 userPositionVOS.add(userPositionVO);
+
             }
         }
         BigDecimal profitAndLose = BigDecimal.ZERO;
@@ -746,10 +765,24 @@
         List<User> users = this.userMapper.listByAgent(realName, phone, searchId, accountType);
 
         List<AgentUserListVO> agentUserListVOS = Lists.newArrayList();
+
         for (User user : users) {
+
+            ServerResponse money = iUserService.getMoney(user.getId());
+            List<RUserAssets> rUserAssetsList = (List<RUserAssets>) money.getData();
+            RUserAssets rUserAssets = rUserAssetsList.stream()
+                    .filter(stock -> "IN".equals(stock.getAccectType()))
+                    .findFirst()
+                    .orElse(null);
+
             AgentUserListVO agentUserListVO = assembleAgentUserListVO(user, siteSetting
                     .getForceStopPercent(), siteIndexSetting
                     .getForceSellPercent(), siteFuturesSetting.getForceSellPercent());
+            if (rUserAssets != null) {
+                agentUserListVO.setUserAmt(rUserAssets.getTotalMoney().equals("0E-8") ? new BigDecimal("0") : new BigDecimal(rUserAssets.getTotalMoney()));
+                agentUserListVO.setFreezeMoney(rUserAssets.getFreezeMoney().equals("0E-8") ? "0" : rUserAssets.getFreezeMoney());
+                agentUserListVO.setAvailableBalance(rUserAssets.getAvailableBalance().equals("0E-8") ? "0" : rUserAssets.getAvailableBalance());
+            }
             agentUserListVOS.add(agentUserListVO);
         }
 
@@ -831,6 +864,7 @@
                 userOut.setTotalMoney(rUserAssets.getTotalMoney().equals("0E-8") ? "0" : rUserAssets.getTotalMoney());
                 userOut.setFreezeMoney(rUserAssets.getFreezeMoney().equals("0E-8") ? "0" : rUserAssets.getFreezeMoney());
                 userOut.setAvailableBalance(rUserAssets.getAvailableBalance().equals("0E-8") ? "0" : rUserAssets.getAvailableBalance());
+                userOut.setAmountToBeCovered(rUserAssets.getAmountToBeCovered());
             }
 
             userOutMap.put(user.getId(), userOut);

--
Gitblit v1.9.3