替换离职人员信息2

This commit is contained in:
xiaozhequ
2024-01-17 14:04:17 +08:00
parent 96d4de62b9
commit e4a30e0282
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.http.HttpRequest;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.xboe.api.vo.*; 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.module.dict.entity.DictDto;
import com.xboe.system.user.dao.UserDao; import com.xboe.system.user.dao.UserDao;
import com.xboe.system.user.entity.User; import com.xboe.system.user.entity.User;
@@ -52,6 +54,9 @@ public class ThirdApi {
@Value("${audience.getOrgUsers}") @Value("${audience.getOrgUsers}")
private String searchOrgUsersUrl; private String searchOrgUsersUrl;
@Value("${userBasic.getTeacherIds}")
private String getTeacherIds;
//获取例外人员的id //获取例外人员的id
public List<String> getUserId(){ public List<String> getUserId(){
String s = Optional.ofNullable(HttpRequest.get(infarasApiUrl).execute() String s = Optional.ofNullable(HttpRequest.get(infarasApiUrl).execute()
@@ -78,7 +83,31 @@ public class ThirdApi {
.body()).orElseThrow(() -> new RuntimeException("token校验失败")); .body()).orElseThrow(() -> new RuntimeException("token校验失败"));
return Opt.ofBlankAble(s).map(t -> JSONUtil.toBean(t, StringResult.class)).map(StringResult::getData).orElseThrow(); 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) { public List<UserInfoListVo> getAllUserList(UserListParam userListParam, String token) {
log.info("获取用户:url:{}", searchOrgUsersUrl); log.info("获取用户:url:{}", searchOrgUsersUrl);
log.info("获取用户:params:{}", JSONUtil.toJsonStr(userListParam)); 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.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.xboe.api.ThirdApi; import com.xboe.api.ThirdApi;
import com.xboe.data.dto.UserData; import com.xboe.data.dto.UserData;
import com.xboe.data.outside.IOutSideDataService; 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.entity.StudyCourse;
import com.xboe.school.study.service.IStudyCourseService; import com.xboe.school.study.service.IStudyCourseService;
import com.xboe.system.organization.service.IOrganizationService; import com.xboe.system.organization.service.IOrganizationService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; 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.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@@ -44,16 +48,16 @@ import javax.servlet.http.HttpServletRequest;
@RestController @RestController
@RequestMapping(value="/xboe/m/course/fulltext") @RequestMapping(value="/xboe/m/course/fulltext")
public class CourseFullTextApi extends ApiBaseController{ public class CourseFullTextApi extends ApiBaseController{
@Autowired @Autowired
ICourseService courseService; ICourseService courseService;
@Autowired @Autowired
ICourseTeacherService courseTeacherService; ICourseTeacherService courseTeacherService;
@Autowired @Autowired
ICourseContentService ccourseService; ICourseContentService ccourseService;
@Autowired(required = false) @Autowired(required = false)
ICourseFullTextSearch fullTextSearch; ICourseFullTextSearch fullTextSearch;
@Resource @Resource
@@ -68,6 +72,8 @@ public class CourseFullTextApi extends ApiBaseController{
@Autowired @Autowired
IOutSideDataService outsideDataService; IOutSideDataService outsideDataService;
@Autowired
StringRedisTemplate redisTemplate;
/** /**
* 课程的初始化 * 课程的初始化
@@ -75,17 +81,17 @@ public class CourseFullTextApi extends ApiBaseController{
*/ */
@GetMapping("/init") @GetMapping("/init")
public JsonResponse<Boolean> initAllCourse(String flag) throws Exception{ public JsonResponse<Boolean> initAllCourse(String flag) throws Exception{
if(fullTextSearch==null) { if(fullTextSearch==null) {
return error("初始化失败:未实现全文检索功能"); return error("初始化失败:未实现全文检索功能");
} }
//重新创建索引,如果已经存在,不会重新建 //重新创建索引,如果已经存在,不会重新建
fullTextSearch.reCreateIndex(ICourseFullTextSearch.DEFAULT_INDEX_NAME); fullTextSearch.reCreateIndex(ICourseFullTextSearch.DEFAULT_INDEX_NAME);
//提取课程信息,因为现在课程没有太多,所以一次性全部查出来, //提取课程信息,因为现在课程没有太多,所以一次性全部查出来,
CourseQueryDto dto =new CourseQueryDto(); CourseQueryDto dto =new CourseQueryDto();
dto.setPublish(true);//必须是已发布的 dto.setPublish(true);//必须是已发布的
List<Course> clist = courseService.findList(dto); List<Course> clist = courseService.findList(dto);
for(Course c:clist) { for(Course c:clist) {
CourseFullText cft=CourseToCourseFullText.convert(c); CourseFullText cft=CourseToCourseFullText.convert(c);
@@ -95,7 +101,7 @@ public class CourseFullTextApi extends ApiBaseController{
//计算课程时长 //计算课程时长
int duration=ccourseService.sumDurationByCourseId(c.getId()); int duration=ccourseService.sumDurationByCourseId(c.getId());
cft.setDuration(duration); cft.setDuration(duration);
//查询教师 //查询教师
CourseTeacherDto teacherDto = courseTeacherService.getTeacherByCourseId(c.getId()); CourseTeacherDto teacherDto = courseTeacherService.getTeacherByCourseId(c.getId());
if(teacherDto!=null && !teacherDto.getNames().isEmpty()) { if(teacherDto!=null && !teacherDto.getNames().isEmpty()) {
@@ -116,19 +122,19 @@ public class CourseFullTextApi extends ApiBaseController{
}else { }else {
cft.setIsSetAudience(0);//无受众 cft.setIsSetAudience(0);//无受众
} }
String fullTextId=fullTextSearch.republish(ICourseFullTextSearch.DEFAULT_INDEX_NAME, cft,c.getFullTextId()); String fullTextId=fullTextSearch.republish(ICourseFullTextSearch.DEFAULT_INDEX_NAME, cft,c.getFullTextId());
log.info("发布课程全文检索成功:"+fullTextId); log.info("发布课程全文检索成功:"+fullTextId);
c.setFullTextId(fullTextId); c.setFullTextId(fullTextId);
if(StringUtils.isNotBlank(fullTextId)) { if(StringUtils.isNotBlank(fullTextId)) {
courseService.updateFieldById(c.getId(),"fullTextId", fullTextId); courseService.updateFieldById(c.getId(),"fullTextId", fullTextId);
} }
}catch(Exception e) { }catch(Exception e) {
log.error("发布课程【"+c.getName()+"("+c.getId()+")】全文检索及更新数据库失败",e); log.error("发布课程【"+c.getName()+"("+c.getId()+")】全文检索及更新数据库失败",e);
} }
} }
return success(true); return success(true);
} }
@@ -151,7 +157,7 @@ public class CourseFullTextApi extends ApiBaseController{
} }
@PostMapping("/republish") @PostMapping("/republish")
public JsonResponse<Boolean> republish(String id) throws Exception{ public JsonResponse<Boolean> republish(String id) throws Exception{
if(fullTextSearch==null) { if(fullTextSearch==null) {
return error("初始化失败:未实现全文检索功能"); return error("初始化失败:未实现全文检索功能");
} }
@@ -163,13 +169,13 @@ public class CourseFullTextApi extends ApiBaseController{
if(c.getPublished()==null || !c.getPublished()) { if(c.getPublished()==null || !c.getPublished()) {
return error("此课程还未发布,请发布课程,不用在这里重新发布"); return error("此课程还未发布,请发布课程,不用在这里重新发布");
} }
CourseFullText cft=CourseToCourseFullText.convert(c); CourseFullText cft=CourseToCourseFullText.convert(c);
try { try {
//计算课程时长 //计算课程时长
int duration=ccourseService.sumDurationByCourseId(c.getId()); int duration=ccourseService.sumDurationByCourseId(c.getId());
cft.setDuration(duration); cft.setDuration(duration);
//查询教师 //查询教师
CourseTeacherDto teacherDto = courseTeacherService.getTeacherByCourseId(c.getId()); CourseTeacherDto teacherDto = courseTeacherService.getTeacherByCourseId(c.getId());
if(teacherDto!=null && !teacherDto.getNames().isEmpty()) { if(teacherDto!=null && !teacherDto.getNames().isEmpty()) {
@@ -193,14 +199,14 @@ public class CourseFullTextApi extends ApiBaseController{
}else { }else {
cft.setIsSetAudience(0);//无受众 cft.setIsSetAudience(0);//无受众
} }
String fullTextId=fullTextSearch.republish(ICourseFullTextSearch.DEFAULT_INDEX_NAME, cft,c.getFullTextId()); String fullTextId=fullTextSearch.republish(ICourseFullTextSearch.DEFAULT_INDEX_NAME, cft,c.getFullTextId());
log.info("发布课程全文检索成功:"+fullTextId); log.info("发布课程全文检索成功:"+fullTextId);
c.setFullTextId(fullTextId); c.setFullTextId(fullTextId);
if(StringUtils.isNotBlank(fullTextId)) { if(StringUtils.isNotBlank(fullTextId)) {
courseService.updateFieldById(c.getId(),"fullTextId", fullTextId); courseService.updateFieldById(c.getId(),"fullTextId", fullTextId);
} }
}catch(Exception e) { }catch(Exception e) {
log.error("发布课程【"+c.getName()+"("+c.getId()+")】全文检索及更新数据库失败",e); log.error("发布课程【"+c.getName()+"("+c.getId()+")】全文检索及更新数据库失败",e);
return error("重新发布失败",e.getMessage()); return error("重新发布失败",e.getMessage());
@@ -208,8 +214,8 @@ public class CourseFullTextApi extends ApiBaseController{
return success(true); return success(true);
} }
/** /**
* 全文检索查询 * 全文检索查询
* @param pager * @param pager
@@ -217,7 +223,7 @@ public class CourseFullTextApi extends ApiBaseController{
* @return * @return
*/ */
@PostMapping("/search") @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 //获取例外人员id
List<String> userId = thirdApi.getUserId(); List<String> userId = thirdApi.getUserId();
@@ -226,6 +232,7 @@ public class CourseFullTextApi extends ApiBaseController{
// String userIds="132,123"; // String userIds="132,123";
//获取没报名课程的id //获取没报名课程的id
String token = request.getHeader("Xboe-Access-Token"); String token = request.getHeader("Xboe-Access-Token");
//
if (StringUtils.isEmpty(token)) { if (StringUtils.isEmpty(token)) {
token = request.getHeader("token"); token = request.getHeader("token");
} }
@@ -317,6 +324,36 @@ public class CourseFullTextApi extends ApiBaseController{
clist=courseService.findStudysScoreByIds(cids); clist=courseService.findStudysScoreByIds(cids);
} }
List<CourseTeacher> teachers = courseService.findTeachersByCourseIds(ids); 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()) { for(CourseFullText c :coursePageList.getList()) {
if(clist!=null) { if(clist!=null) {
@@ -330,7 +367,19 @@ public class CourseFullTextApi extends ApiBaseController{
} }
for(CourseTeacher ct : teachers) { for(CourseTeacher ct : teachers) {
if(ct.getCourseId().equals(c.getId())) { 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; package com.xboe.module.course.api;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.annotation.Resource; import javax.annotation.Resource;
@@ -13,9 +14,11 @@ import com.xboe.api.vo.UserDynamic;
import com.xboe.api.vo.UserdynamicParam; import com.xboe.api.vo.UserdynamicParam;
import com.xboe.common.OrderCondition; import com.xboe.common.OrderCondition;
import com.xboe.core.JsonResponseStatus; import com.xboe.core.JsonResponseStatus;
import com.xboe.module.course.vo.TeacherVo;
import com.xboe.module.usergroup.entity.UserGroupItem; import com.xboe.module.usergroup.entity.UserGroupItem;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; 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.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -86,6 +89,9 @@ public class CoursePortalApi extends ApiBaseController{
@Resource @Resource
private ThirdApi thirdApi; private ThirdApi thirdApi;
@Autowired
StringRedisTemplate redisTemplate;
/** /**
* 根据多个课程id返回对应的课程的图片.返回结果如下, * 根据多个课程id返回对应的课程的图片.返回结果如下,
* { * {
@@ -300,6 +306,18 @@ public class CoursePortalApi extends ApiBaseController{
Teacher t = teacherService.get(ct.getTeacherId()); Teacher t = teacherService.get(ct.getTeacherId());
if(t!=null) { if(t!=null) {
ct.setRemark(t.getDescription()); 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); 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") @GetMapping("/detail-study")
public JsonResponse<List<CourseStudyVo>> detailStudy(String courseId, String aid){ 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 infrasApi.dict=${boe.domain}/infrasApi/dict/getCourseException
#获取非报名课id #获取非报名课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