增加社团成员查询接口

master
pan 4 years ago
parent e5e16b5247
commit 10a11c7e1d
  1. 17
      src/Controller.kt
  2. 8
      src/Dao.kt
  3. 2
      src/MySQL.kt
  4. 56
      src/Service.kt
  5. 9
      src/Vo.kt
  6. 8
      test/ApplicationTest.kt

@ -262,7 +262,8 @@ fun Application.AssociationController() {
log.info("----end-----")
}
post("/load"){
route("/load"){
post{
log.info("社团id查询")
withToken<ShowAssociationVo>(call = call){
try {
@ -274,6 +275,20 @@ fun Application.AssociationController() {
}
log.info("----end-----")
}
post("/members"){
log.info("加载社团成员")
withToken<QueryAssociationMembers>(call = call){
try {
call.respond(ApiResponse(message = "社团成员加载成功",body=AssociationService.load(vo=it)))
} catch (e: Exception) {
log.error(e)
call.respond(Simple.error("社团成员加载失败"))
}
}
}
}
}
}
}

@ -29,9 +29,6 @@ open class Person:IntIdTable(){
object Users: Person(){
@TableComment("学号")
val studentId:Column<String> = varchar(name="student_id",length = 8).uniqueIndex()
@TableComment("社团成员id")
val associationMemberId:Column<EntityID<Int>?> = reference("association_member_id", AssociationMembers).nullable()
}
class User(id:EntityID<Int>):IntEntity(id){
@ -41,7 +38,6 @@ class User(id:EntityID<Int>):IntEntity(id){
var password by Users.password
var desc by Users.desc
val headImg by ImageFile optionalReferencedOn Users.imgId
var associationMember by AssociationMember optionalReferencedOn Users.associationMemberId
}
@ -187,6 +183,9 @@ class Association(id:EntityID<Int>):IntEntity(id){
@TableComment("社团成员信息")
object AssociationMembers:IntIdTable(){
@TableComment("社团成员id")
val userId:Column<EntityID<Int>> = reference("user_id",Users)
@TableComment("社团Id")
val associationId:Column<EntityID<Int>> = reference("association_id",Associations)
@ -196,6 +195,7 @@ object AssociationMembers:IntIdTable(){
class AssociationMember(id:EntityID<Int>):IntEntity(id) {
companion object : IntEntityClass<AssociationMember>(AssociationMembers)
var user by User referencedOn AssociationMembers.userId
var association by Association referencedOn AssociationMembers.associationId
var isHead by AssociationMembers.isHead
}

@ -40,7 +40,7 @@ fun Application.MySQL(testing: Boolean = false){
fun initTable(){
transaction {
val tableList= arrayOf(Users,UserTokens,Managers,ManagerTokens,AuditLeggings,LeaveMessages,ImageFiles,Associations,Associations,Notifications)
val tableList= arrayOf(Users,UserTokens,Managers,ManagerTokens,AuditLeggings,LeaveMessages,ImageFiles,Associations,AssociationMembers,Notifications)
SchemaUtils.createMissingTablesAndColumns(*tableList)
updateComment(*tableList)

@ -82,7 +82,7 @@ object AccountService : AbstractService() {
.md5()
}
token.flush()
val associationMember=AssociationMember.find { AssociationMembers.userId eq matchUser.id }.firstOrNull()
return@transaction UserVo(
studentId = matchUser.studentId, token =
Token(
@ -91,8 +91,8 @@ object AccountService : AbstractService() {
), name = matchUser.name,
headImg = matchUser.headImg?.filepath,
desc = matchUser.desc,
associationMemberVo = matchUser.associationMember?.let {
AssociationMemberVo(association = toAssociationVo(it.association),isHead = it.isHead) }
associationVo = associationMember?.let { toAssociationVo(it.association) },
isHead = associationMember?.isHead
)
}
}
@ -118,6 +118,7 @@ object AccountService : AbstractService() {
}
private fun tokenRes(token:UserToken,matchUser:User):UserVo{
val associationMember=AssociationMember.find { AssociationMembers.userId eq matchUser.id }.firstOrNull()
return UserVo(
studentId = matchUser.studentId, token =
Token(
@ -125,8 +126,8 @@ object AccountService : AbstractService() {
createTime = token.createTime.format()
), name = matchUser.name,
headImg = matchUser.headImg?.filepath, desc = matchUser.desc,
associationMemberVo = matchUser.associationMember?.let {
AssociationMemberVo(association = toAssociationVo(it.association),isHead = it.isHead) }
associationVo = associationMember?.let { toAssociationVo(it.association) },
isHead = associationMember?.isHead
)
}
@ -396,7 +397,8 @@ object AssociationService : AbstractService() {
this.log = log
}
}else {
val association:Association?= AuditLogging.find { AuditLeggings.userId eq user.id }.firstOrNull()?.user?.associationMember?.association
val associationMember=AssociationMember.find { AssociationMembers.userId eq regVo.id }.firstOrNull()
val association:Association?= associationMember?.association
when {
association != null && association.log.result == true -> throw IllegalArgumentException("您是社团团长不能再创建其他社团")
association != null && association.log.result == null -> throw IllegalArgumentException("您已经提交过社团注册资料,请耐心等待后台管理员处理")
@ -435,8 +437,8 @@ object AssociationService : AbstractService() {
*/
fun read(vo:OnlyToken):AssociationCheckVo?{
return transaction {
val association:Association?= AuditLogging.find { AuditLeggings.userId eq vo.token.id }.firstOrNull()?.user?.associationMember?.association
return@transaction association?.let {
val associationMember=AssociationMember.find { AssociationMembers.userId eq vo.token.id }.firstOrNull()
return@transaction associationMember?.association?.let {
AssociationCheckVo(id=it.id.value,name=it.name,desc=it.desc,logo = it.logo.filepath,
faculty = AssociationFaculty.valueOf(it.faculty),level = it.level?.let { it1 ->
AssociationLevel.valueOf(
@ -531,6 +533,12 @@ object AssociationService : AbstractService() {
}
}
/**
* 社团审核
*
* @param vo
* @return
*/
fun loadAudit(vo: OnlyToken): List<DisposeRegInfoVo> {
return transaction {
return@transaction Association.all().map {
@ -606,10 +614,10 @@ object AssociationService : AbstractService() {
}
association.log.nextAudit!=null&&vo.result->{
AssociationMember.new {
user=matchUser
this.association=association
isHead=true
}.apply {
matchUser.associationMember=this
this@AssociationService.log.info("初始化社团团长")
}
Notification.new {
@ -648,6 +656,12 @@ object AssociationService : AbstractService() {
level = it.level?.let { AssociationLevel.valueOf(it) })
}
/**
*
* 查询社团详情
* @param vo
* @return
*/
fun load(vo:ShowAssociationVo): AssociationMainVo {
return transaction {
val associationVo= (Association.findById(vo.id)?:throw AssociationIdError(vo.id)).let {
@ -665,6 +679,30 @@ object AssociationService : AbstractService() {
AssociationMainVo(associationVo = associationVo,head = head)
}
}
/**
* 加载社团成员
*
* @param vo
* @return
*/
fun load(vo:QueryAssociationMembers):List<UserInfoVo>{
return transaction {
Users.innerJoin(AssociationMembers).innerJoin(Associations)
.slice(Users.columns)
.select {
vo.name.let {
if(it==null||it.isEmpty())
Associations.id eq vo.id
else
Associations.id eq vo.id and (Users.name like "%${vo.name}%")
}
}.map {
UserInfoVo(name=it[Users.name],headImg = it[Users.imgId]?.let { ImageFile.findById(it) }?.filepath,
desc=it[Users.desc])
}
}
}
}
/**

@ -89,7 +89,8 @@ data class UserVo(
override val name: String,
override val headImg: String?,
override val desc: String,
val associationMemberVo: AssociationMemberVo?
val associationVo: AssociationVo?,
val isHead: Boolean?
) : OwnInfoVo()
@ -162,6 +163,12 @@ data class ShowAssociationVo(val id: Int,
override val token: Token,
override val clientType: ClientType=ClientType.Foreground):ClientBaseVo()
data class QueryAssociationMembers(val id:Int,
val name:String?=null,
override val token: Token,
override val clientType: ClientType=ClientType.Foreground
):ClientBaseVo()
/**
* 社团级别
*

@ -114,12 +114,10 @@ class ApplicationTest {
fun testAudit(){
initApp {
transaction {
Users.innerJoin(AssociationMembers)
Users.innerJoin(AssociationMembers).innerJoin(Associations)
.slice(Users.columns)
.select { AssociationMembers.isHead eq true and (AssociationMembers.associationId eq 1) }
.firstOrNull()?.let {
println(it[Users.name])
}
.select { Associations.id eq 1 and (Associations.name like "%%") }
.count().let { println("count:${it}") }
}
}
}

Loading…
Cancel
Save