Commit c1610b4f by 叶立庆

Merge branch 'v5.8.4' into 'master'

上线合并

See merge request !26
2 parents fe3e1089 e37d10d0
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
</parent> </parent>
<groupId>cn.com.glsx</groupId> <groupId>cn.com.glsx</groupId>
<artifactId>rpc-dj-mindworkplate-api</artifactId> <artifactId>rpc-dj-mindworkplate-api</artifactId>
<version>5.8.3-SNAPSHOT</version> <version>5.8.4-SNAPSHOT</version>
<name>rpc-dj-mindworkplate-api</name> <name>rpc-dj-mindworkplate-api</name>
<properties> <properties>
<deploy.scanPackage>cn.com.glsx.remote</deploy.scanPackage> <deploy.scanPackage>cn.com.glsx.remote</deploy.scanPackage>
......
...@@ -61,6 +61,27 @@ public class ReceptionHomePageMaterialDetail implements Serializable { ...@@ -61,6 +61,27 @@ public class ReceptionHomePageMaterialDetail implements Serializable {
@Column(name = "content_pic_url") @Column(name = "content_pic_url")
private String contentPicUrl; 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 longImage;
@Column(name = "created_by", insertable = false, updatable = false) @Column(name = "created_by", insertable = false, updatable = false)
private String createdBy; private String createdBy;
......
...@@ -74,6 +74,27 @@ public class ReceptionHomePageMaterialInfo implements Serializable { ...@@ -74,6 +74,27 @@ public class ReceptionHomePageMaterialInfo implements Serializable {
private String contentPicUrl; 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 longImage;
/**
* 素材排序 * 素材排序
*/ */
@ApiModelProperty(name = "materialSort", notes = "素材排序") @ApiModelProperty(name = "materialSort", notes = "素材排序")
......
...@@ -135,6 +135,15 @@ public class SaveOrUpdateHomePageConfigDTO implements Serializable { ...@@ -135,6 +135,15 @@ public class SaveOrUpdateHomePageConfigDTO implements Serializable {
@ApiModelProperty(name = "contentPicUrl", notes = "内容图片") @ApiModelProperty(name = "contentPicUrl", notes = "内容图片")
private String contentPicUrl; private String contentPicUrl;
@ApiModelProperty(name = "imageWidth", notes = "图片宽度(像素)")
private Integer imageWidth;
@ApiModelProperty(name = "imageHeight", notes = "图片高度(像素)")
private Integer imageHeight;
@ApiModelProperty(name = "isLongImage", notes = "是否为长图")
private Boolean longImage;
@ApiModelProperty(name = "materialSort", notes = "素材排序") @ApiModelProperty(name = "materialSort", notes = "素材排序")
private Integer materialSort; private Integer materialSort;
...@@ -157,6 +166,15 @@ public class SaveOrUpdateHomePageConfigDTO implements Serializable { ...@@ -157,6 +166,15 @@ public class SaveOrUpdateHomePageConfigDTO implements Serializable {
@ApiModelProperty(name = "contentPicUrl", notes = "内容图片") @ApiModelProperty(name = "contentPicUrl", notes = "内容图片")
private String contentPicUrl; private String contentPicUrl;
@ApiModelProperty(name = "imageWidth", notes = "图片宽度(像素)")
private Integer imageWidth;
@ApiModelProperty(name = "imageHeight", notes = "图片高度(像素)")
private Integer imageHeight;
@ApiModelProperty(name = "isLongImage", notes = "是否为长图")
private Boolean longImage;
} }
} }
} }
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
<dependency> <dependency>
<groupId>cn.com.glsx</groupId> <groupId>cn.com.glsx</groupId>
<artifactId>rpc-dj-mindworkplate-api</artifactId> <artifactId>rpc-dj-mindworkplate-api</artifactId>
<version>5.8.3-SNAPSHOT</version> <version>5.8.4-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>cn.com.glsx.dj</groupId> <groupId>cn.com.glsx.dj</groupId>
......
package cn.com.glsx.dj.mindworkplate.mapper; package cn.com.glsx.dj.mindworkplate.mapper;
import java.util.List;
import java.util.Map;
import cn.com.glsx.dj.mindworkplate.model.EarlyWarningThresholdConfig; import cn.com.glsx.dj.mindworkplate.model.EarlyWarningThresholdConfig;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -9,4 +12,6 @@ import org.oreframework.datasource.mybatis.mapper.OreMapper; ...@@ -9,4 +12,6 @@ import org.oreframework.datasource.mybatis.mapper.OreMapper;
public interface EarlyWarningThresholdConfigMapper extends OreMapper<EarlyWarningThresholdConfig> { public interface EarlyWarningThresholdConfigMapper extends OreMapper<EarlyWarningThresholdConfig> {
EarlyWarningThresholdConfig findByMerchantNo(@Param("merchantNo") String merchantNo); EarlyWarningThresholdConfig findByMerchantNo(@Param("merchantNo") String merchantNo);
List<Map<String, Object>> findGuaranteeConfigByMerchantId(@Param("merchantId") Integer merchantId);
} }
\ No newline at end of file \ No newline at end of file
...@@ -8,6 +8,7 @@ import cn.com.glsx.dj.mindworkplate.model.EarlyWarningThresholdConfig; ...@@ -8,6 +8,7 @@ import cn.com.glsx.dj.mindworkplate.model.EarlyWarningThresholdConfig;
import cn.com.glsx.dj.mindworkplate.model.EarlyWarningThresholdConfigHistory; import cn.com.glsx.dj.mindworkplate.model.EarlyWarningThresholdConfigHistory;
import cn.com.glsx.dj.mindworkplate.model.EarlyWarningThresholdRangeConfig; import cn.com.glsx.dj.mindworkplate.model.EarlyWarningThresholdRangeConfig;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -15,6 +16,8 @@ import org.springframework.stereotype.Service; ...@@ -15,6 +16,8 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.math.BigDecimal;
import java.util.Map;
@Slf4j @Slf4j
@Service @Service
...@@ -36,6 +39,28 @@ public class EarlyWarningThresholdConfigService { ...@@ -36,6 +39,28 @@ public class EarlyWarningThresholdConfigService {
* @return * @return
*/ */
public EarlyWarningThresholdConfig findByMerchantNo(String merchantNo) { public EarlyWarningThresholdConfig findByMerchantNo(String merchantNo) {
// 优先从新表 dj_car_life_merchant_guarantee 查询兜底配置
try {
Integer merchantId = Integer.valueOf(merchantNo);
List<Map<String, Object>> guaranteeConfigs = earlyWarningThresholdConfigMapper.findGuaranteeConfigByMerchantId(merchantId);
if (CollectionUtils.isNotEmpty(guaranteeConfigs)) {
EarlyWarningThresholdConfig config = new EarlyWarningThresholdConfig();
config.setMerchantNo(merchantNo);
for (Map<String, Object> row : guaranteeConfigs) {
String baseSceneCode = (String) row.get("base_scene_code");
String guaranteeIndex = (String) row.get("guarantee_index");
BigDecimal standard = (BigDecimal) row.get("guarantee_standard");
mapGuaranteeToConfig(config, baseSceneCode, guaranteeIndex, standard);
}
EarlyWarningThresholdRangeConfig warningThresholdRangeConfig = findWarningThresholdRangeConfig(1);
config.setRangeValue(warningThresholdRangeConfig.getRangeValue());
return config;
}
} catch (NumberFormatException e) {
// merchantNo 非纯数字,回退到旧表查询
}
// 兜底:从旧表 early_warning_threshold_config 查询
EarlyWarningThresholdConfig byMerchantNo = earlyWarningThresholdConfigMapper.findByMerchantNo( EarlyWarningThresholdConfig byMerchantNo = earlyWarningThresholdConfigMapper.findByMerchantNo(
merchantNo); merchantNo);
if(byMerchantNo!=null){ if(byMerchantNo!=null){
...@@ -46,6 +71,49 @@ public class EarlyWarningThresholdConfigService { ...@@ -46,6 +71,49 @@ public class EarlyWarningThresholdConfigService {
} }
return byMerchantNo; return byMerchantNo;
} }
private void mapGuaranteeToConfig(EarlyWarningThresholdConfig config, String baseSceneCode, String guaranteeIndex, BigDecimal value) {
if (value == null) {
return;
}
if ("110201".equals(baseSceneCode)) {
switch (guaranteeIndex) {
case "WR_CONV_001":
config.setEwConRate(value);
break;
case "WR_CONV_002":
config.setEwAxbConRate(value);
break;
case "WR_CONV_004":
config.setEwLtConRate(value);
break;
case "WR_CONV_003":
config.setBatteryConversionRate(value);
break;
case "WR_RATE_001":
config.setEwPenetrationRate(value);
break;
case "WR_RATE_002":
config.setEwAxbPenetrationRate(value);
break;
case "WR_RATE_004":
config.setEwLtPenetrationRate(value);
break;
case "WR_RATE_003":
config.setBatteryPenetrationRate(value);
break;
default:
break;
}
} else if ("110101".equals(baseSceneCode)) {
switch (guaranteeIndex) {
case "BE_CONV_001":
config.setRiConRate(value);
break;
default:
break;
}
}
}
/** /**
* 根据类型查询预警阈值 * 根据类型查询预警阈值
* *
......
...@@ -26,7 +26,6 @@ import cn.com.glsx.framework.core.beans.rpc.RpcResponse; ...@@ -26,7 +26,6 @@ import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum; import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException; import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.core.util.RpcAssert; import cn.com.glsx.framework.core.util.RpcAssert;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
...@@ -665,6 +664,9 @@ public class ReceptionMaterialService { ...@@ -665,6 +664,9 @@ public class ReceptionMaterialService {
materialInfo.setHomeEntranceCover(s.getHomeEntranceCover()); materialInfo.setHomeEntranceCover(s.getHomeEntranceCover());
materialInfo.setDeletedFlag(BaseModel.DeletedFlagEnum.N.name()); materialInfo.setDeletedFlag(BaseModel.DeletedFlagEnum.N.name());
materialInfo.setContentPicUrl(s.getContentPicUrl()); materialInfo.setContentPicUrl(s.getContentPicUrl());
materialInfo.setImageWidth(s.getImageWidth());
materialInfo.setImageHeight(s.getImageHeight());
materialInfo.setLongImage(s.getLongImage());
materialInfo.setMaterialSort(s.getMaterialSort()); materialInfo.setMaterialSort(s.getMaterialSort());
if (!CollectionUtils.isEmpty(s.getContentList())) { if (!CollectionUtils.isEmpty(s.getContentList())) {
materialInfo.setMaterialDetailList(s.getContentList().stream().map(d -> { materialInfo.setMaterialDetailList(s.getContentList().stream().map(d -> {
...@@ -674,6 +676,9 @@ public class ReceptionMaterialService { ...@@ -674,6 +676,9 @@ public class ReceptionMaterialService {
materialDetail.setRelVehicleModelId(d.getModelId()); materialDetail.setRelVehicleModelId(d.getModelId());
materialDetail.setRelVehicleModelName(d.getModelName()); materialDetail.setRelVehicleModelName(d.getModelName());
materialDetail.setContentPicUrl(d.getContentPicUrl()); materialDetail.setContentPicUrl(d.getContentPicUrl());
materialDetail.setImageWidth(d.getImageWidth());
materialDetail.setImageHeight(d.getImageHeight());
materialDetail.setLongImage(d.getLongImage());
materialDetail.setDeletedFlag(BaseModel.DeletedFlagEnum.N.name()); materialDetail.setDeletedFlag(BaseModel.DeletedFlagEnum.N.name());
return materialDetail; return materialDetail;
}).collect(Collectors.toList())); }).collect(Collectors.toList()));
......
...@@ -38,4 +38,12 @@ ...@@ -38,4 +38,12 @@
where merchant_no = #{merchantNo} where merchant_no = #{merchantNo}
and deleted_flag = 'N' and deleted_flag = 'N'
</select> </select>
<select id="findGuaranteeConfigByMerchantId" resultType="map">
SELECT base_scene_code, guarantee_index, guarantee_standard
FROM dj_car_life_merchant_guarantee
WHERE merchant_id = #{merchantId, jdbcType=INTEGER}
AND deleted_flag = 'N'
AND base_scene_code IN ('110201', '110101', '100101')
</select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
<result column="rel_vehicle_model_name" property="relVehicleModelName" jdbcType="VARCHAR" /> <result column="rel_vehicle_model_name" property="relVehicleModelName" jdbcType="VARCHAR" />
<result column="rel_vehicle_model_id" property="relVehicleModelId" jdbcType="VARCHAR" /> <result column="rel_vehicle_model_id" property="relVehicleModelId" jdbcType="VARCHAR" />
<result column="content_pic_url" property="contentPicUrl" 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="longImage" jdbcType="BIT" />
<result column="created_by" property="createdBy" jdbcType="VARCHAR" /> <result column="created_by" property="createdBy" jdbcType="VARCHAR" />
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP" /> <result column="created_date" property="createdDate" jdbcType="TIMESTAMP" />
<result column="updated_by" property="updatedBy" jdbcType="VARCHAR" /> <result column="updated_by" property="updatedBy" jdbcType="VARCHAR" />
...@@ -25,8 +28,8 @@ ...@@ -25,8 +28,8 @@
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
--> -->
id, material_info_id, rel_vehicle_series_name, rel_vehicle_series_id, rel_vehicle_model_name, 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, rel_vehicle_model_id, content_pic_url, image_width, image_height, is_long_image,
deleted_flag created_by, created_date, updated_by, updated_date, deleted_flag
</sql> </sql>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
<result column="home_entrance_cover" property="homeEntranceCover" jdbcType="VARCHAR"/> <result column="home_entrance_cover" property="homeEntranceCover" jdbcType="VARCHAR"/>
<result column="rel_vehicle_series" property="relVehicleSeries" jdbcType="VARCHAR"/> <result column="rel_vehicle_series" property="relVehicleSeries" jdbcType="VARCHAR"/>
<result column="content_pic_url" property="contentPicUrl" 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="longImage" jdbcType="BIT"/>
<result column="material_sort" property="materialSort" jdbcType="INTEGER"/> <result column="material_sort" property="materialSort" jdbcType="INTEGER"/>
<result column="created_by" property="createdBy" jdbcType="VARCHAR"/> <result column="created_by" property="createdBy" jdbcType="VARCHAR"/>
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP"/> <result column="created_date" property="createdDate" jdbcType="TIMESTAMP"/>
...@@ -30,23 +33,23 @@ ...@@ -30,23 +33,23 @@
WARNING - @mbg.generated WARNING - @mbg.generated
--> -->
id, material_type, is_show, material_title, material_name, home_entrance_type, home_entrance_cover, 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 updated_date, deleted_flag, config_id
</sql> </sql>
<insert id="insertMultiLevelInfoAndDetail"> <insert id="insertMultiLevelInfoAndDetail">
<foreach collection="list" item="info"> <foreach collection="list" item="info">
INSERT INTO reception_home_page_material_info (material_type, is_show, material_title, material_name, 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.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.longImage});
SET @current_id = LAST_INSERT_ID(); SET @current_id = LAST_INSERT_ID();
<if test="info.materialDetailList != null and !info.materialDetailList.isEmpty()"> <if test="info.materialDetailList != null and !info.materialDetailList.isEmpty()">
<foreach collection="info.materialDetailList" item="detail"> <foreach collection="info.materialDetailList" item="detail">
INSERT INTO reception_home_page_material_detail (material_info_id, rel_vehicle_series_name, 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}, @current_id, #{detail.relVehicleSeriesName}, #{detail.relVehicleSeriesId},
#{detail.relVehicleModelName}, #{detail.relVehicleModelName},
#{detail.relVehicleModelId}, #{detail.contentPicUrl}); #{detail.relVehicleModelId}, #{detail.contentPicUrl}, #{detail.imageWidth}, #{detail.imageHeight}, #{detail.longImage});
<!-- <if test="child.children != null and !child.children.isEmpty()">--> <!-- <if test="child.children != null and !child.children.isEmpty()">-->
<!-- <foreach collection="child.children" item="grandchild" separator=";">--> <!-- <foreach collection="child.children" item="grandchild" separator=";">-->
<!-- INSERT INTO category (name, parent_id) VALUES (#{grandchild.name}, @child_id);--> <!-- INSERT INTO category (name, parent_id) VALUES (#{grandchild.name}, @child_id);-->
......
  • @wangxw1
    commented
    Master

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

    1. MyBatis 多语句执行与会话变量使用存在严重运行期隐患

    • 问题描述:在 ReceptionHomePageMaterialInfoMapper.xml 的 insertMultiLevelInfoAndDetail 方法中,使用了多条 SQL 语句(以分号分隔)并在同一 <insert> 标签内执行,同时依赖 MySQL 会话变量 @current_id = LAST_INSERT_ID() 来关联父子表的主键。
    • 影响分析:
      1. 这种写法强依赖于数据库连接字符串中配置 allowMultiQueries=true。如果生产环境未开启此配置,代码在运行期将直接抛出 SQL 语法错误。
      2. 在使用数据库连接池(如 HikariCP、Druid)的场景下,手动设置 MySQL 会话变量 @current_id 存在极高的交叉污染风险,可能导致子表数据关联到错误的主表记录上。
      3. 这种非标准的写法破坏了 MyBatis 的常规主键回填机制,可维护性极差。
    • 优化建议:废弃多语句拼接。应分为两次数据库操作,利用 MyBatis 的 useGeneratedKeys 标准特性: ```xml <!-- 1. 插入主表并回填 ID --> INSERT INTO reception_home_page_material_info (...) VALUES (...)

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

      在 Java 业务层中,先调用主表插入,获取到回填的 ID 后赋值给 detail 列表,再调用子表的批量插入。
    
    **2. Map 结果集强转存在 `ClassCastException` 与潜在的 NPE 风险**
    - **问题描述**:在 `EarlyWarningThresholdConfigService.java` 中,查询结果使用了 `Map<String, Object>` 接收。代码直接进行强转 `(BigDecimal) row.get("guarantee_standard")`。此外,`mapGuaranteeToConfig` 方法中直接对 `guaranteeIndex` 使用了 `switch` 语句。
    - **影响分析**:
      1. 不同的 JDBC 驱动或底层数据类型变更,可能导致 `row.get("guarantee_standard")` 返回 `Double` 或 `Float`,此时直接强转 `BigDecimal` 会触发 `ClassCastException`,导致核心业务阻断。
      2. 若数据库中 `guarantee_index` 字段存在 `NULL` 值,`switch (guaranteeIndex)` 会直接抛出 `NullPointerException`。
    - **优化建议**:
      1. 强烈建议定义专门的 DO/DTO 实体类来接收 MyBatis 的查询结果,利用框架自身的类型转换机制。
      2. 若必须使用 Map,应安全地转换数值,并在 switch 前进行判空:
      ```java
      // 安全的数值转换
      Object standardObj = row.get("guarantee_standard");
      BigDecimal standard = standardObj != null ? new BigDecimal(standardObj.toString()) : null;
    
      // switch 前判空
      if (guaranteeIndex == null) {
          return;
      }
      switch (guaranteeIndex) { ... }
    

    3. 滥用异常处理作为业务控制流(Anti-pattern)

    • 问题描述:EarlyWarningThresholdConfigService.java 的 findByMerchantNo 方法中,使用 try { Integer.valueOf(merchantNo); } catch (NumberFormatException e) { // 回退旧表 } 来判断商户号是否为纯数字。
    • 影响分析:将异常捕获用于正常的业务逻辑分支控制是经典的“反模式”(Anti-pattern)。异常对象的实例化(尤其是构建堆栈轨迹)是非常消耗 CPU 资源的。在高并发场景下,非数字商户号的查询会导致大量无意义的性能开销。
    • 优化建议:使用正则表达式或工具类进行前置验证: java // 替换 try-catch 逻辑 if (org.apache.commons.lang3.StringUtils.isNumeric(merchantNo)) { Integer merchantId = Integer.valueOf(merchantNo); // 执行新表查询... } // 兜底旧表查询...

    二、评分明细

    • 功能实现的正确性与健壮性 (30/40分) 理由:未违反 MyBatis 子查询和 Dubbo DTO 已有参数变更的红线规则(DTO仅新增字段,具备向下兼容性)。但 Map 结果集强转存在 ClassCastException 隐患,且 switch 存在 NPE 风险,健壮性不足,故扣除 10 分。

    • 安全性与潜在风险 (25/30分) 理由:MyBatis 中使用多语句执行拼接且依赖自定义会话变量 @current_id,在连接池环境下存在并发数据错乱(越权/脏数据)的风险,且强依赖特定的 JDBC 配置,存在系统崩溃风险。

    • 最佳实践与可维护性 (12/20分) 理由:存在明显的反模式实现(将异常用于控制流);mapGuaranteeToConfig 中存在大量未提取为常量的魔法值(Magic Strings);MyBatis 映射未使用实体类而是滥用 Map<String, Object>。布尔字段去 is 前缀符合规范,值得肯定。

    • 性能与资源利用 (3/5分) 理由:通过抛出和捕获 NumberFormatException 来判断字符串是否为数字,会产生不必要的性能损耗与垃圾回收压力。

    • 提交信息质量 (4/5分) 理由:Commit 信息较为清晰,详细说明了字段改名的规范原因以及新增功能的范围,但存在少量无意义的重复提交信息(如“版本 (by jiabao)”)。

    总分:74分

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