fix:【商城】已删除的商品,无法评论,导致 TradeOrderAutoCommentJob 重复持续运行

This commit is contained in:
YunaiV 2025-04-30 21:29:50 +08:00
parent 361e50e5de
commit 95b8cf00fd
7 changed files with 46 additions and 2 deletions

View File

@ -6,6 +6,8 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.Collection;
import java.util.List;
@ -13,6 +15,9 @@ import java.util.List;
@Mapper
public interface ProductSkuMapper extends BaseMapperX<ProductSkuDO> {
@Select("SELECT * FROM product_sku WHERE id = #{id}")
ProductSkuDO selectByIdIncludeDeleted(@Param("id") Long id);
default List<ProductSkuDO> selectListBySpuId(Long spuId) {
return selectList(ProductSkuDO::getSpuId, spuId);
}

View File

@ -11,6 +11,8 @@ import cn.iocoder.yudao.module.product.enums.ProductConstants;
import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.Objects;
import java.util.Set;
@ -18,6 +20,9 @@ import java.util.Set;
@Mapper
public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> {
@Select("SELECT * FROM product_spu WHERE id = #{id}")
ProductSpuDO selectByIdIncludeDeleted(@Param("id") Long id);
/**
* 获取商品 SPU 分页列表数据
*

View File

@ -91,7 +91,7 @@ public class ProductCommentServiceImpl implements ProductCommentService {
}
private ProductSkuDO validateSku(Long skuId) {
ProductSkuDO sku = productSkuService.getSku(skuId);
ProductSkuDO sku = productSkuService.getSku(skuId, true);
if (sku == null) {
throw exception(SKU_NOT_EXISTS);
}
@ -99,7 +99,7 @@ public class ProductCommentServiceImpl implements ProductCommentService {
}
private ProductSpuDO validateSpu(Long spuId) {
ProductSpuDO spu = productSpuService.getSpu(spuId);
ProductSpuDO spu = productSpuService.getSpu(spuId, true);
if (null == spu) {
throw exception(SPU_NOT_EXISTS);
}

View File

@ -29,6 +29,15 @@ public interface ProductSkuService {
*/
ProductSkuDO getSku(Long id);
/**
* 获得商品 SKU 信息
*
* @param id 编号
* @param includeDeleted 是否包含已删除的
* @return 商品 SKU 信息
*/
ProductSkuDO getSku(Long id, boolean includeDeleted);
/**
* 获得商品 SKU 列表
*

View File

@ -68,6 +68,14 @@ public class ProductSkuServiceImpl implements ProductSkuService {
return productSkuMapper.selectById(id);
}
@Override
public ProductSkuDO getSku(Long id, boolean includeDeleted) {
if (includeDeleted) {
return productSkuMapper.selectByIdIncludeDeleted(id);
}
return getSku(id);
}
@Override
public List<ProductSkuDO> getSkuList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {

View File

@ -51,6 +51,15 @@ public interface ProductSpuService {
*/
ProductSpuDO getSpu(Long id);
/**
* 获得商品 SPU
*
* @param id 编号
* @param includeDeleted 是否包含已删除的
* @return 商品 SPU
*/
ProductSpuDO getSpu(Long id, boolean includeDeleted);
/**
* 获得商品 SPU 列表
*

View File

@ -189,6 +189,14 @@ public class ProductSpuServiceImpl implements ProductSpuService {
return productSpuMapper.selectById(id);
}
@Override
public ProductSpuDO getSpu(Long id, boolean includeDeleted) {
if (includeDeleted) {
return productSpuMapper.selectByIdIncludeDeleted(id);
}
return getSpu(id);
}
@Override
public List<ProductSpuDO> getSpuList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {