From dd0b207bedab8934ad68cd31497363c1d5855b5f Mon Sep 17 00:00:00 2001 From: Tang Cheng Date: Tue, 18 Jun 2019 17:25:39 +0800 Subject: [PATCH] =?utf8?q?fix:=20=E4=BF=AE=E6=94=B9=20taccountdaybal=20@ve?= =?utf8?q?rsion=20=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../dlpay/api/domain/TAccountDayBal.java | 11 +--------- .../supwisdom/dlpay/account_process_async.kt | 6 ++--- .../com/supwisdom/dlpay/api/scheduler_task.kt | 2 -- .../api/service/impl/account_service_impl.kt | 22 +++++++++++++------ 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/supwisdom/dlpay/api/domain/TAccountDayBal.java b/src/main/java/com/supwisdom/dlpay/api/domain/TAccountDayBal.java index f31adb3e..c5bd5f4f 100644 --- a/src/main/java/com/supwisdom/dlpay/api/domain/TAccountDayBal.java +++ b/src/main/java/com/supwisdom/dlpay/api/domain/TAccountDayBal.java @@ -19,6 +19,7 @@ public class TAccountDayBal implements Serializable { @Column(name = "amount", precision = 15, scale = 2) private Double amount; + @Version @Column(name = "update_time", nullable = false) private Timestamp updateTime; @@ -31,9 +32,6 @@ public class TAccountDayBal implements Serializable { @Column(name = "checked") private Boolean checked; - @Version - @Column(name = "optlock", columnDefinition = "integer DEFAULT 0", nullable = false) - private Long version; public String getAccno() { return accno; @@ -91,11 +89,4 @@ public class TAccountDayBal implements Serializable { this.checked = checked; } - public Long getVersion() { - return version; - } - - public void setVersion(Long version) { - this.version = version; - } } diff --git a/src/main/kotlin/com/supwisdom/dlpay/account_process_async.kt b/src/main/kotlin/com/supwisdom/dlpay/account_process_async.kt index 462cb7a1..51be41f0 100644 --- a/src/main/kotlin/com/supwisdom/dlpay/account_process_async.kt +++ b/src/main/kotlin/com/supwisdom/dlpay/account_process_async.kt @@ -11,7 +11,6 @@ import org.springframework.scheduling.annotation.AsyncConfigurer import org.springframework.scheduling.annotation.EnableAsync import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor import org.springframework.stereotype.Component -import org.springframework.transaction.annotation.Transactional import java.lang.reflect.Method import java.util.concurrent.Executor @@ -21,8 +20,8 @@ class SpringAsyncConfig : AsyncConfigurer { @Bean("shopAccBalanceUpdater") fun threadPoolExecutor(): Executor { return ThreadPoolTaskExecutor().apply { - corePoolSize = 10 - maxPoolSize = 30 + corePoolSize = 5 + maxPoolSize = 10 setWaitForTasksToCompleteOnShutdown(true) } } @@ -48,7 +47,6 @@ class ShopAccBalanceAsyncTask { private lateinit var shopaccService: ShopaccService @Async("shopAccBalanceUpdater") - @Transactional fun updateShopBalance(shopdtlRefno: String) { shopaccService.recalcShopBalance(shopdtlRefno, true) } diff --git a/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_task.kt b/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_task.kt index 1034dab9..a5846bb6 100644 --- a/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_task.kt +++ b/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_task.kt @@ -5,7 +5,6 @@ import com.supwisdom.dlpay.api.repositories.ShopaccService import org.springframework.beans.factory.annotation.Autowired import org.springframework.scheduling.annotation.Scheduled import org.springframework.stereotype.Service -import org.springframework.transaction.annotation.Transactional @Service class MySchedulerTask { @@ -17,7 +16,6 @@ class MySchedulerTask { } @Scheduled(fixedRate = 5000) - @Transactional fun dealShopUnupdatedDtl() { shopaccService.findUnupdatedShopDtl(100).forEach { doShopBlanceUpdate(it) diff --git a/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/account_service_impl.kt b/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/account_service_impl.kt index 6e72082a..fb88e55e 100644 --- a/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/account_service_impl.kt +++ b/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/account_service_impl.kt @@ -12,6 +12,7 @@ import com.supwisdom.dlpay.framework.util.TradeDict.* import com.supwisdom.dlpay.framework.util.TradeErrorCode import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Repository +import java.sql.Timestamp import javax.persistence.EntityManager import javax.persistence.LockModeType import javax.persistence.OptimisticLockException @@ -33,7 +34,7 @@ class AccountServiceImpl : AccountService { checked = false } - private fun doRecalcAccountBalance(dtl: TPersondtl, account: TAccount): TAccountDayBal { + private fun doRecalcAccountBalance(dtl: TPersondtl, amount: Double, account: TAccount): TAccountDayBal { val accountDayBal = entityManager.find(TAccountDayBal::class.java, TAccountDayBalPk().also { it.accno = account.accno @@ -42,8 +43,7 @@ class AccountServiceImpl : AccountService { accountDayBal.also { it.lastRefno = dtl.refno - it.amount += dtl.amount - it.updateTime = systemUtilServcie.sysdatetime.currentTimestamp + it.amount += amount }.also { entityManager.persist(it) } @@ -58,7 +58,7 @@ class AccountServiceImpl : AccountService { throw TransactionProcessException(TradeErrorCode.SHORT_BALANCE_ERROR, "个人账户余额不足") } dtl.befbal = account.availbal - doRecalcAccountBalance(dtl, account) + doRecalcAccountBalance(dtl, amount, account) account.availbal += dtl.amount account.balance += dtl.amount @@ -87,10 +87,12 @@ class AccountServiceImpl : AccountService { @Repository class ShopaccServiceImpl : ShopaccService { - @PersistenceContext private lateinit var entityManager: EntityManager + @Autowired + private lateinit var systemUtilService: SystemUtilService + override fun recalcShopBalance(dtl: TShopdtl, amount: Double, overdraft: Boolean) { val shopacc = entityManager.find(TShopacc::class.java, dtl.shopaccno, LockModeType.OPTIMISTIC) ?: throw TransactionProcessException(TradeErrorCode.ACCOUNT_NOT_EXISTS, @@ -117,9 +119,15 @@ class ShopaccServiceImpl : ShopaccService { } override fun findUnupdatedShopDtl(maxCount: Int): List { + val startTime = Timestamp(systemUtilService.sysdatetime.sysdate.time - TIME_MINITUES) return entityManager.createQuery(""" - SELECT p FROM TShopdtl p - WHERE p.status='$DTL_STATUS_SUCCESS' and p.updateBala=false + SELECT p FROM TShopdtl p, TTransactionMain m + WHERE m.refno=p.refno and p.status='$DTL_STATUS_SUCCESS' and p.updateBala=false + and m.endTime < '$startTime' ORDER BY p.refno""", TShopdtl::class.java).setMaxResults(maxCount).resultList } + + companion object { + private const val TIME_MINITUES = 5 * 60 * 1000 + } } \ No newline at end of file -- 2.17.1