You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
csamsserver/src/Service.kt

46 lines
1.3 KiB

package com.gyf.csams
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction
import org.slf4j.LoggerFactory
class Service {
companion object {
private val logger = LoggerFactory.getLogger(Service::class.java)
/**
* 检查学号是否已注册
*/
fun registered(selectId: String): Boolean {
return transaction {
return@transaction User.select { User.studentId eq selectId }.count().toInt() > 0
}
}
/**
* 注册
*/
fun register(userVo: UserVo): UserResDto? {
var userResDto: UserResDto? = null
try {
transaction {
val _pwd = randomNum(8)
val result = User.insert {
it[studentId] = userVo.studentId
it[name] = userVo.name
it[password] = _pwd.md5()
}.resultedValues
if (result?.isNotEmpty() == true) {
userResDto = UserResDto(password = _pwd)
}
}
} catch (e: Exception) {
logger.error("注册失败,发生异常:$e")
}
return userResDto
}
}
}