mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-09 19:06:49 +08:00
首页搜索,面授课多讲师相关
This commit is contained in:
@@ -1,19 +1,22 @@
|
||||
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.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;
|
||||
@@ -68,6 +71,8 @@ public class CourseFullTextApi extends ApiBaseController{
|
||||
@Autowired
|
||||
IOutSideDataService outsideDataService;
|
||||
|
||||
@Autowired
|
||||
StringRedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* 课程的初始化
|
||||
@@ -217,8 +222,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();
|
||||
log.info("获取例外人员id userId = " + userId );
|
||||
@@ -226,6 +230,13 @@ public class CourseFullTextApi extends ApiBaseController{
|
||||
// String userIds="132,123";
|
||||
//获取没报名课程的id
|
||||
String token = request.getHeader("Xboe-Access-Token");
|
||||
List<String>list = new ArrayList<>();
|
||||
list.add("123");
|
||||
List<TeacherVo> teacherInfo = thirdApi.getTeacherInfo(list, token);
|
||||
List<TeacherVo> teacherCode = thirdApi.getTeacherInfoByCode(list, token);
|
||||
log.info("测试根据id获取到的教师信息="+teacherInfo);
|
||||
log.info("测试根据Code获取到的教师信息="+teacherCode);
|
||||
//
|
||||
if (StringUtils.isEmpty(token)) {
|
||||
token = request.getHeader("token");
|
||||
}
|
||||
@@ -317,6 +328,41 @@ 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) {
|
||||
for (CourseFullText courseFullText : coursePageList.getList()) {
|
||||
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);
|
||||
}
|
||||
if (Objects.equals(redisTemplate.opsForValue().get(singleTeacherCode), "1")) {
|
||||
log.info("教师已离职,工号:"+singleTeacherCode);
|
||||
singleTeacherNameList.set(i,"BOE教师");
|
||||
}
|
||||
}
|
||||
|
||||
String finalTeacherNames = String.join(",", singleTeacherNameList);
|
||||
courseFullText.setTeacher(finalTeacherNames);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//注意对于多个教师的情况,这里只是设置第一个教师
|
||||
for(CourseFullText c :coursePageList.getList()) {
|
||||
if(clist!=null) {
|
||||
@@ -330,7 +376,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 +412,60 @@ 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.getTeacherCode(), 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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