Commit 5003e540 by 林永健

feat(marketing): 添加营销活动商品销售门店数查询功能

- 在多个请求类中新增 baseSceneCode 和 includeStoreCount 字段
- 添加 MarketingActivityProductStoreCountVO 数据传输对象
- 实现批量查询活动下商品/套餐销售门店数的数据访问方法
- 在 MarketingActivityService 中添加填充门店数的业务逻辑
- 更新 MyBatis XML 映射文件中的查询语句
- 修改商品查询条件从 goods_alias 到 upgrade_goods_name
- 在响应 DTO 中添加 storeCount 字段返回门店数量信息
1 parent 71baebc6
......@@ -36,6 +36,9 @@ public class GoodsPageReqDTO implements Serializable {
@ApiModelProperty(notes = "场景筛选")
private String scene;
@ApiModelProperty(notes = "新场景")
private String baseSceneCode;
/** 按指定门店筛选 */
@ApiModelProperty(notes = "按指定门店筛选")
private Integer merchantId;
......
......@@ -26,4 +26,8 @@ public class MarketingActivityCarSeriesQueryDTO implements Serializable {
/** 是否查询完整信息(含商品/套餐列表) */
@ApiModelProperty(notes = "是否查询完整信息(含商品/套餐列表),默认false")
private Boolean includeDetail = false;
/** 是否查询商品/套餐在适用门店范围内的销售门店数 */
@ApiModelProperty(notes = "是否查询销售门店数(默认false)")
private Boolean includeStoreCount = false;
}
......@@ -25,4 +25,8 @@ public class MarketingActivityProductPageReqDTO implements Serializable {
/** 类型: 0-套餐 1-商品 */
@ApiModelProperty(notes = "类型: 0-套餐 1-商品")
private Integer productType;
/** 是否查询商品/套餐在适用门店范围内的销售门店数 */
@ApiModelProperty(notes = "是否查询销售门店数(默认false)")
private Boolean includeStoreCount = false;
}
......@@ -108,4 +108,8 @@ public class MarketingActivityProductRespDTO implements Serializable {
/** 套餐子商品 */
@ApiModelProperty(notes = "套餐子商品列表(仅PACKAGE类型)")
private List<MarketingActivityProductItemRespDTO> packageItems;
/** 适用门店范围内销售门店数(includeStoreCount=true 时有值) */
@ApiModelProperty(notes = "适用门店范围内销售门店数")
private Integer storeCount;
}
package cn.com.glsx.dj.strategy.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 商品/套餐销售门店数中间结果
*/
@Data
@ApiModel(value = "商品/套餐销售门店数")
public class MarketingActivityProductStoreCountVO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(notes = "明细ID")
private Integer productId;
@ApiModelProperty(notes = "适用门店范围内销售门店数")
private Integer storeCount;
}
......@@ -36,6 +36,9 @@ public class PackagePageReqDTO implements Serializable {
@ApiModelProperty(notes = "场景筛选")
private String scene;
@ApiModelProperty(notes = "新场景")
private String baseSceneCode;
/** 按指定门店筛选 */
@ApiModelProperty(notes = "按指定门店筛选")
private Integer merchantId;
......
......@@ -2,6 +2,7 @@ package cn.com.glsx.dj.strategy.mapper;
import cn.com.glsx.dj.strategy.dto.MarketingActivityProductPageReqDTO;
import cn.com.glsx.dj.strategy.dto.MarketingActivityProductRespDTO;
import cn.com.glsx.dj.strategy.dto.MarketingActivityProductStoreCountVO;
import cn.com.glsx.dj.strategy.model.MarketingActivityProduct;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
......@@ -42,6 +43,11 @@ public interface MarketingActivityProductMapper extends OreMapper<MarketingActiv
List<MarketingActivityProductRespDTO> selectProductWithItemsByActivityId(@Param("activityId") Integer activityId);
/**
* 批量查询活动下每个商品/套餐的销售门店数
*/
List<MarketingActivityProductStoreCountVO> selectStoreCountByActivityId(@Param("activityId") Integer activityId);
/**
* 按门店+商品编码查询有效活动商品
*/
List<MarketingActivityProduct> selectActiveByMerchantIdAndGoodsCodes(
......
......@@ -143,6 +143,11 @@ public class MarketingActivityService {
.forEach(p -> p.setPackageItems(itemMap.getOrDefault(p.getProductId(), Collections.emptyList())));
}
// 是否查询销售门店数
if (Boolean.TRUE.equals(request.getIncludeStoreCount())) {
fillStoreCount(list, request.getActivityId());
}
return res;
}
......@@ -177,6 +182,11 @@ public class MarketingActivityService {
.collect(Collectors.toList()));
}
}
// 是否查询销售门店数
if (Boolean.TRUE.equals(query.getIncludeStoreCount())) {
fillStoreCount(allProducts, activityId);
}
}
}
......@@ -880,6 +890,23 @@ public class MarketingActivityService {
return dto;
}
/**
* 批量查询并填充商品/套餐的销售门店数
*/
private void fillStoreCount(List<MarketingActivityProductRespDTO> productDTOs, Integer activityId) {
if (CollectionUtils.isEmpty(productDTOs)) return;
List<MarketingActivityProductStoreCountVO> storeCounts = marketingActivityProductMapper.selectStoreCountByActivityId(activityId);
if (CollectionUtils.isEmpty(storeCounts)) return;
Map<Integer, Integer> storeCountMap = storeCounts.stream()
.collect(Collectors.toMap(MarketingActivityProductStoreCountVO::getProductId, MarketingActivityProductStoreCountVO::getStoreCount));
for (MarketingActivityProductRespDTO dto : productDTOs) {
Integer count = storeCountMap.get(dto.getProductId());
if (count != null) {
dto.setStoreCount(count);
}
}
}
private MarketingActivityProductRespDTO convertToActivityProductDTO(MarketingActivityProduct p) {
MarketingActivityProductRespDTO pd = new MarketingActivityProductRespDTO();
pd.setProductId(p.getId());
......
......@@ -150,6 +150,21 @@
sort_order ASC
</select>
<!-- 批量查询活动下每个商品/套餐在适用门店范围内的销售门店数 -->
<select id="selectStoreCountByActivityId" resultType="cn.com.glsx.dj.strategy.dto.MarketingActivityProductStoreCountVO">
SELECT p.id AS productId, COUNT(DISTINCT mgr.merchant_id) AS storeCount
FROM dj_marketing_activity_product p
JOIN dj_marketing_activity_store as2 ON as2.activity_id = p.activity_id AND as2.deleted_flag = 'N'
LEFT JOIN dj_car_life_merchant_goods_ref mgr ON mgr.deleted_flag = 'N' AND mgr.merchant_id = as2.merchant_id
LEFT JOIN dj_car_life_merchant_goods_info mgi ON mgi.id = mgr.merchant_goods_id AND mgi.deleted_flag = 'N' AND mgi.status = 1
WHERE p.activity_id = #{activityId} AND p.deleted_flag = 'N'
AND (
(p.product_type = 1 AND p.goods_code = mgi.merchant_goods_code)
OR (p.product_type = 0 AND p.package_code = mgi.package_code AND p.package_code != '')
)
GROUP BY p.id
</select>
<select id="selectActiveByMerchantIdAndGoodsCodes" resultType="cn.com.glsx.dj.strategy.model.MarketingActivityProduct">
SELECT p.goods_code AS goodsCode,
MIN(p.discount_price) AS discountPrice
......
......@@ -25,7 +25,7 @@
#{mid}
</foreach>
<if test="query.goodsName != null and query.goodsName != ''">
AND mgi.goods_alias LIKE CONCAT('%', #{query.goodsName}, '%')
AND mgi.upgrade_goods_name LIKE CONCAT('%', #{query.goodsName}, '%')
</if>
<if test="query.goodsCode != null and query.goodsCode != ''">
AND (mgi.merchant_goods_code LIKE CONCAT('%', #{query.goodsCode}, '%')
......@@ -34,6 +34,9 @@
<if test="query.scene != null and query.scene != ''">
AND mgi.scene_type = #{query.scene}
</if>
<if test="query.baseSceneCode != null and query.baseSceneCode != ''">
AND mgi.base_scene_code = #{query.baseSceneCode}
</if>
<if test="query.merchantId != null">
AND mgr.merchant_id = #{query.merchantId}
</if>
......
......@@ -27,6 +27,9 @@
<if test="query.scene != null and query.scene != ''">
AND p.scene_type = #{query.scene}
</if>
<if test="query.baseSceneCode != null and query.baseSceneCode != ''">
AND p.base_scene_code = #{query.baseSceneCode}
</if>
<if test="query.merchantId != null">
AND mgr.merchant_id = #{query.merchantId}
</if>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!