|
|
|
@ -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<T, E, F> : 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 : AuditService<AssociationRegVo, AuditAssociationVo, A |
|
|
|
|
|
|
|
|
|
private fun toExamVo(question:Question):ExamVo{ |
|
|
|
|
return ExamVo(questionId = question.id.value,question=question.question,optionsA = question.optionsA, |
|
|
|
|
optionsB = question.optionsB,optionsC = question.optionsC,optionsD = question.optionsD,answer = question.answer) |
|
|
|
|
optionsB = question.optionsB,optionsC = question.optionsC,optionsD = question.optionsD,rightOption = question.answer) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -798,37 +801,43 @@ object AssociationService : AuditService<AssociationRegVo, AuditAssociationVo, A |
|
|
|
|
*/ |
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
val association=Association.findById(vo.associationId)?:throw AssociationIdError(vo.associationId) |
|
|
|
|
val join=createJoin(association=association,user = user) |
|
|
|
|
|
|
|
|
|
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}]的问题") |
|
|
|
|
val id=it.examVo.questionId?:throw IllegalArgumentException("问题id不存在") |
|
|
|
|
|
|
|
|
|
val question=Question.findById(id)?:throw IllegalArgumentException("不存在[id=${id}]的问题") |
|
|
|
|
|
|
|
|
|
Answer.new { |
|
|
|
|
this.question=question |
|
|
|
|
answer=it.answer |
|
|
|
|
this.paper=paper |
|
|
|
|
answer= it.answer |
|
|
|
|
this.join=join |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
createJoin(association = association,user=user) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun toJoinVo(join:JoinAssociation):JoinAssociationVo{ |
|
|
|
|
val hasPaper=Answer.find { Answers.joinId eq join.id.value }.count()>0 |
|
|
|
|
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<AnswerVo>{ |
|
|
|
|
fun showAnswer(vo:ShowAnswerVo):List<ApplyAnswerVo>{ |
|
|
|
|
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<AssociationRegVo, AuditAssociationVo, A |
|
|
|
|
* @param association |
|
|
|
|
* @param user |
|
|
|
|
*/ |
|
|
|
|
private fun createJoin(association: Association,user:User){ |
|
|
|
|
JoinAssociation.new { |
|
|
|
|
private fun createJoin(association: Association,user:User):JoinAssociation{ |
|
|
|
|
return 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 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -864,23 +862,11 @@ object AssociationService : AuditService<AssociationRegVo, AuditAssociationVo, A |
|
|
|
|
* @param vo |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
fun createPaper(vo:ApplyAssociationVo):List<ExamVo>{ |
|
|
|
|
fun createPaper(vo:SearchExamVo):List<ExamVo>{ |
|
|
|
|
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<AssociationRegVo, AuditAssociationVo, A |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun createJoinNotification(user:User, association:Association){ |
|
|
|
|
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 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 申请入团 |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
fun applyAssociation(vo:ApplyAssociationVo):ApplyAssociationResultVo{ |
|
|
|
|
fun applyAssociation(vo:SearchExamVo):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) |
|
|
|
@ -910,6 +908,7 @@ object AssociationService : AuditService<AssociationRegVo, AuditAssociationVo, A |
|
|
|
|
//免试入团申请 |
|
|
|
|
else{ |
|
|
|
|
createJoin(association=association,user=user) |
|
|
|
|
createJoinNotification(association=association,user=user) |
|
|
|
|
ApplyAssociationResultVo(result = true,hasPaper = false) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -920,19 +919,11 @@ object AssociationService : AuditService<AssociationRegVo, AuditAssociationVo, A |
|
|
|
|
* 入团申请记录 |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
fun joinAssociation(vo:ApplyAssociationVo):List<JoinAssociationVo>{ |
|
|
|
|
fun joinAssociation(vo:SearchExamVo):List<JoinAssociationVo>{ |
|
|
|
|
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<AssociationRegVo, AuditAssociationVo, A |
|
|
|
|
optionsB = exam.optionsB |
|
|
|
|
optionsC = exam.optionsC |
|
|
|
|
optionsD = exam.optionsD |
|
|
|
|
this.answer = exam.answer |
|
|
|
|
this.answer = exam.rightOption |
|
|
|
|
this.association = association |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
@ -1012,7 +1003,7 @@ object AssociationService : AuditService<AssociationRegVo, AuditAssociationVo, A |
|
|
|
|
optionsB = exam.optionsB |
|
|
|
|
optionsC = exam.optionsC |
|
|
|
|
optionsD = exam.optionsD |
|
|
|
|
this.answer = exam.answer |
|
|
|
|
this.answer = exam.rightOption |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -1286,7 +1277,7 @@ object ActivityService : AuditService<ActivityApplyVo, AuditActVo, ActivityCheck |
|
|
|
|
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), |
|
|
|
|
user = AccountService.toUserInfo(it.user), |
|
|
|
|
createTime = it.createTime.toLong(), content = it.content |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|