Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
潘荣晟
2026-01-20 17:56:02 +08: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.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;
@@ -69,7 +71,7 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
DepartmentMaterialDO departmentMaterial = BeanUtils.toBean(createReqVO, DepartmentMaterialDO.class); DepartmentMaterialDO departmentMaterial = BeanUtils.toBean(createReqVO, DepartmentMaterialDO.class);
departmentMaterialMapper.insert(departmentMaterial); departmentMaterialMapper.insert(departmentMaterial);
// 构造完整响应,方便前端直接刷新数据 // 构造完整响应,方便前端直接刷新数据
return CollUtil.getFirst(decorateDepartmentMaterials(Collections.singletonList(departmentMaterial))); return CollUtil.getFirst(decorateDepartmentMaterials(Collections.singletonList(departmentMaterial)));
} }
@Override @Override
@@ -90,12 +92,12 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
} }
@Override @Override
public void deleteDepartmentMaterialListByIds(List<Long> ids) { public void deleteDepartmentMaterialListByIds(List<Long> ids) {
// 校验存在 // 校验存在
validateDepartmentMaterialExists(ids); validateDepartmentMaterialExists(ids);
// 删除 // 删除
departmentMaterialMapper.deleteByIds(ids); departmentMaterialMapper.deleteByIds(ids);
} }
private void validateDepartmentMaterialExists(List<Long> ids) { private void validateDepartmentMaterialExists(List<Long> ids) {
List<DepartmentMaterialDO> list = departmentMaterialMapper.selectByIds(ids); List<DepartmentMaterialDO> list = departmentMaterialMapper.selectByIds(ids);
@@ -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()); // 设置部门查询范围
@@ -178,8 +194,8 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
Map<Long, MaterialInfomationDO> infoMap = infoIds.isEmpty() Map<Long, MaterialInfomationDO> infoMap = infoIds.isEmpty()
? Collections.emptyMap() ? Collections.emptyMap()
: materialInfomationMapper.selectBatchIds(infoIds).stream() : materialInfomationMapper.selectBatchIds(infoIds).stream()
.filter(Objects::nonNull) .filter(Objects::nonNull)
.collect(Collectors.toMap(MaterialInfomationDO::getId, Function.identity())); .collect(Collectors.toMap(MaterialInfomationDO::getId, Function.identity()));
Set<Long> classIds = new HashSet<>(); Set<Long> classIds = new HashSet<>();
sourceList.forEach(item -> { sourceList.forEach(item -> {
@@ -215,8 +231,8 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
Map<String, BusinessDictionaryDataDO> dictionaryMap = dictionaryValues.isEmpty() Map<String, BusinessDictionaryDataDO> dictionaryMap = dictionaryValues.isEmpty()
? Collections.emptyMap() ? Collections.emptyMap()
: businessDictionaryDataMapper.selectListByValues(dictionaryValues).stream() : businessDictionaryDataMapper.selectListByValues(dictionaryValues).stream()
.filter(Objects::nonNull) .filter(Objects::nonNull)
.collect(Collectors.toMap(BusinessDictionaryDataDO::getValue, Function.identity(), (exist, replace) -> exist)); .collect(Collectors.toMap(BusinessDictionaryDataDO::getValue, Function.identity(), (exist, replace) -> exist));
List<DepartmentMaterialRespVO> respList = new ArrayList<>(sourceList.size()); List<DepartmentMaterialRespVO> respList = new ArrayList<>(sourceList.size());
for (DepartmentMaterialDO item : sourceList) { for (DepartmentMaterialDO item : sourceList) {
@@ -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);
}
} }