init
This commit is contained in:
@@ -4,16 +4,17 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.ijpay.alipay.AliPayApiConfig;
|
||||
import com.ijpay.alipay.AliPayApiConfigKit;
|
||||
import com.ruoyi.cai.domain.PayConfig;
|
||||
import com.ruoyi.cai.domain.PayTotal;
|
||||
import com.ruoyi.cai.service.PayConfigService;
|
||||
import com.ruoyi.cai.service.PayTotalService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
@@ -21,6 +22,8 @@ public class PayConfigManager {
|
||||
private static final Map<Long,PayConfig> PAY_CONFIGS_MAP = new ConcurrentHashMap<>();
|
||||
@Autowired
|
||||
private PayConfigService payConfigService;
|
||||
@Autowired
|
||||
private PayTotalService payTotalService;
|
||||
|
||||
@PostConstruct
|
||||
public void init(){
|
||||
@@ -55,22 +58,50 @@ public class PayConfigManager {
|
||||
|
||||
public PayConfig getWxConfig(){
|
||||
Collection<PayConfig> values = PAY_CONFIGS_MAP.values();
|
||||
Map<String,PayConfig> using = new HashMap<>();
|
||||
for (PayConfig value : values) {
|
||||
if(PayTypeEnum.WX.getCode().equals(value.getPayType())){
|
||||
return value;
|
||||
using.put(value.getWxMcid(),value);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
if(using.isEmpty()){
|
||||
return null;
|
||||
}
|
||||
Set<String> aliAppIds = using.keySet();
|
||||
List<PayTotal> totals = payTotalService.listByWxMcid(aliAppIds);
|
||||
List<String> payIds = totals.stream()
|
||||
.sorted(Comparator.comparing(PayTotal::getMoney))
|
||||
.map(PayTotal::getPayId).collect(Collectors.toList());
|
||||
for (String aliAppId : aliAppIds) {
|
||||
if(!payIds.contains(aliAppId)){
|
||||
return using.get(aliAppId);
|
||||
}
|
||||
}
|
||||
return using.get(payIds.get(0));
|
||||
}
|
||||
|
||||
public PayConfig getAliConfig(){
|
||||
Collection<PayConfig> values = PAY_CONFIGS_MAP.values();
|
||||
Map<String,PayConfig> using = new HashMap<>();
|
||||
for (PayConfig value : values) {
|
||||
if(PayTypeEnum.ALI.getCode().equals(value.getPayType())){
|
||||
return value;
|
||||
using.put(value.getWxMcid(),value);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
if(using.isEmpty()){
|
||||
return null;
|
||||
}
|
||||
Set<String> wxMcidSet = using.keySet();
|
||||
List<PayTotal> totals = payTotalService.listByAliAppId(wxMcidSet);
|
||||
List<String> payIds = totals.stream()
|
||||
.sorted(Comparator.comparing(PayTotal::getMoney))
|
||||
.map(PayTotal::getPayId).collect(Collectors.toList());
|
||||
for (String wxMcid : wxMcidSet) {
|
||||
if(!payIds.contains(wxMcid)){
|
||||
return using.get(wxMcid);
|
||||
}
|
||||
}
|
||||
return using.get(payIds.get(0));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user