修复bindMenu ,增加修改User操作
parent
16ecab1ae0
commit
a73bec5a13
|
|
@ -1,6 +1,7 @@
|
|||
import com.jfinal.plugin.activerecord.ActiveRecordPlugin
|
||||
import com.jfinal.plugin.druid.DruidPlugin
|
||||
import model.ModelMenu2
|
||||
import model.ModelUser2
|
||||
import org.slf4j.LoggerFactory
|
||||
import ro.pippo.controller.ControllerApplication
|
||||
import ro.pippo.core.Pippo
|
||||
|
|
@ -64,6 +65,7 @@ class BasicApplication : ControllerApplication() {
|
|||
"Admin111")
|
||||
val arp = ActiveRecordPlugin(dp)
|
||||
arp.addMapping("menu", ModelMenu2::class.java)
|
||||
arp.addMapping("user", ModelUser2::class.java)
|
||||
dp.start()
|
||||
arp.start()
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,11 @@ class ModelMenu2() : Model<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?) {
|
||||
constructor() : this(null, null, null)
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
package route
|
||||
|
||||
import com.jfinal.kit.JsonKit
|
||||
import com.jfinal.plugin.activerecord.Db
|
||||
import com.jfinal.plugin.activerecord.Record
|
||||
import model.JSONResponse
|
||||
import model.ModelUser
|
||||
import model.ModelUser2
|
||||
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
|
||||
import util.*
|
||||
import java.sql.Timestamp
|
||||
|
||||
|
||||
@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]+}")
|
||||
@Produces(Produces.JSON)
|
||||
fun delUser(@Param("id") id: Int): JSONResponse {
|
||||
|
|
|
|||
|
|
@ -37,9 +37,8 @@ class Service {
|
|||
}
|
||||
|
||||
fun updateUser(user: ModelUser): Boolean {
|
||||
throw NotImplementedException()
|
||||
throw NotImplementedException()
|
||||
}
|
||||
|
||||
fun deleteUser(userId: Int): Boolean {
|
||||
val conn = DBUtil.getConnection()
|
||||
try {
|
||||
|
|
@ -399,9 +398,11 @@ class Service {
|
|||
|
||||
val conn = DBUtil.getConnection()
|
||||
try {
|
||||
return conn.createStatement()
|
||||
.execute("update `menu` set permId=$permId where id=$menuId")
|
||||
} finally {
|
||||
val statement = conn.createStatement()
|
||||
statement.execute("update `menu` set permId=-1 where id=$menuId")
|
||||
val bool = statement.executeUpdate("update `menu` set permId=$permId where id=$menuId")
|
||||
return bool == 1
|
||||
}finally {
|
||||
conn.close()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,7 @@ import model.*
|
|||
import java.sql.ResultSet
|
||||
import java.sql.Timestamp
|
||||
import java.text.SimpleDateFormat
|
||||
import java.time.Clock
|
||||
import java.time.Instant
|
||||
import java.time.ZoneId
|
||||
import java.util.*
|
||||
|
||||
fun responseNotFoundById(): JSONResponse {
|
||||
|
|
@ -17,6 +15,9 @@ fun responseNotFoundById(): JSONResponse {
|
|||
fun responseOperationFailed(): JSONResponse {
|
||||
return JSONResponse(Const.codeServiceOperationFailed, Const.msgOperationFailed, false)
|
||||
}
|
||||
fun responseUpdateUserFailed() : JSONResponse {
|
||||
return JSONResponse(Const.codeServiceOperationFailed,Const.msgUpdateUserFailed,null)
|
||||
}
|
||||
|
||||
fun responseInvalidParams(): JSONResponse {
|
||||
return JSONResponse(Const.codeInvalidParams, Const.msgInvalidParams, null)
|
||||
|
|
@ -106,4 +107,4 @@ fun menuToInsertSQL(menu: ModelMenu): String {
|
|||
insert into `menu`(description,url,permId,createTime)
|
||||
values('${menu.description}','${menu.description}','${menu.permId}','${Timestamp.from(Instant.now())}')
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue