活动点赞收藏

master
pan 4 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. 84
      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
):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()

@ -564,6 +564,41 @@ fun Application.ActivityController(){
check(ActivityService)
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"){
call.withToken<OnlyToken> {
call.respond(ApiResponse(message = "活动信息加载",body = ActivityService.listAll()))

@ -1,6 +1,7 @@
package com.gyf.csams
import com.gyf.csams.JoinAssociations.defaultExpression
import org.jetbrains.exposed.dao.IntEntity
import org.jetbrains.exposed.dao.IntEntityClass
import org.jetbrains.exposed.dao.id.EntityID
@ -477,3 +478,26 @@ class JoinAssociation(id:EntityID<Int>):IntEntity(id){
var applyTime by JoinAssociations.applyTime
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 {
val tableList= arrayOf(Users,UserTokens,Managers,ManagerTokens,AuditLeggings,LeaveMessages,
ImageFiles,Associations,AssociationMembers,Notifications,Activities,PhotoAlbums,ActivityComments,
Renames,Questions,Answers,JoinAssociations)
Renames,Questions,Answers,JoinAssociations,Tendencies)
SchemaUtils.createMissingTablesAndColumns(*tableList)
updateComment(*tableList)

@ -665,7 +665,11 @@ abstract class AuditService<T, E, F> : AbstractService() {
.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
it[AuditLeggings.result] == null || it[AuditLeggings.nextAudit]?.let { it1 ->
AuditLogging.findById(
it1
)?.result
} == null
}
log.info("size:${c.size}")
if (c.size == 1) {
@ -810,8 +814,15 @@ 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,rightOption = question.answer)
return ExamVo(
questionId = question.id.value,
question = question.question,
optionsA = question.optionsA,
optionsB = question.optionsB,
optionsC = question.optionsC,
optionsD = question.optionsD,
rightOption = question.answer
)
}
/**
@ -855,9 +866,11 @@ object AssociationService : AuditService<AssociationRegVo, AuditAssociationVo, A
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),
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())
applyTime = join.applyTime.toLong(), auditTime = join.auditTime?.toLong()
)
}
/**
@ -908,8 +921,10 @@ 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 {
AssociationMember.find {
AssociationMembers.associationId eq association.id and
(AssociationMembers.isHead eq true)
}.firstOrNull()?.apply {
Notification.new {
this.title = "入团申请通知"
this.content = "用户${user.name}申请加入社团"
@ -927,7 +942,8 @@ object AssociationService : AuditService<AssociationRegVo, AuditAssociationVo, A
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 {
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))
}
@ -955,7 +971,8 @@ object AssociationService : AuditService<AssociationRegVo, AuditAssociationVo, A
fun joinAssociation(vo: SearchExamVo): List<JoinAssociationVo> {
return transaction {
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 }
.sortedByDescending { it.applyTime }.map {
toJoinVo(join = it)
}
}
@ -1015,8 +1032,7 @@ object AssociationService : AuditService<AssociationRegVo, AuditAssociationVo, A
}
}
vo.questions.forEach {
exam->
vo.questions.forEach { exam ->
exam.questionId.let {
if (it == null) {
Question.new {
@ -1228,6 +1244,52 @@ object ActivityService : AuditService<ActivityApplyVo, AuditActVo, ActivityCheck
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