feat: 改造多租户支持,采用 multi-tenant library
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/agent/service/AgentServiceProxy.java b/payapi/src/main/java/com/supwisdom/dlpay/agent/service/AgentServiceProxy.java
index 80cb888..e33c0db 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/agent/service/AgentServiceProxy.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/agent/service/AgentServiceProxy.java
@@ -4,8 +4,8 @@
import com.supwisdom.dlpay.agent.domain.QrcodePattern;
import com.supwisdom.dlpay.agent.domain.QrcodePayTrans;
import com.supwisdom.dlpay.framework.service.SystemUtilService;
-import com.supwisdom.dlpay.framework.tenant.TenantContext;
import com.supwisdom.dlpay.framework.util.StringUtil;
+import com.supwisdom.multitenant.TenantContextHolder;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
@@ -33,18 +33,18 @@
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, readOnly = true)
public QrcodePayTrans qrcodePayTransFindByRefno(String refno) {
- return qrcodeTransDao.findByRefnoAndTenantid(refno, TenantContext.getTenantSchema());
+ return qrcodeTransDao.findByRefnoAndTenantid(refno, TenantContextHolder.getContext().getTenant().getId());
}
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, readOnly = true)
public QrcodePayTrans qrcodePayTransFindByMerchIdAndBillno(String merchid, String billno) {
return qrcodeTransDao.findByAgentMerchIdAndHostdateAndBillnoAndTenantid(merchid,
- systemUtilService.getSysdatetime().getHostdate(), billno, TenantContext.getTenantSchema());
+ systemUtilService.getSysdatetime().getHostdate(), billno, TenantContextHolder.getContext().getTenant().getId());
}
public QrcodePayTrans qrcodePayTransSaveOrUpdate(@NotNull QrcodePayTrans bean) {
if (StringUtil.isEmpty(bean.getTenantid())) {
- bean.setTenantid(TenantContext.getTenantSchema());
+ bean.setTenantid(TenantContextHolder.getContext().getTenant().getId());
}
return qrcodeTransDao.save(bean);
}
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/agent/service/impl/QrcodePatternServiceImpl.java b/payapi/src/main/java/com/supwisdom/dlpay/agent/service/impl/QrcodePatternServiceImpl.java
index c14ee51..a0a5c3b 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/agent/service/impl/QrcodePatternServiceImpl.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/agent/service/impl/QrcodePatternServiceImpl.java
@@ -3,7 +3,7 @@
import com.supwisdom.dlpay.agent.dao.QrcodePatternDao;
import com.supwisdom.dlpay.agent.domain.QrcodePattern;
import com.supwisdom.dlpay.agent.service.QrcodePatternService;
-import com.supwisdom.dlpay.framework.tenant.TenantContext;
+import com.supwisdom.multitenant.TenantContextHolder;
import org.jetbrains.annotations.NotNull;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
@@ -22,20 +22,20 @@
@Override
@Cacheable(cacheNames = "qrcode_pattern_cache", key = "@tenantHolder.genKey('qrcode_pattern')")
public List<QrcodePattern> getAllQrcodePattern() {
- return qrcodePatternDao.findByTenantid(TenantContext.getTenantSchema());
+ return qrcodePatternDao.findByTenantid(TenantContextHolder.getContext().getTenant().getId());
}
@Override
@CacheEvict(cacheNames = "qrcode_pattern_cache", key = "@tenantHolder.genKey('qrcode_pattern') + '.*'", allEntries = true)
public void deleteAllQrcodePattern() {
- qrcodePatternDao.deleteByTenantid(TenantContext.getTenantSchema());
+ qrcodePatternDao.deleteByTenantid(TenantContextHolder.getContext().getTenant().getId());
}
@Override
@CacheEvict(cacheNames = "qrcode_pattern_cache", key = "@tenantHolder.genKey('qrcode_pattern') + '.*'", allEntries = true)
public QrcodePattern saveOrUpdateQrcodePattern(@NotNull QrcodePattern pattern) {
if (pattern.getTenantid() == null || pattern.getTenantid().isEmpty()) {
- pattern.setTenantid(TenantContext.getTenantSchema());
+ pattern.setTenantid(TenantContextHolder.getContext().getTenant().getId());
}
return qrcodePatternDao.save(pattern);
}
@@ -43,6 +43,6 @@
@Override
@Cacheable(cacheNames = "qrcode_pattern_cache", key = "@tenantHolder.genKey('qrcode_pattern', #sourceType)")
public List<QrcodePattern> findAllBySourcetype(String sourceType) {
- return qrcodePatternDao.findBySourceTypeAndTenantid(sourceType, TenantContext.getTenantSchema());
+ return qrcodePatternDao.findBySourceTypeAndTenantid(sourceType, TenantContextHolder.getContext().getTenant().getId());
}
}
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/api/service/impl/SourceTypeServiceImpl.java b/payapi/src/main/java/com/supwisdom/dlpay/api/service/impl/SourceTypeServiceImpl.java
index 14631ee..5c6b1ea 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/api/service/impl/SourceTypeServiceImpl.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/api/service/impl/SourceTypeServiceImpl.java
@@ -4,9 +4,9 @@
import com.supwisdom.dlpay.api.domain.*;
import com.supwisdom.dlpay.api.service.SourceTypeService;
import com.supwisdom.dlpay.exception.TransactionProcessException;
-import com.supwisdom.dlpay.framework.tenant.TenantContext;
import com.supwisdom.dlpay.framework.util.StringUtil;
import com.supwisdom.dlpay.framework.util.TradeErrorCode;
+import com.supwisdom.multitenant.TenantContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
@@ -195,18 +195,18 @@
@Override
public List<TSourceType> getAllEnabledSourcetype() {
- return sourceTypeDao.findByEnableAndTenantid(true, TenantContext.getTenantSchema());
+ return sourceTypeDao.findByEnableAndTenantid(true, TenantContextHolder.getContext().getTenant().getId());
}
@Override
public TSourceTypeCheckStatus getSourceTypeCheckStatus(String sourceType) {
- return sourceTypeCheckDao.getBySourceTypeAndTenantId(sourceType, TenantContext.getTenantSchema());
+ return sourceTypeCheckDao.getBySourceTypeAndTenantId(sourceType, TenantContextHolder.getContext().getTenant().getId());
}
@Override
public TSourceTypeCheckStatus saveOrUpdateSourceTypeCheckStatus(TSourceTypeCheckStatus s) {
if (s.getTenantId() == null || s.getTenantId().isEmpty()) {
- s.setTenantId(TenantContext.getTenantSchema());
+ s.setTenantId(TenantContextHolder.getContext().getTenant().getId());
}
return sourceTypeCheckDao.save(s);
}
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/framework/core/DatabaseAdapter.java b/payapi/src/main/java/com/supwisdom/dlpay/framework/core/DatabaseAdapter.java
new file mode 100644
index 0000000..53c85bf
--- /dev/null
+++ b/payapi/src/main/java/com/supwisdom/dlpay/framework/core/DatabaseAdapter.java
@@ -0,0 +1,7 @@
+package com.supwisdom.dlpay.framework.core;
+
+public interface DatabaseAdapter {
+ default String getDefaultSchema() {
+ return "";
+ }
+}
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/framework/core/DatabaseConfig.java b/payapi/src/main/java/com/supwisdom/dlpay/framework/core/DatabaseConfig.java
index 99bb014..8312040 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/framework/core/DatabaseConfig.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/framework/core/DatabaseConfig.java
@@ -4,11 +4,22 @@
import org.springframework.context.annotation.Configuration;
@Configuration
-public class DatabaseConfig {
+public class DatabaseConfig implements DatabaseAdapter {
@Value("${spring.datasource.platform}")
private String platform;
public String getPlatform() {
return platform;
}
+
+ @Override
+ public String getDefaultSchema() {
+ if ("postgresql".equals(getPlatform())) {
+ return "public";
+ } else if ("mysql".equals(getPlatform())) {
+ return "mysql";
+ } else {
+ return "";
+ }
+ }
}
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/framework/core/DayendSettleTask.java b/payapi/src/main/java/com/supwisdom/dlpay/framework/core/DayendSettleTask.java
index f0cc66c..37f30ea 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/framework/core/DayendSettleTask.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/framework/core/DayendSettleTask.java
@@ -3,9 +3,9 @@
import com.supwisdom.dlpay.exception.TransactionException;
import com.supwisdom.dlpay.framework.domain.TSettleLog;
import com.supwisdom.dlpay.framework.service.DayendSettleService;
-import com.supwisdom.dlpay.framework.tenant.TenantContext;
import com.supwisdom.dlpay.framework.util.Constants;
import com.supwisdom.dlpay.framework.util.StringUtil;
+import com.supwisdom.multitenant.TenantDetailsProvider;
import net.javacrumbs.shedlock.core.SchedulerLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -18,6 +18,8 @@
@Autowired
private DayendSettleService dayendSettleService;
+ @Autowired
+ private TenantDetailsProvider tenantDetailsProvider;
private TSettleLog settleLog;
private static final Logger logger = LoggerFactory.getLogger(DayendSettleTask.class);
@@ -26,7 +28,7 @@
@SchedulerLock(name = "DayendSettleTask", lockAtMostForString = "PT30M")
public void doSettleTask() {
if (logger.isDebugEnabled()) logger.debug("进入日结算任务!");
- if (null == TenantContext.getTenantSchema()) TenantContext.setTenantSchema(Constants.DEFAULT_TENANTID);
+ tenantDetailsProvider.defaultTenant(Constants.DEFAULT_TENANTID);
settleLog = dayendSettleService.doCreateSettleLog(); //记录日志
try {
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/framework/core/MutliTenantDatasourceProviderAdapter.java b/payapi/src/main/java/com/supwisdom/dlpay/framework/core/MutliTenantDatasourceProviderAdapter.java
new file mode 100644
index 0000000..d462964
--- /dev/null
+++ b/payapi/src/main/java/com/supwisdom/dlpay/framework/core/MutliTenantDatasourceProviderAdapter.java
@@ -0,0 +1,21 @@
+package com.supwisdom.dlpay.framework.core;
+
+import com.supwisdom.multitenant.datasource.MultiTenantDataSourceProvider;
+import com.supwisdom.multitenant.datasource.config.MultiTenantDataSourceAutoConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@ConditionalOnBean({MultiTenantDataSourceAutoConfiguration.class})
+public class MutliTenantDatasourceProviderAdapter implements DatabaseAdapter {
+ private final MultiTenantDataSourceProvider multiTenantDataSourceProvider;
+
+ public MutliTenantDatasourceProviderAdapter(MultiTenantDataSourceProvider multiTenantDataSourceProvider) {
+ this.multiTenantDataSourceProvider = multiTenantDataSourceProvider;
+ }
+
+ @Override
+ public String getDefaultSchema() {
+ return multiTenantDataSourceProvider.defaultSchema();
+ }
+}
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/framework/dao/TenantCatalogDao.java b/payapi/src/main/java/com/supwisdom/dlpay/framework/dao/TenantCatalogDao.java
new file mode 100644
index 0000000..ce9fe0e
--- /dev/null
+++ b/payapi/src/main/java/com/supwisdom/dlpay/framework/dao/TenantCatalogDao.java
@@ -0,0 +1,8 @@
+package com.supwisdom.dlpay.framework.dao;
+
+import com.supwisdom.dlpay.framework.domain.TTenantCatalog;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface TenantCatalogDao extends JpaRepository<TTenantCatalog, Integer> {
+ TTenantCatalog findTTenantCatalogByTenantid(String tenant);
+}
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/framework/domain/TTenantCatalog.java b/payapi/src/main/java/com/supwisdom/dlpay/framework/domain/TTenantCatalog.java
index 3647664..c893617 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/framework/domain/TTenantCatalog.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/framework/domain/TTenantCatalog.java
@@ -5,7 +5,7 @@
import java.sql.Timestamp;
@Entity
-@Table(name = "tb_tenant_catalog")
+@Table(name = "tb_tenant_catalog", schema = "public")
@SequenceGenerator(name = "tenant_catalog_seq")
public class TTenantCatalog {
@Id
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/framework/security/MyPermissionEvaluator.java b/payapi/src/main/java/com/supwisdom/dlpay/framework/security/MyPermissionEvaluator.java
index d110ae7..51c9c3b 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/framework/security/MyPermissionEvaluator.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/framework/security/MyPermissionEvaluator.java
@@ -1,31 +1,29 @@
package com.supwisdom.dlpay.framework.security;
import com.supwisdom.dlpay.framework.domain.*;
-import com.supwisdom.dlpay.framework.tenant.TenantContext;
import com.supwisdom.dlpay.framework.util.DateUtil;
-import com.supwisdom.dlpay.framework.util.StringUtil;
import com.supwisdom.dlpay.system.service.FunctionService;
import com.supwisdom.dlpay.system.service.OperatorService;
import com.supwisdom.dlpay.system.service.RoleService;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.core.Authentication;
-import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;
import java.io.Serializable;
-import java.util.Collection;
import java.util.List;
@Component
public class MyPermissionEvaluator implements PermissionEvaluator {
- @Autowired
- private RoleService roleService;
- @Autowired
- private OperatorService operatorService;
- @Autowired
- private FunctionService functionService;
+ private final RoleService roleService;
+ private final OperatorService operatorService;
+ private final FunctionService functionService;
+
+ public MyPermissionEvaluator(RoleService roleService, OperatorService operatorService, FunctionService functionService) {
+ this.roleService = roleService;
+ this.operatorService = operatorService;
+ this.functionService = functionService;
+ }
@Override
public boolean hasPermission(Authentication authentication, Object targetUri, Object permission) {
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/framework/service/impl/DayendSettleServiceImpl.java b/payapi/src/main/java/com/supwisdom/dlpay/framework/service/impl/DayendSettleServiceImpl.java
index 94566fa..d38b881 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/framework/service/impl/DayendSettleServiceImpl.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/framework/service/impl/DayendSettleServiceImpl.java
@@ -11,11 +11,11 @@
import com.supwisdom.dlpay.framework.domain.*;
import com.supwisdom.dlpay.framework.service.DayendSettleService;
import com.supwisdom.dlpay.framework.service.SystemUtilService;
-import com.supwisdom.dlpay.framework.tenant.TenantContext;
import com.supwisdom.dlpay.framework.util.DateUtil;
import com.supwisdom.dlpay.framework.util.MoneyUtil;
import com.supwisdom.dlpay.framework.util.StringUtil;
import com.supwisdom.dlpay.framework.util.Subject;
+import com.supwisdom.multitenant.TenantContextHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -70,7 +70,7 @@
public TSettleLog doCreateSettleLog() {
TSettleLog log = new TSettleLog();
log.setStarttime(systemUtilService.getSysdatetime().getHostdatetime());
- log.setTenantId(TenantContext.getTenantSchema());
+ log.setTenantId(TenantContextHolder.getContext().getTenant().getId());
return settleLogDao.save(log);
}
@@ -82,7 +82,7 @@
}
private boolean doSwitchPeriod() throws Exception {
- TPeriod period = periodDao.getTPeriodWithLock(periodYear, periodMonth, TenantContext.getTenantSchema());
+ TPeriod period = periodDao.getTPeriodWithLock(periodYear, periodMonth, TenantContextHolder.getContext().getTenant().getId());
if (period.getSettleflag() == 1) {
throw new Exception("月末结转已完成");
}
@@ -96,7 +96,7 @@
periodMonth = periodMonth + 1; //year不变
}
- TPeriod nextPerid = periodDao.getPeriod(periodYear, periodMonth, TenantContext.getTenantSchema());
+ TPeriod nextPerid = periodDao.getPeriod(periodYear, periodMonth, TenantContextHolder.getContext().getTenant().getId());
if (null != nextPerid) {
if (settledate != Integer.valueOf(nextPerid.getStartdate())) {
throw new Exception("下一个会计期间的开始日期不正确");
@@ -115,27 +115,27 @@
nextPerid.setStartdate(startdate.toString());
nextPerid.setEnddate(enddate.toString());
nextPerid.setSettleflag(0);
- nextPerid.setTenantId(TenantContext.getTenantSchema());
+ nextPerid.setTenantId(TenantContextHolder.getContext().getTenant().getId());
periodDao.save(nextPerid); //保存下个会计期间
}
- settleCtlDao.updateSettlePeriodByTenantid(periodYear, periodMonth, TenantContext.getTenantSchema());
- vouchernoCtlDao.updateVouchernoByTenantid(periodMonth, 0, TenantContext.getTenantSchema());
+ settleCtlDao.updateSettlePeriodByTenantid(periodYear, periodMonth, TenantContextHolder.getContext().getTenant().getId());
+ vouchernoCtlDao.updateVouchernoByTenantid(periodMonth, 0, TenantContextHolder.getContext().getTenant().getId());
return true;
}
private void saveVoucher(VoucherTemp voucherTemp) {
TVoucher voucher = new TVoucher(periodYear, periodMonth, 0, settledate, settledate, voucherTemp.getTranscnt(), Math.abs(voucherTemp.getTransamt()), voucherTemp.getSummary(), "auto", hostdate);
- voucher.setTenantId(TenantContext.getTenantSchema());
+ voucher.setTenantId(TenantContextHolder.getContext().getTenant().getId());
voucher = voucherDao.save(voucher);
TVoucherEntry entry1;
TVoucherEntry entry2;
if (voucherTemp.getTransamt() >= 0) {
- entry1 = new TVoucherEntry(voucher.getVoucherid(), 1, voucherTemp.getDrsubjno(), voucherTemp.getDraccno(), Math.abs(voucherTemp.getTransamt()), 0D, voucherTemp.getSummary(), voucherTemp.getCrsubjno(), voucherTemp.getCraccno(), TenantContext.getTenantSchema());
- entry2 = new TVoucherEntry(voucher.getVoucherid(), 2, voucherTemp.getCrsubjno(), voucherTemp.getCraccno(), 0D, Math.abs(voucherTemp.getTransamt()), voucherTemp.getSummary(), voucherTemp.getDrsubjno(), voucherTemp.getDraccno(), TenantContext.getTenantSchema());
+ entry1 = new TVoucherEntry(voucher.getVoucherid(), 1, voucherTemp.getDrsubjno(), voucherTemp.getDraccno(), Math.abs(voucherTemp.getTransamt()), 0D, voucherTemp.getSummary(), voucherTemp.getCrsubjno(), voucherTemp.getCraccno(), TenantContextHolder.getContext().getTenant().getId());
+ entry2 = new TVoucherEntry(voucher.getVoucherid(), 2, voucherTemp.getCrsubjno(), voucherTemp.getCraccno(), 0D, Math.abs(voucherTemp.getTransamt()), voucherTemp.getSummary(), voucherTemp.getDrsubjno(), voucherTemp.getDraccno(), TenantContextHolder.getContext().getTenant().getId());
} else {
- entry1 = new TVoucherEntry(voucher.getVoucherid(), 1, voucherTemp.getDrsubjno(), voucherTemp.getDraccno(), 0D, Math.abs(voucherTemp.getTransamt()), voucherTemp.getSummary(), voucherTemp.getCrsubjno(), voucherTemp.getCraccno(), TenantContext.getTenantSchema());
- entry2 = new TVoucherEntry(voucher.getVoucherid(), 2, voucherTemp.getCrsubjno(), voucherTemp.getCraccno(), Math.abs(voucherTemp.getTransamt()), 0D, voucherTemp.getSummary(), voucherTemp.getDrsubjno(), voucherTemp.getDraccno(), TenantContext.getTenantSchema());
+ entry1 = new TVoucherEntry(voucher.getVoucherid(), 1, voucherTemp.getDrsubjno(), voucherTemp.getDraccno(), 0D, Math.abs(voucherTemp.getTransamt()), voucherTemp.getSummary(), voucherTemp.getCrsubjno(), voucherTemp.getCraccno(), TenantContextHolder.getContext().getTenant().getId());
+ entry2 = new TVoucherEntry(voucher.getVoucherid(), 2, voucherTemp.getCrsubjno(), voucherTemp.getCraccno(), Math.abs(voucherTemp.getTransamt()), 0D, voucherTemp.getSummary(), voucherTemp.getDrsubjno(), voucherTemp.getDraccno(), TenantContextHolder.getContext().getTenant().getId());
}
voucherEntryDao.save(entry1);
voucherEntryDao.save(entry2);
@@ -143,7 +143,7 @@
@Override
public boolean doDayendSettle() throws Exception {
- TSettlectl tSettlectl = settleCtlDao.findByTenantIdWithLock(TenantContext.getTenantSchema());
+ TSettlectl tSettlectl = settleCtlDao.findByTenantIdWithLock(TenantContextHolder.getContext().getTenant().getId());
if (null == tSettlectl || null == tSettlectl.getBooksetno()) {
throw new Exception("初始化错误,T_SETTLECTL 无初始化数据");
}
@@ -164,7 +164,7 @@
throw new TransactionException(-90, "有对账未完成");
}
- TPeriod period = periodDao.getPeriod(periodYear, periodMonth, TenantContext.getTenantSchema());
+ TPeriod period = periodDao.getPeriod(periodYear, periodMonth, TenantContextHolder.getContext().getTenant().getId());
if (null == period) throw new Exception("year=[" + periodYear + "],month=[" + periodMonth + "] t_period not find ");
if (settledate > Integer.valueOf(period.getEnddate())) {
//月切
@@ -174,25 +174,25 @@
}
//新增科目插入科目余额表(末级科目)
- List<TSubject> newEndsubjectList = subjectDao.getNewSubjectByTenantid(TenantContext.getTenantSchema());
+ List<TSubject> newEndsubjectList = subjectDao.getNewSubjectByTenantid(TenantContextHolder.getContext().getTenant().getId());
if (!StringUtil.isEmpty(newEndsubjectList)) {
for (TSubject subject : newEndsubjectList) {
TSubjectbal subjectbal = new TSubjectbal(subject.getId(),subject.getSubjno(), subject.getTenantId());
subjectbalDao.save(subjectbal);
}
}
- if (subjectDao.checkSettleSubjectByTenantid(TenantContext.getTenantSchema()).getExisted() > 0) {
+ if (subjectDao.checkSettleSubjectByTenantid(TenantContextHolder.getContext().getTenant().getId()).getExisted() > 0) {
throw new Exception("初始化数据错误:科目余额表数据没有包含所有的科目余额");
}
//删除未入账凭证
- if (voucherDao.checkExistUnpostVouhcer(TenantContext.getTenantSchema()).getExisted() > 0) {
- voucherEntryDao.deleteUnpostVoucherentry(TenantContext.getTenantSchema());
- voucherDao.deleteUnpostVoucher(TenantContext.getTenantSchema());
+ if (voucherDao.checkExistUnpostVouhcer(TenantContextHolder.getContext().getTenant().getId()).getExisted() > 0) {
+ voucherEntryDao.deleteUnpostVoucherentry(TenantContextHolder.getContext().getTenant().getId());
+ voucherDao.deleteUnpostVoucher(TenantContextHolder.getContext().getTenant().getId());
}
//用户交易凭证
- List<VoucherTemp> userList = debitCreditDtlDao.getVoucherData(String.valueOf(settledate), TenantContext.getTenantSchema());
+ List<VoucherTemp> userList = debitCreditDtlDao.getVoucherData(String.valueOf(settledate), TenantContextHolder.getContext().getTenant().getId());
if (!StringUtil.isEmpty(userList)) {
for (VoucherTemp temp : userList) {
saveVoucher(temp);
@@ -200,16 +200,16 @@
}
//凭证号
- TVouchernoCtl vouchernoCtl = vouchernoCtlDao.getVouchernoByTenantid(TenantContext.getTenantSchema());
+ TVouchernoCtl vouchernoCtl = vouchernoCtlDao.getVouchernoByTenantid(TenantContextHolder.getContext().getTenant().getId());
if (null == vouchernoCtl) {
vouchernoCtl = new TVouchernoCtl();
vouchernoCtl.setPeriodMonth(periodMonth);
vouchernoCtl.setVoucherno(0);
- vouchernoCtl.setTenantId(TenantContext.getTenantSchema());
+ vouchernoCtl.setTenantId(TenantContextHolder.getContext().getTenant().getId());
vouchernoCtlDao.save(vouchernoCtl);
}
int voucherno = vouchernoCtl.getVoucherno();
- List<TVoucher> voucherList = voucherDao.getSettleVouchers(TenantContext.getTenantSchema());
+ List<TVoucher> voucherList = voucherDao.getSettleVouchers(TenantContextHolder.getContext().getTenant().getId());
if (!StringUtil.isEmpty(voucherList)) {
for (TVoucher voucher : voucherList) {
voucherno++;
@@ -223,7 +223,7 @@
Map<String, Double> v_merchbaldict = new HashMap<String, Double>(0);
//根据商户昨天日结表生成当天日结表(交易前余额), 新增商户添加记录
- List<TShopaccday> lastShopaccdays = shopaccdayDao.getShopaccdayByAccdate(String.valueOf(lastsettday), TenantContext.getTenantSchema());
+ List<TShopaccday> lastShopaccdays = shopaccdayDao.getShopaccdayByAccdate(String.valueOf(lastsettday), TenantContextHolder.getContext().getTenant().getId());
if (!StringUtil.isEmpty(lastShopaccdays)) {
for (TShopaccday lastday : lastShopaccdays) {
TShopaccday today = new TShopaccday(String.valueOf(settledate), lastday.getShopaccno(), periodYear, periodMonth, lastday.getBalance(), 0D, 0D, 0D);
@@ -232,17 +232,17 @@
v_merchbaldict.put(lastday.getShopaccno(), lastday.getBalance());
}
}
- List<String> newShopaccs = shopaccDao.getNewShopacc(String.valueOf(lastsettday), TenantContext.getTenantSchema()); //新增商户
+ List<String> newShopaccs = shopaccDao.getNewShopacc(String.valueOf(lastsettday), TenantContextHolder.getContext().getTenant().getId()); //新增商户
if(!StringUtil.isEmpty(newShopaccs)){
for(String accno:newShopaccs){
TShopaccday today = new TShopaccday(String.valueOf(settledate), accno, periodYear, periodMonth, 0D, 0D, 0D, 0D);
- today.setTenantId(TenantContext.getTenantSchema());
+ today.setTenantId(TenantContextHolder.getContext().getTenant().getId());
shopaccdayDao.save(today);
v_merchbaldict.put(accno, 0D);
}
}
- List<MerchBean> merchBeanList = voucherDao.getShopVoucherByAccdate(settledate, TenantContext.getTenantSchema());
+ List<MerchBean> merchBeanList = voucherDao.getShopVoucherByAccdate(settledate, TenantContextHolder.getContext().getTenant().getId());
if (!StringUtil.isEmpty(merchBeanList)) {
for (MerchBean merch : merchBeanList) {
TShopaccday merchday = shopaccdayDao.getTShopaccdayById(String.valueOf(settledate), merch.getShopaccno());
@@ -254,24 +254,24 @@
shopaccdayDao.save(merchday);
}
}
- shopaccdayDao.updateShopaccdayBalance(String.valueOf(settledate), systemUtilService.getSysdatetime().getHostdatetime(), TenantContext.getTenantSchema()); //批量更新余额,商户日结表生成
+ shopaccdayDao.updateShopaccdayBalance(String.valueOf(settledate), systemUtilService.getSysdatetime().getHostdatetime(), TenantContextHolder.getContext().getTenant().getId()); //批量更新余额,商户日结表生成
//根据科目昨天日结表生成当天日结表(交易前借贷方余额),新增末级科目插入记录(交易前余额为科目贷方余额)
- List<TSubjectday> lastSubjectDays = subjectdayDao.getAllByAccdate(String.valueOf(lastsettday), TenantContext.getTenantSchema());
+ List<TSubjectday> lastSubjectDays = subjectdayDao.getAllByAccdate(String.valueOf(lastsettday), TenantContextHolder.getContext().getTenant().getId());
if (!StringUtil.isEmpty(lastSubjectDays)) {
for (TSubjectday lastday : lastSubjectDays) {
TSubjectday today = new TSubjectday(lastday.getSubjid(),String.valueOf(settledate), lastday.getSubjno(), periodYear, periodMonth, lastday.getDrbal(), lastday.getCrbal(), 0D, 0D, 0D, 0D, lastday.getTenantId());
subjectdayDao.save(today);
}
}
- List<TSubjectbal> newSubjectBals = subjectbalDao.getUnsettleSubjectbal(String.valueOf(lastsettday), TenantContext.getTenantSchema());
+ List<TSubjectbal> newSubjectBals = subjectbalDao.getUnsettleSubjectbal(String.valueOf(lastsettday), TenantContextHolder.getContext().getTenant().getId());
if (!StringUtil.isEmpty(newSubjectBals)) {
for (TSubjectbal newSubject : newSubjectBals) {
TSubjectday today = new TSubjectday(newSubject.getSubjid(),String.valueOf(settledate), newSubject.getSubjno(), periodYear, periodMonth, newSubject.getBegindrbal(), newSubject.getBegincrbal(), 0D, 0D, 0D, 0D, newSubject.getTenantId());
subjectdayDao.save(today);
}
}
- List<TSubject> newFSubjnos = subjectDao.getNewSubjnos(String.valueOf(settledate), TenantContext.getTenantSchema()); //新增非末级科目
+ List<TSubject> newFSubjnos = subjectDao.getNewSubjnos(String.valueOf(settledate), TenantContextHolder.getContext().getTenant().getId()); //新增非末级科目
if (!StringUtil.isEmpty(newFSubjnos)) {
for (TSubject subj : newFSubjnos) {
double beginDrbal = 0;
@@ -289,22 +289,22 @@
//初始化末级科目期初余额(包含商户科目)
Map<String, Double> v_subjbaldict = new HashMap<String, Double>(0);
Map<String, Integer> v_subjbalflagdict = new HashMap<String, Integer>(0);
- List<MerchBean> subjectList = subjectdayDao.getEndSubjectbalInfos(String.valueOf(settledate), TenantContext.getTenantSchema());
+ List<MerchBean> subjectList = subjectdayDao.getEndSubjectbalInfos(String.valueOf(settledate), TenantContextHolder.getContext().getTenant().getId());
if (!StringUtil.isEmpty(subjectList)) {
for (MerchBean bean : subjectList) {
v_subjbaldict.put(bean.getShopaccno(), MoneyUtil.formatYuan(bean.getDramt() + bean.getCramt()));
}
}
- List<SubjectInfoBean> subjInfoList = subjectbalDao.getSubjectbalAndFlag(TenantContext.getTenantSchema());
+ List<SubjectInfoBean> subjInfoList = subjectbalDao.getSubjectbalAndFlag(TenantContextHolder.getContext().getTenant().getId());
for (SubjectInfoBean subj : subjInfoList) {
- TSubjectday tSubjectday = subjectdayDao.getSubjectDayById(String.valueOf(settledate), subj.getSubjno(), TenantContext.getTenantSchema());
+ TSubjectday tSubjectday = subjectdayDao.getSubjectDayById(String.valueOf(settledate), subj.getSubjno(), TenantContextHolder.getContext().getTenant().getId());
if (null == tSubjectday) {
throw new Exception("科目日结表无此科目记录[" + subj.getSubjno() + "]");
}
v_subjbalflagdict.put(subj.getSubjno(), subj.getBalflag());
- MerchBean suminfo = voucherDao.getSettleSuminfo(settledate, subj.getSubjno(), TenantContext.getTenantSchema());
+ MerchBean suminfo = voucherDao.getSettleSuminfo(settledate, subj.getSubjno(), TenantContextHolder.getContext().getTenant().getId());
double sumDramt = ((null == suminfo || null == suminfo.getDramt()) ? 0 : suminfo.getDramt().doubleValue());
double sumCramt = ((null == suminfo || null == suminfo.getCramt()) ? 0 : suminfo.getCramt().doubleValue());
tSubjectday.setDramt(sumDramt);
@@ -318,7 +318,7 @@
subjectdayDao.save(tSubjectday);
}
//根据二级更新一级科目日结
- List<TSubjectday> parentSubject = subjectdayDao.getParentSubjectday(String.valueOf(settledate), TenantContext.getTenantSchema());
+ List<TSubjectday> parentSubject = subjectdayDao.getParentSubjectday(String.valueOf(settledate), TenantContextHolder.getContext().getTenant().getId());
for (TSubjectday fsub : parentSubject) {
FSubjectInfoBean sumInfo = subjectdayDao.getParentSumInfo(String.valueOf(settledate), fsub.getSubjno(), fsub.getTenantId());
fsub.setBegindrbal((null == sumInfo || null == sumInfo.getBegindrbal()) ? 0D : sumInfo.getBegindrbal());
@@ -332,7 +332,7 @@
}
//批量更新凭证明细中商户或科目账户的余额
- List<TVoucherEntry> entryList = voucherEntryDao.getVoucherEntryByVoucherdate(settledate, TenantContext.getTenantSchema());
+ List<TVoucherEntry> entryList = voucherEntryDao.getVoucherEntryByVoucherdate(settledate, TenantContextHolder.getContext().getTenant().getId());
if (!StringUtil.isEmpty(entryList)) {
for (TVoucherEntry vce : entryList) {
if (Subject.SUBJNO_MACHANT_INCOME.equals(vce.getSubjno())) {
@@ -388,7 +388,7 @@
//核算科目日结表科目余额和凭证明细余额是否一致
for (String subjno : v_subjbaldict.keySet()) {
- TSubjectday tSubjectday = subjectdayDao.getSubjectDayById(String.valueOf(settledate), subjno, TenantContext.getTenantSchema());
+ TSubjectday tSubjectday = subjectdayDao.getSubjectDayById(String.valueOf(settledate), subjno, TenantContextHolder.getContext().getTenant().getId());
if (!MoneyUtil.moneyEqual(v_subjbaldict.get(subjno), tSubjectday.getDrbal() + tSubjectday.getCrbal())) {
throw new Exception("结算后检查失败:科目日结表期末余额不等,科目号[" + subjno + "],科目余额[" + (tSubjectday.getDrbal() + tSubjectday.getCrbal()) + "],凭证科目余额[" + v_subjbaldict.get(subjno) + "]");
}
@@ -404,8 +404,8 @@
}
//核对商户日结表余额表和科目日结表商户余额是否一致
- TSubjectday shopSubjectday = subjectdayDao.getSubjectDayById(String.valueOf(settledate), Subject.SUBJNO_MACHANT_INCOME, TenantContext.getTenantSchema());
- Double merchbal = shopaccdayDao.getSumBalance(String.valueOf(settledate), TenantContext.getTenantSchema()); //
+ TSubjectday shopSubjectday = subjectdayDao.getSubjectDayById(String.valueOf(settledate), Subject.SUBJNO_MACHANT_INCOME, TenantContextHolder.getContext().getTenant().getId());
+ Double merchbal = shopaccdayDao.getSumBalance(String.valueOf(settledate), TenantContextHolder.getContext().getTenant().getId()); //
double shopSubbal = (shopSubjectday == null ? 0 : shopSubjectday.getCrbal());
double shopMerchbal = (merchbal == null ? 0 : merchbal);
if (!MoneyUtil.moneyEqual(shopSubbal, shopMerchbal)) {
@@ -413,7 +413,7 @@
}
//核算一级科目余额是否平衡
- FSubjectInfoBean allParentSubjbal = subjectdayDao.getAllParentSubjectSumInfo(String.valueOf(settledate), TenantContext.getTenantSchema());
+ FSubjectInfoBean allParentSubjbal = subjectdayDao.getAllParentSubjectSumInfo(String.valueOf(settledate), TenantContextHolder.getContext().getTenant().getId());
if (!MoneyUtil.moneyEqual(allParentSubjbal.getBegindrbal(), allParentSubjbal.getBegincrbal())) {
throw new Exception("结算后检查失败:一级科目余额表期初余额不平衡,借方[" + allParentSubjbal.getBegindrbal() + "],贷方[" + allParentSubjbal.getBegincrbal() + "]");
}
@@ -424,8 +424,8 @@
throw new Exception("结算后检查失败:一级科目余额表期末额不平衡,借方[" + allParentSubjbal.getDrbal() + "]贷方[" + allParentSubjbal.getCrbal() + "]");
}
//校验科目余额表的balflag=1的总期末余额和balflag=2的总期末余额是否一致
- Double balflag_1_sumbal = subjectbalDao.getSumEndsubjectBalByEndflag(1, TenantContext.getTenantSchema());
- Double balflag_2_sumbal = subjectbalDao.getSumEndsubjectBalByEndflag(2, TenantContext.getTenantSchema());
+ Double balflag_1_sumbal = subjectbalDao.getSumEndsubjectBalByEndflag(1, TenantContextHolder.getContext().getTenant().getId());
+ Double balflag_2_sumbal = subjectbalDao.getSumEndsubjectBalByEndflag(2, TenantContextHolder.getContext().getTenant().getId());
if (null == balflag_1_sumbal || null == balflag_1_sumbal) throw new Exception("结算后检查失败:科目余额表无数据");
if (!MoneyUtil.moneyEqual(balflag_1_sumbal, balflag_2_sumbal)) {
throw new Exception("结算后检查失败:科目余额表期末余额不平衡,借方[" + balflag_1_sumbal + "],贷方[" + balflag_2_sumbal + "]");
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/framework/service/impl/SystemUtilServiceImpl.java b/payapi/src/main/java/com/supwisdom/dlpay/framework/service/impl/SystemUtilServiceImpl.java
index a15f4de..e3eefc4 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/framework/service/impl/SystemUtilServiceImpl.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/framework/service/impl/SystemUtilServiceImpl.java
@@ -1,13 +1,14 @@
package com.supwisdom.dlpay.framework.service.impl;
-import com.supwisdom.dlpay.exception.TransactionCheckException;
import com.supwisdom.dlpay.exception.TransactionProcessException;
import com.supwisdom.dlpay.framework.core.DatabaseConfig;
import com.supwisdom.dlpay.framework.dao.*;
import com.supwisdom.dlpay.framework.data.SystemDateTime;
-import com.supwisdom.dlpay.framework.domain.*;
+import com.supwisdom.dlpay.framework.domain.TBusinesspara;
+import com.supwisdom.dlpay.framework.domain.TSettlectl;
+import com.supwisdom.dlpay.framework.domain.TSyspara;
+import com.supwisdom.dlpay.framework.domain.TTranscode;
import com.supwisdom.dlpay.framework.service.SystemUtilService;
-import com.supwisdom.dlpay.framework.util.DateUtil;
import com.supwisdom.dlpay.framework.util.NumberUtil;
import com.supwisdom.dlpay.framework.util.StringUtil;
import com.supwisdom.dlpay.framework.util.TradeErrorCode;
@@ -16,10 +17,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import java.sql.Timestamp;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
@Service
public class SystemUtilServiceImpl implements SystemUtilService {
@Autowired
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/HibernateConfig.java b/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/HibernateConfig.java
deleted file mode 100644
index bff7098..0000000
--- a/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/HibernateConfig.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package com.supwisdom.dlpay.framework.tenant;
-
-import java.util.HashMap;
-import java.util.Map;
-import javax.sql.DataSource;
-
-import lombok.extern.slf4j.Slf4j;
-import org.hibernate.MultiTenancyStrategy;
-import org.hibernate.cfg.Environment;
-import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
-import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties;
-import org.springframework.boot.autoconfigure.orm.jpa.HibernateSettings;
-import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.orm.jpa.JpaVendorAdapter;
-import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
-import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
-
-
-@Configuration
-@Slf4j
-public class HibernateConfig {
-
- private final JpaProperties jpaProperties;
-
- private final HibernateProperties hibernateProperties;
-
- public HibernateConfig(@Autowired JpaProperties jpaProperties,
- HibernateProperties hibernateProperties) {
- this.jpaProperties = jpaProperties;
- this.hibernateProperties = hibernateProperties;
- }
-
- @Bean
- public JpaVendorAdapter getJpaVendorAdapter() {
- HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
- adapter.setGenerateDdl(true);
- return adapter;
- }
-
- @Bean("entityManagerFactory")
- public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean(DataSource dataSource,
- MultiTenantConnectionProvider multiTenantConnectionProvider,
- CurrentTenantIdentifierResolver currentTenantIdentifierResolver) {
- Map<String, Object> properties = new HashMap<>();
- properties.putAll(hibernateProperties
- .determineHibernateProperties(jpaProperties.getProperties(),
- new HibernateSettings()));
- properties.put(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
- properties.put(Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProvider);
- properties.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolver);
-
- LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
- em.setDataSource(dataSource);
- em.setPackagesToScan("com.supwisdom");
- em.setJpaPropertyMap(properties);
- em.setJpaVendorAdapter(getJpaVendorAdapter());
- log.info("setup multi-tenant entityManagerFactor");
- return em;
- }
-
-}
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/MultiTenantConnectionProviderImpl.java b/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/MultiTenantConnectionProviderImpl.java
deleted file mode 100644
index 0666b65..0000000
--- a/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/MultiTenantConnectionProviderImpl.java
+++ /dev/null
@@ -1,71 +0,0 @@
-package com.supwisdom.dlpay.framework.tenant;
-
-import com.supwisdom.dlpay.framework.util.StringUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.hibernate.HibernateException;
-import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.SQLException;
-
-/**
- * Created by shuwei on 2018/12/4.
- */
-@Slf4j
-@Component
-public class MultiTenantConnectionProviderImpl implements MultiTenantConnectionProvider {
- @Autowired
- private DataSource dataSource;
-
- @Override
- public Connection getAnyConnection() throws SQLException {
- return dataSource.getConnection();
- }
-
- @Override
- public void releaseAnyConnection(Connection connection) throws SQLException {
- connection.close();
- }
-
- @Override
- public Connection getConnection(String ti) throws SQLException {
- String tenantIdentifier = TenantContext.getTenantSchema();
- final Connection connection = getAnyConnection();
- try {
- if (!StringUtil.isEmpty(tenantIdentifier)) {
- log.debug("postgresql set search path to <" + tenantIdentifier + ">");
- connection.createStatement().execute("SET search_path = \"" + tenantIdentifier + "\", public");
- } else {
- log.debug("postgresql set search path to public");
- connection.createStatement().execute("SET search_path = public");
- }
- } catch (SQLException e) {
- throw new HibernateException("Problem setting schema to " + tenantIdentifier, e);
- }
- return connection;
- }
-
- @Override
- public void releaseConnection(String tenantIdentifier, Connection connection) throws SQLException {
- connection.close();
- }
-
- @Override
- public boolean supportsAggressiveRelease() {
- return false;
- }
-
- @SuppressWarnings("rawtypes")
- @Override
- public boolean isUnwrappableAs(Class unwrapType) {
- return false;
- }
-
- @Override
- public <T> T unwrap(Class<T> unwrapType) {
- return null;
- }
-}
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/MultiTenantIdentifierResolver.java b/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/MultiTenantIdentifierResolver.java
deleted file mode 100644
index c1dc432..0000000
--- a/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/MultiTenantIdentifierResolver.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.supwisdom.dlpay.framework.tenant;
-
-import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
-import org.springframework.stereotype.Component;
-
-/**
- * Created by shuwei on 2018/12/4.
- */
-@Component
-public class MultiTenantIdentifierResolver implements CurrentTenantIdentifierResolver {
- @Override
- public String resolveCurrentTenantIdentifier() {
- if (TenantContext.getTenantSchema() == null) {
- return "default";
- }
- return TenantContext.getTenantSchema();
- }
-
- @Override
- public boolean validateExistingCurrentSessions() {
- return true;
- }
-}
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/TenantCacheKeyGen.java b/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/TenantCacheKeyGen.java
index 254c4e4..fa72e3e 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/TenantCacheKeyGen.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/TenantCacheKeyGen.java
@@ -1,6 +1,7 @@
package com.supwisdom.dlpay.framework.tenant;
+import com.supwisdom.multitenant.TenantContextHolder;
import org.apache.commons.lang3.StringUtils;
import org.springframework.cache.interceptor.KeyGenerator;
@@ -14,7 +15,7 @@
StringBuilder name = new StringBuilder();
name.append(target.getClass().getSimpleName())
.append(delimiter);
- String tenant = TenantContext.getTenantSchema();
+ String tenant = TenantContextHolder.getContext().getTenant().getId();
if (StringUtils.isEmpty(tenant)) {
tenant = "default";
}
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/TenantContext.java b/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/TenantContext.java
deleted file mode 100644
index c1d4ca4..0000000
--- a/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/TenantContext.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.supwisdom.dlpay.framework.tenant;
-
-/**
- * Created by shuwei on 2018/11/29.
- */
-public class TenantContext {
- private static ThreadLocal<String> currentTenant = new ThreadLocal<>();
-
- public static void setTenantSchema(String tid) {
- currentTenant.set(tid);
- }
-
- public static String getTenantSchema() {
- return currentTenant.get();
- }
-
- public static void clear() {
- currentTenant.set(null);
- }
-}
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/TenantHolder.java b/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/TenantHolder.java
index 585767f..21311c7 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/TenantHolder.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/TenantHolder.java
@@ -1,5 +1,6 @@
package com.supwisdom.dlpay.framework.tenant;
+import com.supwisdom.multitenant.TenantContextHolder;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
@@ -8,7 +9,7 @@
private static final char delimiter = '-';
public String getId() {
- String id = TenantContext.getTenantSchema();
+ String id = TenantContextHolder.getContext().getTenant().getId();
if (id == null || StringUtils.isEmpty(id)) {
return "default";
}
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/TenantInterceptor.java b/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/TenantInterceptor.java
deleted file mode 100644
index e60b957..0000000
--- a/payapi/src/main/java/com/supwisdom/dlpay/framework/tenant/TenantInterceptor.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.supwisdom.dlpay.framework.tenant;
-
-import com.supwisdom.dlpay.framework.domain.TOperator;
-import com.supwisdom.dlpay.framework.util.Constants;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.stereotype.Component;
-import org.springframework.web.servlet.ModelAndView;
-import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-@Component
-public class TenantInterceptor extends HandlerInterceptorAdapter {
-
- @Override
- public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
- throws Exception {
- String tenantId = request.getHeader(Constants.HEADER_TETANTID);
- Authentication auth = SecurityContextHolder.getContext().getAuthentication();
- if (auth != null && auth.getPrincipal() instanceof TOperator) {
- TOperator oper = (TOperator) auth.getPrincipal();
- if (tenantId != null && !oper.getTenantId().equals(tenantId)) {
- throw new RuntimeException("tenant ID 不匹配");
- }
- TenantContext.setTenantSchema(oper.getTenantId());
- } else {
- TenantContext.setTenantSchema(tenantId);
- }
- return true;
- }
-
- @Override
- public void postHandle(HttpServletRequest request, HttpServletResponse response,
- Object handler, ModelAndView modelAndView)
- throws Exception {
- //
- }
-}
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/framework/util/Signature.java b/payapi/src/main/java/com/supwisdom/dlpay/framework/util/Signature.java
index a0173a0..35c05ac 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/framework/util/Signature.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/framework/util/Signature.java
@@ -1,7 +1,7 @@
package com.supwisdom.dlpay.framework.util;
import com.supwisdom.dlpay.api.util.HMACUtil;
-import com.supwisdom.dlpay.framework.tenant.TenantContext;
+import com.supwisdom.multitenant.TenantContextHolder;
public class Signature {
public static final String SPY_TAC = "DLzJi044R7QHhJCDhpjZId8d";
@@ -12,7 +12,7 @@
}
public static String generateTac(String factor, String data) {
- String tenant = TenantContext.getTenantSchema();
+ String tenant = TenantContextHolder.getContext().getTenant().getId();
if (tenant == null) {
throw new IllegalArgumentException("TenantID 未定义");
}
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/system/controller/FunctionController.java b/payapi/src/main/java/com/supwisdom/dlpay/system/controller/FunctionController.java
index c2dc9d1..63e821c 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/system/controller/FunctionController.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/system/controller/FunctionController.java
@@ -4,11 +4,11 @@
import com.supwisdom.dlpay.api.bean.JsonResult;
import com.supwisdom.dlpay.framework.domain.TFunction;
import com.supwisdom.dlpay.framework.domain.TResource;
-import com.supwisdom.dlpay.framework.tenant.TenantContext;
import com.supwisdom.dlpay.framework.util.PageResult;
import com.supwisdom.dlpay.framework.util.WebConstant;
import com.supwisdom.dlpay.system.bean.FunctionSearchBean;
import com.supwisdom.dlpay.system.service.FunctionService;
+import com.supwisdom.multitenant.TenantContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
@@ -59,7 +59,7 @@
@ResponseBody
public JsonResult add(@RequestBody TFunction function) {
if (function != null) {
- function.setTenantId(TenantContext.getTenantSchema());
+ function.setTenantId(TenantContextHolder.getContext().getTenant().getId());
return functionService.saveFunction(function);
} else {
return JsonResult.error("添加失败");
@@ -124,7 +124,7 @@
public JsonResult addres(@RequestBody TResource resource) {
if (resource != null) {
if(null == resource.getTenantId()){
- resource.setTenantId(TenantContext.getTenantSchema());
+ resource.setTenantId(TenantContextHolder.getContext().getTenant().getId());
}
return functionService.saveRes(resource);
} else {
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/system/controller/ParamController.java b/payapi/src/main/java/com/supwisdom/dlpay/system/controller/ParamController.java
index 22f391e..7dc43bf 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/system/controller/ParamController.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/system/controller/ParamController.java
@@ -9,12 +9,12 @@
import com.supwisdom.dlpay.framework.domain.TBusinesspara;
import com.supwisdom.dlpay.framework.domain.TSyspara;
import com.supwisdom.dlpay.framework.service.SystemUtilService;
-import com.supwisdom.dlpay.framework.tenant.TenantContext;
import com.supwisdom.dlpay.framework.util.*;
import com.supwisdom.dlpay.system.service.DictionaryProxy;
import com.supwisdom.dlpay.system.service.ParamService;
import com.supwisdom.dlpay.util.ConstantUtil;
import com.supwisdom.dlpay.util.WebCheckException;
+import com.supwisdom.multitenant.TenantContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
@@ -354,7 +354,7 @@
apiClient.setAppid(appid.trim());
apiClient.setSecret(RandomUtils.getUUIDStr());
apiClient.setStatus(TradeDict.STATUS_NORMAL);
- apiClient.setTenantId(TenantContext.getTenantSchema());
+ apiClient.setTenantId(TenantContextHolder.getContext().getTenant().getId());
apiClient.setRoles(roles.replaceAll(",", ";"));
if (paramService.saveOrUpdateApiClient(apiClient)) {
return JsonResult.ok("新增成功");
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/OperatorServiceImpl.java b/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/OperatorServiceImpl.java
index 508361c..7a7ca11 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/OperatorServiceImpl.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/OperatorServiceImpl.java
@@ -6,11 +6,11 @@
import com.supwisdom.dlpay.framework.domain.TOperLog;
import com.supwisdom.dlpay.framework.domain.TOperRole;
import com.supwisdom.dlpay.framework.domain.TOperator;
-import com.supwisdom.dlpay.framework.tenant.TenantContext;
import com.supwisdom.dlpay.framework.util.*;
import com.supwisdom.dlpay.system.bean.LogBean;
import com.supwisdom.dlpay.system.bean.OperatorSearchBean;
import com.supwisdom.dlpay.system.service.OperatorService;
+import com.supwisdom.multitenant.TenantContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
@@ -78,10 +78,10 @@
operator.setOpendate(DateUtil.getNow("yyyyMMdd"));
operator.setStatus(TradeDict.STATUS_NORMAL);
operator.setOpertype(WebConstant.OPERTYPE_DEFAULT);
- operator.setTenantId(TenantContext.getTenantSchema());
+ operator.setTenantId(TenantContextHolder.getContext().getTenant().getId());
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
operator.setOperpwd(encoder.encode(WebConstant.OPERPWD_DEFAULT));
- operator.setTenantId(TenantContext.getTenantSchema());
+ operator.setTenantId(TenantContextHolder.getContext().getTenant().getId());
operator = operatorDao.save(operator);
for (String role : roleids) {
TOperRole operRole = new TOperRole();
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/ParamServiceImpl.java b/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/ParamServiceImpl.java
index 88e7e1b..46c8b14 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/ParamServiceImpl.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/ParamServiceImpl.java
@@ -10,13 +10,12 @@
import com.supwisdom.dlpay.framework.domain.TApiClient;
import com.supwisdom.dlpay.framework.domain.TBusinesspara;
import com.supwisdom.dlpay.framework.domain.TSyspara;
-import com.supwisdom.dlpay.framework.tenant.TenantContext;
-import com.supwisdom.dlpay.framework.tenant.TenantHolder;
import com.supwisdom.dlpay.framework.util.PageResult;
import com.supwisdom.dlpay.framework.util.StringUtil;
import com.supwisdom.dlpay.system.service.ParamService;
import com.supwisdom.dlpay.util.ConstantUtil;
import com.supwisdom.dlpay.util.WebCheckException;
+import com.supwisdom.multitenant.TenantContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
@@ -112,7 +111,7 @@
@Override
public boolean saveOrUpdateBusinesspara(TBusinesspara businesspara) {
if (null != businesspara) {
- businesspara.setTenantId(TenantContext.getTenantSchema());
+ businesspara.setTenantId(TenantContextHolder.getContext().getTenant().getId());
businessparaDao.save(businesspara);
return true;
}
@@ -182,7 +181,7 @@
@CacheEvict(cacheNames = "dictionary_cache", key = "@tenantHolder.genKey('sourcetype', #sourceType.sourceType)")
public boolean saveOrUpdateSourceType(TSourceType sourceType) {
if (null != sourceType) {
- sourceType.setTenantid(TenantContext.getTenantSchema());
+ sourceType.setTenantid(TenantContextHolder.getContext().getTenant().getId());
sourceTypeDao.save(sourceType);
return true;
}
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/RoleServiceImpl.java b/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/RoleServiceImpl.java
index ce04c41..0d908a2 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/RoleServiceImpl.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/RoleServiceImpl.java
@@ -7,13 +7,13 @@
import com.supwisdom.dlpay.framework.domain.TResource;
import com.supwisdom.dlpay.framework.domain.TRole;
import com.supwisdom.dlpay.framework.domain.TRoleFunction;
-import com.supwisdom.dlpay.framework.tenant.TenantContext;
import com.supwisdom.dlpay.framework.util.DateUtil;
import com.supwisdom.dlpay.framework.util.PageResult;
import com.supwisdom.dlpay.framework.util.StringUtil;
import com.supwisdom.dlpay.system.bean.FunctionSearchBean;
import com.supwisdom.dlpay.system.bean.ZTreeNode;
import com.supwisdom.dlpay.system.service.RoleService;
+import com.supwisdom.multitenant.TenantContextHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -96,7 +96,7 @@
temp.setRoleName(role.getRoleName());
temp.setRoleDesc(role.getRoleDesc());
temp.setLastsaved(DateUtil.getNow());
- temp.setTenantId(TenantContext.getTenantSchema());
+ temp.setTenantId(TenantContextHolder.getContext().getTenant().getId());
roleDao.save(temp);
} else {
TRole temp = roleDao.findByRoleName(role.getRoleName());
@@ -107,7 +107,7 @@
role.setCreatetime(DateUtil.getNow());
role.setEditflag(1);
role.setRoleCode("ROLE_ADMIN");
- role.setTenantId(TenantContext.getTenantSchema());
+ role.setTenantId(TenantContextHolder.getContext().getTenant().getId());
roleDao.save(role);
}
return JsonResult.ok("成功");
@@ -134,7 +134,7 @@
TPermission perm = new TPermission();
perm.setRoleId(roleId);
perm.setResid(resId);
- perm.setTenantId(TenantContext.getTenantSchema());
+ perm.setTenantId(TenantContextHolder.getContext().getTenant().getId());
return perm;
}
@@ -147,7 +147,7 @@
TRoleFunction func = new TRoleFunction();
func.setFunctionId(funcId);
func.setRoleId(roleId);
- func.setTenantId(TenantContext.getTenantSchema());
+ func.setTenantId(TenantContextHolder.getContext().getTenant().getId());
return func;
}
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/ShopDataServiceImpl.java b/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/ShopDataServiceImpl.java
index 1cccf99..d647d39 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/ShopDataServiceImpl.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/ShopDataServiceImpl.java
@@ -17,13 +17,13 @@
import com.supwisdom.dlpay.framework.data.SystemDateTime;
import com.supwisdom.dlpay.framework.domain.*;
import com.supwisdom.dlpay.framework.service.SystemUtilService;
-import com.supwisdom.dlpay.framework.tenant.TenantContext;
import com.supwisdom.dlpay.framework.util.*;
import com.supwisdom.dlpay.system.bean.*;
import com.supwisdom.dlpay.system.service.ShopDataService;
import com.supwisdom.dlpay.util.ConstantUtil;
import com.supwisdom.dlpay.util.EnumCheck;
import com.supwisdom.dlpay.util.WebCheckException;
+import com.supwisdom.multitenant.TenantContextHolder;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@@ -174,7 +174,7 @@
SystemDateTime dt = systemUtilService.getSysdatetime();
shop.setOpendate(dt.getHostdate());
- shop.setTenantId(TenantContext.getTenantSchema());
+ shop.setTenantId(TenantContextHolder.getContext().getTenant().getId());
shop.setAddOperid(oper == null ? null : oper.getOperid());
if (!needCheck) {
//不需要审核
@@ -328,7 +328,7 @@
//新增
SystemDateTime dt = systemUtilService.getSysdatetime();
shop.setOpendate(dt.getHostdate());
- shop.setTenantId(TenantContext.getTenantSchema());
+ shop.setTenantId(TenantContextHolder.getContext().getTenant().getId());
shopDao.save(shop);
if (enumUtil.isInEnums(shop.getShoptype(), ShopTypes.NORMAL)) {
TShopacc shopacc = new TShopacc();
@@ -413,7 +413,7 @@
@Override
public boolean saveOrUpdateShopPaytype(TShopSourceType shopPaytype) {
if (null != shopPaytype) {
- shopPaytype.setTenantid(TenantContext.getTenantSchema());
+ shopPaytype.setTenantid(TenantContextHolder.getContext().getTenant().getId());
shopSourceTypeDao.save(shopPaytype);
return true;
}
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/SourcetypeCheckManagerServiceImpl.java b/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/SourcetypeCheckManagerServiceImpl.java
index b8790ae..a34165a 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/SourcetypeCheckManagerServiceImpl.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/SourcetypeCheckManagerServiceImpl.java
@@ -8,11 +8,11 @@
import com.supwisdom.dlpay.api.domain.TSourceTypeCheckStatus;
import com.supwisdom.dlpay.api.domain.TTransactionChkdtl;
import com.supwisdom.dlpay.api.domain.TTransactionChkfile;
-import com.supwisdom.dlpay.framework.tenant.TenantContext;
import com.supwisdom.dlpay.framework.util.DateUtil;
import com.supwisdom.dlpay.framework.util.PageResult;
import com.supwisdom.dlpay.framework.util.StringUtil;
import com.supwisdom.dlpay.system.service.SourcetypeCheckManagerService;
+import com.supwisdom.multitenant.TenantContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
@@ -88,7 +88,7 @@
@Override
public List<TSourceType> getNeedCheckSourcetype() {
- List<TSourceType> list = sourceTypeDao.findNeedChecks(TenantContext.getTenantSchema());
+ List<TSourceType> list = sourceTypeDao.findNeedChecks(TenantContextHolder.getContext().getTenant().getId());
if (!StringUtil.isEmpty(list)) {
return list;
}
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/UserDataServiceImpl.java b/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/UserDataServiceImpl.java
index 01105f8..549412b 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/UserDataServiceImpl.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/system/service/impl/UserDataServiceImpl.java
@@ -7,7 +7,6 @@
import com.supwisdom.dlpay.api.types.SexTypes;
import com.supwisdom.dlpay.framework.data.SystemDateTime;
import com.supwisdom.dlpay.framework.service.SystemUtilService;
-import com.supwisdom.dlpay.framework.tenant.TenantContext;
import com.supwisdom.dlpay.framework.util.*;
import com.supwisdom.dlpay.system.bean.CitizenCardSearchBean;
import com.supwisdom.dlpay.system.bean.CitizenCardShowBean;
@@ -15,6 +14,7 @@
import com.supwisdom.dlpay.system.service.UserDataService;
import com.supwisdom.dlpay.util.ConstantUtil;
import com.supwisdom.dlpay.util.WebCheckException;
+import com.supwisdom.multitenant.TenantContextHolder;
import org.hibernate.query.internal.NativeQueryImpl;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
@@ -103,7 +103,7 @@
person.setStatus(TradeDict.STATUS_NORMAL);
}
person.setLastsaved(systemUtilService.getSysdatetime().getHostdatetime());
- person.setTenantid(TenantContext.getTenantSchema());
+ person.setTenantid(TenantContextHolder.getContext().getTenant().getId());
personDao.save(person);
return JsonResult.ok("修改成功");
} else {
@@ -114,7 +114,7 @@
SystemDateTime systemDateTime = systemUtilService.getSysdatetime();
person.setStatus(TradeDict.STATUS_NORMAL);
person.setLastsaved(systemDateTime.getHostdatetime());
- person.setTenantid(TenantContext.getTenantSchema());
+ person.setTenantid(TenantContextHolder.getContext().getTenant().getId());
person = personDao.save(person);
TAccount account = new TAccount();
@@ -344,7 +344,7 @@
person.setEmail(null == email ? null : email.trim());
person.setMobile(null == mobile ? null : mobile.trim());
person.setLastsaved(dt.getHostdatetime());
- person.setTenantid(TenantContext.getTenantSchema());
+ person.setTenantid(TenantContextHolder.getContext().getTenant().getId());
person = personDao.save(person);
TAccount account = new TAccount();
@@ -457,7 +457,7 @@
newPerson.setEmail(null == email ? null : email.trim());
newPerson.setMobile(null == mobile ? null : mobile.trim());
newPerson.setLastsaved(dt.getHostdatetime());
- newPerson.setTenantid(TenantContext.getTenantSchema());
+ newPerson.setTenantid(TenantContextHolder.getContext().getTenant().getId());
newPerson = personDao.save(newPerson);
TAccount account = new TAccount();
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/PayApiApplication.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/PayApiApplication.kt
index fd908eb..746f6b2 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/PayApiApplication.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/PayApiApplication.kt
@@ -1,6 +1,12 @@
package com.supwisdom.dlpay
+import com.supwisdom.dlpay.framework.dao.TenantCatalogDao
import com.supwisdom.dlpay.framework.tenant.TenantCacheKeyGen
+import com.supwisdom.dlpay.framework.util.Constants
+import com.supwisdom.multitenant.TenantDetails
+import com.supwisdom.multitenant.TenantDetailsProvider
+import com.supwisdom.multitenant.annotations.EnableHttpHeaderTenantInterceptor
+import com.supwisdom.multitenant.annotations.EnableSessionTenantInterceptor
import io.lettuce.core.ReadFrom
import mu.KotlinLogging
import net.javacrumbs.shedlock.core.LockProvider
@@ -161,10 +167,34 @@
}
}
+@Component
+class MyTenantDetailsProvider : TenantDetailsProvider {
+ @Autowired
+ private lateinit var tenantCatalogDao: TenantCatalogDao
+
+ private val defaultTenant = TenantDetails().apply {
+ id = Constants.DEFAULT_TENANTID
+ dbSchema = "public"
+ dataCenter = "defaul"
+ }
+
+ override fun createDetailsById(id: String?): TenantDetails {
+ return tenantCatalogDao.findTTenantCatalogByTenantid(id)?.let { catalog ->
+ TenantDetails().apply {
+ this.id = catalog.tenantid
+ dbSchema = catalog.tenantid
+ dataCenter = catalog.dataCenter
+ }
+ } ?: return defaultTenant
+ }
+}
+
@SpringBootApplication
@EnableDiscoveryClient
@EnableScheduling
@EnableCaching
+@EnableHttpHeaderTenantInterceptor
+@EnableSessionTenantInterceptor
@ServletComponentScan
class PayApiApplication : SpringBootServletInitializer() {
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/advices.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/advices.kt
index 19f5064..29f00d5 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/advices.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/advices.kt
@@ -2,11 +2,9 @@
import com.supwisdom.dlpay.api.bean.JsonResult
import com.supwisdom.dlpay.api.exception.RequestParamCheckException
-import com.supwisdom.dlpay.exception.TransactionCheckException
import com.supwisdom.dlpay.exception.TransactionException
import com.supwisdom.dlpay.framework.ResponseBodyBuilder
import com.supwisdom.dlpay.framework.service.CommonService
-import com.supwisdom.dlpay.framework.tenant.TenantContext
import com.supwisdom.dlpay.framework.util.TradeErrorCode
import mu.KotlinLogging
import org.aspectj.lang.ProceedingJoinPoint
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/async_tasks.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/async_tasks.kt
index 10541a8..b2b5ed4 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/async_tasks.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/async_tasks.kt
@@ -13,10 +13,11 @@
import com.supwisdom.dlpay.exception.TransactionException
import com.supwisdom.dlpay.framework.service.DayendSettleService
import com.supwisdom.dlpay.framework.service.SystemUtilService
-import com.supwisdom.dlpay.framework.tenant.TenantContext
import com.supwisdom.dlpay.framework.util.Constants
import com.supwisdom.dlpay.framework.util.StringUtil
import com.supwisdom.dlpay.util.ConstantUtil
+import com.supwisdom.multitenant.TenantContextHolder
+import com.supwisdom.multitenant.TenantDetailsProvider
import mu.KotlinLogging
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler
import org.springframework.beans.factory.annotation.Autowired
@@ -89,9 +90,12 @@
@Autowired
private lateinit var shopaccService: ShopaccService
+ @Autowired
+ private lateinit var tenantDetailsProvider: TenantDetailsProvider
+
@Async("shopAccBalanceUpdater")
fun updateShopBalance(shopdtl: TShopdtl) {
- TenantContext.setTenantSchema(shopdtl.tenantid)
+ TenantContextHolder.getContext().tenant = tenantDetailsProvider.createDetailsById(shopdtl.tenantid)
shopaccService.recalcShopBalance(shopdtl.refno, true)
}
}
@@ -112,10 +116,13 @@
@Autowired
private lateinit var systemUtilService: SystemUtilService
+ @Autowired
+ private lateinit var tenantDetailsProvider: TenantDetailsProvider
+
@Async("queryAgentPayResult")
fun queryResult(transaction: TTransactionMain, qcnt: Int) {
try {
- if (null == TenantContext.getTenantSchema()) TenantContext.setTenantSchema(transaction.tenantid)
+ TenantContextHolder.getContext().tenant = tenantDetailsProvider.createDetailsById(transaction.tenantid)
if (qcnt >= YnrccUtil.QUERY_MAX_COUNT) {
//查询超最大次数
@@ -185,10 +192,13 @@
private val logger = KotlinLogging.logger { }
+ @Autowired
+ private lateinit var tenantDetailsProvider: TenantDetailsProvider
+
@Async("handSettlementAsyncTask")
fun doHandSettleTask() {
logger.info("进入手动发起的异步结算:")
- if (null == TenantContext.getTenantSchema()) TenantContext.setTenantSchema(Constants.DEFAULT_TENANTID)
+ TenantContextHolder.getContext().tenant = tenantDetailsProvider.createDetailsById(Constants.DEFAULT_TENANTID)
val settleLog = dayendSettleService.doCreateSettleLog() //记录日志
try {
val ret = dayendSettleService.doDayendSettle()
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/dali_datasync_api_controller.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/dali_datasync_api_controller.kt
index 32c43b6..212dae7 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/dali_datasync_api_controller.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/dali_datasync_api_controller.kt
@@ -8,8 +8,6 @@
import com.supwisdom.dlpay.api.service.DaliDatasyncService
import com.supwisdom.dlpay.framework.ResponseBodyBuilder
import com.supwisdom.dlpay.framework.service.SystemUtilService
-import com.supwisdom.dlpay.framework.tenant.TenantContext
-import com.supwisdom.dlpay.framework.util.Constants
import com.supwisdom.dlpay.framework.util.DateUtil
import com.supwisdom.dlpay.framework.util.StringUtil
import com.supwisdom.dlpay.framework.util.SysparaUtil
@@ -17,7 +15,7 @@
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
-import java.io.*
+import java.io.File
import java.nio.charset.Charset
@RequestMapping("/api/common/dlcard")
@@ -38,7 +36,6 @@
@PostMapping("/datasync")
fun daliDatasync(@RequestBody param: DaliDatasyncParam): ResponseEntity<Any> {
try {
- if (TenantContext.getTenantSchema() == null) TenantContext.setTenantSchema(Constants.DEFAULT_TENANTID) //fixme: tenantid设置
param.checkParam()
val appid = systemUtilService.getSysparaValue(SysparaUtil.DLCARDMANAGER_APPID)
val appkey = systemUtilService.getSysparaValue(SysparaUtil.DLCARDMANAGER_SECRET)
@@ -131,7 +128,6 @@
}
try {
- if (TenantContext.getTenantSchema() == null) TenantContext.setTenantSchema(Constants.DEFAULT_TENANTID) //fixme: tenantid设置
val txtFile = File(filename)
val batchSize = 1000
var sumCount = 0
@@ -219,7 +215,6 @@
}
try {
- if (TenantContext.getTenantSchema() == null) TenantContext.setTenantSchema(Constants.DEFAULT_TENANTID) //fixme: tenantid设置
var totalcnt = 0
var failcnt = 0
var detailMsg = ""
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/notify_api_controller.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/notify_api_controller.kt
index 3a133e2..e578794 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/notify_api_controller.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/notify_api_controller.kt
@@ -3,7 +3,8 @@
import com.supwisdom.dlpay.agent.AgentCode
import com.supwisdom.dlpay.agent.service.AlipayService
import com.supwisdom.dlpay.agent.service.WechatService
-import com.supwisdom.dlpay.framework.tenant.TenantContext
+import com.supwisdom.multitenant.TenantContextHolder
+import com.supwisdom.multitenant.TenantDetailsProvider
import org.dom4j.Element
import org.dom4j.io.SAXReader
import org.slf4j.LoggerFactory
@@ -27,13 +28,15 @@
lateinit var alipayService: AlipayService
@Autowired
lateinit var wechatService: WechatService
+ @Autowired
+ lateinit var tenantDetailsProvider: TenantDetailsProvider
@RequestMapping(value = ["/wechat/{schema}"])
@ResponseBody
fun index(@PathVariable schema: String, request: HttpServletRequest,
response: HttpServletResponse): String {
logger.error("====================== 收到微信回调通知 wechat notify: ========================")
- TenantContext.setTenantSchema(schema)
+ tenantDetailsProvider.defaultTenant(schema)
try {
// 解析结果存储在HashMap
var map: MutableMap<String, String> = HashMap()
@@ -87,7 +90,7 @@
fun alipay(@PathVariable schema: String, request: HttpServletRequest,
response: HttpServletResponse): String {
logger.error("====================== 收到支付宝回调通知 alipay notify: ========================")
- TenantContext.setTenantSchema(schema)
+ tenantDetailsProvider.defaultTenant(schema)
// 解析结果存储在HashMap
val map = makeMapFromParam(request)
val resp = alipayService.doNotify(map)
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/shop_api_controller.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/shop_api_controller.kt
index 97f2403..b1a0a54 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/shop_api_controller.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/shop_api_controller.kt
@@ -1,26 +1,23 @@
package com.supwisdom.dlpay.api.controller
-import com.supwisdom.dlpay.api.bean.DownloadShopBillData
import com.supwisdom.dlpay.api.bean.DownloadShopBillParam
import com.supwisdom.dlpay.api.bean.OpenShopParam
import com.supwisdom.dlpay.api.bean.QueryShopParam
import com.supwisdom.dlpay.api.exception.RequestParamCheckException
-import com.supwisdom.dlpay.framework.ResponseBodyBuilder
import com.supwisdom.dlpay.api.service.ShopService
import com.supwisdom.dlpay.exception.TransactionException
+import com.supwisdom.dlpay.framework.ResponseBodyBuilder
import com.supwisdom.dlpay.framework.service.CommonService
-import com.supwisdom.dlpay.framework.tenant.TenantContext
import com.supwisdom.dlpay.framework.util.TradeErrorCode
import com.supwisdom.dlpay.system.service.DtlDataService
import com.supwisdom.dlpay.util.ConstantUtil
-import org.apache.log4j.spi.ErrorCode
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
+import java.io.OutputStream
import java.net.URLDecoder
import java.nio.charset.StandardCharsets
import javax.servlet.http.HttpServletResponse
-import java.io.OutputStream as OutputStream
@RestController
@RequestMapping("/api/shop")
@@ -35,7 +32,6 @@
@PostMapping("/open")
fun openAccount(@RequestBody param: OpenShopParam): ResponseEntity<Any> {
try {
- TenantContext.setTenantSchema(param.tenantid)
shopService.findByThirdUniqueId(param.shopUniqueId)?.let {
return ResponseEntity.ok(ResponseBodyBuilder.create()
.fail(TradeErrorCode.BUSINESS_SHOP_EXISTS, "该商户唯一号[${param.shopUniqueId}]已经存在"))
@@ -62,7 +58,6 @@
@GetMapping("/query")
fun queryShop(@RequestBody param: QueryShopParam): ResponseEntity<Any> {
try {
- TenantContext.setTenantSchema(param.tenantid)
shopService.findByShopBySearch(param.shopid, param.shopaccno, param.shopUniqueId)?.let {
return ResponseEntity.ok(ResponseBodyBuilder.create()
.data("shop", it)
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/user_api_controller.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/user_api_controller.kt
index 59c4278..cf9fd8f 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/user_api_controller.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/user_api_controller.kt
@@ -9,17 +9,16 @@
import com.supwisdom.dlpay.exception.TransactionCheckException
import com.supwisdom.dlpay.exception.TransactionException
import com.supwisdom.dlpay.framework.ResponseBodyBuilder
-import com.supwisdom.dlpay.framework.tenant.TenantContext
import com.supwisdom.dlpay.framework.util.Subject
import com.supwisdom.dlpay.framework.util.TradeCode
import com.supwisdom.dlpay.framework.util.TradeDict
import com.supwisdom.dlpay.framework.util.TradeErrorCode
+import com.supwisdom.multitenant.TenantContextHolder
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.ResponseEntity
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.*
import java.net.URLDecoder
-import javax.validation.Valid
import kotlin.math.roundToInt
@RestController
@@ -303,7 +302,7 @@
val originTrans = transactionService.findTransactionByRefno(request.originRefno)
?: return ResponseBodyBuilder.failEntity(result, TradeErrorCode.TRANSACTION_NOT_EXISTS,
"退款原交易参考号不存在")
- if (originTrans.tenantid != TenantContext.getTenantSchema()) {
+ if (originTrans.tenantid != TenantContextHolder.getContext().tenant.id) {
return ResponseBodyBuilder.failEntity(result, TradeErrorCode.INPUT_DATA_ERROR,
"退款交易参考号租户错误")
}
@@ -354,7 +353,7 @@
?: throw TransactionCheckException(TradeErrorCode.TRANSACTION_NOT_EXISTS
, "交易不存在")
val result = CardBizResponse()
- if (transaction.tenantid != TenantContext.getTenantSchema()) {
+ if (transaction.tenantid != TenantContextHolder.getContext().tenant.id) {
return ResponseBodyBuilder.failEntity(result, TradeErrorCode.INPUT_DATA_ERROR,
"非本租户交易参考号")
}
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_sourcetype_chk.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_sourcetype_chk.kt
index eec664a..33d9a72 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_sourcetype_chk.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_sourcetype_chk.kt
@@ -11,15 +11,14 @@
import com.supwisdom.dlpay.api.service.TransactionReconciliationService
import com.supwisdom.dlpay.exception.TransactionException
import com.supwisdom.dlpay.framework.service.SystemUtilService
-import com.supwisdom.dlpay.framework.tenant.TenantContext
import com.supwisdom.dlpay.framework.util.Constants
import com.supwisdom.dlpay.framework.util.DateUtil
import com.supwisdom.dlpay.util.ConstantUtil
+import com.supwisdom.multitenant.TenantDetailsProvider
import mu.KotlinLogging
import net.javacrumbs.shedlock.core.SchedulerLock
import org.springframework.beans.BeansException
import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.context.ApplicationContext
import org.springframework.scheduling.annotation.Async
import org.springframework.scheduling.annotation.AsyncResult
import org.springframework.scheduling.annotation.Scheduled
@@ -81,6 +80,9 @@
@Autowired
private lateinit var sourceTypeCheckExecutor: SourceTypeCheckExecutor
+ @Autowired
+ private lateinit var tenantDetailsProvider: TenantDetailsProvider
+
private fun newSourceTypeStatus(sourceType: TSourceType, accdate: String): TSourceTypeCheckStatus {
return sourceTypeService.saveOrUpdateSourceTypeCheckStatus(TSourceTypeCheckStatus().apply {
this.sourceType = sourceType.sourceType
@@ -160,7 +162,7 @@
@Scheduled(cron = "\${payapi.sourcetype.checker.scheduler:-}")
@SchedulerLock(name = "payapiSourceTypeCheckLock", lockAtMostForString = "PT30M")
fun runCheck() {
- if (TenantContext.getTenantSchema() == null) TenantContext.setTenantSchema(Constants.DEFAULT_TENANTID)
+ tenantDetailsProvider.defaultTenant(Constants.DEFAULT_TENANTID)
val allSourcetype = sourceTypeService.allEnabledSourcetype
?: return
@@ -246,6 +248,9 @@
@Autowired
private lateinit var sourceTypeService: SourceTypeService
+ @Autowired
+ private lateinit var tenantDetailsProvider: TenantDetailsProvider
+
private val logger = KotlinLogging.logger { }
private fun getProvider(sourcetype: String): CheckFileProvider? {
@@ -271,7 +276,7 @@
fun checkAndDownloadChkfile(checkStatus: TSourceTypeCheckStatus): Future<ExecutorResult> {
// 2. 根据对账日期下载对账文件
try {
- if (TenantContext.getTenantSchema() == null) TenantContext.setTenantSchema(checkStatus.tenantId)
+ tenantDetailsProvider.defaultTenant(Constants.DEFAULT_TENANTID)
if (checkStatus.settleStatus) {
return AsyncResult(ExecutorResult(checkStatus, FAIL, "[${checkStatus.checkAccdate}]日对账已完成"))
}
@@ -314,7 +319,7 @@
@Async("sourcetypeCheckTaskExecutor")
fun reconciliation(checkStatus: TSourceTypeCheckStatus): Future<ExecutorResult> {
// 3. 完成对账
- if (TenantContext.getTenantSchema() == null) TenantContext.setTenantSchema(checkStatus.tenantId)
+ tenantDetailsProvider.defaultTenant(Constants.DEFAULT_TENANTID)
if (!checkStatus.checkFileOk) {
return AsyncResult(ExecutorResult(checkStatus, FAIL, "checkAccdate=[${checkStatus.checkAccdate}]对账单未完成下载,不能对账"))
} else if (checkStatus.settleStatus) {
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_ynrccchk_task.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_ynrccchk_task.kt
deleted file mode 100644
index b1bc339..0000000
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_ynrccchk_task.kt
+++ /dev/null
@@ -1,166 +0,0 @@
-package com.supwisdom.dlpay.api
-
-import com.supwisdom.dlpay.agent.citizencard.YnrccUtil
-import com.supwisdom.dlpay.agent.service.CitizencardPayService
-import com.supwisdom.dlpay.api.service.SourceTypeService
-import com.supwisdom.dlpay.api.service.TransactionReconciliationService
-import com.supwisdom.dlpay.api.service.YnrccBusinessService
-import com.supwisdom.dlpay.framework.service.SystemUtilService
-import com.supwisdom.dlpay.framework.util.DateUtil
-import com.supwisdom.dlpay.framework.util.TradeDict
-import mu.KotlinLogging
-import net.javacrumbs.shedlock.core.SchedulerLock
-import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.scheduling.annotation.Scheduled
-import org.springframework.stereotype.Component
-import org.springframework.web.client.RestTemplate
-
-import com.sun.jersey.api.client.Client
-import com.sun.jersey.api.client.ClientResponse
-import com.supwisdom.dlpay.api.bean.YnrccChkfileBean
-import com.supwisdom.dlpay.api.domain.TTransactionChkfile
-import com.supwisdom.dlpay.framework.tenant.TenantContext
-import com.supwisdom.dlpay.framework.util.Constants
-import com.supwisdom.dlpay.framework.util.StringUtil
-import com.supwisdom.dlpay.util.ConstantUtil
-import java.io.BufferedReader
-import java.io.InputStream
-import java.io.InputStreamReader
-import javax.ws.rs.core.MediaType
-
-
-/**
- * 第三方对账任务
- * */
-@Component
-class DownloadYnrccChkfileTask {
- @Autowired
- private lateinit var systemUtilService: SystemUtilService
- @Autowired
- private lateinit var ynrccBusinessService: YnrccBusinessService
- @Autowired
- private lateinit var citizencardPayService: CitizencardPayService
- @Autowired
- private lateinit var transactionReconciliationService: TransactionReconciliationService
- @Autowired
- private lateinit var sourceTypeService: SourceTypeService
-
- private val logger = KotlinLogging.logger { }
-
-
-// @Scheduled(cron = "\${download.ynrcc.chkfile.cron:-}")
-// @SchedulerLock(name = "DownloadYnrccChkfileSchedulerTask", lockAtMostForString = "PT10M")
- fun doDownloadYnrccChkfile() {
- try {
- if (null == TenantContext.getTenantSchema()) TenantContext.setTenantSchema(Constants.DEFAULT_TENANTID)
- //下载对账单逻辑
- val hostdate = systemUtilService.sysdatetime.hostdate
- val downloadLastdate = ynrccBusinessService.getLastDownloadBillDate()
- val diffDays = DateUtil.getIntervalDay(downloadLastdate, hostdate).toInt()
- logger.info("大理农商行对账单下载:downloadLastdate=$downloadLastdate, hostdate=$hostdate, diffDays=$diffDays ")
-
- for (i in 1 until diffDays) {
- val billDate = DateUtil.getNewDay(downloadLastdate, i) //要取对账单的日期
-
- val chkfile = transactionReconciliationService.doInitTransactionChkfile(billDate, TradeDict.PAYTYPE_CITIZEN_CARD)
-
- val resp = citizencardPayService.getChkfilename(billDate, null)
- if (YnrccUtil.CODE_SUCCESS == resp.code) {
- val agentConfig = sourceTypeService.getChargePaytypeConfig(TradeDict.PAYTYPE_CITIZEN_CARD, true)
- val agentUrl = agentConfig[YnrccUtil.YNRCC_ANGENT_URL] + "/download?filename=" + resp.filename
- //根据filename 取文件数据
- downloadYnrccBills(chkfile, agentUrl)
-
- } else if (YnrccUtil.NO_RECORDS_TODAY == resp.code) {
- //当日无交易明细,也创建空记录
- transactionReconciliationService.doSuccessTransactionChkfile(chkfile, "请求银行返回:当日无交易明细")
-
- } else {
- //报错,退出对账单拉取
- logger.error("大理农商行对账单下载[$billDate]报错:${resp.message}")
- chkfile.status = ConstantUtil.CHKFILE_STATUS_ERROR
- chkfile.remark = "请求前置获取对账文件报错:${resp.message}"
- transactionReconciliationService.saveOrUpdateTransactionChkfile(chkfile)
- break
- }
- }
-
- } catch (ex: Exception) {
- ex.printStackTrace()
- }
- }
-
- private fun downloadYnrccBills(chkfile: TTransactionChkfile, agentUrl: String) {
- val client = Client.create()
- client.setConnectTimeout(30000)
- val respClient = client.resource(agentUrl).type(MediaType.APPLICATION_OCTET_STREAM_TYPE).get(ClientResponse::class.java)
- if (200 == respClient.status) {
- val stream = respClient.getEntity(InputStream::class.java)
- BufferedReader(InputStreamReader(stream)).use { reader ->
- val header = reader.readLine()
- val fields = header.split(",").mapNotNull { if (it.isNotEmpty()) it else null }
- val batchSize = 10000 //每次保存的数目
- var failcnt = 0
-
- val datalist = ArrayList<YnrccChkfileBean>()
- while (true) {
- val line = reader.readLine() ?: break
- if (line.isEmpty()) continue
- val columns = line.split(",").mapNotNull { if (it.isNotEmpty()) it else null }
- val bean = YnrccChkfileBean()
- StringUtil.transforToBean(fields, columns, bean)
- datalist.add(bean)
- if (datalist.size >= batchSize) {
- val fcnt = doBatchSaveYnrccCheckDetails(chkfile, datalist) //保存
- failcnt += fcnt
- datalist.clear()
- }
- }
- //保存最后的不足batchSize的记录
- if (datalist.size > 0) {
- val fcnt = doBatchSaveYnrccCheckDetails(chkfile, datalist) //保存
- failcnt += fcnt
- }
-
- if (failcnt > 0) {
- //该天对账单保存错误
- chkfile.status = ConstantUtil.CHKFILE_STATUS_ERROR
- chkfile.remark = "对账单数据存在保存失败记录,请手动核对对账单数据"
- transactionReconciliationService.saveOrUpdateTransactionChkfile(chkfile)
- return
- }
-
- //成功
- transactionReconciliationService.doSuccessTransactionChkfile(chkfile, "对账单数据下载成功")
-
- }
- } else {
- logger.error("请求前置download[${chkfile.accdate}]对账单返回失败:httpStatus=[${respClient.status}]。获取对账文件数据失败")
- chkfile.status = ConstantUtil.CHKFILE_STATUS_ERROR
- chkfile.remark = "请求前置获取对账单数据失败,download返回:httpStatus=${respClient.status}"
- transactionReconciliationService.saveOrUpdateTransactionChkfile(chkfile)
- }
- }
-
- private fun doBatchSaveYnrccCheckDetails(chkfile: TTransactionChkfile, list: ArrayList<YnrccChkfileBean>): Int {
- try {
- transactionReconciliationService.doBatchSaveYnrccTransactionChkDtl(chkfile, list)
- return 0 //批量保存成功,无失败
- } catch (e1: Exception) {
- }
-
- //批量保存有异常,逐笔保存
- var failcnt = 0
- for (bean in list) {
- try {
- transactionReconciliationService.saveYnrccTransactionChkDtl(chkfile, bean)
- } catch (e2: Exception) {
- failcnt++
- e2.printStackTrace()
- continue
- }
- }
- return failcnt
- }
-
-}
\ No newline at end of file
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/charge_api_service_impl.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/charge_api_service_impl.kt
index 52feed2..65df6c3 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/charge_api_service_impl.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/charge_api_service_impl.kt
@@ -8,8 +8,8 @@
import com.supwisdom.dlpay.api.domain.TTransactionMain
import com.supwisdom.dlpay.api.service.ChargeApiService
import com.supwisdom.dlpay.api.service.SourceTypeService
-import com.supwisdom.dlpay.framework.tenant.TenantContext
import com.supwisdom.dlpay.framework.util.StringUtil
+import com.supwisdom.multitenant.TenantContextHolder
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
@@ -41,10 +41,10 @@
}
override fun getDepositCapital(capital: String): TDepositCapitalType {
- return depositCapitalTypeDao.findTDepositCapitalTypeByCodeAndTenantid(capital, TenantContext.getTenantSchema());
+ return depositCapitalTypeDao.findTDepositCapitalTypeByCodeAndTenantid(capital, TenantContextHolder.getContext().tenant.id);
}
override fun findDepositCapitals(): List<TDepositCapitalType> {
- return depositCapitalTypeDao.findTDepositCapitalTypesByTenantid(TenantContext.getTenantSchema())
+ return depositCapitalTypeDao.findTDepositCapitalTypesByTenantid(TenantContextHolder.getContext().tenant.id)
}
}
\ No newline at end of file
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/dali_datasync_service_impl.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/dali_datasync_service_impl.kt
index 96b13f8..b256025 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/dali_datasync_service_impl.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/dali_datasync_service_impl.kt
@@ -13,9 +13,9 @@
import com.supwisdom.dlpay.api.types.IDTypes
import com.supwisdom.dlpay.exception.TransactionProcessException
import com.supwisdom.dlpay.framework.service.SystemUtilService
-import com.supwisdom.dlpay.framework.tenant.TenantContext
import com.supwisdom.dlpay.framework.util.*
import com.supwisdom.dlpay.util.ConstantUtil
+import com.supwisdom.multitenant.TenantContextHolder
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
@@ -102,7 +102,7 @@
mobile = bean.mobile
lastsaved = systime.hostdatetime
}
- person.tenantid = TenantContext.getTenantSchema()
+ person.tenantid = TenantContextHolder.getContext().tenant.id
person = personDao.save(person)
var account = TAccount().apply {
@@ -123,7 +123,7 @@
opendate = systime.hostdate
tac = Signature.SPY_TAC
}
- account.tenantid = TenantContext.getTenantSchema()
+ account.tenantid = TenantContextHolder.getContext().tenant.id
account = accountDao.save(account)
account.tac = account.generateTac()
accountDao.save(account)
@@ -179,7 +179,7 @@
userid = person.userid
lastsaved = systime.hostdatetime
}
- cityCard.tenantid = TenantContext.getTenantSchema()
+ cityCard.tenantid = TenantContextHolder.getContext().tenant.id
cardDao.save(cityCard)
}
@@ -203,7 +203,7 @@
if (TradeDict.STATUS_NORMAL == bankCard.status) {
cardDao.closedBankcardStatusByUserid(bankCard.userid) //注销其他银行卡
}
- bankCard.tenantid = TenantContext.getTenantSchema()
+ bankCard.tenantid = TenantContextHolder.getContext().tenant.id
cardDao.save(bankCard) //绑定新的银行卡
} else {
if (bankCard.userid != person.userid) {
@@ -239,7 +239,7 @@
this.status = TradeDict.DTL_STATUS_FAIL
this.remark = errmsg
this.lastsaved = systemUtilService.sysdatetime.hostdatetime
- this.tenantid = TenantContext.getTenantSchema()
+ this.tenantid = TenantContextHolder.getContext().tenant.id
})
}
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/dtl_query_result_service_impl.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/dtl_query_result_service_impl.kt
index a42427b..25dad23 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/dtl_query_result_service_impl.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/dtl_query_result_service_impl.kt
@@ -3,8 +3,8 @@
import com.supwisdom.dlpay.api.dao.DtlQueryDao
import com.supwisdom.dlpay.api.domain.TDtlQuery
import com.supwisdom.dlpay.api.service.DtlQueryResultService
-import com.supwisdom.dlpay.framework.tenant.TenantContext
import com.supwisdom.dlpay.util.ConstantUtil
+import com.supwisdom.multitenant.TenantContextHolder
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
@@ -15,7 +15,7 @@
override fun saveOrUpdateDtlQuery(dtlQuery: TDtlQuery): TDtlQuery {
if (null == dtlQuery.tenantId) {
- dtlQuery.tenantId = TenantContext.getTenantSchema()
+ dtlQuery.tenantId = TenantContextHolder.getContext().tenant.id
}
return dtlQueryDao.save(dtlQuery)
}
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/pay_service_impl.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/pay_service_impl.kt
index 1807686..f8c9295 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/pay_service_impl.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/pay_service_impl.kt
@@ -11,8 +11,8 @@
import com.supwisdom.dlpay.framework.domain.TFeetypeConfig
import com.supwisdom.dlpay.framework.domain.TShopacc
import com.supwisdom.dlpay.framework.domain.TSubject
-import com.supwisdom.dlpay.framework.tenant.TenantContext
import com.supwisdom.dlpay.framework.util.TradeErrorCode
+import com.supwisdom.multitenant.TenantContextHolder
import org.hibernate.exception.LockTimeoutException
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.dao.CannotAcquireLockException
@@ -74,13 +74,13 @@
}
override fun readShopbyShopaccno(shopaccno: String): TShopacc {
- return shopaccDao.getByShopaccnoAndTenantId(shopaccno, TenantContext.getTenantSchema())?.also {
+ return shopaccDao.getByShopaccnoAndTenantId(shopaccno, TenantContextHolder.getContext().tenant.id)?.also {
shopAccCheck(it)
} ?: throw TransactionProcessException(TradeErrorCode.SHOP_NOT_EXISTS, "商户<$shopaccno>不存在")
}
override fun readSubject(subjno: String): TSubject {
- return subjectDao.findBySubjnoAndTenantId(subjno, TenantContext.getTenantSchema())
+ return subjectDao.findBySubjnoAndTenantId(subjno, TenantContextHolder.getContext().tenant.id)
?: throw TransactionProcessException(TradeErrorCode.SUBJECT_NOT_EXISTS, "科目<$subjno>不存在")
}
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/shop_service_impl.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/shop_service_impl.kt
index b0dbb6b..3d81b97 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/shop_service_impl.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/shop_service_impl.kt
@@ -14,13 +14,11 @@
import com.supwisdom.dlpay.framework.domain.TShop
import com.supwisdom.dlpay.framework.domain.TShopacc
import com.supwisdom.dlpay.framework.service.SystemUtilService
-import com.supwisdom.dlpay.framework.tenant.TenantContext
import com.supwisdom.dlpay.framework.util.*
import com.supwisdom.dlpay.util.EnumCheck
+import com.supwisdom.multitenant.TenantContextHolder
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
-import javax.persistence.EntityManager
-import javax.persistence.PersistenceContext
/**
* Created by shuwei on 2019/4/15.
@@ -112,8 +110,9 @@
override fun checkDownloadShopBillParam(param: DownloadShopBillParam): Boolean {
if (!StringUtil.isEmpty(param.checkdate)) {
- val ctl = settleCtlDao.findByTenantId(TenantContext.getTenantSchema())
- ?: throw TransactionProcessException(TradeErrorCode.BUSINESS_DEAL_ERROR, "[tenantid=${TenantContext.getTenantSchema()}]未找到结算状态表")
+ val ctl = settleCtlDao.findByTenantId(TenantContextHolder.getContext().tenant.id)
+ ?: throw TransactionProcessException(TradeErrorCode.BUSINESS_DEAL_ERROR,
+ "[tenantid=${TenantContextHolder.getContext().tenant.id}]未找到结算状态表")
if (DateUtil.compareDatetime(param.checkdate, "${ctl.settledate}", "yyyyMMdd") >= 0) {
throw TransactionProcessException(TradeErrorCode.INPUT_DATA_ERROR, "对账单未生成") //未结算,不返回对账单
}
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/transaction_reconciliation_service_impl.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/transaction_reconciliation_service_impl.kt
index 9937a31..5585033 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/transaction_reconciliation_service_impl.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/transaction_reconciliation_service_impl.kt
@@ -16,11 +16,11 @@
import com.supwisdom.dlpay.exception.TransactionException
import com.supwisdom.dlpay.framework.dao.BusinessparaDao
import com.supwisdom.dlpay.framework.service.SystemUtilService
-import com.supwisdom.dlpay.framework.tenant.TenantContext
import com.supwisdom.dlpay.framework.util.MoneyUtil
import com.supwisdom.dlpay.framework.util.TradeDict
import com.supwisdom.dlpay.framework.util.TradeErrorCode
import com.supwisdom.dlpay.util.ConstantUtil
+import com.supwisdom.multitenant.TenantContextHolder
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
@@ -82,7 +82,7 @@
this.chkresult = ConstantUtil.CHKDTL_CHKRESULT_UNCHECK
this.resolved = ConstantUtil.CHKDTL_RESOLVED_NONE
this.lastsaved = systemUtilService.sysdatetime.sysdate
- this.tenantid = TenantContext.getTenantSchema()
+ this.tenantid = TenantContextHolder.getContext().tenant.id
})
}
@@ -119,7 +119,7 @@
this.localcnt = 0
this.localamt = 0.00
this.lastsaved = systemUtilService.sysdatetime.sysdate
- this.tenantid = TenantContext.getTenantSchema()
+ this.tenantid = TenantContextHolder.getContext().tenant.id
})
}
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/transaction_service_impl.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/transaction_service_impl.kt
index b91c74b..77c3e01 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/transaction_service_impl.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/transaction_service_impl.kt
@@ -10,8 +10,8 @@
import com.supwisdom.dlpay.exception.TransactionCheckException
import com.supwisdom.dlpay.exception.TransactionProcessException
import com.supwisdom.dlpay.framework.service.SystemUtilService
-import com.supwisdom.dlpay.framework.tenant.TenantContext
import com.supwisdom.dlpay.framework.util.*
+import com.supwisdom.multitenant.TenantContextHolder
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import java.sql.SQLException
@@ -77,7 +77,7 @@
refundAmount = 0.0
checkDate = null
settleDate = null
- tenantid = TenantContext.getTenantSchema()
+ tenantid = TenantContextHolder.getContext().tenant.id
this.sourceType = sourceType.sourceType
dtltype = builder.dtltype
}
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/ynrcc_business_service_impl.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/ynrcc_business_service_impl.kt
index 99b0566..88d6312 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/ynrcc_business_service_impl.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/ynrcc_business_service_impl.kt
@@ -6,9 +6,9 @@
import com.supwisdom.dlpay.framework.dao.BusinessparaDao
import com.supwisdom.dlpay.framework.domain.TBusinesspara
import com.supwisdom.dlpay.framework.service.SystemUtilService
-import com.supwisdom.dlpay.framework.tenant.TenantContext
import com.supwisdom.dlpay.framework.util.DateUtil
import com.supwisdom.dlpay.framework.util.TradeDict
+import com.supwisdom.multitenant.TenantContextHolder
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
@@ -36,7 +36,7 @@
businesspara = TBusinesspara().apply {
this.parakey = YnrccUtil.YNRCC_BILLS_DOWNLOAD_LASTDATE
this.paraval = DateUtil.getNewDay(startdate, -1)
- this.tenantId = TenantContext.getTenantSchema()
+ this.tenantId = TenantContextHolder.getContext().tenant.id
}
}
businesspara = businessparaDao.save(businesspara)
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/framework/tenant.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/framework/tenant.kt
index dc8bbe7..b9b6034 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/framework/tenant.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/framework/tenant.kt
@@ -1,6 +1,5 @@
package com.supwisdom.dlpay.framework
-import com.supwisdom.dlpay.framework.tenant.TenantInterceptor
import mu.KotlinLogging
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Configuration
@@ -23,20 +22,20 @@
// }
//}
-@Configuration
-class MultiTenantDatasourceConfiguration : WebMvcConfigurer {
-
- private val logger = KotlinLogging.logger { }
- @Autowired
- private lateinit var tenantInterceptor: TenantInterceptor
-
- @PostConstruct
- fun post() {
- logger.info("MultiTenantDatasourceConfiguration post constructor.")
- }
-
- override fun addInterceptors(registry: InterceptorRegistry) {
- logger.info("adding interceptor(s).")
- registry.addInterceptor(tenantInterceptor)
- }
-}
+//@Configuration
+//class MultiTenantDatasourceConfiguration : WebMvcConfigurer {
+//
+// private val logger = KotlinLogging.logger { }
+// @Autowired
+// private lateinit var tenantInterceptor: TenantInterceptor
+//
+// @PostConstruct
+// fun post() {
+// logger.info("MultiTenantDatasourceConfiguration post constructor.")
+// }
+//
+// override fun addInterceptors(registry: InterceptorRegistry) {
+// logger.info("adding interceptor(s).")
+// registry.addInterceptor(tenantInterceptor)
+// }
+//}
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/security.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/security.kt
index 9cad14f..ee4a5c6 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/security.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/security.kt
@@ -7,7 +7,6 @@
import com.supwisdom.dlpay.framework.security.MyAuthenticationFailureHandler
import com.supwisdom.dlpay.framework.security.ValidateCodeSecurityConfig
import com.supwisdom.dlpay.framework.service.OperatorDetailService
-import com.supwisdom.dlpay.framework.tenant.TenantContext
import com.supwisdom.dlpay.framework.util.Constants
import com.supwisdom.dlpay.framework.util.TradeDict
import com.supwisdom.dlpay.mobile.AuthLoginFailHandler
@@ -67,9 +66,6 @@
}
override fun doFilterInternal(request: HttpServletRequest, response: HttpServletResponse, filterChain: FilterChain) {
- if (!jwtConfig.multiTenant) {
- TenantContext.setTenantSchema(Constants.DEFAULT_TENANTID)
- }
request.getHeader(jwtConfig.header)?.let { authHeader ->
try {
val jwt = if (authHeader.startsWith(jwtConfig.tokenHeader)) {
@@ -97,7 +93,6 @@
response.status = HttpStatus.UNAUTHORIZED.value()
return
}
- TenantContext.setTenantSchema(tenantId)
}
val auth = UsernamePasswordAuthenticationToken(claims[Constants.JWT_CLAIM_UID], null,
(claims[Constants.JWT_CLAIM_AUTHORITIES] as ArrayList<*>)
@@ -191,7 +186,6 @@
response.status = HttpStatus.UNAUTHORIZED.value()
return
}
- TenantContext.setTenantSchema(tenantId)
}
val auth = UsernamePasswordAuthenticationToken(claims[Constants.JWT_CLAIM_UID], null,
(claims[Constants.JWT_CLAIM_AUTHORITIES] as ArrayList<*>)
diff --git a/payapi/src/main/resources/application.properties b/payapi/src/main/resources/application.properties
index 0a2b535..8627bf0 100644
--- a/payapi/src/main/resources/application.properties
+++ b/payapi/src/main/resources/application.properties
@@ -39,4 +39,8 @@
# user password
auth.password.bcrypt.length=10
###################################################
-spring.redis.database=0
\ No newline at end of file
+spring.redis.database=0
+###################################################
+multi-tenant.header.key=X-TENANT-ID
+multi-tenant.session.name=multi-tenant-id
+multi-tenant.dbschema=public