mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-11 03:46:50 +08:00
增加用户信息的获取
This commit is contained in:
@@ -3,6 +3,7 @@ package com.xboe.data.outside;
|
||||
import java.util.List;
|
||||
|
||||
import com.xboe.data.dto.AudienceUser;
|
||||
import com.xboe.data.dto.UserData;
|
||||
|
||||
public interface IOutSideDataService {
|
||||
|
||||
@@ -11,5 +12,10 @@ public interface IOutSideDataService {
|
||||
* @param task
|
||||
*/
|
||||
List<AudienceUser> getUsersByAudienceId(String audienceId);
|
||||
|
||||
/**
|
||||
* 通过统一用户id获取用户的信息
|
||||
*/
|
||||
UserData getUserInfoByUserId(String userId);
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.xboe.core.SysConstant;
|
||||
import com.xboe.core.api.TokenProxy;
|
||||
import com.xboe.core.utils.OkHttpUtil;
|
||||
import com.xboe.data.dto.AudienceUser;
|
||||
import com.xboe.data.dto.UserData;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -40,20 +41,13 @@ public class OutSideDataServiceImpl implements IOutSideDataService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<AudienceUser> getUsersByAudienceId(String audienceId){
|
||||
|
||||
String baseUrl=SysConstant.getConfigValue("xboe.server.userbasic.url");
|
||||
if(StringUtils.isBlank(baseUrl)) {
|
||||
log.error("获取受众用户错误,未配置用户服务的地址【xboe.server.userbasic.url】");
|
||||
throw new RuntimeException("获取受众用户错误,未配置用户服务的地址");
|
||||
}
|
||||
String token = TokenProxy.getToken(request);
|
||||
String type="application/json";
|
||||
String[] headers=new String[] {"token",token,"Content-Type",type};
|
||||
String url= baseUrl+"/audience/memberList";
|
||||
String url= getBaseUrl("/audience/memberList");
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("audienceId", audienceId);
|
||||
String json = null;
|
||||
@@ -65,7 +59,6 @@ public class OutSideDataServiceImpl implements IOutSideDataService {
|
||||
String responseStr = okHttpUtil.doPostJson(url, json, headers);
|
||||
JsonNode rootNode= mapper.readTree(responseStr);
|
||||
|
||||
|
||||
JsonNode result = rootNode.get("result")!=null ?( rootNode.get("result").get("data") !=null ? rootNode.get("result").get("data"):null):null;
|
||||
if(rootNode.get("result")!=null & rootNode.get("result").isArray()) {
|
||||
//这里应该是单独的线程去处理
|
||||
@@ -83,4 +76,67 @@ public class OutSideDataServiceImpl implements IOutSideDataService {
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UserData getUserInfoByUserId(String userId) {
|
||||
|
||||
String token = TokenProxy.getToken(request);
|
||||
String type="application/json";
|
||||
String[] headers=new String[] {"token",token,"Content-Type",type};
|
||||
String url= getBaseUrl("/user/info");
|
||||
ObjectMapper mapper=new ObjectMapper();
|
||||
try {
|
||||
String responseStr = okHttpUtil.doPostJson(url,"{}", headers);
|
||||
JsonNode rootNode= mapper.readTree(responseStr);
|
||||
int code = rootNode.get("code").asInt();
|
||||
if(code!=200) {
|
||||
log.error("获取当前用户信息返回结果错误:"+responseStr);
|
||||
return null;
|
||||
}
|
||||
UserData user=new UserData();
|
||||
JsonNode result = rootNode.get("result");
|
||||
if(rootNode.get("result")!=null & rootNode.get("result").isObject()) {
|
||||
//这里应该是单独的线程去处理
|
||||
user.setId(getNodeText(result.get("id")));
|
||||
String band=getNodeText(result.get("bandCode"));
|
||||
if(StringUtils.isNotBlank(band) && band.length()>4) {
|
||||
String bandNum=band.substring(4);
|
||||
user.setBandLevel(Integer.valueOf(bandNum));
|
||||
}else {
|
||||
user.setBandLevel(0);
|
||||
}
|
||||
user.setAvatar("");
|
||||
user.setCode(getNodeText(result.get("userNo")));
|
||||
user.setDeleted(false);
|
||||
user.setDepartId(getNodeText(result.get("departId")));
|
||||
user.setDepartName("");//无此字段
|
||||
user.setGender(1);//少此字段
|
||||
user.setKid(getNodeText(result.get("kid")));
|
||||
user.setLearningDuration(result.get("learningDuration").asInt());
|
||||
user.setName(result.get("realName").asText());
|
||||
user.setOrgNamePath(result.get("orgNamePath").asText());
|
||||
user.setUserType(1);//直接设置为学员
|
||||
if(StringUtils.isBlank(user.getCode())) {
|
||||
log.error("通过接口获取当前用户信息【"+user.getId()+"】"+user.getName()+",工号为空,不能使用");
|
||||
throw new RuntimeException("通过接口获取当前用户信息,工号为空,不能使用");
|
||||
}
|
||||
|
||||
}
|
||||
return user;
|
||||
} catch (Exception e) {
|
||||
log.error("获取当前用户信息错误",e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getBaseUrl(String url) {
|
||||
String baseUrl=SysConstant.getConfigValue("xboe.server.userbasic.url");
|
||||
if(StringUtils.isBlank(baseUrl)) {
|
||||
log.error("调用用户接口错误,未配置用户服务的地址【xboe.server.userbasic.url】");
|
||||
throw new RuntimeException("获取用户信息错误,未配置用户服务的地址");
|
||||
}
|
||||
String reqUrl= baseUrl+"/user/info";
|
||||
return reqUrl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import javax.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.xboe.common.OrderCondition;
|
||||
import com.xboe.core.orm.FieldFilters;
|
||||
import com.xboe.core.orm.QueryBuilder;
|
||||
import com.xboe.module.course.dao.CourseTeacherDao;
|
||||
@@ -39,7 +40,7 @@ public class CourseTeacherServiceImpl implements ICourseTeacherService {
|
||||
public CourseTeacherDto getTeacherByCourseId(String courseId) {
|
||||
CourseTeacherDto dto = null;
|
||||
|
||||
List<CourseTeacher> list = dao.findList(FieldFilters.eq("courseId",courseId));
|
||||
List<CourseTeacher> list = dao.findList(OrderCondition.desc("teacherId"),FieldFilters.eq("courseId",courseId));
|
||||
if(list != null && !list.isEmpty()){
|
||||
dto=new CourseTeacherDto();
|
||||
dto.setCourseId(courseId);
|
||||
@@ -60,7 +61,7 @@ public class CourseTeacherServiceImpl implements ICourseTeacherService {
|
||||
public List<CourseTeacherDto> queryTeacher(Collection<String> ids) {
|
||||
List<CourseTeacherDto> teacherDtos = null;
|
||||
if (ids != null && !ids.isEmpty()) {
|
||||
List<CourseTeacher> list = dao.findList(FieldFilters.in("courseId",ids));
|
||||
List<CourseTeacher> list = dao.findList(OrderCondition.desc("teacherId"),FieldFilters.in("courseId",ids));
|
||||
if(list != null && !list.isEmpty()) {
|
||||
teacherDtos = new ArrayList<>();
|
||||
for (String s : ids) {
|
||||
|
||||
Reference in New Issue
Block a user