mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-04 12:18:42 +08:00 
			
		
		
		
	营销活动:修正 selectListBySpuIdsAndStatus 查询 sql,添加接口测试
This commit is contained in:
		@@ -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}}
 | 
			
		||||
@@ -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 com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 | 
			
		||||
import org.apache.ibatis.annotations.Mapper;
 | 
			
		||||
import org.apache.ibatis.annotations.Param;
 | 
			
		||||
import org.apache.ibatis.annotations.Select;
 | 
			
		||||
 | 
			
		||||
import java.time.LocalDateTime;
 | 
			
		||||
@@ -87,6 +88,7 @@ public interface BargainActivityMapper extends BaseMapperX<BargainActivityDO> {
 | 
			
		||||
 | 
			
		||||
    // TODO @puhui999:一个商品,在统一时间,不会参与多个活动;so 是不是不用 inner join 哈?
 | 
			
		||||
    // PS:如果可以参与多个,其实可以这样写 select * from promotion_bargain_activity group by spu_id ORDER BY create_time DESC;通过 group 来过滤
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录
 | 
			
		||||
     *
 | 
			
		||||
@@ -94,16 +96,20 @@ public interface BargainActivityMapper extends BaseMapperX<BargainActivityDO> {
 | 
			
		||||
     * @param status 状态
 | 
			
		||||
     * @return 砍价活动列表
 | 
			
		||||
     */
 | 
			
		||||
    @Select("SELECT p1.* " +
 | 
			
		||||
    @Select("<script> " + "SELECT p1.* " +
 | 
			
		||||
            "FROM promotion_bargain_activity p1 " +
 | 
			
		||||
            "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 " +
 | 
			
		||||
            "  WHERE spu_id IN #{spuIds} " +
 | 
			
		||||
            "  WHERE spu_id IN " +
 | 
			
		||||
            "<foreach collection='spuIds' item='spuId' open='(' separator=',' close=')'>" +
 | 
			
		||||
            "    #{spuId}" +
 | 
			
		||||
            "</foreach>" +
 | 
			
		||||
            "  GROUP BY spu_id " +
 | 
			
		||||
            ") p2 " +
 | 
			
		||||
            "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;")
 | 
			
		||||
    List<BargainActivityDO> selectListBySpuIds(Collection<Long> spuIds, Integer status);
 | 
			
		||||
            "ORDER BY p1.create_time DESC;" +
 | 
			
		||||
            " </script>")
 | 
			
		||||
    List<BargainActivityDO> selectListBySpuIdsAndStatus(@Param("spuIds") Collection<Long> spuIds, @Param("status") Integer status);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -44,6 +44,7 @@ public interface CombinationActivityMapper extends BaseMapperX<CombinationActivi
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO @puhui999:类似 BargainActivityMapper
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录
 | 
			
		||||
     *
 | 
			
		||||
@@ -51,16 +52,21 @@ public interface CombinationActivityMapper extends BaseMapperX<CombinationActivi
 | 
			
		||||
     * @param status 状态
 | 
			
		||||
     * @return 拼团活动列表
 | 
			
		||||
     */
 | 
			
		||||
    @Select("SELECT p1.* " +
 | 
			
		||||
    @Select("<script> " + "SELECT p1.* " +
 | 
			
		||||
            "FROM promotion_combination_activity p1 " +
 | 
			
		||||
            "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 " +
 | 
			
		||||
            "  WHERE spu_id IN #{spuIds} " +
 | 
			
		||||
            "  WHERE spu_id IN " +
 | 
			
		||||
            "<foreach collection='spuIds' item='spuId' open='(' separator=',' close=')'>" +
 | 
			
		||||
            "    #{spuId}" +
 | 
			
		||||
            "</foreach>" +
 | 
			
		||||
            "  GROUP BY spu_id " +
 | 
			
		||||
            ") p2 " +
 | 
			
		||||
            "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;")
 | 
			
		||||
    List<CombinationActivityDO> selectListBySpuIds(@Param("spuIds") Collection<Long> spuIds, @Param("status") Integer status);
 | 
			
		||||
            "ORDER BY p1.create_time DESC;" +
 | 
			
		||||
            " </script>")
 | 
			
		||||
    List<CombinationActivityDO> selectListBySpuIdsAndStatus(@Param("spuIds") Collection<Long> spuIds, @Param("status") Integer status);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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 com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 | 
			
		||||
import org.apache.ibatis.annotations.Mapper;
 | 
			
		||||
import org.apache.ibatis.annotations.Param;
 | 
			
		||||
import org.apache.ibatis.annotations.Select;
 | 
			
		||||
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
@@ -59,6 +60,7 @@ public interface SeckillActivityMapper extends BaseMapperX<SeckillActivityDO> {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO @puhui999:类似 BargainActivityMapper
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录
 | 
			
		||||
     *
 | 
			
		||||
@@ -66,16 +68,20 @@ public interface SeckillActivityMapper extends BaseMapperX<SeckillActivityDO> {
 | 
			
		||||
     * @param status 状态
 | 
			
		||||
     * @return 秒杀活动列表
 | 
			
		||||
     */
 | 
			
		||||
    @Select("SELECT p1.* " +
 | 
			
		||||
    @Select("<script> " + "SELECT p1.* " +
 | 
			
		||||
            "FROM promotion_seckill_activity p1 " +
 | 
			
		||||
            "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 " +
 | 
			
		||||
            "  WHERE spu_id IN #{spuIds} " +
 | 
			
		||||
            "  WHERE spu_id IN " +
 | 
			
		||||
            "<foreach collection='spuIds' item='spuId' open='(' separator=',' close=')'>" +
 | 
			
		||||
            "    #{spuId}" +
 | 
			
		||||
            "</foreach>" +
 | 
			
		||||
            "  GROUP BY spu_id " +
 | 
			
		||||
            ") p2 " +
 | 
			
		||||
            "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;")
 | 
			
		||||
    List<SeckillActivityDO> selectListBySpuIds(Collection<Long> spuIds, Integer status);
 | 
			
		||||
            "ORDER BY p1.create_time DESC;" +
 | 
			
		||||
            " </script>")
 | 
			
		||||
    List<SeckillActivityDO> selectListBySpuIdsAndStatus(@Param("spuIds") Collection<Long> spuIds, @Param("status") Integer status);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -178,7 +178,7 @@ public class BargainActivityServiceImpl implements BargainActivityService {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<BargainActivityDO> getBargainActivityBySpuIdsAndStatus(Collection<Long> spuIds, Integer status) {
 | 
			
		||||
        return bargainActivityMapper.selectListBySpuIds(spuIds, status);
 | 
			
		||||
        return bargainActivityMapper.selectListBySpuIdsAndStatus(spuIds, status);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -228,7 +228,7 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<CombinationActivityDO> getCombinationActivityBySpuIdsAndStatus(Collection<Long> spuIds, Integer status) {
 | 
			
		||||
        return combinationActivityMapper.selectListBySpuIds(spuIds, status);
 | 
			
		||||
        return combinationActivityMapper.selectListBySpuIdsAndStatus(spuIds, status);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -312,7 +312,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<SeckillActivityDO> getSeckillActivityBySpuIdsAndStatus(Collection<Long> spuIds, Integer status) {
 | 
			
		||||
        return seckillActivityMapper.selectListBySpuIds(spuIds, status);
 | 
			
		||||
        return seckillActivityMapper.selectListBySpuIdsAndStatus(spuIds, status);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user