Commit 257a3076 by 叶立庆

Merge branch 'v5.8.6' into 'master'

上线合并

See merge request !8
2 parents 89c7fda3 a0beb6aa
......@@ -12,7 +12,7 @@
<name>rpc-dj-goods-listing-api</name>
<properties>
<deploy.scanPackage>cn.com.glsx.dj.goods.listing.remote</deploy.scanPackage>
<goods-listing.api.version>1.1.0-SNAPSHOT</goods-listing.api.version>
<goods-listing.api.version>5.8.6-SNAPSHOT</goods-listing.api.version>
<smartcarlife.api.version>5.8.4-SNAPSHOT</smartcarlife.api.version>
</properties>
<dependencies>
......
......@@ -13,7 +13,7 @@
<packaging>war</packaging>
<properties>
<skipTests>true</skipTests>
<goods-listing.api.version>1.1.0-SNAPSHOT</goods-listing.api.version>
<goods-listing.api.version>5.8.6-SNAPSHOT</goods-listing.api.version>
</properties>
<dependencies>
<dependency>
......
......@@ -698,7 +698,16 @@ public class GoodsListingApprovalService {
context.detailsByProductBaseIdMap = groupProductDetailsByProductBaseId(context.details);
context.settleGroups = goodsListingGoodsTypeGroupService.listBase(businessCode, RuleTypeEnum.SETTLE_ACCOUNT_RULE.getValue());
context.reconciliationGroups = goodsListingGoodsTypeGroupService.listBase(businessCode, RuleTypeEnum.RECONCILIATION_RULE.getValue());
context.relationsByGroupIdMap = groupRelationsByGroupId(goodsListingGoodsTypeGroupRelationService.listByBusinessCode(businessCode));
// 预处理分组ID集合,优化查询性能
context.settleGroupIds = context.settleGroups.stream()
.map(GoodsListingGoodsTypeGroupDTO::getId)
.collect(Collectors.toSet());
context.reconciliationGroupIds = context.reconciliationGroups.stream()
.map(GoodsListingGoodsTypeGroupDTO::getId)
.collect(Collectors.toSet());
List<GoodsListingGoodsTypeGroupRelation> relations = goodsListingGoodsTypeGroupRelationService.listByBusinessCode(businessCode);
context.relationsByGroupIdMap = groupRelationsByGroupId(relations);
toPackageRuleMap(context, relations);
context.expenseRulesByGroupIdMap = groupExpenseRulesByGroupId(goodsListingExpenseCategoryRuleService.listByBusinessCode(businessCode));
context.distributionRulesByGroupIdMap = groupDistributionRulesByGroupId(goodsListingDistributionRuleService.listByBusinessCode(businessCode));
context.divisionRuleAutos = goodsListingDivisionRuleAutoService.listByBusinessCode(businessCode);
......@@ -778,6 +787,20 @@ public class GoodsListingApprovalService {
return upgradeGoodsMap;
}
//套餐是否有结算规则或对账规则
private void toPackageRuleMap(ApprovalPublishContext context,List<GoodsListingGoodsTypeGroupRelation> relations){
for(GoodsListingGoodsTypeGroupRelation r:relations){
if(StringUtils.isBlank(r.getPackageCode())){
continue;
}
if(context.settleGroupIds.contains(r.getGoodsTypeGroupId())){
context.settlePackageCodes.add(r.getPackageCode());
}
if(context.reconciliationGroupIds.contains(r.getGoodsTypeGroupId())){
context.reconciliationPackageCodes.add(r.getPackageCode());
}
}
}
private Map<Integer, List<GoodsListingGoodsTypeGroupRelation>> groupRelationsByGroupId(List<GoodsListingGoodsTypeGroupRelation> relations) {
if (CollectionUtils.isEmpty(relations)) {
return Collections.emptyMap();
......@@ -1116,7 +1139,17 @@ public class GoodsListingApprovalService {
packageInfo.setSceneType(context.sceneType);
packageInfo.setStatus(CarLifeEnum.MerchantGoodsStatus.ON_SHELF.getValue());
packageInfo.setLastOnShelfTime(context.now);
packageInfo.setFinanceCheckFlag(Objects.equals(context.approval.getShelfModel(),ShelfModelEnum.SPECIAL_SHELF.getValue()) ? StatusEnum.YES.getValue() : StatusEnum.NO.getValue());
packageInfo.setFinanceCheckFlag(StatusEnum.NO.getValue());
if(Objects.equals(context.approval.getShelfModel(),ShelfModelEnum.SPECIAL_SHELF.getValue())){
//特殊上架商品,如为套餐且分账和对账规则都有该套餐规则,则开启财务校验
if(StringUtils.isNotBlank(packageCode)){
if(context.settlePackageCodes.contains(packageCode) && context.reconciliationPackageCodes.contains(packageCode)){
packageInfo.setFinanceCheckFlag(StatusEnum.YES.getValue());
}
}else{
packageInfo.setFinanceCheckFlag(StatusEnum.YES.getValue());
}
}
fillAuditFields(packageInfo, context);
return packageInfo;
}
......@@ -1419,7 +1452,17 @@ public class GoodsListingApprovalService {
}
goodsInfo.setLastOnShelfTime(context.now);
goodsInfo.setShelfSource(CarLifeEnum.MerchantShelfSource.DJ_CREATE_BUSINESS.getValue());
goodsInfo.setFinanceCheckFlag(Objects.equals(context.approval.getShelfModel(),ShelfModelEnum.SPECIAL_SHELF.getValue()) ? StatusEnum.YES.getValue() : StatusEnum.NO.getValue());
goodsInfo.setFinanceCheckFlag(StatusEnum.NO.getValue());
if(Objects.equals(context.approval.getShelfModel(),ShelfModelEnum.SPECIAL_SHELF.getValue())){
//特殊上架商品,如为套餐且分账和对账规则都有该套餐规则,则开启财务校验
if(StringUtils.isNotBlank(packageCode)){
if(context.settlePackageCodes.contains(packageCode) && context.reconciliationPackageCodes.contains(packageCode)){
goodsInfo.setFinanceCheckFlag(StatusEnum.YES.getValue());
}
}else{
goodsInfo.setFinanceCheckFlag(StatusEnum.YES.getValue());
}
}
}
private boolean validateUpgradeGoodsAreas(ApprovalPublishContext context, UpgradeGoodsDTO upgradeGoodsDTO) {
......@@ -2931,7 +2974,11 @@ public class GoodsListingApprovalService {
private Map<Integer, List<GoodsListingProductDetailDTO>> detailsByProductBaseIdMap = Collections.emptyMap();
private List<GoodsListingGoodsTypeGroupDTO> settleGroups;
private List<GoodsListingGoodsTypeGroupDTO> reconciliationGroups;
private Set<Integer> settleGroupIds;
private Set<Integer> reconciliationGroupIds;
private Map<Integer, List<GoodsListingGoodsTypeGroupRelation>> relationsByGroupIdMap = Collections.emptyMap();
private Set<String> settlePackageCodes = new HashSet<>();//有结算规则的packageCode
private Set<String> reconciliationPackageCodes = new HashSet<>();//有对账规则的packageCode
private Map<Integer, List<GoodsListingExpenseCategoryRule>> expenseRulesByGroupIdMap = Collections.emptyMap();
private Map<Integer, List<GoodsListingDistributionRule>> distributionRulesByGroupIdMap = Collections.emptyMap();
private List<GoodsListingDivisionRuleAuto> divisionRuleAutos;
......
......@@ -7,6 +7,7 @@ import cn.com.glsx.dj.goods.listing.model.GoodsListingExpenseCategoryRule;
import cn.com.glsx.dj.goods.listing.model.GoodsListingGoodsTypeGroup;
import cn.com.glsx.dj.goods.listing.model.GoodsListingGoodsTypeGroupRelation;
import cn.com.glsx.dj.smartcarlife.dto.DivisionRuleEffectRecordDTO;
import cn.com.glsx.dj.smartcarlife.enums.GoodsTypeGroupTypeEnum;
import cn.com.glsx.dj.smartcarlife.enums.RpcErrorEnum;
import cn.com.glsx.dj.smartcarlife.enums.RuleTypeEnum;
import cn.com.glsx.dj.smartcarlife.model.*;
......@@ -91,7 +92,7 @@ public class GoodsListingReconciliationRuleService {
}
// 过滤后没有剩余商品关系的旧对账组不再复制,避免生成空对账组。
oldReconciliationGroupRuleList = oldReconciliationGroupRuleList.stream()
.filter(item -> hasCopyableRelations(item.getId(), excludeMerchantGoodsCodes, excludePackageCodes))
.filter(item -> hasCopyableRelations(item, excludeMerchantGoodsCodes, excludePackageCodes))
.collect(Collectors.toList());
if(CollectionUtils.isEmpty(oldReconciliationGroupRuleList)) {
return ;
......@@ -208,11 +209,15 @@ public class GoodsListingReconciliationRuleService {
}
}
private boolean hasCopyableRelations(Integer goodsTypeGroupRuleId, Set<String> excludeMerchantGoodsCodes,
private boolean hasCopyableRelations(MerchantGoodsTypeGroupReconciliationRule rule, Set<String> excludeMerchantGoodsCodes,
Set<String> excludePackageCodes) {
Integer goodsTypeGroupRuleId = rule.getId();
if(goodsTypeGroupRuleId == null) {
return false;
}
if(Objects.equals(rule.getGroupType(), GoodsTypeGroupTypeEnum.ALL.getValue())){
return true;
}
List<GoodsTypeGroupRelation> list = smartcarGoodsTypeGroupRelationMapper.select(GoodsTypeGroupRelation.builder()
.goodsTypeGroupRuleId(goodsTypeGroupRuleId)
.ruleType(RuleTypeEnum.RECONCILIATION_RULE.getValue())
......
......@@ -195,7 +195,7 @@ public class GoodsListingSettleRuleService {
for(MerchantGoodsTypeGroupSettleRule item : oldSettleGroupRuleList) {
Integer newGoodsTypeGroupId = copyGoodsTypeGroupIfNecessary(item.getGoodsTypeGroupId(), goodsTypeGroupMap,
oldGoodsTypeGroupMap, oldGoodsTypeGroupRelationMap, copiedRelationList, now, updatedBy);
if(newGoodsTypeGroupId == null) {
if(item.getGoodsTypeGroupId() != null && newGoodsTypeGroupId == null) {//非全部品类规则
continue;
}
oldGoodsTypeGroupRuleIds.add(item.getId());
......@@ -233,7 +233,7 @@ public class GoodsListingSettleRuleService {
for(MerchantGoodsTypeGroupDivisionRule item : oldDivisionGroupRuleList) {
Integer newGoodsTypeGroupId = copyGoodsTypeGroupIfNecessary(item.getGoodsTypeGroupId(), goodsTypeGroupMap,
oldGoodsTypeGroupMap, oldGoodsTypeGroupRelationMap, copiedRelationList, now, updatedBy);
if(newGoodsTypeGroupId == null) {
if(item.getGoodsTypeGroupId() != null && newGoodsTypeGroupId == null) {//非全部品类规则
continue;
}
oldGoodsTypeGroupRuleIds.add(item.getId());
......
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议,如果必要,给出代码示例(仅限 Top 3)

    1. 生产环境使用 SNAPSHOT 版本(工程最佳实践与稳定性风险)

    • 问题描述:在 rpc-dj-goods-listing-api 和 rpc-dj-goods-listing 的 pom.xml 中,API 版本被修改为 5.8.6-SNAPSHOT。结合提交信息中的“上线合并”,将 SNAPSHOT(快照)版本发布到生产环境属于严重的 Maven 依赖管理反模式。
    • 影响分析:SNAPSHOT 版本是可变的,每次构建都可能拉取到不同的代码,这会导致生产环境的构建具有不可确定性。一旦依赖的下游或自身发生变更,极易引发生产环境的“幽灵Bug”,且难以回溯和排查。
    • 优化建议:上线前的主干分支(Master/Release)必须使用正式的 Release 版本号(如 5.8.6)。建议在 CI/CD 流程中增加对 Master 分支包含 SNAPSHOT 版本的拦截校验。

    2. 潜在的空指针异常(NPE)风险(功能健壮性)

    • 问题描述:在 GoodsListingApprovalService.java 第 701-704 行,直接对 context.settleGroups 和 context.reconciliationGroups 调用了 .stream() 方法。
    • 影响分析:如果 goodsListingGoodsTypeGroupService.listBase() 方法在未查询到数据时返回了 null(而非空集合),调用 .stream() 将直接触发 NullPointerException,导致整个审批/发布流程阻断。
    • 优化建议:防御性编程,在进行流操作前进行判空处理,或使用 Optional 包装。 java // 优化示例 context.settleGroupIds = Optional.ofNullable(context.settleGroups) .orElseGet(Collections::emptyList) .stream() .map(GoodsListingGoodsTypeGroupDTO::getId) .collect(Collectors.toSet());

    3. 财务校验逻辑存在代码重复(可维护性)

    • 问题描述:在 GoodsListingApprovalService.java 中,判断并设置 FinanceCheckFlag 的 10 行核心逻辑代码,在 buildPackageInfo(第 1142-1152 行)和 buildGoodsInfo(第 1455-1465 行)中被完全复制粘贴了两次。
    • 影响分析:违反了 DRY(Don't Repeat Yourself)原则。未来如果关于“特殊上架商品财务校验”的业务规则发生变化,开发人员极容易漏改其中一处,从而引发线上Bug。
    • 优化建议:将这部分逻辑抽取为一个独立的私有方法,提高代码复用性和可维护性。 ```java // 优化示例 private Integer determineFinanceCheckFlag(ApprovalPublishContext context, String packageCode) { if (!Objects.equals(context.approval.getShelfModel(), ShelfModelEnum.SPECIAL_SHELF.getValue())) { return StatusEnum.NO.getValue(); } if (StringUtils.isBlank(packageCode)) { return StatusEnum.YES.getValue(); } if (context.settlePackageCodes.contains(packageCode) && context.reconciliationPackageCodes.contains(packageCode)) { return StatusEnum.YES.getValue(); } return StatusEnum.NO.getValue(); }

    // 原方法调用处直接改为: packageInfo.setFinanceCheckFlag(this.determineFinanceCheckFlag(context, packageCode));

    
    ---
    
    #### 二、评分明细
    
    - **功能实现的正确性与健壮性(36 / 40分)**:
      业务逻辑(如修复全部品类规则未保留的问题、使用 Set 优化查询)实现正确。扣分项在于对集合调用 `stream()` 时缺乏防御性判空,存在潜在的 NPE 风险。未发现违反“Mybatis子查询”及“Dubbo参数变更”的红线规则。
    - **安全性与潜在风险(30 / 30分)**:
      本次代码变更主要集中在业务规则判断与内存数据组装,未发现 SQL 注入、越权、敏感信息泄露等安全漏洞。
    - **最佳实践与可维护性(12 / 20分)**:
      扣分较多。主要原因是“上线合并”的代码中包含了 `SNAPSHOT` 版本,这严重违反了发布规范。其次,服务类中出现了明显的复制粘贴代码(DRY原则),降低了可维护性。
    - **性能与资源利用(5 / 5分)**:
      在 `GoodsListingApprovalService` 中,主动将 List 转换为 `Set` 以将后续的查找时间复杂度从 O(N) 降为 O(1),这是一个很好的性能优化实践,值得肯定。
    - **提交信息质量(4 / 5分)**:
      Commit 信息(如“套餐是按照套餐规则分润才默认开启财务规则校验”)较为清晰地表达了业务意图,具备一定的可追溯性,但“上线合并”提交未清理快照版本。
    
    总分:87分
    
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!