参数代理对象feign调用问题

This commit is contained in:
zhou-hongcheng
2026-03-12 12:10:04 +08:00
parent d0d5c4a15b
commit 4ef1a02933
@@ -1,6 +1,7 @@
package com.mhd.basic.domain.materialBaseInfo.repository.persistence;
import cn.hutool.json.JSONUtil;
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mhd.basic.domain.batch.entity.Batch;
@@ -14,7 +15,7 @@ import com.mhd.common.core.exception.ServiceException;
import com.mhd.common.core.web.domain.AjaxResult;
import com.mhd.common.security.utils.SecurityUtils;
import com.mhd.system.api.WmsServiceFeign;
import com.mhd.system.api.domain.MaterialBaseInfoFeign;
import com.mhd.system.api.domain.*;
import com.mhd.system.api.model.LoginUser;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -24,6 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* 物料基础信息Service业务层处理
@@ -87,8 +89,7 @@ public class MaterialBaseInfoImpl extends ServiceImpl<MaterialBaseInfoMapper, Ma
* @param materialBaseInfoDO
*/
public void synchMaterialBaseInfo(MaterialBaseInfoDO materialBaseInfoDO, Integer updateFeign){
MaterialBaseInfoFeign materialBaseInfoFeign = new MaterialBaseInfoFeign();
BeanUtils.copyProperties(materialBaseInfoDO, materialBaseInfoFeign);
MaterialBaseInfoFeign materialBaseInfoFeign = toFeign(materialBaseInfoDO);
materialBaseInfoFeign.setUpdateFeign(updateFeign);
AjaxResult ajaxResult = wmsServiceFeign.edit(materialBaseInfoFeign);
if (!"200".equals(String.valueOf(ajaxResult.get("code")))){
@@ -96,6 +97,118 @@ public class MaterialBaseInfoImpl extends ServiceImpl<MaterialBaseInfoMapper, Ma
}
}
/**
* 将 DO 转换为 Feign 对象(深拷贝)
*/
public MaterialBaseInfoFeign toFeign(MaterialBaseInfoDO source) {
if (source == null) {
return null;
}
MaterialBaseInfoFeign target = new MaterialBaseInfoFeign();
// 1. 复制基本属性(所有非集合字段)
copyBasicProperties(source, target);
// 2. 深拷贝嵌套对象
target.setMaterialGoodsRule(copyMaterialGoodsRule(source.getMaterialGoodsRule()));
target.setMaterialCommon(copyMaterialCommon(source.getMaterialCommon()));
target.setMaterialWarehouseControl(copyMaterialWarehouseControl(source.getMaterialWarehouseControl()));
target.setMaterialInventoryWarningList(copyMaterialInventoryWarningList(source.getMaterialInventoryWarningList()));
target.setMaterialBarCodeList(copyMaterialBarCodeList(source.getMaterialBarCodeList()));
return target;
}
/**
* 复制基本属性
*/
private void copyBasicProperties(MaterialBaseInfoDO source, MaterialBaseInfoFeign target) {
// 使用 Spring 的 BeanUtils 复制基本字段
BeanUtils.copyProperties(source, target);
}
/**
* 深拷贝商品规则
*/
private MaterialGoodsRuleFeign copyMaterialGoodsRule(MaterialGoodsRuleFeign source) {
if (source == null) {
return null;
}
MaterialGoodsRuleFeign target = new MaterialGoodsRuleFeign();
BeanUtils.copyProperties(source, target);
return target;
}
/**
* 深拷贝公共信息
*/
private MaterialCommonFeign copyMaterialCommon(MaterialCommonFeign source) {
if (source == null) {
return null;
}
MaterialCommonFeign target = new MaterialCommonFeign();
BeanUtils.copyProperties(source, target);
return target;
}
/**
* 深拷贝仓库控制信息
*/
private MaterialWarehouseControlFeign copyMaterialWarehouseControl(MaterialWarehouseControlFeign source) {
if (source == null) {
return null;
}
MaterialWarehouseControlFeign target = new MaterialWarehouseControlFeign();
BeanUtils.copyProperties(source, target);
return target;
}
/**
* 深拷贝库存预警列表
*/
private List<MaterialInventoryWarningFeign> copyMaterialInventoryWarningList(List<MaterialInventoryWarningFeign> sourceList) {
if (CollectionUtils.isEmpty(sourceList)) {
return null;
}
return sourceList.stream()
.map(source -> {
MaterialInventoryWarningFeign target = new MaterialInventoryWarningFeign();
BeanUtils.copyProperties(source, target);
return target;
})
.collect(Collectors.toList());
}
/**
* 深拷贝条码列表
*/
private List<MaterialBarCodeFeign> copyMaterialBarCodeList(List<MaterialBarCodeFeign> sourceList) {
if (CollectionUtils.isEmpty(sourceList)) {
return null;
}
return sourceList.stream()
.map(source -> {
MaterialBarCodeFeign target = new MaterialBarCodeFeign();
BeanUtils.copyProperties(source, target);
return target;
})
.collect(Collectors.toList());
}
/**
* 批量转换(如果有需要)
*/
public List<MaterialBaseInfoFeign> toFeignList(List<MaterialBaseInfoDO> sourceList) {
if (CollectionUtils.isEmpty(sourceList)) {
return null;
}
return sourceList.stream()
.map(this::toFeign)
.collect(Collectors.toList());
}
/**
* @description 校验唯一
* @author ZhouGY