个人资料

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. 81
      src/main/kotlin/com/gyf/csams/Service.kt

@ -148,7 +148,10 @@ data class UserInfoVo(
) : ) :
PersonInfoVo() 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"){ post("/refresh"){
call.withToken<OnlyToken> { call.withToken<InfoUpdateVo> {
try { 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) { } catch (e: Exception) {
log.error(e) 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 name by Users.name
var password by Users.password var password by Users.password
var desc by Users.desc 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 { return transaction {
val matchUser = User.findById(_token.token.id) ?: throw UserIdError(_token.token.id) 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() val token = UserToken.find { UserTokens.userId eq matchUser.id }.firstOrNull()
?: throw IllegalArgumentException("无法根据[userId=${matchUser.id}]找到token") ?: throw IllegalArgumentException("无法根据[userId=${matchUser.id}]找到token")
val associationMember = tokenRes(token=token,matchUser = matchUser)
AssociationMember.find { AssociationMembers.userId eq matchUser.id }.firstOrNull() }
UserVo( ClientType.Background->{
studentId = matchUser.studentId, token = val matchManager = Manager.findById(vo.token.id)?:throw ManagerIdError(vo.token.id)
Token( matchManager.apply {
id = matchUser.id.value, token = token.token, vo.name?.let {
createTime = token.createTime.toLong() matchManager.name=it
), name = matchUser.name, }
headImg = matchUser.headImg?.filepath, vo.desc?.let {
desc = matchUser.desc, matchManager.desc=it
associationVo = associationMember?.let { AssociationService.toAssociationVo(it.association) }, }
isHead = associationMember?.isHead }
) 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? { fun read(vo: OnlyToken, table: IntIdTable): F? {
return transaction { return transaction {
if (isFilter) { if (isFilter) {
val nextAudit = AuditLeggings.alias("nextAudit") // val nextAudit = AuditLeggings.alias("nextAudit")
table.innerJoin(AuditLeggings) val c=table.innerJoin(AuditLeggings)
.innerJoin(nextAudit, { AuditLeggings.nextAudit }, { nextAudit[AuditLeggings.id] }) // .innerJoin(nextAudit, { AuditLeggings.nextAudit }, { nextAudit[AuditLeggings.id] })
.innerJoin(Users) .innerJoin(Users)
.slice(listOf(table.id)) .slice(listOf(table.id,AuditLeggings.result,AuditLeggings.nextAudit))
.select { Users.id eq vo.token.id and (nextAudit[AuditLeggings.result] neq true) } .select { Users.id eq vo.token.id}
.firstOrNull() .filter {
?.let { it -> log.info("it[AuditLeggings.result]=${it[AuditLeggings.result]},it[AuditLeggings.nextAudit]=${it[AuditLeggings.nextAudit]}")
getCheckVo(id = it[table.id]) 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 { } else {
table.innerJoin(AuditLeggings).innerJoin(Users) table.innerJoin(AuditLeggings).innerJoin(Users)
.slice(listOf(table.id)) .slice(listOf(table.id))

Loading…
Cancel
Save