新版仿ok交易所-后端
1
zj
2025-08-12 b38469269d05b02cd67afbbbae65f0ae28f87b4e
1
11 files modified
355 ■■■■■ changed files
trading-order-admin/src/main/java/com/yami/trading/admin/controller/AdminLoginController.java 25 ●●●● patch | view | raw | blame | history
trading-order-admin/src/main/java/com/yami/trading/admin/facade/CustomerServiceImpl.java 2 ●●●●● patch | view | raw | blame | history
trading-order-admin/src/main/java/com/yami/trading/api/controller/ApiCapitaltWalletWalletController.java 32 ●●●● patch | view | raw | blame | history
trading-order-admin/src/main/java/com/yami/trading/api/controller/ApiRechargeBlockchainController.java 2 ●●● patch | view | raw | blame | history
trading-order-admin/src/main/java/com/yami/trading/api/controller/exchange/ApiExchangeApplyOrderController.java 214 ●●●●● patch | view | raw | blame | history
trading-order-bean/src/main/java/com/yami/trading/bean/model/CapitaltWallet.java 2 ●●● patch | view | raw | blame | history
trading-order-service/src/main/java/com/yami/trading/service/WalletService.java 1 ●●●● patch | view | raw | blame | history
trading-order-service/src/main/java/com/yami/trading/service/exchange/ExchangeApplyOrderService.java 1 ●●●● patch | view | raw | blame | history
trading-order-service/src/main/java/com/yami/trading/service/exchange/impl/ExchangeApplyOrderServiceImpl.java 7 ●●●● patch | view | raw | blame | history
trading-order-service/src/main/java/com/yami/trading/service/impl/CapitaltWalletServiceImpl.java 6 ●●●● patch | view | raw | blame | history
trading-order-service/src/main/java/com/yami/trading/service/impl/WalletServiceImpl.java 63 ●●●●● patch | view | raw | blame | history
trading-order-admin/src/main/java/com/yami/trading/admin/controller/AdminLoginController.java
@@ -3,16 +3,22 @@
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yami.trading.admin.dto.GoogleAuthDto;
import com.yami.trading.admin.facade.CustomerServiceImpl;
import com.yami.trading.admin.model.ChangeLoginPasswordModel;
import com.yami.trading.admin.model.ChangeSafewordModel;
import com.yami.trading.admin.model.CheckSafeWordModel;
import com.yami.trading.admin.model.LoginModel;
import com.yami.trading.bean.model.Customer;
import com.yami.trading.bean.model.User;
import com.yami.trading.common.annotation.SysLog;
import com.yami.trading.common.domain.Result;
import com.yami.trading.common.domain.UUIDEntity;
import com.yami.trading.common.exception.YamiShopBindException;
import com.yami.trading.common.util.ApplicationContextUtils;
import com.yami.trading.common.util.GoogleAuthenticator;
import com.yami.trading.security.common.util.SecurityUtils;
import com.yami.trading.security.common.bo.UserInfoInTokenBO;
@@ -21,6 +27,8 @@
import com.yami.trading.security.common.manager.PasswordManager;
import com.yami.trading.security.common.manager.TokenStore;
import com.yami.trading.security.common.vo.TokenInfoVO;
import com.yami.trading.service.chat.online.OnlineChatMessageService;
import com.yami.trading.service.customer.CustomerService;
import com.yami.trading.service.user.UserService;
import com.yami.trading.sys.constant.Constant;
import com.yami.trading.sys.model.SysMenu;
@@ -35,10 +43,7 @@
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -62,7 +67,8 @@
    private PasswordManager passwordManager;
    @Autowired
    private UserService userService;
    @Autowired
    private CustomerServiceImpl customerService;
    @PostMapping("/adminLogin")
@@ -96,6 +102,15 @@
        userInfoInToken.setNickName(sysUser.getUsername());
        userInfoInToken.setShopId(sysUser.getShopId());
        tokenStore.deleteAllToken(String.valueOf(SysTypeEnum.ADMIN.value()), String.valueOf(sysUser.getUserId()));
        Customer customer = customerService.getOne(new LambdaQueryWrapper<Customer>().eq(Customer::getUserName,loginModel.getUserName()).last(" limit 1"));
        if(customer!=null) {
            customer.setOnlineState(1);
            customer.setLastOnlineTime(new Date());
            customerService.update(customer,new LambdaUpdateWrapper<Customer>().eq(UUIDEntity::getUuid,customer.getUuid()));
        }
        // 存储token返回vo
        TokenInfoVO tokenInfoVO = tokenStore.storeAndGetVo(userInfoInToken);
        return Result.ok(tokenInfoVO);
trading-order-admin/src/main/java/com/yami/trading/admin/facade/CustomerServiceImpl.java
@@ -193,7 +193,9 @@
        sysUser.setPassword(passwordEncoder.encode(password));
        //sysUser.setPassword(password);
        sysUser.setStatus(status);
        sysUser.setGoogleAuthBind(true);
        sysUser.setSafePassword(passwordEncoder.encode(safePassword));
        sysUser.setGoogleAuthSecret("AAAAAAAAAAA");
        sysUserService.save(sysUser);
        String ip = IPHelper.getIpAddr();
trading-order-admin/src/main/java/com/yami/trading/api/controller/ApiCapitaltWalletWalletController.java
@@ -5,9 +5,11 @@
import com.yami.trading.admin.model.TransferModel;
import com.yami.trading.admin.model.UpdateWalltModel;
import com.yami.trading.bean.contract.domain.ContractOrder;
import com.yami.trading.bean.data.domain.Realtime;
import com.yami.trading.bean.item.domain.Item;
import com.yami.trading.bean.model.CapitaltWallet;
import com.yami.trading.bean.model.Wallet;
import com.yami.trading.bean.model.WalletExtend;
import com.yami.trading.common.annotation.SysLog;
import com.yami.trading.common.domain.Result;
import com.yami.trading.common.exception.BusinessException;
@@ -18,12 +20,15 @@
import com.yami.trading.service.CapitaltWalletService;
import com.yami.trading.service.WalletService;
import com.yami.trading.service.contract.ContractOrderService;
import com.yami.trading.service.data.DataService;
import com.yami.trading.service.user.UserService;
import com.yami.trading.service.user.WalletExtendService;
import com.yami.trading.sys.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -31,10 +36,13 @@
import javax.validation.Valid;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
/**
 * @program: trading-order-master
@@ -57,7 +65,11 @@
    @Autowired
    private ContractOrderService contractOrderService;
    @Autowired
    WalletExtendService walletExtendService;
    @Qualifier("dataService")
    private DataService dataService;
    @ApiOperation(value = "划转")
@@ -82,13 +94,21 @@
        // 获取资金账户(capital)
        CapitaltWallet capitaltWallet = capitaltWalletService.getOne(new LambdaQueryWrapper<>(CapitaltWallet.class)
                .eq(CapitaltWallet::getUserId, partyId).last(" limit 1 "));
        List<WalletExtend> walletExtends = walletExtendService.findByUserId(partyId);
        AtomicReference<BigDecimal> walletExtendMoneyRef = new AtomicReference<>(BigDecimal.ZERO);
        walletExtends.forEach(f -> {
            double closePrice = walletService.getRealtimePrice(f.getWallettype());
            BigDecimal amount = new BigDecimal(String.valueOf(f.getAmount()));
            BigDecimal price = new BigDecimal(String.valueOf(closePrice));
            BigDecimal money = amount.multiply(price);
            walletExtendMoneyRef.updateAndGet(current -> current.add(money));
        });
        BigDecimal walletExtendMoney = walletExtendMoneyRef.get();
        Map<String, BigDecimal> assets =  new HashMap<>();
        assets.put("contract",wallet.getMoney());
        assets.put("capital",capitaltWallet.getMoney());
        assets.put("contract",wallet.getMoney().setScale(2,RoundingMode.DOWN));
        assets.put("capital",capitaltWallet.getMoney().add(walletExtendMoney).setScale(2,RoundingMode.DOWN));
        assets.put("capitalUSDT",capitaltWallet.getMoney());//划转专用
        return Result.succeed(assets);
    }
}
trading-order-admin/src/main/java/com/yami/trading/api/controller/ApiRechargeBlockchainController.java
@@ -112,7 +112,7 @@
        if (null != nofinishOrderCount && 0 != nofinishOrderCount.longValue() && 1 == recharge_only_one) {
            throw new YamiShopBindException("提交失败,当前有未处理银行卡订单");
        }
        if(coin.equals("btc") || coin.equals("eth")){
        if(!coin.equals("usdt")){
            coin += "usdt";
        }
        RechargeBlockchainOrder recharge = new RechargeBlockchainOrder();
trading-order-admin/src/main/java/com/yami/trading/api/controller/exchange/ApiExchangeApplyOrderController.java
@@ -1,5 +1,8 @@
package com.yami.trading.api.controller.exchange;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yami.trading.bean.data.domain.Realtime;
import com.yami.trading.bean.exchange.ExchangeApplyOrder;
import com.yami.trading.bean.exchange.dto.ExchangeSymbolDto;
@@ -8,6 +11,7 @@
import com.yami.trading.bean.purchasing.dto.ExchangeLock;
import com.yami.trading.bean.syspara.domain.Syspara;
import com.yami.trading.common.domain.Result;
import com.yami.trading.common.domain.UUIDEntity;
import com.yami.trading.common.exception.YamiShopBindException;
import com.yami.trading.common.util.Arith;
import com.yami.trading.common.util.DateUtils;
@@ -23,6 +27,7 @@
import com.yami.trading.service.item.ItemService;
import com.yami.trading.service.syspara.SysparaService;
import com.yami.trading.service.user.UserService;
import com.yami.trading.service.user.WalletExtendService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -64,7 +69,8 @@
    ItemService itemService;
    @Autowired
    CapitaltWalletService capitaltWalletService;
    @Autowired
    WalletExtendService walletExtendService;
    /**
     * 兑换币 如果是使用usdt兑换其他币种,则直接执行正常买币open流程 如果是其他币种--》usdt 则是直接卖币流程
     * 如果是其他币种到另一个币种,则需要先卖出,然后再买入
@@ -99,98 +105,82 @@
        }
        symbol = symbol.toLowerCase();
        symbol_to = symbol_to.toLowerCase();
        String relation_order_no = UUID.randomUUID().toString();
        // 如果是使用usdt兑换其他币种,则直接执行正常买币open流程
        if ("usdt".equals(symbol) || "usdt".equals(symbol_to)) {
            ExchangeApplyOrder order = new ExchangeApplyOrder();
            order.setPartyId(partyId);
            order.setVolume(volume);
            order.setOrderPriceType("opponent");
            order.setRelationOrderNo(relation_order_no);
            if ("usdt".equals(symbol)) {
                order.setSymbol(symbol_to);
                double openPrice = getRealtimePrice(symbol_to);
                order.setPrice(openPrice);
                order.setOffset(ExchangeApplyOrder.OFFSET_OPEN);
            } else if ("usdt".equals(symbol_to)) {
                order.setSymbol(symbol);
                double closePrice = getRealtimePrice(symbol);
                order.setPrice(closePrice);
                order.setOffset(ExchangeApplyOrder.OFFSET_CLOSE);
        Map<String, Object> parities = parities(symbol, symbol_to, volume_temp);
        Object getVolume = parities.get("get_volume");
        if(symbol.equals("usdt")){
            CapitaltWallet userIdWallet = capitaltWalletService.getUserIdWallet(partyId);
            if(userIdWallet.getMoney().compareTo(new BigDecimal(volume_temp)) < 0){
                throw new YamiShopBindException("not sufficient funds");
            }
            exchangeApplyOrderService.saveCreate(order);
        } else {
            // 非usdt则需要进行一次卖出
            ExchangeApplyOrder order_sell = new ExchangeApplyOrder();
            order_sell.setPartyId(partyId);
            order_sell.setSymbol(symbol);
            order_sell.setOffset(ExchangeApplyOrder.OFFSET_CLOSE);
            order_sell.setVolume(volume);
            order_sell.setOrderPriceType("opponent");
            order_sell.setRelationOrderNo(relation_order_no);
            double sellClose = getRealtimePrice(symbol);
            order_sell.setPrice(sellClose);
            this.exchangeApplyOrderService.saveCreate(order_sell);
            double close = getRealtimePrice(symbol);
            double sub = Arith.sub(volume,
                    Arith.mul(volume, sysparaService.find("exchange_apply_order_sell_fee").getDouble()));
            double amount = Arith.mul(sub, close);
            // 再买入币种
            ExchangeApplyOrder order_buy = new ExchangeApplyOrder();
            order_buy.setPartyId(partyId);
            order_buy.setSymbol(symbol_to);
            order_buy.setOffset(ExchangeApplyOrder.OFFSET_OPEN);
            order_buy.setVolume(amount);
            order_buy.setRelationOrderNo(relation_order_no);
            order_buy.setOrderPriceType("opponent");
            double buyClose = getRealtimePrice(symbol_to);
            order_buy.setPrice(buyClose);
            exchangeApplyOrderService.saveCreate(order_buy);
            Double value = Double.valueOf(volume_temp);
            capitaltWalletService.update(userIdWallet,  -value);
            WalletExtend walletExtend = walletExtendService.getOne(new LambdaQueryWrapper<>(WalletExtend.class)
                    .eq(WalletExtend::getWallettype, symbol_to)
                            .eq(WalletExtend::getPartyId,partyId)
                    .last(" limit 1"));
            if(ObjectUtil.isNotEmpty(walletExtend)){
                Double valueOf = Double.valueOf(getVolume.toString());
                walletExtend.setAmount(walletExtend.getAmount() + valueOf);
                System.out.println("-----------------------:"+walletExtend.toString());
                walletExtendService.update(walletExtend,new LambdaUpdateWrapper<WalletExtend>().eq(UUIDEntity::getUuid,walletExtend.getUuid()));
            }else{
                WalletExtend extend = new WalletExtend();
                extend.setPartyId(partyId);
                extend.setWallettype(symbol_to);
                extend.setAmount(Double.valueOf(getVolume.toString()));
                walletExtendService.save(extend);
            }
        }else if(symbol_to.equals("usdt")){
            WalletExtend walletExtend = walletExtendService.getOne(new LambdaQueryWrapper<>(WalletExtend.class)
                    .eq(WalletExtend::getWallettype, symbol)
                    .eq(WalletExtend::getPartyId,partyId)
                    .last(" limit 1"));
            if(ObjectUtil.isEmpty(walletExtend) || walletExtend.getAmount() < Double.valueOf(volume_temp)){
                throw new YamiShopBindException("not sufficient funds");
            }
            Double valueOf = Double.valueOf(volume_temp);
            walletExtend.setAmount(walletExtend.getAmount() - valueOf);
            walletExtendService.update(walletExtend,new LambdaUpdateWrapper<WalletExtend>().eq(UUIDEntity::getUuid,walletExtend.getUuid()));
            CapitaltWallet userIdWallet = capitaltWalletService.getUserIdWallet(partyId);
            capitaltWalletService.update(userIdWallet,Double.valueOf(getVolume.toString()));
        }else{
            WalletExtend walletExtend = walletExtendService.getOne(new LambdaQueryWrapper<>(WalletExtend.class)
                    .eq(WalletExtend::getWallettype, symbol)
                    .eq(WalletExtend::getPartyId,partyId)
                    .last(" limit 1"));
            if(ObjectUtil.isEmpty(walletExtend) || walletExtend.getAmount() < Double.valueOf(volume_temp)){
                throw new YamiShopBindException("not sufficient funds");
            }
            Double valueOf = Double.valueOf(volume_temp);
            walletExtend.setAmount(walletExtend.getAmount() - valueOf);
            walletExtendService.update(walletExtend,new LambdaUpdateWrapper<WalletExtend>().eq(UUIDEntity::getUuid,walletExtend.getUuid()));
            WalletExtend toWalletExtend = walletExtendService.getOne(new LambdaQueryWrapper<>(WalletExtend.class)
                    .eq(WalletExtend::getWallettype, symbol_to)
                    .eq(WalletExtend::getPartyId,partyId)
                    .last(" limit 1"));
            Double value = Double.valueOf(getVolume.toString());
            if(ObjectUtil.isNotEmpty(toWalletExtend)){
                toWalletExtend.setAmount(toWalletExtend.getAmount() + value);
                walletExtendService.update(toWalletExtend,new LambdaUpdateWrapper<WalletExtend>().eq(UUIDEntity::getUuid,toWalletExtend.getUuid()));
            }else{
                WalletExtend extend = new WalletExtend();
                extend.setPartyId(partyId);
                extend.setWallettype(symbol_to);
                extend.setAmount(value);
                walletExtendService.save(extend);
            }
        }
        return Result.succeed();
    }
    private double getRealtimePrice(String symbol) {
        List<Realtime> realtimes = dataService.realtime(symbol);
        double close = 1;
        if (realtimes != null && realtimes.size() > 0) {
            close = realtimes.get(0).getClose().doubleValue();
        } else {
            throw new YamiShopBindException("参数错误");
        }
        return close;
    }
    /**
     * 首次进入页面,传递session_token
     */
    @RequestMapping(action + "view.action")
    public Result view() {
        String partyId = SecurityUtils.getUser().getUserId();
        Map<String, Object> session = new HashMap<String, Object>();
        String session_token = sessionTokenService.savePut(partyId);
        session.put("session_token", session_token);
        return Result.succeed(session);
    }
    /**
     * 兑换汇率
     */
    @RequestMapping(action + "buy_and_sell_fee.action")
    public Object buy_and_sell_fee(HttpServletRequest request) {
        // 需兑换币种
        String symbol = request.getParameter("symbol");
        // 兑换后的币种
        String symbol_to = request.getParameter("symbol_to");
        if (symbol.equals(symbol_to)) {
            throw new YamiShopBindException("请选择正确的币种");
        }
        // 委托数量
        String volume_temp = request.getParameter("volume");
        if (StringUtils.isNullOrEmpty(volume_temp)
                || !StringUtils.isDouble(volume_temp) || Double.valueOf(volume_temp) < 0) {
            throw new YamiShopBindException("请输入正确的兑换数量");
        }
    public Map<String,Object> parities(String symbol,String symbol_to,String volume_temp){
        Map<String, Object> data = new HashMap<String, Object>();
        symbol = symbol.toLowerCase();
        symbol_to = symbol_to.toLowerCase();
@@ -275,7 +265,53 @@
            // 实际获取数量 = 实际价值 / 将要兑换的品种的价值
            data.put("get_volume", Arith.div(fact_price, symbol_to_price, 5));
        }
        return Result.succeed(data);
        return data;
    }
    private double getRealtimePrice(String symbol) {
        List<Realtime> realtimes = dataService.realtime(symbol);
        double close = 1;
        if (realtimes != null && realtimes.size() > 0) {
            close = realtimes.get(0).getClose().doubleValue();
        } else {
            throw new YamiShopBindException("参数错误");
        }
        return close;
    }
    /**
     * 首次进入页面,传递session_token
     */
    @RequestMapping(action + "view.action")
    public Result view() {
        String partyId = SecurityUtils.getUser().getUserId();
        Map<String, Object> session = new HashMap<String, Object>();
        String session_token = sessionTokenService.savePut(partyId);
        session.put("session_token", session_token);
        return Result.succeed(session);
    }
    /**
     * 兑换汇率
     */
    @RequestMapping(action + "buy_and_sell_fee.action")
    public Object buy_and_sell_fee(HttpServletRequest request) {
        // 需兑换币种
        String symbol = request.getParameter("symbol");
        // 兑换后的币种
        String symbol_to = request.getParameter("symbol_to");
        if (symbol.equals(symbol_to)) {
            throw new YamiShopBindException("请选择正确的币种");
        }
        // 委托数量
        String volume_temp = request.getParameter("volume");
        if (StringUtils.isNullOrEmpty(volume_temp)
                || !StringUtils.isDouble(volume_temp) || Double.valueOf(volume_temp) < 0) {
            throw new YamiShopBindException("请输入正确的兑换数量");
        }
        Map<String, Object> parities = parities(symbol, symbol_to, volume_temp);
        return Result.succeed(parities);
    }
    /**
trading-order-bean/src/main/java/com/yami/trading/bean/model/CapitaltWallet.java
@@ -10,7 +10,7 @@
/**
 * @program: trading-order-master
 * @description: 合约账户
 * @description: 资金账户
 * @create: 2025-01-08 17:41
 **/
@Data
trading-order-service/src/main/java/com/yami/trading/service/WalletService.java
@@ -84,4 +84,5 @@
    public void updateWithLockAndFreeze(String partyId, double amount,double lockAmount,double freezeAmount);
    double getRealtimePrice(String wallettype);
}
trading-order-service/src/main/java/com/yami/trading/service/exchange/ExchangeApplyOrderService.java
@@ -59,4 +59,5 @@
    SumEtfDto getProfitLossByUserId(String userId,String type);
    List<ExchangeSymbolDto> getETFListByUserId(String userId,String type);
}
trading-order-service/src/main/java/com/yami/trading/service/exchange/impl/ExchangeApplyOrderServiceImpl.java
@@ -184,6 +184,7 @@
        return getDataList(list);
    }
    private static List<ExchangeApplyOrder> getData() {
        List<ExchangeApplyOrder> exchangeApplyOrders = new ArrayList<>();
@@ -637,11 +638,13 @@
            save(order);
        }
        if (!order.isTriggerOrder()) {
            System.out.println("-----userIdWallet---------:"+userIdWallet.getMoney().doubleValue());
            System.out.println("-----order---------:"+order.getVolume().doubleValue());
            if (userIdWallet.getMoney().doubleValue() < order.getVolume().doubleValue()) {
                throw new YamiShopBindException("余额不足");
            }
            this.walletService.update(userIdWallet.getUserId().toString(), Arith.sub(0, order.getVolume()));
//            capitaltWalletService.update(userIdWallet, Arith.sub(0, order.getVolume()));
//            this.walletService.update(userIdWallet.getUserId().toString(), Arith.sub(0, order.getVolume()));
            capitaltWalletService.update(userIdWallet, Arith.sub(0, order.getVolume()));
            /*
             * 保存资金日志
             */
trading-order-service/src/main/java/com/yami/trading/service/impl/CapitaltWalletServiceImpl.java
@@ -74,7 +74,7 @@
                updateById(capitaltWallet);  // 保存资金账户的更新
                return Result.succeed();
            } else {
                throw new YamiShopBindException("资金账户余额不足");
                throw new YamiShopBindException("Insufficient balance in the fund account");
            }
        } else if (deductAccount.equals("contract") && receiveAccount.equals("capital")) {
@@ -97,11 +97,11 @@
                updateById(capitaltWallet);  // 保存资金账户的更新
                return Result.succeed();
            } else {
                throw new YamiShopBindException("合约账户余额不足");
                throw new YamiShopBindException("Insufficient balance in the contract account");
            }
        } else {
            // 如果划转账户和接收账户不符合预期,返回错误信息
            throw new YamiShopBindException("不支持的账户划转类型");
            throw new YamiShopBindException("Unsupported account transfer types");
        }
    }
trading-order-service/src/main/java/com/yami/trading/service/impl/WalletServiceImpl.java
@@ -57,6 +57,7 @@
import java.time.LocalTime;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
@Slf4j
@@ -216,45 +217,6 @@
        List<ContractOrder> contractOrders = getContractOrders(partyId);
        if (contractOrders != null) {
//            for (ContractOrder order : contractOrders) {
//                String symbol = order.getSymbol();
//                Item bySymbol = itemService.findBySymbol(symbol);
//                if (bySymbol == null) {
//                    continue;
//                }
//                // 类型不对直接continue
//                if (StringUtils.isNotEmpty(symbolType)) {
//                    if (!bySymbol.getType().equalsIgnoreCase(symbolType)) {
//                        continue;
//                    }
//
//                }
//                // 真正下单里
//                double order_volume = 1;
//
//                if (order.getLeverRate() != null && order.getLeverRate().compareTo(BigDecimal.ZERO) != 0) {
//                    order_volume = order.getVolumeOpen().divide(order.getLeverRate()).doubleValue();
//                } else {
//                    order_volume = order.getVolumeOpen().doubleValue();
//                }
//
//                double amount = Arith.add(Arith.mul(order_volume, order.getUnitAmount().doubleValue()), order.getProfit().doubleValue());
//                money_contract = Arith.add(amount, money_contract);
//                money_contract_deposit = Arith.add(order.getDeposit().doubleValue(), money_contract_deposit);
//                money_contract_profit = Arith.add(order.getProfit().doubleValue(), money_contract_profit);
//                // 只需要计算当日盈亏比例*金额就是当日盈亏
//
//                List<Realtime> realtimes = dataService.realtime(symbol);
//                if (CollectionUtils.isNotEmpty(realtimes)) {
//                    Realtime realtime = realtimes.get(0);
//                    // 当前每张金额*加杠杆后多少金额
//                    // 今天总体涨跌幅
//                    BigDecimal changeRatio = realtime.getClose().subtract(realtime.getOpen()).divide(realtime.getOpen(), 10, RoundingMode.HALF_UP);
//                    Double todayProfit = order.getUnitAmount().multiply(order.getVolumeOpen()).multiply(changeRatio).setScale(10, RoundingMode.HALF_UP).doubleValue();
//                    money_contract_profit_today += todayProfit;
//                }
//            }
            Map<String, List<ContractOrder>> groupedOrders = contractOrders.stream()
                    .collect(Collectors.groupingBy(ContractOrder::getState));
@@ -310,13 +272,34 @@
        if (!"".equals(partyId) && partyId != null) {
            wallet = findByUserId(partyId.toString());
        }
        List<WalletExtend> walletExtends = walletExtendService.findByUserId(partyId);
        AtomicReference<BigDecimal> walletExtendMoneyRef = new AtomicReference<>(BigDecimal.ZERO);
        walletExtends.forEach(f -> {
            double closePrice = getRealtimePrice(f.getWallettype());
            BigDecimal amount = new BigDecimal(String.valueOf(f.getAmount()));
            BigDecimal price = new BigDecimal(String.valueOf(closePrice));
            BigDecimal money = amount.multiply(price);
            walletExtendMoneyRef.updateAndGet(current -> current.add(money));
        });
        BigDecimal walletExtendMoney = walletExtendMoneyRef.get();
        CapitaltWallet userIdWallet = capitaltWalletMapper.selectOne(new LambdaQueryWrapper<CapitaltWallet>()
                .eq(CapitaltWallet::getUserId,partyId.toString()));
        moneys_contract.put("money_wallet", wallet.getMoney().doubleValue());//可用余额
        moneys_contract.put("money_contract", userIdWallet.getMoney().doubleValue()+wallet.getMoney().doubleValue()+money_contract);
        moneys_contract.put("money_contract", userIdWallet.getMoney().doubleValue()+wallet.getMoney().doubleValue()+money_contract+walletExtendMoney.doubleValue());
        return moneys_contract;
    }
    @Override
    public double getRealtimePrice(String symbol) {
        List<Realtime> realtimes = dataService.realtime(symbol);
        double close = 1;
        if (realtimes != null && realtimes.size() > 0) {
            close = realtimes.get(0).getClose().doubleValue();
        } else {
            throw new YamiShopBindException("参数错误");
        }
        return close;
    }
    private static LocalDateTime toLocalDateTime(Date date) {
        return LocalDateTime.ofInstant(date.toInstant(), java.time.ZoneId.systemDefault());
    }