物料导入分类问题解决
This commit is contained in:
+177
-1
@@ -4,12 +4,14 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.mhd.common.core.domain.po.UserPo;
|
||||
import com.mhd.common.core.exception.ServiceException;
|
||||
import com.mhd.common.core.enums.DictCode;
|
||||
import com.mhd.common.core.utils.poi.ExcelUtil;
|
||||
import com.mhd.common.core.web.domain.AjaxResult;
|
||||
import com.mhd.common.security.utils.SecurityUtils;
|
||||
import com.mhd.system.api.SystemServiceFeign;
|
||||
import com.mhd.system.api.UserServiceFeign;
|
||||
import com.mhd.system.api.domain.BatchFeignPO;
|
||||
import com.mhd.system.api.domain.PackDetailFeignPO;
|
||||
import com.mhd.system.api.domain.SysDictData;
|
||||
@@ -83,6 +85,8 @@ public class MaterialBaseInfoApplicationService {
|
||||
@Autowired
|
||||
private SystemServiceFeign systemServiceFeign;
|
||||
@Autowired
|
||||
private UserServiceFeign userServiceFeign;
|
||||
@Autowired
|
||||
private IMaterialBaseInfoService materialBaseInfoService;
|
||||
|
||||
/**
|
||||
@@ -483,7 +487,7 @@ public class MaterialBaseInfoApplicationService {
|
||||
if (StringUtils.isBlank(row.getPackName()) && StringUtils.isNotBlank(row.getPackImport())) {
|
||||
row.setPackName(row.getPackImport().trim());
|
||||
}
|
||||
// 货主
|
||||
// 货主:先按本组织已有物料反查,再用用户中心按「货主编码/货主名称」解析 userId(与入库单 import 一致;纯数字也可作名称,例如「1449」)
|
||||
if (row.getShipperId() == null && (StringUtils.isNotBlank(row.getShipperCode()) || StringUtils.isNotBlank(row.getShipperName()))) {
|
||||
MaterialBaseInfo matched = materialBaseInfoService.getOne(new LambdaQueryWrapper<MaterialBaseInfo>()
|
||||
.eq(MaterialBaseInfo::getDelFlag, 1)
|
||||
@@ -510,6 +514,10 @@ public class MaterialBaseInfoApplicationService {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (row.getShipperId() == null) {
|
||||
fillShipperIdFromUserCenterForImport(row);
|
||||
}
|
||||
enrichShipperCodeNameFromExistingMaterialIfNeeded(row);
|
||||
// 包装规格
|
||||
if (row.getPackId() == null && (StringUtils.isNotBlank(row.getPackCode()) || StringUtils.isNotBlank(row.getPackName()))) {
|
||||
Long packId = queryPackIdByCodeOrName(row.getPackCode(), row.getPackName(), row.getOrganizationId());
|
||||
@@ -570,6 +578,174 @@ public class MaterialBaseInfoApplicationService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入时按货主名称/编号从用户中心解析货主ID(与 {@link com.mhd.wms.application.service.stockInOrder.StockInOrderApplicationService#getShipperIdByNameOrCode} 一致)。
|
||||
* 不将纯数字的「货主名称」当作用户ID或主键,避免与业务上以数字作为企业简称/名称的货主(如「1449」)冲突。
|
||||
*/
|
||||
private void fillShipperIdFromUserCenterForImport(MaterialBaseInfoDTO row) {
|
||||
if (row.getShipperId() != null) {
|
||||
return;
|
||||
}
|
||||
if (StringUtils.isBlank(row.getShipperName()) && StringUtils.isBlank(row.getShipperCode())) {
|
||||
return;
|
||||
}
|
||||
Long importOrgId = row.getOrganizationId();
|
||||
String shipperName = StringUtils.isNotBlank(row.getShipperName()) ? row.getShipperName().trim() : null;
|
||||
String shipperCode = StringUtils.isNotBlank(row.getShipperCode()) ? row.getShipperCode().trim() : null;
|
||||
|
||||
if (StringUtils.isNotBlank(shipperName)) {
|
||||
try {
|
||||
AjaxResult ajaxResult = userServiceFeign.getInfoByName(shipperName);
|
||||
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 && shipperUserMatchesImportOrganization(userPo, importOrgId)) {
|
||||
applyUserPoToMaterialImportRow(row, userPo);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.debug("物料导入: getInfoByName 货主失败: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
AjaxResult shipperListResult = userServiceFeign.userShipperListAll();
|
||||
if (!"200".equals(String.valueOf(shipperListResult.get("code"))) || shipperListResult.get("data") == null) {
|
||||
return;
|
||||
}
|
||||
Object data = shipperListResult.get("data");
|
||||
List<Map<String, Object>> shipperList;
|
||||
if (data instanceof List) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> rawList = (List<Object>) data;
|
||||
shipperList = new ArrayList<>();
|
||||
for (Object item : rawList) {
|
||||
if (item instanceof Map) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> mapItem = (Map<String, Object>) item;
|
||||
shipperList.add(mapItem);
|
||||
} else {
|
||||
Map<String, Object> mapItem = JSON.parseObject(JSONObject.toJSONString(item), new TypeReference<Map<String, Object>>() { });
|
||||
shipperList.add(mapItem);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
shipperList = JSON.parseObject(JSONObject.toJSONString(data), new TypeReference<List<Map<String, Object>>>() { });
|
||||
}
|
||||
if (shipperList == null || shipperList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (Map<String, Object> shipper : shipperList) {
|
||||
if (shipper == null) {
|
||||
continue;
|
||||
}
|
||||
Object userId = shipper.get("userId");
|
||||
Object userName = shipper.get("userName");
|
||||
Object userCode = shipper.get("userCode");
|
||||
Object userMemberCode = shipper.get("userMemberCode");
|
||||
Object entName = shipper.get("shipperEnterpriseName");
|
||||
if (userName == null) {
|
||||
userName = shipper.get("name");
|
||||
}
|
||||
if (userName == null) {
|
||||
userName = shipper.get("shipperName");
|
||||
}
|
||||
String normalizedName = StringUtils.isNotBlank(shipperName) ? shipperName : "";
|
||||
String normalizedCode = StringUtils.isNotBlank(shipperCode) ? shipperCode : "";
|
||||
boolean matched = false;
|
||||
if (StringUtils.isNotEmpty(normalizedCode)) {
|
||||
String c1 = userCode != null ? String.valueOf(userCode).trim() : "";
|
||||
String c2 = userMemberCode != null ? String.valueOf(userMemberCode).trim() : "";
|
||||
if (normalizedCode.equals(c1) || normalizedCode.equals(c2)) {
|
||||
matched = true;
|
||||
}
|
||||
}
|
||||
if (!matched && StringUtils.isNotEmpty(normalizedName)) {
|
||||
for (Object cand : new Object[] { userName, entName }) {
|
||||
if (cand == null) {
|
||||
continue;
|
||||
}
|
||||
String s = String.valueOf(cand).trim();
|
||||
if (normalizedName.equals(s) || s.contains(normalizedName)) {
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (matched && userId != null) {
|
||||
try {
|
||||
Long candidateId = Long.valueOf(String.valueOf(userId));
|
||||
AjaxResult infoRes = userServiceFeign.getInfo(candidateId);
|
||||
if (!"200".equals(String.valueOf(infoRes.get("code"))) || infoRes.get("data") == null) {
|
||||
continue;
|
||||
}
|
||||
UserPo up = JSON.parseObject(JSONObject.toJSONString(infoRes.get("data")), UserPo.class);
|
||||
if (shipperUserMatchesImportOrganization(up, importOrgId)) {
|
||||
applyUserPoToMaterialImportRow(row, up);
|
||||
return;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.debug("物料导入: 从货主列表解析用户失败: {}", ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.debug("物料导入: userShipperListAll 失败: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void applyUserPoToMaterialImportRow(MaterialBaseInfoDTO row, UserPo userPo) {
|
||||
if (userPo == null) {
|
||||
return;
|
||||
}
|
||||
row.setShipperId(userPo.getUserId());
|
||||
if (StringUtils.isBlank(row.getShipperCode()) && StringUtils.isNotBlank(userPo.getUserMemberCode())) {
|
||||
row.setShipperCode(userPo.getUserMemberCode());
|
||||
}
|
||||
if (StringUtils.isBlank(row.getShipperName()) && StringUtils.isNotBlank(userPo.getUserName())) {
|
||||
row.setShipperName(userPo.getUserName());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shipperUserMatchesImportOrganization(UserPo userPo, Long importOrganizationId) {
|
||||
if (importOrganizationId == null) {
|
||||
return true;
|
||||
}
|
||||
if (userPo == null) {
|
||||
return false;
|
||||
}
|
||||
Long oid = userPo.getOrganizationId();
|
||||
return oid != null && importOrganizationId.equals(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 已有 shipper_id 时,从本组织任意一条带全量货主信息的物料主数据仅补全仍为空的货主编码/名称。
|
||||
*/
|
||||
private void enrichShipperCodeNameFromExistingMaterialIfNeeded(MaterialBaseInfoDTO row) {
|
||||
if (row.getShipperId() == null || row.getOrganizationId() == null) {
|
||||
return;
|
||||
}
|
||||
if (StringUtils.isNotBlank(row.getShipperCode()) && StringUtils.isNotBlank(row.getShipperName())) {
|
||||
return;
|
||||
}
|
||||
MaterialBaseInfo matched = materialBaseInfoService.getOne(new LambdaQueryWrapper<MaterialBaseInfo>()
|
||||
.eq(MaterialBaseInfo::getDelFlag, 1)
|
||||
.eq(MaterialBaseInfo::getOrganizationId, row.getOrganizationId())
|
||||
.eq(MaterialBaseInfo::getShipperId, row.getShipperId())
|
||||
.isNotNull(MaterialBaseInfo::getShipperName)
|
||||
.orderByDesc(MaterialBaseInfo::getMaterialBaseInfoId)
|
||||
.last("limit 1"));
|
||||
if (matched == null) {
|
||||
return;
|
||||
}
|
||||
if (StringUtils.isBlank(row.getShipperCode()) && StringUtils.isNotBlank(matched.getShipperCode())) {
|
||||
row.setShipperCode(matched.getShipperCode());
|
||||
}
|
||||
if (StringUtils.isBlank(row.getShipperName()) && StringUtils.isNotBlank(matched.getShipperName())) {
|
||||
row.setShipperName(matched.getShipperName());
|
||||
}
|
||||
}
|
||||
|
||||
private void fillOrganizationName(MaterialBaseInfoDTO row, LoginUser loginUser) {
|
||||
if (StringUtils.isNotBlank(row.getOrganizationName())) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user