Update ProdController.java

cyj
pbvfus8to 8 months ago
parent ef4d91a5d9
commit f320a67c5e

@ -37,6 +37,9 @@ import java.util.List;
import java.util.stream.Collectors;
/**
*
* 使
*
* @author lgh on 2018/11/26.
*/
@RestController
@ -44,49 +47,72 @@ import java.util.stream.Collectors;
@Tag(name = "商品接口")
public class ProdController {
// 自动注入商品服务层接口,用于调用与商品相关的核心业务逻辑方法,如根据分类 ID 查询商品列表、获取商品详情等操作
@Autowired
private ProductService prodService;
// 自动注入库存单元SKU服务层接口用于获取商品对应的 SKU 相关信息,例如根据商品 ID 查询其所有的 SKU 列表等操作
@Autowired
private SkuService skuService;
// 自动注入运费模板服务层接口,用于获取商品相关的运费模板信息,比如根据运费模板 ID 获取详细的运费模板及关联信息
@Autowired
private TransportService transportService;
/**
* ID ID ID
* 便
*
* @param categoryId ID
* @param page
* @return ServerResponseEntity ProductDto 便使
*/
@GetMapping("/pageProd")
@Operation(summary = "通过分类id商品列表信息" , description = "根据分类ID获取该分类下所有的商品列表信息")
@Operation(summary = "通过分类id商品列表信息", description = "根据分类ID获取该分类下所有的商品列表信息")
@Parameters({
@Parameter(name = "categoryId", description = "分类ID" , required = true),
@Parameter(name = "categoryId", description = "分类ID", required = true),
})
public ServerResponseEntity<IPage<ProductDto>> prodList(
@RequestParam(value = "categoryId") Long categoryId,PageParam<ProductDto> page) {
@RequestParam(value = "categoryId") Long categoryId, PageParam<ProductDto> page) {
IPage<ProductDto> productPage = prodService.pageByCategoryId(page, categoryId);
return ServerResponseEntity.success(productPage);
}
/**
* ID ID
* SKU ID
* 便
*
* @param prodId ID
* @return ServerResponseEntity ProductDto
*/
@GetMapping("/prodInfo")
@Operation(summary = "商品详情信息" , description = "根据商品IDprodId获取商品信息")
@Parameter(name = "prodId", description = "商品ID" , required = true)
@Operation(summary = "商品详情信息", description = "根据商品IDprodId获取商品信息")
@Parameter(name = "prodId", description = "商品ID", required = true)
public ServerResponseEntity<ProductDto> prodInfo(Long prodId) {
// 通过商品服务层的方法,根据商品 ID 从数据库中获取商品的基本信息,若商品不存在则直接返回空的成功响应(可根据实际需求优化此处逻辑,比如返回特定的错误提示)
Product product = prodService.getProductByProdId(prodId);
if (product == null) {
return ServerResponseEntity.success();
}
// 通过库存单元服务层的方法,根据商品 ID 查询该商品对应的所有 SKU 列表
List<Sku> skuList = skuService.listByProdId(prodId);
// 启用的sku列表
// 使用 Java 8 的 Stream API 过滤出状态为启用(这里假设状态为 1 表示启用)的 SKU 列表,方便前端展示可用的商品库存单元信息
List<Sku> useSkuList = skuList.stream().filter(sku -> sku.getStatus() == 1).collect(Collectors.toList());
// 将启用的 SKU 列表设置到商品对象中,完善商品的详细信息
product.setSkuList(useSkuList);
ProductDto productDto = BeanUtil.copyProperties(product, ProductDto.class);
// 使用 Hutool 的 BeanUtil 将商品对象转换为对应的 DTO 类型,方便按照前端所需的格式返回数据,避免直接暴露数据库实体对象带来的潜在风险
ProductDto productDto = BeanUtil.copyProperties(product, ProductDto.class);
// 商品的配送方式
// 商品的配送方式字符串解析为对应的对象(这里假设使用了自定义的 JSON 解析方法,具体根据实际情况而定),方便后续判断和获取相关的配送信息
Product.DeliveryModeVO deliveryModeVO = Json.parseObject(product.getDeliveryMode(), Product.DeliveryModeVO.class);
// 有店铺配送的方式, 且存在运费模板,才返回运费模板的信息,供前端查阅
if (deliveryModeVO.getHasShopDelivery() && product.getDeliveryTemplateId() != null) {
// 判断如果商品有店铺配送的方式,并且商品关联的运费模板 ID 不为空(即存在运费模板),则通过运费模板服务层的方法,
// 根据运费模板 ID 获取详细的运费模板及关联信息,并设置到商品详情的 DTO 对象中,供前端查阅运费相关情况,方便用户下单时参考运费成本
if (deliveryModeVO.getHasShopDelivery() && product.getDeliveryTemplateId()!= null) {
Transport transportAndAllItems = transportService.getTransportAndAllItems(product.getDeliveryTemplateId());
productDto.setTransport(transportAndAllItems);
}
@ -94,38 +120,65 @@ public class ProdController {
return ServerResponseEntity.success(productDto);
}
/**
*
* 便
*
* @param page
* @return ServerResponseEntity ProductDto 便使
*/
@GetMapping("/lastedProdPage")
@Operation(summary = "新品推荐" , description = "获取新品推荐商品列表")
@Parameters({
})
@Operation(summary = "新品推荐", description = "获取新品推荐商品列表")
@Parameters({})
public ServerResponseEntity<IPage<ProductDto>> lastedProdPage(PageParam<ProductDto> page) {
IPage<ProductDto> productPage = prodService.pageByPutAwayTime(page);
return ServerResponseEntity.success(productPage);
}
/**
* ID ID ID
* 便
*
* @param tagId ID
* @param page
* @return ServerResponseEntity ProductDto 便使
*/
@GetMapping("/prodListByTagId")
@Operation(summary = "通过分组标签获取商品列表" , description = "通过分组标签idtagId获取商品列表")
@Operation(summary = "通过分组标签获取商品列表", description = "通过分组标签idtagId获取商品列表")
@Parameters({
@Parameter(name = "tagId", description = "当前页默认为1" , required = true),
@Parameter(name = "tagId", description = "当前页默认为1", required = true),
})
public ServerResponseEntity<IPage<ProductDto>> prodListByTagId(
@RequestParam(value = "tagId") Long tagId,PageParam<ProductDto> page) {
@RequestParam(value = "tagId") Long tagId, PageParam<ProductDto> page) {
IPage<ProductDto> productPage = prodService.pageByTagId(page, tagId);
return ServerResponseEntity.success(productPage);
}
/**
*
*
*
* @param page
* @return ServerResponseEntity ProductDto 便使
*/
@GetMapping("/moreBuyProdList")
@Operation(summary = "每日疯抢" , description = "获取销量最多的商品列表")
@Operation(summary = "每日疯抢", description = "获取销量最多的商品列表")
@Parameters({})
public ServerResponseEntity<IPage<ProductDto>> moreBuyProdList(PageParam<ProductDto> page) {
IPage<ProductDto> productPage = prodService.moreBuyProdList(page);
return ServerResponseEntity.success(productPage);
}
/**
*
* 便
*
* @return ServerResponseEntity TagProductDto 便使
*/
@GetMapping("/tagProdList")
@Operation(summary = "首页所有标签商品接口" , description = "获取首页所有标签商品接口")
@Operation(summary = "首页所有标签商品接口", description = "获取首页所有标签商品接口")
public ServerResponseEntity<List<TagProductDto>> getTagProdList() {
List<TagProductDto> productDtoList = prodService.tagProdList();
return ServerResponseEntity.success(productDtoList);
}
}
}
Loading…
Cancel
Save