shop--10.商品--解除商品与某商品类别的关联的实现

ProductDao.java

 

1     /**
2      * 删除商品类别之前,将商品类别Id置为空
3      * 
4      * @param productCategoryId
5      * @return
6      */
7     int updateProductCategoryToNull(long productCategoryId);

 

 

 

ProductDao.xml

 

    <update id="updateProductCategoryToNull" parameterType="Long">
        UPDATE
        tb_product
        SET
        product_category_id = null
        WHERE
        product_category_id = 
        #{productCategoryId}
    </update>

 

 

 

接着将之前的ProductCategoryServiceImpl中的删除给完善好

 

 1     //由于先将商品类别 商品id置为空 再删除 分为两步 所以使用事务
 2     @Transactional
 3     @Override
 4     public ProductCategoryExecution deleteProductCategory(long productCategoryId, long shopId)
 5             throws ProductCategoryOperationException {
 6         // TODO 将此商品类别下的商品Id置为空
 7         //解除tb_product里的商品与该productcategoryId的关联
 8         try {
 9             int effectedNum = productDao.updateProductCategoryToNull(productCategoryId);
10             if(effectedNum < 0) {
11                 throw new ProductCategoryOperationException("商品类别更新失败");
12             }
13         }catch (Exception e) {
14             throw new ProductCategoryOperationException("deleteProductCategory error" + e.getMessage());
15         }
16         //删除该productCategory
17         try {
18             int effectedNum = productCategoryDao.deleteProductCategory(productCategoryId, shopId);
19             if(effectedNum <= 0) {
20                 throw new ProductCategoryOperationException("商品类别删除失败");
21             }else {
22                 return new ProductCategoryExecution(ProductCategoryStateEnum.SUCCESS);
23             }
24         }catch (Exception e) {
25             throw new ProductCategoryOperationException("deleteProductCategory error :" + e.getMessage());
26         }
27     }

 

posted @ 2018-08-03 20:14  windbag7  阅读(296)  评论(0编辑  收藏  举报