|
|
@@ -1,8 +1,13 @@
|
|
|
package com.payment.platform.module.payment.enterprise.scheduler;
|
|
|
|
|
|
+import com.alipay.api.AlipayApiException;
|
|
|
+import com.alipay.api.domain.AlipayCommerceEcEnterpriseInfoQueryModel;
|
|
|
+import com.alipay.api.request.AlipayCommerceEcEnterpriseInfoQueryRequest;
|
|
|
+import com.alipay.api.response.AlipayCommerceEcEnterpriseInfoQueryResponse;
|
|
|
+import com.payment.platform.common.exception.BusinessException;
|
|
|
+import com.payment.platform.core.alipay.AlipayClientFactory;
|
|
|
import com.payment.platform.module.payment.enterprise.entity.EnterpriseEntity;
|
|
|
import com.payment.platform.module.payment.enterprise.mapper.EnterpriseMapper;
|
|
|
-import com.payment.platform.module.payment.enterprise.service.AlipayEnterpriseService;
|
|
|
import jakarta.annotation.PostConstruct;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -10,6 +15,7 @@ import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.time.OffsetDateTime;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -22,7 +28,7 @@ import java.util.Map;
|
|
|
public class EnterpriseNameSyncScheduler {
|
|
|
|
|
|
private final EnterpriseMapper enterpriseMapper;
|
|
|
- private final AlipayEnterpriseService alipayEnterpriseService;
|
|
|
+ private final AlipayClientFactory alipayClientFactory;
|
|
|
|
|
|
private static final int MAX_RETRY = 20;
|
|
|
|
|
|
@@ -42,7 +48,7 @@ public class EnterpriseNameSyncScheduler {
|
|
|
int success = 0;
|
|
|
for (EnterpriseEntity entity : list) {
|
|
|
try {
|
|
|
- Map<String, Object> info = alipayEnterpriseService.queryEnterpriseDetail(entity.getEnterpriseId());
|
|
|
+ Map<String, Object> info = queryDetailByProvider(entity);
|
|
|
if (info != null && !info.isEmpty()) {
|
|
|
if (info.get("enterprise_name") != null) entity.setName((String) info.get("enterprise_name"));
|
|
|
if (info.get("enterprise_alias") != null) entity.setShortName((String) info.get("enterprise_alias"));
|
|
|
@@ -53,12 +59,31 @@ public class EnterpriseNameSyncScheduler {
|
|
|
} catch (Exception e) {
|
|
|
int retry = entity.getNameSyncRetryCount() != null ? entity.getNameSyncRetryCount() + 1 : 1;
|
|
|
entity.setNameSyncRetryCount(retry);
|
|
|
- // 指数退避: 10min, 20min, 40min, 80min... 最大 12h
|
|
|
- long delay = Math.min(10L * (1L << Math.min(retry, 6)), 12 * 60);
|
|
|
- entity.setNameSyncNextTime(OffsetDateTime.now().plusMinutes(delay));
|
|
|
}
|
|
|
enterpriseMapper.updateIgnoreTenant(entity);
|
|
|
}
|
|
|
log.info("[企业名称同步] 完成: 成功 {}/{}", success, list.size());
|
|
|
}
|
|
|
+
|
|
|
+ private Map<String, Object> queryDetailByProvider(EnterpriseEntity entity) throws AlipayApiException {
|
|
|
+ AlipayCommerceEcEnterpriseInfoQueryModel model = new AlipayCommerceEcEnterpriseInfoQueryModel();
|
|
|
+ model.setEnterpriseId(entity.getEnterpriseId());
|
|
|
+ AlipayCommerceEcEnterpriseInfoQueryRequest request = new AlipayCommerceEcEnterpriseInfoQueryRequest();
|
|
|
+ request.setBizModel(model);
|
|
|
+ AlipayCommerceEcEnterpriseInfoQueryResponse response =
|
|
|
+ alipayClientFactory.getClientByProvider(entity.getServiceProviderId()).execute(request);
|
|
|
+ if (!response.isSuccess()) {
|
|
|
+ throw new BusinessException(400, response.getSubMsg() != null ? response.getSubMsg() : response.getMsg());
|
|
|
+ }
|
|
|
+ Map<String, Object> result = new LinkedHashMap<>();
|
|
|
+ if (response.getEnterpriseInfo() != null) {
|
|
|
+ var info = response.getEnterpriseInfo();
|
|
|
+ try {
|
|
|
+ result.put("account_id", info.getClass().getMethod("getAccountId").invoke(info));
|
|
|
+ result.put("enterprise_name", info.getClass().getMethod("getEnterpriseName").invoke(info));
|
|
|
+ result.put("enterprise_alias", info.getClass().getMethod("getEnterpriseAlias").invoke(info));
|
|
|
+ } catch (Exception ignored) {}
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|