Commit 6eba4f06 by 林永健

feat(integral): 新增积分时段归属映射功能

- 在 IntegralController 中添加 getPointsPeriodTypeMap 接口
- 更新数据库表结构,增加 points_period_type 字段存储积分时段归属
- 实现积分时段归属映射的环境变量配置和默认映射逻辑
- 添加分笔提现校验功能,根据9月1日前后积分进行分组处理
- 在提现流程中设置积分时段归属标识(1=9月前积分 2=9月后积分)
- 实现提现失败时返还积分的入账时间修正机制
- 增加分时段可提现积分统计功能
- 更新相关实体类和数据传输对象以支持积分时段归属属性
- 升级 stoassistant.api.version 和 shopmall.api.version 至 5.8.6-SNAPSHOT
1 parent 433791ea
......@@ -11,7 +11,7 @@
<name>rpc-scrm-shopmall-api</name>
<properties>
<deploy.scanPackage>cn.com.glsx.shopmall.remote</deploy.scanPackage>
<shopmall.api.version>5.8.5-SNAPSHOT</shopmall.api.version>
<shopmall.api.version>5.8.6-SNAPSHOT</shopmall.api.version>
<stoassistant.api.version>5.6.4-SNAPSHOT</stoassistant.api.version>
</properties>
<dependencies>
......
......@@ -114,6 +114,9 @@ public class IntegralTransferOutDTO extends IntegralTransferOut implements Seria
@ApiModelProperty(notes = "级联标签ID集合(内部使用)", dataType = "list")
private List<Integer> transferOutTagIds;
@ApiModelProperty(notes = "积分时段归属中文描述")
private String pointsPeriodTypeDesc;
/**
* 限制门店商户号集合(配置驱动,供 SQL 动态判断,不落库)
*/
......
package cn.com.glsx.scrm.shopmall.dto.integral;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* 积分时段归属映射项
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("积分时段归属映射项")
public class PointsPeriodTypeDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("积分时段归属标识 1=9月前积分 2=9月后积分")
private Integer pointsPeriodType;
@ApiModelProperty("积分时段归属中文描述")
private String pointsPeriodTypeDesc;
}
......@@ -286,4 +286,13 @@ public class IntegralTransferOut implements Serializable {
@ApiModelProperty(notes = "省份名称快照")
@Column(name = "province_name")
private String provinceName;
@ApiModelProperty(notes = "积分时段归属 1=9月前积分 2=9月后积分")
@Column(name = "points_period_type")
private Integer pointsPeriodType;
@Transient
@ApiModelProperty(notes = "积分时段归属中文描述")
private String pointsPeriodTypeDesc;
}
\ No newline at end of file
......@@ -155,4 +155,9 @@ public interface IntegralTransferOutRemote {
@ApiMethod("查询积分渠道管理员")
RpcResponse<List<IntegralTransferChannelAdmin>> getChannelAdmin(IntegralTransferChannelConfigDTO req);
@ApiMethod("获取积分时段归属映射")
@ApiResponse("积分时段归属映射列表")
RpcResponse<List<PointsPeriodTypeDTO>> getPointsPeriodTypeMap();
}
\ No newline at end of file
......@@ -12,8 +12,8 @@
<packaging>war</packaging>
<properties>
<stoassistant.api.version>5.6.4-SNAPSHOT</stoassistant.api.version>
<shopmall.api.version>5.8.5-SNAPSHOT</shopmall.api.version>
<stoassistant.api.version>5.8.6-SNAPSHOT</stoassistant.api.version>
<shopmall.api.version>5.8.6-SNAPSHOT</shopmall.api.version>
<smartcarlife.api.version>5.6.4-SNAPSHOT</smartcarlife.api.version>
<platform-payment.api.version>5.8.4.3-SNAPSHOT</platform-payment.api.version>
</properties>
......
......@@ -12,7 +12,10 @@ import com.github.pagehelper.Page;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections4.MapUtils;
@Slf4j
@DubboService(validation = "true")
......@@ -465,4 +468,14 @@ public class IntegralTransferOutRemoteImpl implements IntegralTransferOutRemote
return RpcResponse.error(DefaultErrorEnum.SERVER_ERROR);
}
}
@Override
public RpcResponse<List<PointsPeriodTypeDTO>> getPointsPeriodTypeMap() {
try {
return RpcResponse.success(integralTransferOutService.getPointsPeriodTypeMap());
} catch (Exception e) {
log.error("查询积分时段归属映射:{}", e.getMessage(), e);
return RpcResponse.error(DefaultErrorEnum.SERVER_ERROR);
}
}
}
......@@ -91,6 +91,19 @@ public class IntegralTransferOutService {
*/
private static final int NO_MATCH_TAG_ID = -1;
/**
* 积分时段归属映射环境变量 key
*/
private static final String POINTS_PERIOD_TYPE_MAPPING_ENV = "scrm.points.period.type.mapping";
/**
* 默认积分时段归属映射
*/
private static final List<PointsPeriodTypeDTO> DEFAULT_POINTS_PERIOD_TYPE_MAP = java.util.Arrays.asList(
new PointsPeriodTypeDTO(1, "26年9月前积分"),
new PointsPeriodTypeDTO(2, "26年9月后积分")
);
@Autowired
private IntegralTransferOutMapper integralTransferOutMapper;
@Autowired
......@@ -462,6 +475,8 @@ public class IntegralTransferOutService {
// 查询提现单关联订单号列表
// 废弃:积分会版本后不再支持提现和订单关联
// staffMotivationService.appendWithdrawalOrder(result);
// 填充积分时段归属中文描述
thiz.fillPointsPeriodTypeDesc(result);
return page;
} catch (Exception e) {
log.error(e.getMessage(), e);
......@@ -487,6 +502,67 @@ public class IntegralTransferOutService {
}
/**
* 获取积分时段归属映射(优先读取环境变量,解析失败则返回默认映射)
*
* @return 积分时段归属映射列表
*/
public List<PointsPeriodTypeDTO> getPointsPeriodTypeMap() {
String mappingJson = env.getProperty(POINTS_PERIOD_TYPE_MAPPING_ENV);
if (StringUtils.isNotBlank(mappingJson)) {
try {
List<PointsPeriodTypeDTO> parsed = JSON.parseArray(mappingJson, PointsPeriodTypeDTO.class);
if (CollectionUtils.isNotEmpty(parsed)) {
return parsed;
}
} catch (Exception e) {
log.warn("解析积分时段归属映射配置失败,使用默认映射,配置值:{}", mappingJson);
}
}
return new ArrayList<>(DEFAULT_POINTS_PERIOD_TYPE_MAP);
}
/**
* 为提现记录填充积分时段归属中文描述(数据库字段为空时默认展示9月前积分)。
*
* @param dto 提现记录
*/
public void fillPointsPeriodTypeDesc(IntegralTransferOutDTO dto) {
if (dto == null) {
return;
}
Integer pointsPeriodType = dto.getPointsPeriodType();
if (pointsPeriodType == null) {
pointsPeriodType = 1;
dto.setPointsPeriodType(pointsPeriodType);
}
String desc = "26年9月前积分";
List<PointsPeriodTypeDTO> mappingList = getPointsPeriodTypeMap();
if (mappingList != null) {
for (PointsPeriodTypeDTO item : mappingList) {
if (item.getPointsPeriodType().equals(pointsPeriodType)) {
desc = item.getPointsPeriodTypeDesc();
break;
}
}
}
dto.setPointsPeriodTypeDesc(desc);
}
/**
* 为提现记录列表批量填充积分时段归属中文描述。
*
* @param result 提现记录列表
*/
public void fillPointsPeriodTypeDesc(List<IntegralTransferOutDTO> result) {
if (CollectionUtils.isEmpty(result)) {
return;
}
for (IntegralTransferOutDTO dto : result) {
fillPointsPeriodTypeDesc(dto);
}
}
/**
* 为查询结果填充限制门店标记。
*
* @param result 提现记录列表
......@@ -730,6 +806,7 @@ public class IntegralTransferOutService {
detail.setPaymentSubject(approval.getPaymentSubject());
}
}
thiz.fillPointsPeriodTypeDesc(detail);
return detail;
} catch (Exception e) {
log.error(e.getMessage(), e);
......
......@@ -52,6 +52,7 @@
<result column="main_brand_name" jdbcType="VARCHAR" property="mainBrandName" />
<result column="province_code" jdbcType="VARCHAR" property="provinceCode" />
<result column="province_name" jdbcType="VARCHAR" property="provinceName" />
<result column="points_period_type" jdbcType="TINYINT" property="pointsPeriodType" />
</resultMap>
<sql id="Base_Column_List">
<!--
......@@ -64,7 +65,7 @@
updated_by, updated_date, deleted_flag, mode, source, appid, approval_id,
id_card_front, id_card_back, disclaimer_agreement_url,levy_code,levy_name,levy_channel_code,levy_channel_name,
reality_platform_merchant_id,reality_platform_merchant_name,
transfer_out_tag_id, main_brand_id, main_brand_name, province_code, province_name
transfer_out_tag_id, main_brand_id, main_brand_name, province_code, province_name, points_period_type
</sql>
<resultMap extends="BaseResultMap" id="DTOResultMap" type="cn.com.glsx.scrm.shopmall.dto.integral.IntegralTransferOutDTO">
......
  • @wangxw1
    commented
    Owner

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

    1. 性能与资源消耗:循环内重复解析 JSON 配置(重要性:高)

    • 问题描述:在 IntegralTransferOutService.java 中,fillPointsPeriodTypeDesc(List<IntegralTransferOutDTO> result) 方法通过 for 循环遍历列表,并为每个元素调用单体填充方法。而在单体填充方法中,每次都会调用 getPointsPeriodTypeMap(),该方法每次都会读取环境变量并执行 JSON.parseArray(...) 操作。
    • 影响分析:在分页查询或批量处理场景下,如果结果集有 50 条记录,就会同步进行 50 次 JSON 字符串解析操作。这会造成显著的 CPU 资源浪费和无意义的 GC 压力,属于典型的 O(N) 性能瓶颈。
    • 优化建议:将配置获取与解析提取到循环外部,转换为 Map 后再在循环内进行匹配。

      public void fillPointsPeriodTypeDesc(List<IntegralTransferOutDTO> result) {
        if (CollectionUtils.isEmpty(result)) {
            return;
        }
        // 循环外获取并解析配置,仅执行一次
        List<PointsPeriodTypeDTO> mappingList = getPointsPeriodTypeMap();
        Map<Integer, String> typeDescMap = mappingList.stream()
                .collect(Collectors.toMap(PointsPeriodTypeDTO::getPointsPeriodType, PointsPeriodTypeDTO::getPointsPeriodTypeDesc, (v1, v2) -> v1));
      
        for (IntegralTransferOutDTO dto : result) {
            Integer type = dto.getPointsPeriodType() == null ? 1 : dto.getPointsPeriodType();
            dto.setPointsPeriodType(type);
            dto.setPointsPeriodTypeDesc(typeDescMap.get(type));
        }
      }
      

    2. 可维护性与健壮性:业务话术硬编码与配置映射冲突(重要性:中)

    • 问题描述:在 fillPointsPeriodTypeDesc 单体方法中,存在硬编码 String desc = "26年9月前积分";。
    • 影响分析:引入 POINTS_PERIOD_TYPE_MAPPING_ENV 环境变量的初衷是为了通过配置动态驱动文案展示。如果配置中将 type=1 的描述改为了 "2026年9月前积分",但由于某些原因映射匹配失败(或未匹配到),系统会回退到硬编码的文案,导致代码中硬编码的文案与动态配置的默认值(DEFAULT_POINTS_PERIOD_TYPE_MAP)产生潜在的维护割裂。
    • 优化建议:消除局部硬编码,统一以 getPointsPeriodTypeMap() 中的数据为准。如果匹配不到,可以直接使用默认映射常量中的值,保证文案定义的单一数据源。

    3. 最佳实践:非事务/异步方法无需使用 Spring 代理对象调用(重要性:低)

    • 问题描述:在 IntegralTransferOutService 的 pageQuery 和 detail 方法中,调用填充方法使用的是 thiz.fillPointsPeriodTypeDesc(result);。
    • 影响分析:thiz 通常是为了解决 Spring AOP(如 @Transactional 或 @Async)同类方法内部调用失效的问题而注入的代理对象。fillPointsPeriodTypeDesc 只是一个普通的内存数据拼装方法,没有任何 AOP 切面需求。使用 thiz 调用不仅增加了不必要的代理开销,还会给阅读代码的人带来误解(误以为该方法有事务等切面逻辑)。
    • 优化建议:直接使用 this.fillPointsPeriodTypeDesc(result); 或直接调用 fillPointsPeriodTypeDesc(result); 即可。

    二、评分明细

    • 功能实现的正确性与健壮性(36/40分): 核心业务逻辑实现正确,Dubbo 接口新增方法未破坏原有规约,MyBatis 也没有使用违规子查询。扣分点在于处理 pointsPeriodType 为空时的默认逻辑中,存在配置与硬编码双重定义的微小瑕疵,边界处理不够优雅。
    • 安全性与潜在风险(30/30分): 未发现 SQL 注入、XSS、越权等安全隐患。新增的 Dubbo 接口无敏感参数变更,属于安全的扩展。
    • 最佳实践与可维护性(17/20分): 代码结构清晰,DTO 规范合理。扣分点在于滥用了 Spring 代理对象(thiz)调用普通方法,且局部变量的硬编码降低了动态配置的意义。
    • 性能与资源利用(2/5分): 扣除3分。在 for 循环中反复执行 JSON.parseArray 是明显的性能反模式,尤其在分页查询等高频场景下会造成不必要的 CPU 开销。
    • 提交信息质量(5/5分): Commit 信息非常优秀。采用了 feat(scope): subject 的规范格式,且详细列出了具体的变更点、业务逻辑和版本升级信息,可追溯性极强。

    总分:90分

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