营销活动:修正 selectListBySpuIdsAndStatus 查询 sql,添加接口测试

This commit is contained in:
puhui999 2023-10-09 16:18:00 +08:00
parent c869d99a0f
commit 57407a39d2
7 changed files with 41 additions and 18 deletions

View File

@ -0,0 +1,5 @@
### /promotion/activity/list-by-spu-ids 获得多个商品,近期参与的每个活动
GET {{appApi}}/promotion/activity/list-by-spu-ids?spuIds=222&spuIds=633
Authorization: Bearer {{appToken}}
Content-Type: application/json
tenant-id: {{appTenentId}}

View File

@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.Ba
import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -87,6 +88,7 @@ public interface BargainActivityMapper extends BaseMapperX<BargainActivityDO> {
// TODO @puhui999一个商品在统一时间不会参与多个活动so 是不是不用 inner join // TODO @puhui999一个商品在统一时间不会参与多个活动so 是不是不用 inner join
// PS如果可以参与多个其实可以这样写 select * from promotion_bargain_activity group by spu_id ORDER BY create_time DESC通过 group 来过滤 // PS如果可以参与多个其实可以这样写 select * from promotion_bargain_activity group by spu_id ORDER BY create_time DESC通过 group 来过滤
/** /**
* 获取指定 spu 编号最近参加的活动每个 spuId 只返回一条记录 * 获取指定 spu 编号最近参加的活动每个 spuId 只返回一条记录
* *
@ -94,16 +96,20 @@ public interface BargainActivityMapper extends BaseMapperX<BargainActivityDO> {
* @param status 状态 * @param status 状态
* @return 砍价活动列表 * @return 砍价活动列表
*/ */
@Select("SELECT p1.* " + @Select("<script> " + "SELECT p1.* " +
"FROM promotion_bargain_activity p1 " + "FROM promotion_bargain_activity p1 " +
"INNER JOIN ( " + "INNER JOIN ( " +
" SELECT spu_id, MAX(DISTINCT(create_time)) AS max_create_time " + " SELECT spu_id, MAX(DISTINCT create_time) AS max_create_time " +
" FROM promotion_bargain_activity " + " FROM promotion_bargain_activity " +
" WHERE spu_id IN #{spuIds} " + " WHERE spu_id IN " +
"<foreach collection='spuIds' item='spuId' open='(' separator=',' close=')'>" +
" #{spuId}" +
"</foreach>" +
" GROUP BY spu_id " + " GROUP BY spu_id " +
") p2 " + ") p2 " +
"ON p1.spu_id = p2.spu_id AND p1.create_time = p2.max_create_time AND p1.status = #{status} " + "ON p1.spu_id = p2.spu_id AND p1.create_time = p2.max_create_time AND p1.status = #{status} " +
"ORDER BY p1.create_time DESC;") "ORDER BY p1.create_time DESC;" +
List<BargainActivityDO> selectListBySpuIds(Collection<Long> spuIds, Integer status); " </script>")
List<BargainActivityDO> selectListBySpuIdsAndStatus(@Param("spuIds") Collection<Long> spuIds, @Param("status") Integer status);
} }

View File

@ -44,6 +44,7 @@ public interface CombinationActivityMapper extends BaseMapperX<CombinationActivi
} }
// TODO @puhui999类似 BargainActivityMapper // TODO @puhui999类似 BargainActivityMapper
/** /**
* 获取指定 spu 编号最近参加的活动每个 spuId 只返回一条记录 * 获取指定 spu 编号最近参加的活动每个 spuId 只返回一条记录
* *
@ -51,16 +52,21 @@ public interface CombinationActivityMapper extends BaseMapperX<CombinationActivi
* @param status 状态 * @param status 状态
* @return 拼团活动列表 * @return 拼团活动列表
*/ */
@Select("SELECT p1.* " + @Select("<script> " + "SELECT p1.* " +
"FROM promotion_combination_activity p1 " + "FROM promotion_combination_activity p1 " +
"INNER JOIN ( " + "INNER JOIN ( " +
" SELECT spu_id, MAX(DISTINCT(create_time)) AS max_create_time " + " SELECT spu_id, MAX(DISTINCT create_time) AS max_create_time " +
" FROM promotion_combination_activity " + " FROM promotion_combination_activity " +
" WHERE spu_id IN #{spuIds} " + " WHERE spu_id IN " +
"<foreach collection='spuIds' item='spuId' open='(' separator=',' close=')'>" +
" #{spuId}" +
"</foreach>" +
" GROUP BY spu_id " + " GROUP BY spu_id " +
") p2 " + ") p2 " +
"ON p1.spu_id = p2.spu_id AND p1.create_time = p2.max_create_time AND p1.status = #{status} " + "ON p1.spu_id = p2.spu_id AND p1.create_time = p2.max_create_time AND p1.status = #{status} " +
"ORDER BY p1.create_time DESC;") "ORDER BY p1.create_time DESC;" +
List<CombinationActivityDO> selectListBySpuIds(@Param("spuIds") Collection<Long> spuIds, @Param("status") Integer status); " </script>")
List<CombinationActivityDO> selectListBySpuIdsAndStatus(@Param("spuIds") Collection<Long> spuIds, @Param("status") Integer status);
} }

View File

@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.promotion.controller.app.seckill.vo.activity.AppS
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillActivityDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import java.util.Collection; import java.util.Collection;
@ -59,6 +60,7 @@ public interface SeckillActivityMapper extends BaseMapperX<SeckillActivityDO> {
} }
// TODO @puhui999类似 BargainActivityMapper // TODO @puhui999类似 BargainActivityMapper
/** /**
* 获取指定 spu 编号最近参加的活动每个 spuId 只返回一条记录 * 获取指定 spu 编号最近参加的活动每个 spuId 只返回一条记录
* *
@ -66,16 +68,20 @@ public interface SeckillActivityMapper extends BaseMapperX<SeckillActivityDO> {
* @param status 状态 * @param status 状态
* @return 秒杀活动列表 * @return 秒杀活动列表
*/ */
@Select("SELECT p1.* " + @Select("<script> " + "SELECT p1.* " +
"FROM promotion_seckill_activity p1 " + "FROM promotion_seckill_activity p1 " +
"INNER JOIN ( " + "INNER JOIN ( " +
" SELECT spu_id, MAX(DISTINCT(create_time)) AS max_create_time " + " SELECT spu_id, MAX(DISTINCT create_time) AS max_create_time " +
" FROM promotion_seckill_activity " + " FROM promotion_seckill_activity " +
" WHERE spu_id IN #{spuIds} " + " WHERE spu_id IN " +
"<foreach collection='spuIds' item='spuId' open='(' separator=',' close=')'>" +
" #{spuId}" +
"</foreach>" +
" GROUP BY spu_id " + " GROUP BY spu_id " +
") p2 " + ") p2 " +
"ON p1.spu_id = p2.spu_id AND p1.create_time = p2.max_create_time AND p1.status = #{status} " + "ON p1.spu_id = p2.spu_id AND p1.create_time = p2.max_create_time AND p1.status = #{status} " +
"ORDER BY p1.create_time DESC;") "ORDER BY p1.create_time DESC;" +
List<SeckillActivityDO> selectListBySpuIds(Collection<Long> spuIds, Integer status); " </script>")
List<SeckillActivityDO> selectListBySpuIdsAndStatus(@Param("spuIds") Collection<Long> spuIds, @Param("status") Integer status);
} }

View File

@ -178,7 +178,7 @@ public class BargainActivityServiceImpl implements BargainActivityService {
@Override @Override
public List<BargainActivityDO> getBargainActivityBySpuIdsAndStatus(Collection<Long> spuIds, Integer status) { public List<BargainActivityDO> getBargainActivityBySpuIdsAndStatus(Collection<Long> spuIds, Integer status) {
return bargainActivityMapper.selectListBySpuIds(spuIds, status); return bargainActivityMapper.selectListBySpuIdsAndStatus(spuIds, status);
} }
} }

View File

@ -228,7 +228,7 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic
@Override @Override
public List<CombinationActivityDO> getCombinationActivityBySpuIdsAndStatus(Collection<Long> spuIds, Integer status) { public List<CombinationActivityDO> getCombinationActivityBySpuIdsAndStatus(Collection<Long> spuIds, Integer status) {
return combinationActivityMapper.selectListBySpuIds(spuIds, status); return combinationActivityMapper.selectListBySpuIdsAndStatus(spuIds, status);
} }
} }

View File

@ -312,7 +312,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
@Override @Override
public List<SeckillActivityDO> getSeckillActivityBySpuIdsAndStatus(Collection<Long> spuIds, Integer status) { public List<SeckillActivityDO> getSeckillActivityBySpuIdsAndStatus(Collection<Long> spuIds, Integer status) {
return seckillActivityMapper.selectListBySpuIds(spuIds, status); return seckillActivityMapper.selectListBySpuIdsAndStatus(spuIds, status);
} }
} }