2017-09-25 10:06:58 +08:00
|
|
|
package route
|
|
|
|
|
|
2017-09-27 15:52:50 +08:00
|
|
|
import com.jfinal.kit.JsonKit
|
2017-09-29 15:35:20 +08:00
|
|
|
import com.jfinal.plugin.activerecord.Db
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record
|
2017-09-25 10:06:58 +08:00
|
|
|
import model.JSONResponse
|
|
|
|
|
import model.ModelMenu
|
2017-09-28 14:15:18 +08:00
|
|
|
import model.ModelMenu2
|
2017-09-25 10:06:58 +08:00
|
|
|
import ro.pippo.controller.*
|
|
|
|
|
import ro.pippo.controller.extractor.Param
|
|
|
|
|
import service.Service
|
2017-09-29 15:35:20 +08:00
|
|
|
import util.*
|
2017-09-28 14:15:18 +08:00
|
|
|
import java.util.*
|
2017-09-25 10:06:58 +08:00
|
|
|
|
|
|
|
|
@Path("/menu")
|
|
|
|
|
class CtrlMenu : Controller() {
|
|
|
|
|
private val service = Service()
|
|
|
|
|
|
|
|
|
|
@GET("/{id: [0-9]+}")
|
|
|
|
|
@Produces(Produces.JSON)
|
2017-09-25 11:56:47 +08:00
|
|
|
fun getMenuById(@Param("id") id: Int): JSONResponse {
|
2017-09-25 10:06:58 +08:00
|
|
|
val menu = service.getMenuById(id)
|
|
|
|
|
if (menu == null) {
|
|
|
|
|
return responseNotFoundById()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return responseSuccess(menu)
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-26 00:42:38 +08:00
|
|
|
@GET("/{page: [0-9]+}/{size: [0-9]+}")
|
|
|
|
|
@Produces(Produces.JSON)
|
2017-09-27 15:52:50 +08:00
|
|
|
fun pagi(@Param("page") num:Int, @Param("size") size:Int) :String {
|
|
|
|
|
val page = service.pagiMenu(num,size)
|
|
|
|
|
return JsonKit.toJson(responseSuccess(page))
|
2017-09-26 00:42:38 +08:00
|
|
|
}
|
|
|
|
|
|
2017-09-25 10:06:58 +08:00
|
|
|
@GET("/byRole/{roleId: [0-9]+}")
|
|
|
|
|
@Produces(Produces.JSON)
|
2017-09-25 11:56:47 +08:00
|
|
|
fun getMenuByRole(@Param("roleId") roleId: Int): JSONResponse {
|
2017-09-25 10:06:58 +08:00
|
|
|
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 {
|
2017-09-25 11:56:47 +08:00
|
|
|
val menu: ModelMenu? = request.createEntityFromParameters(ModelMenu::class.java)
|
2017-09-25 10:06:58 +08:00
|
|
|
if (menu == null) {
|
|
|
|
|
return responseInvalidParams()
|
|
|
|
|
}
|
2017-09-28 14:15:18 +08:00
|
|
|
val menu2 = ModelMenu2()
|
|
|
|
|
menu2.put("description", menu.description)
|
|
|
|
|
menu2.put("url", menu.url)
|
|
|
|
|
menu2.put("permId", menu.permId)
|
|
|
|
|
menu2.put("createTime", Date())
|
|
|
|
|
val isSuccess = menu2.save()
|
2017-09-25 10:06:58 +08:00
|
|
|
return if (isSuccess) {
|
2017-09-28 14:15:18 +08:00
|
|
|
responseSuccess(menu2)
|
2017-09-25 10:06:58 +08:00
|
|
|
} else {
|
|
|
|
|
responseOperationFailed()
|
|
|
|
|
}
|
2017-09-28 14:15:18 +08:00
|
|
|
|
|
|
|
|
// val isSuccess = service.saveMenu(menu)
|
|
|
|
|
// return if (isSuccess) {
|
|
|
|
|
// responseSuccess(menu)
|
|
|
|
|
// } else {
|
|
|
|
|
// responseOperationFailed()
|
|
|
|
|
// }
|
2017-09-25 10:06:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@POST("/{id: [0-9]+}")
|
|
|
|
|
@Produces(Produces.JSON)
|
2017-09-25 11:56:47 +08:00
|
|
|
fun updateMenu(@Param("id") id: Int): JSONResponse {
|
2017-09-27 18:06:35 +08:00
|
|
|
val menu: ModelMenu? = request.createEntityFromParameters(ModelMenu::class.java)
|
2017-09-25 10:06:58 +08:00
|
|
|
if (menu == null) {
|
|
|
|
|
return responseInvalidParams()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val isSuccess = service.updateMenu(menu)
|
|
|
|
|
return if (isSuccess) {
|
|
|
|
|
responseSuccess(menu)
|
|
|
|
|
} else {
|
|
|
|
|
responseOperationFailed()
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-29 15:35:20 +08:00
|
|
|
//更新
|
|
|
|
|
@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()
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-25 10:06:58 +08:00
|
|
|
@POST("/del/{id: [0-9]+}")
|
|
|
|
|
@Produces(Produces.JSON)
|
2017-09-25 11:56:47 +08:00
|
|
|
fun deleteMenu(@Param("id") id: Int): JSONResponse {
|
2017-09-25 10:06:58 +08:00
|
|
|
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)
|
2017-09-25 11:56:47 +08:00
|
|
|
fun bindMenuToPerm(@Param("menuId") menuId: Int, @Param("permId") permId: Int): JSONResponse {
|
2017-09-25 10:06:58 +08:00
|
|
|
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)
|
2017-09-25 11:56:47 +08:00
|
|
|
fun unbindMenuToPerm(@Param("menuId") menuId: Int, @Param("permId") permId: Int): JSONResponse {
|
2017-09-25 10:06:58 +08:00
|
|
|
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()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|