1
zj
2024-11-10 a6754af1932bcc0dfe30c809d97111cd521d54f5
src/main/java/com/nq/service/impl/UserServiceImpl.java
@@ -1,5 +1,6 @@
package com.nq.service.impl;
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
@@ -34,13 +35,13 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import com.nq.vo.user.UserOut;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -100,7 +101,8 @@
    ISiteIndexSettingService iSiteIndexSettingService;
    @Autowired
    StockPoll stockPoll;
    @Autowired
    IUserService iUserService;
    @Resource
    MoneyLogMapper mapper;
@@ -200,6 +202,7 @@
                return ServerResponse.createByErrorMsg("登录失败。账户锁定",request);
            }
            userAssetsServices.assetsByTypeAndUserId(EStockType.JP.getCode(),user.getId());
//            userAssetsServices.assetsByTypeAndUserId(EStockType.US.getCode(),user.getId());
            this.iSiteLoginLogService.saveLog(user, request);
            return ServerResponse.createBySuccess(user);
        }
@@ -493,6 +496,13 @@
         *  总手续费
         * */
        BigDecimal allHMoney = BigDecimal.ZERO;
        /**
         *  总手续费
         * */
        BigDecimal amountToBeCovered = BigDecimal.ZERO;
        for (int i = 0; i <userAssetsList.size() ; i++) {
            RUserAssets rUserAssets  = new RUserAssets();
            UserAssets userAssets = userAssetsList.get(i);
@@ -514,7 +524,7 @@
            rUserAssets.setIsZf(userAssets.getIsZf());
            rUserAssets.setAmountToBeCovered(userAssets.getAmountToBeCovered().toString());
            BigDecimal rate = rateServices.currencyRate(
                    EStockType.getEStockTypeByCode(userAssets.getAccectType()),EStockType.US);
                    EStockType.getEStockTypeByCode(userAssets.getAccectType()),EStockType.JP);
           BigDecimal  availableBalanceUSD = amt;
           if(amt.compareTo(BigDecimal.ZERO)>0){
@@ -555,7 +565,7 @@
            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());
            rUserAssets.setProfitAndLoss(getProfitAndLose(userId,userAssets.getAccectType()).toString());
            BigDecimal decimal = new BigDecimal(rUserAssets.getTotalMoney()).add(new BigDecimal(rUserAssets.getProfitAndLoss()));
            rUserAssets.setTotalMoney(decimal.toString());
            AllProfitAndLose = AllProfitAndLose.add(profitAndLossUSD);
@@ -564,10 +574,7 @@
            AllHProfitAndLose = AllHProfitAndLose.add(handlingChargeUSD);
            allFreeMoney = allFreeMoney.add(freezeMoneyUSD);
            allHMoney = allHMoney.add(handlingChargeUSD);
            amountToBeCovered = amountToBeCovered.add(new BigDecimal(rUserAssets.getAmountToBeCovered()));
            rUserAssetsList.add(rUserAssets);
        }
@@ -591,17 +598,18 @@
        rUserAssets.setFreezeMoneyUSD(allFreeMoney.setScale(s,BigDecimal.ROUND_DOWN).toString());
        rUserAssets.setSymbol("$");
        rUserAssets.setSymbolCode("USD");
        rUserAssets.setAmountToBeCovered(amountToBeCovered.setScale(s,BigDecimal.ROUND_DOWN).toString());
        rUserAssetsList.add(rUserAssets);
        return ServerResponse.createBySuccess(rUserAssetsList);
    }
    public BigDecimal getProfitAndLose(Integer userId){
    public BigDecimal getProfitAndLose(Integer userId,String  accectType){
        List<UserPosition> userPositions;
        userPositions = userPositionMapper.
                findMyPositionByCodeAndSpell(userId,
                        "","",
                        0, "IN");
                        0, accectType);
        List<UserPositionVO> userPositionVOS = Lists.newArrayList();
@@ -800,11 +808,33 @@
    public ServerResponse listByAdmin(String realName, String phone, Integer agentId, Integer accountType, int pageNum, int pageSize, HttpServletRequest request) {
        PageHelper.startPage(pageNum, pageSize);
        List<User> users = this.userMapper.listByAdmin(realName, phone, agentId, accountType);
        PageInfo pageInfo = new PageInfo(users);
        List<UserOut> userOuts = new ArrayList<>();
        // 获取用户资产信息并构建返回结果
        Map<Integer, UserOut> userOutMap = new HashMap<>();
        for (User user : users) {
            ServerResponse money = iUserService.getMoney(user.getId());
            List<RUserAssets> rUserAssetsList = (List<RUserAssets>) money.getData();
            RUserAssets rUserAssets = rUserAssetsList.stream()
                    .filter(stock -> "ALL".equals(stock.getAccectType()))
                    .findFirst()
                    .orElse(null);
            UserOut userOut = Convert.convert(UserOut.class, user);
            if (rUserAssets != null) {
                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(new BigDecimal(rUserAssets.getAmountToBeCovered()));
            }
            userOutMap.put(user.getId(), userOut);
            userOuts.add(userOut);
        }
        PageInfo pageInfo = new PageInfo(users);
        pageInfo.setList(userOuts);
        return ServerResponse.createBySuccess(pageInfo);
    }