Merge remote-tracking branch '惠信/qms/develop' into qms/develop

This commit is contained in:
曹鹏飞 2026-05-07 08:31:12 +08:00
commit 59bbb396c3
3 changed files with 67 additions and 9 deletions

View File

@ -88,7 +88,7 @@ public class QmsPdiTaskRecordController extends BaseController {
*/
@GetMapping("summary")
public ApiResult<QmsPdiTaskRecordSummaryVO> summary(
@NotNull(message = "任务ID不能为空") @RequestParam Long taskId) {
return ApiResult.success(taskRecordControllerService.summary(taskId));
@NotNull(message = "任务ID不能为空") @RequestParam Long id) {
return ApiResult.success(taskRecordControllerService.summary(id));
}
}

View File

@ -27,15 +27,13 @@ public class QmsInspectionItemAddQO {
private Integer detectionType;
/**
* 检测项名称必传
* 检测项名称后端根据物料类别全路径自动生成无需传入
*/
@NotBlank(message = "检测项名称不能为空")
private String inspectionItemName;
/**
* 检测项编号必传
* 检测项编号后端自动生成CATD_ + 类别码无需传入
*/
@NotBlank(message = "检测项编号不能为空")
private String inspectionNo;
/**

View File

@ -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;
}
}