mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-25 02:32:57 +08:00
fix: 【FCJDFDXTXS-186】修改置顶逻辑
This commit is contained in:
@@ -158,7 +158,6 @@ 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 目前课程是否已置顶
|
||||
@@ -167,21 +166,26 @@ public class CoursePageServiceImpl implements ICoursePageService {
|
||||
return ServiceResponse.failure("已置顶");
|
||||
}
|
||||
// 2.2 查看置顶列表数量
|
||||
IFieldFilter fieldFilter = FieldFilters.eq("isTop", true);
|
||||
int topCount = courseDao.count(fieldFilter);
|
||||
List<CoursePageVo> topList = topList();
|
||||
int topCount = topList.size();
|
||||
if (topCount >= 10) {
|
||||
return ServiceResponse.failure("最多只能置顶10个课程");
|
||||
}
|
||||
// 2.3 设置置顶
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
courseDao.updateMultiFieldById(courseId,
|
||||
UpdateBuilder.create("isTop", top),
|
||||
UpdateBuilder.create("topTime", now),
|
||||
UpdateBuilder.create("sortWeight", 0));
|
||||
fieldMap.put("isTop", 1);
|
||||
fieldMap.put("topTime", now);
|
||||
fieldMap.put("sortWeight", 0);
|
||||
CoursePageVo thisVo = new CoursePageVo();
|
||||
thisVo.setId(courseId);
|
||||
thisVo.setIsTop(true);
|
||||
thisVo.setSortWeight(0);
|
||||
List<CoursePageVo> newTopList = new ArrayList<>();
|
||||
newTopList.add(thisVo);
|
||||
for (int i = 0; i < topList.size(); i++) {
|
||||
CoursePageVo vo = topList.get(i);
|
||||
vo.setSortWeight(i + 1);
|
||||
newTopList.add(vo);
|
||||
}
|
||||
topListSortChange(newTopList);
|
||||
} else {
|
||||
Map<String, Object> fieldMap = new HashMap<>();
|
||||
// 3. 取消置顶
|
||||
// 3.1 课程是否已置顶
|
||||
if (course.getIsTop() == null || !course.getIsTop()) {
|
||||
@@ -196,12 +200,9 @@ public class CoursePageServiceImpl implements ICoursePageService {
|
||||
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, fieldMap);
|
||||
// ES同步
|
||||
if (this.fullTextSearch != null) {
|
||||
publishUtil.updateFieldByDocId(course.getFullTextId(), fieldMap);
|
||||
}
|
||||
}
|
||||
return ServiceResponse.success(true);
|
||||
@@ -212,12 +213,14 @@ public class CoursePageServiceImpl implements ICoursePageService {
|
||||
// 1. 按sortWeight升序排序
|
||||
topList.sort(Comparator.comparingInt(CoursePageVo::getSortWeight));
|
||||
// 2. 更新
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
for (int i = 0, len = topList.size(); i < len; i++) {
|
||||
CoursePageVo vo = topList.get(i);
|
||||
String id = vo.getId();
|
||||
Map<String, Object> fieldMap = new HashMap<>();
|
||||
courseDao.updateMultiFieldById(id,
|
||||
UpdateBuilder.create("isTop", true),
|
||||
UpdateBuilder.create("topTime", now),
|
||||
UpdateBuilder.create("sortWeight", i));
|
||||
fieldMap.put("isTop", 1);
|
||||
fieldMap.put("sortWeight", i);
|
||||
|
||||
Reference in New Issue
Block a user