diff --git a/build.gradle.kts b/build.gradle.kts index 7ed3d4f..7585b66 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -64,9 +64,13 @@ dependencies { testImplementation("io.ktor:ktor-server-tests:$ktor_version") } +// +//kotlin.sourceSets["main"].kotlin.srcDirs("src") +//kotlin.sourceSets["test"].kotlin.srcDirs("test") -kotlin.sourceSets["main"].kotlin.srcDirs("src") -kotlin.sourceSets["test"].kotlin.srcDirs("test") - -sourceSets["main"].resources.srcDirs("resources") -sourceSets["test"].resources.srcDirs("testresources") +listOf("main","test").forEach { + kotlin.sourceSets[it].apply { + kotlin.srcDirs("src/${name}/kotlin") + resources.srcDirs("src/${name}/resources") + } +} \ No newline at end of file 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 fc2e0bc..178a10d 100644 --- a/module/src/main/kotlin/com/gyf/csams/module/ShareVo.kt +++ b/module/src/main/kotlin/com/gyf/csams/module/ShareVo.kt @@ -626,7 +626,7 @@ data class ManagerDutySumVo(val secretariat:ManagerDutyVo, 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) +data class ExamVo(val questionId:Int?=null,val question:String,val optionsA:String,val optionsB:String,val optionsC:String,val optionsD:String,val rightOption:Int) /** * 更新题库 @@ -641,32 +641,12 @@ data class AddExamVo(val questions:List, 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 SearchExamVo(val associationId:Int, override val token: Token, + override val clientType: ClientType=ClientType.Foreground):ClientBaseVo() -/** - * 试题 - * - */ -data class AnswerVo(val examVo: ExamVo,val answer:Int?=null,val paperVo: TestPaperVo) +data class ApplyAnswerVo(val examVo: ExamVo,val answer:Int) -/** - * 答题记录 - * - * @property questionId - * @property paperId - * @property answer - */ -data class ApplyAnswerVo(val questionId:Int,val paperId:Int,val answer:Int) /** * 答卷 * @@ -675,21 +655,15 @@ data class ApplyAnswerVo(val questionId:Int,val paperId:Int,val answer:Int) * @property clientType */ data class AddAnswerVo(val answers:List, - val associationId:Int, - override val token: Token, override val clientType: ClientType=ClientType.Foreground):ClientBaseVo() + override val token: Token, + val associationId: Int, + 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() - /** * 申请入团检查 */ diff --git a/src/main/kotlin/com/gyf/csams/Controller.kt b/src/main/kotlin/com/gyf/csams/Controller.kt index a80d1cb..a3c349a 100644 --- a/src/main/kotlin/com/gyf/csams/Controller.kt +++ b/src/main/kotlin/com/gyf/csams/Controller.kt @@ -375,7 +375,7 @@ fun Application.AssociationController() { post("/check/apply"){ - call.withToken { + call.withToken { try { val body=AssociationService.applyAssociation(vo = it) call.respond(ApiResponse(message = "入团验证信息获取成功",body =body)) @@ -387,7 +387,7 @@ fun Application.AssociationController() { } post("/create/paper"){ - call.withToken { + call.withToken { try { call.respond(ApiResponse(message = "试卷创建成功,请开始作答",body = AssociationService.createPaper(vo=it))) } catch (e: Exception) { @@ -411,7 +411,7 @@ fun Application.AssociationController() { post("/check/join"){ - call.withToken { + call.withToken { try { call.respond(ApiResponse(message = "入团记录查询成功",body=AssociationService.joinAssociation(vo=it))) } catch (e: Exception) { diff --git a/src/main/kotlin/com/gyf/csams/Dao.kt b/src/main/kotlin/com/gyf/csams/Dao.kt index d6c23ba..9ed4946 100644 --- a/src/main/kotlin/com/gyf/csams/Dao.kt +++ b/src/main/kotlin/com/gyf/csams/Dao.kt @@ -1,7 +1,6 @@ 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 @@ -433,44 +432,23 @@ class Question(id:EntityID):IntEntity(id){ 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() + val answer:Column = integer("answer") - @TableComment("试卷") - val paperId:Column> = reference("paper_id",TestPapers) + @TableComment("入团申请记录") + val joinId:Column> = reference("join_id",JoinAssociations) } 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 + var join by JoinAssociation referencedOn Answers.joinId } @TableComment("入团申请记录") @@ -487,9 +465,6 @@ object JoinAssociations:IntIdTable(){ @TableComment("审核时间") val auditTime:Column = datetime("audit_time").nullable() - @TableComment("试卷") - val paperId:Column?> = reference("paper_id",TestPapers).nullable() - @TableComment("申请结果") val result:Column = bool("result").nullable() } @@ -498,7 +473,6 @@ 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 83f4ee4..0709261 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,Questions,TestPapers,Answers,JoinAssociations) + Renames,Questions,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 a562328..76a4cc3 100644 --- a/src/main/kotlin/com/gyf/csams/Service.kt +++ b/src/main/kotlin/com/gyf/csams/Service.kt @@ -44,13 +44,19 @@ object AccountService : AbstractService() { } } + fun toUserInfo(user: User):UserInfoVo{ + return UserInfoVo(name = user.name, headImg = user.headImg?.filepath, desc = user.desc) + } + /** * 注册 */ fun register(userVo: UserRegVo): String? { try { return transaction { - val originPassword = randomNum(8) + + val originPassword = if(environment.developmentMode) (1..8).joinToString("") else randomNum(8) + log.info("密码:${originPassword}") User.new { studentId = userVo.studentId name = userVo.name @@ -324,7 +330,7 @@ object MainService : AbstractService() { return@transaction LeaveMessage.all().toList().map { LeaveMessageDto( message = "${it.user.name}说:${it.message}", - user = UserInfoVo(name = it.user.name, headImg = it.user.headImg?.filepath, desc = it.user.desc) + user = AccountService.toUserInfo(user = it.user) ) } } @@ -342,8 +348,10 @@ object FileService : AbstractService() { super.init(environment) this.uploadDir = environment.config.property("ktor.deployment.filePath").getString() + log.info(this::class.java.classLoader.getResource("")?.path) + filePath = - this::class.java.classLoader.getResource(uploadDir)?.path ?: throw IllegalArgumentException("初始化资源目录失败") + environment.classLoader.getResource(uploadDir)?.path ?: throw IllegalArgumentException("初始化资源目录失败") File(filePath).let { when { it.exists() -> log.info("上传路径[${filePath}]已存在") @@ -690,12 +698,7 @@ abstract class AuditService : AbstractService() { return it?.let { logging -> val auditLogging = AuditLoggingVo( id = logging.id.value, - user = - UserInfoVo( - name = logging.user.name, - headImg = logging.user.headImg?.filepath, - desc = logging.user.desc - ), + user = AccountService.toUserInfo(user = logging.user), applyTime = logging.applyTime.toLong(), manager = logging.manager?.let { ManagerInfoVo( @@ -775,7 +778,7 @@ object AssociationService : AuditService0 + return JoinAssociationVo(id=join.id.value,user = AccountService.toUserInfo(join.user), + associationVo = toAssociationVo(join.association),hasPaper = hasPaper,result = join.result, + applyTime = join.applyTime.toLong(),auditTime = join.auditTime?.toLong()) + } + /** * 显示答卷 * * @param vo * @return */ - fun showAnswer(vo:ShowAnswerVo):List{ + 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())) + Answer.find{ Answers.joinId eq join.id }.map { + ApplyAnswerVo(examVo = toExamVo(it.question),answer = it.answer) } } } @@ -840,21 +849,10 @@ object AssociationService : AuditService{ + fun createPaper(vo:SearchExamVo):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 { + it.shuffled().map { toExamVo(question = it) } } @@ -888,11 +874,23 @@ object AssociationService : AuditService{ + fun joinAssociation(vo:SearchExamVo):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) + JoinAssociation.find { JoinAssociations.associationId eq association.id }.sortedByDescending { it.applyTime }.map { + toJoinVo(join=it) } } } @@ -1001,7 +992,7 @@ object AssociationService : AuditService