|
@@ -1,14 +1,19 @@
|
|
|
package com.izouma.nineth.service;
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import com.huifu.adapay.Adapay;
|
|
import com.huifu.adapay.Adapay;
|
|
|
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
|
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
|
|
import com.huifu.adapay.model.*;
|
|
import com.huifu.adapay.model.*;
|
|
|
import com.izouma.nineth.config.AdapayProperties;
|
|
import com.izouma.nineth.config.AdapayProperties;
|
|
|
|
|
+import com.izouma.nineth.config.EventNames;
|
|
|
|
|
+import com.izouma.nineth.config.GeneralProperties;
|
|
|
import com.izouma.nineth.domain.AdapayMerchant;
|
|
import com.izouma.nineth.domain.AdapayMerchant;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.dto.adapay.MemberInfo;
|
|
import com.izouma.nineth.dto.adapay.MemberInfo;
|
|
|
|
|
+import com.izouma.nineth.dto.adapay.PaymentItem;
|
|
|
|
|
+import com.izouma.nineth.dto.adapay.PaymentList;
|
|
|
import com.izouma.nineth.dto.adapay.SettleAccountsItem;
|
|
import com.izouma.nineth.dto.adapay.SettleAccountsItem;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.repo.AdapayMerchantRepo;
|
|
import com.izouma.nineth.repo.AdapayMerchantRepo;
|
|
@@ -18,6 +23,7 @@ import com.izouma.nineth.utils.SnowflakeIdWorker;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
|
|
+import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
@@ -34,6 +40,8 @@ public class AdapayMerchantService {
|
|
|
|
|
|
|
|
private final AdapayMerchantRepo adapayMerchantRepo;
|
|
private final AdapayMerchantRepo adapayMerchantRepo;
|
|
|
private final AdapayProperties adapayProperties;
|
|
private final AdapayProperties adapayProperties;
|
|
|
|
|
+ private final RocketMQTemplate rocketMQTemplate;
|
|
|
|
|
+ private final GeneralProperties generalProperties;
|
|
|
|
|
|
|
|
@PostConstruct
|
|
@PostConstruct
|
|
|
public void init() {
|
|
public void init() {
|
|
@@ -72,6 +80,19 @@ public class AdapayMerchantService {
|
|
|
return record;
|
|
return record;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public void sendSelectEvent(Long id) {
|
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
|
+ jsonObject.put("name", EventNames.SWITCH_ACCOUNT);
|
|
|
|
|
+ jsonObject.put("data", id);
|
|
|
|
|
+ rocketMQTemplate.convertAndSend(generalProperties.getBroadcastEventTopic(), jsonObject);
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ Thread.sleep(500);
|
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public void select(Long id) throws Exception {
|
|
public void select(Long id) throws Exception {
|
|
|
AdapayMerchant merchant = adapayMerchantRepo.findById(id).orElseThrow(new BusinessException("商户不存在"));
|
|
AdapayMerchant merchant = adapayMerchantRepo.findById(id).orElseThrow(new BusinessException("商户不存在"));
|
|
|
|
|
|
|
@@ -229,24 +250,34 @@ public class AdapayMerchantService {
|
|
|
|
|
|
|
|
public Object query(Long merchantId, String id) throws BaseAdaPayException {
|
|
public Object query(Long merchantId, String id) throws BaseAdaPayException {
|
|
|
AdapayMerchant merchant = adapayMerchantRepo.findById(merchantId).orElseThrow(new BusinessException("商户不存在"));
|
|
AdapayMerchant merchant = adapayMerchantRepo.findById(merchantId).orElseThrow(new BusinessException("商户不存在"));
|
|
|
- Map<String, Object> map = Payment.query(id, merchant.getName());
|
|
|
|
|
- log.info(JSON.toJSONString(map, SerializerFeature.PrettyFormat));
|
|
|
|
|
- return map;
|
|
|
|
|
|
|
+ Map<String, Object> paymentParams = new HashMap<>();
|
|
|
|
|
+ paymentParams.put("app_id", merchant.getAppId());
|
|
|
|
|
+ paymentParams.put("payment_id", id);
|
|
|
|
|
+ Map<String, Object> paymentList = Payment.queryList(paymentParams, merchant.getName());
|
|
|
|
|
+ log.info(JSON.toJSONString(paymentList, SerializerFeature.PrettyFormat));
|
|
|
|
|
+ return paymentList;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public Object refund(Long merchantId, String id) throws BaseAdaPayException {
|
|
public Object refund(Long merchantId, String id) throws BaseAdaPayException {
|
|
|
AdapayMerchant merchant = adapayMerchantRepo.findById(merchantId).orElseThrow(new BusinessException("商户不存在"));
|
|
AdapayMerchant merchant = adapayMerchantRepo.findById(merchantId).orElseThrow(new BusinessException("商户不存在"));
|
|
|
- Map<String, Object> map = Payment.query(id, merchant.getName());
|
|
|
|
|
- if (!"succeeded".equals(MapUtils.getString(map, "status"))) {
|
|
|
|
|
- return map;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> paymentParams = new HashMap<>();
|
|
|
|
|
+ paymentParams.put("app_id", merchant.getAppId());
|
|
|
|
|
+ paymentParams.put("payment_id", id);
|
|
|
|
|
+ Map<String, Object> res = Payment.queryList(paymentParams, merchant.getName());
|
|
|
|
|
+ log.info(JSON.toJSONString(res, SerializerFeature.PrettyFormat));
|
|
|
|
|
+ PaymentList paymentList = JSON.parseObject(JSON.toJSONString(res), PaymentList.class);
|
|
|
|
|
+
|
|
|
|
|
+ if (paymentList.getPayments() != null && paymentList.getPayments().size() == 1) {
|
|
|
|
|
+ PaymentItem paymentItem = paymentList.getPayments().get(0);
|
|
|
|
|
+ Map<String, Object> refundParams = new HashMap<>();
|
|
|
|
|
+ refundParams.put("refund_amt", paymentItem.getPayAmt());
|
|
|
|
|
+ refundParams.put("refund_order_no", new SnowflakeIdWorker(0, 0).nextId() + "");
|
|
|
|
|
+ Map<String, Object> response = Refund.create(id, refundParams, merchant.getName());
|
|
|
|
|
+ log.info(JSON.toJSONString(response, SerializerFeature.PrettyFormat));
|
|
|
|
|
+ return response;
|
|
|
}
|
|
}
|
|
|
- String amt = MapUtils.getString(map, "pay_amt");
|
|
|
|
|
- Map<String, Object> refundParams = new HashMap<>();
|
|
|
|
|
- refundParams.put("refund_amt", amt);
|
|
|
|
|
- refundParams.put("refund_order_no", new SnowflakeIdWorker(0, 0).nextId() + "");
|
|
|
|
|
- Map<String, Object> response = Refund.create(id, refundParams, merchant.getName());
|
|
|
|
|
- log.info(JSON.toJSONString(response, SerializerFeature.PrettyFormat));
|
|
|
|
|
- return response;
|
|
|
|
|
|
|
+ return res;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static void checkSuccess(Map<String, Object> map) {
|
|
public static void checkSuccess(Map<String, Object> map) {
|