fix: 【FCJDFDXTXS-87】修正置顶时对es的修改逻辑

This commit is contained in:
liu.zixi
2025-12-13 15:40:06 +08:00
committed by liuzixi
parent efb3b49603
commit 2ac77e7cc9
2 changed files with 18 additions and 2 deletions

View File

@@ -158,6 +158,7 @@ public class CoursePageServiceImpl implements ICoursePageService {
public ServiceResponse<Boolean> top(String courseId, boolean top) {
// 1. 查询课程数据
Course course = courseDao.get(courseId);
Map<String, Object> fieldMap = new HashMap<>();
if (top) {
// 2. 执行置顶操作
// 2.1 目前课程是否已置顶
@@ -172,10 +173,14 @@ public class CoursePageServiceImpl implements ICoursePageService {
return ServiceResponse.failure("最多只能置顶10个课程");
}
// 2.3 设置置顶
LocalDateTime now = LocalDateTime.now();
courseDao.updateMultiFieldById(courseId,
UpdateBuilder.create("isTop", top),
UpdateBuilder.create("topTime", LocalDateTime.now()),
UpdateBuilder.create("topTime", now),
UpdateBuilder.create("sortWeight", 0));
fieldMap.put("isTop", 1);
fieldMap.put("topTime", now);
fieldMap.put("sortWeight", 0);
} else {
// 3. 取消置顶
// 3.1 课程是否已置顶
@@ -189,12 +194,14 @@ public class CoursePageServiceImpl implements ICoursePageService {
UpdateBuilder.create("isTop", top),
UpdateBuilder.create("topTime", null),
UpdateBuilder.create("sortWeight", 9999));
fieldMap.put("isTop", 0);
fieldMap.put("sortWeight", 9999);
}
// ES同步
if (this.fullTextSearch != null) {
Object fullId = courseDao.findField("fullTextId", FieldFilters.eq("id", courseId));
if (fullId != null) {
publishUtil.updateFieldByDocId((String) fullId, "isTop", top ? 1 : 0);
publishUtil.updateFieldByDocId((String) fullId, fieldMap);
}
}
return ServiceResponse.success(true);

View File

@@ -2,6 +2,7 @@ package com.xboe.module.course.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
@@ -122,6 +123,14 @@ public class PublishCourseUtil {
log.error("更新全文索引字段错误",e);
}
}
public void updateFieldByDocId(String docId, Map<String, Object> fieldMap) {
try {
fullTextSearch.updateFields(ICourseFullTextSearch.DEFAULT_INDEX_NAME, fieldMap, docId);
}catch(Exception e) {
log.error("更新全文索引字段错误",e);
}
}
public void removeByDocId(String docId){
if(fullTextSearch==null) {