package com.safeluck.aaej.app.service
|
|
import com.safeluck.aaej.app.config.DBAlias
|
import com.safeluck.aaej.app.po.DeviceBackList
|
import com.safeluck.aaej.app.po.MobileSession
|
import com.safeluck.aaej.base.dbhelper.impl.DbKey
|
import org.springframework.cache.annotation.CacheConfig
|
import org.springframework.cache.annotation.CacheEvict
|
import org.springframework.cache.annotation.CachePut
|
import org.springframework.cache.annotation.Cacheable
|
import org.springframework.stereotype.Service
|
import org.springframework.util.StringUtils
|
import javax.servlet.http.HttpServletRequest
|
|
@Service
|
class TokenService: BaseService()
|
{
|
fun getToken(request: HttpServletRequest): String? {
|
var token: String? = request.getHeader("Authorization")
|
|
if (token == null) {
|
request.cookies?.run {
|
for (cookie in this) {
|
if (cookie.name == "token") {
|
token = cookie.value
|
}
|
}
|
}
|
|
}
|
return token
|
}
|
|
@DbKey(DBAlias.center)
|
@Cacheable(key="'exists'+#token")
|
fun sessionExists(token:String):Boolean
|
{
|
if(!redisService.keyExists(token))
|
{
|
return dbHelper.queryForInteger("select count(1) from app_session where token = ? ",token)>0
|
}
|
return true
|
}
|
|
@DbKey(DBAlias.center)
|
@Cacheable(key="#token")
|
fun getSession(token:String):MobileSession?
|
{
|
return dbHelper.findById(MobileSession::class.java,token)
|
}
|
|
@DbKey(DBAlias.center)
|
@Cacheable(key="'black_'+#session.ip")
|
fun isBlackList(session:MobileSession):Boolean
|
{
|
return dbHelper.findById(DeviceBackList::class.java,session.ip)!=null
|
}
|
|
|
@DbKey(DBAlias.center)
|
@CachePut(key="#session.token")
|
fun updateSession(session:MobileSession):MobileSession
|
{
|
dbHelper.update(session)
|
return session
|
}
|
|
@DbKey(DBAlias.center)
|
fun deleteSession(session:MobileSession)
|
{
|
dbHelper.delete(session)
|
}
|
|
@DbKey(DBAlias.center)
|
fun insertSession(session:MobileSession):MobileSession
|
{
|
dbHelper.insert(session)
|
return session
|
}
|
}
|