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 implements C2cPaymentMethodService { @Autowired RedisTemplate redisTemplate; @Autowired ExchangeRateService exchangeRateService; @Autowired SysparaService sysparaService; @Override public C2cPaymentMethod get(String id) { return getById(id); } @Override public Page listPage(Page page, String loginPartyId, String userCode, String methodType, String methodName, int type) { return baseMapper.listPage(page,loginPartyId,userCode,methodType,methodName,type); } @Override public Map getByPartyId(String partyId) { List c2cPaymentMethodList= list(Wrappers.query().lambda().eq(C2cPaymentMethod::getPartyId,partyId)); Map map=new HashMap<>(); for (C2cPaymentMethod c2cPaymentMethod:c2cPaymentMethodList){ map.put(c2cPaymentMethod.getUuid(),c2cPaymentMethod); } return map; } @Override public Map getByC2CPartyId(String partyId) { return getByPartyIdAndType(partyId,"2"); } public Map getByPartyIdAndType(String partyId, String type) { List c2cPaymentMethodList= list(Wrappers.query().lambda() .eq(C2cPaymentMethod::getPartyId, partyId) .eq(C2cPaymentMethod::getType, type)); Map map = new HashMap<>(); for (C2cPaymentMethod c2cPaymentMethod : c2cPaymentMethodList) { map.put(c2cPaymentMethod.getUuid(), c2cPaymentMethod); } return map; } @Override public Map getByBankCardPartyId(String partyId) { return getByPartyIdAndType(partyId,"1"); } @Override public String saveData(C2cPaymentMethod method) { save(method); // redisTemplate.opsForValue().set(RedisKeys.C2C_PAYMENT_METHOD_ID + method.getUuid(), method); // Map map = (Map) redisTemplate.opsForValue().get(RedisKeys.C2C_PAYMENT_METHOD_PARTY_ID + method.getPartyId()); // if (null == map) { // map = new ConcurrentHashMap(); // } // 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 getMethodConfigListByPartyId(String partyId) { List res = new ArrayList(); Map 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 getCurrencyMap() { // 获取 C2C支付币种配置 Map curMap = this.getC2cSyspara("bank_card_currency"); if (null == curMap) { curMap = new HashMap(); } Map currencyMap = new HashMap(); List 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 getC2cSyspara(String syspara) { if ("bank_card_currency".equals(syspara)) { // 银行卡支付币种配置 Map acMap = new HashMap(); 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 aetMap = new HashMap(); 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(); } }