@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;
  }
 private Node buildCheckProductCategoryTree(
     List<ProductCategoryDTO> productCategoryDTOList, Map<Long, Object> productCategoryMap) {
   Node root = new Node();
   if (CollectionUtils.isEmpty(productCategoryDTOList)) return root;
   Node node;
   List<Node> nodeList = new ArrayList<Node>();
   for (ProductCategoryDTO dto : productCategoryDTOList) {
     dto.setChecked(productCategoryMap.get(dto.getId()) != null);
     node = dto.toCheckNode();
     if (dto.getParentId() == null) {
       root = node;
       continue;
     }
     nodeList.add(node);
   }
   root.buildTree(root, nodeList);
   return root;
 }
  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;
  }
  public Map<String, Object> validateProductCategoryDTO(
      ProductCategoryDTO productCategoryDTO, ProductCategoryDTO newProductCategoryDTO) {

    String errorMessage = "";
    Map<String, Object> result = new HashMap<String, Object>();

    result = this.validateCategoryName(productCategoryDTO, ProductCategoryType.FIRST_CATEGORY);
    if (!(Boolean) result.get("success")) {
      return result;
    }

    Long parentId = null;

    if (productCategoryDTO.getCategoryType() == ProductCategoryType.THIRD_CATEGORY
        || productCategoryDTO.getCategoryType() == ProductCategoryType.SECOND_CATEGORY) {
      result = this.validateCategoryName(productCategoryDTO, ProductCategoryType.SECOND_CATEGORY);
      if (!(Boolean) result.get("success")) {
        return result;
      }
      List<ProductCategoryDTO> productCategoryDTOList =
          this.getProductCategoryDTOByNameParentId(
              productCategoryDTO.getShopId(), productCategoryDTO.getFirstCategoryName(), -1L);
      if (CollectionUtils.isEmpty(productCategoryDTOList)) {
        errorMessage = ProductCategoryConstant.FIRST_CATEGORY_NO_EXIST;
        result.put("success", false);
        result.put("message", errorMessage);
        return result;
      } else if (productCategoryDTOList.size() > 1) {
        errorMessage = ProductCategoryConstant.FIRST_CATEGORY_ONE_MORE;
        result.put("success", false);
        result.put("message", errorMessage);
        return result;
      }
      parentId = productCategoryDTOList.get(0).getId();
    }

    if (productCategoryDTO.getCategoryType() == ProductCategoryType.FIRST_CATEGORY) {

      newProductCategoryDTO.setName(productCategoryDTO.getFirstCategoryName());
      newProductCategoryDTO.setCategoryType(ProductCategoryType.FIRST_CATEGORY);
      newProductCategoryDTO.setParentId(-1L);
    } else if (productCategoryDTO.getCategoryType() == ProductCategoryType.SECOND_CATEGORY) {

      newProductCategoryDTO.setParentId(parentId);

      List<ProductCategoryDTO> productCategoryDTOList =
          this.getProductCategoryDTOByNameParentId(
              productCategoryDTO.getShopId(),
              productCategoryDTO.getSecondCategoryName(),
              newProductCategoryDTO.getParentId());
      if (CollectionUtils.isNotEmpty(productCategoryDTOList)) {
        if (newProductCategoryDTO.getId() == null) {
          errorMessage = ProductCategoryConstant.SECOND_CATEGORY_EXIST;
          result.put("success", false);
          result.put("message", errorMessage);
          return result;
        } else if (!productCategoryDTOList.get(0).getId().equals(newProductCategoryDTO.getId())) {
          errorMessage = ProductCategoryConstant.SECOND_CATEGORY_EXIST;
          result.put("success", false);
          result.put("message", errorMessage);
          return result;
        }
      }
      newProductCategoryDTO.setName(productCategoryDTO.getSecondCategoryName());
      newProductCategoryDTO.setCategoryType(ProductCategoryType.SECOND_CATEGORY);
    } else if (productCategoryDTO.getCategoryType() == ProductCategoryType.THIRD_CATEGORY) {
      result = this.validateCategoryName(productCategoryDTO, ProductCategoryType.THIRD_CATEGORY);
      if (!(Boolean) result.get("success")) {
        return result;
      }

      List<ProductCategoryDTO> productCategoryDTOList =
          this.getProductCategoryDTOByNameParentId(
              productCategoryDTO.getShopId(), productCategoryDTO.getSecondCategoryName(), parentId);
      if (CollectionUtils.isEmpty(productCategoryDTOList)) {
        errorMessage = ProductCategoryConstant.SECOND_CATEGORY_NO_EXIST;
        result.put("success", false);
        result.put("message", errorMessage);
        return result;
      } else if (productCategoryDTOList.size() > 1) {
        errorMessage = ProductCategoryConstant.SECOND_CATEGORY_ONE_MORE;
        result.put("success", false);
        result.put("message", errorMessage);
        return result;
      }
      newProductCategoryDTO.setParentId(productCategoryDTOList.get(0).getId());

      productCategoryDTOList =
          this.getProductCategoryDTOByNameParentId(
              productCategoryDTO.getShopId(),
              productCategoryDTO.getThirdCategoryName(),
              productCategoryDTOList.get(0).getId());
      if (CollectionUtils.isNotEmpty(productCategoryDTOList)) {

        if (newProductCategoryDTO.getId() == null) {
          errorMessage = ProductCategoryConstant.THIRD_CATEGORY_EXIST;
          result.put("success", false);
          result.put("message", errorMessage);
          return result;
        } else if (!productCategoryDTOList.get(0).getId().equals(newProductCategoryDTO.getId())) {
          errorMessage = ProductCategoryConstant.THIRD_CATEGORY_EXIST;
          result.put("success", false);
          result.put("message", errorMessage);
          return result;
        }
      }

      newProductCategoryDTO.setName(productCategoryDTO.getThirdCategoryName());
      newProductCategoryDTO.setCategoryType(ProductCategoryType.THIRD_CATEGORY);
    } else {
      errorMessage = ProductCategoryConstant.PRODUCT_CATEGORY_ERROR;
      result.put("success", false);
      result.put("message", errorMessage);
      return result;
    }

    List<ProductCategoryDTO> productCategoryDTOList =
        this.getProductCategoryDTOByNameParentId(
            productCategoryDTO.getShopId(),
            newProductCategoryDTO.getName(),
            newProductCategoryDTO.getParentId());
    if (CollectionUtils.isNotEmpty(productCategoryDTOList)) {
      if (newProductCategoryDTO.getId() == null) {
        errorMessage = ProductCategoryConstant.THIRD_CATEGORY_EXIST;
        result.put("success", false);
        result.put("message", errorMessage);
        return result;
      } else if (!productCategoryDTOList.get(0).getId().equals(newProductCategoryDTO.getId())) {
        errorMessage = ProductCategoryConstant.THIRD_CATEGORY_EXIST;
        result.put("success", false);
        result.put("message", errorMessage);
        return result;
      }
    }
    result.put("success", true);
    result.put("message", errorMessage);
    return result;
  }