瀏覽代碼

http://192.168.0.21/index.php?m=bug&f=view&bugID=25872 绑定修改

lyhzzz 3 年之前
父節點
當前提交
28069a3e76

+ 1 - 0
platform-shop/src/main/java/com/platform/controller/CategoryController.java

@@ -7,6 +7,7 @@ import com.platform.service.CategoryService;
 import com.platform.utils.PageUtils;
 import com.platform.utils.Query;
 
+import com.platform.utils.RRException;
 import com.platform.utils.TreeUtils;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;

+ 2 - 0
platform-shop/src/main/java/com/platform/dao/GoodsDao.java

@@ -14,4 +14,6 @@ public interface GoodsDao extends BaseDao<GoodsEntity> {
     Integer queryMaxId();
 
     int deleteByBrandId(@Param("brandId") Long brandId);
+
+    Integer queryCountByCategoryIds(@Param("ids")Integer[] ids);
 }

+ 1 - 1
platform-shop/src/main/java/com/platform/service/impl/BrandServiceImpl.java

@@ -374,7 +374,7 @@ public class BrandServiceImpl implements BrandService {
 
         if(brandBindUserVoList !=null && brandBindUserVoList.size() >0){
             for (BrandBindUserVo vo : brandBindUserVoList) {
-                bindUser(vo.getUserId(), vo.getBrandId(), vo.getCanShow());
+                bindUser(vo.getUserId(), brandId, vo.getCanShow());
             }
         }
 

+ 12 - 1
platform-shop/src/main/java/com/platform/service/impl/CategoryServiceImpl.java

@@ -1,10 +1,13 @@
 package com.platform.service.impl;
 
 import com.platform.dao.CategoryDao;
+import com.platform.dao.GoodsDao;
 import com.platform.entity.CategoryEntity;
 import com.platform.entity.Result;
 import com.platform.service.CategoryService;
 
+import com.platform.service.GoodsService;
+import com.platform.utils.RRException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -24,7 +27,8 @@ import java.util.Map;
 public class CategoryServiceImpl implements CategoryService {
     @Autowired
     private CategoryDao categoryDao;
-
+    @Autowired
+    private GoodsDao goodsDao;
     @Override
     public CategoryEntity queryObject(Integer id) {
         return categoryDao.queryObject(id);
@@ -82,6 +86,13 @@ public class CategoryServiceImpl implements CategoryService {
     @Override
     @Transactional
     public int deleteBatch(Integer[] ids) {
+        if(ids == null || ids.length <= 0){
+            throw new RRException("参数为空!");
+        }
+        Integer count = goodsDao.queryCountByCategoryIds(ids);
+        if(count > 0){
+            throw new RRException("该分类已绑定商品!");
+        }
         categoryDao.deleteByParentBatch(ids);
         return categoryDao.deleteBatch(ids);
     }

+ 7 - 0
platform-shop/src/main/resources/com/platform/dao/GoodsDao.xml

@@ -383,4 +383,11 @@
     <delete id="deleteByBrandId">
         delete from nideshop_goods where brand_id = #{brandId}
     </delete>
+
+    <select id="queryCountByCategoryIds" resultType="integer">
+        select count(id) from nideshop_goods where category_id in
+        <foreach item="id" collection="ids" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </select>
 </mapper>