|
|
@@ -0,0 +1,52 @@
|
|
|
+package com.crm.settlement.config;
|
|
|
+
|
|
|
+import com.crm.rely.backend.core.pojo.table.SysConfigTable;
|
|
|
+import com.crm.rely.backend.model.constant.ConfigConstants;
|
|
|
+import com.crm.rely.backend.service.RedisService;
|
|
|
+import com.crm.settlement.dao.repository.FinanceDepositAddressRepository;
|
|
|
+import com.crm.settlement.dao.repository.SysConfigRepository;
|
|
|
+import jakarta.annotation.PostConstruct;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author gao
|
|
|
+ * @date 2026/1/15
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class AddressIdInitializer {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysConfigRepository configRepository;
|
|
|
+ @Autowired
|
|
|
+ private FinanceDepositAddressRepository depositAddressRepository;
|
|
|
+ @Autowired
|
|
|
+ private RedisService redisService;
|
|
|
+
|
|
|
+ @PostConstruct
|
|
|
+ public void init() {
|
|
|
+ try {
|
|
|
+ // 读取配置值
|
|
|
+ SysConfigTable configTable = configRepository.getByCode(ConfigConstants.ADDRESS_ID_CONTROL_AUTO_NUMBER);
|
|
|
+ if (configTable == null) {
|
|
|
+ long count = depositAddressRepository.count();
|
|
|
+ configTable = new SysConfigTable();
|
|
|
+ configTable.setCode(ConfigConstants.ADDRESS_ID_CONTROL_AUTO_NUMBER);
|
|
|
+ configTable.setValue(String.valueOf(count));
|
|
|
+ configRepository.save(configTable);
|
|
|
+ } else if (configTable.getValue() == null) {
|
|
|
+ long count = depositAddressRepository.count();
|
|
|
+ configTable.setValue(String.valueOf(count));
|
|
|
+ configRepository.save(configTable);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 初始化Redis自增值
|
|
|
+ redisService.saveObject(ConfigConstants.ADDRESS_ID_CONTROL_AUTO_NUMBER,
|
|
|
+ Long.parseLong(configTable.getValue()));
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("钱包地址数量初始化失败,系统启动中断", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|