UserController.java 6.5 KB

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