Skip to content

Commit

Permalink
修改根据sort查被移动步骤为根据主键id来查
Browse files Browse the repository at this point in the history
  • Loading branch information
YeungHoiChiu committed Jun 26, 2024
1 parent 7733410 commit c6844f1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public class StepSort implements Serializable {
private Integer newParentId;
@Schema(description = "更换分组后在新分组中新的index", required = false, example = "1")
private Integer newIndex;
@Schema(description = "移动步骤的sort序号", required = false, example = "1")
private Integer thisSort;
@Schema(description = "被移动步骤的主键id", required = false, example = "1")
private Integer stepsId;

public Integer getThisSort() {
return thisSort;
public Integer getStepsId() {
return stepsId;
}

public void setThisSort(Integer thisSort) {
this.thisSort = thisSort;
public void setStepsId(Integer stepsId) {
this.stepsId = stepsId;
}

public Integer getNewIndex() {
Expand Down Expand Up @@ -92,7 +92,7 @@ public String toString() {
", endId=" + endId +
", newParentId=" + newParentId +
", newIndex=" + newIndex +
", thisSort=" + thisSort +
", stepsId=" + stepsId +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,41 +281,46 @@ public void sortSteps(StepSort stepSort) {
saveOrUpdateBatch(stepsList);
}

/**
* 拖拽步骤顺序,步骤所在分组发生变化时,仅对新分组以及移动步骤的sort进行重新排序
* @param stepSort
* @return
*/
private List<Steps> exchangeAddedStepSort(StepSort stepSort) {
// 获取case全部步骤
List<Steps> stepsList = lambdaQuery().eq(Steps::getCaseId, stepSort.getCaseId()).orderByAsc(Steps::getSort).list();
// 移动新分组内的原本存在的子步骤
List<Steps> groupStepList = stepsList.stream().filter(steps -> Objects.equals(steps.getParentId(), stepSort.getNewParentId())).collect(Collectors.toList());
// 获取新分组的case步骤
List<Steps> stepsList = lambdaQuery().eq(Steps::getCaseId, stepSort.getCaseId()).eq(Steps::getParentId, stepSort.getNewParentId()).list();
// 被移动的步骤实例
Steps movedStep = stepsList.stream().filter(steps -> Objects.equals(steps.getSort(), stepSort.getThisSort())).findFirst().orElse(null);
Steps movedStep = lambdaQuery().eq(Steps::getId, stepSort.getStepsId()).eq(Steps::getCaseId, stepSort.getCaseId()).one();
if(movedStep == null){
throw new SonicException("case中未能获取到该Sort: %s", stepSort.getThisSort());
throw new SonicException("case中未能获取到该id的数据: %s", stepSort.getStepsId());
}
movedStep.setParentId(stepSort.getNewParentId()); // 更新父步骤id
groupStepList.add(movedStep); // 添加到组内列表
if (groupStepList.size() == 1){
// 原本没有子步骤,直接更改父id就好了,不用重新排序
stepSort.setEndId(stepSort.getThisSort()) ;
stepSort.setStartId(stepSort.getThisSort());
stepsList.add(movedStep); // 添加到组内列表
if (stepsList.size() == 1){
// 原本没有子步骤,直接更改父id就好了,没必要重新排序
stepSort.setEndId(movedStep.getSort()) ;
stepSort.setStartId(movedStep.getSort());
stepSort.setDirection("down");
return stepsList;
}else {
groupStepList = groupStepList.stream().sorted(Comparator.comparingInt(Steps::getSort)).collect(Collectors.toList()); // 将所有子步骤包含新加入的步骤重新排序
if (groupStepList.get(stepSort.getNewIndex()).getSort() >= stepSort.getThisSort()){
// 将所有子步骤包含新加入的步骤重新排序,这样就相当于在同一个分组内拖拽排序
List<Steps> groupStepList = stepsList.stream().sorted(Comparator.comparingInt(Steps::getSort)).collect(Collectors.toList());
if (groupStepList.get(stepSort.getNewIndex()).getSort() >= movedStep.getSort()){
stepSort.setDirection("down");
stepSort.setStartId(groupStepList.get(stepSort.getNewIndex()).getSort());
stepSort.setEndId(stepSort.getThisSort());
stepSort.setEndId(movedStep.getSort());
}else {
stepSort.setDirection("up");
stepSort.setStartId(stepSort.getThisSort());
stepSort.setStartId(movedStep.getSort());
stepSort.setEndId(groupStepList.get(stepSort.getNewIndex()).getSort());
}
// 取出需要重新排序的步骤
groupStepList = groupStepList.stream().filter(
steps -> steps.getSort() >= stepSort.getEndId()
&& steps.getSort() <= stepSort.getStartId())
.collect(Collectors.toList());
return groupStepList;
}
return groupStepList;
}

@Override
Expand Down

0 comments on commit c6844f1

Please sign in to comment.