Compare commits
26 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
62b578c7c5 | |
|
|
71d59d1a43 | |
|
|
5deace0a96 | |
|
|
8493e4701a | |
|
|
1a6d31c64c | |
|
|
7da99848a1 | |
|
|
7e4b1662be | |
|
|
fe0700e6c8 | |
|
|
0b45e9a2e4 | |
|
|
164f0995f5 | |
|
|
0f2da43c89 | |
|
|
39a0d26008 | |
|
|
9e9d5b916f | |
|
|
4dfd3e38d9 | |
|
|
2d2e88f66e | |
|
|
a73bec5a13 | |
|
|
16ecab1ae0 | |
|
|
fdb56b58d1 | |
|
|
eefd03b841 | |
|
|
4ac274f25f | |
|
|
5c8eb21401 | |
|
|
9aabe748d6 | |
|
|
b952359dd4 | |
|
|
76835abd49 | |
|
|
5d5f6cbe4d | |
|
|
681ba798f9 |
|
|
@ -0,0 +1 @@
|
||||||
|
java -cp ../target/upgram-1.0-SNAPSHOT.jar:../target/lib/* Main
|
||||||
10
pom.xml
10
pom.xml
|
|
@ -75,11 +75,21 @@
|
||||||
<artifactId>kotlin-stdlib-jre8</artifactId>
|
<artifactId>kotlin-stdlib-jre8</artifactId>
|
||||||
<version>${kotlin.version}</version>
|
<version>${kotlin.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-reflect</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>druid</artifactId>
|
<artifactId>druid</artifactId>
|
||||||
<version>1.1.3</version>
|
<version>1.1.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.jfinal</groupId>
|
||||||
|
<artifactId>jfinal</artifactId>
|
||||||
|
<version>3.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin
|
||||||
|
import com.jfinal.plugin.druid.DruidPlugin
|
||||||
|
import model.*
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import ro.pippo.controller.ControllerApplication
|
import ro.pippo.controller.ControllerApplication
|
||||||
import ro.pippo.core.Pippo
|
import ro.pippo.core.Pippo
|
||||||
|
|
@ -6,18 +9,23 @@ import ro.pippo.session.SessionManager
|
||||||
import ro.pippo.session.SessionRequestResponseFactory
|
import ro.pippo.session.SessionRequestResponseFactory
|
||||||
import ro.pippo.session.cookie.CookieSessionDataStorage
|
import ro.pippo.session.cookie.CookieSessionDataStorage
|
||||||
import route.*
|
import route.*
|
||||||
|
import service.Service
|
||||||
|
import util.md5
|
||||||
|
|
||||||
|
|
||||||
object Main {
|
object Main {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
// System.setProperty("user.timezone","Asia/Shanghai");
|
||||||
val pippo = Pippo(BasicApplication())
|
val pippo = Pippo(BasicApplication())
|
||||||
pippo.start()
|
pippo.start()
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BasicApplication : ControllerApplication() {
|
class BasicApplication : ControllerApplication() {
|
||||||
private val log = LoggerFactory.getLogger(BasicApplication::class.java)
|
private val log = LoggerFactory.getLogger(BasicApplication::class.java)
|
||||||
|
// private val druidDataSource: DruidDataSource = DruidDataSource()
|
||||||
|
|
||||||
override fun onInit() {
|
override fun onInit() {
|
||||||
getRouter().ignorePaths("/favicon.ico")
|
getRouter().ignorePaths("/favicon.ico")
|
||||||
|
|
@ -45,11 +53,61 @@ class BasicApplication : ControllerApplication() {
|
||||||
println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
|
println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ANY("/.*") { routeContext ->
|
||||||
|
if (routeContext.requestUri.contains("user/auth")) {
|
||||||
|
routeContext.next()
|
||||||
|
return@ANY
|
||||||
|
} else {
|
||||||
|
var token = routeContext.getSession<String?>("token")
|
||||||
|
var phone = routeContext.getSession<String?>("phone")
|
||||||
|
if (token != null && phone != null) {
|
||||||
|
val user = Service().getUserByPhone(phone)
|
||||||
|
if (user != null) {
|
||||||
|
if (token == md5(user.phone + ":" + user.passwd)) {
|
||||||
|
routeContext.next()
|
||||||
|
return@ANY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
token = routeContext.getHeader("token")
|
||||||
|
phone = routeContext.getHeader("phone")
|
||||||
|
val user = Service().getUserByPhone(phone)
|
||||||
|
if (user != null) {
|
||||||
|
if (token == md5(user.phone + ":" + user.passwd)) {
|
||||||
|
routeContext.next()
|
||||||
|
return@ANY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// routeContext.status(403)
|
||||||
|
routeContext.json().send(JSONResponse(410, "", null))
|
||||||
|
}.runAsFinally()
|
||||||
|
|
||||||
addControllers(CtrlUser::class.java)
|
addControllers(CtrlUser::class.java)
|
||||||
addControllers(CrtlGroup::class.java)
|
addControllers(CrtlGroup::class.java)
|
||||||
addControllers(CtrlMenu::class.java)
|
addControllers(CtrlMenu::class.java)
|
||||||
addControllers(CtrlPerm::class.java)
|
addControllers(CtrlPerm::class.java)
|
||||||
addControllers(CtrlRole::class.java)
|
addControllers(CtrlRole::class.java)
|
||||||
|
|
||||||
|
|
||||||
|
val dp = DruidPlugin(
|
||||||
|
"jdbc:mysql://rm-wz9n28sq10rz5b0u2o.mysql.rds.aliyuncs.com:3306/sh-upgram?serverTimezone=Asia/Shanghai",
|
||||||
|
"shzhyjxy",
|
||||||
|
"Admin111")
|
||||||
|
val arp = ActiveRecordPlugin(dp)
|
||||||
|
arp.addMapping("menu", JFinalModelMenu::class.java)
|
||||||
|
arp.addMapping("user", JFinalModelUser::class.java)
|
||||||
|
arp.addMapping("group", JFinalModelGroup::class.java)
|
||||||
|
arp.addMapping("perm", JFinalModelPerm::class.java)
|
||||||
|
arp.addMapping("role", JFinalModelRole::class.java)
|
||||||
|
dp.start()
|
||||||
|
arp.start()
|
||||||
|
|
||||||
|
PUT("/test") { context ->
|
||||||
|
context.send("ok")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createRequestResponseFactory(): RequestResponseFactory {
|
override fun createRequestResponseFactory(): RequestResponseFactory {
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,15 @@ object Const {
|
||||||
|
|
||||||
val msgEmptyMsg = ""
|
val msgEmptyMsg = ""
|
||||||
val msgNotFoundById = "根据id没有找到对应资源"
|
val msgNotFoundById = "根据id没有找到对应资源"
|
||||||
|
val msgNotFound = "没有找到对应资源"
|
||||||
val msgInsertUserFailed = "新增用户失败,请检查参数,或许已有相同用户存在"
|
val msgInsertUserFailed = "新增用户失败,请检查参数,或许已有相同用户存在"
|
||||||
val msgUpdateUserFailed = "更新用户信息失败"
|
val msgUpdateUserFailed = "更新用户信息失败"
|
||||||
|
val msgUpdateRoleFailed = "更新角色信息失败"
|
||||||
|
val msgUpdateGroupFailed = "更新组信息失败"
|
||||||
|
val msgUpdateMenuFailed = "更新菜单信息失败"
|
||||||
|
val msgUpdatepermFailed = "更新权限信息失败"
|
||||||
val msgInvalidParams = "参数错误"
|
val msgInvalidParams = "参数错误"
|
||||||
val msgOperationFailed = "操作失败"
|
val msgOperationFailed = "操作失败"
|
||||||
|
val msgCheckNameFailed = "用户名不存在,请重新输入"
|
||||||
|
val msgDuplicateUserName = "用户名已存在"
|
||||||
}
|
}
|
||||||
|
|
@ -1,23 +1,157 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
|
import com.jfinal.plugin.activerecord.Model
|
||||||
import java.sql.Timestamp
|
import java.sql.Timestamp
|
||||||
|
import kotlin.reflect.full.memberProperties
|
||||||
|
|
||||||
class ModelUser(val id: Int?, var name: String?, var passwd: String?, val groupId: Int/*default -1*/, val roleId: Int/*default -1*/, val createTime: Timestamp?) {
|
data class ModelUser(val id: Int?, var name: String?, var phone: String?, var passwd: String?, val groupId: Int/*default -1*/, val roleId: Int/*default -1*/, val createTime: Timestamp?) {
|
||||||
constructor() : this(null, null, null, -1, -1, null)
|
companion object {
|
||||||
|
fun fromJFinal(model: Model<*>): ModelUser {
|
||||||
|
return ModelUser(
|
||||||
|
id = model.getInt("id"),
|
||||||
|
name = model.getStr("name"),
|
||||||
|
phone = model.getStr("phone"),
|
||||||
|
passwd = model.getStr("passwd"),
|
||||||
|
groupId = model.getInt("groupId"),
|
||||||
|
roleId = model.getInt("roleId"),
|
||||||
|
createTime = model.getTimestamp("createTime")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toJFinal(): Model<*> {
|
||||||
|
val model = JFinalModelUser()
|
||||||
|
this::class.memberProperties.forEach {
|
||||||
|
model.set(it.name, it.getter.call(this))
|
||||||
|
}
|
||||||
|
return model
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() : this(null, null, null, null, -1, -1, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
data class ModelGroup(val id: Int?, val description: String, val createTime: Timestamp?) {
|
data class ModelGroup(val id: Int?, val description: String, val parentId: Int?, val createTime: Timestamp?) {
|
||||||
constructor() : this(null, "", null)
|
companion object {
|
||||||
|
fun fromJFinal(model: Model<*>): ModelGroup {
|
||||||
|
return ModelGroup(
|
||||||
|
id = model.getInt("id"),
|
||||||
|
description = model.getStr("description"),
|
||||||
|
parentId = model.getInt("parentId"),
|
||||||
|
createTime = model.getTimestamp("createTime")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toJFinal(): Model<*> {
|
||||||
|
val model = JFinalModelGroup()
|
||||||
|
this::class.memberProperties.forEach {
|
||||||
|
model.set(it.name, it.getter.call(this))
|
||||||
|
}
|
||||||
|
return model
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() : this(null, "", -1, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
data class ModelPerm(val id: Int?, val description: String?, val perm: String?, val createTime: Timestamp?) {
|
data class ModelPerm(val id: Int?, val description: String?, val perm: String?, val createTime: Timestamp?) {
|
||||||
constructor():this(null,null,null,null)
|
companion object {
|
||||||
|
fun fromJFinal(model: Model<*>): ModelPerm {
|
||||||
|
return ModelPerm(
|
||||||
|
id = model.getInt("id"),
|
||||||
|
description = model.getStr("description"),
|
||||||
|
perm = model.getStr("perm"),
|
||||||
|
createTime = model.getTimestamp("createTime")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toJFinal(): Model<*> {
|
||||||
|
val model = JFinalModelGroup()
|
||||||
|
this::class.memberProperties.forEach {
|
||||||
|
model.set(it.name, it.getter.call(this))
|
||||||
|
}
|
||||||
|
return model
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() : this(null, null, null, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
data class ModelMenu(val id: Int?, val description: String?, val url: String?, val permId: Int?, val createTime: Timestamp?) {
|
data class ModelMenu(val id: Int?, val description: String?, val url: String?, val permId: Int?, val parentId: Int?, val order: Int?, val type: Int, val createTime: Timestamp?) {
|
||||||
constructor():this(null,null,null,null,null)
|
companion object {
|
||||||
|
fun fromJFinal(model: Model<*>): ModelMenu {
|
||||||
|
return ModelMenu(
|
||||||
|
id = model.getInt("id"),
|
||||||
|
description = model.getStr("description"),
|
||||||
|
url = model.getStr("url"),
|
||||||
|
permId = model.getInt("permId"),
|
||||||
|
parentId = model.getInt("parentId"),
|
||||||
|
order = model.getInt("order"),
|
||||||
|
type = model.getInt("type"),
|
||||||
|
createTime = model.getTimestamp("createTime")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toJFinal(): Model<*> {
|
||||||
|
val model = JFinalModelMenu()
|
||||||
|
this::class.memberProperties.forEach {
|
||||||
|
model.set(it.name, it.getter.call(this))
|
||||||
|
}
|
||||||
|
return model
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() : this(null, null, null, -1, -1, null, -1, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
data class ModelRole(val id: Int?, val description: String?, val createTime: Timestamp?){
|
data class ModelRole(val id: Int?, val description: String?, val createTime: Timestamp?) {
|
||||||
constructor():this(null,null,null)
|
companion object {
|
||||||
|
fun fromJFinal(model: Model<*>): ModelRole {
|
||||||
|
return ModelRole(
|
||||||
|
id = model.getInt("id"),
|
||||||
|
description = model.getStr("description"),
|
||||||
|
createTime = model.getTimestamp("createTime")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toJFinal(): Model<*> {
|
||||||
|
val model = JFinalModelRole()
|
||||||
|
this::class.memberProperties.forEach {
|
||||||
|
model.set(it.name, it.getter.call(this))
|
||||||
|
}
|
||||||
|
return model
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() : this(null, null, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class JFinalModelUser() : Model<JFinalModelUser>() {
|
||||||
|
companion object {
|
||||||
|
val DAO: JFinalModelUser = JFinalModelUser()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class JFinalModelGroup() : Model<JFinalModelGroup>() {
|
||||||
|
companion object {
|
||||||
|
val DAO: JFinalModelGroup = JFinalModelGroup()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class JFinalModelRole() : Model<JFinalModelRole>() {
|
||||||
|
companion object {
|
||||||
|
val DAO: JFinalModelRole = JFinalModelRole()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class JFinalModelMenu() : Model<JFinalModelMenu>() {
|
||||||
|
companion object {
|
||||||
|
val DAO: JFinalModelMenu = JFinalModelMenu()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class JFinalModelPerm() : Model<JFinalModelPerm>() {
|
||||||
|
companion object {
|
||||||
|
val DAO: JFinalModelPerm = JFinalModelPerm()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
data class JSONResponse(val code: Int, val msg: String, val result: Any?)
|
data class JSONResponse(val code: Int, val msg: String, val result: Any?)
|
||||||
|
|
||||||
|
data class JSONResponseWithExtra(val code: Int, val msg: String, val result: Any?, val extra:Any?)
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
package route
|
package route
|
||||||
|
|
||||||
|
import com.jfinal.kit.JsonKit
|
||||||
|
import com.jfinal.plugin.activerecord.Db
|
||||||
|
import com.jfinal.plugin.activerecord.Record
|
||||||
import config.Const
|
import config.Const
|
||||||
import model.JSONResponse
|
import model.JSONResponse
|
||||||
import model.ModelGroup
|
import model.ModelGroup
|
||||||
import ro.pippo.controller.*
|
import ro.pippo.controller.*
|
||||||
import ro.pippo.controller.extractor.Param
|
import ro.pippo.controller.extractor.Param
|
||||||
import service.Service
|
import service.Service
|
||||||
import util.responseInvalidParams
|
import util.*
|
||||||
import util.responseNotFoundById
|
|
||||||
import util.responseOperationFailed
|
|
||||||
import util.responseSuccess
|
|
||||||
|
|
||||||
@Path("/group")
|
@Path("/group")
|
||||||
class CrtlGroup : Controller() {
|
class CrtlGroup : Controller() {
|
||||||
|
|
@ -32,6 +32,13 @@ class CrtlGroup : Controller() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET("/{page: [0-9]+}/{size: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun pagi(@Param("page") num:Int, @Param("size") size:Int) :String {
|
||||||
|
val page = service.pagiGroup(num,size)
|
||||||
|
return JsonKit.toJson(responseSuccess(page))
|
||||||
|
}
|
||||||
|
|
||||||
@GET("/{id: [0-9]+}")
|
@GET("/{id: [0-9]+}")
|
||||||
@Produces(Produces.JSON)
|
@Produces(Produces.JSON)
|
||||||
fun getGroupById(@Param("id") id:Int):JSONResponse {
|
fun getGroupById(@Param("id") id:Int):JSONResponse {
|
||||||
|
|
@ -74,7 +81,23 @@ class CrtlGroup : Controller() {
|
||||||
responseOperationFailed()
|
responseOperationFailed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//更新
|
||||||
|
@POST("/update")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun updateGrou() : JSONResponse {
|
||||||
|
if (null != request.parameters["id"]) {
|
||||||
|
val record = Record()
|
||||||
|
updateUtil(record,request)
|
||||||
|
val isSuccess = Db.update("group","id",record)
|
||||||
|
return if (isSuccess){
|
||||||
|
responseSuccess(true)
|
||||||
|
} else{
|
||||||
|
responseUpdateGroupFailed()
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
return responseUpdateGroupFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
@POST("/del/{id: [0-9]+}")
|
@POST("/del/{id: [0-9]+}")
|
||||||
@Produces(Produces.JSON)
|
@Produces(Produces.JSON)
|
||||||
fun delGroup(@Param("id") id: Int): JSONResponse {
|
fun delGroup(@Param("id") id: Int): JSONResponse {
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
package route
|
package route
|
||||||
|
|
||||||
|
import com.jfinal.kit.JsonKit
|
||||||
|
import com.jfinal.plugin.activerecord.Db
|
||||||
|
import com.jfinal.plugin.activerecord.Record
|
||||||
import model.JSONResponse
|
import model.JSONResponse
|
||||||
import model.ModelMenu
|
import model.ModelMenu
|
||||||
import ro.pippo.controller.*
|
import ro.pippo.controller.*
|
||||||
import ro.pippo.controller.extractor.Param
|
import ro.pippo.controller.extractor.Param
|
||||||
import service.Service
|
import service.Service
|
||||||
import util.responseInvalidParams
|
import util.*
|
||||||
import util.responseNotFoundById
|
|
||||||
import util.responseOperationFailed
|
|
||||||
import util.responseSuccess
|
|
||||||
|
|
||||||
@Path("/menu")
|
@Path("/menu")
|
||||||
class CtrlMenu : Controller() {
|
class CtrlMenu : Controller() {
|
||||||
|
|
@ -25,6 +25,13 @@ class CtrlMenu : Controller() {
|
||||||
return responseSuccess(menu)
|
return responseSuccess(menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET("/{page: [0-9]+}/{size: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun pagi(@Param("page") num: Int, @Param("size") size: Int): String {
|
||||||
|
val page = service.pagiMenu(num, size)
|
||||||
|
return JsonKit.toJson(responseSuccess(page))
|
||||||
|
}
|
||||||
|
|
||||||
@GET("/byRole/{roleId: [0-9]+}")
|
@GET("/byRole/{roleId: [0-9]+}")
|
||||||
@Produces(Produces.JSON)
|
@Produces(Produces.JSON)
|
||||||
fun getMenuByRole(@Param("roleId") roleId: Int): JSONResponse {
|
fun getMenuByRole(@Param("roleId") roleId: Int): JSONResponse {
|
||||||
|
|
@ -45,18 +52,31 @@ class CtrlMenu : Controller() {
|
||||||
return responseInvalidParams()
|
return responseInvalidParams()
|
||||||
}
|
}
|
||||||
|
|
||||||
val isSuccess = service.saveMenu(menu)
|
// val menu2 = JFinalModelMenu()
|
||||||
|
// menu2.put("description", menu.description)
|
||||||
|
// menu2.put("url", menu.url)
|
||||||
|
// menu2.put("permId", menu.permId)
|
||||||
|
// menu2.put("createTime", Date())
|
||||||
|
// val isSuccess = menu2.save()
|
||||||
|
val isSuccess = service.save(ModelMenu::class, menu)
|
||||||
return if (isSuccess) {
|
return if (isSuccess) {
|
||||||
responseSuccess(menu)
|
responseSuccess(isSuccess)
|
||||||
} else {
|
} else {
|
||||||
responseOperationFailed()
|
responseOperationFailed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// val isSuccess = service.saveMenu(menu)
|
||||||
|
// return if (isSuccess) {
|
||||||
|
// responseSuccess(menu)
|
||||||
|
// } else {
|
||||||
|
// responseOperationFailed()
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST("/{id: [0-9]+}")
|
@POST("/{id: [0-9]+}")
|
||||||
@Produces(Produces.JSON)
|
@Produces(Produces.JSON)
|
||||||
fun updateMenu(@Param("id") id: Int): JSONResponse {
|
fun updateMenu(@Param("id") id: Int): JSONResponse {
|
||||||
val menu: ModelMenu? = request.createEntityFromBody(ModelMenu::class.java)
|
val menu: ModelMenu? = request.createEntityFromParameters(ModelMenu::class.java)
|
||||||
if (menu == null) {
|
if (menu == null) {
|
||||||
return responseInvalidParams()
|
return responseInvalidParams()
|
||||||
}
|
}
|
||||||
|
|
@ -69,6 +89,24 @@ class CtrlMenu : Controller() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//更新
|
||||||
|
@POST("/update")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun updateMen(): JSONResponse {
|
||||||
|
if (null != request.parameters["id"]) {
|
||||||
|
val record = Record()
|
||||||
|
updateUtil(record, request)
|
||||||
|
val isSuccess = Db.update("menu", "id", record)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(true)
|
||||||
|
} else {
|
||||||
|
responseUpdateMenuFailed()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return responseUpdateMenuFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@POST("/del/{id: [0-9]+}")
|
@POST("/del/{id: [0-9]+}")
|
||||||
@Produces(Produces.JSON)
|
@Produces(Produces.JSON)
|
||||||
fun deleteMenu(@Param("id") id: Int): JSONResponse {
|
fun deleteMenu(@Param("id") id: Int): JSONResponse {
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
package route
|
package route
|
||||||
|
|
||||||
|
import com.jfinal.kit.JsonKit
|
||||||
|
import com.jfinal.plugin.activerecord.Db
|
||||||
|
import com.jfinal.plugin.activerecord.Record
|
||||||
import model.JSONResponse
|
import model.JSONResponse
|
||||||
import model.ModelPerm
|
import model.ModelPerm
|
||||||
import ro.pippo.controller.*
|
import ro.pippo.controller.*
|
||||||
import ro.pippo.controller.extractor.Param
|
import ro.pippo.controller.extractor.Param
|
||||||
import service.Service
|
import service.Service
|
||||||
import util.responseInvalidParams
|
import util.*
|
||||||
import util.responseNotFoundById
|
|
||||||
import util.responseOperationFailed
|
|
||||||
import util.responseSuccess
|
|
||||||
|
|
||||||
@Path("/perm")
|
@Path("/perm")
|
||||||
class CtrlPerm : Controller() {
|
class CtrlPerm : Controller() {
|
||||||
|
|
@ -24,6 +24,22 @@ class CtrlPerm : Controller() {
|
||||||
responseSuccess(perm)
|
responseSuccess(perm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//校验用户名是否存在
|
||||||
|
@POST("/checkName/{name}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun checkName(@Param("name") name : String ) :JSONResponse{
|
||||||
|
if ( null == name || "" == name.trim()){
|
||||||
|
responseCheckNameFailed()
|
||||||
|
}
|
||||||
|
service.getPremByName(name) ?: return responseCheckNameFailed()
|
||||||
|
return responseSuccess(true)
|
||||||
|
}
|
||||||
|
@GET("/{page: [0-9]+}/{size: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun pagi(@Param("page") num:Int, @Param("size") size:Int) :String {
|
||||||
|
val page = service.pagiPerm(num,size)
|
||||||
|
return JsonKit.toJson(responseSuccess(page))
|
||||||
|
}
|
||||||
|
|
||||||
@POST("/byRole/{roleId: [0-9]+}")
|
@POST("/byRole/{roleId: [0-9]+}")
|
||||||
@Produces(Produces.JSON)
|
@Produces(Produces.JSON)
|
||||||
|
|
@ -40,7 +56,7 @@ class CtrlPerm : Controller() {
|
||||||
@POST("/")
|
@POST("/")
|
||||||
@Produces(Produces.JSON)
|
@Produces(Produces.JSON)
|
||||||
fun addPerm(): JSONResponse {
|
fun addPerm(): JSONResponse {
|
||||||
val perm: ModelPerm? = request.createEntityFromBody(ModelPerm::class.java)
|
val perm: ModelPerm? = request.createEntityFromParameters(ModelPerm::class.java)
|
||||||
if (perm == null) {
|
if (perm == null) {
|
||||||
return responseInvalidParams()
|
return responseInvalidParams()
|
||||||
}
|
}
|
||||||
|
|
@ -68,7 +84,23 @@ class CtrlPerm : Controller() {
|
||||||
responseOperationFailed()
|
responseOperationFailed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//更新
|
||||||
|
@POST("/update")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun updatePer() :JSONResponse {
|
||||||
|
if (request.parameters["id"] != null) {
|
||||||
|
val record = Record()
|
||||||
|
updateUtil(record,request)
|
||||||
|
val isSuccess = Db.update("perm","id",record)
|
||||||
|
return if (isSuccess){
|
||||||
|
responseSuccess(true)
|
||||||
|
} else{
|
||||||
|
responseUpdatePermFailed()
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
return responseUpdatePermFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
@POST("/del/{id: [0-9]+}")
|
@POST("/del/{id: [0-9]+}")
|
||||||
@Produces(Produces.JSON)
|
@Produces(Produces.JSON)
|
||||||
fun deletePerm(@Param("id") id: Int): JSONResponse {
|
fun deletePerm(@Param("id") id: Int): JSONResponse {
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
package route
|
package route
|
||||||
|
|
||||||
|
import com.jfinal.kit.JsonKit
|
||||||
|
import com.jfinal.plugin.activerecord.Db
|
||||||
|
import com.jfinal.plugin.activerecord.Record
|
||||||
import model.JSONResponse
|
import model.JSONResponse
|
||||||
import model.ModelRole
|
import model.ModelRole
|
||||||
import ro.pippo.controller.*
|
import ro.pippo.controller.*
|
||||||
import ro.pippo.controller.extractor.Param
|
import ro.pippo.controller.extractor.Param
|
||||||
import service.Service
|
import service.Service
|
||||||
import util.responseInvalidParams
|
import util.*
|
||||||
import util.responseNotFoundById
|
|
||||||
import util.responseOperationFailed
|
|
||||||
import util.responseSuccess
|
|
||||||
|
|
||||||
@Path("/role")
|
@Path("/role")
|
||||||
class CtrlRole : Controller() {
|
class CtrlRole : Controller() {
|
||||||
|
|
@ -24,6 +24,22 @@ class CtrlRole : Controller() {
|
||||||
|
|
||||||
return responseSuccess(role)
|
return responseSuccess(role)
|
||||||
}
|
}
|
||||||
|
//校验用户名是否存在
|
||||||
|
@POST("/checkName/{name}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun checkName(@Param("name") name : String ) :JSONResponse{
|
||||||
|
if ( null == name || "" == name.trim()){
|
||||||
|
responseCheckNameFailed()
|
||||||
|
}
|
||||||
|
service.getRoleByName(name) ?: return responseCheckNameFailed()
|
||||||
|
return responseSuccess(true)
|
||||||
|
}
|
||||||
|
@GET("/{page: [0-9]+}/{size: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun pagi(@Param("page") num:Int, @Param("size") size:Int) :String {
|
||||||
|
val page = service.pagiRole(num,size)
|
||||||
|
return JsonKit.toJson(responseSuccess(page))
|
||||||
|
}
|
||||||
|
|
||||||
@GET("/byUser/{userId: [0-9]+}")
|
@GET("/byUser/{userId: [0-9]+}")
|
||||||
@Produces(Produces.JSON)
|
@Produces(Produces.JSON)
|
||||||
|
|
@ -59,7 +75,7 @@ class CtrlRole : Controller() {
|
||||||
|
|
||||||
@POST("/del/{id: [0-9]+}")
|
@POST("/del/{id: [0-9]+}")
|
||||||
@Produces(Produces.JSON)
|
@Produces(Produces.JSON)
|
||||||
fun delRole(@Param("roleId") roleId: Int): JSONResponse {
|
fun delRole(@Param("id") roleId: Int): JSONResponse {
|
||||||
val role = service.getRoleById(roleId)
|
val role = service.getRoleById(roleId)
|
||||||
if (role == null) {
|
if (role == null) {
|
||||||
responseNotFoundById()
|
responseNotFoundById()
|
||||||
|
|
@ -76,7 +92,7 @@ class CtrlRole : Controller() {
|
||||||
@POST("/{id: [0-9]+}")
|
@POST("/{id: [0-9]+}")
|
||||||
@Produces(Produces.JSON)
|
@Produces(Produces.JSON)
|
||||||
fun updateRole():JSONResponse {
|
fun updateRole():JSONResponse {
|
||||||
val role: ModelRole? = request.createEntityFromBody(ModelRole::class.java)
|
val role: ModelRole? = request.createEntityFromParameters(ModelRole::class.java)
|
||||||
if (role == null) {
|
if (role == null) {
|
||||||
return responseNotFoundById()
|
return responseNotFoundById()
|
||||||
}
|
}
|
||||||
|
|
@ -88,4 +104,21 @@ class CtrlRole : Controller() {
|
||||||
responseOperationFailed()
|
responseOperationFailed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//更新
|
||||||
|
@POST("/update")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun updateRol() :JSONResponse{
|
||||||
|
if (request.parameters["id"] != null) {
|
||||||
|
val record = Record()
|
||||||
|
updateUtil(record,request)
|
||||||
|
val isSuccess = Db.update("role","id",record)
|
||||||
|
return if (isSuccess){
|
||||||
|
responseSuccess(true)
|
||||||
|
} else{
|
||||||
|
responseUpdateRoleFailed()
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
return responseUpdateRoleFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,14 +1,16 @@
|
||||||
package route
|
package route
|
||||||
|
|
||||||
|
import com.jfinal.kit.JsonKit
|
||||||
|
import com.jfinal.plugin.activerecord.Db
|
||||||
|
import com.jfinal.plugin.activerecord.Record
|
||||||
|
import config.Const
|
||||||
import model.JSONResponse
|
import model.JSONResponse
|
||||||
import model.ModelUser
|
import model.ModelUser
|
||||||
import ro.pippo.controller.*
|
import ro.pippo.controller.*
|
||||||
import ro.pippo.controller.extractor.Param
|
import ro.pippo.controller.extractor.Param
|
||||||
import service.Service
|
import service.Service
|
||||||
import util.responseInvalidParams
|
import util.*
|
||||||
import util.responseNotFoundById
|
import java.net.URLDecoder
|
||||||
import util.responseOperationFailed
|
|
||||||
import util.responseSuccess
|
|
||||||
|
|
||||||
|
|
||||||
@Path("/user")
|
@Path("/user")
|
||||||
|
|
@ -28,6 +30,13 @@ class CtrlUser : Controller() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET("/{page: [0-9]+}/{size: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun pagi(@Param("page") num: Int, @Param("size") size: Int): String {
|
||||||
|
val page = service.pagiUser(num, size)
|
||||||
|
return JsonKit.toJson(responseSuccess(page))
|
||||||
|
}
|
||||||
|
|
||||||
@POST("/")
|
@POST("/")
|
||||||
@Produces(Produces.JSON)
|
@Produces(Produces.JSON)
|
||||||
fun addUser(): JSONResponse {
|
fun addUser(): JSONResponse {
|
||||||
|
|
@ -35,14 +44,18 @@ class CtrlUser : Controller() {
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return responseInvalidParams()
|
return responseInvalidParams()
|
||||||
}
|
}
|
||||||
val isSuccess = service.saveUser(user)
|
val (status, isSuccess) = service.saveUser(user)
|
||||||
return if (isSuccess) {
|
return if (status == Service.Status.DUPLICATED) {
|
||||||
|
JSONResponse(Const.codeInvalidParams, Const.msgDuplicateUserName, null)
|
||||||
|
} else {
|
||||||
|
if (isSuccess) {
|
||||||
user.passwd = ""
|
user.passwd = ""
|
||||||
responseSuccess(user)
|
responseSuccess(user)
|
||||||
} else {
|
} else {
|
||||||
responseOperationFailed()
|
responseOperationFailed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@POST("/{id: [0-9]+}/{name}")
|
@POST("/{id: [0-9]+}/{name}")
|
||||||
@Produces(Produces.JSON)
|
@Produces(Produces.JSON)
|
||||||
|
|
@ -63,6 +76,35 @@ class CtrlUser : Controller() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//校验用户名是否存在
|
||||||
|
@POST("/checkName/{name}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun checkName(@Param("name") name: String): JSONResponse {
|
||||||
|
if (null == name || "" == name.trim()) {
|
||||||
|
responseCheckNameFailed()
|
||||||
|
}
|
||||||
|
service.getUserByName(name) ?: return responseCheckNameFailed()
|
||||||
|
return responseSuccess(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
//更新 User
|
||||||
|
@POST("/update")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun updateUser(): JSONResponse {
|
||||||
|
if (request.parameters["id"] != null) {
|
||||||
|
val record = Record()
|
||||||
|
updateUtil(record, request)
|
||||||
|
val isSuccess = Db.update("user", "id", record)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(true)
|
||||||
|
} else {
|
||||||
|
responseUpdateUserFailed()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return responseUpdateUserFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@POST("/del/{id: [0-9]+}")
|
@POST("/del/{id: [0-9]+}")
|
||||||
@Produces(Produces.JSON)
|
@Produces(Produces.JSON)
|
||||||
fun delUser(@Param("id") id: Int): JSONResponse {
|
fun delUser(@Param("id") id: Int): JSONResponse {
|
||||||
|
|
@ -93,7 +135,7 @@ class CtrlUser : Controller() {
|
||||||
return if (user == null) {
|
return if (user == null) {
|
||||||
responseNotFoundById()
|
responseNotFoundById()
|
||||||
} else {
|
} else {
|
||||||
val isSuccess = service.changePasswd(user, passwd!!)
|
val (isSuccess, _) = service.changePasswd(user, passwd!!)
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
responseSuccess(true)
|
responseSuccess(true)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -102,6 +144,52 @@ class CtrlUser : Controller() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@POST("/auth")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun auth(): JSONResponse {
|
||||||
|
val phone = request.getQueryParameter("phone")?.toString(null)
|
||||||
|
val passwd = request.getQueryParameter("passwd")?.toString(null)
|
||||||
|
|
||||||
|
if (phone == null || passwd == null) {
|
||||||
|
return responseInvalidParams()
|
||||||
|
}
|
||||||
|
|
||||||
|
val user = service.getUserByPhone(phone)
|
||||||
|
if (user == null) {
|
||||||
|
return JSONResponse(Const.codeResourceNotFound, Const.msgNotFound, null)
|
||||||
|
} else {
|
||||||
|
if (user.passwd == passwd) {
|
||||||
|
user.passwd = null
|
||||||
|
val session = request.getSession(true)
|
||||||
|
val token = md5(phone + ":" + passwd)
|
||||||
|
session.put("phone", phone)
|
||||||
|
session.put("token", token)
|
||||||
|
return responseSuccess(mapOf(
|
||||||
|
"token" to token,
|
||||||
|
"user" to user
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
return JSONResponse(403, "密码错误", null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET("/hasPermission/{userId: [0-9]+}/{perm}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun hasPermission(@Param("userId") userId: Int, @Param("perm") perm: String): JSONResponse {
|
||||||
|
val role = service.getRoleByUserId(userId)
|
||||||
|
if (role != null) {
|
||||||
|
val perms = service.getPermByRoleId(role.id!!)
|
||||||
|
val hasPermission = perms.any {
|
||||||
|
it.perm == URLDecoder.decode(perm)
|
||||||
|
}
|
||||||
|
if (hasPermission) {
|
||||||
|
return responseSuccess(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return responseSuccess(false)
|
||||||
|
}
|
||||||
|
|
||||||
@POST("/bindGroup/{userId: [0-9]+}/{groupId: [0-9]+}")
|
@POST("/bindGroup/{userId: [0-9]+}/{groupId: [0-9]+}")
|
||||||
@Produces(Produces.JSON)
|
@Produces(Produces.JSON)
|
||||||
fun bindGroup(@Param("userId") userId: Int, @Param("groupId") groupId: Int): JSONResponse {
|
fun bindGroup(@Param("userId") userId: Int, @Param("groupId") groupId: Int): JSONResponse {
|
||||||
|
|
|
||||||
|
|
@ -1,239 +1,198 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
|
import com.jfinal.plugin.activerecord.Db
|
||||||
|
import com.jfinal.plugin.activerecord.Model
|
||||||
|
import com.jfinal.plugin.activerecord.Page
|
||||||
|
import com.jfinal.plugin.activerecord.Record
|
||||||
import model.*
|
import model.*
|
||||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException
|
import sun.reflect.generics.reflectiveObjects.NotImplementedException
|
||||||
import util.*
|
import util.*
|
||||||
|
import java.sql.Timestamp
|
||||||
|
import java.util.*
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
import kotlin.reflect.full.companionObjectInstance
|
||||||
|
import kotlin.reflect.full.functions
|
||||||
|
|
||||||
class Service {
|
class Service {
|
||||||
fun getUserById(id: Int): ModelUser? {
|
/*
|
||||||
val rs = DBUtil.getConnection().createStatement()
|
通用函数
|
||||||
.executeQuery("select * from `user` where id=$id")
|
*/
|
||||||
|
|
||||||
return if (rs.next()) {
|
private fun getDAOFromClass(cls: KClass<*>): Model<*> {
|
||||||
return rsToUser(rs)
|
return when (cls) {
|
||||||
|
ModelUser::class -> JFinalModelUser.DAO
|
||||||
|
ModelRole::class -> JFinalModelRole.DAO
|
||||||
|
ModelGroup::class -> JFinalModelGroup.DAO
|
||||||
|
ModelPerm::class -> JFinalModelPerm.DAO
|
||||||
|
ModelMenu::class -> JFinalModelMenu.DAO
|
||||||
|
else -> throw IllegalArgumentException()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> getById(cls: KClass<*>, id: Int): T? {
|
||||||
|
val dao = getDAOFromClass(cls)
|
||||||
|
val model = dao.findById(id) ?: return null
|
||||||
|
|
||||||
|
val companion = cls.companionObjectInstance!!
|
||||||
|
val func = companion::class.functions.filter { "fromJFinal" == it.name }.first()
|
||||||
|
val ret = func.call(companion, model)
|
||||||
|
return ret as T?
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> getByColumn(cls: KClass<*>, instance: Any) {
|
||||||
|
throw NotImplementedException()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun save(cls: KClass<*>, instance: Any): Boolean {
|
||||||
|
val model = instance::class.functions.filter { "toJFinal" == it.name }.first().call(instance) as Model<*>
|
||||||
|
model.set("createTime", Timestamp(Date().time))
|
||||||
|
model.remove("id")
|
||||||
|
return model.save()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> save(cls: KClass<*>, instance: Any, modelNeedReturn: Boolean): Pair<T?, Boolean> {
|
||||||
|
if (modelNeedReturn) {
|
||||||
|
val model = instance::class.functions.filter { "toJFinal" == it.name }.first() as Model<*>
|
||||||
|
val companion = cls.companionObjectInstance!!
|
||||||
|
val func = companion::class.functions.filter { "fromJFinal" == it.name }.first()
|
||||||
|
val ret = func.call(companion, model)
|
||||||
|
return (ret as T) to model.save()
|
||||||
} else {
|
} else {
|
||||||
null
|
return null to save(cls, instance)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveUser(user: ModelUser): Boolean {
|
fun update(cls: KClass<*>, instance: Any): Boolean {
|
||||||
try {
|
val model = instance::class.functions.filter { "toJFinal" == it.name }.first().call(instance) as Model<*>
|
||||||
DBUtil.getConnection().createStatement()
|
return model.update()
|
||||||
.executeUpdate(userToInsertSQL(user))
|
}
|
||||||
return true
|
|
||||||
} catch (e: Exception) {
|
fun <T> update(cls: KClass<*>, instance: Any, modelNeedReturn: Boolean): Pair<T?, Boolean> {
|
||||||
return false
|
if (modelNeedReturn) {
|
||||||
|
val model = instance::class.functions.filter { "toJFinal" == it.name }.first() as Model<*>
|
||||||
|
val companion = cls.companionObjectInstance!!
|
||||||
|
val func = companion::class.functions.filter { "fromJFinal" == it.name }.first()
|
||||||
|
val ret = func.call(companion, model)
|
||||||
|
return (ret as T) to model.update()
|
||||||
|
} else {
|
||||||
|
return null to save(cls, instance)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateUser(user: ModelUser): Boolean {
|
fun deleteById(cls: KClass<*>, id: Int): Boolean {
|
||||||
throw NotImplementedException()
|
val dao = getDAOFromClass(cls)
|
||||||
|
return dao.deleteById(id)
|
||||||
|
}
|
||||||
|
//分隔符
|
||||||
|
|
||||||
|
fun isUserNameDuplicate(name: String): Boolean {
|
||||||
|
val userModel = JFinalModelUser.DAO.findFirst("select * from `user` where name='$name'")
|
||||||
|
return userModel != null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteUser(userId: Int): Boolean {
|
fun saveUser(user: ModelUser): Pair<Status, Boolean> {
|
||||||
return DBUtil.getConnection().createStatement()
|
var isDuplicated = false
|
||||||
.executeUpdate("delete from `user` where id=$userId") > 1
|
if (user.name != null) {
|
||||||
|
isDuplicated = isUserNameDuplicate(user.name!!)
|
||||||
|
}
|
||||||
|
|
||||||
|
return if (isDuplicated) {
|
||||||
|
Status.DUPLICATED to false
|
||||||
|
} else {
|
||||||
|
user.passwd = "111"
|
||||||
|
val result = save(ModelUser::class, user)
|
||||||
|
if (result) {
|
||||||
|
Status.SUCCESS to result
|
||||||
|
} else {
|
||||||
|
Status.FAILED_WITH_UNKNOWN_REASON to result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun changePasswd(user: ModelUser, passwd: String): Boolean {
|
|
||||||
throw NotImplementedException()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getGroupByUserId(userId: Int): ModelGroup? {
|
fun getGroupByUserId(userId: Int): ModelGroup? {
|
||||||
val user = getUserById(userId)
|
val userModel = JFinalModelUser.DAO.findById(userId) ?: return null
|
||||||
if (user == null) {
|
val user = ModelUser.fromJFinal(userModel)
|
||||||
return null
|
|
||||||
|
val groupModel = JFinalModelGroup.DAO.findById(user.groupId) ?: return null
|
||||||
|
return ModelGroup.fromJFinal(groupModel)
|
||||||
}
|
}
|
||||||
val rs = DBUtil.getConnection().createStatement()
|
|
||||||
.executeQuery("select * from `group` where id=${user.groupId}")
|
fun changePasswd(user: ModelUser, passwd: String): Pair<Boolean, ModelUser?> {
|
||||||
return if (rs.next()) {
|
val userModel = user.toJFinal()
|
||||||
return rsToGroup(rs)
|
val result = userModel.set("passwd", passwd).update()
|
||||||
|
return if (result) {
|
||||||
|
true to ModelUser.fromJFinal(userModel.remove("passwd"))
|
||||||
} else {
|
} else {
|
||||||
null
|
false to null
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun saveGroup(group: ModelGroup): Boolean {
|
|
||||||
try {
|
|
||||||
println(groupToInsertSQL(group))
|
|
||||||
DBUtil.getConnection().createStatement()
|
|
||||||
.execute(groupToInsertSQL(group))
|
|
||||||
return true
|
|
||||||
} catch (e: Exception) { e.printStackTrace()
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateGroup(group: ModelGroup): Boolean {
|
|
||||||
throw NotImplementedException()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun deleteGroup(groupId: Int): Boolean {
|
|
||||||
return DBUtil.getConnection().createStatement()
|
|
||||||
.executeUpdate("delete from `group` where id=$groupId") > 1
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getGroupById(groupId: Int): ModelGroup? {
|
|
||||||
val rs = DBUtil.getConnection().createStatement()
|
|
||||||
.executeQuery("select * from `group` where id=$groupId")
|
|
||||||
|
|
||||||
return if (rs.next()) {
|
|
||||||
return rsToGroup(rs)
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun bindUserToGroup(userId: Int, groupId: Int): Boolean {
|
fun bindUserToGroup(userId: Int, groupId: Int): Boolean {
|
||||||
val user = getUserById(userId)
|
JFinalModelGroup.DAO.findById(groupId) ?: return false
|
||||||
if (user == null) {
|
val userModel = JFinalModelUser.DAO.findById(userId) ?: return false
|
||||||
return false
|
userModel.set("groupId", groupId)
|
||||||
}
|
return userModel.update()
|
||||||
|
|
||||||
return DBUtil.getConnection().createStatement()
|
|
||||||
.execute("update `user` set groupId=$groupId where id=$userId")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unbindUserToGroup(userId: Int, groupId: Int): Boolean {
|
fun unbindUserToGroup(userId: Int, groupId: Int): Boolean {
|
||||||
return DBUtil.getConnection().createStatement()
|
JFinalModelGroup.DAO.findById(groupId) ?: return false
|
||||||
.execute("update `user` set groupId=-1 where id=$userId")
|
val userModel = JFinalModelUser.DAO.findById(userId) ?: return false
|
||||||
}
|
userModel.set("groupId", -1)
|
||||||
|
return userModel.update()
|
||||||
fun getRoleById(roleId: Int): ModelRole? {
|
|
||||||
val rs = DBUtil.getConnection().createStatement()
|
|
||||||
.executeQuery("select * from `role` where id=$roleId")
|
|
||||||
|
|
||||||
return if (rs.next()) {
|
|
||||||
return rsToRole(rs)
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getRoleByUserId(userId: Int): ModelRole? {
|
fun getRoleByUserId(userId: Int): ModelRole? {
|
||||||
val user = getUserById(userId)
|
val userModel = JFinalModelUser.DAO.findById(userId) ?: return null
|
||||||
if (user == null) {
|
val user = ModelUser.fromJFinal(userModel)
|
||||||
return null
|
|
||||||
}
|
|
||||||
val rs = DBUtil.getConnection().createStatement()
|
|
||||||
.executeQuery("select * from `role` where id=${user.roleId}")
|
|
||||||
return if (rs.next()) {
|
|
||||||
return rsToRole(rs)
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun saveRole(role: ModelRole): Boolean {
|
val roleModel = JFinalModelRole.DAO.findById(user.roleId) ?: return null
|
||||||
try {
|
return ModelRole.fromJFinal(roleModel)
|
||||||
DBUtil.getConnection().createStatement()
|
|
||||||
.execute(roleToInsertSQL(role))
|
|
||||||
return true
|
|
||||||
} catch (e: Exception) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun deleteRole(roleId: Int): Boolean {
|
|
||||||
return DBUtil.getConnection().createStatement()
|
|
||||||
.executeUpdate("delete from `role` where id=$roleId") > 1
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateRole(role: ModelRole): Boolean {
|
|
||||||
throw NotImplementedException()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun bindUserToRole(userId: Int, roleId: Int): Boolean {
|
fun bindUserToRole(userId: Int, roleId: Int): Boolean {
|
||||||
val user = getUserById(userId)
|
JFinalModelRole.DAO.findById(roleId) ?: return false
|
||||||
if (user == null) {
|
val userModel = JFinalModelUser.DAO.findById(userId) ?: return false
|
||||||
return false
|
userModel.set("roleId", roleId)
|
||||||
}
|
return userModel.update()
|
||||||
|
|
||||||
return DBUtil.getConnection().createStatement()
|
|
||||||
.execute("update `user` set roleId=$roleId where id=$userId")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unbindUserToRole(userId: Int, roleId: Int): Boolean {
|
fun unbindUserToRole(userId: Int, roleId: Int): Boolean {
|
||||||
val user = getUserById(userId)
|
JFinalModelGroup.DAO.findById(roleId) ?: return false
|
||||||
if (user == null) {
|
val userModel = JFinalModelUser.DAO.findById(userId) ?: return false
|
||||||
return false
|
userModel.set("roleId", -1)
|
||||||
}
|
return userModel.update()
|
||||||
|
|
||||||
return DBUtil.getConnection().createStatement()
|
|
||||||
.execute("update `user` set roleId=-1 where id=$userId")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getPermById(permId: Int): ModelPerm? {
|
|
||||||
val rs = DBUtil.getConnection().createStatement()
|
|
||||||
.executeQuery("select * from `perm` where id=$permId")
|
|
||||||
|
|
||||||
return if (rs.next()) {
|
|
||||||
return rsToPerm(rs)
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getPermByRoleId(roleId: Int): List<ModelPerm> {
|
fun getPermByRoleId(roleId: Int): List<ModelPerm> {
|
||||||
val conn = DBUtil.getConnection()
|
val list = mutableListOf<ModelPerm>()
|
||||||
val rs = conn.createStatement()
|
val perms = JFinalModelPerm.DAO.find(
|
||||||
.executeQuery("""
|
"""
|
||||||
select * from perm t
|
select * from perm t
|
||||||
where exists(
|
where exists(
|
||||||
select * from mapping_perm_role m where m.roleid = $roleId
|
select * from mapping_perm_role m where m.roleid = ?
|
||||||
)
|
)
|
||||||
""".trim())
|
""".trim()
|
||||||
val list = mutableListOf<ModelPerm>()
|
) ?: return list
|
||||||
while (rs.next()) {
|
perms.forEach {
|
||||||
list.add(rsToPerm(rs))
|
list.add(ModelPerm.fromJFinal(it))
|
||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
fun savePerm(perm: ModelPerm): Boolean {
|
|
||||||
try {
|
|
||||||
DBUtil.getConnection().createStatement()
|
|
||||||
.executeUpdate(permToInsertSQL(perm))
|
|
||||||
return true
|
|
||||||
} catch (e: Exception) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updatePerm(perm: ModelPerm): Boolean {
|
|
||||||
throw NotImplementedException()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun deletePerm(permId: Int): Boolean {
|
|
||||||
return DBUtil.getConnection().createStatement()
|
|
||||||
.executeUpdate("delete from `perm` where id=$permId") > 1
|
|
||||||
}
|
|
||||||
|
|
||||||
fun bindPermToRole(permId: Int, roleId: Int): Boolean {
|
fun bindPermToRole(permId: Int, roleId: Int): Boolean {
|
||||||
val perm = getPermById(permId)
|
JFinalModelRole.DAO.findById(roleId) ?: return false
|
||||||
val role = getRoleById(roleId)
|
JFinalModelPerm.DAO.findById(permId) ?: return false
|
||||||
if (perm == null || role == null) {
|
val record = Db.findFirst("select * from mapping_perm_role where permId=$permId and roleId=$roleId")
|
||||||
return false
|
return if (record != null) true
|
||||||
}
|
else Db.save("mapping_perm_role", Record().set("permId", permId).set("roleId", roleId))
|
||||||
|
|
||||||
return DBUtil.getConnection().createStatement()
|
|
||||||
.execute("insert into mapping_perm_role($permId,$roleId)")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unbindPermToRole(permId: Int, roleId: Int): Boolean {
|
fun unbindPermToRole(permId: Int, roleId: Int): Boolean {
|
||||||
return DBUtil.getConnection().createStatement()
|
JFinalModelRole.DAO.findById(roleId) ?: return false
|
||||||
.executeUpdate("delete from mapping_perm_role where permId=$permId and roleId=$roleId)") > 1
|
JFinalModelPerm.DAO.findById(permId) ?: return false
|
||||||
}
|
Db.findFirst("select * from mapping_perm_role where permId=$permId and roleId=$roleId") ?: return true
|
||||||
|
return Db.delete("mapping_perm_role", Record().set("permId", permId).set("roleId", roleId))
|
||||||
fun getMenuById(menuId: Int): ModelMenu? {
|
|
||||||
val rs = DBUtil.getConnection().createStatement()
|
|
||||||
.executeQuery("select * from `menu` where id=$menuId")
|
|
||||||
|
|
||||||
return if (rs.next()) {
|
|
||||||
return rsToMenu(rs)
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMenuByRole(roleId: Int): List<ModelMenu> {
|
fun getMenuByRole(roleId: Int): List<ModelMenu> {
|
||||||
|
|
@ -241,37 +200,355 @@ class Service {
|
||||||
throw NotImplementedException()
|
throw NotImplementedException()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveMenu(menu: ModelMenu): Boolean {
|
fun bindMenuToPerm(menuId: Int, permId: Int): Boolean {
|
||||||
|
JFinalModelPerm.DAO.findById(permId) ?: return false
|
||||||
|
val menu = JFinalModelMenu.DAO.findById(menuId) ?: return false
|
||||||
|
menu.set("permId", permId)
|
||||||
|
return menu.update()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun unbindMenuToPerm(menuId: Int, permId: Int): Boolean {
|
||||||
|
JFinalModelPerm.DAO.findById(permId) ?: return false
|
||||||
|
val menu = JFinalModelMenu.DAO.findById(menuId) ?: return false
|
||||||
|
menu.set("permId", -1)
|
||||||
|
return menu.update()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getTableNameFromClass(cls: KClass<*>): String {
|
||||||
|
return when (cls) {
|
||||||
|
ModelUser::class -> "`user`"
|
||||||
|
ModelRole::class -> "`role`"
|
||||||
|
ModelGroup::class -> "`group`"
|
||||||
|
ModelPerm::class -> "`perm`"
|
||||||
|
ModelMenu::class -> "`menu`"
|
||||||
|
else -> throw IllegalArgumentException()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun simplePagi(cls: KClass<*>, page: Int, size: Int): Page<Record> {
|
||||||
|
val tableName = getTableNameFromClass(cls)
|
||||||
|
return Db.paginate(page, size, "select *", "from `$tableName`")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("", ReplaceWith("simplePagi"))
|
||||||
|
fun pagiUser(page: Int, size: Int): Page<Record> {
|
||||||
|
return Db.paginate(page, size, "select *", "from `user`")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("", ReplaceWith("simplePagi"))
|
||||||
|
fun pagiGroup(page: Int, size: Int): Page<Record> {
|
||||||
|
return Db.paginate(page, size, "select *", "from `group`")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("", ReplaceWith("simplePagi"))
|
||||||
|
fun pagiMenu(page: Int, size: Int): Page<Record> {
|
||||||
|
return Db.paginate(page, size, "select *", "from `menu`")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("", ReplaceWith("simplePagi"))
|
||||||
|
fun pagiPerm(page: Int, size: Int): Page<Record> {
|
||||||
|
return Db.paginate(page, size, "select *", "from `perm`")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("", ReplaceWith("simplePagi"))
|
||||||
|
fun pagiRole(page: Int, size: Int): Page<Record> {
|
||||||
|
return Db.paginate(page, size, "select *", "from `role`")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
fun getUserById(id: Int): ModelUser? {
|
||||||
|
val conn = DBUtil.getConnection()
|
||||||
|
val prep = conn.prepareStatement("select * from `user` where id=?")
|
||||||
|
prep.setInt(1, id)
|
||||||
|
val rs = prep.executeQuery()
|
||||||
|
return if (rs.next()) {
|
||||||
|
val user = rsToUser(rs)
|
||||||
|
conn.close()
|
||||||
|
return user
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getUserByPhone(phone:String):ModelUser? {
|
||||||
|
val user = JFinalModelUser.DAO.findFirst("select * from `user` where phone='$phone'")
|
||||||
|
return if (user == null) {
|
||||||
|
null
|
||||||
|
} else {
|
||||||
|
ModelUser.fromJFinal(user)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Deprecated("")
|
||||||
|
fun getUserByName(userName: String): ModelUser? {
|
||||||
|
val conn = DBUtil.getConnection()
|
||||||
|
val prep = conn.prepareStatement("select * from `user` where name=?")
|
||||||
|
prep.setString(1, userName)
|
||||||
|
val rs = prep.executeQuery();
|
||||||
|
return if (rs.next()) {
|
||||||
|
val user = rsToUser(rs)
|
||||||
|
conn.close()
|
||||||
|
return user
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
fun updateUser(user: ModelUser): Boolean {
|
||||||
|
throw NotImplementedException()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
fun deleteUser(userId: Int): Boolean {
|
||||||
|
val conn = DBUtil.getConnection()
|
||||||
try {
|
try {
|
||||||
DBUtil.getConnection().createStatement()
|
val prep = conn.prepareStatement("delete from `user` where id=?")
|
||||||
|
prep.setInt(1, userId)
|
||||||
|
prep.execute()
|
||||||
|
return true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
return false
|
||||||
|
} finally {
|
||||||
|
conn.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
fun saveGroup(group: ModelGroup): Boolean {
|
||||||
|
return save(ModelGroup::class, group)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
fun updateGroup(group: ModelGroup): Boolean {
|
||||||
|
throw NotImplementedException()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
fun deleteGroup(groupId: Int): Boolean {
|
||||||
|
val conn = DBUtil.getConnection()
|
||||||
|
try {
|
||||||
|
val prep = conn.prepareStatement("delete from `group` where id=?")
|
||||||
|
prep.setInt(1, groupId)
|
||||||
|
prep.execute()
|
||||||
|
return true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
return false
|
||||||
|
} finally {
|
||||||
|
conn.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
fun getGroupById(groupId: Int): ModelGroup? {
|
||||||
|
val conn = DBUtil.getConnection()
|
||||||
|
try {
|
||||||
|
val prep = conn.prepareStatement("select * from `group` where id=?")
|
||||||
|
prep.setInt(1, groupId)
|
||||||
|
val rs = prep.executeQuery()
|
||||||
|
return if (rs.next()) {
|
||||||
|
return rsToGroup(rs)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
conn.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
fun getRoleById(roleId: Int): ModelRole? {
|
||||||
|
val conn = DBUtil.getConnection()
|
||||||
|
try {
|
||||||
|
val prep = conn.prepareStatement("select * from `role` where id=?")
|
||||||
|
prep.setInt(1, roleId)
|
||||||
|
val rs = prep.executeQuery()
|
||||||
|
|
||||||
|
return if (rs.next()) {
|
||||||
|
return rsToRole(rs)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
conn.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
fun getRoleByName(roleName: String): ModelRole? {
|
||||||
|
val conn = DBUtil.getConnection()
|
||||||
|
val prep = conn.prepareStatement("select * from `role` where description=?")
|
||||||
|
prep.setString(1, roleName)
|
||||||
|
val rs = prep.executeQuery();
|
||||||
|
return if (rs.next()) {
|
||||||
|
val role = rsToRole(rs)
|
||||||
|
conn.close()
|
||||||
|
return role
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
fun saveRole(role: ModelRole): Boolean {
|
||||||
|
val conn = DBUtil.getConnection()
|
||||||
|
try {
|
||||||
|
conn.createStatement()
|
||||||
|
.execute(roleToInsertSQL(role))
|
||||||
|
return true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
return false
|
||||||
|
} finally {
|
||||||
|
conn.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
fun deleteRole(roleId: Int): Boolean {
|
||||||
|
val conn = DBUtil.getConnection()
|
||||||
|
try {
|
||||||
|
val prep = conn.prepareStatement("delete from `role` where id=?")
|
||||||
|
prep.setInt(1, roleId)
|
||||||
|
prep.execute()
|
||||||
|
|
||||||
|
return true
|
||||||
|
|
||||||
|
} catch (e: Exception) {
|
||||||
|
return false
|
||||||
|
} finally {
|
||||||
|
conn.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
fun updateRole(role: ModelRole): Boolean {
|
||||||
|
throw NotImplementedException()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
fun getPermById(permId: Int): ModelPerm? {
|
||||||
|
val conn = DBUtil.getConnection()
|
||||||
|
try {
|
||||||
|
val prep = conn.prepareStatement("select * from `perm` where id=?")
|
||||||
|
prep.setInt(1, permId)
|
||||||
|
|
||||||
|
val rs = prep.executeQuery()
|
||||||
|
|
||||||
|
return if (rs.next()) {
|
||||||
|
return rsToPerm(rs)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
conn.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
fun getPremByName(permName: String): ModelPerm? {
|
||||||
|
val conn = DBUtil.getConnection()
|
||||||
|
val prep = conn.prepareStatement("select * from `perm` where description=?")
|
||||||
|
prep.setString(1, permName)
|
||||||
|
val rs = prep.executeQuery()
|
||||||
|
return if (rs.next()) {
|
||||||
|
val perm = rsToPerm(rs)
|
||||||
|
conn.close()
|
||||||
|
return perm
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
fun savePerm(perm: ModelPerm): Boolean {
|
||||||
|
val conn = DBUtil.getConnection()
|
||||||
|
try {
|
||||||
|
conn.createStatement()
|
||||||
|
.execute(permToInsertSQL(perm))
|
||||||
|
return true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
return false
|
||||||
|
} finally {
|
||||||
|
conn.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
fun updatePerm(perm: ModelPerm): Boolean {
|
||||||
|
throw NotImplementedException()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
fun deletePerm(permId: Int): Boolean {
|
||||||
|
val conn = DBUtil.getConnection()
|
||||||
|
try {
|
||||||
|
val prep = conn.prepareStatement("delete from `perm` where id=?")
|
||||||
|
prep.setInt(1, permId)
|
||||||
|
prep.execute()
|
||||||
|
|
||||||
|
return true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
return false
|
||||||
|
} finally {
|
||||||
|
conn.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
fun getMenuById(menuId: Int): ModelMenu? {
|
||||||
|
val conn = DBUtil.getConnection()
|
||||||
|
try {
|
||||||
|
val prep = conn.prepareStatement("select * from `menu` where id=?")
|
||||||
|
prep.setInt(1, menuId)
|
||||||
|
|
||||||
|
val rs = prep.executeQuery()
|
||||||
|
|
||||||
|
return if (rs.next()) {
|
||||||
|
return rsToMenu(rs)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
conn.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
fun saveMenu(menu: ModelMenu): Boolean {
|
||||||
|
val conn = DBUtil.getConnection()
|
||||||
|
try {
|
||||||
|
conn.createStatement()
|
||||||
.execute(menuToInsertSQL(menu))
|
.execute(menuToInsertSQL(menu))
|
||||||
return true
|
return true
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
return false
|
return false
|
||||||
|
} finally {
|
||||||
|
conn.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
fun updateMenu(menu: ModelMenu): Boolean {
|
fun updateMenu(menu: ModelMenu): Boolean {
|
||||||
throw NotImplementedException()
|
throw NotImplementedException()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
fun deleteMenu(menuId: Int): Boolean {
|
fun deleteMenu(menuId: Int): Boolean {
|
||||||
return DBUtil.getConnection().createStatement()
|
val conn = DBUtil.getConnection()
|
||||||
.executeUpdate("delete from `menu` where id=$menuId") > 1
|
try {
|
||||||
}
|
val prep = conn.prepareStatement("delete from `menu` where id=?")
|
||||||
|
prep.setInt(1, menuId)
|
||||||
|
prep.execute()
|
||||||
|
|
||||||
fun bindMenuToPerm(menuId: Int, permId: Int): Boolean {
|
return true
|
||||||
val menu = getMenuById(menuId)
|
} catch (e: Exception) {
|
||||||
if (menu == null) {
|
|
||||||
return false
|
return false
|
||||||
|
} finally {
|
||||||
|
conn.close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return DBUtil.getConnection().createStatement()
|
enum class Status {
|
||||||
.execute("update `menu` set permId=$permId where id=$menuId")
|
SUCCESS, FAILED_WITH_UNKNOWN_REASON, DUPLICATED
|
||||||
}
|
|
||||||
|
|
||||||
fun unbindMenuToPerm(menuId: Int, permId: Int): Boolean {
|
|
||||||
return DBUtil.getConnection().createStatement()
|
|
||||||
.execute("update `menu` set permId=-1 where id=$menuId")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ object DBUtil {
|
||||||
private val druidDataSource: DruidDataSource = DruidDataSource()
|
private val druidDataSource: DruidDataSource = DruidDataSource()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
druidDataSource.url = "jdbc:mysql://rm-wz9n28sq10rz5b0u2o.mysql.rds.aliyuncs.com:3306/sh-upgram"
|
druidDataSource.url = "jdbc:mysql://rm-wz9n28sq10rz5b0u2o.mysql.rds.aliyuncs.com:3306/sh-upgram?serverTimezone=GMT"
|
||||||
druidDataSource.driverClassName = "com.mysql.cj.jdbc.Driver"
|
druidDataSource.driverClassName = "com.mysql.cj.jdbc.Driver"
|
||||||
druidDataSource.username = "shzhyjxy"
|
druidDataSource.username = "shzhyjxy"
|
||||||
druidDataSource.password = "Admin111"
|
druidDataSource.password = "Admin111"
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,17 @@
|
||||||
package util
|
package util
|
||||||
|
|
||||||
|
import com.jfinal.plugin.activerecord.Record
|
||||||
import config.Const
|
import config.Const
|
||||||
import model.*
|
import model.*
|
||||||
|
import ro.pippo.core.ParameterValue
|
||||||
|
import ro.pippo.core.Request
|
||||||
|
import java.security.MessageDigest
|
||||||
|
import java.security.NoSuchAlgorithmException
|
||||||
import java.sql.ResultSet
|
import java.sql.ResultSet
|
||||||
import java.sql.Timestamp
|
import java.sql.Timestamp
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
fun responseNotFoundById(): JSONResponse {
|
fun responseNotFoundById(): JSONResponse {
|
||||||
return JSONResponse(Const.codeResourceNotFound, Const.msgNotFoundById, null)
|
return JSONResponse(Const.codeResourceNotFound, Const.msgNotFoundById, null)
|
||||||
|
|
@ -14,6 +21,30 @@ fun responseOperationFailed(): JSONResponse {
|
||||||
return JSONResponse(Const.codeServiceOperationFailed, Const.msgOperationFailed, false)
|
return JSONResponse(Const.codeServiceOperationFailed, Const.msgOperationFailed, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun responseUpdateUserFailed(): JSONResponse {
|
||||||
|
return JSONResponse(Const.codeServiceOperationFailed, Const.msgUpdateUserFailed, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun responseUpdateRoleFailed(): JSONResponse {
|
||||||
|
return JSONResponse(Const.codeServiceOperationFailed, Const.msgUpdateRoleFailed, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun responseUpdateGroupFailed(): JSONResponse {
|
||||||
|
return JSONResponse(Const.codeServiceOperationFailed, Const.msgUpdateGroupFailed, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun responseUpdateMenuFailed(): JSONResponse {
|
||||||
|
return JSONResponse(Const.codeServiceOperationFailed, Const.msgUpdateMenuFailed, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun responseUpdatePermFailed(): JSONResponse {
|
||||||
|
return JSONResponse(Const.codeServiceOperationFailed, Const.msgUpdatepermFailed, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun responseCheckNameFailed(): JSONResponse {
|
||||||
|
return JSONResponse(Const.codeSuccess, "", false)
|
||||||
|
}
|
||||||
|
|
||||||
fun responseInvalidParams(): JSONResponse {
|
fun responseInvalidParams(): JSONResponse {
|
||||||
return JSONResponse(Const.codeInvalidParams, Const.msgInvalidParams, null)
|
return JSONResponse(Const.codeInvalidParams, Const.msgInvalidParams, null)
|
||||||
}
|
}
|
||||||
|
|
@ -22,10 +53,12 @@ fun responseSuccess(result: Any): JSONResponse {
|
||||||
return JSONResponse(Const.codeSuccess, Const.msgEmptyMsg, result)
|
return JSONResponse(Const.codeSuccess, Const.msgEmptyMsg, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun rsToUser(rs: ResultSet): ModelUser {
|
fun rsToUser(rs: ResultSet): ModelUser {
|
||||||
return ModelUser(
|
return ModelUser(
|
||||||
id = rs.getInt("id"),
|
id = rs.getInt("id"),
|
||||||
name = rs.getString("name"),
|
name = rs.getString("name"),
|
||||||
|
phone = rs.getString("phone"),
|
||||||
passwd = rs.getString("passwd"),
|
passwd = rs.getString("passwd"),
|
||||||
groupId = rs.getInt("groupId"),
|
groupId = rs.getInt("groupId"),
|
||||||
roleId = rs.getInt("roleId"),
|
roleId = rs.getInt("roleId"),
|
||||||
|
|
@ -33,28 +66,15 @@ fun rsToUser(rs: ResultSet): ModelUser {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun userToInsertSQL(user: ModelUser): String {
|
|
||||||
return """
|
|
||||||
insert into `user`(name,passwd,createTime)
|
|
||||||
values('${user.name}','${user.passwd}','${Timestamp.from(Instant.now())}')
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
|
|
||||||
fun rsToGroup(rs: ResultSet): ModelGroup {
|
fun rsToGroup(rs: ResultSet): ModelGroup {
|
||||||
return ModelGroup(
|
return ModelGroup(
|
||||||
id = rs.getInt("id"),
|
id = rs.getInt("id"),
|
||||||
description = rs.getString("description"),
|
description = rs.getString("description"),
|
||||||
|
parentId = rs.getInt("parentId"),
|
||||||
createTime = rs.getTimestamp("createTime")
|
createTime = rs.getTimestamp("createTime")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun groupToInsertSQL(group: ModelGroup): String {
|
|
||||||
return """
|
|
||||||
insert into `group`(description,createTime)
|
|
||||||
values('${group.description}','${Timestamp.from(Instant.now())}')
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
|
|
||||||
fun rsToRole(rs: ResultSet): ModelRole {
|
fun rsToRole(rs: ResultSet): ModelRole {
|
||||||
return ModelRole(
|
return ModelRole(
|
||||||
id = rs.getInt("id"),
|
id = rs.getInt("id"),
|
||||||
|
|
@ -66,7 +86,7 @@ fun rsToRole(rs: ResultSet): ModelRole {
|
||||||
fun roleToInsertSQL(role: ModelRole): String {
|
fun roleToInsertSQL(role: ModelRole): String {
|
||||||
return """
|
return """
|
||||||
insert into `role`(description,createTime)
|
insert into `role`(description,createTime)
|
||||||
values('${role.description}','${Timestamp.from(Instant.now())}')
|
values('${role.description}','${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}')
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,7 +101,7 @@ fun rsToPerm(rs: ResultSet): ModelPerm {
|
||||||
|
|
||||||
fun permToInsertSQL(perm: ModelPerm): String {
|
fun permToInsertSQL(perm: ModelPerm): String {
|
||||||
return """
|
return """
|
||||||
insert into `role`(description,perm,createTime)
|
insert into `perm`(description,perm,createTime)
|
||||||
values('${perm.description}','${perm.perm}','${Timestamp.from(Instant.now())}')
|
values('${perm.description}','${perm.perm}','${Timestamp.from(Instant.now())}')
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
@ -92,13 +112,48 @@ fun rsToMenu(rs: ResultSet): ModelMenu {
|
||||||
description = rs.getString("description"),
|
description = rs.getString("description"),
|
||||||
url = rs.getString("url"),
|
url = rs.getString("url"),
|
||||||
permId = rs.getInt("permId"),
|
permId = rs.getInt("permId"),
|
||||||
|
parentId = rs.getInt("parentId"),
|
||||||
|
order = rs.getInt("order"),
|
||||||
|
type = rs.getInt("type"),
|
||||||
createTime = rs.getTimestamp("createTime")
|
createTime = rs.getTimestamp("createTime")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun menuToInsertSQL(menu: ModelMenu): String {
|
fun menuToInsertSQL(menu: ModelMenu): String {
|
||||||
return """
|
return """
|
||||||
insert into `role`(description,url,permId,createTime)
|
insert into `menu`(description,url,permId,createTime)
|
||||||
values('${menu.description}','${menu.description}','${menu.permId}','${Timestamp.from(Instant.now())}')
|
values('${menu.description}','${menu.description}','${menu.permId}','${Timestamp.from(Instant.now())}')
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun updateUtil(record: Record, request: Request): Record {
|
||||||
|
|
||||||
|
val params: Map<String, ParameterValue> = request.parameters
|
||||||
|
params.forEach {
|
||||||
|
if (null != it.value) {
|
||||||
|
record.set(it.key, it.value.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return record
|
||||||
|
}
|
||||||
|
|
||||||
|
fun md5(str: String): String {
|
||||||
|
try {
|
||||||
|
val instance: MessageDigest = MessageDigest.getInstance("MD5")//获取md5加密对象
|
||||||
|
val digest: ByteArray = instance.digest(str.toByteArray())//对字符串加密,返回字节数组
|
||||||
|
val sb = StringBuffer()
|
||||||
|
for (b in digest) {
|
||||||
|
var i: Int = b.toInt() and 0xff//获取低八位有效值
|
||||||
|
var hexString = Integer.toHexString(i)//将整数转化为16进制
|
||||||
|
if (hexString.length < 2) {
|
||||||
|
hexString = "0" + hexString//如果是一位的话,补0
|
||||||
|
}
|
||||||
|
sb.append(hexString)
|
||||||
|
}
|
||||||
|
return sb.toString()
|
||||||
|
|
||||||
|
} catch (e: NoSuchAlgorithmException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
package util
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit e8deba38aa7c1125be08c8f0610ad66a9df29ace
|
||||||
Loading…
Reference in New Issue