商品模块代码提交
This commit is contained in:
parent
90788acc58
commit
45e9129377
|
|
@ -3,8 +3,9 @@ package com.czg.controller.user;
|
|||
import com.czg.log.annotation.OperationLog;
|
||||
import com.czg.product.param.MiniHomeProductParam;
|
||||
import com.czg.product.service.UProductService;
|
||||
import com.czg.product.vo.HotsProductVo;
|
||||
import com.czg.product.vo.MiniAppHomeProductVo;
|
||||
import com.czg.product.vo.ShopGroupProductVo;
|
||||
import com.czg.product.vo.ShopProductVo;
|
||||
import com.czg.resp.CzgResult;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
|
@ -38,12 +39,22 @@ public class UProductController {
|
|||
}
|
||||
|
||||
/**
|
||||
* 小程序点餐-热销商品查询
|
||||
* 小程序点餐-热销商品列表
|
||||
*/
|
||||
@GetMapping("/miniApp/hots/query")
|
||||
@OperationLog("小程序点餐-热销商品列表")
|
||||
public CzgResult<List<HotsProductVo>> queryProductForMiniAppHome() {
|
||||
List<HotsProductVo> list = uProductService.queryHotsProductList();
|
||||
public CzgResult<List<ShopProductVo>> queryHotsProductList() {
|
||||
List<ShopProductVo> list = uProductService.queryHotsProductList();
|
||||
return CzgResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序点餐-分组商品列表
|
||||
*/
|
||||
@GetMapping("/miniApp/group/query")
|
||||
@OperationLog("小程序点餐-分组商品列表")
|
||||
public CzgResult<List<ShopGroupProductVo>> queryGroupProductList() {
|
||||
List<ShopGroupProductVo> list = uProductService.queryGroupProductList();
|
||||
return CzgResult.success(list);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@ package com.czg.product.service;
|
|||
|
||||
import com.czg.product.entity.Product;
|
||||
import com.czg.product.param.MiniHomeProductParam;
|
||||
import com.czg.product.vo.HotsProductVo;
|
||||
import com.czg.product.vo.MiniAppHomeProductVo;
|
||||
import com.czg.product.vo.ShopGroupProductVo;
|
||||
import com.czg.product.vo.ShopProductVo;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -17,5 +18,7 @@ public interface UProductService extends IService<Product> {
|
|||
|
||||
MiniAppHomeProductVo queryProductForMiniAppHome(MiniHomeProductParam param);
|
||||
|
||||
List<HotsProductVo> queryHotsProductList();
|
||||
List<ShopProductVo> queryHotsProductList();
|
||||
|
||||
List<ShopGroupProductVo> queryGroupProductList();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
package com.czg.product.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分组商品
|
||||
*
|
||||
* @author tankaikai
|
||||
* @since 2025-02-19 15:39
|
||||
*/
|
||||
@Data
|
||||
public class ShopGroupProductVo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 分组id
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
* 分组名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 商品列表
|
||||
*/
|
||||
private List<ShopProductVo> productList;
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ import java.time.LocalTime;
|
|||
* @since 2025-02-19 09:23
|
||||
*/
|
||||
@Data
|
||||
public class HotsProductVo implements Serializable {
|
||||
public class ShopProductVo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package com.czg.service.product.mapper;
|
||||
|
||||
import com.czg.product.entity.Product;
|
||||
import com.czg.product.vo.HotsProductVo;
|
||||
import com.czg.product.vo.ShopProductVo;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
|
@ -9,14 +9,15 @@ import org.apache.ibatis.annotations.Param;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-16
|
||||
*/
|
||||
* 商品
|
||||
*
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-16
|
||||
*/
|
||||
@Mapper
|
||||
public interface ProductMapper extends BaseMapper<Product> {
|
||||
|
||||
List<HotsProductVo> queryHotsProductList(@Param("shopId") Long shopId);
|
||||
|
||||
List<ShopProductVo> selectHotsProductList(@Param("shopId") Long shopId);
|
||||
|
||||
List<ShopProductVo> selectGroupProductList(@Param("shopId") Long shopId);
|
||||
}
|
||||
|
|
@ -14,10 +14,7 @@ import com.czg.product.entity.ProdSku;
|
|||
import com.czg.product.entity.Product;
|
||||
import com.czg.product.param.MiniHomeProductParam;
|
||||
import com.czg.product.service.UProductService;
|
||||
import com.czg.product.vo.HotsProductVo;
|
||||
import com.czg.product.vo.MiniAppHomeProdGroupVo;
|
||||
import com.czg.product.vo.MiniAppHomeProductInfoVo;
|
||||
import com.czg.product.vo.MiniAppHomeProductVo;
|
||||
import com.czg.product.vo.*;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.product.mapper.ProdGroupMapper;
|
||||
import com.czg.service.product.mapper.ProdGroupRelationMapper;
|
||||
|
|
@ -164,15 +161,42 @@ public class UProductServiceImpl extends ServiceImpl<ProductMapper, Product> imp
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<HotsProductVo> queryHotsProductList() {
|
||||
public List<ShopProductVo> queryHotsProductList() {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
List<HotsProductVo> list = productMapper.queryHotsProductList(shopId);
|
||||
List<ShopProductVo> list = productMapper.selectHotsProductList(shopId);
|
||||
list.forEach(item -> {
|
||||
item.setIsSaleTime(calcIsSaleTime(item.getDays(), item.getStartTime(), item.getEndTime()));
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ShopGroupProductVo> queryGroupProductList() {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
List<ShopGroupProductVo> groupList = prodGroupMapper.selectListByQueryAs(query().select(ProdGroup::getId, ProdGroup::getName).eq(ProdGroup::getShopId, shopId).eq(ProdGroup::getStatus, StatusEnum.ENABLED.value()).orderBy(ProdGroup::getSort, true), ShopGroupProductVo.class);
|
||||
List<ShopProductVo> productAllList = productMapper.selectGroupProductList(shopId);
|
||||
productAllList.forEach(item -> {
|
||||
item.setIsSaleTime(calcIsSaleTime(item.getDays(), item.getStartTime(), item.getEndTime()));
|
||||
});
|
||||
Map<Long, ShopProductVo> productKv = productAllList.stream().collect(Collectors.toMap(ShopProductVo::getId, shopProductVo -> shopProductVo));
|
||||
for (ShopGroupProductVo group : groupList) {
|
||||
List<Long> productIdList = prodGroupRelationMapper.selectListByQueryAs(query().select(ProdGroupRelation::getProductId).eq(ProdGroupRelation::getProdGroupId, group.getId()), Long.class);
|
||||
if (CollUtil.isEmpty(productIdList)) {
|
||||
group.setProductList(List.of());
|
||||
continue;
|
||||
}
|
||||
List<ShopProductVo> productList = new ArrayList<>();
|
||||
for (Long productId : productIdList) {
|
||||
ShopProductVo product = productKv.get(productId);
|
||||
if (product != null) {
|
||||
productList.add(product);
|
||||
}
|
||||
}
|
||||
group.setProductList(productList);
|
||||
}
|
||||
return groupList.stream().filter(group -> CollUtil.isNotEmpty(group.getProductList())).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算是否在可售时间内
|
||||
*
|
||||
|
|
|
|||
|
|
@ -2,34 +2,53 @@
|
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.czg.service.product.mapper.ProductMapper">
|
||||
|
||||
<select id="queryHotsProductList" resultType="com.czg.product.vo.HotsProductVo">
|
||||
select
|
||||
t1.id,
|
||||
t1.name,
|
||||
t2.origin_price,
|
||||
t2.sale_price,
|
||||
t2.member_price,
|
||||
t1.cover_img,
|
||||
t3.name as unit_name,
|
||||
t1.is_sold_stock,
|
||||
t1.stock_number,
|
||||
t1.type,
|
||||
t1.group_type,
|
||||
t1.days,
|
||||
t1.start_time,
|
||||
t1.end_time,
|
||||
ifnull(t2.suit_num, 1) as suit_num
|
||||
<sql id="shopProductQuery">
|
||||
select t1.id,
|
||||
t1.name,
|
||||
t2.origin_price,
|
||||
t2.sale_price,
|
||||
t2.member_price,
|
||||
t1.cover_img,
|
||||
t3.name as unit_name,
|
||||
t1.is_sold_stock,
|
||||
t1.stock_number,
|
||||
t1.type,
|
||||
t1.group_type,
|
||||
t1.days,
|
||||
t1.start_time,
|
||||
t1.end_time,
|
||||
ifnull(t2.suit_num, 1) as suit_num
|
||||
from tb_product t1
|
||||
left join (select x.product_id,MIN(x.sale_price) as sale_price,x.origin_price,x.member_price,x.suit_num from
|
||||
tb_prod_sku x
|
||||
where x.is_del=0 and x.is_grounding = 1 and x.shop_id = #{shopId} group by x.product_id) t2 on t1.id =
|
||||
t2.product_id
|
||||
left join (select x.product_id,
|
||||
MIN(x.sale_price) as sale_price,
|
||||
x.origin_price,
|
||||
x.member_price,
|
||||
x.suit_num
|
||||
from tb_prod_sku x
|
||||
where x.is_del = 0
|
||||
and x.is_grounding = 1
|
||||
and x.shop_id = #{shopId}
|
||||
group by x.product_id) t2 on t1.id = t2.product_id
|
||||
left join tb_shop_prod_unit t3 on t1.unit_id = t3.id
|
||||
</sql>
|
||||
|
||||
<select id="selectHotsProductList" resultType="com.czg.product.vo.ShopProductVo">
|
||||
<include refid="shopProductQuery"/>
|
||||
<where>
|
||||
and t1.is_del = 0
|
||||
and t1.is_sale = 1
|
||||
and t1.is_hot = 1
|
||||
and t2.sale_price is not null
|
||||
and t1.shop_id = #{shopId}
|
||||
</where>
|
||||
order by t1.sort desc,t1.id desc
|
||||
</select>
|
||||
<select id="selectGroupProductList" resultType="com.czg.product.vo.ShopProductVo">
|
||||
<include refid="shopProductQuery"/>
|
||||
<where>
|
||||
and t1.is_del = 0
|
||||
and t1.is_sale = 1
|
||||
and t2.sale_price is not null
|
||||
and t1.shop_id = #{shopId}
|
||||
</where>
|
||||
order by t1.sort desc,t1.id desc
|
||||
|
|
|
|||
Loading…
Reference in New Issue