예제 #1
0
  @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;
  }
예제 #2
0
  @Override
  public Node getProductCategory(Long shopId) {
    Node root = new Node();
    ProductWriter writer = productDaoManager.getWriter();
    List<ProductCategory> productCategoryList = writer.getProductCategoryByShopId(shopId);
    if (CollectionUtils.isEmpty(productCategoryList)) {
      return root;
    }
    List<Node> nodeList = null;

    Map<Long, List<Node>> secondTypeMap = new HashMap<Long, List<Node>>();
    for (ProductCategory productCategory : productCategoryList) {
      if (productCategory.getParentId() == null
          && productCategory.getCategoryType() == ProductCategoryType.TOP_CATEGORY) {
        root = productCategory.toNode();
      }
      if (productCategory.getCategoryType() == ProductCategoryType.SECOND_CATEGORY) {
        if (secondTypeMap.get(productCategory.getParentId()) == null) {
          nodeList = new ArrayList<Node>();
          secondTypeMap.put(productCategory.getParentId(), nodeList);
        }
        Node node = productCategory.toNode();
        secondTypeMap.get(productCategory.getParentId()).add(node);
      }
    }
    List<Node> nodes = new ArrayList<Node>();
    for (ProductCategory productCategory : productCategoryList) {
      if (productCategory.getCategoryType() == ProductCategoryType.FIRST_CATEGORY) {
        nodeList = secondTypeMap.get(productCategory.getId());
        Node node = productCategory.toNode();
        if (CollectionUtils.isNotEmpty(nodeList)) {
          node.setChildren(nodeList);
        }
        nodes.add(node);
      }
    }

    root.mergeAndBuildTree(root, nodes);
    return root;
  }