Compare commits
1 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
d89ffa8cba |
|
|
@ -5,10 +5,8 @@ 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
|
||||
import util.*
|
||||
import java.sql.Timestamp
|
||||
|
||||
|
||||
@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]+}")
|
||||
@Produces(Produces.JSON)
|
||||
fun delUser(@Param("id") id: Int): JSONResponse {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,13 @@ class Service {
|
|||
}
|
||||
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,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)
|
||||
}
|
||||
|
|
@ -101,4 +103,10 @@ fun menuToInsertSQL(menu: ModelMenu): String {
|
|||
insert into `role`(description,url,permId,createTime)
|
||||
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