Commit e2667d94 by chenxi

5.8.6版本 发货单详情、调拨单详情新增产品ID字段

1 parent ba3c2b1f
......@@ -200,7 +200,4 @@ public class PurchaseOrderDeliveryDetailDTO extends PurchaseOrderDeliveryDetail
@ApiModelProperty(notes="是否支持扫码入库")
private Boolean canScanEnable;
@ApiModelProperty(notes = "升级商品编码")
private String upgradeCommodityCode;
}
......@@ -79,6 +79,13 @@ public class PurchaseOrderDeliveryDetail implements Serializable{
@ApiModelProperty(notes = "升级商品id", required = true, dataType = "int")
@Column(name = "upgrade_goods_id")
private Integer upgradeGoodsId;
/**
* 产品ID(升级商品commodity_code)
*/
@ApiModelProperty(notes = "产品ID")
@Column(name = "upgrade_commodity_code")
private String upgradeCommodityCode;
/**
* 采购订单商品主键ID
......
......@@ -47,6 +47,13 @@ public class StockAllocateDetail implements Serializable {
private String goodsName;
/**
* 产品ID(升级商品commodity_code)
*/
@ApiModelProperty(notes = "产品ID")
@Column(name = "upgrade_commodity_code")
private String upgradeCommodityCode;
/**
* 商品编号
*/
@Column(name = "product_code")
......
......@@ -136,4 +136,12 @@ public interface UpgradeGoodsMapper extends OreMapper<UpgradeGoods> {
*/
List<java.util.Map<String, Object>> countOnShelfMerchantGoods(@Param("upgradeGoodsIds") List<Integer> upgradeGoodsIds);
/**
* 根据升级商品ID列表批量查询产品ID(只返回id、commodity_code)
*
* @param upgradeGoodsIds 升级商品ID列表
* @return 升级商品ID与产品ID的对应关系
*/
List<UpgradeGoods> listCommodityCodeByIds(@Param("upgradeGoodsIds") List<Integer> upgradeGoodsIds);
}
......@@ -124,6 +124,7 @@ public class PurchaseOrderDeliveryDetailService {
detailDTO.setGoodsType(orderGoods.getGoodsType());
detailDTO.setGoodsTypeName(orderGoods.getGoodsTypeName());
detailDTO.setUpgradeGoodsId(orderGoods.getUpgradeGoodsId());
detailDTO.setUpgradeCommodityCode(orderGoods.getUpgradeGoodsCommodityCode());
detailDTO.setType(orderGoods.getType());
detailDTO.setUpgradeGoodsName(orderGoods.getUpgradeGoodsName());
detailDTO.setDeliveryRemark(orderGoods.getDeliveryRemark());
......@@ -196,6 +197,7 @@ public class PurchaseOrderDeliveryDetailService {
detailDTO.setGoodsType(allocateDetail.getGoodsType());
detailDTO.setGoodsTypeName(allocateDetail.getGoodsTypeName());
detailDTO.setUpgradeGoodsId(allocateDetail.getGoodsId());
detailDTO.setUpgradeCommodityCode(allocateDetail.getUpgradeGoodsCommodityCode());
detailDTO.setType(allocateDetail.getProductCode());
detailDTO.setUpgradeGoodsName(allocateDetail.getGoodsName());
//detailDTO.setDeliveryRemark(allocateDetail.getDeliveryRemark());
......
......@@ -5,6 +5,7 @@ import cn.com.glsx.dj.smartcarlife.model.MerchantShopGoodsStock;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
......@@ -25,8 +26,10 @@ import com.github.pagehelper.PageHelper;
import cn.com.glsx.dj.smartcarlife.dto.StockAllocateDetailDTO;
import cn.com.glsx.dj.smartcarlife.dto.StockAllocateRecordDTO;
import cn.com.glsx.dj.smartcarlife.mapper.StockAllocateDetailMapper;
import cn.com.glsx.dj.smartcarlife.mapper.UpgradeGoodsMapper;
import cn.com.glsx.dj.smartcarlife.model.StockAllocateDetail;
import cn.com.glsx.dj.smartcarlife.model.StockAllocateRecord;
import cn.com.glsx.dj.smartcarlife.model.UpgradeGoods;
import cn.com.glsx.framework.core.beans.BaseModel;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
......@@ -43,6 +46,9 @@ public class StockAllocateDetailService {
private StockAllocateDetailMapper stockAllocateDetailMapper;
@Autowired
private UpgradeGoodsMapper upgradeGoodsMapper;
@Autowired
private StockAllocateRecordService stockAllocateRecordService;
@Autowired
......@@ -53,7 +59,18 @@ public class StockAllocateDetailService {
try {
Date now = new Date();
List<Integer> collected = list.stream().map(StockAllocateDetail::getGoodsId)
.filter(Objects::nonNull)
.collect(Collectors.toList());
// 商品id与产品ID(commodity_code)的对应关系
Map<Integer, String> commodityCodeMap = new HashMap<>();
if (!collected.isEmpty()) {
List<UpgradeGoods> upgradeGoodsList = upgradeGoodsMapper.listCommodityCodeByIds(collected);
if (CollectionUtils.isNotEmpty(upgradeGoodsList)) {
commodityCodeMap = upgradeGoodsList.stream()
.filter(x -> Objects.nonNull(x.getId()))
.collect(Collectors.toMap(UpgradeGoods::getId, UpgradeGoods::getCommodityCode, (v1, v2) -> v1));
}
}
Map<StockKey, MerchantShopGoodsStock> stockIndex = new ConcurrentHashMap<>();
Map<StockKey, MerchantShopGoodsStock> callInStockIndex = new ConcurrentHashMap<>();
Integer callOutYqMerchantId = stockAllocateRecordDTO.getCallOutYqMerchantId();
......@@ -71,6 +88,7 @@ public class StockAllocateDetailService {
for (StockAllocateDetail record : list) {
record.setAllocateCode(stockAllocateRecordDTO.getAllocateCode());
record.setInputNumber(BigDecimal.valueOf(0));
record.setUpgradeCommodityCode(commodityCodeMap.get(record.getGoodsId()));
// === 调出库存 ===
StockKey outKey = new StockKey(
......
......@@ -13,6 +13,7 @@
<result column="goods_type" jdbcType="INTEGER" property="goodsType" />
<result column="goods_type_name" jdbcType="VARCHAR" property="goodsTypeName" />
<result column="upgrade_goods_id" jdbcType="INTEGER" property="upgradeGoodsId" />
<result column="upgrade_commodity_code" jdbcType="VARCHAR" property="upgradeCommodityCode" />
<result column="purchase_order_goods_id" property="purchaseOrderGoodsId"/>
<result column="allocate_order_goods_id" property="allocateOrderGoodsId"/>
<result column="type" jdbcType="VARCHAR" property="type" />
......@@ -35,7 +36,7 @@
WARNING - @mbg.generated
-->
id, order_delivery_id, order_code, goods_code, goods_name, goods_type, goods_type_name,
upgrade_goods_id,purchase_order_goods_id, allocate_order_goods_id, type, upgrade_goods_name, purchase_goods_name, third_party_code, third_party_name, purchase_number, stock_num, put_status, delivery_remark, created_by,
upgrade_goods_id, upgrade_commodity_code, purchase_order_goods_id, allocate_order_goods_id, type, upgrade_goods_name, purchase_goods_name, third_party_code, third_party_name, purchase_number, stock_num, put_status, delivery_remark, created_by,
created_date, updated_by, updated_date, deleted_flag
</sql>
<resultMap id="DTOResultMap" type="cn.com.glsx.dj.smartcarlife.dto.PurchaseOrderDeliveryDetailDTO" extends="BaseResultMap">
......@@ -65,7 +66,6 @@
<result column="pendingStockCount" property="pendingStockCount" jdbcType="BIGINT"/>
<result column="inStockCount" property="inStockCount" jdbcType="BIGINT"/>
<result column="totalCount" property="totalCount" jdbcType="BIGINT"/>
<result column="upgrade_goods_commodity_code" property="upgradeCommodityCode" jdbcType="VARCHAR"/>
</resultMap>
......@@ -142,7 +142,7 @@
sar.call_out_merchant_id, sar.call_out_merchant_name,
sar.call_out_yq_merchant_id, sar.call_out_yq_merchant_name,
sad.film_roll_no,
dclpog.upgrade_goods_commodity_code
dclpodd.upgrade_commodity_code
from dj_car_life_purchase_order_delivery_detail dclpodd
left join dj_car_life_purchase_order_delivery dclpod on dclpodd.order_delivery_id = dclpod.id and dclpod.deleted_flag = 'N'
left join dj_car_life_purchase_order dclpo on dclpo.order_code = dclpodd.order_code and dclpo.deleted_flag = 'N'
......@@ -230,13 +230,9 @@
and exists (
select 1
from dj_car_life_purchase_order_delivery_detail dd2
left join dj_car_life_purchase_order_goods og2
on og2.order_code = dd2.order_code
and og2.id = dd2.purchase_order_goods_id
and og2.deleted_flag = 'N'
where dd2.deleted_flag = 'N'
and dd2.order_delivery_id = dclpodd.order_delivery_id
and og2.upgrade_goods_commodity_code like CONCAT('%', #{upgradeCommodityCode},'%')
and dd2.upgrade_commodity_code like CONCAT('%', #{upgradeCommodityCode},'%')
)
</if>
......
......@@ -117,7 +117,7 @@
dd.purchase_goods_name as detail_purchase_goods_name,
dd.third_party_code as detail_third_party_code,
dd.third_party_name as detail_third_party_name,
dclpog.upgrade_goods_commodity_code as detail_upgrade_goods_commodity_code,
dd.upgrade_commodity_code as detail_upgrade_goods_commodity_code,
dclpog.specification_data as detail_specification_data
from (select id,
order_code,
......@@ -181,7 +181,7 @@
dd.purchase_goods_name as detail_purchase_goods_name,
dd.third_party_code as detail_third_party_code,
dd.third_party_name as detail_third_party_name,
dclpog.upgrade_goods_commodity_code as detail_upgrade_goods_commodity_code,
dd.upgrade_commodity_code as detail_upgrade_goods_commodity_code,
if(main.order_type = 1, sar.remark, po.remark) as purchase_order_remark,
concat(ifnull(if(main.order_type = 1, sar.remark, po.remark), ''), ifnull(dd.delivery_remark, '')) as detail_delivery_remark,
if(main.order_type = 1, sad.specification_data, dclpog.specification_data) as detail_specification_data,
......@@ -257,7 +257,7 @@
sad.specification_data as detail_specification_data,
dd.purchase_order_goods_id as detail_purchase_order_goods_id,
dd.allocate_order_goods_id as detail_allocate_order_goods_id,
dclpog.upgrade_goods_commodity_code as detail_upgrade_goods_commodity_code,
dd.upgrade_commodity_code as detail_upgrade_goods_commodity_code,
sar.created_by as allocate_createdBy,
sar.call_in_merchant_id as allocate_callInMerchantId,
sar.call_in_merchant_name as allocate_callInMerchantName,
......
......@@ -9,6 +9,7 @@
<result column="allocate_code" property="allocateCode" jdbcType="VARCHAR" />
<result column="goods_id" property="goodsId" jdbcType="INTEGER" />
<result column="goods_name" property="goodsName" jdbcType="VARCHAR" />
<result column="upgrade_commodity_code" property="upgradeCommodityCode" jdbcType="VARCHAR" />
<result column="product_code" property="productCode"/>
<result column="source_material_id" property="sourceMaterialId" jdbcType="INTEGER" />
<result column="source_material_name" property="sourceMaterialName" jdbcType="VARCHAR" />
......@@ -32,7 +33,7 @@
</resultMap>
<resultMap id="StockAllocateDetailDTOMap" type="cn.com.glsx.dj.smartcarlife.dto.StockAllocateDetailDTO" extends="BaseResultMap">
<result column="commodity_code" property="upgradeGoodsCommodityCode" jdbcType="VARCHAR" />
<result column="upgrade_commodity_code" property="upgradeGoodsCommodityCode" jdbcType="VARCHAR" />
<result column="specification_data" property="specificationData"/>
<result column="specification_type_sequence" property="specificationTypeSequence"/>
</resultMap>
......@@ -41,7 +42,7 @@
<!--
WARNING - @mbg.generated
-->
id, allocate_code, goods_id, goods_name,product_code, source_material_id, source_material_name,
id, allocate_code, goods_id, goods_name, upgrade_commodity_code, product_code, source_material_id, source_material_name,
goods_type, goods_type_name, allocate_number, deleted_flag, created_by, created_date,
updated_by, updated_date,product_code,conversion_value, delivery_number, delivery_status, upgrade_purchase_price,input_number,specification_data,
out_stock_qty,in_stock_qty
......@@ -58,7 +59,7 @@
sad.out_stock_qty,sad.in_stock_qty,
gi.goods_type,gi.goods_type_name,sad.allocate_number,sad.deleted_flag,sad.created_by,sad.created_date,
sad.updated_by, sad.updated_date, sad.film_roll_no, sad.delivery_number, sad.input_number, sad.delivery_status,
ug.specification_data,ug.specification_type_sequence,ug.commodity_code
ug.specification_data,ug.specification_type_sequence,sad.upgrade_commodity_code
from dj_car_life_stock_allocate_detail sad
left join dj_car_life_upgrade_goods ug on sad.goods_id = ug.id and ug.deleted_flag ='N'
left join dj_car_life_goods_info gi on gi.goods_code= ug.goods_code and gi.deleted_flag ='N'
......
......@@ -1239,5 +1239,16 @@
group by ug.id
</select>
<!-- 根据升级商品id批量查询产品ID -->
<select id="listCommodityCodeByIds" resultType="cn.com.glsx.dj.smartcarlife.model.UpgradeGoods">
select ug.id, ug.commodity_code
from dj_car_life_upgrade_goods ug
where ug.deleted_flag = 'N'
and ug.id in
<foreach collection="upgradeGoodsIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper>
  • @wangxw1
    commented
    Master

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

    1. MyBatis SQL 语句中使用了子查询(违反重要规则)

    • 问题描述:在 PurchaseOrderDeliveryDetailMapper.xml 的 <if test="upgradeCommodityCode != null ..."> 条件分支中,保留并修改了 exists (select 1 from ...) 的子查询逻辑;同时在 PurchaseOrderDeliveryMapper.xml 中也存在派生表(from (select ...))的子查询。
    • 影响分析:此举直接违反了“mybatis的sql语句不允许使用子查询”的强制规范。子查询(尤其是相关子查询)在表数据量膨胀时极易导致索引失效或引发全表扫描,造成严重的性能瓶颈,且不利于数据库查询优化器选择最优执行计划。
    • 优化建议:将 exists 子查询改写为 INNER JOIN 关联查询,或者在 Service 层拆分为两次查询(先查询符合条件的主键集合,再通过 IN 查询主数据,并在内存中完成组装)。

    2. Stream API Collectors.toMap 存在空指针异常(NPE)风险

    • 问题描述:在 StockAllocateDetailService.java 中,使用 Collectors.toMap 将 UpgradeGoods 列表转换为 Map 时,仅过滤了 Id 不为空,未过滤 CommodityCode。
    • 影响分析:Java 8 的 Collectors.toMap 底层调用了 Map.merge,该方法严格禁止 value 为 null。如果数据库中存在 commodity_code 为空的记录,这里将直接抛出 NullPointerException,导致整个业务流程阻断。另外,提取 goodsId 的集合未做去重,会导致 SQL IN 子句中出现重复参数。
    • 优化建议:在 filter 中增加对 CommodityCode 的非空判断;同时在提取 goodsId 集合时增加 distinct() 去重操作。
    • 代码示例: ```java // 优化建议:增加 distinct() 去重,并在 filter 中确保 value 不为 null List collected = list.stream().map(StockAllocateDetail::getGoodsId) .filter(Objects::nonNull) .distinct() // 增加去重,优化生成的 SQL .collect(Collectors.toList());

    // ... commodityCodeMap = upgradeGoodsList.stream() .filter(x -> Objects.nonNull(x.getId()) && Objects.nonNull(x.getCommodityCode())) // 增加 value 的非空判断 .collect(Collectors.toMap(UpgradeGoods::getId, UpgradeGoods::getCommodityCode, (v1, v2) -> v1));

    
    **3. DTO 字段结构变更存在 Dubbo RPC 兼容性风险(违反重要规则)**
    - **问题描述**:在 `PurchaseOrderDeliveryDetailDTO.java` 中删除了 `upgradeCommodityCode` 字段,将其移动到了父类 `PurchaseOrderDeliveryDetail` 模型中。
    - **影响分析**:根据规则,“Dubbo服务提供者Remote接口中的已有请求参数变更视为危险实现”。虽然字段名未变,但类的层级结构发生了改变。如果该 DTO 用作 Dubbo 接口的参数或返回值,在消费端和提供端版本不一致时,某些序列化框架(如部分配置下的 JSON、Kryo)在处理父类字段时可能会丢失数据或导致反序列化失败。
    - **优化建议**:对于作为 RPC 接口传输的 DTO 对象,应尽量避免修改其类层级结构。建议在 DTO 中保留该字段声明以确保向下兼容性,或者在充分验证当前 RPC 序列化协议对父类字段变更完全兼容后再进行重构。
    
    #### 二、评分明细
    
    - **功能实现的正确性与健壮性(30/40分)**:业务逻辑基本实现,但 `Collectors.toMap` 存在明显的 `NullPointerException` 隐患,且构造 `IN` 查询集合时未做去重处理,影响代码健壮性。
    - **安全性与潜在风险(22/30分)**:SQL 防注入处理良好(使用了安全的 CONCAT 拼接),但 DTO 字段上移至父类触及了 Dubbo 接口参数变更的危险规则,存在序列化兼容性隐患。
    - **最佳实践与可维护性(10/20分)**:严重违反了“不允许使用子查询”的工程强制规范,未能借本次修改契机将历史遗留的子查询进行重构。
    - **性能与资源利用(3/5分)**:子查询在数据量增大时存在慢 SQL 风险;未去重的集合会导致 SQL 解析开销无意义增加。
    - **提交信息质量(5/5分)**:Commit 信息清晰准确,较好地概括了本次代码的业务变更点。
    
    总分:70分
    
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!