java为菜单树设置无限层级的序号
private Integer lastLayerNum = 1;//上一级的菜单的层级
private String lastSortNum = "";//上一级的菜单的序号
private Map<Integer, String> layerSortNumMap = new HashMap<Integer, String>();//存储每一层级最后一个序号的前缀
//设置序号
String sortNum = "";
if (lastLayerNum >= menu.getLayerNum()) {
// lastSortNum = layerSortNumMap.containsKey(menu.getLayerNum() - 1) ? layerSortNumMap.get(menu.getLayerNum() - 1) : "";
lastSortNum = layerSortNumMap.getOrDefault(menu.getLayerNum() - 1, "");
}
if (menu.getLayerNum() == 1) {// 第一级
sortNum = ChineseNumberUtil.toChinese(String.valueOf(menu.getSortNum()));
} else if (menu.getLayerNum() == 2) {
sortNum = "(" + ChineseNumberUtil.toChinese(String.valueOf(menu.getSortNum())) + ")";
} else if (menu.getLayerNum() > 2) {
sortNum = lastSortNum + "-" + String.valueOf(menu.getSortNum());
}
lastSortNum = sortNum;
lastLayerNum = menu.getLayerNum();
layerSortNumMap.put(menu.getLayerNum(), lastSortNum);
row.getCell(0).setCellValue(sortNum);
不积跬步无以至千里,不积小流无以成江海