diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/mapper/SupermarketProductMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/mapper/SupermarketProductMapper.java index 5fda026..4603f07 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/mapper/SupermarketProductMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/mapper/SupermarketProductMapper.java @@ -57,4 +57,6 @@ public interface SupermarketProductMapper { * @return 结果 */ public int deleteSupermarketProductByProductIds(Long[] productIds); + + public int getProductCountOfSupermarket(Long[] supermarketIds); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/impl/SupermarketInfoServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/impl/SupermarketInfoServiceImpl.java index cb72651..055c89c 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/impl/SupermarketInfoServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/impl/SupermarketInfoServiceImpl.java @@ -1,6 +1,8 @@ package com.bonus.canteen.core.supermarket.service.impl; import java.util.List; + +import com.bonus.canteen.core.supermarket.mapper.SupermarketProductMapper; import com.bonus.common.core.exception.ServiceException; import com.bonus.common.core.utils.DateUtils; import com.bonus.common.security.utils.SecurityUtils; @@ -20,6 +22,8 @@ import com.bonus.canteen.core.supermarket.service.ISupermarketInfoService; public class SupermarketInfoServiceImpl implements ISupermarketInfoService { @Autowired private SupermarketInfoMapper supermarketInfoMapper; + @Autowired + SupermarketProductMapper supermarketProductMapper; /** * 查询超市 @@ -85,6 +89,10 @@ public class SupermarketInfoServiceImpl implements ISupermarketInfoService { */ @Override public int deleteSupermarketInfoBySupermarketIds(Long[] supermarketIds) { + int count = supermarketProductMapper.getProductCountOfSupermarket(supermarketIds); + if (count > 0) { + throw new ServiceException("该超市含有商品,不能删除"); + } return supermarketInfoMapper.deleteSupermarketInfoBySupermarketIds(supermarketIds); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/supermarket/SupermarketProductMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/supermarket/SupermarketProductMapper.xml index fa4e16e..cb5349b 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/supermarket/SupermarketProductMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/supermarket/SupermarketProductMapper.xml @@ -173,4 +173,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{productId} + + \ No newline at end of file