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 a7f4edb..ffb466c 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 @@ -18,6 +18,8 @@ public interface SupermarketProductMapper { */ public SupermarketProduct selectSupermarketProductByProductId(Long productId); + public List selectSupermarketProductByMaterialIds(Long[] materialIds); + /** * 查询超市商城商品列表 * diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/impl/SupermarketMaterialServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/impl/SupermarketMaterialServiceImpl.java index a4e38bd..a0bb2b1 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/impl/SupermarketMaterialServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/impl/SupermarketMaterialServiceImpl.java @@ -1,6 +1,9 @@ package com.bonus.canteen.core.supermarket.service.impl; import java.util.List; + +import com.bonus.canteen.core.supermarket.domain.SupermarketProduct; +import com.bonus.canteen.core.supermarket.mapper.SupermarketProductMapper; import com.bonus.common.core.exception.ServiceException; import com.bonus.common.core.utils.DateUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -8,6 +11,7 @@ import org.springframework.stereotype.Service; import com.bonus.canteen.core.supermarket.mapper.SupermarketMaterialMapper; import com.bonus.canteen.core.supermarket.domain.SupermarketMaterial; import com.bonus.canteen.core.supermarket.service.ISupermarketMaterialService; +import org.springframework.util.CollectionUtils; /** * 商品信息Service业务层处理 @@ -19,6 +23,8 @@ import com.bonus.canteen.core.supermarket.service.ISupermarketMaterialService; public class SupermarketMaterialServiceImpl implements ISupermarketMaterialService { @Autowired private SupermarketMaterialMapper supermarketMaterialMapper; + @Autowired + private SupermarketProductMapper supermarketProductMapper; /** * 查询商品信息 @@ -82,6 +88,10 @@ public class SupermarketMaterialServiceImpl implements ISupermarketMaterialServi */ @Override public int deleteSupermarketMaterialByMaterialIds(Long[] materialIds) { + List list = supermarketProductMapper.selectSupermarketProductByMaterialIds(materialIds); + if (!CollectionUtils.isEmpty(list)) { + throw new ServiceException("该原料下含有商品,不能删除"); + } return supermarketMaterialMapper.deleteSupermarketMaterialByMaterialIds(materialIds); } 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 c202325..7eb5dda 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 @@ -22,7 +22,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select product_id, supermarket_id, material_id, putaway_state, if_online, sale_price, pref_price, person_limit, one_day_limit, img_url, inventory_num, create_by, create_time, update_by, update_time from supermarket_product + select product_id, supermarket_id, material_id, putaway_state, if_online, sale_price, pref_price, + person_limit, one_day_limit, img_url, inventory_num, create_by, create_time, update_by, update_time + from supermarket_product + + insert into supermarket_product