diff --git a/servers/boe-server-all/src/main/java/com/xboe/module/course/api/CourseFullTextApi.java b/servers/boe-server-all/src/main/java/com/xboe/module/course/api/CourseFullTextApi.java index 33c1e590..2c41ad44 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/module/course/api/CourseFullTextApi.java +++ b/servers/boe-server-all/src/main/java/com/xboe/module/course/api/CourseFullTextApi.java @@ -1,12 +1,13 @@ package com.xboe.module.course.api; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; + +import java.util.*; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.lang.Opt; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException; import com.xboe.api.ThirdApi; import com.xboe.data.dto.UserData; @@ -48,16 +49,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 @@ -81,17 +82,17 @@ public class CourseFullTextApi extends ApiBaseController{ */ @GetMapping("/init") public JsonResponse initAllCourse(String flag) throws Exception{ - + if(fullTextSearch==null) { return error("初始化失败:未实现全文检索功能"); } //重新创建索引,如果已经存在,不会重新建 fullTextSearch.reCreateIndex(ICourseFullTextSearch.DEFAULT_INDEX_NAME); - + //提取课程信息,因为现在课程没有太多,所以一次性全部查出来, CourseQueryDto dto =new CourseQueryDto(); dto.setPublish(true);//必须是已发布的 - + List clist = courseService.findList(dto); for(Course c:clist) { CourseFullText cft=CourseToCourseFullText.convert(c); @@ -101,7 +102,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()) { @@ -122,19 +123,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); } @@ -157,7 +158,7 @@ public class CourseFullTextApi extends ApiBaseController{ } @PostMapping("/republish") public JsonResponse republish(String id) throws Exception{ - + if(fullTextSearch==null) { return error("初始化失败:未实现全文检索功能"); } @@ -169,13 +170,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()) { @@ -199,14 +200,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()); @@ -214,8 +215,8 @@ public class CourseFullTextApi extends ApiBaseController{ return success(true); } - - + + /** * 全文检索查询 * @param pager @@ -224,7 +225,6 @@ public class CourseFullTextApi extends ApiBaseController{ */ @PostMapping("/search") public JsonResponse> search(Pagination pager, CourseQueryDto dto, Integer minDuration, Integer maxDuration, HttpServletRequest request) throws JsonProcessingException { - //获取例外人员id List userId = thirdApi.getUserId(); log.info("获取例外人员id userId = " + userId ); @@ -232,7 +232,6 @@ 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"); } @@ -333,23 +332,28 @@ public class CourseFullTextApi extends ApiBaseController{ } } } + //为面授课的时候 - if(teachers.size()==0){ - log.info("查询面授课"); + if (teachers.size() == 0) { 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教师"); + List singleTeacherNameList = Arrays.asList(courseFullText.getTeacher().split(",")); + List singleTeacherCodeList = Arrays.asList(courseFullText.getTeacherCode().split(",")); + log.info("课程name="+courseFullText.getName()); + for (int i=0;i coursePageList) { + List allTeacherCodeList = Opt.ofEmptyAble(coursePageList.getList()).stream().flatMap(Collection::stream) + .flatMap(courseFullText -> { + return Arrays.asList(courseFullText.getTeacherCode().split(",")).stream(); + }).collect(Collectors.toList()); + log.info("同步教师状态到redis allTeacherCodeList = " + allTeacherCodeList); + //用户中心接口,根据工号获取人员信息 + List TeacherVoList = thirdApi.getTeacherInfoByCode(allTeacherCodeList, token); + log.info("同步教师状态到redis TeacherVoList = " + TeacherVoList); + if (CollectionUtil.isNotEmpty(TeacherVoList)) { + for (TeacherVo teacherVo : TeacherVoList) { + redisTemplate.opsForValue().set(teacherVo.getTeacherCode(), teacherVo.getStatus()); + //设置过期时间为1天 + redisTemplate.expire(teacherVo.getTeacherCode(), 24 * 60 * 60, TimeUnit.SECONDS); + } + } + } + }