Commit 5edefe51 authored by jiawei's avatar jiawei

BUG修改===》》》修改学习内容展板列表排序问题

parent 5cc29b80
......@@ -189,4 +189,9 @@ public class ExhibitionBoard implements Serializable {
@TableField(exist = false)
private List<Map<String, String>> audioLanguageList;
/**
* 学习类容展板排序加的临时字段,表中不存在
*/
@TableField(exist = false)
private Integer sortorder;
}
......@@ -13,6 +13,7 @@ import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
......@@ -147,5 +148,57 @@ public class LearningContentBoardController extends BaseController {
return getSuccessResult();
}
/**
* 修改后的接口
* 通用排序方法(拖拽排序/所有排序完成后点击保存)
*
* @param sourceId 源实体ID
* @param targetId 目标实体ID
* @return Void
*/
@ApiOperation(value = "根据学习内容id-展板排序")
@PutMapping(value = "/sortById")
@ApiImplicitParams(value = {
@ApiImplicitParam(name = "id", value = "学习内容id", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "sourceId", value = "展板源id", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "targetId", value = "展板目标id", paramType = "query", dataType = "String")
})
@RequiresAuthentication //@RequiresPermissions("learning:content:board:sort")
public Map<String, Object> sortById(String id, String sourceId, String targetId) {
LambdaQueryWrapper<LearningContentBoard> sourceEq = new QueryWrapper<LearningContentBoard>().lambda()
.eq(LearningContentBoard::getLearningContentId, id)
.eq(LearningContentBoard::getExhibitionBoardId, sourceId);
//
LambdaQueryWrapper<LearningContentBoard> targetEq = new QueryWrapper<LearningContentBoard>().lambda()
.eq(LearningContentBoard::getLearningContentId, id)
.eq(LearningContentBoard::getExhibitionBoardId, targetId);
List<LearningContentBoard> theSource = this.learningContentBoardService.list(sourceEq);
List<LearningContentBoard> theTarget = this.learningContentBoardService.list(targetEq);
if (CollectionUtils.isEmpty(theSource) && CollectionUtils.isEmpty(theTarget)) {
return getFailResult("排序展板不存在");
}
//排序字段互换
LearningContentBoard lcbS = theSource.get(0);
LearningContentBoard lcbT = theTarget.get(0);
theSource.stream().forEach(s -> {
s.setSortorder(lcbT.getSortorder());
});
theTarget.stream().forEach(t -> {
t.setSortorder(lcbS.getSortorder());
});
boolean batch = learningContentBoardService.updateBatchById(theSource);
boolean batch1 = learningContentBoardService.updateBatchById(theTarget);
return getSuccessResult();
}
}
......@@ -31,10 +31,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
......@@ -141,9 +138,11 @@ public class LearningContentController extends BaseController {
learningContentBoardQueryWrapper.select("max(sortorder) as sortorder");
LearningContentBoard one = this.learningContentBoardService.getOne(learningContentBoardQueryWrapper);
if (one != null && one.getSortorder() != null) {
learningContent.setSortorder(one.getSortorder() + 1);
// learningContent.setSortorder(one.getSortorder() + 1);
learningContentBoard.setSortorder(one.getSortorder() + 1);
} else {
learningContent.setSortorder(1);
// learningContent.setSortorder(1);
learningContentBoard.setSortorder(1);
}
this.learningContentBoardService.save(learningContentBoard);
}
......@@ -420,10 +419,24 @@ public class LearningContentController extends BaseController {
}
final LambdaQueryWrapper<LearningContentBoard> queryWrapper2 = Wrappers.<LearningContentBoard>lambdaQuery().eq(LearningContentBoard::getLearningContentId, id);
queryWrapper2.select(LearningContentBoard::getExhibitionBoardId);
final List<String> exhibitionBoardIdList = this.learningContentBoardService.listObjs(queryWrapper2, Object::toString);
queryWrapper2.select(LearningContentBoard::getExhibitionBoardId,LearningContentBoard::getSortorder)
.orderByAsc(LearningContentBoard::getSortorder);
final List<LearningContentBoard> exhibitionBoardIdListNew = this.learningContentBoardService.list(queryWrapper2);
final List<String> exhibitionBoardIdList = exhibitionBoardIdListNew.stream().map(LearningContentBoard::getExhibitionBoardId).collect(Collectors.toList());
// final List<String> exhibitionBoardIdList = this.learningContentBoardService.listObjs(queryWrapper2, Object::toString);
if (!exhibitionBoardIdList.isEmpty()) {
final List<ExhibitionBoard> exhibitionBoardList = this.exhibitionBoardService.listByIds(exhibitionBoardIdList);
List<ExhibitionBoard> exhibitionBoardList = this.exhibitionBoardService.listByIds(exhibitionBoardIdList);
//设置sortorder ,然后在排序
exhibitionBoardList.stream().forEach(eb -> {
exhibitionBoardIdListNew.stream().forEach(lcb -> {
if (eb.getId().equals(lcb.getExhibitionBoardId())) {
eb.setSortorder(lcb.getSortorder());
}
});
});
exhibitionBoardList = exhibitionBoardList.stream().sorted(Comparator.comparing(ExhibitionBoard::getSortorder)).collect(Collectors.toList());
if (!exhibitionBoardList.isEmpty()) {
learningContent.setExhibitionBoardIdList(exhibitionBoardList.stream().map(ExhibitionBoard::getId).collect(Collectors.toList()));
learningContent.setExhibitionBoardNameList(exhibitionBoardList.stream().map(ExhibitionBoard::getName).collect(Collectors.toList()));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment