Commit 9eca7ced by 林永健

feat(marketing): 优化活动车系查询接口支持完整信息返回

- 移除 MarketingActivityCarSeries 实体类的直接引用
- 新增 MarketingActivityCarSeriesQueryDTO 和 MarketingActivityCarSeriesRespDTO 数据传输对象
- 在 MarketingActivityCarSeriesPageRequest 中添加 includeDetail 参数控制详细信息查询
- 修改 carSeries 接口接受查询DTO参数并返回响应DTO列表
- 更新 MyBatis 映射文件中的结果映射配置
- 添加 selectProductWithItemsByActivityId 方法实现商品套餐级联查询
- 扩展 MarketingActivityService.carSeries 方法支持 includeDetail 逻辑
- 重构 SQL 查询使用 resultMap 替代 resultType 提升灵活性
- 统一商品名称字段为 productName 并调整相关 DTO 结构
1 parent f639e62d
......@@ -20,13 +20,21 @@ public class GoodsRespDTO implements Serializable {
private static final long serialVersionUID = 1L;
/** 产品ID(对应 upgrade_goods.commodity_code) */
@ApiModelProperty(notes = "产品ID")
private String productId;
/** 上架商品编码 */
@ApiModelProperty(notes = "上架商品编码")
private String goodsCode;
/** 产品名称 */
/** 产品名称(来自 upgrade_goods.upgrade_goods_name) */
@ApiModelProperty(notes = "产品名称")
private String goodsName;
private String productName;
/** 商品别名(来自 merchant_goods_info.goods_alias) */
@ApiModelProperty(notes = "商品别名")
private String goodsAlias;
/** 上架ID */
@ApiModelProperty(notes = "上架ID")
......
package cn.com.glsx.dj.strategy.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 活动车系查询请求DTO
*
* @author
* @version 1.0
* @since 2026/06/24
*/
@Data
@ApiModel(value = "活动车系查询请求")
public class MarketingActivityCarSeriesQueryDTO implements Serializable {
private static final long serialVersionUID = 1L;
/** 活动ID */
@ApiModelProperty(notes = "活动ID", required = true)
private Integer activityId;
/** 是否查询完整信息(含商品/套餐列表) */
@ApiModelProperty(notes = "是否查询完整信息(含商品/套餐列表),默认false")
private Boolean includeDetail = false;
}
package cn.com.glsx.dj.strategy.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 活动车系响应DTO(含可选的商品/套餐详情列表)
*
* @author
* @version 1.0
* @since 2026/06/24
*/
@Data
@ApiModel(value = "活动车系响应")
public class MarketingActivityCarSeriesRespDTO implements Serializable {
private static final long serialVersionUID = 1L;
/** 车系关联ID */
@ApiModelProperty(notes = "车系关联ID")
private Integer id;
/** 活动ID */
@ApiModelProperty(notes = "活动ID")
private Integer activityId;
/** 品牌ID(一级) */
@ApiModelProperty(notes = "品牌ID(一级)")
private Integer brandId;
/** 品牌名称 */
@ApiModelProperty(notes = "品牌名称")
private String brandName;
/** 子品牌ID(二级) */
@ApiModelProperty(notes = "子品牌ID(二级)")
private Integer childId;
/** 子品牌名称 */
@ApiModelProperty(notes = "子品牌名称")
private String childName;
/** 车系ID(三级) */
@ApiModelProperty(notes = "车系ID(三级)")
private Integer carSeriesId;
/** 车系名称 */
@ApiModelProperty(notes = "车系名称")
private String carSeriesName;
/** 商品列表(includeDetail=true 时有值) */
@ApiModelProperty(notes = "商品列表(仅 includeDetail=true 时返回)")
private List<MarketingActivityProductRespDTO> goodsList;
/** 套餐列表(includeDetail=true 时有值) */
@ApiModelProperty(notes = "套餐列表(仅 includeDetail=true 时返回)")
private List<MarketingActivityProductRespDTO> packageList;
}
......@@ -41,6 +41,10 @@ public class MarketingActivityProductRespDTO implements Serializable {
@ApiModelProperty(notes = "商品类型名称(仅GOODS类型有值)")
private String goodsTypeName;
/** 商品名称或套餐名称 */
@ApiModelProperty(notes = "商品名称或套餐名称")
private String productName;
/** 上架商品编码 */
@ApiModelProperty(notes = "上架商品编码")
private String goodsCode;
......
......@@ -20,13 +20,25 @@ public class PackageItemRespDTO implements Serializable {
private static final long serialVersionUID = 1L;
/** 产品ID(对应 upgrade_goods.commodity_code) */
@ApiModelProperty(notes = "产品ID")
private String productId;
/** 子商品编码 */
@ApiModelProperty(notes = "子商品编码")
private String goodsCode;
/** 子商品名称 */
@ApiModelProperty(notes = "子商品名称")
private String goodsName;
/** 产品名称(来自 upgrade_goods.upgrade_goods_name) */
@ApiModelProperty(notes = "产品名称")
private String productName;
/** 商品别名(来自 merchant_goods_info.goods_alias) */
@ApiModelProperty(notes = "商品别名")
private String goodsAlias;
/** 上架ID */
@ApiModelProperty(notes = "上架ID")
private String listingId;
/** 子商品现售价 */
@ApiModelProperty(notes = "子商品现售价")
......
......@@ -76,6 +76,12 @@ public class MarketingActivityProduct implements Serializable {
private String goodsTypeName;
/**
* 商品名称或套餐名称
*/
@Column(name = "product_name")
private String productName;
/**
* 选项卡名称
*/
@Column(name = "tab_name")
......
package cn.com.glsx.dj.strategy.remote;
import cn.com.glsx.dj.strategy.dto.*;
import cn.com.glsx.dj.strategy.model.MarketingActivityCarSeries;
import cn.com.glsx.dj.strategy.model.MarketingActivityProduct;
import cn.com.glsx.framework.core.annotation.ApiMethod;
import cn.com.glsx.framework.core.annotation.ApiParam;
......@@ -54,9 +53,9 @@ public interface MarketingActivityRemote {
RpcResponse<RpcPagination<OperationLogVO>> logs(RpcPagination<MarketingActivityLogPageReqDTO> pagination);
@ApiMethod("查询活动关联车系")
@ApiParam(name = "activityId", notes = "活动ID", dataType = ApiParam.DataTypeEnum.INT, required = true)
@ApiResponse("车系列表")
RpcResponse<List<MarketingActivityCarSeries>> carSeries(Integer activityId);
@ApiParam(name = "query", notes = "查询条件", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("车系列表(含可选商品/套餐详情)")
RpcResponse<List<MarketingActivityCarSeriesRespDTO>> carSeries(MarketingActivityCarSeriesQueryDTO query);
@ApiMethod("编辑营销活动")
@ApiParam(name = "request", notes = "编辑请求", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
......
package cn.com.glsx.dj.strategy.mapper;
import cn.com.glsx.dj.strategy.dto.MarketingActivityCarSeriesRespDTO;
import cn.com.glsx.dj.strategy.model.MarketingActivityCarSeries;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
......@@ -18,9 +19,9 @@ import java.util.List;
public interface MarketingActivityCarSeriesMapper extends OreMapper<MarketingActivityCarSeries> {
/**
* 按活动ID查询车系列表
* 按活动ID查询车系列表(返回 DTO,可配合 includeDetail 使用)
*/
List<MarketingActivityCarSeries> selectByActivityId(@Param("activityId") Integer activityId);
List<MarketingActivityCarSeriesRespDTO> selectByActivityId(@Param("activityId") Integer activityId);
/**
* 按活动ID删除所有车系关联(逻辑删除)
......
......@@ -37,6 +37,11 @@ public interface MarketingActivityProductMapper extends OreMapper<MarketingActiv
List<MarketingActivityProduct> selectByActivityIds(@Param("activityIds") List<Integer> activityIds);
/**
* 级联查询商品/套餐 + 套餐子商品(LEFT JOIN product_item,含 items 集合)
*/
List<MarketingActivityProductRespDTO> selectProductWithItemsByActivityId(@Param("activityId") Integer activityId);
/**
* 按门店+商品编码查询有效活动商品
*/
List<MarketingActivityProduct> selectActiveByMerchantIdAndGoodsCodes(
......
package cn.com.glsx.dj.strategy.remote;
import cn.com.glsx.dj.strategy.dto.*;
import cn.com.glsx.dj.strategy.model.MarketingActivityCarSeries;
import cn.com.glsx.dj.strategy.model.MarketingActivityProduct;
import cn.com.glsx.dj.strategy.service.MarketingActivityService;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
......@@ -110,9 +109,9 @@ public class MarketingActivityRemoteImpl implements MarketingActivityRemote {
}
@Override
public RpcResponse<List<MarketingActivityCarSeries>> carSeries(Integer activityId) {
public RpcResponse<List<MarketingActivityCarSeriesRespDTO>> carSeries(MarketingActivityCarSeriesQueryDTO query) {
try {
List<MarketingActivityCarSeries> result = marketingActivityService.carSeries(activityId);
List<MarketingActivityCarSeriesRespDTO> result = marketingActivityService.carSeries(query);
return RpcResponse.success(result);
} catch (RpcServiceException e) {
log.error("查询活动车系发生业务异常", e);
......
......@@ -148,9 +148,39 @@ public class MarketingActivityService {
/**
* 查询活动关联车系列表
*
* @param query 查询条件(activityId + includeDetail)
*/
public List<MarketingActivityCarSeries> carSeries(Integer activityId) {
return marketingActivityCarSeriesMapper.selectByActivityId(activityId);
public List<MarketingActivityCarSeriesRespDTO> carSeries(MarketingActivityCarSeriesQueryDTO query) {
Integer activityId = query.getActivityId();
Boolean includeDetail = query.getIncludeDetail();
List<MarketingActivityCarSeriesRespDTO> result = marketingActivityCarSeriesMapper.selectByActivityId(activityId);
if (CollectionUtils.isEmpty(result)) {
return Collections.emptyList();
}
if (Boolean.TRUE.equals(includeDetail)) {
// 级联查询商品/套餐 + 套餐子商品
List<MarketingActivityProductRespDTO> allProducts = marketingActivityProductMapper.selectProductWithItemsByActivityId(activityId);
if (!CollectionUtils.isEmpty(allProducts)) {
Map<Integer, List<MarketingActivityProductRespDTO>> productMap = allProducts.stream()
.collect(Collectors.groupingBy(MarketingActivityProductRespDTO::getCarSeriesId));
for (MarketingActivityCarSeriesRespDTO dto : result) {
List<MarketingActivityProductRespDTO> csProducts = productMap.getOrDefault(dto.getId(), Collections.emptyList());
if (!CollectionUtils.isEmpty(csProducts)) {
dto.setGoodsList(csProducts.stream()
.filter(p -> ProductTypeEnum.GOODS.getValue().equals(p.getProductType()))
.collect(Collectors.toList()));
dto.setPackageList(csProducts.stream()
.filter(p -> ProductTypeEnum.PACKAGE.getValue().equals(p.getProductType()))
.collect(Collectors.toList()));
}
}
}
}
return result;
}
/**
......@@ -640,6 +670,7 @@ public class MarketingActivityService {
}
}
p.setProductName(req.getProductName());
p.setSortOrder(req.getSortOrder() != null ? req.getSortOrder() : 0);
p.setTabName(req.getTabName());
p.setTabDescription(req.getTabDescription());
......@@ -810,6 +841,7 @@ public class MarketingActivityService {
pd.setGoodsTypeName(p.getGoodsTypeName());
pd.setGoodsCode(p.getGoodsCode());
pd.setPackageCode(p.getPackageCode());
pd.setProductName(p.getProductName());
pd.setSortOrder(p.getSortOrder());
pd.setTabName(p.getTabName());
pd.setTabDescription(p.getTabDescription());
......
......@@ -2,13 +2,19 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.com.glsx.dj.strategy.mapper.MarketingActivityCarSeriesMapper">
<select id="selectByActivityId" resultType="cn.com.glsx.dj.strategy.model.MarketingActivityCarSeries">
SELECT id, activity_id activityId,
brand_id brandId, brand_name brandName,
child_id childId, child_name childName,
car_series_id carSeriesId, car_series_name carSeriesName,
created_by createdBy, created_date createdDate
FROM dj_marketing_activity_car_series
<resultMap id="CarSeriesRespDTOResultMap" type="cn.com.glsx.dj.strategy.dto.MarketingActivityCarSeriesRespDTO">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="activity_id" property="activityId" jdbcType="INTEGER"/>
<result column="brand_id" property="brandId" jdbcType="INTEGER"/>
<result column="brand_name" property="brandName" jdbcType="VARCHAR"/>
<result column="child_id" property="childId" jdbcType="INTEGER"/>
<result column="child_name" property="childName" jdbcType="VARCHAR"/>
<result column="car_series_id" property="carSeriesId" jdbcType="INTEGER"/>
<result column="car_series_name" property="carSeriesName" jdbcType="VARCHAR"/>
</resultMap>
<select id="selectByActivityId" resultMap="CarSeriesRespDTOResultMap">
SELECT * FROM dj_marketing_activity_car_series
WHERE activity_id = #{activityId} AND deleted_flag = 'N'
</select>
......
......@@ -28,6 +28,7 @@
<result column="sort_order" property="sortOrder" jdbcType="INTEGER"/>
<result column="goods_type" property="goodsType" jdbcType="INTEGER"/>
<result column="goods_type_name" property="goodsTypeName" jdbcType="VARCHAR"/>
<result column="product_name" property="productName" jdbcType="VARCHAR"/>
<result column="tab_name" property="tabName" jdbcType="VARCHAR"/>
<result column="tab_description" property="tabDescription" jdbcType="VARCHAR"/>
<result column="discount_price" property="discountPrice" jdbcType="DECIMAL"/>
......@@ -67,6 +68,40 @@
<result column="detail_image_url" property="detailImageUrl" jdbcType="VARCHAR"/>
</resultMap>
<!-- 级联查询商品/套餐 + 套餐子商品(LEFT JOIN product_item,一次查询带回所有数据) -->
<resultMap id="ProductWithItemsResultMap" type="cn.com.glsx.dj.strategy.dto.MarketingActivityProductRespDTO" extends="ProductRespDTOResultMap">
<collection property="packageItems" ofType="cn.com.glsx.dj.strategy.dto.MarketingActivityProductItemRespDTO">
<id column="item_id" property="itemId"/>
<result column="item_activity_product_id" property="activityProductId"/>
<result column="item_goods_code" property="goodsCode"/>
<result column="item_goods_name" property="goodsName"/>
<result column="item_goods_type" property="goodsType"/>
<result column="item_goods_type_name" property="goodsTypeName"/>
<result column="item_current_price" property="currentPrice"/>
<result column="item_minimum_price" property="minimumPrice"/>
<result column="item_discount_price" property="discountPrice"/>
<result column="item_sales_incentive" property="salesIncentive"/>
</collection>
</resultMap>
<select id="selectProductWithItemsByActivityId" resultMap="ProductWithItemsResultMap">
SELECT p.*,
i.id AS item_id,
i.activity_product_id AS item_activity_product_id,
i.goods_code AS item_goods_code,
i.goods_name AS item_goods_name,
i.goods_type AS item_goods_type,
i.goods_type_name AS item_goods_type_name,
i.current_price AS item_current_price,
i.minimum_price AS item_minimum_price,
i.discount_price AS item_discount_price,
i.sales_incentive AS item_sales_incentive
FROM dj_marketing_activity_product p
LEFT JOIN dj_marketing_activity_product_item i ON i.activity_product_id = p.id AND i.deleted_flag = 'N'
WHERE p.activity_id = #{activityId} AND p.deleted_flag = 'N'
ORDER BY p.sort_order
</select>
<select id="selectProductDTOList" resultMap="ProductRespDTOResultMap">
SELECT *
FROM dj_marketing_activity_product
......
......@@ -4,14 +4,16 @@
<!-- 分页查询适用门店范围内的上架商品(仅取必要字段) -->
<select id="pageGoods" resultType="cn.com.glsx.dj.strategy.dto.GoodsRespDTO">
SELECT mgi.merchant_goods_code AS goodsCode,
mgi.goods_alias AS goodsName,
ug.commodity_code AS listingId,
mgi.scene_type AS scene,
mgi.base_scene_code AS baseSceneCode,
SELECT ug.commodity_code AS productId,
mgi.merchant_goods_code AS goodsCode,
ug.upgrade_goods_name AS productName,
mgi.goods_alias AS goodsAlias,
ug.commodity_code AS listingId,
mgi.scene_type AS scene,
mgi.base_scene_code AS baseSceneCode,
COUNT(DISTINCT mgr.merchant_id) AS storeCount,
mgi.sell_price AS currentPrice,
mgi.min_sell_price AS minimumPrice
mgi.sell_price AS currentPrice,
mgi.min_sell_price AS minimumPrice
FROM dj_car_life_merchant_goods_info mgi
LEFT JOIN dj_car_life_upgrade_goods ug ON ug.id = mgi.upgrade_goods_id AND ug.deleted_flag = 'N'
JOIN dj_car_life_merchant_goods_ref mgr ON mgr.merchant_goods_id = mgi.id AND mgr.deleted_flag = 'N'
......@@ -42,7 +44,8 @@
<!-- 查询商品/套餐在适用门店范围内的门店列表(不分页,取交集) -->
<select id="findStores" resultType="cn.com.glsx.dj.strategy.dto.GoodsStoreRespDTO">
SELECT mgr.merchant_id AS merchantId,
SELECT DISTINCT
mgr.merchant_id AS merchantId,
sm.merchant_name AS merchantName,
sm.address AS merchantAddress
FROM dj_car_life_merchant_goods_info mgi
......
......@@ -52,11 +52,15 @@
<!-- 查询套餐下所有子商品 -->
<select id="findPackageItems" resultType="cn.com.glsx.dj.strategy.dto.PackageItemRespDTO">
SELECT mgi.merchant_goods_code AS goodsCode,
mgi.goods_alias AS goodsName,
SELECT ug.commodity_code AS productId,
mgi.merchant_goods_code AS goodsCode,
ug.upgrade_goods_name AS productName,
mgi.goods_alias AS goodsAlias,
ug.commodity_code AS listingId,
mgi.sell_price AS currentPrice,
mgi.min_sell_price AS minimumPrice
FROM dj_car_life_merchant_goods_info mgi
LEFT JOIN dj_car_life_upgrade_goods ug ON ug.id = mgi.upgrade_goods_id AND ug.deleted_flag = 'N'
WHERE mgi.package_code = #{packageCode}
AND mgi.deleted_flag = 'N'
AND mgi.status = 1
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!