BUG712,组织机构物料信息功能中,扩展物料编码的属性查询条件支持

This commit is contained in:
yangchaojin
2026-01-20 17:32:13 +08:00
parent b597920d55
commit a5f972db14

View File

@@ -6,6 +6,7 @@ import com.zt.plat.module.base.dal.dao.materialhasproperties.MaterialHasProperti
import com.zt.plat.module.base.dal.dao.materialproperties.MaterialPropertiesMapper; import com.zt.plat.module.base.dal.dao.materialproperties.MaterialPropertiesMapper;
import com.zt.plat.module.base.dal.dataobject.materialhasproperties.MaterialHasPropertiesDO; import com.zt.plat.module.base.dal.dataobject.materialhasproperties.MaterialHasPropertiesDO;
import com.zt.plat.module.base.dal.dataobject.materialproperties.MaterialPropertiesDO; import com.zt.plat.module.base.dal.dataobject.materialproperties.MaterialPropertiesDO;
import com.zt.plat.module.base.service.masterdatasync.support.MasterDataPropertyDefinition;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@@ -13,6 +14,7 @@ import org.springframework.validation.annotation.Validated;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.zt.plat.framework.common.pojo.PageResult; import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.util.collection.CollectionUtils; import com.zt.plat.framework.common.util.collection.CollectionUtils;
@@ -122,7 +124,7 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
@Override @Override
public List<DepartmentMaterialRespVO> getDepartmentMaterialByIds(List<Long> ids) { public List<DepartmentMaterialRespVO> getDepartmentMaterialByIds(List<Long> ids) {
List<DepartmentMaterialDO> data = departmentMaterialMapper.selectByIds(ids); List<DepartmentMaterialDO> data = departmentMaterialMapper.selectByIds(ids);
if (org.apache.commons.collections4.CollectionUtils.isEmpty( data)) { if (org.apache.commons.collections4.CollectionUtils.isEmpty(data)) {
return null; return null;
} }
return decorateDepartmentMaterials(data); return decorateDepartmentMaterials(data);
@@ -144,8 +146,22 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
pageReqVO.setInfomationIds(matchedInfoIds); pageReqVO.setInfomationIds(matchedInfoIds);
} }
// 如果搜索物料编码,需要同时搜索中铜编码和中铝编码(作为物料属性存储)
if (StrUtil.isNotBlank(pageReqVO.getMaterialNumber())) {
// 优化:将分类筛选结果传入,在数据库层面就完成筛选,减少数据传输
List<Long> codeMatchedIds = queryMaterialIdsByAttribute(pageReqVO.getMaterialNumber(), null);
if (!CollUtil.isEmpty(codeMatchedIds)) {
// 合并编码集合条件并去重
List<Long> ids = Stream
.concat(pageReqVO.getInfomationIds().stream(), codeMatchedIds.stream())
.distinct()
.toList();
pageReqVO.setInfomationIds(ids);
}
}
// 判断部门是否是公司,非公司的部门需要显示所属公司下的所有物料信息 // 判断部门是否是公司,非公司的部门需要显示所属公司下的所有物料信息
if(pageReqVO.getIsCompany() != null && !pageReqVO.getIsCompany()) { if (pageReqVO.getIsCompany() != null && !pageReqVO.getIsCompany()) {
List<DeptRespDTO> deptList = (deptApi.upFindCompanyNode(pageReqVO.getDeptId())).getData(); List<DeptRespDTO> deptList = (deptApi.upFindCompanyNode(pageReqVO.getDeptId())).getData();
if (!CollUtil.isEmpty(deptList)) { if (!CollUtil.isEmpty(deptList)) {
pageReqVO.setDeptIds(deptList.stream().map(DeptRespDTO::getId).toList()); // 设置部门查询范围 pageReqVO.setDeptIds(deptList.stream().map(DeptRespDTO::getId).toList()); // 设置部门查询范围
@@ -373,4 +389,66 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
return attributes; return attributes;
} }
} }
/**
* 获取中铜编码和中铝编码的属性ID使用本地缓存避免重复查询
*/
private static volatile List<Long> cachedCodePropertyIds = null;
private List<Long> getCachedCodePropertyIds() {
if (cachedCodePropertyIds == null) {
synchronized (DepartmentMaterialServiceImpl.class) {
if (cachedCodePropertyIds == null) {
List<MaterialPropertiesDO> properties = materialPropertiesMapper.selectList(
new LambdaQueryWrapperX<MaterialPropertiesDO>()
.in(MaterialPropertiesDO::getCode, Arrays.asList(
MasterDataPropertyDefinition.CHALCO_CODE.getCode(),
MasterDataPropertyDefinition.ZHONGTONG_CODE.getCode()))
);
if (CollUtil.isNotEmpty(properties)) {
cachedCodePropertyIds = properties.stream()
.map(MaterialPropertiesDO::getId)
.filter(Objects::nonNull)
.collect(Collectors.toList());
} else {
cachedCodePropertyIds = Collections.emptyList();
}
}
}
}
return cachedCodePropertyIds;
}
/**
* 根据物料编码或属性编码中铜编码、中铝编码查询物料ID列表
* 优化版本:减少数据库查询次数,提升性能
*
* @param code 编码关键字(支持模糊查询)
* @param classIdFilter 分类筛选的物料ID列表可为null
* @return 匹配的物料ID列表
*/
private List<Long> queryMaterialIdsByAttribute(String code, List<Long> classIdFilter) {
Set<Long> materialIds = new HashSet<>();
// 2. 查询中铜编码和中铝编码属性使用缓存的属性ID
List<Long> propertyIds = getCachedCodePropertyIds();
if (CollUtil.isNotEmpty(propertyIds)) {
// 查询属性值表中匹配的物料
List<MaterialHasPropertiesDO> hasProperties = materialHasPropertiesMapper.selectList(
new LambdaQueryWrapperX<MaterialHasPropertiesDO>()
.in(MaterialHasPropertiesDO::getPropertiesId, propertyIds)
.like(MaterialHasPropertiesDO::getValue, code)
.in(Objects.nonNull(classIdFilter), MaterialHasPropertiesDO::getInfomationId, classIdFilter)
);
if (CollUtil.isNotEmpty(hasProperties)) {
materialIds.addAll(hasProperties.stream()
.map(MaterialHasPropertiesDO::getInfomationId)
.filter(Objects::nonNull)
.collect(Collectors.toSet()));
}
}
return new ArrayList<>(materialIds);
}
} }