增加社团成员查询接口

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-----") log.info("----end-----")
} }
post("/load"){ route("/load"){
post{
log.info("社团id查询") log.info("社团id查询")
withToken<ShowAssociationVo>(call = call){ withToken<ShowAssociationVo>(call = call){
try { try {
@ -274,6 +275,20 @@ fun Application.AssociationController() {
} }
log.info("----end-----") 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(){ object Users: Person(){
@TableComment("学号") @TableComment("学号")
val studentId:Column<String> = varchar(name="student_id",length = 8).uniqueIndex() 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){ class User(id:EntityID<Int>):IntEntity(id){
@ -41,7 +38,6 @@ class User(id:EntityID<Int>):IntEntity(id){
var password by Users.password var password by Users.password
var desc by Users.desc var desc by Users.desc
val headImg by ImageFile optionalReferencedOn Users.imgId 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("社团成员信息") @TableComment("社团成员信息")
object AssociationMembers:IntIdTable(){ object AssociationMembers:IntIdTable(){
@TableComment("社团成员id")
val userId:Column<EntityID<Int>> = reference("user_id",Users)
@TableComment("社团Id") @TableComment("社团Id")
val associationId:Column<EntityID<Int>> = reference("association_id",Associations) val associationId:Column<EntityID<Int>> = reference("association_id",Associations)
@ -196,6 +195,7 @@ object AssociationMembers:IntIdTable(){
class AssociationMember(id:EntityID<Int>):IntEntity(id) { class AssociationMember(id:EntityID<Int>):IntEntity(id) {
companion object : IntEntityClass<AssociationMember>(AssociationMembers) companion object : IntEntityClass<AssociationMember>(AssociationMembers)
var user by User referencedOn AssociationMembers.userId
var association by Association referencedOn AssociationMembers.associationId var association by Association referencedOn AssociationMembers.associationId
var isHead by AssociationMembers.isHead var isHead by AssociationMembers.isHead
} }

@ -40,7 +40,7 @@ fun Application.MySQL(testing: Boolean = false){
fun initTable(){ fun initTable(){
transaction { 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) SchemaUtils.createMissingTablesAndColumns(*tableList)
updateComment(*tableList) updateComment(*tableList)

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

Loading…
Cancel
Save