충전이벤트가 적용되지 않는 버그 수정
This commit is contained in:
		| @@ -3,7 +3,7 @@ package kr.co.vividnext.sodalive.can.charge | ||||
| import com.fasterxml.jackson.databind.ObjectMapper | ||||
| import kr.co.bootpay.Bootpay | ||||
| import kr.co.vividnext.sodalive.can.CanRepository | ||||
| import kr.co.vividnext.sodalive.can.charge.event.ChargeEventService | ||||
| import kr.co.vividnext.sodalive.can.charge.event.ChargeSpringEvent | ||||
| import kr.co.vividnext.sodalive.can.payment.Payment | ||||
| import kr.co.vividnext.sodalive.can.payment.PaymentGateway | ||||
| import kr.co.vividnext.sodalive.can.payment.PaymentStatus | ||||
| @@ -16,6 +16,7 @@ import okhttp3.Request | ||||
| import okhttp3.RequestBody.Companion.toRequestBody | ||||
| import org.json.JSONObject | ||||
| import org.springframework.beans.factory.annotation.Value | ||||
| import org.springframework.context.ApplicationEventPublisher | ||||
| import org.springframework.data.repository.findByIdOrNull | ||||
| import org.springframework.http.HttpHeaders | ||||
| import org.springframework.security.core.userdetails.User | ||||
| @@ -30,7 +31,7 @@ class ChargeService( | ||||
|     private val memberRepository: MemberRepository, | ||||
|     private val objectMapper: ObjectMapper, | ||||
|     private val okHttpClient: OkHttpClient, | ||||
|     private val chargeEventService: ChargeEventService, | ||||
|     private val applicationEventPublisher: ApplicationEventPublisher, | ||||
|  | ||||
|     @Value("\${bootpay.application-id}") | ||||
|     private val bootpayApplicationId: String, | ||||
| @@ -84,9 +85,11 @@ class ChargeService( | ||||
|                     charge.payment?.status = PaymentStatus.COMPLETE | ||||
|                     member.charge(charge.chargeCan, charge.rewardCan, "pg") | ||||
|  | ||||
|                     chargeEventService.applyChargeEvent( | ||||
|                         chargeId = charge.id!!, | ||||
|                         memberId = member.id!! | ||||
|                     applicationEventPublisher.publishEvent( | ||||
|                         ChargeSpringEvent( | ||||
|                             chargeId = charge.id!!, | ||||
|                             memberId = member.id!! | ||||
|                         ) | ||||
|                     ) | ||||
|                 } else { | ||||
|                     throw SodaException("결제정보에 오류가 있습니다.") | ||||
| @@ -136,9 +139,11 @@ class ChargeService( | ||||
|                 charge.payment?.status = PaymentStatus.COMPLETE | ||||
|                 member.charge(charge.chargeCan, charge.rewardCan, "ios") | ||||
|  | ||||
|                 chargeEventService.applyChargeEvent( | ||||
|                     chargeId = charge.id!!, | ||||
|                     memberId = member.id!! | ||||
|                 applicationEventPublisher.publishEvent( | ||||
|                     ChargeSpringEvent( | ||||
|                         chargeId = charge.id!!, | ||||
|                         memberId = member.id!! | ||||
|                     ) | ||||
|                 ) | ||||
|             } else { | ||||
|                 throw SodaException("결제정보에 오류가 있습니다.") | ||||
|   | ||||
| @@ -12,7 +12,6 @@ import kr.co.vividnext.sodalive.fcm.FcmEventType | ||||
| import kr.co.vividnext.sodalive.member.Member | ||||
| import kr.co.vividnext.sodalive.member.MemberRepository | ||||
| import kr.co.vividnext.sodalive.member.auth.AuthRepository | ||||
| import org.slf4j.LoggerFactory | ||||
| import org.springframework.context.ApplicationEventPublisher | ||||
| import org.springframework.data.repository.findByIdOrNull | ||||
| import org.springframework.stereotype.Service | ||||
| @@ -29,20 +28,15 @@ class ChargeEventService( | ||||
|     private val chargeEventRepository: ChargeEventRepository, | ||||
|     private val applicationEventPublisher: ApplicationEventPublisher | ||||
| ) { | ||||
|  | ||||
|     private val logger = LoggerFactory.getLogger(this::class.java) | ||||
|  | ||||
|     @Transactional | ||||
|     fun applyChargeEvent(chargeId: Long, memberId: Long) { | ||||
|         logger.info("충전 이벤트 시작") | ||||
|         val charge = chargeRepository.findByIdOrNull(chargeId) | ||||
|             ?: throw SodaException("결제정보에 오류가 있습니다.") | ||||
|             ?: throw SodaException("이벤트가 적용되지 않았습니다.\n고객센터에 문의해 주세요.") | ||||
|  | ||||
|         val member = memberRepository.findByIdOrNull(memberId) | ||||
|             ?: throw SodaException("결제정보에 오류가 있습니다.") | ||||
|             ?: throw SodaException("이벤트가 적용되지 않았습니다.\n고객센터에 문의해 주세요.") | ||||
|  | ||||
|         if (member.auth != null) { | ||||
|             logger.info("본인인증 있음") | ||||
|             val authDate = authRepository.getOldestCreatedAtByDi(member.auth!!.di) | ||||
|             val memberIds = authRepository.getMemberIdsByDi(member.auth!!.di) | ||||
|  | ||||
| @@ -51,14 +45,12 @@ class ChargeEventService( | ||||
|                 chargeCount += chargeRepository.getChargeCountAfterDate(memberId = id, authDate) | ||||
|             } | ||||
|  | ||||
|             logger.info("충전횟수 : $chargeCount") | ||||
|             if (chargeCount > 0) { | ||||
|             if (chargeCount > 1) { | ||||
|                 applyOtherEvent(charge, member) | ||||
|             } else { | ||||
|                 applyFirstChargeEvent(charge, member) | ||||
|             } | ||||
|         } else { | ||||
|             logger.info("본인인증 없음") | ||||
|             applyOtherEvent(charge, member) | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -0,0 +1,21 @@ | ||||
| package kr.co.vividnext.sodalive.can.charge.event | ||||
|  | ||||
| import org.springframework.scheduling.annotation.Async | ||||
| import org.springframework.stereotype.Component | ||||
| import org.springframework.transaction.event.TransactionalEventListener | ||||
|  | ||||
| class ChargeSpringEvent( | ||||
|     val chargeId: Long, | ||||
|     val memberId: Long | ||||
| ) | ||||
|  | ||||
| @Component | ||||
| class ChargeSpringEventListener( | ||||
|     private val chargeEventService: ChargeEventService | ||||
| ) { | ||||
|     @Async | ||||
|     @TransactionalEventListener | ||||
|     fun applyChargeEvent(event: ChargeSpringEvent) { | ||||
|         chargeEventService.applyChargeEvent(event.chargeId, event.memberId) | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user