新版仿ok交易所-后端
1
zyy
2026-03-09 4164ba59cb88d33b191f42d3bef122f6f7af6312
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
package com.yami.trading.service.rate;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yami.trading.bean.rate.domain.ExchangeRate;
import com.yami.trading.common.exception.YamiShopBindException;
import com.yami.trading.common.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.trading.bean.rate.domain.UserRateConfig;
import com.yami.trading.dao.rate.UserRateConfigMapper;
 
/**
 * 用户汇率管理Service
 *
 * @author lucas
 * @version 2023-03-28
 */
@Service
@Transactional
public class UserRateConfigService extends ServiceImpl<UserRateConfigMapper, UserRateConfig> {
    @Autowired
    ExchangeRateService exchangeRateService;
 
    public void update(String rateId, String partyId) {
        ExchangeRate exchangeRate = exchangeRateService.getById(rateId);
        if (null == exchangeRate) {
            throw new YamiShopBindException("rate is null");
        }
        UserRateConfig userConfig = this.getByPartyId(partyId);
        if (userConfig == null) {
            userConfig = new UserRateConfig();
            userConfig.setPartyId(partyId);
        }
        userConfig.setCurrency(exchangeRate.getCurrency());
        saveOrUpdate(userConfig);
    }
 
    /**
     * 查询用户计价方式,如果没有配置,则返回默认的计价方式
     */
    public ExchangeRate findUserConfig(String partyId) {
        ExchangeRate exchangeRate = null;
        String user_default_currency = "USD";
        if (StringUtils.isNullOrEmpty(partyId)) {
            exchangeRate = exchangeRateService.findBy(ExchangeRate.IN, user_default_currency);
        } else {
            UserRateConfig userRateConfig = getByPartyId(partyId);
            if (userRateConfig == null) {
                exchangeRate = exchangeRateService.findBy(ExchangeRate.IN, user_default_currency);
            } else {
                exchangeRate = exchangeRateService.findBy(ExchangeRate.IN, userRateConfig.getCurrency());
            }
        }
        return exchangeRate;
    }
 
    public UserRateConfig getByPartyId(String partyId) {
        return getOne(Wrappers.<UserRateConfig>query().lambda().eq(UserRateConfig::getPartyId, partyId));
    }
}