微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

flex-mx:tree三级树形后台代码

		List<String> result = new ArrayList<String>();
		List<String> result2 = new ArrayList<String>();
		List<Object[]> addvcds = ceZhanChaXunService.getAllCityInfo();//市
		List<Object[]> cz = ceZhanChaXunService.getAllCountyInfo();//市+区县
		List<Object[]> xq=ceZhanChaXunService.getonlyAreaInfo();//县区信息
		Map<String,List<JSONObject>> data = new LinkedHashMap<String,List<JSONObject>>();
		Map<String,List<JSONObject>> data2 = new LinkedHashMap<String,List<JSONObject>>();
		List<Object[]> stations = ceZhanChaXunService.getAllCeZhanOfCounty();//区县+测站
		//市
		for(Object[] addvcd : addvcds) {
			data.put(addvcd[2].toString(),new ArrayList<JSONObject>());//
		}
		//市+县
		for(Object[] obj : cz) {
			String addvcd = obj[2].toString().trim();
			JSONObject item = new JSONObject();
			item.put("stcd",obj[0].toString().trim());
			item.put("label",obj[1].toString().trim());
			item.put("addvcd",obj[2].toString().trim());
			if(null==data.get(addvcd)){
				break;	
			}
			data.get(addvcd).add(item);
		}
		//县
		for(Object[] addvcd : xq) {
			data2.put(addvcd[2].toString(),new ArrayList<JSONObject>());//121条
		}
		//县+测站
		for(Object[] obj : stations) {
			String addvcd = obj[2].toString().trim();
			JSONObject item = new JSONObject();
			item.put("stcd",obj[2].toString().trim());
			item.put("selected",true);
			item.put("drp",0);
			if(null==data2.get(addvcd)){
				break;	
			}
			data2.get(addvcd).add(item);
		}
		
		for(Map.Entry<String,List<JSONObject>> entry2:data2.entrySet()) {
			JSONObject item = new JSONObject();
			item.put("label",entry2.getKey());
			item.put("state",false);
			item.put("children",entry2.getValue());//二级
			result2.add(item.toJSONString());//result2:县+测站
		}
		//==============================================================================================================================
		//合肥市
		List<net.sf.json.JSONObject> hfList=new ArrayList<net.sf.json.JSONObject>();
		List<String> hfList2=result2.subList(0,9);
		for (String obj : hfList2) {
			net.sf.json.JSONObject object=net.sf.json.JSONObject.fromObject(obj);
			hfList.add(object);
		}
		//芜湖市
		List<net.sf.json.JSONObject> whList=new ArrayList<net.sf.json.JSONObject>();
		List<String> whList2=result2.subList(9,17);
		for (String obj : whList2) {
			net.sf.json.JSONObject object=net.sf.json.JSONObject.fromObject(obj);
			whList.add(object);
		}
		//蚌埠市
		List<net.sf.json.JSONObject> bbList=new ArrayList<net.sf.json.JSONObject>();
		List<String> bbList2=result2.subList(17,24);//String bbString=result2.subList(17,24).toString();//蚌埠7
		for (String obj : bbList2) {
			net.sf.json.JSONObject object=net.sf.json.JSONObject.fromObject(obj);
			bbList.add(object);
		}
		//淮南市
		List<net.sf.json.JSONObject> hnList=new ArrayList<net.sf.json.JSONObject>();
		List<String> hnList2=result2.subList(24,30);
		for (String obj : hnList2) {
			net.sf.json.JSONObject object=net.sf.json.JSONObject.fromObject(obj);
			hnList.add(object);
		}
		//马鞍山市
		List<net.sf.json.JSONObject> masList=new ArrayList<net.sf.json.JSONObject>();
		List<String> masList2=result2.subList(30,36);
		for (String obj : masList2) {
			net.sf.json.JSONObject object=net.sf.json.JSONObject.fromObject(obj);
			masList.add(object);
		}
		//淮北市
		List<net.sf.json.JSONObject> hbList=new ArrayList<net.sf.json.JSONObject>();
		List<String> hbList2=result2.subList(36,40);
		for (String obj : hbList2) {
			net.sf.json.JSONObject object=net.sf.json.JSONObject.fromObject(obj);
			hbList.add(object);
		}
		//铜陵市
		List<net.sf.json.JSONObject> tlList=new ArrayList<net.sf.json.JSONObject>();
		List<String> tlList2=result2.subList(40,44);
		for (String obj : tlList2) {
			net.sf.json.JSONObject object=net.sf.json.JSONObject.fromObject(obj);
			tlList.add(object);
		}
		//安庆市
		List<net.sf.json.JSONObject> aqList=new ArrayList<net.sf.json.JSONObject>();
		List<String> aqList2=result2.subList(44,55);
		for (String obj : aqList2) {
			net.sf.json.JSONObject object=net.sf.json.JSONObject.fromObject(obj);
			aqList.add(object);
		}
		//黄山市
		List<net.sf.json.JSONObject> hsList=new ArrayList<net.sf.json.JSONObject>();
		List<String> hsList2=result2.subList(55,62);
		for (String obj : hsList2) {
			net.sf.json.JSONObject object=net.sf.json.JSONObject.fromObject(obj);
			hsList.add(object);
		}
		//滁州市
		List<net.sf.json.JSONObject> czList=new ArrayList<net.sf.json.JSONObject>();
		List<String> czList2=result2.subList(62,70);
		for (String obj : czList2) {
			net.sf.json.JSONObject object=net.sf.json.JSONObject.fromObject(obj);
			czList.add(object);
		}
		//阜阳市
		List<net.sf.json.JSONObject> fyList=new ArrayList<net.sf.json.JSONObject>();
		List<String> fyList2=result2.subList(70,78);
		for (String obj : fyList2) {
			net.sf.json.JSONObject object=net.sf.json.JSONObject.fromObject(obj);
			fyList.add(object);
		}
		//宿州市
		List<net.sf.json.JSONObject> szList=new ArrayList<net.sf.json.JSONObject>();
		List<String> szList2=result2.subList(78,83);
		for (String obj : szList2) {
			net.sf.json.JSONObject object=net.sf.json.JSONObject.fromObject(obj);
			szList.add(object);
		}
		//六安市
		List<net.sf.json.JSONObject> laList=new ArrayList<net.sf.json.JSONObject>();
		List<String> laList2=result2.subList(83,90);
		for (String obj : laList2) {
			net.sf.json.JSONObject object=net.sf.json.JSONObject.fromObject(obj);
			laList.add(object);
		}
		//亳州市
		List<net.sf.json.JSONObject> bzList=new ArrayList<net.sf.json.JSONObject>();
		List<String> bzList2=result2.subList(90,94);
		for (String obj : bzList2) {
			net.sf.json.JSONObject object=net.sf.json.JSONObject.fromObject(obj);
			bzList.add(object);
		}
		//池州市
		List<net.sf.json.JSONObject> cz2List=new ArrayList<net.sf.json.JSONObject>();
		List<String> cz2List2=result2.subList(94,98);
		for (String obj : cz2List2) {
			net.sf.json.JSONObject object=net.sf.json.JSONObject.fromObject(obj);
			cz2List.add(object);
		}
		//宣城市
		List<net.sf.json.JSONObject> xcList=new ArrayList<net.sf.json.JSONObject>();
		List<String> xcList2=result2.subList(98,105);
		for (String obj : xcList2) {
			net.sf.json.JSONObject object=net.sf.json.JSONObject.fromObject(obj);
			xcList.add(object);
		}
		//======================================================================================================================
		for(Map.Entry<String,List<JSONObject>> entry:data.entrySet()) {
			JSONObject item = new JSONObject();
			item.put("label",entry.getKey());
			item.put("state",false);
			if("合肥市".equals(entry.getKey())){
				item.put("children",hfList );
			}else if("芜湖市".equals(entry.getKey())){
				item.put("children",whList );
			}else if("蚌埠市".equals(entry.getKey())){
				item.put("children",bbList );
			}else if("淮南市".equals(entry.getKey())){
				item.put("children",hnList );
			}else if("马鞍山市".equals(entry.getKey())){
				item.put("children",masList );
			}else if("淮北市".equals(entry.getKey())){
				item.put("children",hbList );
			}else if("铜陵市".equals(entry.getKey())){
				item.put("children",tlList );
			}else if("安庆市".equals(entry.getKey())){
				item.put("children",aqList );
			}else if("黄山市".equals(entry.getKey())){
				item.put("children",hsList );
			}else if("滁州市".equals(entry.getKey())){
				item.put("children",czList );
			}else if("阜阳市".equals(entry.getKey())){
				item.put("children",fyList );
			}else if("宿州市".equals(entry.getKey())){
				item.put("children",szList );
			}else if("六安市".equals(entry.getKey())){
				item.put("children",laList );
			}else if("亳州市".equals(entry.getKey())){
				item.put("children",bzList );
			}else if("池州市".equals(entry.getKey())){
				item.put("children",cz2List );
			}else if("宣城市".equals(entry.getKey())){
				item.put("children",xcList );
			}
			else{
				continue;
			}
			
			result.add(item.toJSONString());//result:市+县
		}
		return result;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐