更新商城前端商品,购物车,订单的价格,后端存储的时候单位分,显示的时候统一转为元
This commit is contained in:
parent
6b7ba7258c
commit
28452bab26
@ -47,9 +47,7 @@ public class AppGoodsController {
|
||||
@Operation(summary = "根据商品类型查询")
|
||||
@LogPrint
|
||||
public ResultBean<PageListBean<GoodsResp>> getPageListByCategoryId(@RequestBody @Validated CategoryTypeReq params) {
|
||||
IPage<GoodsEntity> page = goodsService.getPageListByCategoryId(params);
|
||||
PageListBean<GoodsResp> pageListBean = PageConverterUtils.convertPageListBean(page, GoodsConvert.INSTANCE::convertList);
|
||||
return ResultBean.success(pageListBean);
|
||||
return ResultBean.success(goodsService.getPageListByCategoryId(params));
|
||||
}
|
||||
|
||||
@PostMapping("/paged")
|
||||
@ -81,8 +79,6 @@ public class AppGoodsController {
|
||||
@Operation(summary = "商品查询")
|
||||
@LogPrint
|
||||
public ResultBean<PageListBean<GoodsResp>> searchGoods(@RequestBody @Validated GoodSearchReq params){
|
||||
IPage<GoodsEntity> page = goodsService.searchGoods(params);
|
||||
PageListBean<GoodsResp> pageListBean = PageConverterUtils.convertPageListBean(page, GoodsConvert.INSTANCE::convertList);
|
||||
return ResultBean.success(pageListBean);
|
||||
return ResultBean.success(goodsService.searchGoods(params));
|
||||
}
|
||||
}
|
||||
@ -1,16 +1,12 @@
|
||||
package com.seer.teach.mall.app.good.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.seer.teach.common.PageListBean;
|
||||
import com.seer.teach.mall.entity.GoodsEntity;
|
||||
import com.seer.teach.mall.request.CategoryTypeReq;
|
||||
import com.seer.teach.mall.request.GoodSearchReq;
|
||||
import com.seer.teach.mall.request.GoodsDetailsReq;
|
||||
import com.seer.teach.mall.response.GoodSpuDetailResp;
|
||||
import com.seer.teach.mall.response.GoodsResp;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 商城商品服务类
|
||||
@ -22,32 +18,36 @@ import java.util.Set;
|
||||
public interface IAppGoodsService {
|
||||
|
||||
/**
|
||||
* 根据商品类别查询
|
||||
* @param params
|
||||
* @return
|
||||
* 根据商品类别查询商品列表
|
||||
*
|
||||
* @param params 商品类别查询参数,包含分类ID、分页信息等
|
||||
* @return 分页商品列表响应数据
|
||||
*/
|
||||
IPage<GoodsEntity> getPageListByCategoryId(CategoryTypeReq params);
|
||||
PageListBean<GoodsResp> getPageListByCategoryId(CategoryTypeReq params);
|
||||
|
||||
/**
|
||||
* 商品详情页查询
|
||||
* @param params
|
||||
* @return
|
||||
* 查询商品详情信息
|
||||
*
|
||||
* @param params 商品详情查询参数,包含商品SPU ID等信息
|
||||
* @return 商品详细信息响应数据
|
||||
*/
|
||||
GoodSpuDetailResp getGoodsDetails(GoodsDetailsReq params);
|
||||
|
||||
/**
|
||||
* Author: afa
|
||||
* Desc: 商品模糊查询
|
||||
* Params: params
|
||||
* Time: 2025/6/19 20:39
|
||||
* 商品模糊搜索功能
|
||||
* 支持按商品名称、描述等关键字进行模糊匹配搜索
|
||||
*
|
||||
* @param params 商品搜索参数,包含搜索关键字、筛选条件等
|
||||
* @return 分页搜索结果列表
|
||||
*/
|
||||
IPage<GoodsEntity> searchGoods(GoodSearchReq params);
|
||||
|
||||
PageListBean<GoodsResp> searchGoods(GoodSearchReq params);
|
||||
|
||||
/**
|
||||
* 商品分页查询
|
||||
* @param params
|
||||
* @return
|
||||
* 支持多种筛选条件的商品列表分页查询
|
||||
*
|
||||
* @param params 商品查询参数,包含分页、排序、筛选条件等
|
||||
* @return 分页商品列表响应数据
|
||||
*/
|
||||
PageListBean<GoodsResp> getPageList(GoodSearchReq params);
|
||||
}
|
||||
}
|
||||
@ -36,9 +36,7 @@ import java.util.Set;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* WechatGoodsServiceImpl类实现IWechatGoodsService接口,提供微信商城商品相关服务
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@ -48,32 +46,23 @@ public class AppGoodsServiceImpl implements IAppGoodsService {
|
||||
|
||||
private final IAppGoodsSpecificationService specificationService;
|
||||
|
||||
/**
|
||||
* 根据商品类别查询商品列表
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public IPage<GoodsEntity> getPageListByCategoryId(CategoryTypeReq params) {
|
||||
public PageListBean<GoodsResp> getPageListByCategoryId(CategoryTypeReq params) {
|
||||
Page<GoodsEntity> page = new Page<>(params.getPage(), params.getLimits());
|
||||
IPage<GoodsEntity> pageList = goodsService.page(page,
|
||||
Wrappers.lambdaQuery(GoodsEntity.class)
|
||||
.eq(GoodsEntity::getCategoryId, params.getCategoryId())
|
||||
.eq(StringUtils.isNotBlank(params.getTenantId()),GoodsEntity::getTenantId, params.getTenantId()));
|
||||
if(CollectionUtils.isEmpty(pageList.getRecords())){
|
||||
return new Page<>();
|
||||
return new PageListBean<>();
|
||||
}
|
||||
pageList.getRecords().forEach(item-> {
|
||||
item.setSalesCount(item.getSalesCount() + item.getVirtualSellVolume());
|
||||
});
|
||||
return pageList;
|
||||
return PageConverterUtils.convertPageListBean(page, GoodsConvert.INSTANCE::convertList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商品ID查询商品详情
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Override
|
||||
public GoodSpuDetailResp getGoodsDetails(GoodsDetailsReq params) {
|
||||
GoodsEntity goodsEntity = goodsService.getById(params.getId());
|
||||
@ -117,7 +106,7 @@ public class AppGoodsServiceImpl implements IAppGoodsService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<GoodsEntity> searchGoods(GoodSearchReq params) {
|
||||
public PageListBean<GoodsResp> searchGoods(GoodSearchReq params) {
|
||||
// 创建一个分页对象
|
||||
Page<GoodsEntity> page = Page.of(params.getPageNo(), params.getPageSize());
|
||||
// 初始化返回的分页列表对象
|
||||
@ -136,28 +125,26 @@ public class AppGoodsServiceImpl implements IAppGoodsService {
|
||||
if(log.isDebugEnabled()){
|
||||
log.info("模糊查询商品列表结果:{}", resultPage.getRecords());
|
||||
}
|
||||
return resultPage;
|
||||
return PageConverterUtils.convertPageListBean(page, GoodsConvert.INSTANCE::convertList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public PageListBean<GoodsResp> getPageList(GoodSearchReq searchReq) {
|
||||
IPage<GoodsEntity> iPage = searchGoods(searchReq);
|
||||
List<GoodsEntity> records = iPage.getRecords();
|
||||
PageListBean<GoodsResp> iPage = searchGoods(searchReq);
|
||||
List<GoodsResp> records = iPage.getList();
|
||||
if(CollectionUtils.isEmpty(records)){
|
||||
return new PageListBean<>();
|
||||
}
|
||||
Set<Integer> goodIds = records.stream().map(GoodsEntity::getId).collect(Collectors.toSet());
|
||||
Set<Integer> goodIds = records.stream().map(GoodsResp::getId).collect(Collectors.toSet());
|
||||
List<GoodsSpecificationEntity> specificationEntities = specificationService.list(new LambdaUpdateWrapper<>(GoodsSpecificationEntity.class).in(GoodsSpecificationEntity::getGoodsId,goodIds));
|
||||
PageListBean<GoodsResp> pageListBean = PageConverterUtils.convertPageListBean(iPage, GoodsConvert.INSTANCE::convertList);
|
||||
|
||||
List<GoodsSpecificationResp> goodsSpecificationRespList = GoodsSpecificationConvert.INSTANCE.list(specificationEntities);
|
||||
Map<Integer, List<GoodsSpecificationResp>> specificationMap = goodsSpecificationRespList.stream().collect(Collectors.groupingBy(GoodsSpecificationResp::getGoodsId));
|
||||
pageListBean.getList().forEach(goodsResp -> {
|
||||
iPage.getList().forEach(goodsResp -> {
|
||||
goodsResp.setSpecifications(specificationMap.get(goodsResp.getId()));
|
||||
});
|
||||
return pageListBean;
|
||||
return iPage;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user