Merge branch 'dev' into 'test'

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

See merge request jygk/dsc-base!26
This commit is contained in:
朝锦 杨
2026-01-20 09:36:41 +00:00

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.dataobject.materialhasproperties.MaterialHasPropertiesDO;
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 org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@@ -13,6 +14,7 @@ import org.springframework.validation.annotation.Validated;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.util.collection.CollectionUtils;
@@ -69,7 +71,7 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
DepartmentMaterialDO departmentMaterial = BeanUtils.toBean(createReqVO, DepartmentMaterialDO.class);
departmentMaterialMapper.insert(departmentMaterial);
// 构造完整响应,方便前端直接刷新数据
return CollUtil.getFirst(decorateDepartmentMaterials(Collections.singletonList(departmentMaterial)));
return CollUtil.getFirst(decorateDepartmentMaterials(Collections.singletonList(departmentMaterial)));
}
@Override
@@ -90,12 +92,12 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
}
@Override
public void deleteDepartmentMaterialListByIds(List<Long> ids) {
public void deleteDepartmentMaterialListByIds(List<Long> ids) {
// 校验存在
validateDepartmentMaterialExists(ids);
// 删除
departmentMaterialMapper.deleteByIds(ids);
}
}
private void validateDepartmentMaterialExists(List<Long> ids) {
List<DepartmentMaterialDO> list = departmentMaterialMapper.selectByIds(ids);
@@ -122,7 +124,7 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
@Override
public List<DepartmentMaterialRespVO> getDepartmentMaterialByIds(List<Long> 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 decorateDepartmentMaterials(data);
@@ -144,8 +146,22 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
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();
if (!CollUtil.isEmpty(deptList)) {
pageReqVO.setDeptIds(deptList.stream().map(DeptRespDTO::getId).toList()); // 设置部门查询范围
@@ -178,8 +194,8 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
Map<Long, MaterialInfomationDO> infoMap = infoIds.isEmpty()
? Collections.emptyMap()
: materialInfomationMapper.selectBatchIds(infoIds).stream()
.filter(Objects::nonNull)
.collect(Collectors.toMap(MaterialInfomationDO::getId, Function.identity()));
.filter(Objects::nonNull)
.collect(Collectors.toMap(MaterialInfomationDO::getId, Function.identity()));
Set<Long> classIds = new HashSet<>();
sourceList.forEach(item -> {
@@ -215,8 +231,8 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
Map<String, BusinessDictionaryDataDO> dictionaryMap = dictionaryValues.isEmpty()
? Collections.emptyMap()
: businessDictionaryDataMapper.selectListByValues(dictionaryValues).stream()
.filter(Objects::nonNull)
.collect(Collectors.toMap(BusinessDictionaryDataDO::getValue, Function.identity(), (exist, replace) -> exist));
.filter(Objects::nonNull)
.collect(Collectors.toMap(BusinessDictionaryDataDO::getValue, Function.identity(), (exist, replace) -> exist));
List<DepartmentMaterialRespVO> respList = new ArrayList<>(sourceList.size());
for (DepartmentMaterialDO item : sourceList) {
@@ -373,4 +389,66 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
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);
}
}