新版仿ok交易所-后端
1
zj
2026-02-03 c7c4c4eec809cfd5e399edab50fae9bf68681585
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package com.yami.trading.api.controller;
 
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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;
import com.yami.trading.common.exception.YamiShopBindException;
import com.yami.trading.common.util.StringUtils;
import com.yami.trading.common.web.ResultObject;
import com.yami.trading.security.common.util.SecurityUtils;
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;
import org.springframework.web.bind.annotation.RestController;
 
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
 * @description: 合约账户
 * @create: 2025-01-08 17:57
 **/
@RestController
@RequestMapping("/api/wallet")
@Api(tags = "合约账户")
public class ApiCapitaltWalletWalletController {
 
    @Autowired
    SysUserService sysUserService;
 
    @Autowired
    CapitaltWalletService capitaltWalletService;
 
    @Autowired
    WalletService walletService;
 
    @Autowired
    private ContractOrderService contractOrderService;
    @Autowired
    WalletExtendService walletExtendService;
 
    @Qualifier("dataService")
    private DataService dataService;
 
 
    @ApiOperation(value = "划转")
    @PostMapping("/transfer.action")
    public Result updateWallt(@Valid TransferModel model) {
        String partyId = SecurityUtils.getCurrentUserId();
        if(!StringUtils.isNotEmpty(partyId)){
            throw new YamiShopBindException("请登录!");
        }
        return capitaltWalletService.updateWallt(partyId,model.getDeductAccount(),model.getReceiveAccount(),model.getMoneyRevise());
    }
 
    @ApiOperation(value = "获取资产")
    @PostMapping("/getassets.action")
    public Result updateWallt() {
        String partyId = SecurityUtils.getCurrentUserId();
        if(!StringUtils.isNotEmpty(partyId)){
            throw new YamiShopBindException("请登录!");
        }
        // 获取合约账户(contract)
        Wallet wallet = walletService.saveWalletByPartyId(partyId);
        // 获取资金账户(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().setScale(2,RoundingMode.DOWN));
        assets.put("amountToBeCovered",wallet.getAmountToBeCovered().setScale(2,RoundingMode.DOWN));
        assets.put("capital",capitaltWallet.getMoney().add(walletExtendMoney).setScale(2,RoundingMode.DOWN));
        assets.put("capitalUSDT",capitaltWallet.getMoney());//划转专用
        return Result.succeed(assets);
    }
}