diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/flow/CaseFlowServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/flow/CaseFlowServiceImpl.java index 2bc0181..7c16bf0 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/flow/CaseFlowServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/flow/CaseFlowServiceImpl.java @@ -223,13 +223,49 @@ public class CaseFlowServiceImpl implements CaseFlowService { @Override public Boolean sortCaseFlow(MsCaseFlowSearchVO caseFlowVO) { if (caseFlowVO != null && caseFlowVO.getId() != null && caseFlowVO.getSortType() != null) { + //升序查询所有案件流程信息 + Example example = new Example(MsCaseFlow.class); + example.setOrderByClause(" sort ASC"); + List msCaseFlows = msCaseFlowMapper.selectByExample(example); + if (msCaseFlows == null || msCaseFlows.size() == 0 || msCaseFlows.size() == 1) { + return false; + } + //查找出要调整顺序的这行数据在集合的下标是多少 + int currentIndex = 0; + for (int i = 0; i < msCaseFlows.size(); i++) { + if (msCaseFlows.get(i).getId().equals(caseFlowVO.getId())) { + currentIndex = i; + break; + } + } if (caseFlowVO.getSortType() == 0) { - //降序 - - return true; + //降序(序号加1) + if (currentIndex == msCaseFlows.size() - 1) { + return false; + } else { + int nextIndex = currentIndex + 1; + MsCaseFlow current = msCaseFlows.get(currentIndex); + current.setSort(current.getSort() + 1); + MsCaseFlow next = msCaseFlows.get(nextIndex); + next.setSort(next.getSort() - 1); + msCaseFlowMapper.updateByPrimaryKeySelective(current); + msCaseFlowMapper.updateByPrimaryKeySelective(next); + return true; + } } else if (caseFlowVO.getSortType() == 1) { - //升序 - return true; + //升序(序号减1) + if (currentIndex == 0) { + return false; + } else { + int lastIndex = currentIndex - 1; + MsCaseFlow current = msCaseFlows.get(currentIndex); + current.setSort(current.getSort() - 1); + MsCaseFlow last = msCaseFlows.get(lastIndex); + last.setSort(last.getSort() + 1); + msCaseFlowMapper.updateByPrimaryKeySelective(current); + msCaseFlowMapper.updateByPrimaryKeySelective(last); + return true; + } } } return false;