|
@@ -46,23 +46,71 @@ public class TStandardChapterController extends BaseController
|
|
|
@GetMapping("/list")
|
|
|
public AjaxResult list(TStandardChapter tStandardChapter)
|
|
|
{
|
|
|
-// //数组集合结构
|
|
|
-// List<TStandardChapter> tStandardChapters = tStandardChapterService.selectTStandardChapterList(tStandardChapter);
|
|
|
-// //树状VO结构
|
|
|
-// ArrayList<TreeVO> treeVo = new ArrayList<>();
|
|
|
-// for (TStandardChapter standardChapter : tStandardChapters) {
|
|
|
-// Long id = standardChapter.getId();
|
|
|
-// String code = standardChapter.getCode();
|
|
|
-// String name = standardChapter.getName();
|
|
|
-// if (code.indexOf(".") == -1) {
|
|
|
-// TreeVO vo = new TreeVO();
|
|
|
-// vo.setId(id);
|
|
|
-// vo.setLabel(name);
|
|
|
-// treeVo.add(vo);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return success(treeVo);
|
|
|
- return success(tStandardChapterService.selectTStandardChapterList(tStandardChapter));
|
|
|
+ //数组集合结构
|
|
|
+ List<TStandardChapter> tStandardChapters = tStandardChapterService.selectTStandardChapterList(tStandardChapter);
|
|
|
+ //树状VO结构
|
|
|
+ ArrayList<TreeVO> treeVo = new ArrayList<>();
|
|
|
+ for (TStandardChapter standardChapter : tStandardChapters) {//第2次遍历,插入1级
|
|
|
+ Long id = standardChapter.getId();
|
|
|
+ String code = standardChapter.getCode();
|
|
|
+ String name = standardChapter.getName();
|
|
|
+ if (code.indexOf(".") == -1) {//没有“.”
|
|
|
+ TreeVO vo = new TreeVO();
|
|
|
+ vo.setId(id);
|
|
|
+ vo.setCode(code);
|
|
|
+ vo.setName(name);
|
|
|
+ vo.setLabel(code + " " + name);
|
|
|
+ treeVo.add(vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (TStandardChapter standardChapter : tStandardChapters) {//第2次遍历,插入2级
|
|
|
+ Long id = standardChapter.getId();
|
|
|
+ String code = standardChapter.getCode();
|
|
|
+ String name = standardChapter.getName();
|
|
|
+ if (code.indexOf(".") != -1 && code.indexOf(".") == code.lastIndexOf(".")) {//有“.”,只有一个“.”,即第一个“.”的index=最后一个“.”的index
|
|
|
+ String parentCode = code.substring(0, code.lastIndexOf("."));//1级节点code
|
|
|
+ for (TreeVO treeVO : treeVo) {
|
|
|
+ String voCode = treeVO.getCode();
|
|
|
+ ArrayList<TreeVO> children = treeVO.getChildren();
|
|
|
+ if (parentCode.equals(voCode)) {
|
|
|
+ TreeVO vo = new TreeVO();
|
|
|
+ vo.setId(id);
|
|
|
+ vo.setCode(code);
|
|
|
+ vo.setName(name);
|
|
|
+ vo.setLabel(code + " " + name);
|
|
|
+ children.add(vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (TStandardChapter standardChapter : tStandardChapters) {//第3次遍历,插入3级
|
|
|
+ Long id = standardChapter.getId();
|
|
|
+ String code = standardChapter.getCode();
|
|
|
+ String name = standardChapter.getName();
|
|
|
+ if (code.indexOf(".") != -1 && code.indexOf(".") != code.lastIndexOf(".")) {
|
|
|
+ String parentCode = code.substring(0, code.lastIndexOf("."));//2级节点code
|
|
|
+ String rootCode = parentCode.substring(0, parentCode.lastIndexOf("."));//1级节点code
|
|
|
+ for (TreeVO treeVO : treeVo) {
|
|
|
+ ArrayList<TreeVO> children = treeVO.getChildren();
|
|
|
+ for (TreeVO child : children) {
|
|
|
+ String childCode = child.getCode();
|
|
|
+ ArrayList<TreeVO> childChild = child.getChildren();
|
|
|
+ if (parentCode.equals(childCode)) {
|
|
|
+ TreeVO vo = new TreeVO();
|
|
|
+ vo.setId(id);
|
|
|
+ vo.setCode(code);
|
|
|
+ vo.setName(name);
|
|
|
+ vo.setLabel(code + " " + name);
|
|
|
+ childChild.add(vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return success(treeVo);
|
|
|
+// return success(tStandardChapterService.selectTStandardChapterList(tStandardChapter));
|
|
|
}
|
|
|
|
|
|
/**
|