美文网首页
Java排序上下移

Java排序上下移

作者: 尼尔君 | 来源:发表于2020-08-08 01:01 被阅读0次
    
        final  Integer DOWN = 1;
        final  Integer UP = -1;
    
    
        @Override
        public List orderHandler(Long id, Integer downOrUp){
    
            SysRouter current = new SysRouter();
            current.setId(id);
    
            current.setStatus(1);
            current = queryOne(current);
    
            if(Objects.isNull(current)){
                return queryRouter();
            }
            SysRouter neighbour = new SysRouter();
            neighbour.setParentId(current.getParentId());
    
            if(Objects.equals(downOrUp,DOWN)){
    
                neighbour.setOrderNum(current.getOrderNum()+DOWN);
                SysRouter sysRouter = queryOne(neighbour);
                if(Objects.nonNull(sysRouter )){
                    sysRouter.setOrderNum(current.getOrderNum());
                    update(sysRouter);
                }
                current.setOrderNum(neighbour.getOrderNum());
            }else {
                if(current.getOrderNum()-1<=0){
                    return queryRouter();
                }
    
                neighbour.setOrderNum((current.getOrderNum()+UP));
    
                SysRouter sysRouter = queryOne(neighbour);
                if(Objects.nonNull(sysRouter )) {
                    sysRouter.setOrderNum(current.getOrderNum());
                    update(sysRouter);
                }
                current.setOrderNum(neighbour.getOrderNum());
    
            }
    
            update(current);
    
            return queryRouter();
        }
    

    相关文章

      网友评论

          本文标题:Java排序上下移

          本文链接:https://www.haomeiwen.com/subject/fmscdktx.html