自动判断嵌套循环层数进行封装
2016-12-19 09:43
218 查看
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略
}
@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略
}
相关文章推荐
- java(安全方便的从控制台读入数据)[对Scanner类进行封装,用正则表达式判断]
- Js~对Boxy弹出框进行封装,提供弹出后自动隐藏与自动跳转功能
- 获取网络判断和数据进行封装
- 智能进行WIFI,CMWAP和CMNET的自动判断访问
- 新知识杂记(Assert进行异常判断、参数封装、枚举类)-2017/4/19
- 用百度siteapp的uaredirect.js判断用户访问端而进行域名的自动跳转,并通过cookie记录手机访问电脑端的状态
- js判断是手机访问还是电脑访问,进行自动跳转
- JS~字符串长度判断,超出进行自动截取(支持中文)
- JS~字符串长度判断,超出进行自动截取(支持中文)
- java(安全方便的从控制台读入数据)[对Scanner类进行封装,用正则表达式判断]
- JS判断来路是否是百度等搜索索引进行弹窗或自动跳转的实现代码
- java(安全方便的从控制台读入数据)[对Scanner类进行封装,用正则表达式判断]
- JS~字符串长度判断,超出进行自动截取(支持中文)
- js判断来路是否是百度等搜索索引进行弹窗或自动跳转
- JS字符串长度判断,超出进行自动截取的实例(支持中文)
- Exsi主机判断UPS状态自动进行关机的讨论
- JS~字符串长度判断,超出进行自动截取(支持中文)
- js判断来路是否是百度等搜索索引进行弹窗或自动跳转
- android的日积月累-进行WIFI,CMWAP和CMNET的自动判断访问
- JS~字符串长度判断,超出进行自动截取(支持中文)