mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-09 02:46:50 +08:00
Merge branch 'zcwy_yk'
# Conflicts: # servers/boe-server-all/src/main/java/com/xboe/module/course/api/CourseFullTextApi.java
This commit is contained in:
@@ -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<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);
|
||||
@@ -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<Boolean> 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<PageList<CourseFullText>> search(Pagination pager, CourseQueryDto dto, Integer minDuration, Integer maxDuration, HttpServletRequest request) throws JsonProcessingException {
|
||||
|
||||
//获取例外人员id
|
||||
List<String> 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<String> singleTeacherNameList = Arrays.asList(courseFullText.getTeacher().split(","));
|
||||
List<String> singleTeacherCodeList = Arrays.asList(courseFullText.getTeacherCode().split(","));
|
||||
log.info("课程name="+courseFullText.getName());
|
||||
for (int i=0;i<singleTeacherCodeList.size();i++){
|
||||
String singleTeacherCode=singleTeacherCodeList.get(i);
|
||||
log.info("工号为"+singleTeacherCode);
|
||||
log.info("教师状态为:" + redisTemplate.opsForValue().get(singleTeacherCode));
|
||||
if (StringUtils.isEmpty(redisTemplate.opsForValue().get(singleTeacherCode))) {
|
||||
syncTeacherStatusToRedis(token, coursePageList);
|
||||
}
|
||||
}else {
|
||||
if(Objects.equals(redisTemplate.opsForValue().get(courseFullText.getTeacherCode()), "1")){
|
||||
log.info("状态="+redisTemplate.opsForValue().get(courseFullText.getTeacherCode()));
|
||||
courseFullText.setTeacher("BOE教师");
|
||||
if (Objects.equals(redisTemplate.opsForValue().get(singleTeacherCode), "1")) {
|
||||
log.info("教师已离职,工号:"+singleTeacherCode);
|
||||
singleTeacherNameList.set(i,"BOE教师");
|
||||
}
|
||||
}
|
||||
|
||||
String finalTeacherNames = String.join(",", singleTeacherNameList);
|
||||
courseFullText.setTeacher(finalTeacherNames);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,7 +420,7 @@ public class CourseFullTextApi extends ApiBaseController{
|
||||
for (TeacherVo teacherVo : teacherInfoByCode) {
|
||||
redisTemplate.opsForValue().set(teacherVo.getTeacherCode(), teacherVo.getStatus());
|
||||
//设置过期时间为1天
|
||||
redisTemplate.expire(teacherVo.getTeacherId(), 24 * 60 * 60, TimeUnit.SECONDS);
|
||||
redisTemplate.expire(teacherVo.getTeacherCode(), 24 * 60 * 60, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,4 +444,23 @@ public class CourseFullTextApi extends ApiBaseController{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void syncTeacherStatusToRedis(String token, PageList<CourseFullText> coursePageList) {
|
||||
List<String> 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<TeacherVo> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user