com.github.freegeese.maven.plugin.autocode.demo.base.TreeableService Maven / Gradle / Ivy
package com.github.freegeese.maven.plugin.autocode.demo.base;
/**
* 树状结构Service
*
* @param
* @param
* @param
*/
public class TreeableService, E extends Treeable, ID> extends SortableService {
@Override
protected int move(E from, Position position) {
M mapper = getMapper();
E to = null;
switch (position) {
case TOP:
to = mapper.selectFirst(from);
break;
case UP:
to = mapper.selectPrevious(from);
break;
case DOWN:
to = mapper.selectNext(from);
break;
case BOTTOM:
to = mapper.selectLast(from);
break;
}
// 没有找到目标行(两种可能:1.当前行在顶部,向上移动 2.当前行在底部,向下移动)
if (null == to) {
return 0;
}
// 同一行记录
if (to.getId().equals(from.getId())) {
return 0;
}
return mapper.move(from, to);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy