|
|
|
@ -42,18 +42,18 @@ object AccountService { |
|
|
|
|
* |
|
|
|
|
* @param userLoginVo 登陆表单 |
|
|
|
|
*/ |
|
|
|
|
fun login(userLoginVo: UserLoginVo,_ip:String):TokenResDto{ |
|
|
|
|
fun login(userLoginVo: UserLoginVo,_ip:String):Token?{ |
|
|
|
|
return transaction { |
|
|
|
|
val user=User.find { Users.studentId eq userLoginVo.studentId }.firstOrNull() |
|
|
|
|
|
|
|
|
|
when { |
|
|
|
|
user==null -> { |
|
|
|
|
logger.warn("学号:${userLoginVo.studentId}不存在") |
|
|
|
|
return@transaction TokenResDto(isValid = false) |
|
|
|
|
return@transaction null |
|
|
|
|
} |
|
|
|
|
userLoginVo.password.md5() != user.password -> { |
|
|
|
|
logger.warn("密码:${userLoginVo.password}错误") |
|
|
|
|
return@transaction TokenResDto(isValid = false) |
|
|
|
|
return@transaction null |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
val token=UserToken.new{ |
|
|
|
@ -62,13 +62,19 @@ object AccountService { |
|
|
|
|
device=userLoginVo.device |
|
|
|
|
token=listOf(studentId,ip,device).joinToString(separator = ('a' .. 'z').random().toString()).md5() |
|
|
|
|
} |
|
|
|
|
return@transaction TokenResDto(isValid = true,token = Token(token = token.token,createTime = token.createTime.toEpochSecond( |
|
|
|
|
ZoneOffset.of("+8")),studentId = token.studentId)) |
|
|
|
|
token.flush() |
|
|
|
|
return@transaction Token(studentId = userLoginVo.studentId,token = token.token, |
|
|
|
|
createTime = token.createTime.toEpochSecond( |
|
|
|
|
ZoneOffset.of("+8")),name=user.name) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun validToken(token: Token):Boolean{ |
|
|
|
|
return validToken(TokenVo(token = token.token,studentId = token.studentId)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 令牌校验 |
|
|
|
|
* |
|
|
|
@ -99,3 +105,54 @@ object AccountService { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
object MainService{ |
|
|
|
|
private val logger = LoggerFactory.getLogger(MainService::class.java) |
|
|
|
|
|
|
|
|
|
var maxSize:Int=20 |
|
|
|
|
|
|
|
|
|
fun register(maxSize:Int){ |
|
|
|
|
this.maxSize=maxSize |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 创建留言信息 |
|
|
|
|
* |
|
|
|
|
* @param leaveMessageVo |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
fun createMessage(leaveMessageVo: LeaveMessageVo):Boolean{ |
|
|
|
|
return if(leaveMessageVo.message.isNotEmpty()){ |
|
|
|
|
return transaction { |
|
|
|
|
val count=LeaveMessage.count().toInt() |
|
|
|
|
logger.info("系统留言数:$count,限制数:$maxSize") |
|
|
|
|
if(count>= maxSize){ |
|
|
|
|
LeaveMessage.all().sortedBy { it.createTime }.subList(0, count-maxSize).forEach { |
|
|
|
|
it.delete() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
logger.info("保存留言:${leaveMessageVo.message}") |
|
|
|
|
LeaveMessage.new { |
|
|
|
|
studentId = leaveMessageVo.token.studentId |
|
|
|
|
message = leaveMessageVo.message |
|
|
|
|
} |
|
|
|
|
logger.info("留言保存成功") |
|
|
|
|
return@transaction true |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
logger.info("留言不能为空") |
|
|
|
|
false |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun getAllLeaveMessage():List<LeaveMessageFormatVo>{ |
|
|
|
|
return transaction { |
|
|
|
|
logger.info("获取所有留言") |
|
|
|
|
return@transaction LeaveMessage.all().toList().map { |
|
|
|
|
LeaveMessageFormatVo(message = "${User.find { Users.studentId eq it.studentId }.first().name}说:${it.message}",studentId = it.studentId) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|