新增 删除商品sku信息同时删除es中数据
This commit is contained in:
		@@ -86,7 +86,7 @@ public class SkuInfoController {
 | 
			
		||||
    //TODO 删除es
 | 
			
		||||
    public Result remove(@PathVariable Long id) {
 | 
			
		||||
        try {
 | 
			
		||||
            skuInfoService.removeById(id);
 | 
			
		||||
            skuInfoService.deleteById(id);
 | 
			
		||||
            return Result.ok(null);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("删除商品sku信息异常", e);
 | 
			
		||||
@@ -98,7 +98,7 @@ public class SkuInfoController {
 | 
			
		||||
    //TODO 删除es
 | 
			
		||||
    public Result batchRemove(@RequestBody List<Long> idList) {
 | 
			
		||||
        try {
 | 
			
		||||
            skuInfoService.removeByIds(idList);
 | 
			
		||||
            skuInfoService.deleteByIds(idList);
 | 
			
		||||
            return Result.ok(null);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw new RuntimeException("根据id列表删除商品sku信息异常", e);
 | 
			
		||||
 
 | 
			
		||||
@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.service.IService;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * <p>
 | 
			
		||||
 * sku信息 服务类
 | 
			
		||||
@@ -29,4 +31,8 @@ public interface SkuInfoService extends IService<SkuInfo> {
 | 
			
		||||
    void publish(Long skuId, Integer status);
 | 
			
		||||
 | 
			
		||||
    void isNewPerson(Long skuId, Integer status);
 | 
			
		||||
 | 
			
		||||
    void deleteByIds(List<Long> idList);
 | 
			
		||||
 | 
			
		||||
    void deleteById(Long id);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -202,6 +202,7 @@ public class SkuInfoServiceImpl extends ServiceImpl<SkuInfoMapper, SkuInfo> impl
 | 
			
		||||
     * @param skuId
 | 
			
		||||
     * @param status
 | 
			
		||||
     */
 | 
			
		||||
    @Transactional(rollbackFor = {Exception.class})
 | 
			
		||||
    @Override
 | 
			
		||||
    public void publish(Long skuId, Integer status) {
 | 
			
		||||
        // 更改发布状态
 | 
			
		||||
@@ -235,6 +236,24 @@ public class SkuInfoServiceImpl extends ServiceImpl<SkuInfoMapper, SkuInfo> impl
 | 
			
		||||
        baseMapper.updateById(skuInfo);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void deleteByIds(List<Long> idList) {
 | 
			
		||||
        baseMapper.deleteBatchIds(idList);
 | 
			
		||||
 | 
			
		||||
        //商品下架:发送mq消息同步es
 | 
			
		||||
        for (Long id : idList) {
 | 
			
		||||
            rabbitService.sendMessage(MqConst.EXCHANGE_GOODS_DIRECT, MqConst.ROUTING_GOODS_LOWER, id);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void deleteById(Long id) {
 | 
			
		||||
        baseMapper.deleteById(id);
 | 
			
		||||
 | 
			
		||||
        //商品删除:发送mq消息同步es
 | 
			
		||||
        rabbitService.sendMessage(MqConst.EXCHANGE_GOODS_DIRECT, MqConst.ROUTING_GOODS_LOWER, id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private SkuInfoVo getSkuInfoDB(Long skuId) {
 | 
			
		||||
        SkuInfoVo skuInfoVo = new SkuInfoVo();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user