UserController.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package com.jkcredit.invoice.controller.user;
  2. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  3. import com.jkcredit.invoice.annotation.LoginRequired;
  4. import com.jkcredit.invoice.model.entity.user.User;
  5. import com.jkcredit.invoice.service.user.UserService;
  6. import com.jkcredit.invoice.util.MD5Util;
  7. import com.jkcredit.invoice.util.RespR;
  8. import io.swagger.annotations.Api;
  9. import io.swagger.annotations.ApiImplicitParam;
  10. import io.swagger.annotations.ApiImplicitParams;
  11. import io.swagger.annotations.ApiOperation;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.web.bind.annotation.*;
  14. /**
  15. * @description:
  16. * @author: sunzhaoning
  17. * @create: 2019-05-29 09:14
  18. * @version: V1.0
  19. **/
  20. @Api(tags = "用户操作")
  21. @RestController
  22. @RequestMapping(value = {"/user"})
  23. public class UserController {
  24. @Autowired
  25. private UserService userService;
  26. /**
  27. * 通过ID查询用户信息
  28. *
  29. * @param id ID
  30. * @return 用户信息
  31. */
  32. @GetMapping("/{id}")
  33. @ApiOperation(value="通过ID查询用户信息", notes="通过ID查询用户信息")
  34. @LoginRequired
  35. @ApiImplicitParams({
  36. @ApiImplicitParam(name = "id", value = "用id", required = true, dataType = "Integer")
  37. })
  38. public RespR user(@PathVariable Integer id) {
  39. return new RespR<>(userService.selectUserById(id));
  40. }
  41. /**
  42. * 删除用户信息
  43. *
  44. * @param id ID
  45. * @return R
  46. */
  47. @DeleteMapping("/{id}")
  48. @ApiOperation(value="根据用户名id删除用户信息", notes="根据用户名id删除用户信息")
  49. @LoginRequired
  50. public RespR userDel(@PathVariable Integer id) {
  51. User sysUser = userService.getById(id);
  52. return new RespR<>(userService.deleteUserById(sysUser));
  53. }
  54. /**
  55. * 添加用户
  56. *
  57. * @param user 用户信息
  58. * @return success/false
  59. */
  60. @PostMapping
  61. @ApiOperation(value="新增用户详细信息", notes="新增用户详细信息")
  62. @LoginRequired
  63. public RespR user(@RequestBody User user) {
  64. user.setPassword(MD5Util.encrypt(user.getPassword()));
  65. User user1 = userService.selectUserByUserName(user.getUserName());
  66. if(null != user1){
  67. return new RespR<>(Boolean.FALSE, "该用户已存在");
  68. }
  69. return new RespR<>(userService.saveUser(user));
  70. }
  71. /**
  72. * 更新用户信息
  73. *
  74. * @param user 用户信息
  75. * @return R
  76. */
  77. @PostMapping("/updateUser")
  78. @ApiOperation(value="更新用户信息", notes="更新用户信息")
  79. @LoginRequired
  80. public RespR updateUser(@RequestBody User user) {
  81. if(user.getPassword()!=null){
  82. user.setPassword(MD5Util.encrypt(user.getPassword()));
  83. }
  84. return new RespR<>(userService.updateUserInfo(user));
  85. }
  86. /**
  87. * 分页查询用户
  88. *
  89. * @param page 参数集
  90. * @param user 查询参数列表
  91. * @return 用户集合
  92. */
  93. @PostMapping("/page")
  94. @ApiOperation(value="分页查询用户", notes="分页查询用户")
  95. @LoginRequired
  96. public RespR getUserPage(Page page, User user) {
  97. return new RespR<>(userService.getUserWithRolePage(page, user));
  98. }
  99. /**
  100. * 重置密码
  101. *
  102. * @param user user
  103. * @return success/false
  104. */
  105. @PutMapping("/restPassword")
  106. @ApiOperation(value="重置密码", notes="重置密码")
  107. @LoginRequired
  108. public RespR updateUserInfoPassWord(@RequestBody User user) {
  109. user.setPassword(MD5Util.encrypt(user.getPassword()));
  110. return userService.restPassword(user);
  111. }
  112. /**
  113. * 修改锁定状态
  114. *
  115. * @param user user
  116. * @return success/false
  117. */
  118. @PutMapping("/lock")
  119. @ApiOperation(value="修改锁定状态", notes="修改锁定状态")
  120. @LoginRequired
  121. public RespR updateLock(@RequestBody User user) {
  122. return userService.updateLock(user);
  123. }
  124. }