Merge branch 'zcwy0110_jw' into 'master'

替换离职人员信息2

See merge request !68
This commit is contained in:
joshen
2024-01-17 14:38:39 +08:00
7 changed files with 222 additions and 23 deletions

View File

@@ -5,6 +5,8 @@ import cn.hutool.core.lang.Opt;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.xboe.api.vo.*;
import com.xboe.module.course.vo.TeacherInfoVo;
import com.xboe.module.course.vo.TeacherVo;
import com.xboe.module.dict.entity.DictDto;
import com.xboe.system.user.dao.UserDao;
import com.xboe.system.user.entity.User;
@@ -52,6 +54,9 @@ public class ThirdApi {
@Value("${audience.getOrgUsers}")
private String searchOrgUsersUrl;
@Value("${userBasic.getTeacherIds}")
private String getTeacherIds;
//获取例外人员的id
public List<String> getUserId(){
String s = Optional.ofNullable(HttpRequest.get(infarasApiUrl).execute()
@@ -78,7 +83,31 @@ public class ThirdApi {
.body()).orElseThrow(() -> new RuntimeException("token校验失败"));
return Opt.ofBlankAble(s).map(t -> JSONUtil.toBean(t, StringResult.class)).map(StringResult::getData).orElseThrow();
}
//获取离职教师信息
public List<TeacherVo>getTeacherInfo(List<String> teacherIds, String token){
TeacherInfoVo teacherInfoVo=new TeacherInfoVo();
teacherInfoVo.setTeacherIds(teacherIds);
log.info("获取离职教师信息");
log.info(JSONUtil.toJsonStr(teacherInfoVo));
String resp = Optional.ofNullable(
HttpRequest.post(getTeacherIds).body(JSONUtil.toJsonStr(teacherInfoVo)).header("token", token).execute()
.body()).orElseThrow(() -> new RuntimeException("token校验失败"));
GetTeacherIdsResult getTeacherIdsResult = JSONUtil.toBean(resp, GetTeacherIdsResult.class);
log.info("getTeacherIdsResult = " + getTeacherIdsResult.getResult());
return getTeacherIdsResult.getResult();
}
public List<TeacherVo>getTeacherInfoByCode(List<String> teacherCode,String token){
TeacherInfoVo teacherInfoVo=new TeacherInfoVo();
teacherInfoVo.setTeacherIds(teacherCode);
log.info("获取离职教师信息");
log.info("参数为"+JSONUtil.toJsonStr(teacherCode));
String resp = Optional.ofNullable(
HttpRequest.post(getTeacherIds).body(JSONUtil.toJsonStr(teacherInfoVo)).header("token", token).execute()
.body()).orElseThrow(() -> new RuntimeException("token校验失败"));
GetTeacherIdsResult getTeacherIdsResult = JSONUtil.toBean(resp, GetTeacherIdsResult.class);
log.info("getTeacherIdsResult = " + getTeacherIdsResult);
return getTeacherIdsResult.getResult();
}
public List<UserInfoListVo> getAllUserList(UserListParam userListParam, String token) {
log.info("获取用户:url:{}", searchOrgUsersUrl);
log.info("获取用户:params:{}", JSONUtil.toJsonStr(userListParam));

View File

@@ -0,0 +1,27 @@
package com.xboe.api.vo;
import cn.hutool.json.JSONUtil;
import com.xboe.module.course.vo.TeacherVo;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import java.util.Date;
import java.util.List;
@Data
@Slf4j
public class GetTeacherIdsResult {
private String error;
private String message;
private String permissions;
private List<TeacherVo> result;
private int status;
private Date timestamp;
public GetTeacherIdsResult success() {
if (this.status != 200) {
log.error("获取学员列表失败----{}", JSONUtil.toJsonPrettyStr(this));
return null;
}
return this;
}
}

View File

@@ -4,16 +4,20 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.xboe.api.ThirdApi;
import com.xboe.data.dto.UserData;
import com.xboe.data.outside.IOutSideDataService;
import com.xboe.module.course.vo.TeacherVo;
import com.xboe.school.study.entity.StudyCourse;
import com.xboe.school.study.service.IStudyCourseService;
import com.xboe.system.organization.service.IOrganizationService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -44,16 +48,16 @@ import javax.servlet.http.HttpServletRequest;
@RestController
@RequestMapping(value="/xboe/m/course/fulltext")
public class CourseFullTextApi extends ApiBaseController{
@Autowired
ICourseService courseService;
@Autowired
ICourseTeacherService courseTeacherService;
@Autowired
ICourseContentService ccourseService;
@Autowired(required = false)
ICourseFullTextSearch fullTextSearch;
@Resource
@@ -68,6 +72,8 @@ public class CourseFullTextApi extends ApiBaseController{
@Autowired
IOutSideDataService outsideDataService;
@Autowired
StringRedisTemplate redisTemplate;
/**
* 课程的初始化
@@ -75,17 +81,17 @@ public class CourseFullTextApi extends ApiBaseController{
*/
@GetMapping("/init")
public JsonResponse<Boolean> initAllCourse(String flag) throws Exception{
if(fullTextSearch==null) {
return error("初始化失败:未实现全文检索功能");
}
//重新创建索引,如果已经存在,不会重新建
fullTextSearch.reCreateIndex(ICourseFullTextSearch.DEFAULT_INDEX_NAME);
//提取课程信息,因为现在课程没有太多,所以一次性全部查出来,
CourseQueryDto dto =new CourseQueryDto();
dto.setPublish(true);//必须是已发布的
List<Course> clist = courseService.findList(dto);
for(Course c:clist) {
CourseFullText cft=CourseToCourseFullText.convert(c);
@@ -95,7 +101,7 @@ public class CourseFullTextApi extends ApiBaseController{
//计算课程时长
int duration=ccourseService.sumDurationByCourseId(c.getId());
cft.setDuration(duration);
//查询教师
CourseTeacherDto teacherDto = courseTeacherService.getTeacherByCourseId(c.getId());
if(teacherDto!=null && !teacherDto.getNames().isEmpty()) {
@@ -116,19 +122,19 @@ public class CourseFullTextApi extends ApiBaseController{
}else {
cft.setIsSetAudience(0);//无受众
}
String fullTextId=fullTextSearch.republish(ICourseFullTextSearch.DEFAULT_INDEX_NAME, cft,c.getFullTextId());
log.info("发布课程全文检索成功:"+fullTextId);
c.setFullTextId(fullTextId);
if(StringUtils.isNotBlank(fullTextId)) {
courseService.updateFieldById(c.getId(),"fullTextId", fullTextId);
}
}catch(Exception e) {
log.error("发布课程【"+c.getName()+"("+c.getId()+")】全文检索及更新数据库失败",e);
}
}
return success(true);
}
@@ -151,7 +157,7 @@ public class CourseFullTextApi extends ApiBaseController{
}
@PostMapping("/republish")
public JsonResponse<Boolean> republish(String id) throws Exception{
if(fullTextSearch==null) {
return error("初始化失败:未实现全文检索功能");
}
@@ -163,13 +169,13 @@ public class CourseFullTextApi extends ApiBaseController{
if(c.getPublished()==null || !c.getPublished()) {
return error("此课程还未发布,请发布课程,不用在这里重新发布");
}
CourseFullText cft=CourseToCourseFullText.convert(c);
try {
//计算课程时长
int duration=ccourseService.sumDurationByCourseId(c.getId());
cft.setDuration(duration);
//查询教师
CourseTeacherDto teacherDto = courseTeacherService.getTeacherByCourseId(c.getId());
if(teacherDto!=null && !teacherDto.getNames().isEmpty()) {
@@ -193,14 +199,14 @@ public class CourseFullTextApi extends ApiBaseController{
}else {
cft.setIsSetAudience(0);//无受众
}
String fullTextId=fullTextSearch.republish(ICourseFullTextSearch.DEFAULT_INDEX_NAME, cft,c.getFullTextId());
log.info("发布课程全文检索成功:"+fullTextId);
c.setFullTextId(fullTextId);
if(StringUtils.isNotBlank(fullTextId)) {
courseService.updateFieldById(c.getId(),"fullTextId", fullTextId);
}
}catch(Exception e) {
log.error("发布课程【"+c.getName()+"("+c.getId()+")】全文检索及更新数据库失败",e);
return error("重新发布失败",e.getMessage());
@@ -208,8 +214,8 @@ public class CourseFullTextApi extends ApiBaseController{
return success(true);
}
/**
* 全文检索查询
* @param pager
@@ -217,7 +223,7 @@ public class CourseFullTextApi extends ApiBaseController{
* @return
*/
@PostMapping("/search")
public JsonResponse<PageList<CourseFullText>> search(Pagination pager, CourseQueryDto dto, Integer minDuration, Integer maxDuration, HttpServletRequest request){
public JsonResponse<PageList<CourseFullText>> search(Pagination pager, CourseQueryDto dto, Integer minDuration, Integer maxDuration, HttpServletRequest request) throws JsonProcessingException {
//获取例外人员id
List<String> userId = thirdApi.getUserId();
@@ -226,6 +232,7 @@ public class CourseFullTextApi extends ApiBaseController{
// String userIds="132,123";
//获取没报名课程的id
String token = request.getHeader("Xboe-Access-Token");
//
if (StringUtils.isEmpty(token)) {
token = request.getHeader("token");
}
@@ -317,6 +324,36 @@ public class CourseFullTextApi extends ApiBaseController{
clist=courseService.findStudysScoreByIds(cids);
}
List<CourseTeacher> teachers = courseService.findTeachersByCourseIds(ids);
//教师id
List<String> teacherIds =new ArrayList<>();
for(CourseFullText course :coursePageList.getList()) {
for (CourseTeacher ct : teachers) {
if (ct.getCourseId().equals(course.getId())) {
teacherIds.add(ct.getTeacherId());
}
}
}
//为面授课的时候
if(teachers.size()==0){
log.info("查询面授课");
for (CourseFullText courseFullText : coursePageList.getList()) {
log.info("教师状态="+redisTemplate.opsForValue().get(courseFullText.getTeacherCode()));
if (redisTemplate.opsForValue().get(courseFullText.getTeacherCode())==null){
getTeacherStatusByCode(token, coursePageList);
if(Objects.equals(redisTemplate.opsForValue().get(courseFullText.getTeacherCode()), "1")){
log.info("redis无信息设置教师");
courseFullText.setTeacher("BOE教师");
}
}else {
if(Objects.equals(redisTemplate.opsForValue().get(courseFullText.getTeacherCode()), "1")){
log.info("状态="+redisTemplate.opsForValue().get(courseFullText.getTeacherCode()));
courseFullText.setTeacher("BOE教师");
}
}
}
}
//
//注意对于多个教师的情况,这里只是设置第一个教师
for(CourseFullText c :coursePageList.getList()) {
if(clist!=null) {
@@ -330,7 +367,19 @@ public class CourseFullTextApi extends ApiBaseController{
}
for(CourseTeacher ct : teachers) {
if(ct.getCourseId().equals(c.getId())) {
c.setTeacher(ct.getTeacherName());
//根据ct.getTeacherId()从redis取数据
if(redisTemplate.opsForValue().get(ct.getTeacherId())==null){
getTeacherInfo(token, teacherIds);
}
if (Objects.equals(redisTemplate.opsForValue().get(ct.getTeacherId()), "1")) {
log.info("课程id="+c.getId());
log.info("教师id="+ct.getTeacherId());
log.info("教师在职状态"+redisTemplate.opsForValue().get(ct.getTeacherId()));
c.setTeacher("BOE教师");
}else{
c.setTeacher(ct.getTeacherName());
}
}
}
@@ -354,4 +403,41 @@ public class CourseFullTextApi extends ApiBaseController{
}
}
private void getTeacherStatusByCode(String token, PageList<CourseFullText> coursePageList) {
log.info("获取教师信息通过工号 ");
List<String> teacherCoeds = new ArrayList<>();
for (CourseFullText courseFullText : coursePageList.getList()) {
teacherCoeds.add(courseFullText.getTeacherCode());
}
if(!teacherCoeds.isEmpty()) {
List<TeacherVo> teacherInfoByCode = thirdApi.getTeacherInfoByCode(teacherCoeds, token);
if(teacherInfoByCode.size()!=0){
for (TeacherVo teacherVo : teacherInfoByCode) {
redisTemplate.opsForValue().set(teacherVo.getTeacherCode(), teacherVo.getStatus());
//设置过期时间为1天
redisTemplate.expire(teacherVo.getTeacherId(), 24 * 60 * 60, TimeUnit.SECONDS);
}
}
}
}
private void getTeacherInfo(String token, List<String> teacherIds) {
List<TeacherVo> teacherInfo = thirdApi.getTeacherInfo(teacherIds, token);
// log.info("根据教师id查询教师信息 teacherInfo = " + teacherInfo);
// log.info("根据教师id查询教师信息 teacherInfo.size = " + teacherInfo.size());
if(teacherInfo== null){
log.info("根据教师id查询教师信息 teacherInfo = " + teacherInfo);
}else {
//将teacherInfo中的teacherId作为key和status作为value存到redis中
for (TeacherVo teacherVo : teacherInfo) {
//teacherVo.getTeacherId()存到redis中
redisTemplate.opsForValue().set(teacherVo.getTeacherId(), teacherVo.getStatus());
//设置过期时间为1天
redisTemplate.expire(teacherVo.getTeacherId(), 24 * 60 * 60, TimeUnit.SECONDS);
}
}
}
}

View File

@@ -1,6 +1,7 @@
package com.xboe.module.course.api;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.annotation.Resource;
@@ -13,9 +14,11 @@ import com.xboe.api.vo.UserDynamic;
import com.xboe.api.vo.UserdynamicParam;
import com.xboe.common.OrderCondition;
import com.xboe.core.JsonResponseStatus;
import com.xboe.module.course.vo.TeacherVo;
import com.xboe.module.usergroup.entity.UserGroupItem;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -86,6 +89,9 @@ public class CoursePortalApi extends ApiBaseController{
@Resource
private ThirdApi thirdApi;
@Autowired
StringRedisTemplate redisTemplate;
/**
* 根据多个课程id返回对应的课程的图片.返回结果如下,
* {
@@ -300,6 +306,18 @@ public class CoursePortalApi extends ApiBaseController{
Teacher t = teacherService.get(ct.getTeacherId());
if(t!=null) {
ct.setRemark(t.getDescription());
if(redisTemplate.opsForValue().get(ct.getTeacherId())!=null){
if(Objects.equals(redisTemplate.opsForValue().get(ct.getTeacherId()), "1")){
ct.setTeacherName("BOE教师");
}
}else if (redisTemplate.opsForValue().get(ct.getTeacherId())==null){
List<String> list=new ArrayList<>();
list.add(ct.getTeacherId());
getTeacherInfo(request.getHeader("Xboe-Access-Token"),list);
if(Objects.equals(redisTemplate.opsForValue().get(ct.getTeacherId()), "1")){
ct.setTeacherName("BOE教师");
}
}
}
}
@@ -312,7 +330,23 @@ public class CoursePortalApi extends ApiBaseController{
return success(rs);
}
private void getTeacherInfo(String token, List<String> teacherIds) {
List<TeacherVo> teacherInfo = thirdApi.getTeacherInfo(teacherIds, token);
// log.info("根据教师id查询教师信息 teacherInfo = " + teacherInfo);
// log.info("根据教师id查询教师信息 teacherInfo.size = " + teacherInfo.size());
if(teacherInfo== null){
log.info("根据教师id查询教师信息 teacherInfo = " + teacherInfo);
}else {
//将teacherInfo中的teacherId作为key和status作为value存到redis中
for (TeacherVo teacherVo : teacherInfo) {
//teacherVo.getTeacherId()存到redis中
redisTemplate.opsForValue().set(teacherVo.getTeacherId(), teacherVo.getStatus());
//设置过期时间为1天
redisTemplate.expire(teacherVo.getTeacherId(), 24 * 60 * 60, TimeUnit.SECONDS);
}
}
}
@GetMapping("/detail-study")
public JsonResponse<List<CourseStudyVo>> detailStudy(String courseId, String aid){

View File

@@ -0,0 +1,11 @@
package com.xboe.module.course.vo;
import lombok.Data;
import java.util.List;
@Data
public class TeacherInfoVo {
List<String> teacherIds;
List<String> teacherCode;
}

View File

@@ -0,0 +1,10 @@
package com.xboe.module.course.vo;
import lombok.Data;
@Data
public class TeacherVo {
String teacherId;
String status;
String teacherCode;
}

View File

@@ -69,4 +69,6 @@ audience.getOrgUsers=${boe.domain}/userbasic/user/getOrgUsers
#获取工号
infrasApi.dict=${boe.domain}/infrasApi/dict/getCourseException
#获取非报名课id
manageApi.stu.offcourse=${boe.domain}/manageApi/stu/offcourse/getOffCourseId
manageApi.stu.offcourse=${boe.domain}/manageApi/stu/offcourse/getOffCourseId
#获取离职教师id
userBasic.getTeacherIds=${boe.domain}/userbasic/user/getTeacherInfo