AbstractCusDeclareBiz.java 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package com.emato.cuspay.biz.wx;
  2. import com.emato.cuspay.biz.CuspayBiz;
  3. import com.emato.cuspay.entity.merch.MerchPayCfg;
  4. import com.emato.cuspay.service.MerchPaymentService;
  5. import com.google.common.collect.Maps;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import javax.annotation.PostConstruct;
  8. import java.util.List;
  9. import java.util.Map;
  10. /**
  11. * 加载缓存
  12. * @author zx
  13. * @version 1.0
  14. * 2018-05-23 10:00
  15. */
  16. public abstract class AbstractCusDeclareBiz implements CuspayBiz {
  17. @Autowired
  18. private MerchPaymentService paymentService;
  19. //商户支付信息缓存
  20. private Map<String, MerchPayCfg> payCaches = Maps.newHashMap();
  21. //重新加载缓存
  22. @PostConstruct
  23. private void reloadPayCaches() {
  24. if (this.paymentService == null)
  25. throw new NullPointerException("paymentService is null");
  26. List<MerchPayCfg> list = this.paymentService.loadMerchPayCfg();
  27. if (list != null && !list.isEmpty()) {
  28. list.forEach(cfg ->{
  29. payCaches.put(cfg.getAppid(), cfg);
  30. });
  31. }
  32. }
  33. //获取商户支付数据
  34. protected MerchPayCfg getMerchPayCfgCache(String sn) {
  35. MerchPayCfg merchPayCfg = payCaches.get(sn);
  36. if(merchPayCfg == null) {
  37. this.reloadPayCaches();
  38. return payCaches.get(sn);
  39. }
  40. return merchPayCfg;
  41. }
  42. public MerchPaymentService getPaymentService() {
  43. return paymentService;
  44. }
  45. public void setPaymentService(MerchPaymentService paymentService) {
  46. this.paymentService = paymentService;
  47. }
  48. }