修复bindMenu ,增加修改User操作
parent
16ecab1ae0
commit
a73bec5a13
|
|
@ -1,6 +1,7 @@
|
||||||
import com.jfinal.plugin.activerecord.ActiveRecordPlugin
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin
|
||||||
import com.jfinal.plugin.druid.DruidPlugin
|
import com.jfinal.plugin.druid.DruidPlugin
|
||||||
import model.ModelMenu2
|
import model.ModelMenu2
|
||||||
|
import model.ModelUser2
|
||||||
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
|
||||||
|
|
@ -64,6 +65,7 @@ class BasicApplication : ControllerApplication() {
|
||||||
"Admin111")
|
"Admin111")
|
||||||
val arp = ActiveRecordPlugin(dp)
|
val arp = ActiveRecordPlugin(dp)
|
||||||
arp.addMapping("menu", ModelMenu2::class.java)
|
arp.addMapping("menu", ModelMenu2::class.java)
|
||||||
|
arp.addMapping("user", ModelUser2::class.java)
|
||||||
dp.start()
|
dp.start()
|
||||||
arp.start()
|
arp.start()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,11 @@ class ModelMenu2() : Model<ModelMenu2>() {
|
||||||
val DAO: ModelMenu2 = ModelMenu2()
|
val DAO: ModelMenu2 = ModelMenu2()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
class ModelUser2() : Model<ModelUser2>() {
|
||||||
|
companion object {
|
||||||
|
val DAO: ModelUser2 = ModelUser2()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
constructor() : this(null, null, null)
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
package route
|
package route
|
||||||
|
|
||||||
import com.jfinal.kit.JsonKit
|
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.ModelUser
|
import model.ModelUser
|
||||||
|
import model.ModelUser2
|
||||||
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.sql.Timestamp
|
||||||
import util.responseOperationFailed
|
|
||||||
import util.responseSuccess
|
|
||||||
|
|
||||||
|
|
||||||
@Path("/user")
|
@Path("/user")
|
||||||
|
|
@ -70,7 +71,40 @@ class CtrlUser : Controller() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//更新 User
|
||||||
|
@POST("/update")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun updateUser() :JSONResponse{
|
||||||
|
if (request.parameters["id"] != null) {
|
||||||
|
val record = Record()
|
||||||
|
if ( null != request.parameters["id"] ) {
|
||||||
|
record.set("id", request.parameters["id"]?.toInt())
|
||||||
|
}
|
||||||
|
if ( null != request.parameters["name"] ) {
|
||||||
|
record.set("name", request.parameters["name"]?.toString())
|
||||||
|
}
|
||||||
|
if (null != request.parameters["passwd"] ) {
|
||||||
|
record.set("passwd", request.parameters["passwd"]?.toString())
|
||||||
|
}
|
||||||
|
if ( null != request.parameters["groupId"] ) {
|
||||||
|
record.set("groupId", request.parameters["groupId"]?.toString())
|
||||||
|
}
|
||||||
|
if ( null != request.parameters["roleId"]) {
|
||||||
|
record.set("roleId", request.parameters["roleId"]?.toString())
|
||||||
|
}
|
||||||
|
if ( null != request.parameters["createTime"] ) {
|
||||||
|
record.set("createTime", Timestamp.valueOf(request.parameters["createTime"]?.toString()))
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,8 @@ class Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateUser(user: ModelUser): Boolean {
|
fun updateUser(user: ModelUser): Boolean {
|
||||||
throw NotImplementedException()
|
throw NotImplementedException()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteUser(userId: Int): Boolean {
|
fun deleteUser(userId: Int): Boolean {
|
||||||
val conn = DBUtil.getConnection()
|
val conn = DBUtil.getConnection()
|
||||||
try {
|
try {
|
||||||
|
|
@ -399,9 +398,11 @@ class Service {
|
||||||
|
|
||||||
val conn = DBUtil.getConnection()
|
val conn = DBUtil.getConnection()
|
||||||
try {
|
try {
|
||||||
return conn.createStatement()
|
val statement = conn.createStatement()
|
||||||
.execute("update `menu` set permId=$permId where id=$menuId")
|
statement.execute("update `menu` set permId=-1 where id=$menuId")
|
||||||
} finally {
|
val bool = statement.executeUpdate("update `menu` set permId=$permId where id=$menuId")
|
||||||
|
return bool == 1
|
||||||
|
}finally {
|
||||||
conn.close()
|
conn.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,7 @@ import model.*
|
||||||
import java.sql.ResultSet
|
import java.sql.ResultSet
|
||||||
import java.sql.Timestamp
|
import java.sql.Timestamp
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.time.Clock
|
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.time.ZoneId
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
fun responseNotFoundById(): JSONResponse {
|
fun responseNotFoundById(): JSONResponse {
|
||||||
|
|
@ -17,6 +15,9 @@ fun responseNotFoundById(): JSONResponse {
|
||||||
fun responseOperationFailed(): JSONResponse {
|
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 responseInvalidParams(): JSONResponse {
|
fun responseInvalidParams(): JSONResponse {
|
||||||
return JSONResponse(Const.codeInvalidParams, Const.msgInvalidParams, null)
|
return JSONResponse(Const.codeInvalidParams, Const.msgInvalidParams, null)
|
||||||
|
|
@ -106,4 +107,4 @@ fun menuToInsertSQL(menu: ModelMenu): String {
|
||||||
insert into `menu`(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())}')
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue