|
|
|
|
@ -30,6 +30,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.time.LocalTime;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
@ -56,12 +58,20 @@ public class QmsInspectionItemServiceImpl extends ServiceImpl<QmsInspectionItemM
|
|
|
|
|
String operator = UserUtil.getUserName();
|
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
|
|
|
|
|
// 根据物料类别ID生成编号和名称
|
|
|
|
|
QmsQcMaterialCategory category = materialCategoryService.getById(qo.getMaterialTypeId());
|
|
|
|
|
if (category == null) {
|
|
|
|
|
throw new NflgException(STATE.BusinessError, "物料类别不存在");
|
|
|
|
|
}
|
|
|
|
|
String inspectionNo = "CATD_" + category.getCategoryCode();
|
|
|
|
|
String inspectionItemName = buildCategoryFullPath(qo.getMaterialTypeId());
|
|
|
|
|
|
|
|
|
|
// 保存主表
|
|
|
|
|
QmsInspectionItem item = new QmsInspectionItem()
|
|
|
|
|
.setMaterialTypeId(qo.getMaterialTypeId())
|
|
|
|
|
.setDetectionType(qo.getDetectionType())
|
|
|
|
|
.setInspectionItemName(qo.getInspectionItemName())
|
|
|
|
|
.setInspectionNo(qo.getInspectionNo())
|
|
|
|
|
.setInspectionItemName(inspectionItemName)
|
|
|
|
|
.setInspectionNo(inspectionNo)
|
|
|
|
|
.setCreateBy(operator)
|
|
|
|
|
.setCreateTime(now)
|
|
|
|
|
.setUpdateBy(operator)
|
|
|
|
|
@ -162,8 +172,15 @@ public class QmsInspectionItemServiceImpl extends ServiceImpl<QmsInspectionItemM
|
|
|
|
|
throw new NflgException(STATE.BusinessError, "开始时间不能晚于结束时间");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果传了物料类别,收集该类别及所有子孙类别ID
|
|
|
|
|
List<Long> categoryIds = null;
|
|
|
|
|
if (Objects.nonNull(qo.getMaterialTypeId())) {
|
|
|
|
|
categoryIds = collectDescendantIds(qo.getMaterialTypeId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Long> finalCategoryIds = categoryIds;
|
|
|
|
|
IPage<QmsInspectionItem> page = lambdaQuery()
|
|
|
|
|
.eq(Objects.nonNull(qo.getMaterialTypeId()), QmsInspectionItem::getMaterialTypeId, qo.getMaterialTypeId())
|
|
|
|
|
.in(finalCategoryIds != null && !finalCategoryIds.isEmpty(), QmsInspectionItem::getMaterialTypeId, finalCategoryIds)
|
|
|
|
|
.like(StrUtil.isNotBlank(qo.getInspectionItemName()), QmsInspectionItem::getInspectionItemName, qo.getInspectionItemName())
|
|
|
|
|
.ge(Objects.nonNull(start), QmsInspectionItem::getCreateTime, Objects.nonNull(start) ? start.atStartOfDay() : null)
|
|
|
|
|
.le(Objects.nonNull(end), QmsInspectionItem::getCreateTime, Objects.nonNull(end) ? end.atTime(LocalTime.MAX) : null)
|
|
|
|
|
@ -327,4 +344,47 @@ public class QmsInspectionItemServiceImpl extends ServiceImpl<QmsInspectionItemM
|
|
|
|
|
vo.setDeterminationType(d.getDeterminationType());
|
|
|
|
|
return vo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构建物料类别全路径名称(如:采购物料/原材料/板材/普通钢板)
|
|
|
|
|
*/
|
|
|
|
|
private String buildCategoryFullPath(Long categoryId) {
|
|
|
|
|
List<String> names = new ArrayList<>();
|
|
|
|
|
Long currentId = categoryId;
|
|
|
|
|
while (currentId != null) {
|
|
|
|
|
QmsQcMaterialCategory cat = materialCategoryService.getById(currentId);
|
|
|
|
|
if (cat == null) break;
|
|
|
|
|
names.add(cat.getCategoryName());
|
|
|
|
|
currentId = cat.getParentCategoryRowId();
|
|
|
|
|
}
|
|
|
|
|
Collections.reverse(names);
|
|
|
|
|
return String.join("/", names);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 收集指定类别及其所有子孙类别的ID集合
|
|
|
|
|
*/
|
|
|
|
|
private List<Long> collectDescendantIds(Long categoryId) {
|
|
|
|
|
List<QmsQcMaterialCategory> all = materialCategoryService.list();
|
|
|
|
|
// 构建 parentId -> children 映射
|
|
|
|
|
Map<Long, List<QmsQcMaterialCategory>> childrenMap = all.stream()
|
|
|
|
|
.filter(c -> c.getParentCategoryRowId() != null && c.getParentCategoryRowId() > 0)
|
|
|
|
|
.collect(Collectors.groupingBy(QmsQcMaterialCategory::getParentCategoryRowId));
|
|
|
|
|
|
|
|
|
|
List<Long> result = new ArrayList<>();
|
|
|
|
|
// BFS 收集所有后代
|
|
|
|
|
java.util.Deque<Long> queue = new java.util.ArrayDeque<>();
|
|
|
|
|
queue.add(categoryId);
|
|
|
|
|
while (!queue.isEmpty()) {
|
|
|
|
|
Long current = queue.poll();
|
|
|
|
|
result.add(current);
|
|
|
|
|
List<QmsQcMaterialCategory> children = childrenMap.get(current);
|
|
|
|
|
if (children != null) {
|
|
|
|
|
for (QmsQcMaterialCategory child : children) {
|
|
|
|
|
queue.add(child.getId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|