Compare commits
1 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
d89ffa8cba |
|
|
@ -5,10 +5,8 @@ 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.sql.Timestamp
|
||||||
import util.responseOperationFailed
|
|
||||||
import util.responseSuccess
|
|
||||||
|
|
||||||
|
|
||||||
@Path("/user")
|
@Path("/user")
|
||||||
|
|
@ -63,6 +61,28 @@ class CtrlUser : Controller() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//更新 User
|
||||||
|
@POST("/update")
|
||||||
|
@Produces(Produces.JSON)
|
||||||
|
fun updateUser() :JSONResponse{
|
||||||
|
if (request.parameters["id"] != null) {
|
||||||
|
var user = ModelUser(request.parameters["id"]?.toInt()
|
||||||
|
, request.parameters["name"]?.toString()
|
||||||
|
, request.parameters["passwd"]?.toString()
|
||||||
|
, request.parameters["groupId"]!!.toInt()
|
||||||
|
, request.parameters["roleId"]!!.toInt()
|
||||||
|
, Timestamp.valueOf(request.parameters["createTime"]?.toString()))
|
||||||
|
|
||||||
|
val isSuccess = service.updateUser(user)
|
||||||
|
|
||||||
|
return if (isSuccess){
|
||||||
|
responseSuccess(request.parameters["id"].toString())
|
||||||
|
} else{
|
||||||
|
responseUpdateUserFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,13 @@ class Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateUser(user: ModelUser): Boolean {
|
fun updateUser(user: ModelUser): Boolean {
|
||||||
throw NotImplementedException()
|
try {
|
||||||
|
DBUtil.getConnection().createStatement()
|
||||||
|
.executeUpdate(updateToUser(user))
|
||||||
|
return true
|
||||||
|
} catch (e:Exception){
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteUser(userId: Int): Boolean {
|
fun deleteUser(userId: Int): Boolean {
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,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)
|
||||||
}
|
}
|
||||||
|
|
@ -102,3 +104,9 @@ fun menuToInsertSQL(menu: ModelMenu): String {
|
||||||
values('${menu.description}','${menu.description}','${menu.permId}','${Timestamp.from(Instant.now())}')
|
values('${menu.description}','${menu.description}','${menu.permId}','${Timestamp.from(Instant.now())}')
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
fun updateToUser(model:ModelUser) :String {
|
||||||
|
return """
|
||||||
|
update user set name = ${model.name} ,passwd = ${model.passwd} ,groupId = ${model.groupId} ,roleId = ${model.roleId}
|
||||||
|
where id = ${model.id}
|
||||||
|
"""
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue