@ResponseBody @RequestMapping( value = "getIpAddressAllByGroupIdBYBBSA", method = RequestMethod.POST, produces = MediaTypes.JSON) public Set<String> getIpAddressAllByGroupIdBYBBSA( @RequestParam("id") Integer id, HttpServletRequest request) throws SQLException { Set<String> ipAddressList = new HashSet<String>(); List<GroupBean> groupBeanList = new ArrayList<GroupBean>(); // 选中的组 BLGroup groupNode = groupService.findByGroupId(id); // 子组 List<BLGroup> groupList = groupService.getAllChildrenGroup(id, new ArrayList<BLGroup>()); groupList.add(groupNode); List<Integer> ordinaryGroupList = new ArrayList<Integer>(); List<Integer> smartGroups = new ArrayList<Integer>(); for (BLGroup blGroup : groupList) { if (blGroup.getGROUP_TYPE_ID() == 1) { if (blGroup.getGROUP_TYPE_ID() instanceof Integer) ordinaryGroupList.add(blGroup.getGROUP_ID()); } else { smartGroups.add(blGroup.getGROUP_ID()); } } String ordinaryGroups = ""; for (Integer g : ordinaryGroupList) ordinaryGroups += "," + g; if (ordinaryGroupList.size() > 0) { String groupIDwhere = ordinaryGroups.substring(1, ordinaryGroups.length()); if (",".equals(groupIDwhere.substring(groupIDwhere.length() - 1, groupIDwhere.length()))) { groupIDwhere = groupIDwhere.substring(0, groupIDwhere.length() - 1); } SessionImplementor sessionImplementor = (SessionImplementor) entityManager.getDelegate(); Connection connection = sessionImplementor.connection(); Statement statement = connection.createStatement(); String sql = "select blgroup_device.device_id,blgroup_device.group_id,server.name IP_ADDRESS " + "from blgroup_device,device server,blgroup where server.agent_state_id=100 and server.device_state_id=50 " + "and blgroup_device.device_id=server.device_id and blgroup_device.group_id=blgroup.group_id " + "and blgroup.group_id in (" + groupIDwhere + ")"; System.out.println("SQL: " + sql); ResultSet resultSet = statement.executeQuery(sql); if (resultSet.next()) { ipAddressList.add(resultSet.getString("IP_ADDRESS")); } } if (smartGroups.size() > 0) { SessionImplementor sessionImplementor = (SessionImplementor) entityManager.getDelegate(); Connection connection = sessionImplementor.connection(); Statement statement = connection.createStatement(); for (Integer groupid : smartGroups) { SmartGroup smartGroup = smartGroupService.findWithGroupId(groupid); if (null != smartGroup) { String sql = smartGroup.getQUERY_STRING().substring(0, smartGroup.getQUERY_STRING().length() - 1); ResultSet resultSet = statement.executeQuery(sql); while (resultSet.next()) { ipAddressList.add(resultSet.getString("IP_ADDRESS")); } } } } return ipAddressList; // deviceFilter.deviceFilterRole(ipAddressList,UserNameUtil.getUserNameByRequest(request)); }