123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package com.emato.cuspay.wx.declare;
- import com.emato.cuspay.base.merch.MerchCusService;
- import com.emato.cuspay.base.merch.MerchPaymentService;
- import com.emato.cuspay.dto.merch.MerchCusCfg;
- import com.emato.cuspay.dto.merch.MerchNoti;
- import com.emato.cuspay.dto.merch.MerchPayCfg;
- import com.google.common.collect.Maps;
- import org.springframework.beans.BeansException;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.config.BeanPostProcessor;
- import javax.annotation.PostConstruct;
- import java.util.List;
- import java.util.Map;
- /**
- * @author zx
- * @version 1.0
- * 2018-05-18 14:21
- */
- public abstract class AbstractCusDeclare implements CusDeclare{
- @Autowired
- private MerchPaymentService paymentService;
- //商户支付信息缓存
- private Map<String, MerchPayCfg> payCaches = Maps.newHashMap();
- //重新加载缓存
- @PostConstruct
- private void reloadPayCaches() {
- if (this.paymentService == null)
- throw new NullPointerException("paymentService is null");
- List<MerchPayCfg> list = this.paymentService.loadMerchPayCfg();
- if (list != null && !list.isEmpty()) {
- list.forEach(cfg ->{
- payCaches.put(cfg.getMerchSn(), cfg);
- });
- }
- }
- //获取商户支付数据
- protected MerchPayCfg getMerchPayCfgCache(String sn) {
- MerchPayCfg merchPayCfg = payCaches.get(sn);
- if(merchPayCfg == null) {
- this.reloadPayCaches();
- return payCaches.get(sn);
- }
- return merchPayCfg;
- }
- public MerchPaymentService getPaymentService() {
- return paymentService;
- }
- public void setPaymentService(MerchPaymentService paymentService) {
- this.paymentService = paymentService;
- }
- }
|