/** * @Description: 宁静 * * @author [email protected] * @date 2015年12月2日 下午2:43:38 * @param station * @return */ private AgentListDto toDto(User user) { AgentListDto agentListDto = new AgentListDto(); agentListDto.setId(user.getId()); agentListDto.setName(user.getName()); agentListDto.setAgentCode(user.getCode()); agentListDto.setCreater(user.getCreater()); agentListDto.setAddress(user.getAddress()); agentListDto.setTelephone(user.getTelephone()); if (!StringUtils.isEmpty(user.getParentUid())) { try { String parentName = userService.getUserById(user.getParentUid()).getName(); agentListDto.setParentName(parentName); } catch (BizException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // 处理实体中的特殊转换值 if (null != user.getCreaterTime()) // 创建时间 { agentListDto.setCreaterTime( DateUtil.formatDate(user.getCreaterTime(), DateUtil.FULL_DATE_FORMAT)); } if (null != user.getProvinceCode()) // 省级区域 { Province province = new Province(); province = provinceService.getProvinceByPcode(user.getProvinceCode()); agentListDto.setProvince(null != province ? province.getPname() : ""); } if (null != user.getCityCode()) // 市级区域 { if (Constants.CITY_ALL.equals(user.getCityCode())) { agentListDto.setCity(Constants.CITY_ALL_NAME); } else { City city = new City(); city = cityService.getCityByCcode(user.getCityCode()); agentListDto.setCity(null != city ? city.getCname() : ""); } } if (null != user.getRegionCode()) // 市级区域 { if (Constants.REGION_ALL.equals(user.getRegionCode())) { agentListDto.setCity(Constants.REGION_ALL_NAME); } else { Region region = new Region(); region = regionService.getRegionByAcode(user.getRegionCode()); agentListDto.setRegion(null != region ? region.getAname() : ""); } } return agentListDto; }
@RequestMapping(value = "/getAgentList", method = RequestMethod.GET) public @ResponseBody Map<String, Object> getAgentList( @RequestParam(value = "page", required = false) int page, @RequestParam(value = "rows", required = false) int rows, @RequestParam(value = "searchFormNumber", required = false) String searchFormNumber, @RequestParam(value = "searchFormName", required = false) String searchFormName, @RequestParam(value = "searchFormTelephone", required = false) String searchFormTelephone, @RequestParam(value = "searchFormProvince", required = false) String searchFormProvince, @RequestParam(value = "searchFormCity", required = false) String searchFormCity, @RequestParam(value = "searchFormParentId", required = false) String searchFormParentId, ModelMap model, HttpSession httpSession) throws Exception { Map<String, Object> returnData = new HashMap<String, Object>(); Pageable pageable = new PageRequest(page - 1, rows); // 参数 StringBuffer buffer = new StringBuffer(); LinkedHashMap<String, String> orderBy = new LinkedHashMap<String, String>(); orderBy.put("id", "desc"); List<Object> params = new ArrayList<Object>(); // 只查询未删除数据 params.add(Constants.IS_NOT_DELETED); // 只查询有效的数据 buffer.append(" a.IS_DELETED = ?").append(params.size()); if (null != searchFormNumber && !"".equals(searchFormNumber)) { params.add(searchFormNumber); // 根据站点号 buffer.append(" and a.CODE = ?").append(params.size()); } if (null != searchFormProvince && !"".equals(searchFormProvince) && !Constants.PROVINCE_ALL.equals(searchFormProvince)) { params.add(searchFormProvince); // 根据省份查询产品数据 buffer.append(" and a.province_Code = ?").append(params.size()); } if (null != searchFormCity && !"".equals(searchFormCity) && !Constants.CITY_ALL.equals(searchFormCity)) { params.add(searchFormCity); // 根据省份查询产品数据 buffer.append(" and a.city_Code = ?").append(params.size()); } if (null != searchFormName && !"".equals(searchFormName)) { params.add("%" + searchFormName + "%"); // 根据产品描述模糊查询产品数据 buffer.append(" and a.NAME like ?").append(params.size()); } if (null != searchFormTelephone && !"".equals(searchFormTelephone)) { params.add(searchFormTelephone); // 根据产品描述模糊查询产品数据 buffer.append(" and a.TELEPHONE = ?").append(params.size()); } if (null != searchFormParentId && !"".equals(searchFormParentId)) { params.add(searchFormParentId); // 根据产品描述模糊查询产品数据 buffer.append(" and a.PARENT_UID = ?").append(params.size()); } QueryResult<User> stationList = userService.getAgentList( User.class, buffer.toString(), params.toArray(), orderBy, pageable); List<User> users = stationList.getResultList(); List<AgentListDto> stationDtos = this.toDtos(users); int totalrow = stationList.getTotalCount(); returnData.put("rows", stationDtos); returnData.put("total", totalrow); return returnData; }