|
@@ -1,7 +1,9 @@
|
|
|
|
|
|
package com.redxun.knowledge.service;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.redxun.common.base.db.BaseDao;
|
|
|
import com.redxun.common.base.db.BaseService;
|
|
|
import com.redxun.common.base.search.QueryFilter;
|
|
@@ -10,6 +12,7 @@ import com.redxun.common.tool.IdGenerator;
|
|
|
import com.redxun.common.service.impl.SuperServiceImpl;
|
|
|
import com.redxun.common.tool.StringUtils;
|
|
|
import com.redxun.knowledge.common.UserService;
|
|
|
+import com.redxun.knowledge.entity.dao.Banner;
|
|
|
import com.redxun.knowledge.entity.dao.Knowledge;
|
|
|
import com.redxun.knowledge.entity.dao.KnowledgeLabel;
|
|
|
import com.redxun.knowledge.entity.vo.BannerAdminVo;
|
|
@@ -19,6 +22,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
/**
|
|
@@ -81,4 +85,46 @@ public class KnowledgeLabelServiceImpl extends SuperServiceImpl<KnowledgeLabelMa
|
|
|
|
|
|
return page;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 调整知识标签排序位置
|
|
|
+ *
|
|
|
+ * @param labelId 标签ID
|
|
|
+ * @param status true 上升 false 下降
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void exchangePosition(String labelId, Boolean status) {
|
|
|
+ KnowledgeLabel label = get(labelId);
|
|
|
+ if (label == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Integer sort = label.getSort();
|
|
|
+ KnowledgeLabel labelTarget = null;
|
|
|
+ List<KnowledgeLabel> labels = knowledgeLabelMapper.selectList(new QueryWrapper<KnowledgeLabel>().eq("IS_DEL", 0).orderByAsc("SORT"));
|
|
|
+ if (status) {
|
|
|
+ // 上升
|
|
|
+ List<KnowledgeLabel> collect = labels.stream().filter(e -> e.getSort() < sort).collect(Collectors.toList());
|
|
|
+ if (ObjectUtils.isNotEmpty(collect)) {
|
|
|
+ labelTarget = collect.get(collect.size() - 1);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 下降
|
|
|
+ List<KnowledgeLabel> collect = labels.stream().filter(e -> e.getSort() > sort).collect(Collectors.toList());
|
|
|
+ if (ObjectUtils.isNotEmpty(collect)) {
|
|
|
+ labelTarget = collect.get(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 交换位置
|
|
|
+ if (labelTarget != null) {
|
|
|
+ knowledgeLabelMapper.updateSort(labelId, labelTarget.getSort());
|
|
|
+ knowledgeLabelMapper.updateSort(labelTarget.getPkId(), sort);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public String delLabel(String labelId) {
|
|
|
+ knowledgeLabelMapper.delLabel(labelId);
|
|
|
+ return labelId;
|
|
|
+ }
|
|
|
}
|