@Override public ProductCategoryDTO fillProductCategoryDTOInfo(ProductCategoryDTO productCategoryDTO) { if (productCategoryDTO == null) { return null; } ProductWriter productWriter = productDaoManager.getWriter(); if (productCategoryDTO.getCategoryType() == ProductCategoryType.TOP_CATEGORY || productCategoryDTO.getCategoryType() == ProductCategoryType.FIRST_CATEGORY) { productCategoryDTO.setFirstCategoryId(productCategoryDTO.getId()); productCategoryDTO.setFirstCategoryName(productCategoryDTO.getName()); } else if (productCategoryDTO.getCategoryType() == ProductCategoryType.SECOND_CATEGORY) { productCategoryDTO.setSecondCategoryId(productCategoryDTO.getId()); productCategoryDTO.setSecondCategoryName(productCategoryDTO.getName()); ProductCategory firstProductCategory = productWriter.getById(ProductCategory.class, productCategoryDTO.getParentId()); productCategoryDTO.setFirstCategoryId(firstProductCategory.getId()); productCategoryDTO.setFirstCategoryName(firstProductCategory.getName()); } else if (productCategoryDTO.getCategoryType() == ProductCategoryType.THIRD_CATEGORY) { productCategoryDTO.setThirdCategoryName(productCategoryDTO.getName()); productCategoryDTO.setThirdCategoryId(productCategoryDTO.getId()); ProductCategory secondProductCategory = productWriter.getById(ProductCategory.class, productCategoryDTO.getParentId()); productCategoryDTO.setSecondCategoryId(secondProductCategory.getId()); productCategoryDTO.setSecondCategoryName(secondProductCategory.getName()); ProductCategory firstProductCategory = productWriter.getById(ProductCategory.class, secondProductCategory.getParentId()); productCategoryDTO.setFirstCategoryId(firstProductCategory.getId()); productCategoryDTO.setFirstCategoryName(firstProductCategory.getName()); } return productCategoryDTO; }
public List<ProductCategoryDTO> getThirdProductCategoryDTOByName(Long shopId, String name) { ProductWriter productWriter = productDaoManager.getWriter(); List<ProductCategory> productCategoryList = productWriter.getThirdProductCategoryByName(shopId, name); List<ProductCategoryDTO> productCategoryDTOList = new ArrayList<ProductCategoryDTO>(); if (CollectionUtils.isEmpty(productCategoryList)) { return productCategoryDTOList; } for (ProductCategory productCategory : productCategoryList) { ProductCategoryDTO productCategoryDTO = productCategory.toDTO(); ProductCategoryDTO secondProductCategory = ProductCategoryCache.getProductCategoryDTOById(productCategoryDTO.getParentId()); if (secondProductCategory != null) { productCategoryDTO.setSecondCategoryName(secondProductCategory.getName()); productCategoryDTO.setSecondCategoryId(secondProductCategory.getId()); } productCategoryDTOList.add(productCategoryDTO); } return productCategoryDTOList; }