package com.yami.trading.service.user.impl; import cn.hutool.json.JSONUtil; import com.yami.trading.bean.model.Wallet; import com.yami.trading.bean.model.WalletExtend; import com.yami.trading.common.exception.YamiShopBindException; import com.yami.trading.common.util.StringUtils; import com.yami.trading.service.WalletService; import com.yami.trading.service.user.UserRecomService; import com.yami.trading.service.user.UserStatisticsService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; @Service @Slf4j public class UserStatisticsServiceImpl implements UserStatisticsService { @Autowired UserRecomService userRecomService; @Autowired WalletService walletService; @Override public List> getAssetsAll(String loginPartyId,String targetPartyId) { if (!StringUtils.isNullOrEmpty(loginPartyId)) { // List children = this.userRecomService.findChildren(loginPartyId); // if (children.size() == 0) { // return new ArrayList<>(); // } // if(!children.contains(targetPartyId)) throw new BusinessException("目标用户不属于登录人下级"); } Map moneyAll = walletService.getMoneyAll(targetPartyId); Map nameMap = getNameMap(); List> result = new LinkedList>(); log.info(JSONUtil.toJsonPrettyStr(moneyAll)+"============="); log.info(JSONUtil.toJsonPrettyStr(nameMap)+"============="); for(Map.Entry entry :nameMap.entrySet()) { if("money_trader".equals(entry.getKey())) { continue; } Map data = new HashMap(); data.put("name", entry.getValue()); data.put("value", moneyAll.get(entry.getKey())); result.add(data); } return result; } public Map getNameMap(){ Map data = new LinkedHashMap(); data.put("money_all_coin", "钱包资产折合[USDT]"); data.put("money_miner", "矿机"); data.put("money_finance", "理财"); data.put("money_contract", "永续合约"); data.put("money_futures", "交割合约"); data.put("money_fund", "基金"); data.put("money_coin", "币余额"); data.put("money_wallet", "钱包USDT"); // data.put("money_trader", "理财资产"); data.put("money_ico", "ico"); data.put("total", "总资产"); return data; } @Override public List> getWalletExtends(String loginPartyId, String targetPartyId) { // if (!StringUtils.isNullOrEmpty(loginPartyId)) { // List children = this.userRecomService.findChildren(loginPartyId); // if (children.size() == 0) { // return new ArrayList<>(); // } // if(!children.contains(targetPartyId)) throw new YamiShopBindException("目标用户不属于登录人下级"); // } List findExtend = walletService.findExtend(targetPartyId); List> result = new LinkedList>(); if(ObjectUtils.isNotEmpty(findExtend)) { for(WalletExtend we : findExtend) { if(ObjectUtils.isNotEmpty(we)) { Map data = new HashMap(); if ("USDT_USER".equals(we.getWallettype()) || "ETH_DAPP".equals(we.getWallettype()) || "USDT_DAPP".equals(we.getWallettype()) || "ETH_USER".equals(we.getWallettype())) { continue; } data.put("wallettype", we.getWallettype()); data.put("amount", new BigDecimal(we.getAmount()).setScale(8, RoundingMode.FLOOR).toPlainString()); data.put("lock_amount",null==we?0:new BigDecimal(we.getLockAmount()).setScale(8, RoundingMode.FLOOR).toPlainString() ); data.put("freeze_amount",null==we?0:new BigDecimal(we.getFreezeAmount()).setScale(8, RoundingMode.FLOOR).toPlainString() ); result.add(data); } } } Map data = new HashMap(); Wallet wallet = walletService.saveWalletByPartyId(targetPartyId); data.put("wallettype", "usdt"); data.put("amount",null==wallet?0:new BigDecimal(wallet.getMoney().doubleValue()).setScale(8, RoundingMode.FLOOR).toPlainString() ); data.put("lock_amount",null==wallet?0:wallet.getLockMoney().setScale(8, RoundingMode.FLOOR).toPlainString() ); data.put("freeze_amount",null==wallet?0:wallet.getFreezeMoney().setScale(8, RoundingMode.FLOOR).toPlainString() ); result.add(0,data); return result; } }