新版仿ok交易所-后端
zj
2025-01-06 6e21cf6973aa1898259ddceda665f0f1b06272ab
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package com.yami.trading.service.c2c.impl;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.trading.bean.c2c.dto.C2cPaymentMethodDto;
import com.yami.trading.bean.model.C2cPaymentMethod;
import com.yami.trading.bean.rate.domain.ExchangeRate;
import com.yami.trading.common.constants.Constants;
import com.yami.trading.common.constants.RedisKeys;
import com.yami.trading.dao.c2c.C2cPaymentMethodMapper;
import com.yami.trading.service.c2c.C2cPaymentMethodService;
import com.yami.trading.service.rate.ExchangeRateService;
import com.yami.trading.service.syspara.SysparaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
 
@Service
public class C2cPaymentMethodServiceImpl extends ServiceImpl<C2cPaymentMethodMapper, C2cPaymentMethod>  implements C2cPaymentMethodService {
 
    @Autowired
    RedisTemplate redisTemplate;
 
    @Autowired
    ExchangeRateService exchangeRateService;
 
    @Autowired
    SysparaService sysparaService;
    @Override
    public C2cPaymentMethod get(String id) {
        return getById(id);
    }
 
    @Override
    public Page<C2cPaymentMethodDto> listPage(Page page, String loginPartyId, String userCode, String methodType, String methodName) {
        return baseMapper.listPage(page,loginPartyId,userCode,methodType,methodName);
    }
 
    @Override
    public Map<String, C2cPaymentMethod> getByPartyId(String partyId) {
       List<C2cPaymentMethod> c2cPaymentMethodList=  list(Wrappers.<C2cPaymentMethod>query().lambda().eq(C2cPaymentMethod::getPartyId,partyId));
         Map<String,C2cPaymentMethod> map=new HashMap<>();
        for (C2cPaymentMethod c2cPaymentMethod:c2cPaymentMethodList){
            map.put(c2cPaymentMethod.getUuid(),c2cPaymentMethod);
        }
        return map;
    }
 
 
    @Override
    public String saveData(C2cPaymentMethod method) {
        save(method);
//        redisTemplate.opsForValue().set(RedisKeys.C2C_PAYMENT_METHOD_ID + method.getUuid(), method);
//        Map<String, C2cPaymentMethod> map = (Map<String, C2cPaymentMethod>) redisTemplate.opsForValue().get(RedisKeys.C2C_PAYMENT_METHOD_PARTY_ID + method.getPartyId());
//        if (null == map) {
//            map = new ConcurrentHashMap<String, C2cPaymentMethod>();
//        }
//        map.put(method.getUuid(), method);
//        redisTemplate.opsForValue().set(RedisKeys.C2C_PAYMENT_METHOD_PARTY_ID + method.getPartyId(), map);
        return method.getUuid();
    }
 
    @Override
    public C2cPaymentMethod getC2cPaymentMethod(String id) {
        return getById(id);
    }
 
    @Override
    public List<C2cPaymentMethod> getMethodConfigListByPartyId(String partyId) {
 
        List<C2cPaymentMethod> res = new ArrayList<C2cPaymentMethod>();
 
        Map<String, C2cPaymentMethod> methodMap = this.getByPartyId(partyId);
        if (null == methodMap || 0 == methodMap.size()) {
            return res;
        }
 
        for (String key : methodMap.keySet()) {
            C2cPaymentMethod method = methodMap.get(key);
            if (null != method) {
                res.add(method);
            }
        }
 
        return res;
    }
 
    /**
     * 获取 支付币种Map
     */
    public Map<String, String> getCurrencyMap() {
 
        // 获取 C2C支付币种配置
        Map<String, String> curMap = this.getC2cSyspara("bank_card_currency");
        if (null == curMap) {
            curMap = new HashMap<String, String>();
        }
 
        Map<String, String> currencyMap = new HashMap<String, String>();
 
        List<ExchangeRate> exchangeRateList = exchangeRateService.findBy(Constants.OUT_OR_IN_DEFAULT);
        for (ExchangeRate er : exchangeRateList) {
            if (curMap.keySet().contains(er.getCurrency())) {
                currencyMap.put(er.getCurrency(), String.format("%s(%s)", er.getCurrency(), er.getName()));
            }
        }
        return currencyMap;
    }
 
 
 
    /*
     * 获取 银行卡支付币种配置、银行卡支付时效
     */
    public Map<String, String> getC2cSyspara(String syspara) {
 
        if ("bank_card_currency".equals(syspara)) {
 
            // 银行卡支付币种配置
            Map<String, String> acMap = new HashMap<String, String>();
            Object obj = sysparaService.find("bank_card_currency");
            if (null != obj) {
                String acStr = this.sysparaService.find("bank_card_currency").getSvalue().toString();
                String[] acArray = acStr.split("&&");
                for (int i = 0; i < acArray.length; i++) {
                    String[] ac = acArray[i].split("##");
                    acMap.put(ac[0], ac[1]);
                }
                return acMap;
            }
        } else if ("bank_card_expire_time".equals(syspara)) {
 
            // 银行卡支付时效
            Map<String, String> aetMap = new HashMap<String, String>();
            Object obj = this.sysparaService.find("bank_card_expire_time");
            if (null != obj) {
                String aetStr = this.sysparaService.find("bank_card_expire_time").getSvalue().toString();
                String[] aetArray = aetStr.split("&&");
                for (int i = 0; i < aetArray.length; i++) {
                    String[] aet = aetArray[i].split("##");
                    aetMap.put(aet[0], aet[1]);
                }
                return aetMap;
            }
        }
 
        return new HashMap<String, String>();
    }
}