|
|
|
@ -2,6 +2,7 @@ package com.gyf.csams |
|
|
|
|
|
|
|
|
|
import io.ktor.application.* |
|
|
|
|
import io.ktor.http.content.* |
|
|
|
|
import org.jetbrains.exposed.sql.and |
|
|
|
|
import org.jetbrains.exposed.sql.deleteWhere |
|
|
|
|
import org.jetbrains.exposed.sql.transactions.transaction |
|
|
|
|
import org.slf4j.Logger |
|
|
|
@ -80,7 +81,7 @@ object AccountService:AbstractService() { |
|
|
|
|
token=listOf(matchUser.id,ip,device).joinToString(separator = ('a' .. 'z').random().toString()).md5() |
|
|
|
|
} |
|
|
|
|
token.flush() |
|
|
|
|
return@transaction Token(userId = matchUser.id.value,token = token.token, |
|
|
|
|
return@transaction Token(id = matchUser.id.value,token = token.token, |
|
|
|
|
createTime = token.createTime.toEpochSecond( |
|
|
|
|
ZoneOffset.of("+8"))) |
|
|
|
|
} |
|
|
|
@ -89,20 +90,10 @@ object AccountService:AbstractService() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun validToken(token: Token):Boolean{ |
|
|
|
|
return validToken(TokenVo(token = token.token,userId = token.userId)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 令牌校验 |
|
|
|
|
* |
|
|
|
|
* @param tokenVo |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
fun validToken(tokenVo: TokenVo):Boolean{ |
|
|
|
|
return transaction { |
|
|
|
|
!UserToken.find { |
|
|
|
|
UserTokens.userId eq tokenVo.userId |
|
|
|
|
UserTokens.token eq tokenVo.token |
|
|
|
|
UserTokens.userId eq token.id |
|
|
|
|
UserTokens.token eq token.token |
|
|
|
|
}.empty() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -154,7 +145,7 @@ object MainService:AbstractService(){ |
|
|
|
|
} |
|
|
|
|
log.info("保存留言:${leaveMessageVo.message}") |
|
|
|
|
LeaveMessage.new { |
|
|
|
|
user= User.findById(leaveMessageVo.token.userId)?:throw IllegalArgumentException("非法id") |
|
|
|
|
user= User.findById(leaveMessageVo.token.id)?:throw IllegalArgumentException("非法id") |
|
|
|
|
message = leaveMessageVo.message |
|
|
|
|
} |
|
|
|
|
log.info("留言保存成功") |
|
|
|
@ -236,7 +227,8 @@ object FileService:AbstractService(){ |
|
|
|
|
log.info("map=${map}") |
|
|
|
|
val userId=getPartData<PartData.FormItem>(map,"id").value |
|
|
|
|
val token= getPartData<PartData.FormItem>(map,"token").value |
|
|
|
|
val tokenVo=TokenVo(token=token,userId=userId.toInt()) |
|
|
|
|
val createTime= getPartData<PartData.FormItem>(map,"createTime").value |
|
|
|
|
val tokenVo=Token(token=token,id=userId.toInt(),createTime=createTime.toLong()) |
|
|
|
|
if(AccountService.validToken(tokenVo)){ |
|
|
|
|
map.remove("id") |
|
|
|
|
map.remove("token") |
|
|
|
@ -252,6 +244,7 @@ object FileService:AbstractService(){ |
|
|
|
|
val file=File(filePath,fullFileName).apply { |
|
|
|
|
writeBytes(fileBytes) |
|
|
|
|
} |
|
|
|
|
log.info("文件成功保存到${file.absolutePath}") |
|
|
|
|
val fileId= save(id = userId,"${uploadDir}/${fullFileName}",file=file) |
|
|
|
|
fileIds.add(fileId) |
|
|
|
|
} |
|
|
|
@ -276,6 +269,12 @@ object AssociationService: AbstractService() { |
|
|
|
|
desc=vo.desc |
|
|
|
|
logo=ImageFile.findById(vo.fileId) ?: throw IllegalArgumentException("文件id不存在!") |
|
|
|
|
} |
|
|
|
|
Notification.new { |
|
|
|
|
title="注册社团" |
|
|
|
|
content="您成功提交了一份社团注册资料,请耐心等待后台受理" |
|
|
|
|
receiverId=vo.token.id |
|
|
|
|
receiverClient=ReceiverType.Foreground.name |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
log.info("未审核社团创建成功") |
|
|
|
|
true |
|
|
|
@ -297,8 +296,69 @@ enum class ManagerType(val desc:String,val level:Int){ |
|
|
|
|
LiaisonOfficer("外联部干事",4) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 通知服务 |
|
|
|
|
*/ |
|
|
|
|
object NotificationService:AbstractService(){ |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 拉取最新通知 |
|
|
|
|
* |
|
|
|
|
* @param vo |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
fun pull(vo:NotificationDto):List<NotificationVo>{ |
|
|
|
|
return transaction { |
|
|
|
|
val notifications=Notification.find { Notifications.pull eq false and |
|
|
|
|
(Notifications.receiverId eq vo.receiverId) and |
|
|
|
|
(Notifications.receiverClient eq vo.receiverClient.name) } |
|
|
|
|
log.info("获取${notifications.count()}条最新通知") |
|
|
|
|
return@transaction notifications.map { |
|
|
|
|
it.pull=true |
|
|
|
|
NotificationVo(title=it.title,id=it.id.value,content = it.content,createTime = it.createTime.toEpochSecond( |
|
|
|
|
ZoneOffset.of("+8"))) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 未读通知计数 |
|
|
|
|
* |
|
|
|
|
* @param vo |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
fun count(vo:NotificationDto):Long{ |
|
|
|
|
return transaction { |
|
|
|
|
return@transaction Notification.find{ Notifications.read eq false and |
|
|
|
|
(Notifications.receiverId eq vo.receiverId) and |
|
|
|
|
(Notifications.receiverClient eq vo.receiverClient.name) }.count().apply { |
|
|
|
|
log.info("未读通知${this}条") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* TODO |
|
|
|
|
* |
|
|
|
|
* @param vo |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
fun list(vo:NotificationDto): List<NotificationVo>? { |
|
|
|
|
return vo.page?.let { |
|
|
|
|
transaction { |
|
|
|
|
log.info("page:${it}") |
|
|
|
|
return@transaction Notification.find{ |
|
|
|
|
(Notifications.receiverId eq vo.receiverId) and |
|
|
|
|
(Notifications.receiverClient eq vo.receiverClient.name) }. |
|
|
|
|
limit(n=it.pageSize,offset = (it.currentPage-1)*it.pageSize).map { |
|
|
|
|
NotificationVo(title=it.title,id=it.id.value,content = it.content,createTime = it.createTime.toEpochSecond( |
|
|
|
|
ZoneOffset.of("+8"))*1000) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|