UserController.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package com.adi.airopt.controller;
  2. import com.adi.common.config.AdiConfig;
  3. import com.adi.common.constant.CacheConstants;
  4. import com.adi.common.core.controller.BaseController;
  5. import com.adi.common.core.domain.AjaxResult;
  6. import com.adi.common.core.domain.entity.SysUser;
  7. import com.adi.common.core.page.PageDomain;
  8. import com.adi.common.core.page.TableDataInfo;
  9. import com.adi.common.core.page.TableSupport;
  10. import com.adi.common.core.redis.RedisCache;
  11. import com.adi.common.utils.PageUtils;
  12. import com.adi.config.AiroptHttpConfig;
  13. import com.adi.framework.web.domain.server.Sys;
  14. import com.adi.system.domain.SysUserOnline;
  15. import com.adi.util.HttpUtils;
  16. import com.alibaba.fastjson2.JSONObject;
  17. import com.github.pagehelper.PageHelper;
  18. import org.apache.http.HttpResponse;
  19. import org.apache.http.util.EntityUtils;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.security.access.prepost.PreAuthorize;
  22. import org.springframework.web.bind.annotation.*;
  23. import java.io.IOException;
  24. import java.util.*;
  25. /**
  26. * ariopt 用户数据数据查询
  27. *
  28. * @author adi
  29. */
  30. @RestController
  31. @RequestMapping("/buss/user")
  32. public class UserController extends BaseController {
  33. public final static String UserKeyPre = "USER_";
  34. /** 系统基础配置 */
  35. @Autowired
  36. private AiroptHttpConfig airConfig;
  37. @Autowired
  38. private RedisCache redisCache;
  39. /**
  40. * 获取在线用户
  41. */
  42. @RequestMapping("/online")
  43. public AjaxResult online() throws IOException
  44. {
  45. Collection<String> keys = redisCache.keys(airConfig.getUserKeyPre() + "*");
  46. Map<String, Object> result = new HashMap<>(2);
  47. result.put("count", keys.size());
  48. List<String> uids = new ArrayList<>();
  49. for (String key : keys)
  50. {
  51. String uid = key.replace(airConfig.getUserKeyPre(),"");
  52. uids.add(uid);
  53. }
  54. result.put("uids", uids);
  55. return AjaxResult.success(result);
  56. }
  57. /**
  58. * 获取用户信息
  59. */
  60. @RequestMapping("/detail/{uid}")
  61. public AjaxResult userdetil(@PathVariable String uid) throws IOException
  62. {
  63. String host =airConfig.getUrl();
  64. Map<String, String> bodys =new HashMap<>();
  65. bodys.put("channelNo",airConfig.getChannelNo());
  66. bodys.put("clientToken",airConfig.getClientToken());
  67. bodys.put("transCode","B00031");
  68. bodys.put("userId",airConfig.getUserId());
  69. bodys.put("uid",uid);
  70. try {
  71. HttpResponse response= HttpUtils.doPost(host,bodys);
  72. int stat = response.getStatusLine().getStatusCode();
  73. if (stat != 200) {
  74. return AjaxResult.error("业务服务链接失败");
  75. }
  76. String res = EntityUtils.toString(response.getEntity());
  77. JSONObject res_obj = JSONObject.parseObject(res);
  78. return AjaxResult.success(res_obj);
  79. } catch (Exception e) {
  80. e.printStackTrace();
  81. return AjaxResult.error("业务服务链接失败");
  82. }
  83. }
  84. /**
  85. * 获取用户信息
  86. */
  87. @RequestMapping("/list")
  88. public AjaxResult userlist(@RequestParam String searchtag) throws IOException
  89. {
  90. PageDomain pageDomain = TableSupport.buildPageRequest();
  91. Integer pageNum = pageDomain.getPageNum();
  92. Integer pageSize = pageDomain.getPageSize();
  93. String host =airConfig.getUrl();
  94. Map<String, String> bodys =new HashMap<>();
  95. bodys.put("channelNo",airConfig.getChannelNo());
  96. bodys.put("clientToken",airConfig.getClientToken());
  97. bodys.put("transCode","B00030");
  98. bodys.put("userId",airConfig.getUserId());
  99. bodys.put("searchtag",searchtag);
  100. bodys.put("count", pageSize.toString());
  101. bodys.put("page",pageNum.toString());
  102. try {
  103. HttpResponse response= HttpUtils.doPost(host,bodys);
  104. int stat = response.getStatusLine().getStatusCode();
  105. if (stat != 200) {
  106. return AjaxResult.error("业务服务链接失败");
  107. }
  108. String res = EntityUtils.toString(response.getEntity());
  109. JSONObject res_obj = JSONObject.parseObject(res);
  110. return AjaxResult.success(res_obj);
  111. } catch (Exception e) {
  112. e.printStackTrace();
  113. return AjaxResult.error("业务服务链接失败");
  114. }
  115. }
  116. /**
  117. * 重置密码
  118. */
  119. @RequestMapping("repwd/{uid}")
  120. public AjaxResult repwd(@PathVariable String uid) throws IOException
  121. {
  122. String host =airConfig.getUrl();
  123. Map<String, String> bodys =new HashMap<>();
  124. bodys.put("channelNo",airConfig.getChannelNo());
  125. bodys.put("clientToken",airConfig.getClientToken());
  126. bodys.put("transCode","B00032");
  127. bodys.put("userId",airConfig.getUserId());
  128. bodys.put("uid",uid);
  129. try {
  130. HttpResponse response= HttpUtils.doPost(host,bodys);
  131. int stat = response.getStatusLine().getStatusCode();
  132. if (stat != 200) {
  133. return AjaxResult.error("业务服务链接失败");
  134. }
  135. String res = EntityUtils.toString(response.getEntity());
  136. JSONObject res_obj = JSONObject.parseObject(res);
  137. return AjaxResult.success(res_obj);
  138. } catch (Exception e) {
  139. e.printStackTrace();
  140. return AjaxResult.error("业务服务链接失败");
  141. }
  142. }
  143. }