Ejemplo n.º 1
0
 /**
  * 判断一个分类是否能被删除 1.该分类下面有商品(无论商品是什么状态)都不能删除 2.二级分类下面有三级分类(无论状态是什么)不能删除该二级分类
  * 3.一级分类下面有二级分类(无论状态是什么)不能删除该一级分类
  *
  * @param objectId
  * @return
  */
 @Override
 public boolean canDelete(Long objectId) {
   if (objectId == null) {
     return false;
   }
   ProductCategory category = getByObjectId(objectId);
   if (category.getLayer() == 1) {
     ProductCategory sample = new ProductCategory();
     sample.setFirstId(category.getFirstId());
     sample.setLayer(2);
     long count = getObjectCount(sample);
     if (count != 0) {
       return false;
     }
   } else if (category.getLayer() == 2) {
     ProductCategory sample = new ProductCategory();
     sample.setSecondId(category.getSecondId());
     sample.setLayer(3);
     long count = getObjectCount(sample);
     if (count != 0) {
       return false;
     }
   } else {
     Product sample = new Product();
     sample.setCategoryId(objectId);
     sample.setDeleted(IBSConstants.STATUS_NO);
     long count = productManager.getObjectCount(sample);
     if (count != 0) {
       return false;
     }
   }
   return true;
 }
Ejemplo n.º 2
0
 /**
  * 判断一个分类是否置为无效 1.二级分类下面有有效分类一级分类不能为无效 2.三级分类下面全部为无效则二级可为无效 3.关联的福利商城分类有效则三级分类不能无效
  * 4.该分类下面有商品(无论商品是什么状态)都不能置为无效
  *
  * @param objectId
  * @return
  */
 @Override
 public boolean canInvalid(Long objectId) {
   if (objectId == null) {
     return true;
   }
   ProductCategory category = getByObjectId(objectId);
   if (category.getLayer() == 1) {
     ProductCategory sample = new ProductCategory();
     sample.setFirstId(category.getFirstId());
     sample.setStatus(IBSConstants.EFFECTIVE);
     sample.setLayer(2);
     long count = getObjectCount(sample);
     if (count != 0) {
       return false;
     }
   } else if (category.getLayer() == 2) {
     ProductCategory sample = new ProductCategory();
     sample.setSecondId(category.getSecondId());
     sample.setStatus(IBSConstants.EFFECTIVE);
     sample.setLayer(3);
     long count = getObjectCount(sample);
     if (count != 0) {
       return false;
     }
   } else {
     // 是否有关联的福利商城的分类
     long mallCategoryCount =
         productMallCategoryDao.getRelatedProductMallCategoryByCategoryId(objectId);
     if (mallCategoryCount != 0) {
       return false;
     }
     Product sample = new Product();
     sample.setCategoryId(objectId);
     sample.setDeleted(IBSConstants.STATUS_NO);
     long count = productManager.getObjectCount(sample);
     if (count != 0) {
       return false;
     }
   }
   return true;
 }
Ejemplo n.º 3
0
  /** 保存时三级分类ID的序列化 */
  @Override
  @Transactional
  public ProductCategory save(ProductCategory entity) {
    if (entity.getLayer() == 1) {
      if (StringUtils.isBlank(entity.getFirstId())) {
        String firstId = sequenceManager.getNextId("SEQ_FIRST_ID").toString();
        entity.setFirstId(firstId);
      }
    } else if (entity.getLayer() == 2) {
      if (StringUtils.isBlank(entity.getSecondId())) {
        String secondId = sequenceManager.getNextId("SEQ_SECOND_ID").toString();
        entity.setSecondId(secondId);
      }
    } else if (entity.getLayer() == 3) {
      if (StringUtils.isBlank(entity.getThirdId())) {
        String thirdId = sequenceManager.getNextId("SEQ_THIRD_ID").toString();
        entity.setThirdId(thirdId);
      }
    } else {

    }
    return super.save(entity);
  }