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();
}
网友评论