|
|
@@ -211,45 +211,56 @@ public class CostProjectTaskMaterialSummaryManagerImpl extends BaseManagerImpl<C
|
|
|
}
|
|
|
|
|
|
String taskId = current.getTaskId();
|
|
|
- Integer currentOrderNum = current.getMaterialOrderNum() != null ? current.getMaterialOrderNum() : 0;
|
|
|
|
|
|
- // 查询同任务下的其他记录
|
|
|
+ // 查询同任务下的所有记录,按序号和ID排序
|
|
|
LambdaQueryWrapper<CostProjectTaskMaterialSummary> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(CostProjectTaskMaterialSummary::getTaskId, taskId)
|
|
|
- .ne(CostProjectTaskMaterialSummary::getId, id)
|
|
|
- .orderByAsc(CostProjectTaskMaterialSummary::getMaterialOrderNum);
|
|
|
-
|
|
|
- List<CostProjectTaskMaterialSummary> otherList = this.list(queryWrapper);
|
|
|
-
|
|
|
- if ("down".equals(direction)) {
|
|
|
- // 下移:找到比当前orderNum大的最小orderNum的记录,交换
|
|
|
- CostProjectTaskMaterialSummary next = otherList.stream()
|
|
|
- .filter(s -> s.getMaterialOrderNum() != null && s.getMaterialOrderNum() > currentOrderNum)
|
|
|
- .min(java.util.Comparator.comparing(CostProjectTaskMaterialSummary::getMaterialOrderNum))
|
|
|
- .orElse(null);
|
|
|
-
|
|
|
- if (next != null) {
|
|
|
- Integer temp = current.getMaterialOrderNum();
|
|
|
- current.setMaterialOrderNum(next.getMaterialOrderNum());
|
|
|
- next.setMaterialOrderNum(temp);
|
|
|
- this.updateById(current);
|
|
|
- this.updateById(next);
|
|
|
- }
|
|
|
- } else if ("up".equals(direction)) {
|
|
|
- // 上移:找到比当前orderNum小的最大orderNum的记录,交换
|
|
|
- CostProjectTaskMaterialSummary prev = otherList.stream()
|
|
|
- .filter(s -> s.getMaterialOrderNum() != null && s.getMaterialOrderNum() < currentOrderNum)
|
|
|
- .max(java.util.Comparator.comparing(CostProjectTaskMaterialSummary::getMaterialOrderNum))
|
|
|
- .orElse(null);
|
|
|
-
|
|
|
- if (prev != null) {
|
|
|
- Integer temp = current.getMaterialOrderNum();
|
|
|
- current.setMaterialOrderNum(prev.getMaterialOrderNum());
|
|
|
- prev.setMaterialOrderNum(temp);
|
|
|
- this.updateById(current);
|
|
|
- this.updateById(prev);
|
|
|
+ .orderByAsc(CostProjectTaskMaterialSummary::getMaterialOrderNum)
|
|
|
+ .orderByAsc(CostProjectTaskMaterialSummary::getId);
|
|
|
+ List<CostProjectTaskMaterialSummary> list = this.list(queryWrapper);
|
|
|
+
|
|
|
+ // 找到当前位置
|
|
|
+ int currentIndex = -1;
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ if (list.get(i).getId().equals(id)) {
|
|
|
+ currentIndex = i;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
+ if (currentIndex == -1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取最大序号作为临时序号
|
|
|
+ Integer tempOrderNum = list.stream()
|
|
|
+ .filter(s -> s.getMaterialOrderNum() != null)
|
|
|
+ .map(CostProjectTaskMaterialSummary::getMaterialOrderNum)
|
|
|
+ .max(Integer::compareTo)
|
|
|
+ .orElse(0) + 10000;
|
|
|
+
|
|
|
+ if ("down".equals(direction) && currentIndex < list.size() - 1) {
|
|
|
+ // 下移:与下一个交换
|
|
|
+ CostProjectTaskMaterialSummary next = list.get(currentIndex + 1);
|
|
|
+ Integer currentOrder = current.getMaterialOrderNum();
|
|
|
+ Integer nextOrder = next.getMaterialOrderNum();
|
|
|
+ current.setMaterialOrderNum(tempOrderNum);
|
|
|
+ this.updateById(current);
|
|
|
+ next.setMaterialOrderNum(currentOrder);
|
|
|
+ this.updateById(next);
|
|
|
+ current.setMaterialOrderNum(nextOrder);
|
|
|
+ this.updateById(current);
|
|
|
+ } else if ("up".equals(direction) && currentIndex > 0) {
|
|
|
+ // 上移:与上一个交换
|
|
|
+ CostProjectTaskMaterialSummary prev = list.get(currentIndex - 1);
|
|
|
+ Integer currentOrder = current.getMaterialOrderNum();
|
|
|
+ Integer prevOrder = prev.getMaterialOrderNum();
|
|
|
+ current.setMaterialOrderNum(tempOrderNum);
|
|
|
+ this.updateById(current);
|
|
|
+ prev.setMaterialOrderNum(currentOrder);
|
|
|
+ this.updateById(prev);
|
|
|
+ current.setMaterialOrderNum(prevOrder);
|
|
|
+ this.updateById(current);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|