mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-09 02:46:50 +08:00
提交ES的修改
This commit is contained in:
@@ -79,9 +79,6 @@ public class CourseFullTextApi extends ApiBaseController{
|
||||
for(int i=0;i<crowds.size();i++) {
|
||||
crowdIds[i]=crowds.get(i).getGroupId();
|
||||
}
|
||||
if(crowdIds.length>1) {
|
||||
System.out.println("课程["+cft.getName()+"]内容:"+crowdIds[0]+","+crowdIds[1]);
|
||||
}
|
||||
//String audienceIds=StringUtils.join(crowdIds,",");
|
||||
//log.info("受众信息",audienceIds);
|
||||
//cft.setAudience(audienceIds);
|
||||
@@ -107,6 +104,82 @@ public class CourseFullTextApi extends ApiBaseController{
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/delete-by-id")
|
||||
public JsonResponse<Boolean> deleteById(String id) throws Exception{
|
||||
if(fullTextSearch==null){
|
||||
return error("初始化失败:未实现全文检索功能");
|
||||
}
|
||||
if(StringUtils.isBlank(id)) {
|
||||
return error("未指定id");
|
||||
}
|
||||
try {
|
||||
boolean ok=fullTextSearch.deleteById(ICourseFullTextSearch.DEFAULT_INDEX_NAME, id);
|
||||
return success(ok);
|
||||
}catch(Exception e) {
|
||||
log.error("根据课程id删除全文检索课程失败",e);
|
||||
return error("删除失败",e.getMessage());
|
||||
}
|
||||
}
|
||||
@PostMapping("/republish")
|
||||
public JsonResponse<Boolean> republish(String id) throws Exception{
|
||||
|
||||
if(fullTextSearch==null) {
|
||||
return error("初始化失败:未实现全文检索功能");
|
||||
}
|
||||
if(StringUtils.isBlank(id)) {
|
||||
return error("未指定id");
|
||||
}
|
||||
//提取课程信息,因为现在课程没有太多,所以一次性全部查出来,
|
||||
Course c =courseService.get(id);
|
||||
if(c.getPublished()==null || !c.getPublished()) {
|
||||
return error("此课程还未发布,请发布课程,不用在这里重新发布");
|
||||
}
|
||||
|
||||
CourseFullText cft=CourseToCourseFullText.convert(c);
|
||||
try {
|
||||
//计算课程时长
|
||||
int duration=ccourseService.sumDurationByCourseId(c.getId());
|
||||
cft.setDuration(duration);
|
||||
|
||||
//查询教师
|
||||
CourseTeacherDto teacherDto = courseTeacherService.getTeacherByCourseId(c.getId());
|
||||
if(teacherDto!=null && !teacherDto.getNames().isEmpty()) {
|
||||
cft.setTeacher(StringUtils.join(teacherDto.getNames(),","));
|
||||
}
|
||||
//查询课程受众
|
||||
List<CourseCrowd> crowds = courseService.findCrowdByCourseId(c.getId());
|
||||
if(crowds!=null && !crowds.isEmpty()) {
|
||||
String[] crowdIds=new String[crowds.size()];
|
||||
for(int i=0;i<crowds.size();i++) {
|
||||
crowdIds[i]=crowds.get(i).getGroupId();
|
||||
}
|
||||
// if(crowdIds.length>1) {
|
||||
// log.info("课程["+cft.getName()+"]内容:"+crowdIds[0]+","+crowdIds[1]);
|
||||
// }
|
||||
//String audienceIds=StringUtils.join(crowdIds,",");
|
||||
//log.info("受众信息",audienceIds);
|
||||
//cft.setAudience(audienceIds);
|
||||
cft.setAudiences(crowdIds);
|
||||
cft.setIsSetAudience(1);//有受众
|
||||
}else {
|
||||
cft.setIsSetAudience(0);//无受众
|
||||
}
|
||||
|
||||
String fullTextId=fullTextSearch.republish(ICourseFullTextSearch.DEFAULT_INDEX_NAME, cft,c.getFullTextId());
|
||||
log.info("发布课程全文检索成功:"+fullTextId);
|
||||
c.setFullTextId(fullTextId);
|
||||
if(StringUtils.isNotBlank(fullTextId)) {
|
||||
courseService.updateFieldById(c.getId(),"fullTextId", fullTextId);
|
||||
}
|
||||
|
||||
}catch(Exception e) {
|
||||
log.error("发布课程【"+c.getName()+"("+c.getId()+")】全文检索及更新数据库失败",e);
|
||||
return error("重新发布失败",e.getMessage());
|
||||
}
|
||||
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 全文检索查询
|
||||
|
||||
@@ -460,7 +460,7 @@ public class CourseServiceImpl implements ICourseService {
|
||||
|
||||
if(StringUtils.isNotBlank(course.getFullTextId())) {
|
||||
try {
|
||||
fullTextSearch.remove(ICourseFullTextSearch.DEFAULT_INDEX_NAME,course.getFullTextId());
|
||||
fullTextSearch.removeByDocId(ICourseFullTextSearch.DEFAULT_INDEX_NAME,course.getFullTextId());
|
||||
} catch (Exception e) {
|
||||
//log.error("删除课程时删除全文索引错误",e);
|
||||
}
|
||||
@@ -484,7 +484,7 @@ public class CourseServiceImpl implements ICourseService {
|
||||
//删除分两种情况,一个是管理员删除,一个是自己删除 ,所以这里的处理移到前端了
|
||||
if(c.getFullTextId()!=null) {
|
||||
try {
|
||||
fullTextSearch.remove(ICourseFullTextSearch.DEFAULT_INDEX_NAME,c.getFullTextId());
|
||||
fullTextSearch.removeByDocId(ICourseFullTextSearch.DEFAULT_INDEX_NAME,c.getFullTextId());
|
||||
}catch(Exception e) {
|
||||
log.error("删除课程时删除全文索引错误",e);
|
||||
}
|
||||
@@ -661,7 +661,7 @@ public class CourseServiceImpl implements ICourseService {
|
||||
//更新后需要删除发布
|
||||
if(StringUtils.isNotBlank(c.getFullTextId())) {
|
||||
try {
|
||||
fullTextSearch.remove(ICourseFullTextSearch.DEFAULT_INDEX_NAME,c.getFullTextId());
|
||||
fullTextSearch.removeByDocId(ICourseFullTextSearch.DEFAULT_INDEX_NAME,c.getFullTextId());
|
||||
} catch (Exception e) {
|
||||
//log.error("删除课程时删除全文索引错误",e);
|
||||
}
|
||||
@@ -903,7 +903,7 @@ public class CourseServiceImpl implements ICourseService {
|
||||
Object fullId=courseDao.findField("fullTextId", FieldFilters.eq("id", id));
|
||||
if(fullId!=null) {
|
||||
try {
|
||||
fullTextSearch.remove(ICourseFullTextSearch.DEFAULT_INDEX_NAME, (String)fullId);
|
||||
fullTextSearch.removeByDocId(ICourseFullTextSearch.DEFAULT_INDEX_NAME, (String)fullId);
|
||||
}catch(Exception e) {
|
||||
log.error("更新全文索引字段错误",e);
|
||||
}
|
||||
@@ -953,7 +953,7 @@ public class CourseServiceImpl implements ICourseService {
|
||||
Object fullId=courseDao.findField("fullTextId", FieldFilters.eq("id", id));
|
||||
if(fullId!=null) {
|
||||
try {
|
||||
fullTextSearch.remove(ICourseFullTextSearch.DEFAULT_INDEX_NAME, (String)fullId);
|
||||
fullTextSearch.removeByDocId(ICourseFullTextSearch.DEFAULT_INDEX_NAME, (String)fullId);
|
||||
}catch(Exception e) {
|
||||
log.error("停用,从索引中删除课程失败",e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user