This commit is contained in:
秦鸿展
2026-07-25 19:31:11 +08:00
parent f3fc2b3093
commit 96c95dabc6
7 changed files with 26 additions and 181 deletions
@@ -18,7 +18,7 @@ import java.util.Set;
/**
* bms财务结算系统feign调用接口
*/
@FeignClient(contextId = "BmsService", value = ServiceNameConstants.BMS_SERVICE, url = "http://10.102.192.32:8019",fallbackFactory = RemoteBmsFeignFallbackFactory.class, configuration = FeignAutoConfiguration.class)
@FeignClient(contextId = "BmsService", value = ServiceNameConstants.BMS_SERVICE, url = "http://10.33.0.109:8019",fallbackFactory = RemoteBmsFeignFallbackFactory.class, configuration = FeignAutoConfiguration.class)
public interface BmsServiceFeign {
@@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@FeignClient(contextId = "OmsService", value = ServiceNameConstants.OMS_SERVICE,url = "http://10.102.192.33:8017", fallbackFactory = RemoteOmsFeignFallbackFactory.class, configuration = FeignAutoConfiguration.class)
@FeignClient(contextId = "OmsService", value = ServiceNameConstants.OMS_SERVICE,url = "http://10.33.0.99:8017", fallbackFactory = RemoteOmsFeignFallbackFactory.class, configuration = FeignAutoConfiguration.class)
public interface OmsServiceFeign {
@@ -26,7 +26,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@FeignClient(contextId = "commonWlhyServiceFeign",value = ServiceNameConstants.WLHY_SERVICE,url = "http://10.102.192.31:8014",configuration = FeignAutoConfiguration.class)
@FeignClient(contextId = "commonWlhyServiceFeign",value = ServiceNameConstants.WLHY_SERVICE,url = "http://10.33.0.129:8014",configuration = FeignAutoConfiguration.class)
public interface WlhyServiceFeign {
/**
@@ -21,7 +21,7 @@ import java.util.Map;
* @description: TODO
* @date 2024/5/10 8:58
**/
@FeignClient(contextId = "remoteWmsServiceFeign",value = ServiceNameConstants.WMS_SERVICE, url = "http://10.102.192.32:8016", fallbackFactory = RemoteWmsFallbackFactory.class, configuration = FeignAutoConfiguration.class)
@FeignClient(contextId = "remoteWmsServiceFeign",value = ServiceNameConstants.WMS_SERVICE, url = "http://10.33.0.109:8016", fallbackFactory = RemoteWmsFallbackFactory.class, configuration = FeignAutoConfiguration.class)
public interface WmsServiceFeign {
/**
@@ -9,7 +9,7 @@ import com.mhd.system.api.feign.FeignAutoConfiguration;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
@FeignClient(contextId = "YmsService", value = ServiceNameConstants.YMS_SERVICE,fallbackFactory = RemoteBmsFeignFallbackFactory.class,url = "http://10.102.192.33:8018", configuration = FeignAutoConfiguration.class)
@FeignClient(contextId = "YmsService", value = ServiceNameConstants.YMS_SERVICE,fallbackFactory = RemoteBmsFeignFallbackFactory.class,url = "http://10.33.0.99:8018", configuration = FeignAutoConfiguration.class)
public interface YmsServiceFeign {
/**
@@ -67,6 +67,9 @@ public class MaterialBaseInfoAsyncService {
private MaterialBaseInfoDomainService materialBaseInfoDomainService;
@Autowired
private com.mhd.wms.domain.materialGoodsRule.service.MaterialGoodsRuleDomainService materialGoodsRuleDomainService;
@org.springframework.context.annotation.Lazy
@Autowired
private MaterialBaseInfoApplicationService materialBaseInfoApplicationService;
@Async
public void doImportData(File tmpFile, String fileName, LoginUser loginUser) {
@@ -122,16 +125,16 @@ public class MaterialBaseInfoAsyncService {
if (StringUtils.isBlank(row.getHsCode()) && StringUtils.isNotBlank(row.getHsCodeImport())) {
row.setHsCode(row.getHsCodeImport().trim());
}
normalizeImportBarCodeWhenDuplicateOfHs(row);
fillIdsFromExistingMasterData(row);
fillOrganizationFromShipperIfNeeded(row);
materialBaseInfoApplicationService.normalizeImportBarCodeWhenDuplicateOfHs(row);
materialBaseInfoApplicationService.fillIdsFromExistingMasterData(row);
materialBaseInfoApplicationService.fillOrganizationFromShipperIfNeeded(row);
if (!isValidOrgId(row.getOrganizationId()) && isValidOrgId(loginOrgId)) {
row.setOrganizationId(loginOrgId);
}
if (row.getTopOrganizationId() == null && isValidOrgId(loginTopOrgId)) {
row.setTopOrganizationId(loginTopOrgId);
}
fillOrganizationName(row, loginUser);
materialBaseInfoApplicationService.fillOrganizationName(row, loginUser);
String shipperCode = StringUtils.defaultString(row.getShipperCode(), "");
String duplicateKey = row.getOrganizationId() + "|" + shipperCode + "|" + row.getMaterialCode();
@@ -153,7 +156,7 @@ public class MaterialBaseInfoAsyncService {
errors.append("").append(rowNum).append("行:物料已存在;");
continue;
}
normalizeMaterialClassifyImportFields(row);
materialBaseInfoApplicationService.fillClassifyTypeAndUnit(row);
// 包装规格查询(带缓存)
String packCacheKey = row.getOrganizationId() + "|" + StringUtils.defaultString(row.getPackName());
@@ -193,42 +196,18 @@ public class MaterialBaseInfoAsyncService {
MaterialBaseInfoDO materialBaseInfoDO = new MaterialBaseInfoDO();
BeanUtils.copyProperties(row, materialBaseInfoDO);
materialBaseInfoDO.setMaterialGoodsRule(buildImportMaterialGoodsRule(row));
materialBaseInfoDO.setMaterialGoodsRule(materialBaseInfoApplicationService.buildImportMaterialGoodsRule(row));
materialBaseInfoDO.setMaterialCommon(null);
materialBaseInfoDO.setMaterialWarehouseControl(null);
materialBaseInfoDO.setMaterialBarCodeList(buildImportBarCodeList(row));
materialBaseInfoDO.setMaterialBarCodeList(materialBaseInfoApplicationService.buildImportBarCodeList(row));
// 补全创建人信息(异步线程没有 SecurityContext,用 loginUser
if (loginUser != null) {
materialBaseInfoDO.setCreateBy(loginUser.getUserid());
materialBaseInfoDO.setCreateByName(loginUser.getUsername());
}
materialBaseInfoDO.setCreateTime(new Date());
materialBaseInfoDO.setDelFlag(1);
// 通过 domainService 插入,获取自增 ID
Long materialBaseInfoId = materialBaseInfoDomainService.insert(materialBaseInfoDO);
materialBaseInfoDO.setMaterialBaseInfoId(materialBaseInfoId);
// 商品规则
com.mhd.wms.domain.materialGoodsRule.repository.todo.MaterialGoodsRuleDO goodsRule = materialBaseInfoDO.getMaterialGoodsRule();
if (goodsRule != null) {
goodsRule.setMaterialBaseInfoId(materialBaseInfoId);
materialGoodsRuleDomainService.insert(goodsRule);
}
// 公共信息
MaterialCommonDO materialCommonDO = materialBaseInfoDO.getMaterialCommon();
if (materialCommonDO != null) {
materialCommonDO.setMaterialBaseInfoId(materialBaseInfoId);
materialCommonDomainService.insert(materialCommonDO);
}
// 仓库控制信息
MaterialWarehouseControlDO materialWarehouseControlDO = materialBaseInfoDO.getMaterialWarehouseControl();
if (materialWarehouseControlDO != null) {
materialWarehouseControlDO.setMaterialBaseInfoId(materialBaseInfoId);
materialWarehouseControlDomainService.insert(materialWarehouseControlDO);
}
// 库存预警
materialInventoryWarningDomainService.batchInsertOrUpdate(materialBaseInfoDO);
// 条码信息
materialBarCodeDomainService.batchInsertOrUpdate(materialBaseInfoDO);
// 调用原 ApplicationService 的 insert,走完整的插入逻辑(含商品规则、公共信息、NC编码等)
materialBaseInfoApplicationService.insert(materialBaseInfoDO);
successCount++;
} catch (Exception e) {
log.error("物料主数据异步导入 - 第{}行处理异常", rowNum, e);
@@ -255,141 +234,7 @@ public class MaterialBaseInfoAsyncService {
}
}
// ====== 以下方法从 MaterialBaseInfoApplicationService 复制,避免循环依赖 ======
private void normalizeImportBarCodeWhenDuplicateOfHs(MaterialBaseInfoDTO row) {
if (row == null || StringUtils.isBlank(row.getBarCode())) {
return;
}
String hsCode = StringUtils.trimToEmpty(row.getHsCode());
if (hsCode.isEmpty()) {
return;
}
if (row.getBarCode().trim().equals(hsCode)) {
row.setBarCode(null);
}
}
private void fillIdsFromExistingMasterData(MaterialBaseInfoDTO row) {
if (StringUtils.isBlank(row.getPackName()) && StringUtils.isNotBlank(row.getPackImport())) {
row.setPackName(row.getPackImport().trim());
}
if (row.getShipperId() == null && (StringUtils.isNotBlank(row.getShipperCode()) || StringUtils.isNotBlank(row.getShipperName()))) {
MaterialBaseInfo matched = findExistingMaterialByShipper(row);
if (matched != null) {
row.setShipperId(matched.getShipperId());
if (StringUtils.isBlank(row.getShipperCode())) {
row.setShipperCode(matched.getShipperCode());
}
if (StringUtils.isBlank(row.getShipperName())) {
row.setShipperName(matched.getShipperName());
}
}
}
if (row.getShipperId() == null) {
fillShipperIdFromUserCenterForImport(row);
}
if (row.getPackId() == null && (StringUtils.isNotBlank(row.getPackCode()) || StringUtils.isNotBlank(row.getPackName()))) {
Long packId = queryPackIdByCodeOrName(row.getPackCode(), row.getPackName(), row.getOrganizationId());
if (packId != null) {
row.setPackId(packId);
}
}
}
private MaterialBaseInfo findExistingMaterialByShipper(MaterialBaseInfoDTO row) {
LambdaQueryWrapper<MaterialBaseInfo> wrapper = new LambdaQueryWrapper<MaterialBaseInfo>()
.eq(MaterialBaseInfo::getDelFlag, 1)
.eq(MaterialBaseInfo::getOrganizationId, row.getOrganizationId());
if (StringUtils.isNotBlank(row.getShipperCode())) {
wrapper.eq(MaterialBaseInfo::getShipperCode, row.getShipperCode());
}
wrapper.last("limit 1");
return materialBaseInfoService.getOne(wrapper, false);
}
private void fillShipperIdFromUserCenterForImport(MaterialBaseInfoDTO row) {
if (row.getShipperId() != null) {
return;
}
if (StringUtils.isBlank(row.getShipperName()) && StringUtils.isBlank(row.getShipperCode())) {
return;
}
try {
AjaxResult ajaxResult = userServiceFeign.getInfoByName(row.getShipperName());
if ("200".equals(String.valueOf(ajaxResult.get("code"))) && ajaxResult.get("data") != null) {
UserPo userPo = JSON.parseObject(JSONObject.toJSONString(ajaxResult.get("data")), UserPo.class);
if (userPo != null) {
row.setShipperId(userPo.getUserId());
}
}
} catch (Exception ignored) {
}
}
private void fillOrganizationFromShipperIfNeeded(MaterialBaseInfoDTO row) {
if (isValidOrgId(row.getOrganizationId()) || row.getShipperId() == null) {
return;
}
try {
AjaxResult infoRes = userServiceFeign.getInfo(row.getShipperId());
if ("200".equals(String.valueOf(infoRes.get("code"))) && infoRes.get("data") != null) {
UserPo userPo = JSON.parseObject(JSONObject.toJSONString(infoRes.get("data")), UserPo.class);
if (userPo != null) {
row.setShipperId(userPo.getUserId());
if (!isValidOrgId(row.getOrganizationId()) && isValidOrgId(userPo.getOrganizationId())) {
row.setOrganizationId(userPo.getOrganizationId());
}
if (row.getTopOrganizationId() == null && isValidOrgId(userPo.getTopOrganizationId())) {
row.setTopOrganizationId(userPo.getTopOrganizationId());
}
}
}
} catch (Exception ignored) {
}
}
private void fillOrganizationName(MaterialBaseInfoDTO row, LoginUser loginUser) {
if (StringUtils.isNotBlank(row.getOrganizationName())) {
return;
}
if (loginUser != null && loginUser.getUserPo() != null && StringUtils.isNotBlank(loginUser.getUserPo().getOrganizationName())) {
row.setOrganizationName(loginUser.getUserPo().getOrganizationName());
}
}
private void normalizeMaterialClassifyImportFields(MaterialBaseInfoDTO row) {
// 简化版:不做复杂分类查询,保持原值
}
private Long queryPackIdByCodeOrName(String packCode, String packName, Long organizationId) {
Object result = systemServiceFeign.getPackList(StringUtils.trimToNull(packCode), StringUtils.trimToNull(packName), organizationId);
if (result == null) {
return null;
}
Map<String, Object> resultMap = JSON.parseObject(JSONObject.toJSONString(result), new TypeReference<Map<String, Object>>() {});
List<Map<String, Object>> rows = extractTableDataRows(resultMap);
if (CollectionUtils.isEmpty(rows)) {
return null;
}
Map<String, Object> first = rows.get(0);
if (first == null) {
return null;
}
String packId = first.get("packId") == null ? "" : String.valueOf(first.get("packId"));
if (StringUtils.isBlank(packId) || !StringUtils.isNumeric(packId)) {
return null;
}
return Long.valueOf(packId);
}
private List<com.mhd.wms.domain.materialBarCode.repository.todo.MaterialBarCodeDO> buildImportBarCodeList(MaterialBaseInfoDTO row) {
return Collections.emptyList();
}
private com.mhd.wms.domain.materialGoodsRule.repository.todo.MaterialGoodsRuleDO buildImportMaterialGoodsRule(MaterialBaseInfoDTO row) {
return null;
}
// ====== 以下工具方法 ======
private List<Map<String, Object>> extractTableDataRows(Map<String, Object> resultMap) {
if (resultMap == null) {
+8 -8
View File
@@ -14,20 +14,20 @@ spring:
nacos:
discovery:
# server-addr: 127.0.0.1:8848
# server-addr: 10.33.0.129:6010
server-addr: 10.33.0.129:6010
# 线上测试环境配置 容器名+端口号
server-addr: 10.102.192.31:6848
username: nacos
password: manhuoda@2023
# server-addr: 10.102.192.31:6848
# username: nacos
# password: manhuoda@2023
#线上正式环境
# server-addr: 10.102.192.105:6848
config:
# server-addr: 127.0.0.1:8848
# server-addr: 10.33.0.129:6010
server-addr: 10.33.0.129:6010
# 线上测试环境配置 容器名+端口号
server-addr: 10.102.192.31:6848
username: nacos
password: manhuoda@2023
# server-addr: 10.102.192.31:6848
# username: nacos
# password: manhuoda@2023
#线上正式环境
# server-addr: 10.102.192.105:6848
# 配置文件格式