活动点赞收藏

master
pan 3 years ago
parent 83286d547d
commit c8100c29d5
  1. 24
      module/src/main/kotlin/com/gyf/csams/module/ShareVo.kt
  2. 35
      src/main/kotlin/com/gyf/csams/Controller.kt
  3. 24
      src/main/kotlin/com/gyf/csams/Dao.kt
  4. 2
      src/main/kotlin/com/gyf/csams/MySQL.kt
  5. 260
      src/main/kotlin/com/gyf/csams/Service.kt

@ -696,5 +696,27 @@ data class AuditJoinVo(val joinId:Int, val result:Boolean,
override val clientType: ClientType=ClientType.Foreground override val clientType: ClientType=ClientType.Foreground
):ClientBaseVo() ):ClientBaseVo()
/**
* 组成申请社团试卷的题库最小题目数量
*/
const val QUESTION_MIN_SIZE=5
enum class TendencyType(val desc:String){
Like("点赞"),
Collect("收藏")
}
data class TendencyVo(val activityId: Int, val type:TendencyType,
override val token: Token,
override val clientType: ClientType=ClientType.Foreground
):ClientBaseVo()
data class CheckTendencyVo(val activityId: Int, override val token: Token,
override val clientType: ClientType=ClientType.Foreground):ClientBaseVo()
data class CheckTendencyResVo(val hasLike:Boolean, val hasCollect:Boolean)
data class FindTendencyVo(val type:TendencyType, override val token: Token,
override val clientType: ClientType=ClientType.Foreground):ClientBaseVo()
const val QUESTION_MIN_SIZE=5

@ -564,6 +564,41 @@ fun Application.ActivityController(){
check(ActivityService) check(ActivityService)
read(ActivityService,Activities) read(ActivityService,Activities)
post("/tendency"){
call.withToken<TendencyVo> {
try {
ActivityService.tendency(vo=it)
call.respond(ApiResponse(message = "${it.type.desc}成功",body = true))
} catch (e: Exception) {
log.error(e)
call.respond(ApiResponse(message = "${it.type.desc}失败",body = false))
}
}
}
post("/tendency/check"){
call.withToken<CheckTendencyVo> {
try {
call.respond(ApiResponse(message = "活动倾向查询成功",body=ActivityService.checkTendency(vo=it)))
} catch (e: Exception) {
log.error(e)
call.respond(ApiResponse(message = "活动倾向查询失败",body=null))
}
}
}
post("/tendency/find"){
call.withToken<FindTendencyVo> {
try {
call.respond(ApiResponse(message = "活动倾向查询成功",body=ActivityService.findTendency(vo=it)))
} catch (e: Exception) {
log.error(e)
call.respond(ApiResponse(message = "活动倾向查询失败",body=null))
}
}
}
post("/list/all"){ post("/list/all"){
call.withToken<OnlyToken> { call.withToken<OnlyToken> {
call.respond(ApiResponse(message = "活动信息加载",body = ActivityService.listAll())) call.respond(ApiResponse(message = "活动信息加载",body = ActivityService.listAll()))

@ -1,6 +1,7 @@
package com.gyf.csams package com.gyf.csams
import com.gyf.csams.JoinAssociations.defaultExpression
import org.jetbrains.exposed.dao.IntEntity import org.jetbrains.exposed.dao.IntEntity
import org.jetbrains.exposed.dao.IntEntityClass import org.jetbrains.exposed.dao.IntEntityClass
import org.jetbrains.exposed.dao.id.EntityID import org.jetbrains.exposed.dao.id.EntityID
@ -477,3 +478,26 @@ class JoinAssociation(id:EntityID<Int>):IntEntity(id){
var applyTime by JoinAssociations.applyTime var applyTime by JoinAssociations.applyTime
var auditTime by JoinAssociations.auditTime var auditTime by JoinAssociations.auditTime
} }
@TableComment("用户倾向")
object Tendencies:IntIdTable(){
@TableComment("点赞用户")
val userId:Column<EntityID<Int>> = reference("user_id",Users)
@TableComment("点赞活动")
val activityId:Column<EntityID<Int>> = reference("activity_id",Activities)
@TableComment("点赞时间")
val createTime:Column<LocalDateTime> = datetime("create_time").defaultExpression(CurrentDateTime())
@TableComment("倾向类型")
val type:Column<Int> = integer("type")
}
class Tendency(id:EntityID<Int>):IntEntity(id){
companion object:IntEntityClass<Tendency>(Tendencies)
var user by User referencedOn Tendencies.userId
var activity by Activity referencedOn Tendencies.activityId
val createTime by Tendencies.createTime
var type by Tendencies.type
}

@ -42,7 +42,7 @@ fun initTable(){
transaction { transaction {
val tableList= arrayOf(Users,UserTokens,Managers,ManagerTokens,AuditLeggings,LeaveMessages, val tableList= arrayOf(Users,UserTokens,Managers,ManagerTokens,AuditLeggings,LeaveMessages,
ImageFiles,Associations,AssociationMembers,Notifications,Activities,PhotoAlbums,ActivityComments, ImageFiles,Associations,AssociationMembers,Notifications,Activities,PhotoAlbums,ActivityComments,
Renames,Questions,Answers,JoinAssociations) Renames,Questions,Answers,JoinAssociations,Tendencies)
SchemaUtils.createMissingTablesAndColumns(*tableList) SchemaUtils.createMissingTablesAndColumns(*tableList)
updateComment(*tableList) updateComment(*tableList)

@ -44,7 +44,7 @@ object AccountService : AbstractService() {
} }
} }
fun toUserInfo(user: User):UserInfoVo{ fun toUserInfo(user: User): UserInfoVo {
return UserInfoVo(name = user.name, headImg = user.headImg?.filepath, desc = user.desc) return UserInfoVo(name = user.name, headImg = user.headImg?.filepath, desc = user.desc)
} }
@ -55,7 +55,7 @@ object AccountService : AbstractService() {
try { try {
return transaction { return transaction {
val originPassword = if(environment.developmentMode) (1..8).joinToString("") else randomNum(8) val originPassword = if (environment.developmentMode) (1..8).joinToString("") else randomNum(8)
log.info("密码:${originPassword}") log.info("密码:${originPassword}")
User.new { User.new {
studentId = userVo.studentId studentId = userVo.studentId
@ -156,15 +156,15 @@ object AccountService : AbstractService() {
} }
} }
fun uploadHeadImg(data: List<PartData>){ fun uploadHeadImg(data: List<PartData>) {
val userId=data.getFormParam("id").toInt() val userId = data.getFormParam("id").toInt()
transaction { transaction {
val fileIds =FileService.storeFile(data) val fileIds = FileService.storeFile(data)
if(fileIds?.isNotEmpty()==true){ if (fileIds?.isNotEmpty() == true) {
val fileId=fileIds.first() val fileId = fileIds.first()
val user=User.findById(userId)?:throw UserIdError(userId) val user = User.findById(userId) ?: throw UserIdError(userId)
user.apply { user.apply {
headImg=ImageFile.findById(fileId)?:throw FileIdError(fileId) headImg = ImageFile.findById(fileId) ?: throw FileIdError(fileId)
} }
} }
} }
@ -172,34 +172,34 @@ object AccountService : AbstractService() {
fun refreshInfo(vo: InfoUpdateVo): PersonInfoVo { fun refreshInfo(vo: InfoUpdateVo): PersonInfoVo {
return transaction { return transaction {
when(vo.clientType){ when (vo.clientType) {
ClientType.Foreground->{ ClientType.Foreground -> {
val matchUser = User.findById(vo.token.id) ?: throw UserIdError(vo.token.id) val matchUser = User.findById(vo.token.id) ?: throw UserIdError(vo.token.id)
matchUser.apply { matchUser.apply {
vo.name?.let { vo.name?.let {
matchUser.name=it matchUser.name = it
} }
vo.desc?.let { vo.desc?.let {
matchUser.desc=it 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")
tokenRes(token=token,matchUser = matchUser) tokenRes(token = token, matchUser = matchUser)
} }
ClientType.Background->{ ClientType.Background -> {
val matchManager = Manager.findById(vo.token.id)?:throw ManagerIdError(vo.token.id) val matchManager = Manager.findById(vo.token.id) ?: throw ManagerIdError(vo.token.id)
matchManager.apply { matchManager.apply {
vo.name?.let { vo.name?.let {
matchManager.name=it matchManager.name = it
} }
vo.desc?.let { vo.desc?.let {
matchManager.desc=it matchManager.desc = it
} }
} }
val token=ManagerToken.find { ManagerTokens.managerId eq matchManager.id }.firstOrNull() val token = ManagerToken.find { ManagerTokens.managerId eq matchManager.id }.firstOrNull()
?: throw IllegalArgumentException("无法根据[matchId=${matchManager.id}]找到token") ?: throw IllegalArgumentException("无法根据[matchId=${matchManager.id}]找到token")
tokenRes(token=token,matchManager=matchManager) tokenRes(token = token, matchManager = matchManager)
} }
} }
} }
@ -658,19 +658,23 @@ abstract class AuditService<T, E, F> : AbstractService() {
return transaction { return transaction {
if (isFilter) { if (isFilter) {
// val nextAudit = AuditLeggings.alias("nextAudit") // val nextAudit = AuditLeggings.alias("nextAudit")
val c=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,AuditLeggings.result,AuditLeggings.nextAudit)) .slice(listOf(table.id, AuditLeggings.result, AuditLeggings.nextAudit))
.select { Users.id eq vo.token.id} .select { Users.id eq vo.token.id }
.filter { .filter {
log.info("it[AuditLeggings.result]=${it[AuditLeggings.result]},it[AuditLeggings.nextAudit]=${it[AuditLeggings.nextAudit]}") 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 it[AuditLeggings.result] == null || it[AuditLeggings.nextAudit]?.let { it1 ->
AuditLogging.findById(
it1
)?.result
} == null
} }
log.info("size:${c.size}") log.info("size:${c.size}")
if(c.size==1){ if (c.size == 1) {
getCheckVo(c.first()[table.id]) getCheckVo(c.first()[table.id])
}else{ } else {
null null
} }
} else { } else {
@ -809,9 +813,16 @@ object AssociationService : AuditService<AssociationRegVo, AuditAssociationVo, A
} }
} }
private fun toExamVo(question:Question):ExamVo{ private fun toExamVo(question: Question): ExamVo {
return ExamVo(questionId = question.id.value,question=question.question,optionsA = question.optionsA, return ExamVo(
optionsB = question.optionsB,optionsC = question.optionsC,optionsD = question.optionsD,rightOption = question.answer) questionId = question.id.value,
question = question.question,
optionsA = question.optionsA,
optionsB = question.optionsB,
optionsC = question.optionsC,
optionsD = question.optionsD,
rightOption = question.answer
)
} }
/** /**
@ -820,7 +831,7 @@ object AssociationService : AuditService<AssociationRegVo, AuditAssociationVo, A
* @param vo * @param vo
* @return * @return
*/ */
fun loadExam(vo:SearchExamVo):List<ExamVo>{ fun loadExam(vo: SearchExamVo): List<ExamVo> {
return transaction { return transaction {
Question.find { Questions.associationId eq vo.associationId }.map { Question.find { Questions.associationId eq vo.associationId }.map {
toExamVo(question = it) toExamVo(question = it)
@ -832,32 +843,34 @@ object AssociationService : AuditService<AssociationRegVo, AuditAssociationVo, A
* 提交答卷 * 提交答卷
* *
*/ */
fun applyAnswer(vo:AddAnswerVo){ fun applyAnswer(vo: AddAnswerVo) {
transaction { transaction {
val user=User.findById(vo.token.id)?:throw UserIdError(vo.token.id) val user = User.findById(vo.token.id) ?: throw UserIdError(vo.token.id)
val association=Association.findById(vo.associationId)?:throw AssociationIdError(vo.associationId) val association = Association.findById(vo.associationId) ?: throw AssociationIdError(vo.associationId)
val join=createJoin(association=association,user = user) val join = createJoin(association = association, user = user)
vo.answers.forEach { vo.answers.forEach {
val id=it.examVo.questionId?:throw IllegalArgumentException("问题id不存在") val id = it.examVo.questionId ?: throw IllegalArgumentException("问题id不存在")
val question=Question.findById(id)?:throw IllegalArgumentException("不存在[id=${id}]的问题") val question = Question.findById(id) ?: throw IllegalArgumentException("不存在[id=${id}]的问题")
Answer.new { Answer.new {
this.question=question this.question = question
answer= it.answer answer = it.answer
this.join=join this.join = join
} }
} }
} }
} }
private fun toJoinVo(join:JoinAssociation):JoinAssociationVo{ private fun toJoinVo(join: JoinAssociation): JoinAssociationVo {
val hasPaper=Answer.find { Answers.joinId eq join.id.value }.count()>0 val hasPaper = Answer.find { Answers.joinId eq join.id.value }.count() > 0
return JoinAssociationVo(id=join.id.value,user = AccountService.toUserInfo(join.user), return JoinAssociationVo(
associationVo = toAssociationVo(join.association),hasPaper = hasPaper,result = join.result, id = join.id.value, user = AccountService.toUserInfo(join.user),
applyTime = join.applyTime.toLong(),auditTime = join.auditTime?.toLong()) associationVo = toAssociationVo(join.association), hasPaper = hasPaper, result = join.result,
applyTime = join.applyTime.toLong(), auditTime = join.auditTime?.toLong()
)
} }
/** /**
@ -866,11 +879,11 @@ object AssociationService : AuditService<AssociationRegVo, AuditAssociationVo, A
* @param vo * @param vo
* @return * @return
*/ */
fun showAnswer(vo:ShowAnswerVo):List<ApplyAnswerVo>{ fun showAnswer(vo: ShowAnswerVo): List<ApplyAnswerVo> {
return transaction { return transaction {
val join=JoinAssociation.findById(vo.joinId)?:throw IllegalArgumentException("找不到[id=${vo.joinId}]申请记录") val join = JoinAssociation.findById(vo.joinId) ?: throw IllegalArgumentException("找不到[id=${vo.joinId}]申请记录")
Answer.find{ Answers.joinId eq join.id }.map { Answer.find { Answers.joinId eq join.id }.map {
ApplyAnswerVo(examVo = toExamVo(it.question),answer = it.answer) ApplyAnswerVo(examVo = toExamVo(it.question), answer = it.answer)
} }
} }
} }
@ -882,10 +895,10 @@ object AssociationService : AuditService<AssociationRegVo, AuditAssociationVo, A
* @param association * @param association
* @param user * @param user
*/ */
private fun createJoin(association: Association,user:User):JoinAssociation{ private fun createJoin(association: Association, user: User): JoinAssociation {
return JoinAssociation.new { return JoinAssociation.new {
this.association=association this.association = association
this.user=user this.user = user
} }
} }
@ -895,9 +908,9 @@ object AssociationService : AuditService<AssociationRegVo, AuditAssociationVo, A
* @param vo * @param vo
* @return * @return
*/ */
fun createPaper(vo:SearchExamVo):List<ExamVo>{ fun createPaper(vo: SearchExamVo): List<ExamVo> {
return transaction { return transaction {
val association= Association.findById(vo.associationId)?:throw AssociationIdError(vo.associationId) val association = Association.findById(vo.associationId) ?: throw AssociationIdError(vo.associationId)
Question.find { Questions.associationId eq association.id }.let { it -> Question.find { Questions.associationId eq association.id }.let { it ->
it.shuffled().map { it.shuffled().map {
toExamVo(question = it) toExamVo(question = it)
@ -907,9 +920,11 @@ object AssociationService : AuditService<AssociationRegVo, AuditAssociationVo, A
} }
private fun createJoinNotification(user:User, association:Association){ private fun createJoinNotification(user: User, association: Association) {
AssociationMember.find { AssociationMembers.associationId eq association.id and AssociationMember.find {
(AssociationMembers.isHead eq true) }.firstOrNull()?.apply { AssociationMembers.associationId eq association.id and
(AssociationMembers.isHead eq true)
}.firstOrNull()?.apply {
Notification.new { Notification.new {
this.title = "入团申请通知" this.title = "入团申请通知"
this.content = "用户${user.name}申请加入社团" this.content = "用户${user.name}申请加入社团"
@ -923,28 +938,29 @@ object AssociationService : AuditService<AssociationRegVo, AuditAssociationVo, A
* 申请入团 * 申请入团
* *
*/ */
fun applyAssociation(vo:SearchExamVo):ApplyAssociationResultVo{ fun applyAssociation(vo: SearchExamVo): ApplyAssociationResultVo {
return transaction { return transaction {
val user=User.findById(vo.token.id)?:throw UserIdError(vo.token.id) val user = User.findById(vo.token.id) ?: throw UserIdError(vo.token.id)
val association= Association.findById(vo.associationId)?:throw AssociationIdError(vo.associationId) 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 { JoinAssociation.find { JoinAssociations.userId eq vo.token.id and (JoinAssociations.result eq null) }
if(it!=null){ .firstOrNull().let {
return@transaction ApplyAssociationResultVo(associationVo = toAssociationVo(it.association)) if (it != null) {
} return@transaction ApplyAssociationResultVo(associationVo = toAssociationVo(it.association))
} }
}
Question.find { Questions.associationId eq association.id }.let { it ->
//题库需要满足最少题目数才能生成试卷 Question.find { Questions.associationId eq association.id }.let { it ->
if(it.count()>=QUESTION_MIN_SIZE){ //题库需要满足最少题目数才能生成试卷
ApplyAssociationResultVo(result = true,hasPaper = true) if (it.count() >= QUESTION_MIN_SIZE) {
} ApplyAssociationResultVo(result = true, hasPaper = true)
//免试入团申请 }
else{ //免试入团申请
createJoin(association=association,user=user) else {
createJoinNotification(association=association,user=user) createJoin(association = association, user = user)
ApplyAssociationResultVo(result = true,hasPaper = false) createJoinNotification(association = association, user = user)
} ApplyAssociationResultVo(result = true, hasPaper = false)
} }
}
} }
} }
@ -952,11 +968,12 @@ object AssociationService : AuditService<AssociationRegVo, AuditAssociationVo, A
* 入团申请记录 * 入团申请记录
* *
*/ */
fun joinAssociation(vo:SearchExamVo):List<JoinAssociationVo>{ fun joinAssociation(vo: SearchExamVo): List<JoinAssociationVo> {
return transaction { return transaction {
val association=Association.findById(vo.associationId)?:throw AssociationIdError(vo.associationId) val association = Association.findById(vo.associationId) ?: throw AssociationIdError(vo.associationId)
JoinAssociation.find { JoinAssociations.associationId eq association.id }.sortedByDescending { it.applyTime }.map { JoinAssociation.find { JoinAssociations.associationId eq association.id }
toJoinVo(join=it) .sortedByDescending { it.applyTime }.map {
toJoinVo(join = it)
} }
} }
} }
@ -965,16 +982,16 @@ object AssociationService : AuditService<AssociationRegVo, AuditAssociationVo, A
* 审核入团申请 * 审核入团申请
* @param vo * @param vo
*/ */
fun auditJoin(vo:AuditJoinVo){ fun auditJoin(vo: AuditJoinVo) {
transaction { transaction {
val join=JoinAssociation.findById(vo.joinId)?:throw IllegalArgumentException("审核记录不存在") val join = JoinAssociation.findById(vo.joinId) ?: throw IllegalArgumentException("审核记录不存在")
join.result=vo.result join.result = vo.result
join.auditTime= LocalDateTime.now() join.auditTime = LocalDateTime.now()
if(vo.result){ if (vo.result) {
AssociationMember.new { AssociationMember.new {
user=join.user user = join.user
association=join.association association = join.association
isHead=false isHead = false
} }
//入团申请通过,通知社团其他人 //入团申请通过,通知社团其他人
AssociationMember.find { AssociationMembers.associationId eq join.association.id }.forEach { AssociationMember.find { AssociationMembers.associationId eq join.association.id }.forEach {
@ -989,11 +1006,11 @@ object AssociationService : AuditService<AssociationRegVo, AuditAssociationVo, A
} }
} }
//把审核结果发送给申请人 //把审核结果发送给申请人
Notification.new{ Notification.new {
this.title="入团审核结果" this.title = "入团审核结果"
this.content="您申请加入${join.association.name}社团审核${if(vo.result)"通过" else "不通过"}" this.content = "您申请加入${join.association.name}社团审核${if (vo.result) "通过" else "不通过"}"
this.receiverId=join.user.id.value this.receiverId = join.user.id.value
receiverClient=ClientType.Foreground.name receiverClient = ClientType.Foreground.name
} }
} }
} }
@ -1005,18 +1022,17 @@ object AssociationService : AuditService<AssociationRegVo, AuditAssociationVo, A
*/ */
fun updateExam(vo: AddExamVo) { fun updateExam(vo: AddExamVo) {
transaction { transaction {
val association=Association.findById(vo.associationId)?:throw IllegalArgumentException("找不到社团信息") val association = Association.findById(vo.associationId) ?: throw IllegalArgumentException("找不到社团信息")
vo.deleteIds?.let { vo.deleteIds?.let {
//删除社团题目 //删除社团题目
Question.find { Questions.associationId eq association.id and (Questions.id inList it ) }.forEach { Question.find { Questions.associationId eq association.id and (Questions.id inList it) }.forEach {
log.info("删除[id=${it.id}]题目") log.info("删除[id=${it.id}]题目")
it.delete() it.delete()
} }
} }
vo.questions.forEach { vo.questions.forEach { exam ->
exam->
exam.questionId.let { exam.questionId.let {
if (it == null) { if (it == null) {
Question.new { Question.new {
@ -1228,6 +1244,52 @@ object ActivityService : AuditService<ActivityApplyVo, AuditActVo, ActivityCheck
return testFind(Activities, Activity, auditId) return testFind(Activities, Activity, auditId)
} }
private fun checkTendency(userId:Int, activityId:Int, type:TendencyType): SizedIterable<Tendency> {
val user=User.findById(userId)?:throw UserIdError(userId)
val activity=Activity.findById(activityId)?:throw ActivityIdError(activityId)
return Tendency.find { Tendencies.userId eq user.id and (Tendencies.activityId eq activity.id) and
(Tendencies.type eq type.ordinal) }
}
fun checkTendency(vo: CheckTendencyVo):CheckTendencyResVo{
return transaction {
val hasLike= checkTendency(userId = vo.token.id,activityId = vo.activityId,type = TendencyType.Like).count()==1L
val hasCollect=checkTendency(userId = vo.token.id,activityId = vo.activityId,type = TendencyType.Collect).count()==1L
CheckTendencyResVo(hasLike=hasLike,hasCollect=hasCollect)
}
}
fun findTendency(vo:FindTendencyVo):List<ActivityVo>{
return transaction {
val user=User.findById(vo.token.id)?:throw UserIdError(vo.token.id)
Tendency.find { Tendencies.userId eq user.id and (Tendencies.type eq vo.type.ordinal) }.map {
toActivityVo(activity = it.activity)
}
}
}
/**
* 活动倾向
*
*/
fun tendency(vo: TendencyVo) {
transaction {
checkTendency(userId = vo.token.id,activityId = vo.activityId,type = vo.type).apply {
if (count() == 1L) {
first().delete()
} else {
Tendency.new {
this.user= User[vo.token.id]
this.activity= Activity[vo.activityId]
this.type=vo.type.ordinal
}
}
}
}
}
/** /**
* 查看活动信息 * 查看活动信息
* *

Loading…
Cancel
Save