feat(新增-首页接口管理): 获取首页数据

Signed-off-by: bunny <1319900154@qq.com>
This commit is contained in:
bunny 2024-03-27 13:01:31 +08:00
parent a68ae1f34e
commit e648c9b1ee
12 changed files with 194 additions and 6 deletions

View File

@ -2,14 +2,18 @@ package com.atguigu.spzx.model.vo.h5;
import com.atguigu.spzx.model.entity.product.Category;
import com.atguigu.spzx.model.entity.product.ProductSku;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class IndexVo {
private List<Category> categoryList ; // 一级分类的类别数据
private List<ProductSku> productSkuList ; // 畅销商品列表数据
private List<Category> categoryList; // 一级分类的类别数据
private List<ProductSku> productSkuList; // 畅销商品列表数据
}

View File

@ -0,0 +1,38 @@
package com.atguigu.product.controller;
import com.atguigu.product.service.CategoryService;
import com.atguigu.product.service.ProductService;
import com.atguigu.spzx.model.entity.product.Category;
import com.atguigu.spzx.model.entity.product.ProductSku;
import com.atguigu.spzx.model.vo.h5.IndexVo;
import com.atguigu.spzx.model.vo.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Tag(name = "首页接口管理")
@RestController
@RequestMapping(value = "/api/product/index")
public class IndexController {
@Autowired
private CategoryService categoryService;
@Autowired
private ProductService productService;
@Operation(summary = "获取首页数据", description = "获取首页数据")
@GetMapping
public Result<IndexVo> findData() {
// 查询以及分类
List<Category> categoryList = categoryService.selectOneCategory();
// 根据销量排序获取前十条数据
List<ProductSku> productSkuList = productService.selectProductSkuBySale();
IndexVo vo = IndexVo.builder().categoryList(categoryList).productSkuList(productSkuList).build();
return Result.success(vo);
}
}

View File

@ -0,0 +1,16 @@
package com.atguigu.product.mapper;
import com.atguigu.spzx.model.entity.product.Category;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface CategoryMapper {
/**
* 查询以及分类
*
* @return 分类列表
*/
List<Category> findOneCategory();
}

View File

@ -0,0 +1,16 @@
package com.atguigu.product.mapper;
import com.atguigu.spzx.model.entity.product.ProductSku;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface ProductSkuMapper {
/**
* 根据销量排序获取前十条数据
*
* @return ProductSku列表
*/
List<ProductSku> selectProductSkuBySale();
}

View File

@ -0,0 +1,14 @@
package com.atguigu.product.service;
import com.atguigu.spzx.model.entity.product.Category;
import java.util.List;
public interface CategoryService {
/**
* 查询以及分类
*
* @return 分类实体类列表
*/
List<Category> selectOneCategory();
}

View File

@ -0,0 +1,14 @@
package com.atguigu.product.service;
import com.atguigu.spzx.model.entity.product.ProductSku;
import java.util.List;
public interface ProductService {
/**
* 根据销量排序获取前十条数据
*
* @return ProductSku 列表
*/
List<ProductSku> selectProductSkuBySale();
}

View File

@ -0,0 +1,25 @@
package com.atguigu.product.service.impl;
import com.atguigu.product.mapper.CategoryMapper;
import com.atguigu.product.service.CategoryService;
import com.atguigu.spzx.model.entity.product.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class CategoryServiceImpl implements CategoryService {
@Autowired
private CategoryMapper categoryMapper;
/**
* 查询以及分类
*
* @return 分类实体类列表
*/
@Override
public List<Category> selectOneCategory() {
return categoryMapper.findOneCategory();
}
}

View File

@ -0,0 +1,25 @@
package com.atguigu.product.service.impl;
import com.atguigu.product.mapper.ProductSkuMapper;
import com.atguigu.product.service.ProductService;
import com.atguigu.spzx.model.entity.product.ProductSku;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ProductServiceImpl implements ProductService {
@Autowired
private ProductSkuMapper productSkuMapper;
/**
* 根据销量排序获取前十条数据
*
* @return ProductSku 列表
*/
@Override
public List<ProductSku> selectProductSkuBySale() {
return productSkuMapper.selectProductSkuBySale();
}
}

View File

@ -4,4 +4,7 @@ bunny:
port: 3305
sqlData: db_spzx
username: root
password: "02120212"
password: "02120212"
nacos:
server-addr: z-bunny.cn:8848

View File

@ -8,7 +8,7 @@ spring:
cloud:
nacos:
server-addr: 192.168.1.5:8848
server-addr: ${bunny.nacos.server-addr}
datasource:
type: com.zaxxer.hikari.HikariDataSource

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.atguigu.product.mapper.CategoryMapper">
<!-- 用于select查询公用抽取的列 -->
<sql id="columns">
id,name,image_url,parent_id,status,order_num,create_time,update_time,is_deleted
</sql>
<!-- 查询以及分类 -->
<select id="findOneCategory" resultType="com.atguigu.spzx.model.entity.product.Category">
select
<include refid="columns"/>
from category
where is_deleted = 0
and parent_id = #{parentId} order by id
</select>
</mapper>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.atguigu.product.mapper.ProductSkuMapper">
<!-- 根据销量排序,获取前十条数据 -->
<select id="selectProductSkuBySale" resultType="com.atguigu.spzx.model.entity.product.ProductSku">
SELECT psku.*
FROM product_sku psku
INNER JOIN product p ON p.id = psku.product_id
WHERE p.`status` = 1
AND p.is_deleted = 0
AND psku.is_deleted = 0
ORDER BY psku.sale_num DESC
LIMIT 10
</select>
</mapper>