private fun canStartCheck(sourcetype: TSourceType): Boolean {
val hosttime = systemUtilService.sysdatetime.hosttime
- if(DateUtil.checkDatetimeValid(sourcetype.startChktime,DateUtil.TIME_FMT) && DateUtil.compareDatetime(hosttime, sourcetype.startChktime, DateUtil.TIME_FMT)<=0){
+ if (DateUtil.checkDatetimeValid(sourcetype.startChktime, DateUtil.TIME_FMT) && DateUtil.compareDatetime(hosttime, sourcetype.startChktime, DateUtil.TIME_FMT) <= 0) {
return false //sourcetype 设定了每天开始对账时间,小于这个对账时间不能对账
}
return true
@Scheduled(cron = "\${payapi.sourcetype.checker.scheduler:-}")
@SchedulerLock(name = "payapiSourceTypeCheckLock", lockAtMostForString = "PT30M")
fun runCheck() {
- if(TenantContext.getTenantSchema()==null) TenantContext.setTenantSchema(Constants.DEFAULT_TENANTID)
+ if (TenantContext.getTenantSchema() == null) TenantContext.setTenantSchema(Constants.DEFAULT_TENANTID)
val allSourcetype = sourceTypeService.allEnabledSourcetype
?: return
fun checkAndDownloadChkfile(checkStatus: TSourceTypeCheckStatus): Future<ExecutorResult> {
// 2. 根据对账日期下载对账文件
try {
- if(TenantContext.getTenantSchema()==null) TenantContext.setTenantSchema(Constants.DEFAULT_TENANTID)
+ if (TenantContext.getTenantSchema() == null) TenantContext.setTenantSchema(checkStatus.tenantId)
if (checkStatus.settleStatus) {
return AsyncResult(ExecutorResult(checkStatus, FAIL, "[${checkStatus.checkAccdate}]日对账已完成"))
}
@Async("sourcetypeCheckTaskExecutor")
fun reconciliation(checkStatus: TSourceTypeCheckStatus): Future<ExecutorResult> {
// 3. 完成对账
- if(TenantContext.getTenantSchema()==null) TenantContext.setTenantSchema(Constants.DEFAULT_TENANTID)
+ if (TenantContext.getTenantSchema() == null) TenantContext.setTenantSchema(checkStatus.tenantId)
if (!checkStatus.checkFileOk) {
return AsyncResult(ExecutorResult(checkStatus, FAIL, "checkAccdate=[${checkStatus.checkAccdate}]对账单未完成下载,不能对账"))
} else if (checkStatus.settleStatus) {
return AsyncResult(ExecutorResult(checkStatus, SUCCESS, "checkAccdate=[${checkStatus.checkAccdate}]对账已成功"))
}
- val result =transactionReconciliationService.getTransactionChkfile(checkStatus.checkAccdate, checkStatus.sourceType)?.let { chkfile ->
+ val result = transactionReconciliationService.getTransactionChkfile(checkStatus.checkAccdate, checkStatus.sourceType)?.let { chkfile ->
try {
- doCheckProcess(chkfile, checkStatus) //执行对账过程
- when (checkStatus.settleStatus) {
- true -> ExecutorResult(checkStatus, SUCCESS, "对账成功,双方一致")
- false -> ExecutorResult(checkStatus, FAIL, chkfile.remark)
+ val chkStatus = doCheckProcess(chkfile, checkStatus) //执行对账过程
+ when (chkStatus.settleStatus) {
+ true -> ExecutorResult(chkStatus, SUCCESS, "对账成功,双方一致")
+ false -> ExecutorResult(chkStatus, FAIL, chkfile.remark)
}
} catch (ex: Exception) {
ex.printStackTrace()
return AsyncResult(result)
}
- fun doCheckProcess(chkfile: TTransactionChkfile, checkStatus: TSourceTypeCheckStatus) {
+ fun doCheckProcess(chkfile: TTransactionChkfile, checkStatus: TSourceTypeCheckStatus): TSourceTypeCheckStatus {
//step1: 假设绝大多数记录都是一致的情况下,下面的逻辑采用每1000条批量处理提高性能,统一处理交易一致的记录
(0..chkfile.othercnt step 1000).forEach {
try {
if (transactionReconciliationService.checkUncheckExists(chkfile.id)) {
throw TransactionException(-2, "存在未对账的明细记录")
}
- //step4: 判断本地是否有多余成功流水,并保存
+
+ //step4: 判断本地是否有多余成功流水,并保存recordno为负值
try {
transactionReconciliationService.doCheckLocalMoreDtls(chkfile)
} catch (e1: TransactionException) {
checkStatus.repairStatus = false
checkStatus.settleStatus = false
checkStatus.remark = e1.message
- sourceTypeService.saveOrUpdateSourceTypeCheckStatus(checkStatus)
- return //直接返回
+ return sourceTypeService.saveOrUpdateSourceTypeCheckStatus(checkStatus)
}
/**
* 2. 对"是否可以补帐"的定义是必须"对账完成"
* 3. 当所有明细完成对账或补帐才能结算
*/
- transactionReconciliationService.doFinishChkfileStatus(chkfile, checkStatus)
+ transactionReconciliationService.doFinishChkfileStatus(chkfile, checkStatus) //乐观锁,此事务不更新数据库。否则会影响两表的version
//补账, result为equal或unequal时补帐,error跳过
if (checkStatus.checkStatus && checkStatus.repairStatus) {
}
}
- transactionReconciliationService.doConfirmChkfileStatus(chkfile, checkStatus)
+ return transactionReconciliationService.doConfirmChkfileStatus(chkfile, checkStatus)
}
}
\ No newline at end of file
checkStatus.repairStatus = true
}
checkStatus.remark = chkfile.remark
- transactionChkfileDao.save(chkfile)
- sourceTypeService.saveOrUpdateSourceTypeCheckStatus(checkStatus)
+
+// transactionChkfileDao.save(chkfile)
+// sourceTypeService.saveOrUpdateSourceTypeCheckStatus(checkStatus)
}
override fun getNeedRepairChkdtls(chkfile: TTransactionChkfile): List<TTransactionChkdtl> {
transactionChkdtlDao.save(chkdtl)
}
- override fun doConfirmChkfileStatus(chkfile: TTransactionChkfile, checkStatus: TSourceTypeCheckStatus): TTransactionChkfile {
+ override fun doConfirmChkfileStatus(chkfile: TTransactionChkfile, checkStatus: TSourceTypeCheckStatus): TSourceTypeCheckStatus {
val personSumInfo = persondtlDao.getPersondtlSumInfo(chkfile.accdate, chkfile.sourcetype, chkfile.tenantid)
chkfile.localcnt = personSumInfo.totalcnt ?: 0
chkfile.localamt = personSumInfo.totalamt ?: 0.00
}
}
- sourceTypeService.saveOrUpdateSourceTypeCheckStatus(checkStatus)
- return transactionChkfileDao.save(chkfile)
+ transactionChkfileDao.save(chkfile)
+ return sourceTypeService.saveOrUpdateSourceTypeCheckStatus(checkStatus)
}
}
\ No newline at end of file