/** * 判断一个分类是否能被删除 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; }
/** * 构造商品运营分类Left tree的结构 * * @param 商品运营分类List * @return Left tree的HTML */ @Override public ProductCategory getProductCategoryByFirstId(String firstId) { ProductCategory sample = new ProductCategory(); sample.setFirstId(firstId); sample.setLayer(1); List<ProductCategory> list = getBySample(sample); if (list.size() > 0) { return list.get(0); } return null; }
/** * 根据三级分类ID得到三级分类 * * @param 三级分类ID * @return 三级分类 */ @Override public ProductCategory getProductCategoryByThirdId(String thirdId) { ProductCategory productCategory = new ProductCategory(); productCategory.setThirdId(thirdId); productCategory.setLayer(3); List<ProductCategory> list = getBySample(productCategory); if (list.size() > 0) { return list.get(0); } return null; }
/** * 判断一个分类是否置为无效 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; }