SsoUserController.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package com.jd.controller;
  2. import com.jd.code.ConstString;
  3. import com.jd.entity.basic.SsoUser;
  4. import com.jd.service.SsoUserService;
  5. import com.jd.util.Blank;
  6. import com.jd.util.SendUtil;
  7. import io.swagger.annotations.Api;
  8. import io.swagger.annotations.ApiOperation;
  9. import org.springframework.beans.factory.annotation.Value;
  10. import org.springframework.web.bind.annotation.GetMapping;
  11. import org.springframework.web.bind.annotation.PostMapping;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RestController;
  14. import java.util.Map;
  15. /**
  16. * @author Admin
  17. */
  18. @RestController
  19. @RequestMapping("ssoUser")
  20. @Api(value = "SSO用户管理", tags = {"SSO用户管理"})
  21. public class SsoUserController {
  22. @Value("${security.oauth2.client.user.password}")
  23. private String oauth2Pwd;
  24. private final SsoUserService ssoUserService;
  25. public SsoUserController(SsoUserService ssoUserService) {
  26. this.ssoUserService = ssoUserService;
  27. }
  28. /**
  29. * SSO用户登录
  30. * @param loginAccount
  31. * @param loginPwd
  32. * @param clientId
  33. * @return
  34. */
  35. @PostMapping("userLogin")
  36. @ApiOperation(value = "SSO用户登录")
  37. public Map<String, Object> ssoUserLogin(String loginAccount, String loginPwd, String clientId) {
  38. if (Blank.isEmpty(loginAccount, loginPwd)) {
  39. return SendUtil.send(false, ConstString.REQUEST_WRONGPARAMS);
  40. }
  41. return ssoUserService.userLogin(loginAccount, loginPwd, clientId, oauth2Pwd);
  42. }
  43. /**
  44. * 根据登录帐号查询当前登录用户信息
  45. * @param clientId
  46. * @param loginAccount
  47. * @return
  48. */
  49. @PostMapping("getCurrentLoginInfo")
  50. @ApiOperation(value = "根据登录帐号查询当前登录用户信息")
  51. public Map<String, Object> getCurrentLoginInfo(String clientId, String loginAccount) {
  52. if (Blank.isEmpty(clientId, loginAccount)) {
  53. return SendUtil.send(false, ConstString.REQUEST_WRONGPARAMS);
  54. }
  55. return ssoUserService.getCurrentLoginInfo(clientId, loginAccount);
  56. }
  57. /**
  58. * 分页查询SSO用户列表
  59. * @param page
  60. * @param limit
  61. * @return
  62. */
  63. @GetMapping("getSsoUserListByPage")
  64. @ApiOperation(value = "分页查询SSO用户列表")
  65. public Map<String, Object> getSsoUserListByPage(Integer page, Integer limit, String queryValue) {
  66. if (Blank.isEmpty(page, limit)) {
  67. return SendUtil.send(false, ConstString.REQUEST_WRONGPARAMS);
  68. }
  69. return ssoUserService.getSsoUserListByPage(page, limit, queryValue);
  70. }
  71. /**
  72. * 新增SSO用户
  73. * @param ssoUser
  74. * @return
  75. */
  76. @PostMapping("insertSsoUser")
  77. @ApiOperation(value = "新增SSO用户")
  78. public Map<String, Object> insertSsoUser(SsoUser ssoUser) {
  79. String[] params = new String[]{"systemId", "loginAccount", "loginPwd"};
  80. if (!Blank.checkObjectParamNotNull(ssoUser, params)) {
  81. return SendUtil.send(false, ConstString.REQUEST_WRONGPARAMS);
  82. }
  83. return ssoUserService.insertSsoUser(ssoUser);
  84. }
  85. /**
  86. * 编辑SSO用户
  87. * @param ssoUser
  88. * @return
  89. */
  90. @PostMapping("updateSsoUser")
  91. @ApiOperation(value = "编辑SSO用户")
  92. public Map<String, Object> updateSsoUser(SsoUser ssoUser) {
  93. String[] params = new String[]{"userId", "systemId", "loginAccount"};
  94. if (!Blank.checkObjectParamNotNull(ssoUser, params)) {
  95. return SendUtil.send(false, ConstString.REQUEST_WRONGPARAMS);
  96. }
  97. return ssoUserService.updateSsoUser(ssoUser);
  98. }
  99. /**
  100. * 根据Id删除SSO用户
  101. * @param userId
  102. * @return
  103. */
  104. @PostMapping("deleteSsoUser")
  105. @ApiOperation(value = "根据Id删除SSO用户")
  106. public Map<String, Object> deleteSsoUser(Integer userId) {
  107. if (Blank.isEmpty(userId)) {
  108. return SendUtil.send(false, ConstString.REQUEST_WRONGPARAMS);
  109. }
  110. return ssoUserService.deleteSsoUser(userId);
  111. }
  112. /**
  113. * 根据Id查询SSO用户详情
  114. * @param userId
  115. * @return
  116. */
  117. @GetMapping("getSsoUserInfo")
  118. @ApiOperation(value = "根据Id查询SSO用户详情")
  119. public Map<String, Object> getSsoUserInfo(Integer userId) {
  120. if (Blank.isEmpty(userId)) {
  121. return SendUtil.send(false, ConstString.REQUEST_WRONGPARAMS);
  122. }
  123. return ssoUserService.getSsoUserInfo(userId);
  124. }
  125. /**
  126. * 注销
  127. * @param clientId 客户机id
  128. * @param loginAccount 登录账户
  129. * @return {@link Map}<{@link String}, {@link Object}>
  130. */
  131. @GetMapping("logout")
  132. @ApiOperation("退出登录")
  133. public Map<String, Object> logout(String clientId, String loginAccount) {
  134. if (Blank.isEmpty(clientId, loginAccount)) {
  135. return SendUtil.send(false, ConstString.REQUEST_WRONGPARAMS);
  136. }
  137. return ssoUserService.logout(clientId, loginAccount);
  138. }
  139. }