diff --git a/src/main/java/neatlogic/framework/lrcode/LRCodeManager.java b/src/main/java/neatlogic/framework/lrcode/LRCodeManager.java index 7d11b3226dfa9009591d9568b4dced4c875bb89e..f81eea365758189715c28a1ee7a919d7274f6bc2 100644 --- a/src/main/java/neatlogic/framework/lrcode/LRCodeManager.java +++ b/src/main/java/neatlogic/framework/lrcode/LRCodeManager.java @@ -212,24 +212,32 @@ public class LRCodeManager { treeMapper.batchUpdateTreeNodeRightCode(tableName, treeNodeVo.getLft(), -step, condition); } + public static void rebuildLeftRightCodeOrderBySortKey(String tableName, String idKey, String parentIdKey, String sortKey) { + rebuildLeftRightCode(tableName, idKey, parentIdKey, null, 1, null, sortKey); + } + + public static void rebuildLeftRightCodeOrderBySortKey(String tableName, String idKey, String parentIdKey, String condition, String sortKey) { + rebuildLeftRightCode(tableName, idKey, parentIdKey, null, 1, condition, sortKey); + } + public static void rebuildLeftRightCode(String tableName, String idKey, String parentIdKey) { - rebuildLeftRightCode(tableName, idKey, parentIdKey, null, 1, null); + rebuildLeftRightCode(tableName, idKey, parentIdKey, null, 1, null, null); } public static void rebuildLeftRightCode(String tableName, String idKey, String parentIdKey, String condition) { - rebuildLeftRightCode(tableName, idKey, parentIdKey, null, 1, condition); + rebuildLeftRightCode(tableName, idKey, parentIdKey, null, 1, condition, null); } - private static Integer rebuildLeftRightCode(String tableName, String idKey, String parentIdKey, Object parentIdValue, int parentLft, String condition) { - List catalogList = treeMapper.getTreeNodeListByParentId(tableName, idKey, parentIdKey, parentIdValue, condition); + private static Integer rebuildLeftRightCode(String tableName, String idKey, String parentIdKey, Object parentIdValue, int parentLft, String condition, String sortKey) { + List catalogList = treeMapper.getTreeNodeListByParentId(tableName, idKey, parentIdKey, parentIdValue, condition, sortKey); for (TreeNodeVo catalog : catalogList) { if (catalog.getChildrenCount() == 0) { treeMapper.updateTreeNodeLeftRightCodeById(tableName, idKey, catalog.getIdValue(), parentLft + 1, parentLft + 2); parentLft += 2; } else { int lft = parentLft + 1; - parentLft = rebuildLeftRightCode(tableName, idKey, parentIdKey, catalog.getIdValue(), lft, condition); + parentLft = rebuildLeftRightCode(tableName, idKey, parentIdKey, catalog.getIdValue(), lft, condition, sortKey); treeMapper.updateTreeNodeLeftRightCodeById(tableName, idKey, catalog.getIdValue(), lft, parentLft + 1); parentLft += 1; } diff --git a/src/main/java/neatlogic/framework/lrcode/dao/mapper/TreeMapper.java b/src/main/java/neatlogic/framework/lrcode/dao/mapper/TreeMapper.java index 6f1a17a06ec743d5e95049e01e506ce6b02a78be..8f3537b1d889159ad8466311815f7cae4569d74e 100644 --- a/src/main/java/neatlogic/framework/lrcode/dao/mapper/TreeMapper.java +++ b/src/main/java/neatlogic/framework/lrcode/dao/mapper/TreeMapper.java @@ -65,7 +65,7 @@ public interface TreeMapper { * @Returns:java.lang.Object **/ // public Object checkLeafNodeLeftRightCodeAreNotContinuous(@Param("tableName")String tableName, @Param("idKey") String idKey, @Param("parentIdKey") String parentIdKey); - public List getTreeNodeListByParentId(@Param("tableName") String tableName, @Param("idKey") String idKey, @Param("parentIdKey") String parentIdKey, @Param("parentIdValue") Object parentIdValue, @Param("condition") String condition); + public List getTreeNodeListByParentId(@Param("tableName") String tableName, @Param("idKey") String idKey, @Param("parentIdKey") String parentIdKey, @Param("parentIdValue") Object parentIdValue, @Param("condition") String condition, @Param("sortKey") String sortKey); public int updateTreeNodeLeftRightCodeById(@Param("tableName") String tableName, @Param("idKey") String idKey, @Param("idValue") Object idValue, @Param("lft") int lft, @Param("rht") int rht); diff --git a/src/main/java/neatlogic/framework/lrcode/dao/mapper/TreeMapper.xml b/src/main/java/neatlogic/framework/lrcode/dao/mapper/TreeMapper.xml index 0f61c7f343e2367e4ff0f0b552c2c0188e2d4f62..0d1995e7207f2bde94c87cfdd442aa0457ac8e12 100644 --- a/src/main/java/neatlogic/framework/lrcode/dao/mapper/TreeMapper.xml +++ b/src/main/java/neatlogic/framework/lrcode/dao/mapper/TreeMapper.xml @@ -72,7 +72,9 @@ and ${condition} - ORDER BY a.`lft` + + ORDER BY a.`${sortKey}` + @@ -146,4 +148,4 @@ WHERE `lft` >= #{lft} AND `rht` <= #{rht} - \ No newline at end of file +