Example #1
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;
 }
Example #2
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);
    }
  }