mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-07 02:37:26 +08:00
[F] Fix tests
This commit is contained in:
@@ -13,42 +13,43 @@ import java.util.concurrent.ThreadLocalRandom
|
||||
@Service
|
||||
class CardService(val cardRepo: CardRepository) {
|
||||
/**
|
||||
* Find a card by External Id
|
||||
* @param extId External Id
|
||||
* Find a card by External ID
|
||||
* @param extId External ID
|
||||
* @return Optional of a Card
|
||||
*/
|
||||
fun getCardByExtId(extId: String): Optional<Card> = cardRepo.findByExtId(extId.toLong())
|
||||
|
||||
/**
|
||||
* Find a card by External Id
|
||||
* Find a card by External ID
|
||||
*
|
||||
* @param extId External Id
|
||||
* @param extId External ID
|
||||
* @return Optional of a Card
|
||||
*/
|
||||
fun getCardByExtId(extId: Long?): Optional<Card> = cardRepo.findByExtId(extId)
|
||||
|
||||
/**
|
||||
* Find a card by it's access code
|
||||
* @param accessCode String represent of a access code
|
||||
* Find a card by its access code
|
||||
* @param accessCode String represent of an access code
|
||||
* @return Optional of a Card
|
||||
*/
|
||||
fun getCardByAccessCode(accessCode: String?): Optional<Card> = cardRepo.findByLuid(accessCode)
|
||||
|
||||
/**
|
||||
* Register a new card with access code
|
||||
* @param accessCode String represent of a access code
|
||||
* @param accessCode String represent of an access code
|
||||
* @return a new registered Card
|
||||
*/
|
||||
fun registerByAccessCode(accessCode: String?): Card {
|
||||
val card = Card()
|
||||
card.luid = accessCode
|
||||
var extId = ThreadLocalRandom.current().nextLong(99999999)
|
||||
while (cardRepo.findByExtId(extId).isPresent) {
|
||||
extId = ThreadLocalRandom.current().nextLong(99999999)
|
||||
var eid = ThreadLocalRandom.current().nextLong(99999999)
|
||||
while (cardRepo.findByExtId(eid).isPresent) {
|
||||
eid = ThreadLocalRandom.current().nextLong(99999999)
|
||||
}
|
||||
card.extId = extId
|
||||
card.registerTime = LocalDateTime.now()
|
||||
card.accessTime = LocalDateTime.now()
|
||||
return cardRepo.save(card)
|
||||
|
||||
return cardRepo.save(Card().apply {
|
||||
luid = accessCode
|
||||
extId = eid
|
||||
registerTime = LocalDateTime.now()
|
||||
accessTime = registerTime
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user