|
@@ -0,0 +1,109 @@
|
|
|
+package com.yonge.cooleshow.biz.dal.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.microsvc.toolkit.middleware.payment.common.api.PaymentServiceContext;
|
|
|
+import com.microsvc.toolkit.middleware.payment.impl.AdapayPaymentServicePlugin;
|
|
|
+import com.microsvc.toolkit.middleware.payment.properties.PayConfigProperties;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.PaymentMerchantConfig;
|
|
|
+import com.yonge.cooleshow.biz.dal.wrapper.PaymentMerchantConfigWrapper;
|
|
|
+import com.yonge.cooleshow.biz.dal.mapper.PaymentMerchantConfigMapper;
|
|
|
+import com.yonge.cooleshow.biz.dal.service.PaymentMerchantConfigService;
|
|
|
+
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 支付三方账户配置
|
|
|
+ * 2023-07-28 16:53:51
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class PaymentMerchantConfigServiceImpl extends ServiceImpl<PaymentMerchantConfigMapper, PaymentMerchantConfig> implements PaymentMerchantConfigService {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PayConfigProperties properties;
|
|
|
+
|
|
|
+ @PostConstruct
|
|
|
+ public void init(){
|
|
|
+ List<PaymentMerchantConfig> list = this.list();
|
|
|
+
|
|
|
+ if(CollectionUtils.isEmpty(list)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (PaymentMerchantConfig config : list) {
|
|
|
+ PayConfigProperties.AdapayPayConfig adapayPayConfig = new PayConfigProperties.AdapayPayConfig();
|
|
|
+ adapayPayConfig.setEnable(true);
|
|
|
+ adapayPayConfig.setAppId(config.getAppId());
|
|
|
+ adapayPayConfig.setPayType(config.getPaymentVendor());
|
|
|
+ adapayPayConfig.setMerchantId(config.getMerKey());
|
|
|
+ adapayPayConfig.setMerchantId(config.getApiKey());
|
|
|
+ adapayPayConfig.setPayNotifyUrl(properties.getPayNotifyUrl());
|
|
|
+ adapayPayConfig.setRefundNotifyUrl(properties.getRefundNotifyUrl());
|
|
|
+ adapayPayConfig.setKeyPublic(config.getRsaPublicKey());
|
|
|
+ adapayPayConfig.setKeyPrivate(config.getRsaPrivateKey());
|
|
|
+ adapayPayConfig.setSupportCreditCards(properties.getSupportCreditCards());
|
|
|
+ AdapayPaymentServicePlugin plugin = null;
|
|
|
+ try {
|
|
|
+ plugin = new AdapayPaymentServicePlugin(config.getPaymentVendor(), adapayPayConfig, false);
|
|
|
+ PaymentServiceContext.addPlugin(plugin);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("初始化支付插件失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询详情
|
|
|
+ * @param id 详情ID
|
|
|
+ * @return PaymentMerchantConfig
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PaymentMerchantConfig detail(Long id) {
|
|
|
+
|
|
|
+ return baseMapper.selectById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询
|
|
|
+ * @param page IPage<PaymentMerchantConfig>
|
|
|
+ * @param query PaymentMerchantConfigWrapper.PaymentMerchantConfigQuery
|
|
|
+ * @return IPage<PaymentMerchantConfig>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<PaymentMerchantConfig> selectPage(IPage<PaymentMerchantConfig> page, PaymentMerchantConfigWrapper.PaymentMerchantConfigQuery query) {
|
|
|
+
|
|
|
+ return page.setRecords(baseMapper.selectPage(page, query));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加
|
|
|
+ * @param paymentMerchantConfig PaymentMerchantConfigWrapper.PaymentMerchantConfig
|
|
|
+ * @return Boolean
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean add(PaymentMerchantConfigWrapper.PaymentMerchantConfig paymentMerchantConfig) {
|
|
|
+
|
|
|
+ return this.save(JSON.parseObject(paymentMerchantConfig.jsonString(), PaymentMerchantConfig.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新
|
|
|
+ * @param paymentMerchantConfig PaymentMerchantConfigWrapper.PaymentMerchantConfig
|
|
|
+ * @return Boolean
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean update(PaymentMerchantConfigWrapper.PaymentMerchantConfig paymentMerchantConfig){
|
|
|
+
|
|
|
+ return this.updateById(JSON.parseObject(paymentMerchantConfig.jsonString(), PaymentMerchantConfig.class));
|
|
|
+ }
|
|
|
+}
|