修复BUG712,组织物料信息查询范围调整

This commit is contained in:
yangchaojin
2026-01-20 09:23:25 +08:00
parent 5f14fe798d
commit b597920d55
6 changed files with 123 additions and 1 deletions

View File

@@ -45,4 +45,9 @@ public class DepartmentMaterialPageReqVO extends PageParam {
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
@Schema(description = "是否是公司")
private Boolean isCompany;
@Schema(description = "部门ID集合(内部使用)")
private List<Long> deptIds;
}

View File

@@ -1,5 +1,7 @@
package com.zt.plat.module.base.controller.admin.departmentmaterial.vo;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
@@ -77,4 +79,13 @@ public class DepartmentMaterialRespVO {
// base_material_status 系统字典取值
private String status;
@JsonIgnore
@Schema(description = "物料基础字段 + 属性编码->原值的动态键值,基础字段优先,序列化时直接展开为顶层字段")
private Map<String, Object> flatAttributes;
@JsonAnyGetter
public Map<String, Object> getFlatAttributes() {
return flatAttributes;
}
}

View File

@@ -23,6 +23,7 @@ public interface DepartmentMaterialMapper extends BaseMapperX<DepartmentMaterial
.inIfPresent(DepartmentMaterialDO::getInfomationId, reqVO.getInfomationIds())
.eqIfPresent(DepartmentMaterialDO::getClassesId, reqVO.getClassesId())
.eqIfPresent(DepartmentMaterialDO::getDeptId, reqVO.getDeptId())
.inIfPresent(DepartmentMaterialDO::getDeptId, reqVO.getDeptIds())
.eqIfPresent(DepartmentMaterialDO::getDictionaryDataValue, reqVO.getDictionaryDataValue())
.eqIfPresent(DepartmentMaterialDO::getStatus, reqVO.getStatus())
.eqIfPresent(DepartmentMaterialDO::getRemark, reqVO.getRemark())

View File

@@ -2,6 +2,10 @@ package com.zt.plat.module.base.service.departmentmaterial;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.zt.plat.module.base.dal.dao.materialhasproperties.MaterialHasPropertiesMapper;
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 jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@@ -50,6 +54,12 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
@Resource
private BusinessDictionaryDataMapper businessDictionaryDataMapper;
@Resource
private MaterialHasPropertiesMapper materialHasPropertiesMapper;
@Resource
private MaterialPropertiesMapper materialPropertiesMapper;
@Resource
private DeptApi deptApi;
@@ -106,7 +116,7 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
if (data == null) {
return null;
}
return CollUtil.getFirst(decorateDepartmentMaterials(Collections.singletonList(data)));
return CollUtil.getFirst(buildPropertyAggregates(decorateDepartmentMaterials(Collections.singletonList(data))));
}
@Override
@@ -134,6 +144,15 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
pageReqVO.setInfomationIds(matchedInfoIds);
}
// 判断部门是否是公司,非公司的部门需要显示所属公司下的所有物料信息
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()); // 设置部门查询范围
pageReqVO.setDeptId(null); // 置空部门编号
}
}
PageResult<DepartmentMaterialDO> pageResult = departmentMaterialMapper.selectPage(pageReqVO);
// 重置,避免后续使用该入参出现意外的 in 条件
pageReqVO.setInfomationIds(null);
@@ -283,4 +302,75 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
return path;
}
private List<DepartmentMaterialRespVO> buildPropertyAggregates(List<DepartmentMaterialRespVO> list) {
if (CollUtil.isEmpty(list)) {
return Collections.emptyList();
}
List<MaterialHasPropertiesDO> hasPropertiesList = materialHasPropertiesMapper.selectList(
new LambdaQueryWrapperX<MaterialHasPropertiesDO>().in(MaterialHasPropertiesDO::getInfomationId,
list.stream().map(DepartmentMaterialRespVO::getInfomationId).toList()));
if (CollUtil.isEmpty(hasPropertiesList)) {
return list;
}
Set<Long> propertiesIds = hasPropertiesList.stream()
.map(MaterialHasPropertiesDO::getPropertiesId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
Map<Long, MaterialPropertiesDO> propertiesMap = propertiesIds.isEmpty()
? Collections.emptyMap()
: materialPropertiesMapper.selectBatchIds(propertiesIds).stream()
.filter(Objects::nonNull)
.collect(Collectors.toMap(MaterialPropertiesDO::getId, Function.identity()));
Map<Long, List<MaterialHasPropertiesDO>> infoPropsMap = hasPropertiesList.stream()
.collect(Collectors.groupingBy(MaterialHasPropertiesDO::getInfomationId));
Map<Long, MaterialPropertiesAggregate> result = new HashMap<>();
for (Map.Entry<Long, List<MaterialHasPropertiesDO>> entry : infoPropsMap.entrySet()) {
Long infoId = entry.getKey();
List<MaterialHasPropertiesDO> props = entry.getValue();
// 按 sort 升序,保持 deterministic重复 code 时保留首条
props.sort(Comparator.comparing((MaterialHasPropertiesDO o) -> o.getSort() == null ? Long.MAX_VALUE : o.getSort())
.thenComparing(MaterialHasPropertiesDO::getPropertiesId, Comparator.nullsLast(Long::compareTo))
.thenComparing(MaterialHasPropertiesDO::getId, Comparator.nullsLast(Long::compareTo)));
Map<String, Object> flatMap = new LinkedHashMap<>();
for (MaterialHasPropertiesDO item : props) {
MaterialPropertiesDO property = propertiesMap.get(item.getPropertiesId());
String code = property != null ? property.getCode() : null;
if (StrUtil.isBlank(code)) {
continue;
}
if (flatMap.containsKey(code)) {
continue;
}
flatMap.put(code, item.getValue());
}
result.put(infoId, new MaterialPropertiesAggregate(flatMap));
}
return list.stream().peek(item -> {
Map<String, Object> flatMap = new LinkedHashMap<>();
MaterialPropertiesAggregate aggregate = result.get(item.getInfomationId());
if (aggregate != null && CollUtil.isNotEmpty(aggregate.getAttributes())) {
aggregate.getAttributes().forEach((k, v) -> {
// 基础字段优先,存在同名则跳过属性值
if (!flatMap.containsKey(k)) {
flatMap.put(k, v);
}
});
item.setFlatAttributes(flatMap);
}
}).collect(Collectors.toList());
}
private record MaterialPropertiesAggregate(Map<String, Object> attributes) {
public Map<String, Object> getAttributes() {
return attributes;
}
}
}