样式规范(QMS):统一控制器与服务格式化

- 优化QMS任务记录代码的导入顺序及换行符。
- 确保控制器与服务文件符合项目风格规范。
This commit is contained in:
yf001217 2026-05-28 15:23:40 +08:00
parent 0985594f6b
commit f5d3b2e766
3 changed files with 307 additions and 0 deletions

View File

@ -13,6 +13,8 @@ import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* PQC任务
*
@ -66,6 +68,14 @@ public class QmsPqcTaskRecordController {
return ApiResult.success(pqcTaskRecordService.getReviewDetail(taskId));
}
/**
* 查询PQC检查点进度
*/
@GetMapping("/point/progress")
public ApiResult<QmsPqcTaskRecordPointProgressVO> getPointProgress(@RequestParam Long taskId) {
return ApiResult.success(pqcTaskRecordService.getPointProgress(taskId));
}
/**
* 暂存
*/

View File

@ -610,6 +610,94 @@ public class QmsPqcTaskRecordControllerService {
return vo;
}
/**
* 查询PQC检查点进度
*/
public QmsPqcTaskRecordPointProgressVO getPointProgress(Long taskId) {
QmsPqcTaskRecord currentTask = pqcTaskRecordService.getById(taskId);
VUtil.trueThrowBusinessError(currentTask == null).throwMessage("任务不存在");
String no = currentTask.getNo();
String modelNo = currentTask.getModelNo();
QmsPqcInspectionRule latestRule = pqcInspectionRuleService.lambdaQuery()
.eq(QmsPqcInspectionRule::getModelNo, modelNo)
.eq(QmsPqcInspectionRule::getIsDisabled, true)
.orderByDesc(QmsPqcInspectionRule::getRuleVersion)
.last("LIMIT 1")
.one();
LinkedHashMap<String, StepProgressAccumulator> stepMap = new LinkedHashMap<>();
Integer latestRuleVersion = latestRule != null ? latestRule.getRuleVersion() : null;
if (latestRule != null) {
List<QmsPqcInspectionPoint> latestPoints = pqcInspectionPointService.lambdaQuery()
.eq(QmsPqcInspectionPoint::getPqcRuleId, latestRule.getId())
.orderByAsc(QmsPqcInspectionPoint::getStepDicItemId)
.orderByAsc(QmsPqcInspectionPoint::getId)
.list();
for (QmsPqcInspectionPoint point : latestPoints) {
StepProgressAccumulator stepAccumulator = stepMap.computeIfAbsent(buildStepKey(point),
k -> StepProgressAccumulator.fromPoint(point));
stepAccumulator.putIfAbsent(buildPointKey(point),
PointProgressAccumulator.fromLatestPoint(point, latestRuleVersion));
}
}
List<QmsPqcTaskRecord> taskRecords = pqcTaskRecordService.lambdaQuery()
.eq(QmsPqcTaskRecord::getNo, no)
.eq(QmsPqcTaskRecord::getModelNo, modelNo)
.isNotNull(QmsPqcTaskRecord::getInspectionPointId)
.orderByAsc(QmsPqcTaskRecord::getCreateTime)
.list();
if (!taskRecords.isEmpty()) {
Set<Long> pointIds = taskRecords.stream()
.map(QmsPqcTaskRecord::getInspectionPointId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
Map<Long, QmsPqcInspectionPoint> pointMap = new HashMap<>();
if (!pointIds.isEmpty()) {
pointMap = pqcInspectionPointService.listByIds(pointIds).stream()
.collect(Collectors.toMap(QmsPqcInspectionPoint::getId, point -> point));
}
Set<Long> ruleIds = pointMap.values().stream()
.map(QmsPqcInspectionPoint::getPqcRuleId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
Map<Long, Integer> ruleVersionMap = new HashMap<>();
if (!ruleIds.isEmpty()) {
ruleVersionMap = pqcInspectionRuleService.listByIds(ruleIds).stream()
.collect(Collectors.toMap(QmsPqcInspectionRule::getId, QmsPqcInspectionRule::getRuleVersion));
}
for (QmsPqcTaskRecord record : taskRecords) {
QmsPqcInspectionPoint point = pointMap.get(record.getInspectionPointId());
if (point == null) {
continue;
}
Integer recordRuleVersion = ruleVersionMap.get(point.getPqcRuleId());
StepProgressAccumulator stepAccumulator = stepMap.computeIfAbsent(buildStepKey(point),
k -> StepProgressAccumulator.fromPoint(point));
String key = buildPointKey(point);
PointProgressAccumulator accumulator = stepAccumulator.computeIfAbsent(key,
k -> PointProgressAccumulator.fromTaskPoint(point));
accumulator.mergeRecord(point, recordRuleVersion, record.getStatus());
}
}
QmsPqcTaskRecordPointProgressVO result = new QmsPqcTaskRecordPointProgressVO();
result.setNo(no);
result.setModelNo(modelNo);
result.setSteps(stepMap.values().stream()
.map(StepProgressAccumulator::toVO)
.collect(Collectors.toList()));
return result;
}
/**
* 解析文件列表
*/
@ -1012,6 +1100,129 @@ public class QmsPqcTaskRecordControllerService {
}
}
/**
* 生成检查点合并键
*/
private String buildStepKey(QmsPqcInspectionPoint point) {
String stepName = StrUtil.blankToDefault(point.getStepName(), "");
String stepDicItemId = point.getStepDicItemId() == null ? "" : point.getStepDicItemId().toString();
return stepDicItemId + "|" + stepName;
}
private String buildPointKey(QmsPqcInspectionPoint point) {
String pointCode = StrUtil.blankToDefault(point.getInspectionPointCode(), "");
String pointName = StrUtil.blankToDefault(point.getInspectionPointName(), "");
return buildStepKey(point) + "|" + pointCode + "|" + pointName;
}
private static String formatRuleVersion(Collection<Integer> versions, Integer fallbackVersion) {
if (versions != null && !versions.isEmpty()) {
String versionText = versions.stream()
.filter(Objects::nonNull)
.distinct()
.sorted()
.map(version -> "V" + version)
.collect(Collectors.joining("/"));
if (StrUtil.isNotBlank(versionText)) {
return versionText;
}
}
return fallbackVersion == null ? null : "V" + fallbackVersion;
}
/**
* 检查点进度聚合器
*/
private static class PointProgressAccumulator {
private String stepName;
private Long stepDicItemId;
private String inspectionPointName;
private String inspectionPointCode;
private Long inspectionPointId;
private boolean completed;
private int inspectionCount;
private final Set<Integer> versions = new LinkedHashSet<>();
private Integer fallbackVersion;
private static PointProgressAccumulator fromLatestPoint(QmsPqcInspectionPoint point, Integer latestRuleVersion) {
PointProgressAccumulator accumulator = new PointProgressAccumulator();
accumulator.stepName = point.getStepName();
accumulator.stepDicItemId = point.getStepDicItemId();
accumulator.inspectionPointName = point.getInspectionPointName();
accumulator.inspectionPointCode = point.getInspectionPointCode();
accumulator.inspectionPointId = point.getId();
accumulator.fallbackVersion = latestRuleVersion;
return accumulator;
}
private static PointProgressAccumulator fromTaskPoint(QmsPqcInspectionPoint point) {
PointProgressAccumulator accumulator = new PointProgressAccumulator();
accumulator.stepName = point.getStepName();
accumulator.stepDicItemId = point.getStepDicItemId();
accumulator.inspectionPointName = point.getInspectionPointName();
accumulator.inspectionPointCode = point.getInspectionPointCode();
accumulator.inspectionPointId = point.getId();
return accumulator;
}
private void mergeRecord(QmsPqcInspectionPoint point, Integer recordRuleVersion, Short status) {
inspectionCount++;
if (status != null && status == 3) {
completed = true;
}
if (recordRuleVersion != null) {
versions.add(recordRuleVersion);
}
}
private QmsPqcTaskRecordPointProgressVO toVO() {
QmsPqcTaskRecordPointProgressVO vo = new QmsPqcTaskRecordPointProgressVO();
vo.setStepName(stepName);
vo.setStepDicItemId(stepDicItemId);
vo.setInspectionPointName(inspectionPointName);
vo.setInspectionPointCode(inspectionPointCode);
vo.setInspectionPointId(inspectionPointId);
vo.setCompleted(completed);
vo.setInspectionCount(inspectionCount);
vo.setRuleVersion(formatRuleVersion(versions, fallbackVersion));
return vo;
}
}
/**
* 步装进度聚合器
*/
private static class StepProgressAccumulator {
private String stepName;
private Long stepDicItemId;
private final LinkedHashMap<String, PointProgressAccumulator> points = new LinkedHashMap<>();
private static StepProgressAccumulator fromPoint(QmsPqcInspectionPoint point) {
StepProgressAccumulator accumulator = new StepProgressAccumulator();
accumulator.stepName = point.getStepName();
accumulator.stepDicItemId = point.getStepDicItemId();
return accumulator;
}
private PointProgressAccumulator computeIfAbsent(String key, java.util.function.Supplier<PointProgressAccumulator> supplier) {
return points.computeIfAbsent(key, k -> supplier.get());
}
private void putIfAbsent(String key, PointProgressAccumulator accumulator) {
points.putIfAbsent(key, accumulator);
}
private QmsPqcTaskRecordPointProgressVO.StepVO toVO() {
QmsPqcTaskRecordPointProgressVO.StepVO vo = new QmsPqcTaskRecordPointProgressVO.StepVO();
vo.setStepName(stepName);
vo.setStepDicItemId(stepDicItemId);
vo.setPoints(points.values().stream()
.map(PointProgressAccumulator::toVO)
.collect(Collectors.toList()));
return vo;
}
}
/**
* 提交结果类
*/

View File

@ -0,0 +1,86 @@
package com.nflg.wms.common.pojo.vo;
import lombok.Data;
import java.util.List;
/**
* PQC任务检查点进度返回对象
*/
@Data
public class QmsPqcTaskRecordPointProgressVO {
/**
* 机台编号
*/
private String no;
/**
* 机型编号
*/
private String modelNo;
/**
* 步装列表
*/
private List<StepVO> steps;
/**
* 步装进度
*/
@Data
public static class StepVO {
/**
* 步装名称
*/
private String stepName;
/**
* 步装字典ID
*/
private Long stepDicItemId;
/**
* 检查点列表
*/
private List<PointVO> points;
}
/**
* 检查点进度
*/
@Data
public static class PointVO {
/**
* 检查点名称
*/
private String inspectionPointName;
/**
* 检查点编号
*/
private String inspectionPointCode;
/**
* 检查点流水号
*/
private Long inspectionPointId;
/**
* 是否完成true=已完成false=未完成
*/
private Boolean completed;
/**
* 检测次数
*/
private Integer inspectionCount;
/**
* 检测版本示例V1/V2/V3
*/
private String ruleVersion;
}
}