mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-07 01:46:47 +08:00
学习课程ES相关的修改
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package com.xboe.school.study.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -42,7 +45,7 @@ public class StudyCourseESApi extends ApiBaseController{
|
||||
return error("无ES的实现","");
|
||||
}
|
||||
try {
|
||||
PageList<CourseStudyDto> rs=search.search(page.getPageIndex(),page.getPageSize(), dto);
|
||||
PageList<CourseStudyDto> rs=search.search(page.getStartRow(),page.getPageSize(), dto);
|
||||
return success(rs);
|
||||
}catch(Exception e) {
|
||||
log.error("查询报名学习ES失败",e);
|
||||
@@ -60,7 +63,7 @@ public class StudyCourseESApi extends ApiBaseController{
|
||||
return success(true);
|
||||
}catch(Exception e) {
|
||||
log.error("创建索引失败",e);
|
||||
return error("创建索引失败",e.getMessage(),false);
|
||||
return error("创建索引失败:"+e.getMessage(),e.getMessage(),false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +78,25 @@ public class StudyCourseESApi extends ApiBaseController{
|
||||
return success(true);
|
||||
}catch(Exception e) {
|
||||
log.error("删除索引失败",e);
|
||||
return error("删除索引失败",e.getMessage(),false);
|
||||
return error("删除索引失败:"+e.getMessage(),e.getMessage(),false);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/delete-by-esid")
|
||||
public JsonResponse<Boolean> deleteByDocId(String esid){
|
||||
//前端一定要二次询问
|
||||
if(search==null) {
|
||||
return error("无ES的实现","",false);
|
||||
}
|
||||
if(StringUtils.isBlank(esid)) {
|
||||
return badRequest("未指定ESId");
|
||||
}
|
||||
try {
|
||||
search.removeByDocId(esid);
|
||||
return success(true);
|
||||
}catch(Exception e) {
|
||||
log.error("删除ES学习课程错误",e);
|
||||
return error("删除失败:"+e.getMessage(),e.getMessage(),false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,6 +109,7 @@ public class StudyCourseESApi extends ApiBaseController{
|
||||
if(search==null) {
|
||||
return error("无ES的实现","",false);
|
||||
}
|
||||
LocalDateTime now=LocalDateTime.now();
|
||||
//按分页初始化
|
||||
int pageIndex=1;
|
||||
int pageSize=1000;
|
||||
@@ -106,7 +128,11 @@ public class StudyCourseESApi extends ApiBaseController{
|
||||
dto.setCourseType(sc.getCourseType());
|
||||
dto.setProgress(sc.getProgress()==null? 0:sc.getProgress().intValue());
|
||||
dto.setSource(2);//固定值,新系统
|
||||
dto.setStartTime(sc.getStartTime().toEpochSecond(ZoneOffset.of("+8")));
|
||||
if(sc.getStartTime()!=null) {
|
||||
dto.setStartTime(sc.getStartTime().toEpochSecond(ZoneOffset.of("+8")));
|
||||
}else {
|
||||
dto.setStartTime(now.toEpochSecond(ZoneOffset.of("+8")));
|
||||
}
|
||||
dto.setStatus(sc.getStatus());
|
||||
try {
|
||||
search.publishOrUpdate(dto, null);
|
||||
|
||||
@@ -36,6 +36,14 @@ public interface IStudyCourseService {
|
||||
*/
|
||||
StudyCourse findByCourseIdAndAid(String courseId,String aid);
|
||||
|
||||
/**
|
||||
* 为ES初始化的处理
|
||||
* @param pageIndex
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
PageList<StudyCourse> findByES(int pageIndex,int pageSize) throws Exception;
|
||||
|
||||
/**
|
||||
* 分页查询课程学习记录,用户的课程学习记录
|
||||
* @param pageIndex
|
||||
|
||||
@@ -666,4 +666,28 @@ public class StudyCourseServiceImpl implements IStudyCourseService{
|
||||
return sc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageList<StudyCourse> findByES(int pageIndex, int pageSize) throws Exception {
|
||||
QueryBuilder query=QueryBuilder.from(StudyCourse.class.getSimpleName()+" sc,"+ Course.class.getSimpleName()+" c");
|
||||
query.addField("sc");
|
||||
query.addField("c.coverImg");
|
||||
query.setPageIndex(pageIndex);
|
||||
query.setPageSize(pageSize);
|
||||
query.addFilter(FieldFilters.eqField("sc.courseId","c.id"));
|
||||
query.addFilter(FieldFilters.eq("c.enabled",true));
|
||||
query.addFilter(FieldFilters.eq("c.deleted",false));
|
||||
List<StudyCourse> rslist=new ArrayList<StudyCourse>();
|
||||
PageList<Object[]> list=studyCourseDao.findPageFields(query.builder());
|
||||
for(Object[] objs : list.getList()) {
|
||||
StudyCourse sc=(StudyCourse)objs[0];
|
||||
sc.setCourseImage((String)objs[1]);
|
||||
rslist.add(sc);
|
||||
}
|
||||
PageList<StudyCourse> rs=new PageList<StudyCourse>();
|
||||
rs.setCount(list.getCount());
|
||||
rs.setPageSize(pageSize);
|
||||
rs.setList(rslist);
|
||||
return rs;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user