UserController.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package com.ims.eval.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.ims.eval.entity.dto.result.R;
  4. import com.ims.eval.entity.Myuser;
  5. import com.ims.eval.feign.RemoteServiceBuilder;
  6. import com.ims.eval.service.IUserService;
  7. import io.swagger.annotations.ApiOperation;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.web.bind.annotation.*;
  11. import java.util.List;
  12. import java.util.concurrent.atomic.AtomicBoolean;
  13. /**
  14. * <p>
  15. * 前端控制器
  16. * </p>
  17. *
  18. * @author wang
  19. * @since 2023-03-03
  20. */
  21. @Slf4j
  22. @RestController
  23. @RequestMapping("//user")
  24. public class UserController {
  25. @Autowired
  26. private IUserService userService;
  27. @Autowired
  28. private RemoteServiceBuilder remoteServiceBuilder;
  29. /**
  30. * 更具code获取用户信息
  31. * @return
  32. */
  33. @GetMapping(value = "getSysUser")
  34. public JSONObject getSysUser(
  35. @RequestParam(value = "code", required = false) String code) {
  36. JSONObject json = null;
  37. try {
  38. json = remoteServiceBuilder.getGatewayUrl().getSysUser(code);
  39. } catch (Exception e) {
  40. e.printStackTrace();
  41. }
  42. return json;
  43. }
  44. /**
  45. * 根据token获取code
  46. * @return
  47. */
  48. @GetMapping(value = "getCodeByToken")
  49. public JSONObject getCodeByToken(
  50. @RequestParam(value = "token", required = false) String token) {
  51. JSONObject json = null;
  52. try {
  53. json = remoteServiceBuilder.getGatewayUrl().getCodeByToken(token);
  54. } catch (Exception e) {
  55. e.printStackTrace();
  56. }
  57. return json;
  58. }
  59. /**
  60. * 登录接口
  61. * @param username
  62. * @param password
  63. * @return
  64. */
  65. @PostMapping(value = "bladeAuth")
  66. public R bladeAuth(
  67. @RequestParam(value = "username", required = false) String username,
  68. @RequestParam(value = "password", required = false) String password) {
  69. JSONObject json = null;
  70. try {
  71. json = userService.getbladeAuth("000000",username,password,"password","all","account");
  72. } catch (Exception e) {
  73. log.error("错误",e);
  74. return R.error().customError("登录失败");
  75. }
  76. return R.ok().data(json);
  77. }
  78. /**
  79. * 退出登录
  80. * @param token
  81. * @return
  82. */
  83. @PostMapping(value = "removeByToken")
  84. public JSONObject removeByToken(@RequestParam(value = "token", required = true) String token) {
  85. JSONObject json = null;
  86. try {
  87. json = remoteServiceBuilder.getGatewayUrl().removeByToken(token);
  88. } catch (Exception e) {
  89. log.error("错误",e);
  90. }
  91. return json;
  92. }
  93. //@ImsPreAuth("eval:dataDictionary:edit")
  94. @PostMapping(value = "/save")
  95. @ApiOperation(value = "新增(修改)", notes = "新增(修改)")
  96. public R addAll(@RequestBody List<Myuser> user) {
  97. AtomicBoolean b = new AtomicBoolean(false);
  98. user.stream().forEach(i -> {
  99. b.set(userService.saveOrUpdate(i));
  100. });
  101. if (b.get()) {
  102. return R.ok().data(b);
  103. } else {
  104. return R.error().data("保存失败!");
  105. }
  106. }
  107. /**
  108. * 查询所有数据
  109. * @param id 主键
  110. * @param orgId 组织id
  111. * @return
  112. */
  113. //@ImsPreAuth("eval:organizationEvaluationRule:view")
  114. @GetMapping(value = "listAll")
  115. public R listAll(
  116. @RequestParam(value = "id", required = false) String id,
  117. @RequestParam(value = "orgId", required = false) String orgId,
  118. @RequestParam(value = "unitId", required = false) String unitId) {
  119. List<Myuser> list = userService.listAll(id, orgId,unitId);
  120. return R.ok().data(list);
  121. }
  122. /**
  123. * 查询所有数据
  124. * @param id 主键
  125. * @return
  126. */
  127. //@ImsPreAuth("eval:organizationEvaluationRule:view")
  128. @GetMapping(value = "getId")
  129. public R getByid(
  130. @RequestParam(value = "id", required = false) String id) {
  131. Myuser user = userService.getById(id);
  132. return R.ok().data(user);
  133. }
  134. }