mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-09 19:06:49 +08:00
增加报名学习的ES查询接口
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
package com.xboe.school.study.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.xboe.common.PageList;
|
||||
import com.xboe.common.Pagination;
|
||||
import com.xboe.core.JsonResponse;
|
||||
import com.xboe.core.api.ApiBaseController;
|
||||
import com.xboe.module.course.dto.CourseStudyDto;
|
||||
import com.xboe.module.course.service.ICourseStudySearch;
|
||||
import com.xboe.school.study.entity.StudyCourse;
|
||||
import com.xboe.school.study.service.IStudyCourseService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* ES的课程检索
|
||||
* @author seastar
|
||||
*
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping(value="/xboe/school/study/es")
|
||||
public class StudyCourseESApi extends ApiBaseController{
|
||||
|
||||
@Autowired(required = false)
|
||||
ICourseStudySearch search;
|
||||
|
||||
@Autowired
|
||||
IStudyCourseService service;
|
||||
|
||||
@RequestMapping(value="/search",method = {RequestMethod.GET,RequestMethod.POST})
|
||||
public JsonResponse<PageList<CourseStudyDto>> search(Pagination page, CourseStudyDto dto){
|
||||
if(search==null) {
|
||||
return error("无ES的实现","");
|
||||
}
|
||||
try {
|
||||
PageList<CourseStudyDto> rs=search.search(page.getPageIndex(),page.getPageSize(), dto);
|
||||
return success(rs);
|
||||
}catch(Exception e) {
|
||||
log.error("查询报名学习ES失败",e);
|
||||
return error("查询失败",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/index-create")
|
||||
public JsonResponse<Boolean> createIndex(){
|
||||
if(search==null) {
|
||||
return error("无ES的实现","",false);
|
||||
}
|
||||
try {
|
||||
search.createIndex();
|
||||
return success(true);
|
||||
}catch(Exception e) {
|
||||
log.error("创建索引失败",e);
|
||||
return error("创建索引失败",e.getMessage(),false);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/index-delete")
|
||||
public JsonResponse<Boolean> deleteIndex(){
|
||||
//前端一定要二次询问
|
||||
if(search==null) {
|
||||
return error("无ES的实现","",false);
|
||||
}
|
||||
try {
|
||||
search.deleteIndex();
|
||||
return success(true);
|
||||
}catch(Exception e) {
|
||||
log.error("删除索引失败",e);
|
||||
return error("删除索引失败",e.getMessage(),false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化课程学习数据
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/init")
|
||||
public JsonResponse<Boolean> init(){
|
||||
if(search==null) {
|
||||
return error("无ES的实现","",false);
|
||||
}
|
||||
//按分页初始化
|
||||
int pageIndex=1;
|
||||
int pageSize=1000;
|
||||
int total=1001;
|
||||
while(total>pageIndex*pageSize) {
|
||||
PageList<StudyCourse> result = service.findPage(pageIndex,pageSize, null, null, null);
|
||||
pageIndex++;
|
||||
total=result.getCount();
|
||||
for(StudyCourse sc : result.getList()) {
|
||||
CourseStudyDto dto=new CourseStudyDto();
|
||||
dto.setId(sc.getId());
|
||||
dto.setAccountId(sc.getAid());
|
||||
dto.setCourseId(sc.getCourseId());
|
||||
dto.setCourseImage(sc.getCourseImage());
|
||||
dto.setCourseName(sc.getCourseName());
|
||||
dto.setCourseType(sc.getCourseType());
|
||||
dto.setProgress(sc.getProgress()==null? 0:sc.getProgress().intValue());
|
||||
dto.setSource(2);//固定值,新系统
|
||||
dto.setStartTime(sc.getStartTime().toEpochSecond(ZoneOffset.of("+8")));
|
||||
dto.setStatus(sc.getStatus());
|
||||
try {
|
||||
search.publishOrUpdate(dto, null);
|
||||
} catch (IOException e) {
|
||||
log.error("ES发布课程学习【"+sc.getAname()+","+sc.getCourseName()+"】失败",e);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return success(true);
|
||||
}
|
||||
}
|
||||
@@ -221,10 +221,10 @@ public class StudyCourseServiceImpl implements IStudyCourseService{
|
||||
query.addFilter(FieldFilters.eq("c.deleted",false));
|
||||
|
||||
query.addField("sc");
|
||||
// 先写死
|
||||
// if(oc!=null) {
|
||||
// oc=OrderCondition.desc("sc.id");
|
||||
// }
|
||||
|
||||
if(oc==null) {
|
||||
oc=OrderCondition.desc("sc.addTime");
|
||||
}
|
||||
query.addOrder(oc);
|
||||
if(sc!=null) {
|
||||
if(StringUtils.isNotBlank(sc.getCourseName())) {
|
||||
|
||||
Reference in New Issue
Block a user