Пример #1
0
 public ProductCategoryDTO getProductCategoryDTOById(Long shopId, Long id) {
   if (id == null) {
     return null;
   }
   ProductWriter productWriter = productDaoManager.getWriter();
   return productWriter.getById(ProductCategory.class, id).toDTO();
 }
Пример #2
0
  public List<ProductCategoryDTO> getProductCategoryByNameOrId(
      Long productCategoryId, String name, Long shopId, Pager pager) {
    ProductWriter productWriter = productDaoManager.getWriter();
    List<ProductCategory> productCategoryList = null;

    if (productCategoryId == null && StringUtil.isEmpty(name)) {
      productCategoryList = productWriter.getProductCategoryFuzzyName(shopId, null, pager);
      List<ProductCategoryDTO> productCategoryDTOList = new ArrayList<ProductCategoryDTO>();
      if (CollectionUtils.isNotEmpty(productCategoryList)) {
        for (ProductCategory productCategory : productCategoryList) {
          productCategoryDTOList.add(productCategory.toDTO());
        }
      }
      return productCategoryDTOList;
    }

    if (StringUtil.isNotEmpty(name)) {
      productCategoryList = productWriter.getProductCategoryFuzzyName(shopId, name, pager);
      List<ProductCategoryDTO> productCategoryDTOList = new ArrayList<ProductCategoryDTO>();
      if (CollectionUtils.isNotEmpty(productCategoryList)) {
        for (ProductCategory productCategory : productCategoryList) {
          productCategoryDTOList.add(productCategory.toDTO());
        }
      }
      return productCategoryDTOList;
    }

    if (productCategoryId != null) {
      List<ProductCategoryDTO> productCategoryDTOList =
          this.getProductCategoryDTOByParentId(shopId, productCategoryId, pager);
      return productCategoryDTOList;
    }

    return null;
  }
Пример #3
0
 @Override
 public List<ProductCategoryDTO> getProductCategoryDTOByIds(Set<Long> ids) {
   List<ProductCategoryDTO> productCategoryDTOList = new ArrayList<ProductCategoryDTO>();
   if (CollectionUtils.isEmpty(ids)) return productCategoryDTOList;
   ProductWriter productWriter = productDaoManager.getWriter();
   List<ProductCategory> entityList = productWriter.getProductCategoryByIds(ids);
   for (ProductCategory entity : entityList) {
     productCategoryDTOList.add(entity.toDTO());
   }
   return productCategoryDTOList;
 }
Пример #4
0
 public List<ProductCategoryDTO> getProductCategoryDTOByShopId(Long shopId) {
   List<ProductCategoryDTO> productCategoryDTOList = new ArrayList<ProductCategoryDTO>();
   ProductWriter productWriter = productDaoManager.getWriter();
   List<ProductCategory> productCategoryList = productWriter.getProductCategoryByShopId(shopId);
   if (CollectionUtils.isNotEmpty(productCategoryList)) {
     for (ProductCategory productCategory : productCategoryList) {
       productCategoryDTOList.add(productCategory.toDTO());
     }
   }
   return productCategoryDTOList;
 }
Пример #5
0
 @Override
 public List<ProductCategoryRelationDTO> productCategoryRelationDTOQuery(
     Long shopId, Long... productLocalInfoIds) {
   List<ProductCategoryRelationDTO> result = new ArrayList<ProductCategoryRelationDTO>();
   if (ArrayUtils.isEmpty(productLocalInfoIds) || shopId == null) {
     return result;
   }
   ProductWriter productWriter = productDaoManager.getWriter();
   List<ProductCategoryRelation> productCategoryRelations =
       productWriter.getProductCategoryRelations(shopId, productLocalInfoIds);
   if (CollectionUtils.isNotEmpty(productCategoryRelations)) {
     for (ProductCategoryRelation productCategoryRelation : productCategoryRelations) {
       result.add(productCategoryRelation.toDTO());
     }
   }
   return result;
 }
Пример #6
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;
  }
Пример #7
0
  @Override
  public void saveProductCategoryRelation(
      Long shopId, Long productCategoryId, Long productLocalInfoId) {
    ProductWriter productWriter = productDaoManager.getWriter();
    Object status = productWriter.begin();
    try {
      ProductCategoryRelation productCategoryRelation =
          CollectionUtil.getFirst(
              productWriter.getProductCategoryRelations(shopId, productLocalInfoId));
      if (productCategoryRelation == null) {
        productCategoryRelation = new ProductCategoryRelation();
        productCategoryRelation.setShopId(shopId);
        productCategoryRelation.setProductLocalInfoId(productLocalInfoId);
      }

      productCategoryRelation.setProductCategoryId(productCategoryId);
      productWriter.saveOrUpdate(productCategoryRelation);
      productWriter.commit(status);
    } finally {
      productWriter.rollback(status);
    }
  }
Пример #8
0
  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;
  }
Пример #9
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;
  }
Пример #10
0
 public ProductCategoryDTO saveOrUpdateProductCategoryDTO(ProductCategoryDTO productCategoryDTO) {
   if (productCategoryDTO == null) {
     return productCategoryDTO;
   }
   ProductWriter writer = productDaoManager.getWriter();
   Object status = writer.begin();
   ProductCategory productCategory = null;
   try {
     if (productCategoryDTO.getId() == null) {
       productCategory = new ProductCategory(productCategoryDTO);
       writer.save(productCategory);
     } else {
       productCategory = writer.getById(ProductCategory.class, productCategoryDTO.getId());
       productCategory = productCategory.fromDTO(productCategoryDTO, false);
       writer.saveOrUpdate(productCategory);
     }
     writer.commit(status);
     productCategoryDTO = productCategory.toDTO();
   } finally {
     writer.rollback(status);
   }
   return productCategoryDTO;
 }
Пример #11
0
  public ProdCategorySearchResult getProductCategoryDTOByCondition(
      ProdCategorySearchCondition prodCategorySearchCondition) {
    if (prodCategorySearchCondition == null) {
      return null;
    }
    ProductWriter productWriter = productDaoManager.getWriter();
    ProdCategorySearchResult prodCategorySearchResult = new ProdCategorySearchResult();

    int totalRows =
        this.countCategoryByNameOrId(
            productWriter,
            prodCategorySearchCondition.getProductCategoryId(),
            prodCategorySearchCondition.getProductCategoryName(),
            prodCategorySearchCondition.getShopId());
    prodCategorySearchResult.setTotalRows(totalRows);

    if (prodCategorySearchCondition.isHasPager()) {
      Pager pager = new Pager();
      pager.setRowStart(prodCategorySearchCondition.getStart());
      pager.setPageSize(prodCategorySearchCondition.getLimit());
      prodCategorySearchCondition.setPager(pager);
    }
    List<ProductCategoryDTO> productCategoryDTOList =
        this.getProductCategoryByNameOrId(
            prodCategorySearchCondition.getProductCategoryId(),
            prodCategorySearchCondition.getProductCategoryName(),
            prodCategorySearchCondition.getShopId(),
            prodCategorySearchCondition.getPager());
    if (CollectionUtils.isEmpty(productCategoryDTOList)) {
      return null;
    }
    this.fillProductCategoryDTOListInfo(productCategoryDTOList);

    prodCategorySearchResult.setResults(productCategoryDTOList);
    prodCategorySearchResult.setSuccess(true);
    return prodCategorySearchResult;
  }
Пример #12
0
 @Override
 public List<Long> getProductCategoryIdsByShopId(Long shopId, int start, int pageSize) {
   ProductWriter productWriter = productDaoManager.getWriter();
   return productWriter.getProductCategoryIdsByShopId(shopId, start, pageSize);
 }