@Override public Response<List<AddressFactory>> findFactories(Long productId, Long parkId) { Response<List<AddressFactory>> result = new Response<List<AddressFactory>>(); if (productId == null) { log.error("find address factory need productId"); result.setError("factory.productId.null"); return result; } if (parkId == null) { log.error("find address factory need parkId"); result.setError("factory.parkId.null"); return result; } try { // 获取类目与工厂关系 List<Long> factoryIds = Lists.transform( categoryFactoryDao.findByProductId(productId, parkId), new Function<CategoryFactory, Long>() { @Override public Long apply(CategoryFactory categoryFactory) { return categoryFactory.getFactoryId(); } }); result.setResult(addressFactoryDao.findByFactoryIds(factoryIds)); } catch (Exception e) { log.error( "find address factory failed , productId={}, parkId={}, error code={}", productId, parkId, Throwables.getStackTraceAsString(e)); result.setError("find.factory.failed"); } return result; }
@Override public Response<List<AddressFactory>> findFactoryByIds(List<Long> factoryIds) { Response<List<AddressFactory>> result = new Response<List<AddressFactory>>(); if (factoryIds == null || factoryIds.isEmpty()) { log.error("find park and factory info need factoryIds"); result.setError("parkAddress.factoryIds.null"); return result; } try { result.setResult(addressFactoryDao.findByFactoryIds(factoryIds)); } catch (Exception e) { log.error( "find address factory failed , factoryIds={}, error code={}", factoryIds, Throwables.getStackTraceAsString(e)); result.setError("find.factory.failed"); } return result; }
@Override public Response<List<ParkFactoryDto>> findDetailFactories(Long productId, List<Long> factoryIds) { Response<List<ParkFactoryDto>> result = new Response<List<ParkFactoryDto>>(); if (productId == null) { log.error("find park and factory info need productId"); result.setError("parkAddress.productId.null"); return result; } if (factoryIds == null || factoryIds.isEmpty()) { log.error("find park and factory info need factoryIds"); result.setError("parkAddress.factoryIds.null"); return result; } try { List<CategoryFactory> categoryFactoryList = categoryFactoryDao.findByParams(productId, factoryIds); // 园区信息查询结果列表 List<AddressPark> parkQuery = addressParkDao.findByIds( Lists.transform( categoryFactoryList, new Function<CategoryFactory, Long>() { @Override public Long apply(CategoryFactory categoryFactory) { return categoryFactory.getParkId(); } })); Map<Long, AddressPark> parkMap = Maps.newHashMap(); for (AddressPark addressPark : parkQuery) { parkMap.put(addressPark.getId(), addressPark); } // 工厂信息查询结果列表 List<AddressFactory> factoryQuery = addressFactoryDao.findByFactoryIds( Lists.transform( categoryFactoryList, new Function<CategoryFactory, Long>() { @Override public Long apply(CategoryFactory categoryFactory) { return categoryFactory.getFactoryId(); } })); Map<Long, AddressFactory> factoryMap = Maps.newHashMap(); for (AddressFactory factory : factoryQuery) { factoryMap.put(factory.getId(), factory); } // 组装园区工厂信息列表 List<ParkFactoryDto> parkFactoryDtoList = Lists.newArrayList(); ParkFactoryDto parkFactoryDto; AddressPark addressPark; AddressFactory addressFactory; for (CategoryFactory categoryFactory : categoryFactoryList) { parkFactoryDto = new ParkFactoryDto(); addressPark = parkMap.get(categoryFactory.getParkId()); addressFactory = factoryMap.get(categoryFactory.getFactoryId()); parkFactoryDto.setParkId(addressPark.getId()); parkFactoryDto.setParkName(addressPark.getParkName()); parkFactoryDto.setFactoryId(addressFactory.getId()); parkFactoryDto.setFactoryNum(addressFactory.getFactoryNum()); parkFactoryDto.setFactoryName(addressFactory.getFactoryName()); parkFactoryDtoList.add(parkFactoryDto); } result.setResult(parkFactoryDtoList); } catch (Exception e) { log.error( "find park and factory failed , productId={}, factoryIds={}", productId, factoryIds); result.setError("find.factory.failed"); } return result; }