コード例 #1
0
 @Override
 @Transactional
 public void removeProduct(long id) {
   Product product = productDaoImpl.getProduct(id);
   productDaoImpl.removeProduct(id);
   File file = new File(Product.PRODUCT_IMAGES_DIR + product.getImagepath());
   if (file.exists()) {
     file.delete();
   }
 }
コード例 #2
0
 @Override
 @Transactional
 public void updateProduct(Product product) {
   if (product.getCreatedAt() == null) {
     product.setCreatedAt(new Date());
   }
   if (product.getUpdatedAt() == null) {
     product.setUpdatedAt(new Date());
   }
   productDaoImpl.updateProduct(product);
 }
コード例 #3
0
  @Override
  @Transactional
  public void renewalProducts(
      Map<String, Product> mapNewProducts, Map<String, Manufactorer> mapManufactorer) {
    // сделать всех стрых неактивными
    this.disableExistsProducts();

    // найти всех старых
    Map<String, Product> existsProducts = new HashMap<String, Product>();
    List<Product> listProducts = this.listProducts();

    for (Product product : listProducts) {
      existsProducts.put(product.getNomencloture(), product);
    }

    Product currentProduct;
    int counter = 0;

    try {
      for (Map.Entry<String, Product> entry : mapNewProducts.entrySet()) {
        counter++;
        if (counter == 393) {
          System.out.println("wqw");
        }
        if (existsProducts.containsKey(entry.getKey())) {
          currentProduct = existsProducts.get(entry.getKey());

          // возьмем производителя
          String manufactorerTitle = currentProduct.getManufactorer().getTitle();
          if (mapManufactorer.containsKey(manufactorerTitle)) {
            currentProduct.setManufactorer(mapManufactorer.get(manufactorerTitle));
            currentProduct.setState(Product.STATE_ACTIVE);
            this.updateProduct(currentProduct);
          }
        } else {
          // добавим в бд
          currentProduct = mapNewProducts.get(entry.getKey());

          // возьмем производителя
          String manufactorerTitle = currentProduct.getManufactorerName();
          if (mapManufactorer.containsKey(manufactorerTitle)) {
            // проверить производителя на активность

            Manufactorer man = mapManufactorer.get(manufactorerTitle);

            currentProduct.setManufactorer(mapManufactorer.get(manufactorerTitle));
            currentProduct.setState(Product.STATE_ACTIVE);

            this.addProduct(currentProduct);

            // получим и обновим id
            currentProduct.setId((this.getLastInsertedId()).longValue());
            mapNewProducts.put(currentProduct.getNomencloture(), currentProduct);
          } else {
            // нет производителя
          }
        }
      }
    } catch (Exception e) {
      System.out.println(e.getStackTrace());
    }
  }