123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- package com.adi.airopt.controller;
- import com.adi.airopt.vo.AiroptUser;
- import com.adi.common.core.controller.BaseController;
- import com.adi.common.core.domain.AjaxResult;
- import com.adi.common.core.page.PageDomain;
- import com.adi.common.core.page.TableSupport;
- import com.adi.common.core.redis.RedisCache;
- import com.adi.config.AiroptHttpConfig;
- import com.adi.util.HttpUtils;
- import com.alibaba.fastjson2.JSONObject;
- import com.mysql.cj.util.StringUtils;
- import org.apache.http.HttpResponse;
- import org.apache.http.util.EntityUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.*;
- import java.io.IOException;
- import java.util.*;
- /**
- * ariopt 用户数据数据查询
- *
- * @author adi
- */
- @RestController
- @RequestMapping("/buss/user")
- public class UserController extends BaseController {
- public final static String UserKeyPre = "USER_";
- /** 系统基础配置 */
- @Autowired
- private AiroptHttpConfig airConfig;
- @Autowired
- private RedisCache redisCache;
- /**
- * 获取在线用户
- */
- @RequestMapping("/online")
- public AjaxResult online() throws IOException
- {
- Collection<String> keys = redisCache.keys(airConfig.getUserKeyPre() + "*");
- Map<String, Object> result = new HashMap<>(2);
- result.put("count", keys.size());
- List<String> uids = new ArrayList<>();
- for (String key : keys)
- {
- String uid = key.replace(airConfig.getUserKeyPre(),"");
- uids.add(uid);
- }
- result.put("uids", uids);
- return AjaxResult.success(result);
- }
- /**
- * 获取用户信息
- */
- @RequestMapping("/detail/{uid}")
- public AjaxResult userdetil(@PathVariable String uid) throws IOException
- {
- String host =airConfig.getUrl();
- Map<String, String> bodys =new HashMap<>();
- bodys.put("channelNo",airConfig.getChannelNo());
- bodys.put("clientToken",airConfig.getClientToken());
- bodys.put("transCode","B00031");
- bodys.put("userId",airConfig.getUserId());
- bodys.put("uid",uid);
- try {
- HttpResponse response= HttpUtils.doPost(host,bodys);
- int stat = response.getStatusLine().getStatusCode();
- if (stat != 200) {
- return AjaxResult.error("业务服务链接失败");
- }
- String res = EntityUtils.toString(response.getEntity());
- JSONObject res_obj = JSONObject.parseObject(res);
- return AjaxResult.success(res_obj);
- } catch (Exception e) {
- e.printStackTrace();
- return AjaxResult.error("业务服务链接失败");
- }
- }
- /**
- * 获取用户信息
- */
- @RequestMapping("/list")
- public AjaxResult userlist(@RequestParam String searchtag) throws IOException
- {
- PageDomain pageDomain = TableSupport.buildPageRequest();
- Integer pageNum = pageDomain.getPageNum();
- Integer pageSize = pageDomain.getPageSize();
- String host =airConfig.getUrl();
- Map<String, String> bodys =new HashMap<>();
- bodys.put("channelNo",airConfig.getChannelNo());
- bodys.put("clientToken",airConfig.getClientToken());
- bodys.put("transCode","B00030");
- bodys.put("userId",airConfig.getUserId());
- if(!StringUtils.isNullOrEmpty(searchtag)){
- bodys.put("searchtag",searchtag);
- }
- bodys.put("count", pageSize.toString());
- bodys.put("page",pageNum.toString());
- try {
- HttpResponse response= HttpUtils.doPost(host,bodys);
- int stat = response.getStatusLine().getStatusCode();
- if (stat != 200) {
- return AjaxResult.error("业务服务链接失败");
- }
- String res = EntityUtils.toString(response.getEntity());
- JSONObject res_obj = JSONObject.parseObject(res);
- return AjaxResult.success(res_obj);
- } catch (Exception e) {
- e.printStackTrace();
- return AjaxResult.error("业务服务链接失败");
- }
- }
- /**
- * 重置密码
- */
- @RequestMapping("repwd/{uid}")
- public AjaxResult repwd(@PathVariable String uid) throws IOException
- {
- String host =airConfig.getUrl();
- Map<String, String> bodys =new HashMap<>();
- bodys.put("channelNo",airConfig.getChannelNo());
- bodys.put("clientToken",airConfig.getClientToken());
- bodys.put("transCode","B00032");
- bodys.put("userId",airConfig.getUserId());
- bodys.put("uid",uid);
- try {
- HttpResponse response= HttpUtils.doPost(host,bodys);
- int stat = response.getStatusLine().getStatusCode();
- if (stat != 200) {
- return AjaxResult.error("业务服务链接失败");
- }
- String res = EntityUtils.toString(response.getEntity());
- JSONObject res_obj = JSONObject.parseObject(res);
- return AjaxResult.success(res_obj);
- } catch (Exception e) {
- e.printStackTrace();
- return AjaxResult.error("业务服务链接失败");
- }
- }
- /**
- * 用户信息修改
- */
- @RequestMapping("update")
- public AjaxResult update(@Validated @RequestBody AiroptUser user) throws IOException
- {
- String host =airConfig.getUrl();
- Map<String, String> bodys =new HashMap<>();
- bodys.put("channelNo",airConfig.getChannelNo());
- bodys.put("clientToken",airConfig.getClientToken());
- bodys.put("transCode","B00033");
- bodys.put("userId",airConfig.getUserId());
- bodys.put("uid",user.getUid());
- bodys.put("nickName",user.getNickname());
- bodys.put("username",user.getUsername());
- bodys.put("mobileNo",user.getMobileNo());
- bodys.put("headProfile",user.getHeadProfile());
- bodys.put("company",user.getCompany());
- bodys.put("email",user.getEmail());
- try {
- HttpResponse response= HttpUtils.doPost(host,bodys);
- int stat = response.getStatusLine().getStatusCode();
- if (stat != 200) {
- return AjaxResult.error("业务服务链接失败");
- }
- String res = EntityUtils.toString(response.getEntity());
- JSONObject res_obj = JSONObject.parseObject(res);
- return AjaxResult.success(res_obj);
- } catch (Exception e) {
- e.printStackTrace();
- return AjaxResult.error("业务服务链接失败");
- }
- }
- }
|