|
|
|
@ -56,14 +56,12 @@ object AccountService:AbstractService() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 登录 |
|
|
|
|
* 前台登录 |
|
|
|
|
* |
|
|
|
|
* @param userLoginVo 登陆表单 |
|
|
|
|
*/ |
|
|
|
|
fun login(userLoginVo: UserLoginVo,_ip:String):Token?{ |
|
|
|
|
return transaction { |
|
|
|
|
val matchUser=User.find { Users.studentId eq userLoginVo.studentId }.firstOrNull() |
|
|
|
|
|
|
|
|
|
when { |
|
|
|
|
matchUser==null -> { |
|
|
|
|
log.warn("学号:${userLoginVo.studentId}不存在") |
|
|
|
@ -89,6 +87,43 @@ object AccountService:AbstractService() { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun login(managerLoginVo: ManagerLoginVo, _ip:String):Token?{ |
|
|
|
|
return transaction { |
|
|
|
|
val matchUser=Manager.find { Managers.account eq managerLoginVo.account }.firstOrNull() |
|
|
|
|
when { |
|
|
|
|
matchUser==null -> { |
|
|
|
|
log.warn("学号:${managerLoginVo.account}不存在") |
|
|
|
|
return@transaction null |
|
|
|
|
} |
|
|
|
|
managerLoginVo.password.md5() != matchUser.password -> { |
|
|
|
|
log.warn("密码:${managerLoginVo.password}错误") |
|
|
|
|
return@transaction null |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
val token=ManagerToken.new{ |
|
|
|
|
manager=matchUser |
|
|
|
|
ip=_ip |
|
|
|
|
device=managerLoginVo.device |
|
|
|
|
token=listOf(matchUser.id,ip,device).joinToString(separator = ('a' .. 'z').random().toString()).md5() |
|
|
|
|
} |
|
|
|
|
token.flush() |
|
|
|
|
return@transaction Token(id = matchUser.id.value,token = token.token, |
|
|
|
|
createTime = token.createTime.toEpochSecond( |
|
|
|
|
ZoneOffset.of("+8"))) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun validManagerToken(token:Token):Boolean{ |
|
|
|
|
return transaction { |
|
|
|
|
!ManagerToken.find { |
|
|
|
|
ManagerTokens.managerId eq token.id |
|
|
|
|
ManagerTokens.token eq token.token |
|
|
|
|
}.empty() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun validToken(token: Token):Boolean{ |
|
|
|
|
return transaction { |
|
|
|
|
!UserToken.find { |
|
|
|
@ -256,11 +291,19 @@ object FileService:AbstractService(){ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 社团服务 |
|
|
|
|
*/ |
|
|
|
|
object AssociationService: AbstractService() { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 注册社团 |
|
|
|
|
* |
|
|
|
|
* @param vo |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
fun register(vo:RegAssociationVo):Boolean{ |
|
|
|
|
return try { |
|
|
|
|
transaction { |
|
|
|
@ -275,6 +318,14 @@ object AssociationService: AbstractService() { |
|
|
|
|
receiverId=vo.token.id |
|
|
|
|
receiverClient=ReceiverType.Foreground.name |
|
|
|
|
} |
|
|
|
|
val user=User.findById(vo.token.id) |
|
|
|
|
if(user!=null) { |
|
|
|
|
BackgroundService.createBackgroundNotification(title = "审核注册社团",content = "用户${user.name}提交了一份社团资料需要您进行受理", |
|
|
|
|
duty = Duty.PamphaBhusal) |
|
|
|
|
}else{ |
|
|
|
|
log.warn("无法根据token id:${vo.token.id}查找到用户名") |
|
|
|
|
} |
|
|
|
|
return@transaction true |
|
|
|
|
} |
|
|
|
|
log.info("未审核社团创建成功") |
|
|
|
|
true |
|
|
|
@ -285,7 +336,7 @@ object AssociationService: AbstractService() { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
enum class ManagerType(val desc:String,val level:Int){ |
|
|
|
|
enum class Duty(val desc:String, val level:Int){ |
|
|
|
|
Teacher("老师",1), |
|
|
|
|
PamphaBhusal("总部长",2), |
|
|
|
|
SecretaryOfTheMinister("秘书部部长",3), |
|
|
|
@ -338,7 +389,6 @@ object NotificationService:AbstractService(){ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* TODO |
|
|
|
|
* |
|
|
|
|
* @param vo |
|
|
|
|
* @return |
|
|
|
@ -373,17 +423,38 @@ object BackgroundService:AbstractService(){ |
|
|
|
|
initManager() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun createManager(type:ManagerType, num:Int=1): MutableList<InitManagerDto> { |
|
|
|
|
/** |
|
|
|
|
* 前台任务通知管理员处理 |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
fun createBackgroundNotification(content:String,title:String,duty: Duty){ |
|
|
|
|
Manager.find { Managers.duty eq duty.name }.apply { |
|
|
|
|
if(count()==0L){ |
|
|
|
|
log.warn("找不到适当的${duty.desc}处理此任务") |
|
|
|
|
}else{ |
|
|
|
|
forEach { |
|
|
|
|
Notification.new { |
|
|
|
|
this.title = title |
|
|
|
|
this.content = content |
|
|
|
|
receiverId= it.id.value |
|
|
|
|
receiverClient=ReceiverType.Background.name |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun createManager(duty:Duty, num:Int=1): MutableList<InitManagerDto> { |
|
|
|
|
val managerList= mutableListOf<InitManagerDto>() |
|
|
|
|
repeat(num){ |
|
|
|
|
val originPassword=randomNum() |
|
|
|
|
Manager.new { |
|
|
|
|
account= randomNum() |
|
|
|
|
password = originPassword.md5() |
|
|
|
|
duty=type.name |
|
|
|
|
level=type.level |
|
|
|
|
this.duty =duty.name |
|
|
|
|
level=duty.level |
|
|
|
|
}.apply { |
|
|
|
|
managerList.add(InitManagerDto(account=account,originPassword=originPassword)) |
|
|
|
|
managerList.add(InitManagerDto(account=account,originPassword=originPassword,duty=duty)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return managerList |
|
|
|
@ -398,20 +469,20 @@ object BackgroundService:AbstractService(){ |
|
|
|
|
Manager.count().let { it -> |
|
|
|
|
if (it.toInt() == 0) { |
|
|
|
|
val allManager = mutableListOf<InitManagerDto>() |
|
|
|
|
allManager.addAll(createManager(ManagerType.Teacher, 1)) |
|
|
|
|
allManager.addAll(createManager(ManagerType.PamphaBhusal, 1)) |
|
|
|
|
allManager.addAll(createManager(ManagerType.SecretaryOfTheMinister, 1)) |
|
|
|
|
allManager.addAll(createManager(ManagerType.PropagandaDepartment, 1)) |
|
|
|
|
allManager.addAll(createManager(ManagerType.LiaisonMinister, 1)) |
|
|
|
|
allManager.addAll(createManager(Duty.Teacher, 1)) |
|
|
|
|
allManager.addAll(createManager(Duty.PamphaBhusal, 1)) |
|
|
|
|
allManager.addAll(createManager(Duty.SecretaryOfTheMinister, 1)) |
|
|
|
|
allManager.addAll(createManager(Duty.PropagandaDepartment, 1)) |
|
|
|
|
allManager.addAll(createManager(Duty.LiaisonMinister, 1)) |
|
|
|
|
arrayOf( |
|
|
|
|
ManagerType.SecretaryDepartmentOfficer, |
|
|
|
|
ManagerType.PublicityDepartmentOfficer, |
|
|
|
|
ManagerType.LiaisonOfficer |
|
|
|
|
Duty.SecretaryDepartmentOfficer, |
|
|
|
|
Duty.PublicityDepartmentOfficer, |
|
|
|
|
Duty.LiaisonOfficer |
|
|
|
|
).forEach { |
|
|
|
|
allManager.addAll(createManager(it, 3)) |
|
|
|
|
} |
|
|
|
|
allManager.forEach { |
|
|
|
|
file.appendText("${it.account}------${it.originPassword}\n") |
|
|
|
|
file.appendText("${it.account}------${it.originPassword}------${it.duty.desc}\n") |
|
|
|
|
} |
|
|
|
|
log.info("共生成${allManager.size}个管理员账号") |
|
|
|
|
} else { |
|
|
|
|