feat(goods): 添加商品信息列表查询功能并优化相关逻辑

- 在 ProductBo 中添加 id 字段用于查询
- 实现 ProductBusinessImpl 中的 page 方法用于分页查询
- 更新 ProductService 接口,将 IPage 改为 Page 类型
- 修改 ProductServiceImpl 中的 getList 方法,适应新的 Page 类型
- 优化 SysTenantMapper.xml 中的 SQL 查询条件
This commit is contained in:
huk 2025-09-13 17:27:12 +08:00
parent 4479995b17
commit 9a6f0e14d7
7 changed files with 25 additions and 7 deletions

View File

@ -14,6 +14,7 @@ import com.wzj.soopin.goods.service.ProductService;
import com.wzj.soopin.goods.service.SkuService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.web.core.BusinessImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -31,6 +32,14 @@ public class ProductBusinessImpl extends BusinessImpl<ProductService, ProductCon
private final SkuConvert skuConvert;
@Override
public Page<ProductVO> page(ProductBo bo) {
Page<Product> page = new Page<>();
page.setCurrent(bo.getCurrent());
page.setSize(bo.getSize());
return productService.getList(bo, page);
}
@Transactional(rollbackFor = Exception.class)
@Override
public boolean save(ProductBo bo) {
@ -38,13 +47,19 @@ public class ProductBusinessImpl extends BusinessImpl<ProductService, ProductCon
Product product = converter.toPo(bo);
product.setType(1);
product.setSales("0");
product.setTenantId(LoginHelper.getTenantId());
productService.saveOrUpdate(product);
//清理掉旧的SKU
skuService.remove(new LambdaQueryWrapper<Sku>().eq(Sku::getProductId, product.getId()));
// 2. 保存SKU列表
if (CollectionUtils.isNotEmpty(bo.getSkuList())) {
List<Sku> skus = bo.getSkuList().stream()
.map(skuBO -> skuConvert.toPo(skuBO))
.map(skuBO -> {
Sku sku = skuConvert.toPo(skuBO);
sku.setProductId(product.getId());
sku.setTenantId(LoginHelper.getTenantId());
return sku;
})
.collect(Collectors.toList());
skuService.saveBatch(skus);
}

View File

@ -35,7 +35,7 @@ public class ProductController extends BaseController {
@Tag(name ="查询商品信息列表")
@PostMapping("list")
public R<IPage<ProductVO>> list(@RequestBody ProductBo bo) {
public R<IPage<ProductVO>> list(@RequestBody ProductBo bo,@RequestBody Page<Product> page) {
return R.ok(business.page(bo));
}

View File

@ -14,6 +14,9 @@ import java.util.List;
@Schema(description = "商品信息 查询 对象")
public class ProductBo extends BaseBO<Product> {
@Schema(description = "主键")
private Long id;
@Schema(description = "BRAND_ID 精确匹配")
private Long brandId;

View File

@ -33,7 +33,7 @@ public interface ProductMapper extends BaseMapper<Product> {
@InterceptorIgnore(tenantLine = "true")
IPage<ProductVO> getlist(@Param("page") Page<Product> page, @Param("query") ProductBo query, @Param("tenantIds") List<String> tenantIds);
Page<ProductVO> getlist(@Param("page") Page<Product> page, @Param("query") ProductBo query, @Param("tenantIds") List<String> tenantIds);

View File

@ -9,7 +9,7 @@ import com.wzj.soopin.goods.domain.vo.ProductVO;
public interface ProductService extends IService<Product> {
IPage<ProductVO> getList(ProductBo query, Page<Product> page);
Page<ProductVO> getList(ProductBo query, Page<Product> page);
IPage<ProductVO> getRecommendPage(Page<Product> page);

View File

@ -46,7 +46,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
private final SysUserTenantMapper sysUserTenantMapper;
@Override
public IPage<ProductVO> getList(ProductBo query, Page<Product> page) {
public Page<ProductVO> getList(ProductBo query, Page<Product> page) {
String tenantId = LoginHelper.getTenantId();
List<String> tenantIds = CollUtil.newArrayList(tenantId);
if(LoginHelper.isTenantAdmin()){

View File

@ -29,7 +29,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND e.person_name LIKE CONCAT('%', #{query.personName}, '%')
</if>
<if test="query.storeName != null and query.storeName != ''">
AND e.store_name LIKE CONCAT('%', #{query.storeName}, '%')
AND t.store_name LIKE CONCAT('%', #{query.storeName}, '%')
</if>
<if test="query.contactUserName != null and query.contactUserName != ''">
AND t.contact_user_name LIKE CONCAT('%', #{query.contactUserName}, '%')
@ -41,7 +41,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND t.contact_phone LIKE CONCAT('%', #{query.contactPhone}, '%')
</if>
<if test="query.entryTime != null and query.entryTime != ''">
AND t.entry_time LIKE CONCAT('%', #{query.entryTime}, '%')
AND e.entry_time LIKE CONCAT('%', #{query.entryTime}, '%')
</if>
<if test="query.birthday != null and query.birthday != ''">
AND t.birthday LIKE CONCAT('%', #{query.birthday}, '%')