@Column(name = "amount", precision = 15, scale = 2)
private Double amount;
+ @Version
@Column(name = "update_time", nullable = false)
private Timestamp updateTime;
@Column(name = "checked")
private Boolean checked;
- @Version
- @Column(name = "optlock", columnDefinition = "integer DEFAULT 0", nullable = false)
- private Long version;
public String getAccno() {
return accno;
this.checked = checked;
}
- public Long getVersion() {
- return version;
- }
-
- public void setVersion(Long version) {
- this.version = version;
- }
}
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
@Bean("shopAccBalanceUpdater")
fun threadPoolExecutor(): Executor {
return ThreadPoolTaskExecutor().apply {
- corePoolSize = 10
- maxPoolSize = 30
+ corePoolSize = 5
+ maxPoolSize = 10
setWaitForTasksToCompleteOnShutdown(true)
}
}
private lateinit var shopaccService: ShopaccService
@Async("shopAccBalanceUpdater")
- @Transactional
fun updateShopBalance(shopdtlRefno: String) {
shopaccService.recalcShopBalance(shopdtlRefno, true)
}
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
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
accountDayBal.also {
it.lastRefno = dtl.refno
- it.amount += dtl.amount
- it.updateTime = systemUtilServcie.sysdatetime.currentTimestamp
+ it.amount += amount
}.also {
entityManager.persist(it)
}
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
@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,
}
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