自动判断嵌套循环层数进行封装

List list1;

@RequestMapping(value = "", method = RequestMethod.POST)
@ApiOperation(value = "", httpMethod = "POST", notes = "根据组织级别的级别查询所属组织树结构", response = VOrgParentLevel.class)
@Log(operationType = "select操作", operationName = "根据组织级别的级别查询所属组织树结构", businessType = "查看")
public @ResponseBody JSON select(@ApiParam(value = "组织级别ID")String orgLevelCode) {
String orgLevel = null;
if (tls.selectById(orgLevelCode) != null) {
orgLevel = tls.selectById(orgLevelCode).getOrgLevel();
}
Wrapper ew = new EntityWrapper();
if (orgLevel != null) {
ew.where("ORG_LEVEL<{0}", orgLevel);
}
ew.where("PARENT_ORG_CODE={0}", "");
List list = volpservice.selectList(ew);
list1 = new ArrayList();
ListUitl.copylistAtoB(list, list1);
a(list1, orgLevel);
JSON j = (JSON) JSON.toJSON(list1);
return j;
}

public void a(List list, String orgLevel) {
Wrapper ew = new EntityWrapper();
if (orgLevel != null) {
ew.where("ORG_LEVEL<{0}", orgLevel);
}
if (list != null) {
for (int i = 0; i < list.size(); i++) {
ew.where("PARENT_ORG_CODE={0}", list.get(i).getId());
List list2 = volpservice.selectList(ew);
if (list2 != null && list2.size() > 0) {
List list3 = new ArrayList();
ListUitl.copylistAtoB(list2, list3);
list.get(i).setChildren(list3);
a(list3, orgLevel);
}
}
}
}
list的copy
public class ListUitl {

    public static void copylistAtoB(List a, List b) {
        if (a != null) {

            for (int i = 0; i < a.size(); i++) {
                if (a.get(0) instanceof VMenuParent) {// 所有查出来的菜单
                    b.add(new VMenuParent1(((VMenuParent) a.get(i)).getMenuCode(), ((VMenuParent) a.get(i)).getMenuName()));
                }
                if (a.get(0) instanceof VDefaultrollMenus) {// 默认角色查出来的菜单
                    b.add(new VMenuParent1(((VDefaultrollMenus) a.get(i)).getMenuCode(), ((VDefaultrollMenus) a.get(i)).getMenuName()));
                }
                if (a.get(0) instanceof VOrgParentLevel) {// 组织树
                    b.add(new VMenuParent1(((VOrgParentLevel) a.get(i)).getOrgCode(), ((VOrgParentLevel) a.get(i)).getOrgName()));
                }
                if (a.get(0) instanceof TbOrganization) {// 组织树
                    b.add(new VMenuParent1(((TbOrganization) a.get(i)).getOrgCode(), ((TbOrganization) a.get(i)).getOrgName()));
                }
                if (a.get(0) instanceof VUserMenu) {// 登录查出来的用户和菜单
                VMenuParent1 vm = new VMenuParent1(((VUserMenu) a.get(i)).getMenuCode(), ((VUserMenu) a.get(i)).getMenuName());
                vm.setLinkAddress(((VUserMenu) a.get(i)).getLinkAddress());
                vm.setMenuAddress(((VUserMenu) a.get(i)).getMenuAddress());
                vm.setBigpicture(((VUserMenu) a.get(i)).getBigpicture());
                b.add(vm);
                }
            }
        }
    }
}

封装类
public class VMenuParent1 implements Serializable {

    private static final long serialVersionUID = 1L;
   
    @ApiModelProperty(value = "菜单编号")
    private String id;

   
    @ApiModelProperty(value = "菜单名称")
    private String text;

   
    private String menuAddress;
    
    private String linkAddress;
    
    private List children;
    
    private String bigpicture;
    
    public VMenuParent1() {
super();
// TODO Auto-generated constructor stub
}

public VMenuParent1(String id, String text) {
        super();
        this.id = id;
        this.text = text;
    }
    。。。。get/set略

你可能感兴趣的:(自动判断嵌套循环层数进行封装)