:refactor: HCS推送开关配置统一收敛至HcsProperties并支持Nacos动态刷新
This commit is contained in:
+3
-8
@@ -29,12 +29,12 @@ import jakarta.annotation.PreDestroy;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springblade.core.redis.cache.BladeRedis;
|
import org.springblade.core.redis.cache.BladeRedis;
|
||||||
|
import org.springblade.hcs.config.HcsProperties;
|
||||||
import org.springblade.transport.constant.HcsSyncConstant;
|
import org.springblade.transport.constant.HcsSyncConstant;
|
||||||
import org.springblade.transport.mapper.ContractManageMapper;
|
import org.springblade.transport.mapper.ContractManageMapper;
|
||||||
import org.springblade.transport.mapper.ProjectApplyMapper;
|
import org.springblade.transport.mapper.ProjectApplyMapper;
|
||||||
import org.springblade.transport.pojo.entity.ContractManage;
|
import org.springblade.transport.pojo.entity.ContractManage;
|
||||||
import org.springblade.transport.pojo.entity.ProjectApply;
|
import org.springblade.transport.pojo.entity.ProjectApply;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.support.TransactionSynchronization;
|
import org.springframework.transaction.support.TransactionSynchronization;
|
||||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||||
@@ -77,18 +77,13 @@ public class HcsImmediatePushSupport {
|
|||||||
*/
|
*/
|
||||||
private static final AtomicInteger THREAD_COUNTER = new AtomicInteger(1);
|
private static final AtomicInteger THREAD_COUNTER = new AtomicInteger(1);
|
||||||
|
|
||||||
|
private final HcsProperties hcsProperties;
|
||||||
private final HcsProjectSyncSupport hcsProjectSyncSupport;
|
private final HcsProjectSyncSupport hcsProjectSyncSupport;
|
||||||
private final HcsContractSyncSupport hcsContractSyncSupport;
|
private final HcsContractSyncSupport hcsContractSyncSupport;
|
||||||
private final ProjectApplyMapper projectApplyMapper;
|
private final ProjectApplyMapper projectApplyMapper;
|
||||||
private final ContractManageMapper contractManageMapper;
|
private final ContractManageMapper contractManageMapper;
|
||||||
private final BladeRedis bladeRedis;
|
private final BladeRedis bladeRedis;
|
||||||
|
|
||||||
/**
|
|
||||||
* 即时推送总开关(thirdParty.hcs.push.immediate-enabled,默认关闭灰度打开;关闭时完全回落扫描链路)
|
|
||||||
*/
|
|
||||||
@Value("${thirdParty.hcs.push.immediate-enabled:false}")
|
|
||||||
private boolean immediateEnabled;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 推送线程池:2 线程 daemon,即时推送与定时扫描互不影响
|
* 推送线程池:2 线程 daemon,即时推送与定时扫描互不影响
|
||||||
*/
|
*/
|
||||||
@@ -120,7 +115,7 @@ public class HcsImmediatePushSupport {
|
|||||||
* 开关校验后注册提交时机:有活动事务注册 afterCommit 回调(回滚不推送),无事务(MK 回调单条更新自动提交)直接异步
|
* 开关校验后注册提交时机:有活动事务注册 afterCommit 回调(回滚不推送),无事务(MK 回调单条更新自动提交)直接异步
|
||||||
*/
|
*/
|
||||||
private void submitAfterCommit(String bizType, Long id, Runnable pushAction) {
|
private void submitAfterCommit(String bizType, Long id, Runnable pushAction) {
|
||||||
if (!immediateEnabled) {
|
if (!hcsProperties.getPush().isImmediateEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Runnable pushTask = () -> this.pushWithLock(bizType, id, pushAction);
|
Runnable pushTask = () -> this.pushWithLock(bizType, id, pushAction);
|
||||||
|
|||||||
+5
-36
@@ -48,7 +48,6 @@ import org.springblade.transport.support.hcs.HcsInvoiceRegSyncSupport;
|
|||||||
import org.springblade.transport.support.hcs.HcsPaymentSyncSupport;
|
import org.springblade.transport.support.hcs.HcsPaymentSyncSupport;
|
||||||
import org.springblade.transport.support.hcs.HcsProjectSyncSupport;
|
import org.springblade.transport.support.hcs.HcsProjectSyncSupport;
|
||||||
import org.springblade.transport.support.hcs.HcsReceiptBillSyncSupport;
|
import org.springblade.transport.support.hcs.HcsReceiptBillSyncSupport;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -111,42 +110,12 @@ public class HcsPushTask {
|
|||||||
private final HcsReceiptBillSyncSupport hcsReceiptBillSyncSupport;
|
private final HcsReceiptBillSyncSupport hcsReceiptBillSyncSupport;
|
||||||
private final BladeRedis bladeRedis;
|
private final BladeRedis bladeRedis;
|
||||||
|
|
||||||
/**
|
|
||||||
* 项目立项(C102)推送开关,默认关闭(Nacos thirdParty.hcs.push.project.sync-enabled,灰度打开)
|
|
||||||
*/
|
|
||||||
@Value("${thirdParty.hcs.push.project.sync-enabled:false}")
|
|
||||||
private boolean projectSyncEnabled;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 合同(C103)推送开关,默认关闭(Nacos thirdParty.hcs.push.contract.sync-enabled,灰度打开)
|
|
||||||
*/
|
|
||||||
@Value("${thirdParty.hcs.push.contract.sync-enabled:false}")
|
|
||||||
private boolean contractSyncEnabled;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 付款链(C106 特批 / C108 履约记录)推送开关,默认关闭(Nacos thirdParty.hcs.push.payment.sync-enabled,灰度打开)
|
|
||||||
*/
|
|
||||||
@Value("${thirdParty.hcs.push.payment.sync-enabled:false}")
|
|
||||||
private boolean paymentSyncEnabled;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 开票登记(C111)推送开关,默认关闭(Nacos thirdParty.hcs.push.invoice-application.sync-enabled,灰度打开)
|
|
||||||
*/
|
|
||||||
@Value("${thirdParty.hcs.push.invoice-application.sync-enabled:false}")
|
|
||||||
private boolean invoiceApplicationSyncEnabled;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 收票单(C109)推送开关,默认关闭(Nacos thirdParty.hcs.push.invoice-receipt.sync-enabled,灰度打开)
|
|
||||||
*/
|
|
||||||
@Value("${thirdParty.hcs.push.invoice-receipt.sync-enabled:false}")
|
|
||||||
private boolean invoiceReceiptSyncEnabled;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 项目立项(C102)定时推送:扫描审批通过且待同步/待补偿的项目,独立开关与 cron 调度
|
* 项目立项(C102)定时推送:扫描审批通过且待同步/待补偿的项目,独立开关与 cron 调度
|
||||||
*/
|
*/
|
||||||
@Scheduled(cron = "${thirdParty.hcs.push.project.cron:0 */5 * * * ?}")
|
@Scheduled(cron = "${thirdParty.hcs.push.project.cron:0 */5 * * * ?}")
|
||||||
public void pushHcsProject() {
|
public void pushHcsProject() {
|
||||||
this.runOnce("项目立项", HcsSyncConstant.BIZ_TYPE_PROJECT, projectSyncEnabled, this::pushUnsyncedProjects);
|
this.runOnce("项目立项", HcsSyncConstant.BIZ_TYPE_PROJECT, hcsProperties.getPush().getProject().isSyncEnabled(), this::pushUnsyncedProjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -155,7 +124,7 @@ public class HcsPushTask {
|
|||||||
*/
|
*/
|
||||||
@Scheduled(cron = "${thirdParty.hcs.push.contract.cron:0 1/5 * * * ?}")
|
@Scheduled(cron = "${thirdParty.hcs.push.contract.cron:0 1/5 * * * ?}")
|
||||||
public void pushHcsContract() {
|
public void pushHcsContract() {
|
||||||
this.runOnce("合同", HcsSyncConstant.BIZ_TYPE_CONTRACT, contractSyncEnabled, this::syncHcsContracts);
|
this.runOnce("合同", HcsSyncConstant.BIZ_TYPE_CONTRACT, hcsProperties.getPush().getContract().isSyncEnabled(), this::syncHcsContracts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -171,7 +140,7 @@ public class HcsPushTask {
|
|||||||
*/
|
*/
|
||||||
@Scheduled(cron = "${thirdParty.hcs.push.payment.cron:0 2/5 * * * ?}")
|
@Scheduled(cron = "${thirdParty.hcs.push.payment.cron:0 2/5 * * * ?}")
|
||||||
public void pushHcsPayment() {
|
public void pushHcsPayment() {
|
||||||
this.runOnce("付款链", HcsSyncConstant.BIZ_TYPE_PAYMENT, paymentSyncEnabled, this::pushUnsyncedPayments);
|
this.runOnce("付款链", HcsSyncConstant.BIZ_TYPE_PAYMENT, hcsProperties.getPush().getPayment().isSyncEnabled(), this::pushUnsyncedPayments);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -179,7 +148,7 @@ public class HcsPushTask {
|
|||||||
*/
|
*/
|
||||||
@Scheduled(cron = "${thirdParty.hcs.push.invoice-application.cron:0 3/5 * * * ?}")
|
@Scheduled(cron = "${thirdParty.hcs.push.invoice-application.cron:0 3/5 * * * ?}")
|
||||||
public void pushHcsInvoiceApplication() {
|
public void pushHcsInvoiceApplication() {
|
||||||
this.runOnce("开票登记", HcsSyncConstant.BIZ_TYPE_INVOICE_APPLICATION, invoiceApplicationSyncEnabled, this::pushUnsyncedInvoiceApplications);
|
this.runOnce("开票登记", HcsSyncConstant.BIZ_TYPE_INVOICE_APPLICATION, hcsProperties.getPush().getInvoiceApplication().isSyncEnabled(), this::pushUnsyncedInvoiceApplications);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -187,7 +156,7 @@ public class HcsPushTask {
|
|||||||
*/
|
*/
|
||||||
@Scheduled(cron = "${thirdParty.hcs.push.invoice-receipt.cron:0 4/5 * * * ?}")
|
@Scheduled(cron = "${thirdParty.hcs.push.invoice-receipt.cron:0 4/5 * * * ?}")
|
||||||
public void pushHcsInvoiceReceipt() {
|
public void pushHcsInvoiceReceipt() {
|
||||||
this.runOnce("收票单", HcsSyncConstant.BIZ_TYPE_INVOICE_RECEIPT, invoiceReceiptSyncEnabled, this::pushUnsyncedInvoiceReceipts);
|
this.runOnce("收票单", HcsSyncConstant.BIZ_TYPE_INVOICE_RECEIPT, hcsProperties.getPush().getInvoiceReceipt().isSyncEnabled(), this::pushUnsyncedInvoiceReceipts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+36
@@ -152,6 +152,10 @@ public class HcsProperties {
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static class Push {
|
public static class Push {
|
||||||
|
/**
|
||||||
|
* 审批通过即时推送总开关(thirdParty.hcs.push.immediate-enabled,默认关闭灰度打开;关闭时完全回落扫描链路)
|
||||||
|
*/
|
||||||
|
private boolean immediateEnabled = false;
|
||||||
/**
|
/**
|
||||||
* 每类单据单轮扫描批量(全局)
|
* 每类单据单轮扫描批量(全局)
|
||||||
*/
|
*/
|
||||||
@@ -160,6 +164,38 @@ public class HcsProperties {
|
|||||||
* 推送失败自动重试上限,超限仅人工重推(全局)
|
* 推送失败自动重试上限,超限仅人工重推(全局)
|
||||||
*/
|
*/
|
||||||
private int maxRetry = 5;
|
private int maxRetry = 5;
|
||||||
|
/**
|
||||||
|
* 项目立项(C102)推送开关(thirdParty.hcs.push.project.sync-enabled,默认关闭,灰度打开)
|
||||||
|
*/
|
||||||
|
private Task project = new Task();
|
||||||
|
/**
|
||||||
|
* 合同(C103)推送开关(thirdParty.hcs.push.contract.sync-enabled,默认关闭,灰度打开)
|
||||||
|
*/
|
||||||
|
private Task contract = new Task();
|
||||||
|
/**
|
||||||
|
* 付款链(C106 特批 / C108 履约记录)推送开关(thirdParty.hcs.push.payment.sync-enabled,默认关闭,灰度打开)
|
||||||
|
*/
|
||||||
|
private Task payment = new Task();
|
||||||
|
/**
|
||||||
|
* 开票登记(C111)推送开关(thirdParty.hcs.push.invoice-application.sync-enabled,默认关闭,灰度打开)
|
||||||
|
*/
|
||||||
|
private Task invoiceApplication = new Task();
|
||||||
|
/**
|
||||||
|
* 收票单(C109)推送开关(thirdParty.hcs.push.invoice-receipt.sync-enabled,默认关闭,灰度打开)
|
||||||
|
*/
|
||||||
|
private Task invoiceReceipt = new Task();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单类单据推送任务配置(thirdParty.hcs.push.{bizType}.sync-enabled;
|
||||||
|
* cron 有代码默认值错峰每 5 分钟,保持 @Scheduled 占位符形式,未纳入本类)
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class Task {
|
||||||
|
/**
|
||||||
|
* 推送开关,默认关闭(灰度打开)
|
||||||
|
*/
|
||||||
|
private boolean syncEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
|||||||
Reference in New Issue
Block a user