mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-14 21:36:48 +08:00
修改用户中心接口,头像修改,个性签名修改,根据用户的id集合查询用户
This commit is contained in:
@@ -5,6 +5,7 @@ import java.util.List;
|
||||
import com.xboe.data.dto.AudienceUser;
|
||||
import com.xboe.data.dto.UserData;
|
||||
import com.xboe.data.dto.UserOrgIds;
|
||||
import com.xboe.system.user.vo.UserSimpleVo;
|
||||
|
||||
public interface IOutSideDataService {
|
||||
|
||||
@@ -24,5 +25,20 @@ public interface IOutSideDataService {
|
||||
* 获取用户有权限的机构id
|
||||
*/
|
||||
UserOrgIds getOrgIds();
|
||||
|
||||
/**
|
||||
* 根据aid集合,从用户中心获取要显示的用户信息
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
List<UserSimpleVo> findByIds(List<String> ids);
|
||||
|
||||
/**
|
||||
* 更新用户的头像,签名
|
||||
* @param aid
|
||||
* @param avatar
|
||||
* @param sign
|
||||
*/
|
||||
void updateUser(String aid,String avatar,String sign);
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.xboe.core.utils.OkHttpUtil;
|
||||
import com.xboe.data.dto.AudienceUser;
|
||||
import com.xboe.data.dto.UserData;
|
||||
import com.xboe.data.dto.UserOrgIds;
|
||||
import com.xboe.system.user.vo.UserSimpleVo;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -88,7 +89,7 @@ public class OutSideDataServiceImpl implements IOutSideDataService {
|
||||
public UserData getUserInfoByToken(String token) {
|
||||
//String token = TokenProxy.getBoeToken(request);
|
||||
|
||||
log.info("请求user/info: "+token);
|
||||
log.info("请求/userbasic/user/info");
|
||||
//String token="eyJ0eXBlIjoidG9rZW4iLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC91LmJvZS5jb20iLCJpYXQiOjE2NzIxMTI3NTUsImV4cCI6MTY3MjExOTk1NSwiR2l2ZW5OYW1lIjoiYm9ldSIsInVzZXJJZCI6IjZCMDQ5RkFGLUMzMTQtN0NDRi0wRDI4LTBEMjNGNEM0MjUzMSIsInVJZCI6Ijk2NTM0MjAyNzQ5NzYwNzE2OCIsInBlcm1pc3Npb24iOiIifQ==.1348e0cfbb064d6d348d3976db3618974c1b1e8d2f6c6f45ae8294f09223f9b1";
|
||||
String type="application/json";
|
||||
String[] headers=new String[] {"token",token,"Content-Type",type};
|
||||
@@ -99,9 +100,9 @@ public class OutSideDataServiceImpl implements IOutSideDataService {
|
||||
//OkHttpUtil http=new OkHttpUtil();
|
||||
String responseStr = okHttpUtil.doPostJson(url,"{}", headers);
|
||||
if(StringUtils.isBlank(responseStr)) {
|
||||
log.error("获取user/info返回空值");
|
||||
log.error("获取/userbasic/user/info返回空值");
|
||||
}
|
||||
log.info("获取用户信息:"+responseStr);
|
||||
//log.info("获取用户信息:"+responseStr);
|
||||
//System.out.println(responseStr);
|
||||
JsonNode rootNode= mapper.readTree(responseStr);
|
||||
int code = rootNode.get("status").asInt();
|
||||
@@ -114,7 +115,6 @@ public class OutSideDataServiceImpl implements IOutSideDataService {
|
||||
if(result!=null && result.isObject()) {
|
||||
//这里应该是单独的线程去处理
|
||||
user.setId(getNodeText(result.get("userId")));//最新接口变化,id改成userId
|
||||
log.info("用户的id="+user.getId());
|
||||
String band=getNodeText(result.get("bandCode"));
|
||||
if(StringUtils.isNotBlank(band) && band.length()>4) {
|
||||
String bandNum=band.substring(4);
|
||||
@@ -174,10 +174,10 @@ public class OutSideDataServiceImpl implements IOutSideDataService {
|
||||
JsonNode permission=permissionNodes.next();
|
||||
String permissionText=permission.asText();
|
||||
if("front-admin".equals(permissionText)) {
|
||||
log.info("用户是默认管理员");
|
||||
//log.info("用户是默认管理员");
|
||||
user.setAdminType(1);//设置为管理员,但是是非默认管理员
|
||||
}else if("front-teacher".equals(permissionText)) {
|
||||
log.info("用户有教师身份");
|
||||
//log.info("用户有教师身份");
|
||||
user.setTeacher(true);//设置为教师
|
||||
}
|
||||
}
|
||||
@@ -212,8 +212,6 @@ public class OutSideDataServiceImpl implements IOutSideDataService {
|
||||
log.error("通过接口获取用户信息结果result错误:"+responseStr);
|
||||
throw new RuntimeException("通过接口获取用户信息结果result错误");
|
||||
}
|
||||
log.info("用户管理员:"+user.getAdminType());
|
||||
//System.out.println("老师:"+user.getTeacher());
|
||||
return user;
|
||||
} catch (Exception e) {
|
||||
log.error("获取当前用户信息错误",e);
|
||||
@@ -272,72 +270,6 @@ public class OutSideDataServiceImpl implements IOutSideDataService {
|
||||
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
//// List<String> orgIds = new ArrayList<>();
|
||||
//// String token = "eyJ0eXBlIjoidG9rZW4iLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC91LmJvZS5jb20iLCJpYXQiOjE2NzUzMDkxMDcsImV4cCI6MTY3NTMxNjMwNywiR2l2ZW5OYW1lIjoiYm9ldSIsInVzZXJJZCI6IjdFMDY1NzQxLTkzRUItRTc1Ni02Mzk5LUIwQTA1QUY2NEE3OSIsInVJZCI6Ijk2NTM2OTU4MjM5Mjk3MTI2NCIsInBlcm1pc3Npb24iOiIifQ==.6780daf88206d3f4f2cfc184268f4c1b80f25a916105219a5a6f2e904762b1e8";
|
||||
//// String type="application/json";
|
||||
//// String[] headers=new String[] {"token",token,"Content-Type",type};
|
||||
//// String url= ("https://u.boe.com/userbasic/org/manageOrgIds");
|
||||
//// ObjectMapper mapper=new ObjectMapper();
|
||||
//// String responseStr=null;
|
||||
//// try{
|
||||
//// OkHttpUtil http=new OkHttpUtil();
|
||||
//// responseStr = http.doPostJson(url,"{}", headers);
|
||||
//// System.out.println(responseStr);
|
||||
//// JsonNode rootNode= mapper.readTree(responseStr);
|
||||
//// int code = rootNode.get("status").asInt();
|
||||
//// System.out.println("code="+code);
|
||||
//// if(code!=200) {
|
||||
//// log.error("获取当前用户拥有权限机构id错误:"+responseStr);
|
||||
//// }
|
||||
////
|
||||
//// if(rootNode.get("result")!=null & rootNode.get("result").isArray()) {
|
||||
//// JsonNode result = rootNode.get("result");
|
||||
//// Iterator<JsonNode> elements = result.elements();
|
||||
//// while (elements.hasNext()){
|
||||
//// orgIds.add(elements.next().toString());
|
||||
//// }
|
||||
//// }
|
||||
//// for(String str : orgIds) {
|
||||
//// System.out.println(str);
|
||||
//// }
|
||||
//// }catch (Exception e){
|
||||
//// log.error("获取当前用户有权限的机构id错误",e);
|
||||
//// }
|
||||
// String token="eyJhbGciOiJIUzI1NiIsInR5cGUiOiJ0b2tlbiJ9.eyJpc3MiOiJodHRwOi8vdS5ib2UuY29tIiwiR2l2ZW5OYW1lIjoiYm9ldSIsInVJZCI6OTY1MzQyMDI3NDk3NjA3MTY4LCJ1c2VySWQiOiI2QjA0OUZBRi1DMzE0LTdDQ0YtMEQyOC0wRDIzRjRDNDI1MzEiLCJleHAiOjE2NzUzMzUxNTU3MTZ9.d9f78b2c6bac6001f732015f509eff04f50c6a426e7c01f259f884c8da6ac92c";
|
||||
// String url= "https://u-pre.boe.com/userbasic/audience/members";
|
||||
// Map<String, String> params = new HashMap<>();
|
||||
// params.put("audienceId", "7008604893867151361");
|
||||
// String json = null;
|
||||
// List<AudienceUser> list=new ArrayList<AudienceUser>();
|
||||
// ObjectMapper mapper=new ObjectMapper();
|
||||
// try {
|
||||
//
|
||||
// json = mapper.writeValueAsString(params);
|
||||
// OkHttpUtil http=new OkHttpUtil();
|
||||
// String[] headers=new String[] {"token",token,"Content-Type","application/json"};
|
||||
// String responseStr = http.doPostJson(url, json, headers);
|
||||
// System.out.println(responseStr);
|
||||
// JsonNode rootNode= mapper.readTree(responseStr);
|
||||
//
|
||||
// JsonNode result = rootNode.get("result");
|
||||
// if(result!=null && result.isArray()) {
|
||||
// //这里应该是单独的线程去处理
|
||||
// for(JsonNode node :result) {
|
||||
// AudienceUser au=new AudienceUser();
|
||||
// au.setId(node.get("userId").asText());
|
||||
// au.setName(node.get("name").asText());
|
||||
// au.setCode(node.get("userNo").asText());
|
||||
// list.add(au);
|
||||
// System.out.println(au.getName());
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// log.error("获取受众用户列表错误",e);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
private String getBaseUrl(String url) {
|
||||
String baseUrl=SysConstant.getConfigValue("xboe.server.userbasic.url");
|
||||
if(StringUtils.isBlank(baseUrl)) {
|
||||
@@ -348,4 +280,89 @@ public class OutSideDataServiceImpl implements IOutSideDataService {
|
||||
return reqUrl;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<UserSimpleVo> findByIds(List<String> ids) {
|
||||
|
||||
//请求信息,token加在header中
|
||||
String token = TokenProxy.getToken(request);
|
||||
String type="application/json";
|
||||
String[] headers=new String[] {"token",token,"Content-Type",type};
|
||||
String url= getBaseUrl("/org/getUserMessageToDai");
|
||||
//返回信息
|
||||
List<UserSimpleVo> uids=new ArrayList<UserSimpleVo>();
|
||||
ObjectMapper mapper=new ObjectMapper();
|
||||
String responseStr=null;
|
||||
try{
|
||||
String idsJson=mapper.writeValueAsString(ids);
|
||||
log.info("请求的的接口:"+url);
|
||||
log.info("请求的数据:"+idsJson);
|
||||
responseStr = okHttpUtil.doPostJson(url,idsJson, headers);
|
||||
log.info("返回的数据:"+responseStr);
|
||||
JsonNode rootNode= mapper.readTree(responseStr);
|
||||
int code = rootNode.get("status").asInt();
|
||||
if(code!=200) {
|
||||
log.error("根据aid集合获取用户信息错误:"+code);
|
||||
return null;
|
||||
}
|
||||
|
||||
//返回的是集合
|
||||
JsonNode result = rootNode.get("result");
|
||||
if(result!=null && result.isArray()) {
|
||||
|
||||
Iterator<JsonNode> elements = result.elements();
|
||||
while (elements.hasNext()){
|
||||
JsonNode node=elements.next();
|
||||
UserSimpleVo vo=new UserSimpleVo();
|
||||
vo.setAid(node.get("aid").asText());
|
||||
vo.setAvatar(getNodeText(node.get("avatar")));
|
||||
vo.setCode(getNodeText(node.get("code")));
|
||||
vo.setName(getNodeText(node.get("name")));
|
||||
vo.setOrgInfo(getNodeText(node.get("orgInfo")));
|
||||
vo.setSign(getNodeText(node.get("sign")));
|
||||
//别是1.男;2.女;3其他;4.保密 20230626
|
||||
int gender=result.get("gender").asInt();
|
||||
if(gender>2) {
|
||||
gender=1;
|
||||
}
|
||||
vo.setSex(gender);
|
||||
uids.add(vo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}catch (Exception e){
|
||||
log.error("根据aid集合获取用户信息错误",e);
|
||||
}
|
||||
return uids;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateUser(String aid, String avatar, String sign) {
|
||||
|
||||
String token = TokenProxy.getToken(request);
|
||||
String type="application/json";
|
||||
String[] headers=new String[] {"token",token,"Content-Type",type};
|
||||
String url= getBaseUrl("/org/updateUserMessage");
|
||||
//返回信息
|
||||
ObjectMapper mapper=new ObjectMapper();
|
||||
String responseStr=null;
|
||||
try{
|
||||
String postJson="{\"aid\":\""+aid+"\",\"avatar\":\""+avatar+"\",\"sign\":\""+sign+"\"}";
|
||||
log.info("请求的的接口:"+url);
|
||||
log.info("请求的数据:"+postJson);
|
||||
responseStr = okHttpUtil.doPostJson(url,postJson, headers);
|
||||
log.info("返回的数据:"+responseStr);
|
||||
JsonNode rootNode= mapper.readTree(responseStr);
|
||||
int code = rootNode.get("status").asInt();
|
||||
if(code!=200) {
|
||||
log.error("根据ai更新用户信息错误:"+code);
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("根据aid更新用户信息错误",e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class SysConsoleApi extends ApiBaseController{
|
||||
Map<String,Object> map=new HashMap<String,Object>();
|
||||
//获取当前用户数据
|
||||
CurrentUser cu=super.getCurrent();
|
||||
map.put("msg",2);//未读消息提示是0
|
||||
map.put("msg",0);//未读消息提示是0
|
||||
map.put("aid",cu.getAccountId());//
|
||||
map.put("name",cu.getName());//
|
||||
map.put("avatar","");//头像,如果没有就提供一个默认的
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.xboe.common.utils.StringUtil;
|
||||
import com.xboe.constants.Constants;
|
||||
import com.xboe.core.JsonResponse;
|
||||
import com.xboe.core.api.ApiBaseController;
|
||||
import com.xboe.data.outside.IOutSideDataService;
|
||||
import com.xboe.externalinterface.system.service.IFwUserService;
|
||||
import com.xboe.module.teacher.entity.Teacher;
|
||||
import com.xboe.module.teacher.service.ITeacherService;
|
||||
@@ -61,6 +62,9 @@ public class UserApi extends ApiBaseController {
|
||||
|
||||
@Resource
|
||||
IUserService userService;
|
||||
|
||||
@Resource
|
||||
IOutSideDataService outsideService;
|
||||
|
||||
/**
|
||||
* 分页查询用户信息
|
||||
@@ -255,16 +259,23 @@ public class UserApi extends ApiBaseController {
|
||||
public JsonResponse<List<UserSimpleVo>> findByIds(@RequestBody List<String> ids) {
|
||||
|
||||
List<UserSimpleVo> list = null;
|
||||
//最后从缓存中取,根据用户的id, 缓存用户的头像地址,姓名,机构信息。一期可以先直接查询,缓存可以后续修改
|
||||
if (ids != null && ids.size() > 0) {
|
||||
list = new ArrayList<>();
|
||||
for (String id : ids) {
|
||||
Account account = accountService.get(id);
|
||||
UserSimpleVo vo = getAuthorVo(account);
|
||||
if (vo != null) {
|
||||
list.add(vo);
|
||||
}
|
||||
}
|
||||
// //最后从缓存中取,根据用户的id, 缓存用户的头像地址,姓名,机构信息。一期可以先直接查询,缓存可以后续修改
|
||||
// if (ids != null && ids.size() > 0) {
|
||||
// list = new ArrayList<>();
|
||||
// for (String id : ids) {
|
||||
// Account account = accountService.get(id);
|
||||
// UserSimpleVo vo = getAuthorVo(account);
|
||||
// if (vo != null) {
|
||||
// list.add(vo);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//从用户中心接口中获取
|
||||
try {
|
||||
list=outsideService.findByIds(ids);
|
||||
}catch(Exception e) {
|
||||
log.error("从用户中心获取用户信息失败",e);
|
||||
return badRequest("从用户中心获取用户信息失败");
|
||||
}
|
||||
return success(list);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user