예제 #1
0
 @Override
 public List<ProductCategoryDTO> getRecentlyUsedProductCategoryDTOList(Long shopId, Long userId) {
   List<ProductCategoryDTO> productCategoryDTOList = new ArrayList<ProductCategoryDTO>();
   if (shopId == null) return productCategoryDTOList;
   IRecentlyUsedDataService recentlyUsedDataService =
       ServiceManager.getService(IRecentlyUsedDataService.class);
   int maxSize = ConfigUtils.getRecentlyUsedProductCategoryNum();
   List<RecentlyUsedDataDTO> recentlyUsedDataDTOList =
       recentlyUsedDataService.getRecentlyUsedDataDTOList(
           shopId, userId, RecentlyUsedDataType.USED_PRODUCT_CATEGORY, maxSize);
   if (CollectionUtils.isNotEmpty(recentlyUsedDataDTOList)) {
     Set<Long> prouctCategoryIdSet = new HashSet<Long>();
     for (RecentlyUsedDataDTO recentlyUsedDataDTO : recentlyUsedDataDTOList) {
       prouctCategoryIdSet.add(recentlyUsedDataDTO.getDataId());
     }
     List<ProductCategoryDTO> productCategoryDTOs =
         getProductCategoryDTOByIds(prouctCategoryIdSet);
     fillProductCategoryDTOListInfo(productCategoryDTOs);
     Map<Long, ProductCategoryDTO> productCategoryDTOMap = new HashMap<Long, ProductCategoryDTO>();
     for (ProductCategoryDTO productCategoryDTO : productCategoryDTOs) {
       productCategoryDTOMap.put(productCategoryDTO.getId(), productCategoryDTO);
     }
     ProductCategoryDTO productCategoryDTO = null;
     for (RecentlyUsedDataDTO recentlyUsedDataDTO : recentlyUsedDataDTOList) {
       productCategoryDTO = productCategoryDTOMap.get(recentlyUsedDataDTO.getDataId());
       if (productCategoryDTO != null) {
         productCategoryDTOList.add(productCategoryDTO);
       }
     }
   }
   return productCategoryDTOList;
 }
예제 #2
0
  public Map<String, Object> validateCategoryName(
      ProductCategoryDTO productCategoryDTO, ProductCategoryType productCategoryType) {
    Map<String, Object> result = new HashMap<String, Object>();
    String errorMessage = "";

    if (productCategoryType == ProductCategoryType.FIRST_CATEGORY) {

      if (StringUtils.isEmpty(productCategoryDTO.getFirstCategoryName())) {
        errorMessage = ProductCategoryConstant.FIRST_CATEGORY_EMPTY;
        result.put("success", false);
        result.put("message", errorMessage);
        return result;
      }
      if (productCategoryDTO.getFirstCategoryName().length()
          > productCategoryDTO.getFirstCategoryName().trim().length()) {
        errorMessage = ProductCategoryConstant.FIRST_CATEGORY_CONTAIN_SPACE;
        result.put("success", false);
        result.put("message", errorMessage);
        return result;
      }
    } else if (productCategoryType == ProductCategoryType.SECOND_CATEGORY) {
      if (StringUtils.isEmpty(productCategoryDTO.getSecondCategoryName())) {
        errorMessage = ProductCategoryConstant.SECOND_CATEGORY_EMPTY;
        result.put("success", false);
        result.put("message", errorMessage);
        return result;
      }
      if (productCategoryDTO.getSecondCategoryName().length()
          > productCategoryDTO.getSecondCategoryName().trim().length()) {
        errorMessage = ProductCategoryConstant.SECOND_CATEGORY_CONTAIN_SPACE;
        result.put("success", false);
        result.put("message", errorMessage);
        return result;
      }
    } else if (productCategoryType == ProductCategoryType.THIRD_CATEGORY) {
      if (StringUtils.isEmpty(productCategoryDTO.getThirdCategoryName())) {
        errorMessage = ProductCategoryConstant.THIRD_CATEGORY_EMPTY;
        result.put("success", false);
        result.put("message", errorMessage);
        return result;
      }
      if (productCategoryDTO.getThirdCategoryName().length()
          > productCategoryDTO.getThirdCategoryName().trim().length()) {
        errorMessage = ProductCategoryConstant.THIRD_CATEGORY_CONTAIN_SPACE;
        result.put("success", false);
        result.put("message", errorMessage);
        return result;
      }
    }

    result.put("success", true);
    result.put("message", ProductCategoryConstant.VALIDATE_SUCCESS);
    return result;
  }
예제 #3
0
  @Override
  public Node getCheckedBusinessScope(Long shopId, Set<Long> ids) {
    List<ProductCategoryDTO> productCategoryDTOList =
        this.getProductCategoryDTOByShopId(ShopConstant.BC_ADMIN_SHOP_ID);

    // 经营范围
    List<ProductCategoryDTO> shopBusinessScopeDTOList = this.getProductCategoryDTOByIds(ids);
    Map<Long, Object> map = new HashMap<Long, Object>();
    for (ProductCategoryDTO dto : shopBusinessScopeDTOList) {
      map.put(dto.getId(), dto);
    }
    CheckNode root = (CheckNode) buildCheckProductCategoryTree(productCategoryDTOList, map);
    root.reBuildTreeForChecked();
    return root;
  }
예제 #4
0
 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;
 }
예제 #5
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;
 }
예제 #6
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;
  }
예제 #7
0
  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;
  }
예제 #8
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;
  }