fix: 修改 taccountdaybal @version 问题
authorTang Cheng <cheng.tang@supwisdom.com>
Tue, 18 Jun 2019 09:25:39 +0000 (17:25 +0800)
committerTang Cheng <cheng.tang@supwisdom.com>
Tue, 18 Jun 2019 09:25:48 +0000 (17:25 +0800)
src/main/java/com/supwisdom/dlpay/api/domain/TAccountDayBal.java
src/main/kotlin/com/supwisdom/dlpay/account_process_async.kt
src/main/kotlin/com/supwisdom/dlpay/api/scheduler_task.kt
src/main/kotlin/com/supwisdom/dlpay/api/service/impl/account_service_impl.kt

index f31adb3..c5bd5f4 100644 (file)
@@ -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;
-  }
 }
index 462cb7a..51be41f 100644 (file)
@@ -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)
     }
index 1034dab..a5846bb 100644 (file)
@@ -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)
index 6e72082..fb88e55 100644 (file)
@@ -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<TShopdtl> {
+        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