个人资料

master
pan 4 years ago
parent d340be70e4
commit 83286d547d
  1. 5
      module/src/main/kotlin/com/gyf/csams/module/ShareVo.kt
  2. 18
      src/main/kotlin/com/gyf/csams/Controller.kt
  3. 2
      src/main/kotlin/com/gyf/csams/Dao.kt
  4. 85
      src/main/kotlin/com/gyf/csams/Service.kt

@ -148,7 +148,10 @@ data class UserInfoVo(
) :
PersonInfoVo()
data class InfoUpdateVo(val name:String?=null, val desc:String?=null,
override val token: Token,
override val clientType: ClientType
):ClientBaseVo()
/**
* 用户注册信息

@ -94,13 +94,25 @@ fun Application.AccountController() {
}
}
post("/upload/img"){
val data= call.receiveMultipart()
try {
AccountService.uploadHeadImg(data = data.readAllParts())
call.respond(ApiResponse(message = "上传头像成功",body = true))
} catch (e: Exception) {
log.error(e)
call.respond(ApiResponse(message = "上传头像失败",body = false))
}
}
post("/refresh"){
call.withToken<OnlyToken> {
call.withToken<InfoUpdateVo> {
try {
call.respond(ApiResponse(message = "个人信息获取成功",body =AccountService.refreshInfo(_token = it) ))
log.info("info=${it}")
call.respond(ApiResponse(message = "个人信息刷新成功",body =AccountService.refreshInfo(vo = it) ))
} catch (e: Exception) {
log.error(e)
call.respond(Simple.error(message = "个人信息获取失败"))
call.respond(Simple.error(message = "个人信息刷新失败"))
}
}
}

@ -38,7 +38,7 @@ class User(id:EntityID<Int>):IntEntity(id){
var name by Users.name
var password by Users.password
var desc by Users.desc
val headImg by ImageFile optionalReferencedOn Users.imgId
var headImg by ImageFile optionalReferencedOn Users.imgId
}

@ -156,24 +156,52 @@ object AccountService : AbstractService() {
}
}
fun refreshInfo(_token: OnlyToken): UserVo {
fun uploadHeadImg(data: List<PartData>){
val userId=data.getFormParam("id").toInt()
transaction {
val fileIds =FileService.storeFile(data)
if(fileIds?.isNotEmpty()==true){
val fileId=fileIds.first()
val user=User.findById(userId)?:throw UserIdError(userId)
user.apply {
headImg=ImageFile.findById(fileId)?:throw FileIdError(fileId)
}
}
}
}
fun refreshInfo(vo: InfoUpdateVo): PersonInfoVo {
return transaction {
val matchUser = User.findById(_token.token.id) ?: throw UserIdError(_token.token.id)
val token = UserToken.find { UserTokens.userId eq matchUser.id }.firstOrNull()
?: throw IllegalArgumentException("无法根据[userId=${matchUser.id}]找到token")
val associationMember =
AssociationMember.find { AssociationMembers.userId eq matchUser.id }.firstOrNull()
UserVo(
studentId = matchUser.studentId, token =
Token(
id = matchUser.id.value, token = token.token,
createTime = token.createTime.toLong()
), name = matchUser.name,
headImg = matchUser.headImg?.filepath,
desc = matchUser.desc,
associationVo = associationMember?.let { AssociationService.toAssociationVo(it.association) },
isHead = associationMember?.isHead
)
when(vo.clientType){
ClientType.Foreground->{
val matchUser = User.findById(vo.token.id) ?: throw UserIdError(vo.token.id)
matchUser.apply {
vo.name?.let {
matchUser.name=it
}
vo.desc?.let {
matchUser.desc=it
}
}
val token = UserToken.find { UserTokens.userId eq matchUser.id }.firstOrNull()
?: throw IllegalArgumentException("无法根据[userId=${matchUser.id}]找到token")
tokenRes(token=token,matchUser = matchUser)
}
ClientType.Background->{
val matchManager = Manager.findById(vo.token.id)?:throw ManagerIdError(vo.token.id)
matchManager.apply {
vo.name?.let {
matchManager.name=it
}
vo.desc?.let {
matchManager.desc=it
}
}
val token=ManagerToken.find { ManagerTokens.managerId eq matchManager.id }.firstOrNull()
?: throw IllegalArgumentException("无法根据[matchId=${matchManager.id}]找到token")
tokenRes(token=token,matchManager=matchManager)
}
}
}
}
@ -629,17 +657,22 @@ abstract class AuditService<T, E, F> : AbstractService() {
fun read(vo: OnlyToken, table: IntIdTable): F? {
return transaction {
if (isFilter) {
val nextAudit = AuditLeggings.alias("nextAudit")
table.innerJoin(AuditLeggings)
.innerJoin(nextAudit, { AuditLeggings.nextAudit }, { nextAudit[AuditLeggings.id] })
// val nextAudit = AuditLeggings.alias("nextAudit")
val c=table.innerJoin(AuditLeggings)
// .innerJoin(nextAudit, { AuditLeggings.nextAudit }, { nextAudit[AuditLeggings.id] })
.innerJoin(Users)
.slice(listOf(table.id))
.select { Users.id eq vo.token.id and (nextAudit[AuditLeggings.result] neq true) }
.firstOrNull()
?.let { it ->
getCheckVo(id = it[table.id])
.slice(listOf(table.id,AuditLeggings.result,AuditLeggings.nextAudit))
.select { Users.id eq vo.token.id}
.filter {
log.info("it[AuditLeggings.result]=${it[AuditLeggings.result]},it[AuditLeggings.nextAudit]=${it[AuditLeggings.nextAudit]}")
it[AuditLeggings.result]==null|| it[AuditLeggings.nextAudit]?.let { it1 -> AuditLogging.findById(it1)?.result } ==null
}
log.info("size:${c.size}")
if(c.size==1){
getCheckVo(c.first()[table.id])
}else{
null
}
} else {
table.innerJoin(AuditLeggings).innerJoin(Users)
.slice(listOf(table.id))

Loading…
Cancel
Save