From 484ecc4ad976a47db82a001bdbed8765798dbc21 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Mon, 7 Jun 2021 22:16:57 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=98=E5=BA=93=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/gyf/csams/module/ShareVo.kt | 99 +++- resources/static/image/.gitkeep | 0 src/main/kotlin/com/gyf/csams/Controller.kt | 95 ++++ src/main/kotlin/com/gyf/csams/Dao.kt | 72 ++- src/main/kotlin/com/gyf/csams/MySQL.kt | 2 +- src/main/kotlin/com/gyf/csams/Service.kt | 507 ++++++++++++++---- test/ApplicationTest.kt | 3 +- 7 files changed, 664 insertions(+), 114 deletions(-) create mode 100644 resources/static/image/.gitkeep 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 505ba3d..fc2e0bc 100644 --- a/module/src/main/kotlin/com/gyf/csams/module/ShareVo.kt +++ b/module/src/main/kotlin/com/gyf/csams/module/ShareVo.kt @@ -623,4 +623,101 @@ data class ManagerDutyVo(val manager: ManagerInfoVo,val people:Int) data class ManagerDutySumVo(val secretariat:ManagerDutyVo, val propaganda:ManagerDutyVo, - val publicRelationsDepartment:ManagerDutyVo) \ No newline at end of file + val publicRelationsDepartment:ManagerDutyVo) + + +data class ExamVo(val questionId:Int?=null,val question:String,val optionsA:String,val optionsB:String,val optionsC:String,val optionsD:String,val answer:Int) + +/** + * 更新题库 + * + * @property questions + * @property token + * @property clientType + */ +data class AddExamVo(val questions:List, + val deleteIds:List?=null, + override val token: Token, + override val clientType: ClientType=ClientType.Foreground, + val associationId:Int):ClientBaseVo() + +data class SearchExamVo(val associationId:Int, override val token: Token, override val clientType: ClientType=ClientType.Foreground):ClientBaseVo() + +/** + * 试卷 + * + * @property user + * @property createTime + * @property applyTime + */ +data class TestPaperVo(val user: UserInfoVo,val createTime: Long,val applyTime: Long?) + +/** + * 试题 + * + + */ +data class AnswerVo(val examVo: ExamVo,val answer:Int?=null,val paperVo: TestPaperVo) + +/** + * 答题记录 + * + * @property questionId + * @property paperId + * @property answer + */ +data class ApplyAnswerVo(val questionId:Int,val paperId:Int,val answer:Int) +/** + * 答卷 + * + * @property answers + * @property token + * @property clientType + */ +data class AddAnswerVo(val answers:List, + val associationId:Int, + override val token: Token, override val clientType: ClientType=ClientType.Foreground):ClientBaseVo() + +data class ShowAnswerVo(val joinId:Int, override val token: Token, + override val clientType: ClientType=ClientType.Foreground):ClientBaseVo() + +/** + * 申请入团 + * + * @property associationId + * @property token + * @property clientType + */ +data class ApplyAssociationVo(val associationId:Int, override val token: Token, override val clientType: ClientType=ClientType.Foreground):ClientBaseVo() + +/** +* 申请入团检查 + */ +data class ApplyAssociationResultVo(val result:Boolean?=null,val hasPaper:Boolean?=null,val associationVo: AssociationVo?=null) + +/** + * 申请入团记录 + * + */ +data class JoinAssociationVo(val id:Int,val user: UserInfoVo, + val associationVo: AssociationVo, + val hasPaper: Boolean, + val result: Boolean?=null, + val applyTime: Long, + val auditTime: Long?=null) + + + +/** + * 审核结果 + * + * @property joinId + * @property result + */ +data class AuditJoinVo(val joinId:Int, val result:Boolean, + override val token: Token, + override val clientType: ClientType=ClientType.Foreground +):ClientBaseVo() + + +const val QUESTION_MIN_SIZE=5 \ No newline at end of file diff --git a/resources/static/image/.gitkeep b/resources/static/image/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/main/kotlin/com/gyf/csams/Controller.kt b/src/main/kotlin/com/gyf/csams/Controller.kt index 3816793..a80d1cb 100644 --- a/src/main/kotlin/com/gyf/csams/Controller.kt +++ b/src/main/kotlin/com/gyf/csams/Controller.kt @@ -350,6 +350,101 @@ fun Application.AssociationController() { check(AssociationService) read(AssociationService,Associations) + post("/update/exam"){ + call.withToken { + try { + AssociationService.updateExam(vo=it) + call.respond(ApiResponse(message = "题库更新成功",body=true)) + } catch (e: Exception) { + log.error(e) + call.respond(ApiResponse(message = "题库更新失败",body=false)) + } + } + } + + post("/load/exam"){ + call.withToken { + try { + call.respond(ApiResponse(message = "加载题库",body = AssociationService.loadExam(vo = it))) + } catch (e: Exception) { + log.error(e) + call.respond(ApiResponse(message = "题库加载失败",body = null)) + } + } + } + + + post("/check/apply"){ + call.withToken { + try { + val body=AssociationService.applyAssociation(vo = it) + call.respond(ApiResponse(message = "入团验证信息获取成功",body =body)) + } catch (e: Exception) { + log.error(e) + call.respond(ApiResponse(message = "入团验证信息获取失败",body=null)) + } + } + } + + post("/create/paper"){ + call.withToken { + try { + call.respond(ApiResponse(message = "试卷创建成功,请开始作答",body = AssociationService.createPaper(vo=it))) + } catch (e: Exception) { + log.error(e) + call.respond(ApiResponse(message = "试卷创建失败",body=null)) + } + } + } + + post("/apply/paper"){ + call.withToken { + try { + AssociationService.applyAnswer(vo=it) + call.respond(ApiResponse(message = "提交成功",body = true)) + } catch (e: Exception) { + log.error(e) + call.respond(ApiResponse(message = "提交成功",body = false)) + } + } + } + + + post("/check/join"){ + call.withToken { + try { + call.respond(ApiResponse(message = "入团记录查询成功",body=AssociationService.joinAssociation(vo=it))) + } catch (e: Exception) { + log.error(e) + call.respond(ApiResponse(message = "入团记录查询失败",body=null)) + } + } + } + + post("/audit/join"){ + call.withToken { + try { + AssociationService.auditJoin(vo = it) + call.respond(ApiResponse(message = "审核成功",body=true)) + } catch (e: Exception) { + log.error(e) + call.respond(ApiResponse(message = "审核失败",body=false)) + } + } + } + + post("/show/answer"){ + call.withToken { + try { + call.respond(ApiResponse(message = "查看答案成功",body = AssociationService.showAnswer(vo=it))) + } catch (e: Exception) { + log.error(e) + call.respond(ApiResponse(message = "查看答案失败",body=null)) + } + } + } + + route("/rename"){ register(RenameService) diff --git a/src/main/kotlin/com/gyf/csams/Dao.kt b/src/main/kotlin/com/gyf/csams/Dao.kt index 5aa9d9f..d6c23ba 100644 --- a/src/main/kotlin/com/gyf/csams/Dao.kt +++ b/src/main/kotlin/com/gyf/csams/Dao.kt @@ -1,5 +1,7 @@ package com.gyf.csams +import com.gyf.csams.Notifications.defaultExpression +import com.gyf.csams.TestPapers.defaultExpression import org.jetbrains.exposed.dao.IntEntity import org.jetbrains.exposed.dao.IntEntityClass import org.jetbrains.exposed.dao.id.EntityID @@ -413,6 +415,9 @@ object Questions:IntIdTable(){ @TableComment("选项D") val optionsD:Column = varchar("optionsD",15) + @TableComment("答案") + val answer:Column = integer("answer") + @TableComment("所属社团") val associationId:Column> = reference("association_id",Associations) } @@ -424,12 +429,77 @@ class Question(id:EntityID):IntEntity(id){ var optionsB by Questions.optionsB var optionsC by Questions.optionsC var optionsD by Questions.optionsD + var answer by Questions.answer + var association by Association referencedOn Questions.associationId } @TableComment("试卷") object TestPapers:IntIdTable(){ + @TableComment("答题用户") + val userId:Column> = reference("user_id",Users) + + @TableComment("生成时间") + val createTime:Column = datetime("create_time").defaultExpression(CurrentDateTime()) + + @TableComment("提交时间") + val applyTime:Column = datetime("apply_time").nullable() + +} + +class TestPaper(id:EntityID):IntEntity(id){ + companion object:IntEntityClass(TestPapers) + var user by User referencedOn TestPapers.userId + var createTime by TestPapers.createTime + var applyTime by TestPapers.applyTime +} + +@TableComment("试题") +object Answers:IntIdTable(){ + @TableComment("问题") val questionId:Column> = reference("question_id",Questions) + @TableComment("答案") + val answer:Column = integer("answer").nullable() + + @TableComment("试卷") + val paperId:Column> = reference("paper_id",TestPapers) +} + +class Answer(id:EntityID):IntEntity(id){ + companion object:IntEntityClass(Answers) + var question by Question referencedOn Answers.questionId + var answer by Answers.answer + var paper by TestPaper referencedOn Answers.paperId +} -} \ No newline at end of file +@TableComment("入团申请记录") +object JoinAssociations:IntIdTable(){ + @TableComment("申请人") + val userId:Column> = reference("user_id",Users) + + @TableComment("申请社团") + val associationId:Column> = reference("association_id",Associations) + + @TableComment("申请时间") + val applyTime:Column = datetime("create_time").defaultExpression(CurrentDateTime()) + + @TableComment("审核时间") + val auditTime:Column = datetime("audit_time").nullable() + + @TableComment("试卷") + val paperId:Column?> = reference("paper_id",TestPapers).nullable() + + @TableComment("申请结果") + val result:Column = bool("result").nullable() +} + +class JoinAssociation(id:EntityID):IntEntity(id){ + companion object:IntEntityClass(JoinAssociations) + var user by User referencedOn JoinAssociations.userId + var association by Association referencedOn JoinAssociations.associationId + var paper by TestPaper optionalReferencedOn JoinAssociations.paperId + var result by JoinAssociations.result + var applyTime by JoinAssociations.applyTime + var auditTime by JoinAssociations.auditTime +} diff --git a/src/main/kotlin/com/gyf/csams/MySQL.kt b/src/main/kotlin/com/gyf/csams/MySQL.kt index 8e87385..83f4ee4 100644 --- a/src/main/kotlin/com/gyf/csams/MySQL.kt +++ b/src/main/kotlin/com/gyf/csams/MySQL.kt @@ -42,7 +42,7 @@ fun initTable(){ transaction { val tableList= arrayOf(Users,UserTokens,Managers,ManagerTokens,AuditLeggings,LeaveMessages, ImageFiles,Associations,AssociationMembers,Notifications,Activities,PhotoAlbums,ActivityComments, - Renames) + Renames,Questions,TestPapers,Answers,JoinAssociations) SchemaUtils.createMissingTablesAndColumns(*tableList) updateComment(*tableList) diff --git a/src/main/kotlin/com/gyf/csams/Service.kt b/src/main/kotlin/com/gyf/csams/Service.kt index 4b45c3f..a562328 100644 --- a/src/main/kotlin/com/gyf/csams/Service.kt +++ b/src/main/kotlin/com/gyf/csams/Service.kt @@ -64,10 +64,10 @@ object AccountService : AbstractService() { } } - fun login(vo:BaseLoginVo,ip:String):OwnInfoVo{ - return when (vo) { - is UserLoginVo -> login(vo,ip) - is ManagerLoginVo -> login(vo,ip) + fun login(vo: BaseLoginVo, ip: String): OwnInfoVo { + return when (vo) { + is UserLoginVo -> login(vo, ip) + is ManagerLoginVo -> login(vo, ip) else -> throw IllegalArgumentException("vo:${vo::class.java}类型不合法") } } @@ -199,7 +199,6 @@ object AccountService : AbstractService() { } - fun getManagerVo(token: Token): ManagerVo { return transaction { val c = ManagerToken.find { @@ -249,10 +248,10 @@ object AccountService : AbstractService() { } fun validToken(vo: T): Boolean { - return when(vo.clientType){ - ClientType.Foreground->validUserToken(vo.token) - ClientType.Background-> validManagerToken(vo.token) - else->throw IllegalArgumentException("不清楚是来自哪个平台的token信息") + return when (vo.clientType) { + ClientType.Foreground -> validUserToken(vo.token) + ClientType.Background -> validManagerToken(vo.token) + else -> throw IllegalArgumentException("不清楚是来自哪个平台的token信息") } } @@ -343,7 +342,8 @@ object FileService : AbstractService() { super.init(environment) this.uploadDir = environment.config.property("ktor.deployment.filePath").getString() - filePath = this::class.java.classLoader.getResource(uploadDir)?.path ?: throw IllegalArgumentException("初始化资源目录失败") + filePath = + this::class.java.classLoader.getResource(uploadDir)?.path ?: throw IllegalArgumentException("初始化资源目录失败") File(filePath).let { when { it.exists() -> log.info("上传路径[${filePath}]已存在") @@ -375,9 +375,9 @@ object FileService : AbstractService() { throw IllegalArgumentException("找不到key:${key}") } - fun List.getFormParam(key:String):String{ + fun List.getFormParam(key: String): String { forEach { - if(it.name==key && it is PartData.FormItem){ + if (it.name == key && it is PartData.FormItem) { return it.value } } @@ -385,9 +385,9 @@ object FileService : AbstractService() { } fun storeFile(data: List): List? { - val userId = data.getFormParam(key="id") - val token = data.getFormParam(key="token") - val createTime = data.getFormParam(key="createTime") + val userId = data.getFormParam(key = "id") + val token = data.getFormParam(key = "token") + val createTime = data.getFormParam(key = "createTime") val tokenVo = Token(token = token, id = userId.toInt(), createTime = createTime.toLong()) if (AccountService.validUserToken(tokenVo)) { val fileIds = mutableListOf() @@ -482,8 +482,12 @@ abstract class AuditService : AbstractService() { */ abstract fun findEntity(auditId: Int): AbstractAudit - protected inline fun ,reified Table:AbstractAudits> testFind(table:Table,row:Row,auditId: Int): E { - return row.find { table.auditId eq auditId } .firstOrNull() ?: throw AuditIdError(auditId) + protected inline fun , reified Table : AbstractAudits> testFind( + table: Table, + row: Row, + auditId: Int + ): E { + return row.find { table.auditId eq auditId }.firstOrNull() ?: throw AuditIdError(auditId) } /** @@ -513,7 +517,7 @@ abstract class AuditService : AbstractService() { * 通过审核后 * */ - protected open fun afterAudit(entity: AbstractAudit){} + protected open fun afterAudit(entity: AbstractAudit) {} /** * 资料受理 @@ -608,7 +612,7 @@ abstract class AuditService : AbstractService() { } //过滤完成的审核记录?(可多次提交的资料) - open val isFilter:Boolean=true + open val isFilter: Boolean = true /** * TODO 审核进度查询 @@ -616,19 +620,19 @@ abstract class AuditService : AbstractService() { */ fun read(vo: OnlyToken, table: IntIdTable): F? { return transaction { - if(isFilter){ + if (isFilter) { val nextAudit = AuditLeggings.alias("nextAudit") 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)} + .select { Users.id eq vo.token.id and (nextAudit[AuditLeggings.result] neq true) } .firstOrNull() ?.let { it -> getCheckVo(id = it[table.id]) } - }else { + } else { table.innerJoin(AuditLeggings).innerJoin(Users) .slice(listOf(table.id)) .select { Users.id eq vo.token.id } @@ -647,7 +651,7 @@ abstract class AuditService : AbstractService() { return AuditCheckVo( checkStatus = when { audit.nextAudit == null && audit.manager == null -> CheckStatus.WaitFirst - audit.nextAudit == null && audit.manager != null && audit.result==null -> CheckStatus.AcceptFirst + audit.nextAudit == null && audit.manager != null && audit.result == null -> CheckStatus.AcceptFirst audit.nextAudit != null && audit.nextAudit?.manager == null -> CheckStatus.WaitLast audit.nextAudit != null && audit.nextAudit?.result == null -> CheckStatus.AcceptLast else -> CheckStatus.Finish @@ -655,7 +659,7 @@ abstract class AuditService : AbstractService() { applyTime = audit.applyTime.toLong(), firstCause = audit.cause ?: "", lastCause = audit.nextAudit?.cause, - result=audit.nextAudit?.result==true + result = audit.nextAudit?.result == true ) } @@ -687,7 +691,11 @@ abstract class AuditService : AbstractService() { val auditLogging = AuditLoggingVo( id = logging.id.value, user = - UserInfoVo(name = logging.user.name, headImg = logging.user.headImg?.filepath, desc = logging.user.desc), + UserInfoVo( + name = logging.user.name, + headImg = logging.user.headImg?.filepath, + desc = logging.user.desc + ), applyTime = logging.applyTime.toLong(), manager = logging.manager?.let { ManagerInfoVo( @@ -707,7 +715,7 @@ abstract class AuditService : AbstractService() { } } - protected fun createNotifications(vo:ClientBaseVo,user:User){ + protected fun createNotifications(vo: ClientBaseVo, user: User) { foreground( receiverId = vo.token.id, content = "您成功提交了一份${dataType},请耐心等待后台受理" @@ -727,7 +735,7 @@ object AssociationService : AuditService{ + /** + * 加载所有社团 + * + * @return + */ + fun loadAll(): List { return transaction { Association.all().map { toAssociationVo(it) @@ -760,13 +773,265 @@ object AssociationService : AuditService{ + return transaction { + Question.find { Questions.associationId eq vo.associationId }.map { + toExamVo(question = it) + } + } + } + + /** + * 提交答卷 + * + */ + fun applyAnswer(vo:AddAnswerVo){ + transaction { + val association= Association.findById(vo.associationId)?:throw AssociationIdError(vo.associationId) + val user=User.findById(vo.token.id)?:throw UserIdError(vo.token.id) + vo.answers.forEach { + val question=Question.findById(it.questionId)?:throw IllegalArgumentException("不存在[id=${it.questionId}]的问题") + val paper=TestPaper.findById(it.paperId)?:throw IllegalArgumentException("不存在[id=${it.paperId}]的问题") + + Answer.new { + this.question=question + answer=it.answer + this.paper=paper + } + } + createJoin(association = association,user=user) + } + } + + /** + * 显示答卷 + * + * @param vo + * @return + */ + fun showAnswer(vo:ShowAnswerVo):List{ + return transaction { + val join=JoinAssociation.findById(vo.joinId)?:throw IllegalArgumentException("找不到[id=${vo.joinId}]申请记录") + val paperId= join.paper?.id?:throw IllegalArgumentException("[id=${join.id}]没有关联试卷") + val paper=TestPaper.findById(paperId)?:throw IllegalArgumentException("[id=${paperId}]关联的试卷不存在") + Answer.find { Answers.paperId eq paperId}.map { + AnswerVo(examVo = toExamVo(it.question),answer = it.answer,paperVo = + TestPaperVo(user = UserInfoVo(name=join.user.name,headImg = join.user.headImg?.filepath,desc=join.user.desc), + createTime = paper.createTime.toLong(),applyTime = paper.applyTime?.toLong())) + } + } + } + + + /** + * 创建申请记录 + * + * @param association + * @param user + */ + private fun createJoin(association: Association,user:User){ + JoinAssociation.new { + this.association=association + this.user=user + }.apply { + //通知团长处理 + AssociationMember.find { AssociationMembers.associationId eq association.id and + (AssociationMembers.isHead eq true) }.firstOrNull()?.apply { + Notification.new { + this.title = "入团申请通知" + this.content = "用户${user.name}申请加入社团" + this.receiverId = user.id.value + receiverClient = ClientType.Foreground.name + } + } + } + } + + /** + * 生成试卷 + * + * @param vo + * @return + */ + fun createPaper(vo:ApplyAssociationVo):List{ + return transaction { + val association= Association.findById(vo.associationId)?:throw AssociationIdError(vo.associationId) + val user=User.findById(vo.token.id)?:throw UserIdError(vo.token.id) + Question.find { Questions.associationId eq association.id }.let { it -> + val paper=TestPaper.new { + this.user=user + this.applyTime= LocalDateTime.now() + } + it.shuffled().apply { + forEach { + Answer.new { + this.paper=paper + this.question=it + } + } + }.map { + toExamVo(question = it) + } + } + } + } + + + /** + * 申请入团 + * + */ + fun applyAssociation(vo:ApplyAssociationVo):ApplyAssociationResultVo{ + return transaction { + val user=User.findById(vo.token.id)?:throw UserIdError(vo.token.id) + val association= Association.findById(vo.associationId)?:throw AssociationIdError(vo.associationId) + JoinAssociation.find { JoinAssociations.userId eq vo.token.id and (JoinAssociations.result eq null) }.firstOrNull().let { + if(it!=null){ + return@transaction ApplyAssociationResultVo(associationVo = toAssociationVo(it.association)) + } + } + + Question.find { Questions.associationId eq association.id }.let { it -> + //题库需要满足最少题目数才能生成试卷 + if(it.count()>=QUESTION_MIN_SIZE){ + ApplyAssociationResultVo(result = true,hasPaper = true) + } + //免试入团申请 + else{ + createJoin(association=association,user=user) + ApplyAssociationResultVo(result = true,hasPaper = false) + } + } + } + } + + /** + * 入团申请记录 + * + */ + fun joinAssociation(vo:ApplyAssociationVo):List{ + return transaction { + val association=Association.findById(vo.associationId)?:throw AssociationIdError(vo.associationId) + val user=User.findById(vo.token.id)?:throw UserIdError(vo.token.id) + + JoinAssociation.find { JoinAssociations.associationId eq association.id }.map { + val userInfoVo=UserInfoVo(name = user.name,headImg = user.headImg?.filepath,desc=user.desc) + + JoinAssociationVo(user = userInfoVo, + associationVo = toAssociationVo(it.association), + hasPaper = it.paper!=null,result = it.result, + applyTime = it.applyTime.toLong(), + auditTime = it.auditTime?.toLong(),id = it.id.value) + } + } + } + + /** + * 审核入团申请 + * @param vo + */ + fun auditJoin(vo:AuditJoinVo){ + transaction { + val join=JoinAssociation.findById(vo.joinId)?:throw IllegalArgumentException("审核记录不存在") + join.result=vo.result + join.auditTime= LocalDateTime.now() + if(vo.result){ + AssociationMember.new { + user=join.user + association=join.association + isHead=false + } + //入团申请通过,通知社团其他人 + AssociationMember.find { AssociationMembers.associationId eq join.association.id }.forEach { + Notification.new { + this.title = "入团通知" + this.content = "欢迎新人${join.user.name}加入社团" + this.receiverId = it.user.id.value + receiverClient = ClientType.Foreground.name + }.apply { + log.info("通知前台用户${dataType}处理进度") + } + } + } + //把审核结果发送给申请人 + Notification.new{ + this.title="入团审核结果" + this.content="您申请加入${join.association.name}社团审核${if(vo.result)"通过" else "不通过"}" + this.receiverId=join.user.id.value + receiverClient=ClientType.Foreground.name + } + } + } + + /** + * 更新题库 + * + * @param vo + */ + fun updateExam(vo: AddExamVo) { + transaction { + val association=Association.findById(vo.associationId)?:throw IllegalArgumentException("找不到社团信息") + + vo.deleteIds?.let { + //删除社团题目 + Question.find { Questions.associationId eq association.id and (Questions.id inList it ) }.forEach { + log.info("删除[id=${it.id}]题目") + it.delete() + } + } + + vo.questions.forEach { + exam-> + exam.questionId.let { + if (it == null) { + Question.new { + question = exam.question + optionsA = exam.optionsA + optionsB = exam.optionsB + optionsC = exam.optionsC + optionsD = exam.optionsD + this.answer = exam.answer + this.association = association + } + } else { + log.info("更新[id=${it}]的题目") + Question.findById(it)?.apply { + question = exam.question + optionsA = exam.optionsA + optionsB = exam.optionsB + optionsC = exam.optionsC + optionsD = exam.optionsD + this.answer = exam.answer + } + } + } + } + } + } + + /** + * 更新社团信息 + * + * @param vo + */ + fun update(vo: AssociationVo) { transaction { Association.findById(vo.associationId).let { - if(it==null){ + if (it == null) { throw AssociationIdError(vo.associationId) - }else{ - it.level=vo.level?.name + } else { + it.level = vo.level?.name } } } @@ -785,7 +1050,7 @@ object AssociationService : AuditService throw IllegalArgumentException("您已经提交过${dataType},请耐心等待后台管理员处理") association == null -> { Association.new { - set(vo=vo,user=user) + set(vo = vo, user = user) faculty = faculty(user.studentId).name } @@ -802,7 +1067,7 @@ object AssociationService : AuditService() { +object ActivityService : AuditService() { override val dataType: String = "活动申请书" override fun findEntity(auditId: Int): AbstractAudit { - return testFind(Activities,Activity,auditId) + return testFind(Activities, Activity, auditId) } /** * 查看活动信息 * */ - fun listAll():List{ + fun listAll(): List { return transaction { Activity.all().map { - ManagerActVo(association = AssociationService.toAssociationVo(it.association), - score = (1..5).random(),activityVo = toActivityVo(it)) + ManagerActVo( + association = AssociationService.toAssociationVo(it.association), + score = (1..5).random(), activityVo = toActivityVo(it) + ) } } } @@ -956,12 +1224,14 @@ object ActivityService : AuditService{ + fun random(): List { return transaction { PhotoAlbum.all().shuffled().map { - MainActivityPhotoVo(url=it.photo.filepath, + MainActivityPhotoVo( + url = it.photo.filepath, activityVo = toActivityVo(it.activity), - associationVo = AssociationService.toAssociationVo(it.activity.association)) + associationVo = AssociationService.toAssociationVo(it.activity.association) + ) } } } @@ -971,18 +1241,18 @@ object ActivityService : AuditService){ - val activityId=data.getFormParam("activityId") - val name=data.getFormParam("name") + fun upload(data: List) { + val activityId = data.getFormParam("activityId") + val name = data.getFormParam("name") transaction { - (Activity.findById(activityId.toInt())?:throw IllegalArgumentException("活动id参数有误:${activityId}")).apply { - val fileId=FileService.storeFile(data) + (Activity.findById(activityId.toInt()) ?: throw IllegalArgumentException("活动id参数有误:${activityId}")).apply { + val fileId = FileService.storeFile(data) //保存到相册 fileId?.forEach { PhotoAlbum.new { - activity=this@apply - photo=ImageFile.findById(it)?:throw FileIdError(it) - this.name=name + activity = this@apply + photo = ImageFile.findById(it) ?: throw FileIdError(it) + this.name = name }.let { log.info("保存照片:${it.name}") } @@ -996,12 +1266,12 @@ object ActivityService : AuditService{ + fun loadComment(vo: SearchCommentVo): List { return transaction { ActivityComment.find { ActivityComments.activityId eq vo.activityId }.map { - BBSVo(user = UserInfoVo(name=it.user.name,headImg = it.user.headImg?.filepath,desc = it.user.desc), - createTime = it.createTime.toLong(),content = it.content) + BBSVo( + user = UserInfoVo(name = it.user.name, headImg = it.user.headImg?.filepath, desc = it.user.desc), + createTime = it.createTime.toLong(), content = it.content + ) } } } @@ -1027,21 +1299,20 @@ object ActivityService : AuditService{ + fun load(vo: SearchActivityPhotoVo): List { return transaction { PhotoAlbum.find { PhotoAlbums.activityId eq vo.activityId }.map { - ActivityPhotoVo(name = it.name,url=it.photo.filepath) + ActivityPhotoVo(name = it.name, url = it.photo.filepath) } } } - /** * 活动列表 * */ - fun load(vo:SearchActivityVo):List{ + fun load(vo: SearchActivityVo): List { return transaction { val nextAudit = AuditLeggings.alias("nextAudit") return@transaction Activities.innerJoin(otherTable = AuditLeggings) @@ -1050,7 +1321,8 @@ object ActivityService : AuditService throw IllegalArgumentException("不是社团团长无法申请活动") else -> { Activity.new { - set(vo.activityVo,user=user) - association = Association.findById(vo.associationId) ?: throw AssociationIdError(vo.associationId) + set(vo.activityVo, user = user) + association = + Association.findById(vo.associationId) ?: throw AssociationIdError(vo.associationId) } } } } - createNotifications(vo=vo,user=user) + createNotifications(vo = vo, user = user) } } - private fun toActivityVo(activity:Activity):ActivityVo{ + private fun toActivityVo(activity: Activity): ActivityVo { return ActivityVo( activityName = activity.activityName, activityTime = activity.activityTime.toLong(), activityAddress = activity.activityAddress, activityDesc = activity.activityDesc, @@ -1137,7 +1412,7 @@ object ActivityService : AuditService): ActivityCheckVo { - return (Activity.findById(id) ?: throw ActivityIdError(id.value)).let { + return (Activity.findById(id) ?: throw ActivityIdError(id.value)).let { ActivityCheckVo( activityVo = toActivityVo(activity = it), auditCheckVo = toCheckVo(it.audit) @@ -1150,13 +1425,13 @@ object ActivityService : AuditService(){ +object RenameService : AuditService() { override val dataType: String = "换名申请表" - fun Rename.set(vo:RenameVo,user:User){ - newName=vo.newName - cause=vo.cause - audit=AuditLogging.new { + fun Rename.set(vo: RenameVo, user: User) { + newName = vo.newName + cause = vo.cause + audit = AuditLogging.new { this.user = user } } @@ -1164,8 +1439,8 @@ object RenameService : AuditService() //TODO 类型自动转换 override fun afterAudit(entity: AbstractAudit) { - if(entity is Rename){ - entity.association.name=entity.newName + if (entity is Rename) { + entity.association.name = entity.newName } } @@ -1200,18 +1475,17 @@ object RenameService : AuditService() } - override fun findEntity(auditId: Int): AbstractAudit { - return testFind(Renames,Rename,auditId) + return testFind(Renames, Rename, auditId) } - private fun toRenameVo(rename: Rename):RenameVo{ - return RenameVo(renameId = rename.id.value,newName = rename.newName,cause = rename.cause) + private fun toRenameVo(rename: Rename): RenameVo { + return RenameVo(renameId = rename.id.value, newName = rename.newName, cause = rename.cause) } override fun getCheckVo(id: EntityID): RenameCheckVo { - return (Rename.findById(id)?:throw IllegalArgumentException("找不到[id=${id}]${dataType}")).let { - RenameCheckVo(renameVo = toRenameVo(it),auditCheckVo = toCheckVo(it.audit)) + return (Rename.findById(id) ?: throw IllegalArgumentException("找不到[id=${id}]${dataType}")).let { + RenameCheckVo(renameVo = toRenameVo(it), auditCheckVo = toCheckVo(it.audit)) } } @@ -1219,7 +1493,11 @@ object RenameService : AuditService() return transaction { return@transaction createSortedBy(Rename).map { val audit = toAuditLoggingVo(it.audit) ?: throw IllegalArgumentException("转换审核记录出错!!!!") - AuditRenameVo(renameVo = toRenameVo(rename = it),audit = audit,associationVo = AssociationService.toAssociationVo(it.association)) + AuditRenameVo( + renameVo = toRenameVo(rename = it), + audit = audit, + associationVo = AssociationService.toAssociationVo(it.association) + ) }.apply { log.info("找到${this.size}份${ActivityService.dataType}") } @@ -1309,29 +1587,34 @@ object BackgroundService : AbstractService() { } - fun toManagerVo(manager: Manager):ManagerInfoVo{ - return ManagerInfoVo(duty = manager.duty.let { Duty.valueOf(it) },name=manager.name, - headImg = manager.headImg?.filepath,desc = manager.desc) + fun toManagerVo(manager: Manager): ManagerInfoVo { + return ManagerInfoVo( + duty = manager.duty.let { Duty.valueOf(it) }, name = manager.name, + headImg = manager.headImg?.filepath, desc = manager.desc + ) } - /** * 加载部门部长,和总人数 * */ - fun load():ManagerDutySumVo{ + fun load(): ManagerDutySumVo { return transaction { - val secretariat=Manager.find { Managers.duty eq Duty.SecretaryOfTheMinister.name }.first() - val secretariatCount=Manager.find{ Managers.duty eq Duty.SecretaryDepartmentOfficer.name }.count() - val propaganda=Manager.find {Managers.duty eq Duty.PropagandaDepartment.name }.first() - val propagandaCount=Manager.find{ Managers.duty eq Duty.PublicityDepartmentOfficer.name }.count() - val publicRelationsDepartment=Manager.find{ Managers.duty eq Duty.LiaisonMinister.name }.first() - val publicRelationsDepartmentCount=Manager.find{ Managers.duty eq Duty.LiaisonOfficer.name }.count() - ManagerDutySumVo(secretariat = ManagerDutyVo(manager = toManagerVo(secretariat),people = secretariatCount.toInt()), - propaganda = ManagerDutyVo(manager = toManagerVo(propaganda),people = propagandaCount.toInt()), - publicRelationsDepartment = ManagerDutyVo(manager = toManagerVo(publicRelationsDepartment), - people=publicRelationsDepartmentCount.toInt())) + val secretariat = Manager.find { Managers.duty eq Duty.SecretaryOfTheMinister.name }.first() + val secretariatCount = Manager.find { Managers.duty eq Duty.SecretaryDepartmentOfficer.name }.count() + val propaganda = Manager.find { Managers.duty eq Duty.PropagandaDepartment.name }.first() + val propagandaCount = Manager.find { Managers.duty eq Duty.PublicityDepartmentOfficer.name }.count() + val publicRelationsDepartment = Manager.find { Managers.duty eq Duty.LiaisonMinister.name }.first() + val publicRelationsDepartmentCount = Manager.find { Managers.duty eq Duty.LiaisonOfficer.name }.count() + ManagerDutySumVo( + secretariat = ManagerDutyVo(manager = toManagerVo(secretariat), people = secretariatCount.toInt()), + propaganda = ManagerDutyVo(manager = toManagerVo(propaganda), people = propagandaCount.toInt()), + publicRelationsDepartment = ManagerDutyVo( + manager = toManagerVo(publicRelationsDepartment), + people = publicRelationsDepartmentCount.toInt() + ) + ) } } @@ -1340,18 +1623,22 @@ object BackgroundService : AbstractService() { * * @return */ - fun loadDetail():AllOfficerVo{ + fun loadDetail(): AllOfficerVo { return transaction { - val secretariat=Manager.find{ Managers.duty eq Duty.SecretaryDepartmentOfficer.name }.map { + val secretariat = Manager.find { Managers.duty eq Duty.SecretaryDepartmentOfficer.name }.map { toManagerVo(it) } - val propaganda=Manager.find {Managers.duty eq Duty.PublicityDepartmentOfficer.name }.map { + val propaganda = Manager.find { Managers.duty eq Duty.PublicityDepartmentOfficer.name }.map { toManagerVo(it) } - val publicRelationsDepartment=Manager.find { Managers.duty eq Duty.LiaisonOfficer.name }.map { + val publicRelationsDepartment = Manager.find { Managers.duty eq Duty.LiaisonOfficer.name }.map { toManagerVo(it) } - AllOfficerVo(secretariat=secretariat,propaganda = propaganda,publicRelationsDepartment=publicRelationsDepartment) + AllOfficerVo( + secretariat = secretariat, + propaganda = propaganda, + publicRelationsDepartment = publicRelationsDepartment + ) } } diff --git a/test/ApplicationTest.kt b/test/ApplicationTest.kt index 57923bb..433529c 100644 --- a/test/ApplicationTest.kt +++ b/test/ApplicationTest.kt @@ -119,7 +119,8 @@ class ApplicationTest { @Test fun test(){ - println("12345678".substring(IntRange(4,5))) + val c:String?=null + c.let { println(it) } } @Test