AbstractCusDeclareBiz.java 1.7 KB

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