From 83286d547dcace13af5bb3d9f5d97051623aaa89 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Wed, 9 Jun 2021 02:35:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E8=B5=84=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/gyf/csams/module/ShareVo.kt | 5 +- src/main/kotlin/com/gyf/csams/Controller.kt | 18 +++- src/main/kotlin/com/gyf/csams/Dao.kt | 2 +- src/main/kotlin/com/gyf/csams/Service.kt | 85 +++++++++++++------ 4 files changed, 79 insertions(+), 31 deletions(-) diff --git a/module/src/main/kotlin/com/gyf/csams/module/ShareVo.kt b/module/src/main/kotlin/com/gyf/csams/module/ShareVo.kt index 178a10d..446850b 100644 --- a/module/src/main/kotlin/com/gyf/csams/module/ShareVo.kt +++ b/module/src/main/kotlin/com/gyf/csams/module/ShareVo.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() /** * 用户注册信息 diff --git a/src/main/kotlin/com/gyf/csams/Controller.kt b/src/main/kotlin/com/gyf/csams/Controller.kt index a3c349a..93197a0 100644 --- a/src/main/kotlin/com/gyf/csams/Controller.kt +++ b/src/main/kotlin/com/gyf/csams/Controller.kt @@ -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 { + call.withToken { 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 = "个人信息刷新失败")) } } } diff --git a/src/main/kotlin/com/gyf/csams/Dao.kt b/src/main/kotlin/com/gyf/csams/Dao.kt index 9ed4946..c947c2f 100644 --- a/src/main/kotlin/com/gyf/csams/Dao.kt +++ b/src/main/kotlin/com/gyf/csams/Dao.kt @@ -38,7 +38,7 @@ class User(id:EntityID):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 } diff --git a/src/main/kotlin/com/gyf/csams/Service.kt b/src/main/kotlin/com/gyf/csams/Service.kt index 76a4cc3..131d6ba 100644 --- a/src/main/kotlin/com/gyf/csams/Service.kt +++ b/src/main/kotlin/com/gyf/csams/Service.kt @@ -156,24 +156,52 @@ object AccountService : AbstractService() { } } - fun refreshInfo(_token: OnlyToken): UserVo { + fun uploadHeadImg(data: List){ + 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 : 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))