@ -22,25 +22,23 @@ import com.xmomen.framework.mybatis.dao.MybatisDao;
import java.util.HashMap ;
import java.util.Map ;
/ * *
* Created by Jeng on 2016 / 1 / 5.
* /
@RestController
public class UserController {
// 注入UserService
@Autowired
UserService userService ;
// 注入UserMapper
@Autowired
UserMapper userMapper ;
// 注入MybatisDao
@Autowired
MybatisDao mybatisDao ;
/ * *
* 用 户 列 表
* @param id
* /
// 用户列表
@RequestMapping ( value = "/user" , method = RequestMethod . GET )
@Log ( actionName = "查询用户列表" )
public Page < User > getUserList ( @RequestParam ( value = "limit" ) Integer limit ,
@ -48,35 +46,32 @@ public class UserController {
@RequestParam ( value = "id" , required = false ) Integer id ,
@RequestParam ( value = "keyword" , required = false ) String keyword ,
@RequestParam ( value = "organizationId" , required = false ) Integer organizationId ) {
// 创建一个Map, 用于存储查询条件
Map < String , Object > map = new HashMap < String , Object > ( ) ;
map . put ( "id" , id ) ;
map . put ( "keyword" , keyword ) ;
map . put ( "organizationId" , organizationId ) ;
// 调用MybatisDao的selectPage方法, 查询用户列表
return ( Page < User > ) mybatisDao . selectPage ( UserMapper . UserMapperNameSpace + "getUsers" , map , limit , offset ) ;
}
/ * *
* 用 户 列 表
* @param id
* /
// 用户列表
@RequestMapping ( value = "/user/{id}" , method = RequestMethod . GET )
@Log ( actionName = "查询用户" )
public SysUsers getUserList ( @PathVariable ( value = "id" ) Integer id ) {
// 调用MybatisDao的selectByPrimaryKey方法, 查询用户
return mybatisDao . selectByPrimaryKey ( SysUsers . class , id ) ;
}
/ * *
* 新 增 用 户
* @param createUser
* @param bindingResult
* @return
* /
// 新增用户
@RequestMapping ( value = "/user" , method = RequestMethod . POST )
@Log ( actionName = "新增用户" )
public SysUsers createUser ( @RequestBody @Valid CreateUserVo createUser , BindingResult bindingResult ) throws ArgumentValidException {
// 验证参数是否合法
if ( bindingResult ! = null & & bindingResult . hasErrors ( ) ) {
throw new ArgumentValidException ( bindingResult ) ;
}
// 创建一个CreateUser对象, 用于存储用户信息
CreateUser user = new CreateUser ( ) ;
user . setAge ( createUser . getAge ( ) ) ;
user . setOfficeTel ( createUser . getOfficeTel ( ) ) ;
@ -90,57 +85,49 @@ public class UserController {
user . setLocked ( createUser . getLocked ( ) ! = null & & createUser . getLocked ( ) = = true ? true : false ) ;
user . setOrganizationId ( createUser . getOrganizationId ( ) ) ;
user . setUserGroupIds ( createUser . getUserGroupIds ( ) ) ;
// 调用UserService的createUser方法, 新增用户
return userService . createUser ( user ) ;
}
/ * *
* 更 新 用 户
* @param id
* @param updateUserVo
* @param bindingResult
* @throws ArgumentValidException
* /
// 更新用户
@RequestMapping ( value = "/user/{id}" , method = RequestMethod . PUT )
@Log ( actionName = "更新用户" )
public void updateUser ( @PathVariable ( value = "id" ) Integer id ,
@RequestBody @Valid UpdateUserVo updateUserVo , BindingResult bindingResult ) throws ArgumentValidException {
// 验证参数是否合法
if ( bindingResult ! = null & & bindingResult . hasErrors ( ) ) {
throw new ArgumentValidException ( bindingResult ) ;
}
// 调用UserService的updateUser方法, 更新用户
userService . updateUser ( updateUserVo ) ;
}
/ * *
* 删 除 用 户
* @param id
* /
// 删除用户
@RequestMapping ( value = "/user/{id}" , method = RequestMethod . DELETE )
@Log ( actionName = "删除用户" )
public void deleteUser ( @PathVariable ( value = "id" ) Long id ) {
// 调用MybatisDao的deleteByPrimaryKey方法, 删除用户
mybatisDao . deleteByPrimaryKey ( SysUsers . class , id ) ;
}
/ * *
* 锁 定 用 户
* @param id
* /
// 锁定用户
@RequestMapping ( value = "/user/{id}/locked" , method = RequestMethod . PUT )
@Log ( actionName = "修改用户信息" )
public void lockedUser ( @PathVariable ( value = "id" ) Integer id ,
@RequestParam ( value = "locked" ) Boolean locked ) {
// 创建一个SysUsers对象, 用于存储用户信息
SysUsers sysUsers = new SysUsers ( ) ;
sysUsers . setLocked ( locked ? 1 : 0 ) ;
sysUsers . setId ( id ) ;
// 调用MybatisDao的update方法, 更新用户信息
mybatisDao . update ( sysUsers ) ;
}
/ * *
* 重 置 密 码
* @param id
* /
// 重置密码
@RequestMapping ( value = "/user/{id}/resetPassword" , method = RequestMethod . PUT )
@Log ( actionName = "重置密码" )
public void resetPassword ( @PathVariable ( value = "id" ) Integer id ) {
// 调用UserService的changePassword方法, 重置密码
userService . changePassword ( id , "123456" ) ;
}