@@ -5,7 +5,13 @@ import java.time.LocalDateTime;
import java.time.ZoneOffset ;
import java.util.ArrayList ;
import java.util.List ;
import java.util.Map ;
import java.util.stream.Collectors ;
import cn.hutool.core.collection.CollectionUtil ;
import com.xboe.module.course.entity.Course ;
import com.xboe.module.course.service.ICourseService ;
import org.apache.commons.compress.utils.Lists ;
import cn.hutool.core.collection.CollectionUtil ;
import com.alibaba.fastjson2.JSON ;
import com.xboe.core.orm.FieldFilters ;
@@ -15,6 +21,7 @@ import com.xboe.module.course.dto.RankingDto;
import com.xboe.module.course.entity.Course ;
import org.apache.commons.lang3.StringUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.web.bind.annotation.GetMapping ;
import org.springframework.web.bind.annotation.PostMapping ;
import org.springframework.web.bind.annotation.RequestBody ;
@@ -51,8 +58,14 @@ public class StudyCourseESApi extends ApiBaseController{
@Autowired
IStudyCourseService service ;
@Resource
private CourseDao courseDao ;
@Autowired
ICourseService courseService ;
@Value ( " ${xboe.upload.file.http_path} " )
private String httpPath ;
@Value ( " ${xboe.image.course.default} " )
private String defaultCourseImage ;
@Resource
private PhpOnlineStudyRecordScheduledTasks phpOnlineStudyRecordScheduledTasks ;
@@ -66,65 +79,61 @@ public class StudyCourseESApi extends ApiBaseController{
try {
dto . setAccountId ( getCurrent ( ) . getAccountId ( ) ) ;
PageList < CourseStudyDto > rs = search . search ( page . getStartRow ( ) , page . getPageSize ( ) , dto ) ;
List < CourseStudyDto > list = rs . getList ( ) ;
List < String > emptyIds = new ArrayList < > ( ) ;
log . info ( " test data gengxin CourseStudyDto list ==> {} " , JSON . toJSONString ( list ) ) ;
if ( CollectionUtil . isNotEmpty ( list ) ) {
log . info ( " test data gengxin CourseStudyDto isNotEmpty list ==> {} " , JSON . toJSONString ( list ) ) ;
//todo 过滤数据
for ( CourseStudyDto courseStudyDto : list ) {
log . info ( " test data gengxin CourseStudyDto isNotEmpty item ==> {} " , JSON . toJSONString ( courseStudyDto ) ) ;
//在线课 录播课
if ( courseStudyDto . getCourseType ( ) = = 20 | | courseStudyDto . getCourseType ( ) = = 21 ) {
if ( StringUtils . isBlank ( courseStudyDto . getCourseImage ( ) ) ) {
emptyIds . add ( courseStudyDto . getCourseId ( ) ) ;
}
}
}
//todo 图片空返回结果
List < CourseStudyDto > emptyImgCourseStudyDtos = new ArrayList ( ) ;
//在线课查询
if ( CollectionUtil . isNotEmpty ( emptyIds ) ) {
QueryBuilder query = QueryBuilder . from ( Course . class ) ;
query . addFields ( " id " , " name " , " type " , " coverImg " ) ;
//todo 确认下 是否是这个字段
query . addFilter ( FieldFilters . in ( " id " , emptyIds ) ) ;
query . addFilter ( FieldFilters . eq ( " enabled " , true ) ) ;
query . addFilter ( FieldFilters . eq ( " deleted " , false ) ) ;
List < Object [ ] > listFields = courseDao . findListFields ( query . builder ( ) ) ;
log . info ( " test data gengxin CourseStudyDto isNotEmpty listFields ==> {} " , JSON . toJSONString ( listFields ) ) ;
if ( CollectionUtil . isNotEmpty ( listFields ) ) {
for ( Object [ ] objs : listFields ) {
CourseStudyDto CourseStudyDtoResult = new CourseStudyDto ( ) ;
CourseStudyDtoResult . setId ( ( String ) objs [ 0 ] ) ;
CourseStudyDtoResult . setCourseName ( ( String ) objs [ 1 ] ) ;
CourseStudyDtoResult . setCourseType ( ( Integer ) objs [ 2 ] ) ;
CourseStudyDtoResult . setCourseImage ( ( String ) objs [ 3 ] ) ;
emptyImgCourseStudyDtos . add ( CourseStudyDtoResult ) ;
}
}
log . info ( " test data gengxin CourseStudyDto isNotEmpty emptyImgCourseStudyDtos ==> {} " , JSON . toJSONString ( emptyImgCourseStudyDtos ) ) ;
handleCourseImage ( rs ) ;
//todo 进行赋值处理 最外层
emptyImgCourseStudyDtos . forEach ( item - > {
list . forEach ( subjectItem - > {
if ( item . getCourseId ( ) . equals ( subjectItem . getCourseId ( ) ) ) {
//赋值
subjectItem . setCourseImage ( item . getCourseImage ( ) ) ;
}
} ) ;
} ) ;
log . info ( " test data gengxin CourseStudyDto isNotEmpty result ==> {} " , JSON . toJSONString ( list ) ) ;
}
}
return success ( rs ) ;
} catch ( Exception e ) {
log . error ( " 查询报名学习ES失败 " , e ) ;
return error ( " 查询失败 " , e . getMessage ( ) ) ;
}
}
private void handleCourseImage ( PageList < CourseStudyDto > rs ) {
if ( rs = = null | | CollectionUtil . isEmpty ( rs . getList ( ) ) ) {
return ;
}
List < String > emptyImageCourseIds = Lists . newArrayList ( ) ;
for ( CourseStudyDto courseStudyDto : rs . getList ( ) ) {
if ( StringUtils . isBlank ( courseStudyDto . getCourseImage ( ) ) ) {
// 过滤课程类型
if ( courseStudyDto . getCourseType ( ) = = 10
| | courseStudyDto . getCourseType ( ) = = 20 ) {
emptyImageCourseIds . add ( courseStudyDto . getCourseId ( ) ) ;
} else {
log . warn ( " 课程图片为空, 课程id为: {},课程类型:{} " , courseStudyDto . getCourseId ( ) , courseStudyDto . getCourseType ( ) ) ;
}
}
}
if ( CollectionUtil . isEmpty ( emptyImageCourseIds ) ) {
return ;
}
List < Course > courseList = courseService . findByIds ( emptyImageCourseIds ) ;
if ( CollectionUtil . isNotEmpty ( courseList ) ) {
// courseList转换成map
Map < String , Course > courseMap = courseList . stream ( ) . collect ( Collectors . toMap ( Course : : getId , course - > course ) ) ;
// 赋值ES图片
for ( CourseStudyDto courseStudyDto : rs . getList ( ) ) {
if ( emptyImageCourseIds . contains ( courseStudyDto . getCourseId ( ) ) ) {
Course currentCourse = courseMap . get ( courseStudyDto . getCourseId ( ) ) ;
if ( null ! = currentCourse ) {
if ( StringUtils . isNotBlank ( currentCourse . getCoverImg ( ) ) ) {
// 拼接域名
courseStudyDto . setCourseImage ( httpPath + currentCourse . getCoverImg ( ) ) ;
} else {
// 赋值默认图片
courseStudyDto . setCourseImage ( defaultCourseImage ) ;
}
}
}
}
}
}
@RequestMapping ( value = " /list-by-ids " , method = { RequestMethod . POST } )
public JsonResponse < List < StudyCourse > > search ( @RequestBody List < String > ids ) {
if ( ids . isEmpty ( ) ) {