init
commit
2319c09f71
|
|
@ -0,0 +1,10 @@
|
||||||
|
# Created by .ignore support plugin (hsz.mobi)
|
||||||
|
### Example user template template
|
||||||
|
### Example user template
|
||||||
|
|
||||||
|
# IntelliJ project files
|
||||||
|
.idea
|
||||||
|
*.iml
|
||||||
|
out
|
||||||
|
gen
|
||||||
|
target
|
||||||
|
|
@ -0,0 +1,118 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>cn.cloudowr</groupId>
|
||||||
|
<artifactId>upgram</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<kotlin.version>1.1.4</kotlin.version>
|
||||||
|
<pippo.version>1.5.0</pippo.version>
|
||||||
|
</properties>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>central</id>
|
||||||
|
<url>http://jcenter.bintray.com</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ro.pippo</groupId>
|
||||||
|
<artifactId>pippo-core</artifactId>
|
||||||
|
<version>${pippo.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ro.pippo</groupId>
|
||||||
|
<artifactId>pippo-controller</artifactId>
|
||||||
|
<version>${pippo.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ro.pippo</groupId>
|
||||||
|
<artifactId>pippo-jackson</artifactId>
|
||||||
|
<version>${pippo.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ro.pippo</groupId>
|
||||||
|
<artifactId>pippo-session-cookie</artifactId>
|
||||||
|
<version>${pippo.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ro.pippo</groupId>
|
||||||
|
<artifactId>pippo-jetty</artifactId>
|
||||||
|
<version>${pippo.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-simple</artifactId>
|
||||||
|
<version>1.7.13</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>6.0.6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>fastjson</artifactId>
|
||||||
|
<version>1.2.37</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-stdlib-jre8</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>druid</artifactId>
|
||||||
|
<version>1.1.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-maven-plugin</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>compile</id>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>compile</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>test-compile</id>
|
||||||
|
<phase>test-compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>test-compile</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<jvmTarget>1.8</jvmTarget>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>verify</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-dependencies</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
||||||
|
<includeScope>runtime</includeScope>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
import ro.pippo.controller.ControllerApplication
|
||||||
|
import ro.pippo.core.Pippo
|
||||||
|
import ro.pippo.core.RequestResponseFactory
|
||||||
|
import ro.pippo.session.SessionManager
|
||||||
|
import ro.pippo.session.SessionRequestResponseFactory
|
||||||
|
import ro.pippo.session.cookie.CookieSessionDataStorage
|
||||||
|
import route.*
|
||||||
|
|
||||||
|
|
||||||
|
object Main {
|
||||||
|
@JvmStatic
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
val pippo = Pippo(BasicApplication())
|
||||||
|
pippo.start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class BasicApplication : ControllerApplication() {
|
||||||
|
private val log = LoggerFactory.getLogger(BasicApplication::class.java)
|
||||||
|
|
||||||
|
override fun onInit() {
|
||||||
|
getRouter().ignorePaths("/favicon.ico")
|
||||||
|
|
||||||
|
// send files from a local folder (try a request like 'src/main/java/ro/pippo/demo/basic/BasicApplication.java')
|
||||||
|
addFileResourceRoute("/src", "src")
|
||||||
|
|
||||||
|
// register a custom ExceptionHandler
|
||||||
|
errorHandler.setExceptionHandler(ForbiddenException::class.java) { e, routeContext ->
|
||||||
|
log.info("Called custom exception handler")
|
||||||
|
routeContext.setLocal<String>("message", e.message)
|
||||||
|
errorHandler.handle(403, routeContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
// register a request logger
|
||||||
|
routePreDispatchListeners.add { request, _ ->
|
||||||
|
println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
|
||||||
|
println("requestPath = " + request.path)
|
||||||
|
println("requestUri = " + request.uri)
|
||||||
|
println("requestUrl = " + request.url)
|
||||||
|
println("contextPath = " + request.contextPath)
|
||||||
|
println("applicationPath = " + request.applicationPath)
|
||||||
|
println("applicationUri = " + request.applicationUri)
|
||||||
|
println("applicationUriWithQuery = " + request.applicationUriWithQuery)
|
||||||
|
println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
|
||||||
|
}
|
||||||
|
|
||||||
|
addControllers(CtrlUser::class.java)
|
||||||
|
addControllers(CrtlGroup::class.java)
|
||||||
|
addControllers(CtrlMenu::class.java)
|
||||||
|
addControllers(CtrlPerm::class.java)
|
||||||
|
addControllers(CtrlRole::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createRequestResponseFactory(): RequestResponseFactory {
|
||||||
|
val sessionDataStorage = CookieSessionDataStorage(pippoSettings)
|
||||||
|
val sessionManager = SessionManager(sessionDataStorage)
|
||||||
|
|
||||||
|
return SessionRequestResponseFactory(this, sessionManager)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ForbiddenException(message: String) : RuntimeException(message)
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
package config
|
||||||
|
|
||||||
|
object Const {
|
||||||
|
val codeSuccess = 200
|
||||||
|
val codeInvalidParams = 400
|
||||||
|
val codeResourceNotFound = 404
|
||||||
|
val codeServiceOperationFailed = 500
|
||||||
|
|
||||||
|
val msgEmptyMsg = ""
|
||||||
|
val msgNotFoundById = "根据id没有找到对应资源"
|
||||||
|
val msgInsertUserFailed = "新增用户失败,请检查参数,或许已有相同用户存在"
|
||||||
|
val msgUpdateUserFailed = "更新用户信息失败"
|
||||||
|
val msgPasswdIsRequired = "密码不能为空"
|
||||||
|
val msgOperationFailed = "操作失败"
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package model
|
||||||
|
|
||||||
|
import java.sql.Timestamp
|
||||||
|
|
||||||
|
class ModelUser(val id: Int?, var name: 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class ModelGroup(val id: Int?, val desc: String, val createTime: Timestamp?) {
|
||||||
|
constructor() : this(null, "", null)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class ModelPerm(val id: Int?, val desc: String?, val perm: String?, val createTime: Timestamp?) {
|
||||||
|
constructor():this(null,null,null,null)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class ModelMenu(val id: Int?, val desc: String?, val url: String?, val permId: Int?, val createTime: Timestamp?) {
|
||||||
|
constructor():this(null,null,null,null,null)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class ModelRole(val id: Int?, val desc: String?, val createTime: Timestamp?){
|
||||||
|
constructor():this(null,null,null)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
package model
|
||||||
|
|
||||||
|
data class JSONResponse(val code: Int, val msg: String, val result: Any?)
|
||||||
|
|
@ -0,0 +1,83 @@
|
||||||
|
package route
|
||||||
|
|
||||||
|
import config.Const
|
||||||
|
import model.JSONResponse
|
||||||
|
import model.ModelGroup
|
||||||
|
import ro.pippo.controller.*
|
||||||
|
import ro.pippo.controller.extractor.Param
|
||||||
|
import service.Service
|
||||||
|
import util.responseInvalidParams
|
||||||
|
import util.responseNotFoundById
|
||||||
|
import util.responseOperationFailed
|
||||||
|
import util.responseSuccess
|
||||||
|
|
||||||
|
@Path("/group")
|
||||||
|
class CrtlGroup : Controller() {
|
||||||
|
private val service: Service = Service()
|
||||||
|
|
||||||
|
@GET("/{userId: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun getGroupByUser(@Param userId: Int): JSONResponse {
|
||||||
|
val user = service.getUserById(userId)
|
||||||
|
|
||||||
|
return if (user == null) {
|
||||||
|
responseNotFoundById()
|
||||||
|
} else {
|
||||||
|
val group = service.getGroupByUserId(userId)
|
||||||
|
if (group == null) {
|
||||||
|
JSONResponse(Const.codeResourceNotFound, "用户没有绑定角色", null)
|
||||||
|
} else {
|
||||||
|
responseSuccess(group)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun addGroup(): JSONResponse {
|
||||||
|
val group: ModelGroup? = request.createEntityFromBody(ModelGroup::class.java)
|
||||||
|
if (group == null) {
|
||||||
|
return responseInvalidParams()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSuccess = service.saveGroup(group)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(isSuccess)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/{groupId: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun updateGroup(@Param groupId: Int): JSONResponse {
|
||||||
|
val group: ModelGroup? = request.createEntityFromBody(ModelGroup::class.java)
|
||||||
|
if (group == null) {
|
||||||
|
return responseInvalidParams()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSuccess = service.updateGroup(group)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(group)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/del/{id: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun delGroup(@Param id: Int): JSONResponse {
|
||||||
|
val group = service.getGroupById(id)
|
||||||
|
|
||||||
|
if (group == null) {
|
||||||
|
responseNotFoundById()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSuccess = service.deleteGroup(id)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(id)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,123 @@
|
||||||
|
package route
|
||||||
|
|
||||||
|
import model.JSONResponse
|
||||||
|
import model.ModelMenu
|
||||||
|
import ro.pippo.controller.*
|
||||||
|
import ro.pippo.controller.extractor.Param
|
||||||
|
import service.Service
|
||||||
|
import util.responseInvalidParams
|
||||||
|
import util.responseNotFoundById
|
||||||
|
import util.responseOperationFailed
|
||||||
|
import util.responseSuccess
|
||||||
|
|
||||||
|
@Path("/menu")
|
||||||
|
class CtrlMenu : Controller() {
|
||||||
|
private val service = Service()
|
||||||
|
|
||||||
|
@GET("/{id: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun getMenuById(@Param id: Int): JSONResponse {
|
||||||
|
val menu = service.getMenuById(id)
|
||||||
|
if (menu == null) {
|
||||||
|
return responseNotFoundById()
|
||||||
|
}
|
||||||
|
|
||||||
|
return responseSuccess(menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET("/byRole/{roleId: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun getMenuByRole(@Param roleId: Int): JSONResponse {
|
||||||
|
val role = service.getRoleById(roleId)
|
||||||
|
if (role == null) {
|
||||||
|
return responseNotFoundById()
|
||||||
|
}
|
||||||
|
|
||||||
|
val menus = service.getMenuByRole(roleId)
|
||||||
|
return responseSuccess(menus)
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun addMenu(): JSONResponse {
|
||||||
|
val menu: ModelMenu? = request.createEntityFromBody(ModelMenu::class.java)
|
||||||
|
if (menu == null) {
|
||||||
|
return responseInvalidParams()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSuccess = service.saveMenu(menu)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(menu)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/{id: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun updateMenu(@Param id: Int): JSONResponse {
|
||||||
|
val menu: ModelMenu? = request.createEntityFromBody(ModelMenu::class.java)
|
||||||
|
if (menu == null) {
|
||||||
|
return responseInvalidParams()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSuccess = service.updateMenu(menu)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(menu)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/del/{id: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun deleteMenu(@Param id: Int): JSONResponse {
|
||||||
|
val menu = service.getMenuById(id)
|
||||||
|
if (menu == null) {
|
||||||
|
return responseNotFoundById()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSuccess = service.deleteMenu(id)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(id)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/bindPerm/{menuId: [0-9]+}/{permId: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun bindMenuToPerm(@Param menuId: Int, @Param permId: Int): JSONResponse {
|
||||||
|
val menu = service.getMenuById(menuId)
|
||||||
|
val perm = service.getPermById(permId)
|
||||||
|
|
||||||
|
if (menu == null || perm == null) {
|
||||||
|
return responseNotFoundById()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSuccess = service.bindMenuToPerm(menuId, permId)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(true)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/unbindPerm/{menuId: [0-9]+}/{permId: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun unbindMenuToPerm(@Param menuId: Int, @Param permId: Int): JSONResponse {
|
||||||
|
val menu = service.getMenuById(menuId)
|
||||||
|
val perm = service.getPermById(permId)
|
||||||
|
|
||||||
|
if (menu == null || perm == null) {
|
||||||
|
return responseNotFoundById()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSuccess = service.unbindMenuToPerm(menuId, permId)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(true)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,123 @@
|
||||||
|
package route
|
||||||
|
|
||||||
|
import model.JSONResponse
|
||||||
|
import model.ModelPerm
|
||||||
|
import ro.pippo.controller.*
|
||||||
|
import ro.pippo.controller.extractor.Param
|
||||||
|
import service.Service
|
||||||
|
import util.responseInvalidParams
|
||||||
|
import util.responseNotFoundById
|
||||||
|
import util.responseOperationFailed
|
||||||
|
import util.responseSuccess
|
||||||
|
|
||||||
|
@Path("/perm")
|
||||||
|
class CtrlPerm : Controller() {
|
||||||
|
private val service = Service()
|
||||||
|
|
||||||
|
@GET("/{id: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun getPermById(@Param id: Int): JSONResponse {
|
||||||
|
val perm = service.getPermById(id)
|
||||||
|
return if (perm == null) {
|
||||||
|
responseNotFoundById()
|
||||||
|
} else {
|
||||||
|
responseSuccess(perm)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/byRole/{roleId: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun getPermByRoleId(@Param roleId: Int): JSONResponse {
|
||||||
|
val role = service.getRoleById(roleId)
|
||||||
|
if (role == null) {
|
||||||
|
return responseNotFoundById()
|
||||||
|
}
|
||||||
|
|
||||||
|
val perms = service.getPermByRoleId(roleId)
|
||||||
|
return responseSuccess(perms)
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun addPerm(): JSONResponse {
|
||||||
|
val perm: ModelPerm? = request.createEntityFromBody(ModelPerm::class.java)
|
||||||
|
if (perm == null) {
|
||||||
|
return responseInvalidParams()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSuccess = service.savePerm(perm)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(perm)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/{id: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun updatePerm(): JSONResponse {
|
||||||
|
val perm: ModelPerm? = request.createEntityFromBody(ModelPerm::class.java)
|
||||||
|
if (perm == null) {
|
||||||
|
return responseInvalidParams()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSuccess = service.updatePerm(perm)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(perm)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/del/{id: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun deletePerm(@Param id: Int): JSONResponse {
|
||||||
|
val perm = service.getPermById(id)
|
||||||
|
if (perm == null) {
|
||||||
|
return responseNotFoundById()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSuccess = service.deletePerm(id)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(id)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/bindRole/{permId: [0-9]+}/{roleId: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun bindPermToRole(@Param permId: Int,@Param roleId: Int): JSONResponse {
|
||||||
|
val perm = service.getPermById(permId)
|
||||||
|
val role = service.getRoleById(roleId)
|
||||||
|
|
||||||
|
if (perm == null || role == null) {
|
||||||
|
return responseNotFoundById()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSuccess = service.bindPermToRole(permId, roleId)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(true)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/unbindRole/{permId: [0-9]+}/{roleId: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun unbindPermToRole(@Param permId: Int,@Param roleId: Int): JSONResponse {
|
||||||
|
val perm = service.getPermById(permId)
|
||||||
|
val role = service.getRoleById(roleId)
|
||||||
|
|
||||||
|
if (perm == null || role == null) {
|
||||||
|
return responseNotFoundById()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSuccess = service.unbindPermToRole(permId, roleId)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(true)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,91 @@
|
||||||
|
package route
|
||||||
|
|
||||||
|
import model.JSONResponse
|
||||||
|
import model.ModelRole
|
||||||
|
import ro.pippo.controller.*
|
||||||
|
import ro.pippo.controller.extractor.Param
|
||||||
|
import service.Service
|
||||||
|
import util.responseInvalidParams
|
||||||
|
import util.responseNotFoundById
|
||||||
|
import util.responseOperationFailed
|
||||||
|
import util.responseSuccess
|
||||||
|
|
||||||
|
@Path("/role")
|
||||||
|
class CtrlRole : Controller() {
|
||||||
|
val service = Service()
|
||||||
|
|
||||||
|
@GET("/{id: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun getRoleById(@Param id: Int): JSONResponse {
|
||||||
|
val role = service.getRoleById(id)
|
||||||
|
if (role == null) {
|
||||||
|
return responseNotFoundById()
|
||||||
|
}
|
||||||
|
|
||||||
|
return responseSuccess(role)
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET("/byUserId/{userId: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun getRoleByUserId(@Param userId: Int): JSONResponse {
|
||||||
|
val user = service.getUserById(userId)
|
||||||
|
if (user == null) {
|
||||||
|
return responseNotFoundById()
|
||||||
|
}
|
||||||
|
|
||||||
|
val role = service.getRoleByUserId(userId)
|
||||||
|
if (role == null) {
|
||||||
|
return responseNotFoundById()
|
||||||
|
}
|
||||||
|
|
||||||
|
return responseSuccess(role)
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun addRole(): JSONResponse {
|
||||||
|
val role: ModelRole? = request.createEntityFromBody(ModelRole::class.java)
|
||||||
|
if (role == null) {
|
||||||
|
return responseInvalidParams()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSuccess = service.saveRole(role)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(role)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/del/{id: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun delRole(@Param roleId: Int): JSONResponse {
|
||||||
|
val role = service.getRoleById(roleId)
|
||||||
|
if (role == null) {
|
||||||
|
responseNotFoundById()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSuccess = service.deleteRole(roleId)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(roleId)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/{id: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun updateRole():JSONResponse {
|
||||||
|
val role: ModelRole? = request.createEntityFromBody(ModelRole::class.java)
|
||||||
|
if (role == null) {
|
||||||
|
return responseNotFoundById()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSuccess = service.updateRole(role)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(role)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,177 @@
|
||||||
|
package route
|
||||||
|
|
||||||
|
import model.JSONResponse
|
||||||
|
import model.ModelUser
|
||||||
|
import ro.pippo.controller.*
|
||||||
|
import ro.pippo.controller.extractor.Param
|
||||||
|
import service.Service
|
||||||
|
import util.responseInvalidParams
|
||||||
|
import util.responseNotFoundById
|
||||||
|
import util.responseOperationFailed
|
||||||
|
import util.responseSuccess
|
||||||
|
|
||||||
|
|
||||||
|
@Path("/user")
|
||||||
|
class CtrlUser : Controller() {
|
||||||
|
private val service = Service()
|
||||||
|
|
||||||
|
@GET("/{id: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun getUserById(@Param("id") id: Int): JSONResponse {
|
||||||
|
val user = service.getUserById(id)
|
||||||
|
|
||||||
|
return if (user == null) {
|
||||||
|
responseNotFoundById()
|
||||||
|
} else {
|
||||||
|
user.passwd = ""
|
||||||
|
responseSuccess(user)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun addUser(): JSONResponse {
|
||||||
|
val user: ModelUser? = request.createEntityFromParameters(ModelUser::class.java)
|
||||||
|
if (user == null) {
|
||||||
|
return responseInvalidParams()
|
||||||
|
}
|
||||||
|
val isSuccess = service.saveUser(user)
|
||||||
|
return if (isSuccess) {
|
||||||
|
user.passwd = ""
|
||||||
|
responseSuccess(user)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/{id: [0-9]+}/{name}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun updateUserName(@Param("id") id: Int, @Param("name") name: String): JSONResponse {
|
||||||
|
val user = service.getUserById(id)
|
||||||
|
|
||||||
|
return if (user == null) {
|
||||||
|
responseNotFoundById()
|
||||||
|
} else {
|
||||||
|
user.name = name
|
||||||
|
val isSuccess = service.updateUser(user)
|
||||||
|
if (isSuccess) {
|
||||||
|
user.passwd = ""
|
||||||
|
responseSuccess(user)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/del/{id: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun delUser(@Param("id") id: Int): JSONResponse {
|
||||||
|
val user = service.getUserById(id)
|
||||||
|
|
||||||
|
if (user == null) {
|
||||||
|
return responseNotFoundById()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSuccess = service.deleteUser(id)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(id)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/passwd/{id: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun changePasswd(@Param("id") id: Int): JSONResponse {
|
||||||
|
val passwd = request.queryParameters["passwd"]?.toString()
|
||||||
|
if (passwd == null) {
|
||||||
|
return responseInvalidParams()
|
||||||
|
}
|
||||||
|
|
||||||
|
val user = service.getUserById(id)
|
||||||
|
|
||||||
|
return if (user == null) {
|
||||||
|
responseNotFoundById()
|
||||||
|
} else {
|
||||||
|
val isSuccess = service.changePasswd(user, passwd!!)
|
||||||
|
if (isSuccess) {
|
||||||
|
responseSuccess(true)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/bindGroup/{userId: [0-9]+}/{groupId: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun bindGroup(@Param("userId") userId: Int, @Param("groupId") groupId: Int): JSONResponse {
|
||||||
|
val user = service.getUserById(userId)
|
||||||
|
val group = service.getGroupById(groupId)
|
||||||
|
|
||||||
|
if (user == null || group == null) {
|
||||||
|
return responseNotFoundById()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSuccess = service.bindUserToGroup(userId, groupId)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(true)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/unbindGroup/{userId: [0-9]+}/{groupId: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun unbindGroup(@Param("userId") userId: Int, @Param("groupId") groupId: Int): JSONResponse {
|
||||||
|
val user = service.getUserById(userId)
|
||||||
|
val group = service.getGroupById(groupId)
|
||||||
|
|
||||||
|
if (user == null || group == null) {
|
||||||
|
return responseNotFoundById()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSuccess = service.unbindUserToGroup(userId, groupId)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(true)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/bindRole/{userId: [0-9]+}/{roleId: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun bindRole(@Param("userId") userId: Int, @Param("roleId") roleId: Int): JSONResponse {
|
||||||
|
val user = service.getUserById(userId)
|
||||||
|
val role = service.getRoleById(roleId)
|
||||||
|
|
||||||
|
if (user == null || role == null) {
|
||||||
|
return responseNotFoundById()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSuccess = service.bindUserToRole(userId, roleId)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(true)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST("/unbindRole/{userId: [0-9]+}/{roleId: [0-9]+}")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun unbindRole(@Param("userId") userId: Int, @Param("roleId") roleId: Int): JSONResponse {
|
||||||
|
val user = service.getUserById(userId)
|
||||||
|
val role = service.getRoleById(roleId)
|
||||||
|
|
||||||
|
if (user == null || role == null) {
|
||||||
|
return responseNotFoundById()
|
||||||
|
}
|
||||||
|
|
||||||
|
val isSuccess = service.unbindUserToRole(userId, roleId)
|
||||||
|
return if (isSuccess) {
|
||||||
|
responseSuccess(true)
|
||||||
|
} else {
|
||||||
|
responseOperationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,265 @@
|
||||||
|
package service
|
||||||
|
|
||||||
|
import model.*
|
||||||
|
import sun.reflect.generics.reflectiveObjects.NotImplementedException
|
||||||
|
import util.*
|
||||||
|
|
||||||
|
class Service {
|
||||||
|
fun getUserById(id: Int): ModelUser? {
|
||||||
|
val rs = DBUtil.getConnection().createStatement()
|
||||||
|
.executeQuery("select * from `user` where id=$id")
|
||||||
|
|
||||||
|
return if (rs.next()) {
|
||||||
|
return rsToUser(rs)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun saveUser(user: ModelUser): Boolean {
|
||||||
|
try {
|
||||||
|
DBUtil.getConnection().createStatement()
|
||||||
|
.executeUpdate(userToInsertSQL(user))
|
||||||
|
return true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateUser(user: ModelUser): Boolean {
|
||||||
|
throw NotImplementedException()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deleteUser(userId: Int): Boolean {
|
||||||
|
return DBUtil.getConnection().createStatement()
|
||||||
|
.executeUpdate("delete from `user` where id=$userId") > 1
|
||||||
|
}
|
||||||
|
|
||||||
|
fun changePasswd(user: ModelUser, passwd: String): Boolean {
|
||||||
|
throw NotImplementedException()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getGroupByUserId(userId: Int): ModelGroup? {
|
||||||
|
val user = getUserById(userId)
|
||||||
|
if (user == null) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
val rs = DBUtil.getConnection().createStatement()
|
||||||
|
.executeQuery("select * from `group` where id=${user.groupId}")
|
||||||
|
return if (rs.next()) {
|
||||||
|
return rsToGroup(rs)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun saveGroup(group: ModelGroup): Boolean {
|
||||||
|
try {
|
||||||
|
DBUtil.getConnection().createStatement()
|
||||||
|
.execute(groupToInsertSQL(group))
|
||||||
|
return true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
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 {
|
||||||
|
val user = getUserById(userId)
|
||||||
|
if (user == null) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return DBUtil.getConnection().createStatement()
|
||||||
|
.execute("update `user` set groupId=$groupId where id=$userId")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun unbindUserToGroup(userId: Int, groupId: Int): Boolean {
|
||||||
|
return DBUtil.getConnection().createStatement()
|
||||||
|
.execute("update `user` set groupId=-1 where id=$userId")
|
||||||
|
}
|
||||||
|
|
||||||
|
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? {
|
||||||
|
val user = getUserById(userId)
|
||||||
|
if (user == null) {
|
||||||
|
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 {
|
||||||
|
try {
|
||||||
|
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 {
|
||||||
|
val user = getUserById(userId)
|
||||||
|
if (user == null) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return DBUtil.getConnection().createStatement()
|
||||||
|
.execute("update `user` set roleId=$roleId where id=$userId")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun unbindUserToRole(userId: Int, roleId: Int): Boolean {
|
||||||
|
val user = getUserById(userId)
|
||||||
|
if (user == null) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
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> {
|
||||||
|
//todo join
|
||||||
|
throw NotImplementedException()
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
val perm = getPermById(permId)
|
||||||
|
val role = getRoleById(roleId)
|
||||||
|
if (perm == null || role == null) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return DBUtil.getConnection().createStatement()
|
||||||
|
.execute("insert into mapping_perm_role($permId,$roleId)")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun unbindPermToRole(permId: Int, roleId: Int): Boolean {
|
||||||
|
return DBUtil.getConnection().createStatement()
|
||||||
|
.executeUpdate("delete from mapping_perm_role where permId=$permId and roleId=$roleId)") > 1
|
||||||
|
}
|
||||||
|
|
||||||
|
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> {
|
||||||
|
//todo join
|
||||||
|
throw NotImplementedException()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun saveMenu(menu: ModelMenu): Boolean {
|
||||||
|
try {
|
||||||
|
DBUtil.getConnection().createStatement()
|
||||||
|
.execute(menuToInsertSQL(menu))
|
||||||
|
return true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateMenu(menu: ModelMenu): Boolean {
|
||||||
|
throw NotImplementedException()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deleteMenu(menuId: Int): Boolean {
|
||||||
|
return DBUtil.getConnection().createStatement()
|
||||||
|
.executeUpdate("delete from `menu` where id=$menuId") > 1
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bindMenuToPerm(menuId: Int, permId: Int): Boolean {
|
||||||
|
val menu = getMenuById(menuId)
|
||||||
|
if (menu == null) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return DBUtil.getConnection().createStatement()
|
||||||
|
.execute("update `menu` set permId=$permId where id=$menuId")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun unbindMenuToPerm(menuId: Int, permId: Int): Boolean {
|
||||||
|
return DBUtil.getConnection().createStatement()
|
||||||
|
.execute("update `menu` set permId=-1 where id=$menuId")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package util
|
||||||
|
|
||||||
|
import com.alibaba.druid.pool.DruidDataSource
|
||||||
|
import com.alibaba.druid.pool.DruidPooledConnection
|
||||||
|
|
||||||
|
|
||||||
|
object DBUtil {
|
||||||
|
private val druidDataSource: DruidDataSource = DruidDataSource()
|
||||||
|
|
||||||
|
init {
|
||||||
|
druidDataSource.url = "jdbc:mysql://rm-wz9n28sq10rz5b0u2o.mysql.rds.aliyuncs.com:3306/sh-upgram"
|
||||||
|
druidDataSource.driverClassName = "com.mysql.cj.jdbc.Driver"
|
||||||
|
druidDataSource.username = "shzhyjxy"
|
||||||
|
druidDataSource.password = "Admin111"
|
||||||
|
druidDataSource.maxActive = 20
|
||||||
|
druidDataSource.initialSize = 1
|
||||||
|
druidDataSource.maxWait = 30 * 1000
|
||||||
|
druidDataSource.minIdle = 1
|
||||||
|
druidDataSource.timeBetweenEvictionRunsMillis = 60000
|
||||||
|
druidDataSource.minEvictableIdleTimeMillis = 300000
|
||||||
|
druidDataSource.validationQuery = "select 'x'"
|
||||||
|
druidDataSource.isTestWhileIdle = true
|
||||||
|
druidDataSource.isTestOnBorrow = true
|
||||||
|
druidDataSource.isTestOnReturn = true
|
||||||
|
druidDataSource.isPoolPreparedStatements = true
|
||||||
|
druidDataSource.maxOpenPreparedStatements = 20
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getConnection(): DruidPooledConnection {
|
||||||
|
return druidDataSource.connection
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,105 @@
|
||||||
|
package util
|
||||||
|
|
||||||
|
import config.Const
|
||||||
|
import model.*
|
||||||
|
import ro.pippo.core.Request
|
||||||
|
import java.sql.ResultSet
|
||||||
|
import java.sql.Timestamp
|
||||||
|
import java.time.Instant
|
||||||
|
|
||||||
|
fun responseNotFoundById(): JSONResponse {
|
||||||
|
return JSONResponse(Const.codeResourceNotFound, Const.msgNotFoundById, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun responseOperationFailed(): JSONResponse {
|
||||||
|
return JSONResponse(Const.codeServiceOperationFailed, Const.msgOperationFailed, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun responseInvalidParams(): JSONResponse {
|
||||||
|
return JSONResponse(Const.codeInvalidParams, Const.msgPasswdIsRequired, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun responseSuccess(result: Any): JSONResponse {
|
||||||
|
return JSONResponse(Const.codeSuccess, Const.msgEmptyMsg, result)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun rsToUser(rs: ResultSet): ModelUser {
|
||||||
|
return ModelUser(
|
||||||
|
id = rs.getInt("id"),
|
||||||
|
name = rs.getString("name"),
|
||||||
|
passwd = rs.getString("passwd"),
|
||||||
|
groupId = rs.getInt("groupId"),
|
||||||
|
roleId = rs.getInt("roleId"),
|
||||||
|
createTime = rs.getTimestamp("createTime")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
return ModelGroup(
|
||||||
|
id = rs.getInt("id"),
|
||||||
|
desc = rs.getString("desc"),
|
||||||
|
createTime = rs.getTimestamp("createTime")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun groupToInsertSQL(group: ModelGroup): String {
|
||||||
|
return """
|
||||||
|
insert into `group`(desc,createTime)
|
||||||
|
values('${group.desc}','${Timestamp.from(Instant.now())}')
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
|
||||||
|
fun rsToRole(rs: ResultSet): ModelRole {
|
||||||
|
return ModelRole(
|
||||||
|
id = rs.getInt("id"),
|
||||||
|
desc = rs.getString("desc"),
|
||||||
|
createTime = rs.getTimestamp("createTime")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun roleToInsertSQL(role: ModelRole): String {
|
||||||
|
return """
|
||||||
|
insert into `role`(desc,createTime)
|
||||||
|
values('${role.desc}','${Timestamp.from(Instant.now())}')
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
|
||||||
|
fun rsToPerm(rs: ResultSet): ModelPerm {
|
||||||
|
return ModelPerm(
|
||||||
|
id = rs.getInt("id"),
|
||||||
|
desc = rs.getString("desc"),
|
||||||
|
perm = rs.getString("perm"),
|
||||||
|
createTime = rs.getTimestamp("createTime")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun permToInsertSQL(perm: ModelPerm): String {
|
||||||
|
return """
|
||||||
|
insert into `role`(desc,perm,createTime)
|
||||||
|
values('${perm.desc}','${perm.perm}','${Timestamp.from(Instant.now())}')
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
|
||||||
|
fun rsToMenu(rs: ResultSet): ModelMenu {
|
||||||
|
return ModelMenu(
|
||||||
|
id = rs.getInt("id"),
|
||||||
|
desc = rs.getString("desc"),
|
||||||
|
url = rs.getString("url"),
|
||||||
|
permId = rs.getInt("permId"),
|
||||||
|
createTime = rs.getTimestamp("createTime")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun menuToInsertSQL(menu: ModelMenu): String {
|
||||||
|
return """
|
||||||
|
insert into `role`(desc,url,permId,createTime)
|
||||||
|
values('${menu.desc}','${menu.desc}','${menu.permId}','${Timestamp.from(Instant.now())}')
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
application.languages=zh_CN
|
||||||
|
# Control the port that Pippo binds
|
||||||
|
server.port = 8338
|
||||||
|
|
||||||
|
# Control the network ip address Pippo binds
|
||||||
|
# Specify 0.0.0.0 for all available interfaces
|
||||||
|
server.host = localhost
|
||||||
|
|
||||||
|
# Specify the context path of the application
|
||||||
|
server.contextPath = /
|
||||||
Loading…
Reference in New Issue