Commit 0252c144 by 章家宝

feat:7月份需求,延保谈客素材支持长图交互需求实现

1 parent fe3e1089
......@@ -61,6 +61,27 @@ public class ReceptionHomePageMaterialDetail implements Serializable {
@Column(name = "content_pic_url")
private String contentPicUrl;
/**
* 图片宽度(像素)
*/
@ApiModelProperty(name = "imageWidth", notes = "图片宽度(像素)")
@Column(name = "image_width")
private Integer imageWidth;
/**
* 图片高度(像素)
*/
@ApiModelProperty(name = "imageHeight", notes = "图片高度(像素)")
@Column(name = "image_height")
private Integer imageHeight;
/**
* 是否为长图(true=是 false=否)
*/
@ApiModelProperty(name = "isLongImage", notes = "是否为长图(true=是 false=否)")
@Column(name = "is_long_image")
private Boolean isLongImage;
@Column(name = "created_by", insertable = false, updatable = false)
private String createdBy;
......
......@@ -74,6 +74,27 @@ public class ReceptionHomePageMaterialInfo implements Serializable {
private String contentPicUrl;
/**
* 图片宽度(像素)
*/
@ApiModelProperty(name = "imageWidth", notes = "图片宽度(像素)")
@Column(name = "image_width")
private Integer imageWidth;
/**
* 图片高度(像素)
*/
@ApiModelProperty(name = "imageHeight", notes = "图片高度(像素)")
@Column(name = "image_height")
private Integer imageHeight;
/**
* 是否为长图(true=是 false=否)
*/
@ApiModelProperty(name = "isLongImage", notes = "是否为长图(true=是 false=否)")
@Column(name = "is_long_image")
private Boolean isLongImage;
/**
* 素材排序
*/
@ApiModelProperty(name = "materialSort", notes = "素材排序")
......
......@@ -135,6 +135,15 @@ public class SaveOrUpdateHomePageConfigDTO implements Serializable {
@ApiModelProperty(name = "contentPicUrl", notes = "内容图片")
private String contentPicUrl;
@ApiModelProperty(name = "imageWidth", notes = "图片宽度(像素)")
private Integer imageWidth;
@ApiModelProperty(name = "imageHeight", notes = "图片高度(像素)")
private Integer imageHeight;
@ApiModelProperty(name = "isLongImage", notes = "是否为长图")
private Boolean isLongImage;
@ApiModelProperty(name = "materialSort", notes = "素材排序")
private Integer materialSort;
......@@ -157,6 +166,15 @@ public class SaveOrUpdateHomePageConfigDTO implements Serializable {
@ApiModelProperty(name = "contentPicUrl", notes = "内容图片")
private String contentPicUrl;
@ApiModelProperty(name = "imageWidth", notes = "图片宽度(像素)")
private Integer imageWidth;
@ApiModelProperty(name = "imageHeight", notes = "图片高度(像素)")
private Integer imageHeight;
@ApiModelProperty(name = "isLongImage", notes = "是否为长图")
private Boolean isLongImage;
}
}
}
......@@ -665,6 +665,9 @@ public class ReceptionMaterialService {
materialInfo.setHomeEntranceCover(s.getHomeEntranceCover());
materialInfo.setDeletedFlag(BaseModel.DeletedFlagEnum.N.name());
materialInfo.setContentPicUrl(s.getContentPicUrl());
materialInfo.setImageWidth(s.getImageWidth());
materialInfo.setImageHeight(s.getImageHeight());
materialInfo.setIsLongImage(s.getIsLongImage());
materialInfo.setMaterialSort(s.getMaterialSort());
if (!CollectionUtils.isEmpty(s.getContentList())) {
materialInfo.setMaterialDetailList(s.getContentList().stream().map(d -> {
......@@ -674,6 +677,9 @@ public class ReceptionMaterialService {
materialDetail.setRelVehicleModelId(d.getModelId());
materialDetail.setRelVehicleModelName(d.getModelName());
materialDetail.setContentPicUrl(d.getContentPicUrl());
materialDetail.setImageWidth(d.getImageWidth());
materialDetail.setImageHeight(d.getImageHeight());
materialDetail.setIsLongImage(d.getIsLongImage());
materialDetail.setDeletedFlag(BaseModel.DeletedFlagEnum.N.name());
return materialDetail;
}).collect(Collectors.toList()));
......
......@@ -12,6 +12,9 @@
<result column="rel_vehicle_model_name" property="relVehicleModelName" jdbcType="VARCHAR" />
<result column="rel_vehicle_model_id" property="relVehicleModelId" jdbcType="VARCHAR" />
<result column="content_pic_url" property="contentPicUrl" jdbcType="VARCHAR" />
<result column="image_width" property="imageWidth" jdbcType="INTEGER" />
<result column="image_height" property="imageHeight" jdbcType="INTEGER" />
<result column="is_long_image" property="isLongImage" jdbcType="BIT" />
<result column="created_by" property="createdBy" jdbcType="VARCHAR" />
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP" />
<result column="updated_by" property="updatedBy" jdbcType="VARCHAR" />
......@@ -25,8 +28,8 @@
<!--
WARNING - @mbg.generated
-->
id, material_info_id, rel_vehicle_series_name, rel_vehicle_series_id, rel_vehicle_model_name,
rel_vehicle_model_id, content_pic_url, created_by, created_date, updated_by, updated_date,
deleted_flag
id, material_info_id, rel_vehicle_series_name, rel_vehicle_series_id, rel_vehicle_model_name,
rel_vehicle_model_id, content_pic_url, image_width, image_height, is_long_image,
created_by, created_date, updated_by, updated_date, deleted_flag
</sql>
</mapper>
\ No newline at end of file
......@@ -15,6 +15,9 @@
<result column="home_entrance_cover" property="homeEntranceCover" jdbcType="VARCHAR"/>
<result column="rel_vehicle_series" property="relVehicleSeries" jdbcType="VARCHAR"/>
<result column="content_pic_url" property="contentPicUrl" jdbcType="VARCHAR"/>
<result column="image_width" property="imageWidth" jdbcType="INTEGER"/>
<result column="image_height" property="imageHeight" jdbcType="INTEGER"/>
<result column="is_long_image" property="isLongImage" jdbcType="BIT"/>
<result column="material_sort" property="materialSort" jdbcType="INTEGER"/>
<result column="created_by" property="createdBy" jdbcType="VARCHAR"/>
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP"/>
......@@ -30,23 +33,23 @@
WARNING - @mbg.generated
-->
id, material_type, is_show, material_title, material_name, home_entrance_type, home_entrance_cover,
rel_vehicle_series, content_pic_url, material_sort, created_by, created_date, updated_by,
rel_vehicle_series, content_pic_url, image_width, image_height, is_long_image, material_sort, created_by, created_date, updated_by,
updated_date, deleted_flag, config_id
</sql>
<insert id="insertMultiLevelInfoAndDetail">
<foreach collection="list" item="info">
INSERT INTO reception_home_page_material_info (material_type, is_show, material_title, material_name,
home_entrance_type, home_entrance_cover, material_sort, config_id, content_pic_url) VALUES(
home_entrance_type, home_entrance_cover, material_sort, config_id, content_pic_url, image_width, image_height, is_long_image) VALUES(
#{info.materialType}, #{info.isShow}, #{info.materialTitle}, #{info.materialName}, #{info.homeEntranceType},
#{info.homeEntranceCover}, #{info.materialSort}, #{info.configId}, #{info.contentPicUrl});
#{info.homeEntranceCover}, #{info.materialSort}, #{info.configId}, #{info.contentPicUrl}, #{info.imageWidth}, #{info.imageHeight}, #{info.isLongImage});
SET @current_id = LAST_INSERT_ID();
<if test="info.materialDetailList != null and !info.materialDetailList.isEmpty()">
<foreach collection="info.materialDetailList" item="detail">
INSERT INTO reception_home_page_material_detail (material_info_id, rel_vehicle_series_name,
rel_vehicle_series_id, rel_vehicle_model_name, rel_vehicle_model_id, content_pic_url) VALUES(
rel_vehicle_series_id, rel_vehicle_model_name, rel_vehicle_model_id, content_pic_url, image_width, image_height, is_long_image) VALUES(
@current_id, #{detail.relVehicleSeriesName}, #{detail.relVehicleSeriesId},
#{detail.relVehicleModelName},
#{detail.relVehicleModelId}, #{detail.contentPicUrl});
#{detail.relVehicleModelId}, #{detail.contentPicUrl}, #{detail.imageWidth}, #{detail.imageHeight}, #{detail.isLongImage});
<!-- <if test="child.children != null and !child.children.isEmpty()">-->
<!-- <foreach collection="child.children" item="grandchild" separator=";">-->
<!-- INSERT INTO category (name, parent_id) VALUES (#{grandchild.name}, @child_id);-->
......
  • @wangxw1
    commented
    Master

    这里是对您提交的代码进行的专业代码审查意见。

    一、关键问题与优化建议(Top 3)

    1. 严重:MyBatis 存在多语句拼接与会话变量滥用(安全与最佳实践)

    • 问题描述:在 ReceptionHomePageMaterialInfoMapper.xml 的 insertMultiLevelInfoAndDetail 中,使用了 ; 分隔多条 INSERT 语句,并依赖 MySQL 会话变量 SET @current_id = LAST_INSERT_ID(); 来实现主从表关联插入。本次修改继续沿用了这一模式并增加了新字段。
    • 影响分析:
      1. 安全风险:执行多条分号隔开的 SQL 需要在 JDBC 连接 URL 中配置 allowMultiQueries=true,这会极大增加系统遭受 SQL 注入攻击时的破坏范围(攻击者可拼接任意破坏性语句)。
      2. 稳定性风险:在数据库连接池环境下,使用 @current_id 这种会话级变量,一旦发生异常或事务回滚,变量状态可能污染复用的连接,导致后续并发请求出现主从数据错乱。
    • 优化建议:废弃这种写法。使用 MyBatis 原生的 useGeneratedKeys 特性在 Java 内存中完成主从 ID 传递。 ```xml <!-- 主表插入 --> INSERT INTO reception_home_page_material_info (...) VALUES (...)

    <!-- 子表批量插入 --> INSERT INTO reception_home_page_material_detail (material_info_id, ...) VALUES (#{infoId}, ...)

      *(注:然后在 Java Service 层先调用主表插入获取 ID,再将 ID 赋给 Detail 列表进行批量插入)*
    
    **2. 警告:Dubbo Remote 接口 DTO 参数变更风险(功能与稳定性)**
    - **问题描述**:修改了 `SaveOrUpdateHomePageConfigDTO`,为其内部类新增了 `imageWidth`、`imageHeight` 和 `isLongImage` 三个字段。
    - **影响分析**:根据审查规则:**“dubbo服务提供者Remote接口中的已有请求参数变更视为危险实现”**。虽然新增字段在 Dubbo 默认的 Hessian2 序列化中通常是向下兼容的,但如果该 DTO 被外部系统广泛引用,提供者和消费者的发布顺序若不当(如消费者先发且传递了新字段,而提供者未更新),可能导致反序列化丢失数据或引发异常。
    - **优化建议**:
      1. 确认该 DTO 的影响范围。如果属于核心 Remote 接口,必须严格遵循“先发布 Provider,后发布 Consumer”的上线顺序。
      2. 建议在 DTO 新增字段上添加 `@JSONField` 或 `@transient` 等序列化兼容注解(视具体使用的序列化框架而定),确保兼容性。
    
    **3. 缺陷:缺少包装类型的非空处理与校验(健壮性)**
    - **问题描述**:在 `ReceptionMaterialService.java` 中,直接将 DTO 中的 `Integer` 和 `Boolean` 包装类赋值给 Model,未做任何防御性编程处理。
    - **影响分析**:由于是新增字段,旧版本的前端或调用方在请求时不会传递这些参数,导致 DTO 中的 `isLongImage` 等字段为 `null`。
      1. 如果数据库表中 `is_long_image` 等字段设计为 `NOT NULL`,直接插入 `null` 会导致 SQL 异常。
      2. 如果后续业务逻辑中对 `isLongImage` 进行了隐式拆箱(例如 `if (materialInfo.getIsLongImage())`),会直接触发 `NullPointerException`。
    - **优化建议**:在 DTO 层提供默认值,或在 Service 转换时进行空值保护。
      ```java
      // 示例代码
      materialInfo.setImageWidth(s.getImageWidth() != null ? s.getImageWidth() : 0);
      materialInfo.setImageHeight(s.getImageHeight() != null ? s.getImageHeight() : 0);
      materialInfo.setIsLongImage(s.getIsLongImage() != null ? s.getIsLongImage() : Boolean.FALSE);
    

    二、评分明细

    • 功能实现的正确性与健壮性(32/40分): 扣分原因:虽然完成了字段透传的业务逻辑,但忽略了新老接口兼容时的空指针风险(包装类 null 值处理),健壮性存在隐患。未出现 MyBatis 子查询违规。
    • 安全性与潜在风险(15/30分): 扣分原因:XML 中存在多语句拼接执行(依赖 allowMultiQueries=true),这是典型的安全高危反模式;同时 DTO 参数变更触及了 Dubbo 接口变更的危险红线,存在潜在的序列化风险。
    • 最佳实践与可维护性(12/20分): 扣分原因:在 MyBatis 中使用 MySQL 会话变量(@current_id)处理主从表外键关联严重违背了持久层框架的最佳实践,不利于代码维护和数据库迁移。
    • 性能与资源利用(5/5分): 得分原因:本次修改仅为新增字段的映射与透传,无明显性能瓶颈或资源浪费情况。
    • 提交信息质量(5/5分): 得分原因:Commit 信息(feat:7月份需求,延保谈客素材支持长图交互需求实现)清晰说明了业务背景、需求范围及变更目的,具备良好的可追溯性。

    总分:69分

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!