缺件不再阻塞已有组件拼装展示
This commit is contained in:
@@ -63,7 +63,9 @@ java -jar cadworld-api/target/cadworld-api-0.0.1-SNAPSHOT.jar
|
||||
|
||||
没有可用躯干时返回无匹配结果,不再尝试其他角色为根。一个角色只对应一个实例,躯干的中英文别名也归一化到同一个角色。除作为基础部件自动补入的躯干外,不补入其他未要求的中间连接件;一个实例的数量可验证,同角色多个实例的数量要求需要澄清,不会静默去重冒充数量达标。躯干替代项只用于替换当前唯一躯干。
|
||||
|
||||
`complete/partial/no_match` 描述需求匹配,`assembly.ready/blocked` 描述模型装配。接受降级只解除用户确认阻塞,不消除缺件、未验证能力、安装基准和资源问题。替代项是相对默认方案的一次替换预览;当前未实现多项替换的服务端验证或装配方案保存。
|
||||
`complete/partial/no_match` 描述需求匹配,`assembly.ready/blocked` 只描述已有组件的安装与资源是否有效。缺件通过 `missingParts` 和 `partial` 提示,不进入 `assembly.issues`;未接受降级也不阻塞有效组件预览,因此 `partial` 可同时返回 `assembly.ready`。没有可用组件、躯干根不合法、安装基准缺失、坐标图或资源异常仍阻塞。仅有有效躯干时可以显示躯干,连接数组为空。
|
||||
|
||||
接受降级记录用户确认,仍验证组件版本并重新校验安装数据,不消除缺件、未验证能力或机械/资源问题。默认组合和替代候选使用相同装配判定。升级规则后,旧匹配快照需调用 `rematch` 更新,重复 `confirm` 不会重算。替代项是相对默认方案的一次替换预览;当前未实现多项替换的服务端验证或装配方案保存。
|
||||
|
||||
## 机械安装数据
|
||||
|
||||
@@ -97,6 +99,6 @@ T_parentRoot_childRoot = T_parentRoot_parentInterface × inverse(T_childRoot_chi
|
||||
|
||||
自动测试使用 Java H2 表、模拟模型客户端、本地模拟 Responses HTTP 服务与测试资源域名,不调用真实付费模型、不访问业务 MySQL 或 OSS。
|
||||
|
||||
覆盖规则包原始 Node 输出与 Java 规范化的四组一致性样例、证据和图片归属、单位补充、数值与冲突边界、模型拒绝/超时/异常、SSE、取消和重试、版本和幂等、硬要求/偏好、降级接受、资源版本变化和重新匹配、私有附件过期清理,以及坐标累积、子安装基准取逆、端口歧义与活动关节阻塞。既有管理端上传、版本控制、逻辑删除与审计测试也参加回归。
|
||||
覆盖规则包原始 Node 输出与 Java 规范化的四组一致性样例、证据和图片归属、单位补充、数值与冲突边界、模型拒绝/超时/异常、SSE、取消和重试、版本和幂等、硬要求/偏好、降级接受、资源版本变化和重新匹配、私有附件过期清理,以及坐标累积、子安装基准取逆、端口歧义与活动关节阻塞。验证缺件且未接受降级时默认组件与替代候选可预览、仅有躯干可显示,同时保留缺件和整机总量未验证提示;机械或资源异常仍阻塞。既有管理端上传、版本控制、逻辑删除与审计测试也参加回归。
|
||||
|
||||
真实图片 OCR 和多模态识别质量仍需配置实际模型后使用机械样本验收。修改提示词、Schema 或类别目录时,应同步来源版本、规则校验与一致性样例,不能只替换提示词后直接发布。
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
3. 发送消息,使用 POST + fetch 接收 SSE。
|
||||
4. 收到 `analysis.completed`:`needs_clarification` 时展示追问,用户在同一会话发送新消息;`ready` 时展示摘要、详细需求及来源,请用户确认。
|
||||
5. 确认时只提交 `analysisId`、`revision` 和 `confirmed:true`,不回传或修改解析 JSON。
|
||||
6. 后端先固定最符合要求的一个躯干,再沿其接口匹配其他组件;前端展示组件、逐项校验和装配诊断。需要降级时让用户主动接受;只有 `assembly.status=ready` 才能应用后端连接位姿。
|
||||
6. 后端先固定最符合要求的一个躯干,再沿其接口匹配其他组件;前端展示组件、逐项校验和装配诊断。`assembly.status=ready` 时即可应用已有组件的连接位姿,包括缺件的部分方案;同时展示缺件和未满足要求,需要降级时提供用户主动接受入口。
|
||||
|
||||
浏览器需要保留后端设置的 HttpOnly Cookie,所有调用均设置 `credentials:"include"`。不需要读写 Cookie 值,也不传 `userId`、模型 Key 或系统提示词。当前按匿名浏览器访客隔离对话和图片,清除 Cookie 后不能访问之前记录。生产使用 HTTPS;前后端通过同站点 `/api` 代理接入。开发跨端口需后端配置具体允许域名,并使用一致的主机名(不要混用 localhost 与 127.0.0.1)。
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
| POST | `/api/robot-analyses/{analysisId}/confirm` | 确认 JSON | 匹配结果,重复确认返回同一结果 |
|
||||
| POST | `/api/robot-analyses/{analysisId}/rematch` | 确认 JSON | 使用保存的需求重新匹配,不重新调用模型 |
|
||||
| GET | `/api/robot-demand-matches/{matchId}` | 无 | 保存的匹配结果 |
|
||||
| POST | `/api/robot-demand-matches/{matchId}/accept-degradation` | 接受 JSON | 原方案及更新后的装配阻塞状态 |
|
||||
| POST | `/api/robot-demand-matches/{matchId}/accept-degradation` | 接受 JSON | 原方案、接受状态及重新校验的装配结果 |
|
||||
|
||||
既有结构化 `POST /api/robot-matches` 和公开组件详情保留,见 [组件接口文档](api.md)。本流程的状态为小写,与既有接口的 `MATCHED/FALLBACK/PARTIAL/NO_MATCH` 分开使用。
|
||||
|
||||
@@ -575,10 +575,10 @@ async function sendMessage(conversationId, message, onEvent, signal) {
|
||||
| `requirementChecks[]` | 对应 `intentId`,状态 `satisfied` / `unmet` / `unverified`;前端关联解析中的详细需求 |
|
||||
| `unmetRequirements` | 字段差距,包括偏好差距;硬要求判定以详细校验为准 |
|
||||
| `totals` | 组件标称参数求和;不重复统计 BOM。质量未知时 `massKg=null`,`knownMassKg` 为已知部分 |
|
||||
| `missingParts` | 缺失角色和原因;没有可用躯干时返回 `no_match`,其他现存角色可标记 `NO_TORSO`;仍是 HTTP 200 |
|
||||
| `missingParts` | 缺失角色和原因,仅提示完整性,不阻塞已有组件装配;没有可用躯干时返回 `no_match`,其他现存角色可标记 `NO_TORSO`;仍是 HTTP 200 |
|
||||
| `searchLimited` | 候选或搜索被截断,本方案不是已证明的全局最优 |
|
||||
| `degradationAcceptanceRequired` | 硬要求未满足、未验证或缺件时需用户主动接受 |
|
||||
| `assembly.status` | `ready` 才可应用完整连接;`blocked` 展示 issues,不自动拼装 |
|
||||
| `degradationAcceptanceRequired` | 硬要求未满足、未验证或缺件时需用户主动接受该降级方案;不影响有效组件的装配预览 |
|
||||
| `assembly.status` | `ready`:已有组件的安装与资源校验通过,可应用返回的连接位姿;`blocked`:展示 issues,不自动拼装。与需求是否完整达标分别判断 |
|
||||
|
||||
公开组件字段与 [组件详情](api.md) 一致,不包含数据库主键和独立 OSS 对象键。`urdfMainPath` 与资源清单中的 `relativePath` 保留目录层级,使用 `resources[].url` 加载模型和 mesh。公开资源 `expiresAt=null`,不是临时签名;`version` 表示组件版本。
|
||||
|
||||
@@ -590,6 +590,48 @@ async function sendMessage(conversationId, message, onEvent, signal) {
|
||||
|
||||
选定躯干后不因其他躯干能多接几件或更接近整机总量而自动换根。其他组件须能通过现有接口路径连接到这个躯干;例如右手通过右臂连接,允许沿链匹配,但不自动补入未要求的中间连接件。达标搜索和降级搜索沿用同一个躯干。缺件时返回该躯干及可连接的部分方案;无可用躯干时返回 `no_match`,不会用头部或手臂代替根。
|
||||
|
||||
### 缺件时展示已有组合
|
||||
|
||||
`status=partial` 可以同时有 `assembly.status=ready`。例如需要躯干、右臂和头部,库存只有能连接的躯干与右臂,且两件资源和安装基准有效,返回如下片段:
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "partial",
|
||||
"rootCategory": "torso_0",
|
||||
"degradationAcceptanceRequired": true,
|
||||
"degradationAccepted": false,
|
||||
"missingParts": [
|
||||
{
|
||||
"category": "head_0",
|
||||
"reason": "NO_COMPONENT"
|
||||
}
|
||||
],
|
||||
"assembly": {
|
||||
"status": "ready",
|
||||
"rootInstanceId": "DM-33333333333333333333333333333333:torso_0",
|
||||
"matrixLayout": "column-major",
|
||||
"connections": [
|
||||
{
|
||||
"parentInstanceId": "DM-33333333333333333333333333333333:torso_0",
|
||||
"parentFrame": "J_ARM",
|
||||
"parentLink": "BASE",
|
||||
"childInstanceId": "DM-33333333333333333333333333333333:arm_r",
|
||||
"childFrame": "ARM_ROOT",
|
||||
"childRootLink": "ARM_ROOT",
|
||||
"parentRootToInterface": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1],
|
||||
"childRootToInterface": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
|
||||
"childRootRelativeToParentRoot": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1]
|
||||
}
|
||||
],
|
||||
"issues": []
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
前端加载 `components[]` 中已有的模型并应用上述连接,提示“缺少头部”,同时保留降级接受入口。展示模型无需先接受降级,展示不等于用户已经接受。仅有有效躯干时也可返回 `ready`,此时 `connections=[]`,前端显示躯干本身。
|
||||
|
||||
缺失角色不返回占位组件或伪造连接。`totals` 仍是已有组件的标称参数之和;所需组件未齐全时,整机总量要求仍可能为 `unverified`。替代候选遵循同一规则。没有可用躯干、安装基准缺失、连接图异常或资源清单不完整仍返回 `blocked`;新结果的 `assembly.issues` 不再包含 `MISSING_PARTS` 或 `DEGRADATION_NOT_ACCEPTED`。
|
||||
|
||||
### 替代项示例
|
||||
|
||||
下面是 `alternatives[].items[]` 的完整对象示例,仍是同一右臂角色:
|
||||
@@ -840,7 +882,7 @@ async function sendMessage(conversationId, message, onEvent, signal) {
|
||||
}
|
||||
```
|
||||
|
||||
返回同一匹配结构,`degradationAccepted=true`、`degradationAcceptanceRequired=false`;只清除 `DEGRADATION_NOT_ACCEPTED` 阻塞。缺件、安装基准、资源问题和未验证能力仍保留,`status` 不会因此变成 `complete`。不要在点击接受后直接将装配状态改为 ready。
|
||||
返回同一匹配结构,`degradationAccepted=true`、`degradationAcceptanceRequired=false`,记录用户接受降级。装配预览无需等待接受;接受时仍验证组件版本并重新校验安装数据。缺件和未满足/未验证要求继续保留,`status` 不会因此变成 `complete`;安装基准或资源问题也不会被消除。不要在点击接受后直接将装配状态改为 ready。
|
||||
|
||||
部分返回片段示例(仅展示发生变化的字段):
|
||||
|
||||
@@ -865,6 +907,8 @@ async function sendMessage(conversationId, message, onEvent, signal) {
|
||||
|
||||
组件版本变化或逻辑删除后,接受旧方案返回 `COMPONENT_REVISION_CONFLICT`。调用 `POST /api/robot-analyses/{analysisId}/rematch` 并传 `{revision:1,confirmed:true}` 使用保存的需求重新匹配;返回新 `matchId`,旧匹配编码失效。再次解析需求则发送新消息。
|
||||
|
||||
已保存的旧匹配结果不会自动更新。升级缺件预览规则或补齐组件安装信息后,调用 `rematch` 获取新结果;重复调用 `confirm` 会返回已有快照。
|
||||
|
||||
错误响应示例:
|
||||
|
||||
```json
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
spring:
|
||||
datasource:
|
||||
# 优先使用与管理端一致的 APP_DB_*,兼容原有 DB_* 环境变量。
|
||||
url: ${APP_DB_URL:${DB_URL:jdbc:mysql://127.0.0.1:3306/cadworld?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai}}
|
||||
url: ${APP_DB_URL:${DB_URL:jdbc:mysql://39.105.93.138:3306/cadworld?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai}}
|
||||
username: ${APP_DB_USERNAME:${DB_USERNAME:}}
|
||||
password: ${APP_DB_PASSWORD:${DB_PASSWORD:}}
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
||||
@@ -164,9 +164,81 @@ class DemandFlowApiTest {
|
||||
assertThat(result.path("missingParts").get(0).path("category").asText()).isEqualTo("head_0");
|
||||
assertThat(result.path("status").asText()).isEqualTo("partial");
|
||||
assertThat(result.path("degradationAcceptanceRequired").asBoolean()).isTrue();
|
||||
assertThat(result.path("assembly").path("status").asText()).isEqualTo("ready");
|
||||
assertThat(result.path("assembly").path("issues")).isEmpty();
|
||||
assertThat(result.path("assembly").path("connections").get(0).path("parentInstanceId").asText()).endsWith(":torso_0");
|
||||
}
|
||||
|
||||
@Test void missingPartsAllowAssemblyBeforeDegradationAcceptanceIncludingAlternatives() throws Exception {
|
||||
components(true, 20);
|
||||
doAnswer(invocation -> {
|
||||
ObjectNode raw = raw(invocation.getArgument(0));
|
||||
raw.withArray("partCategories").addObject().put("category", "head_0").put("source", "explicit").put("reason", "所需头部")
|
||||
.putArray("evidenceIds").add("e1");
|
||||
return raw;
|
||||
}).when(model).analyze(anyList());
|
||||
Session session = create();
|
||||
JsonNode parsed = submit(session, "m1", TEXT + ",还需要头部", List.of());
|
||||
String analysisId = parsed.path("analysisId").asText();
|
||||
JsonNode result = confirm(session, analysisId, 1);
|
||||
|
||||
assertThat(result.path("status").asText()).isEqualTo("partial");
|
||||
assertThat(result.path("components")).hasSize(2);
|
||||
assertThat(result.path("components").get(0).path("component").path("category").asText()).isEqualTo("torso_0");
|
||||
assertThat(result.path("missingParts").findValuesAsText("category")).containsExactly("head_0");
|
||||
assertThat(result.path("requirementChecks").findValuesAsText("status")).contains("unverified");
|
||||
assertThat(result.path("degradationAcceptanceRequired").asBoolean()).isTrue();
|
||||
assertThat(result.path("degradationAccepted").asBoolean()).isFalse();
|
||||
assertThat(result.path("assembly").path("status").asText()).isEqualTo("ready");
|
||||
assertThat(result.path("assembly").path("issues")).isEmpty();
|
||||
assertThat(result.path("assembly").path("connections")).hasSize(1);
|
||||
assertThat(result.path("assembly").path("connections").get(0).path("childRootRelativeToParentRoot")).hasSize(16);
|
||||
JsonNode alternative = result.path("alternatives").get(1).path("items").get(0);
|
||||
assertThat(alternative.path("degradationAcceptanceRequired").asBoolean()).isTrue();
|
||||
assertThat(alternative.path("assembly").path("status").asText()).isEqualTo("ready");
|
||||
assertThat(alternative.path("assembly").path("issues")).isEmpty();
|
||||
assertThat(alternative.path("assembly").path("connections")).hasSize(1);
|
||||
|
||||
JsonNode cached = data(mvc.perform(get("/api/robot-demand-matches/" + result.path("matchId").asText()).cookie(session.cookie()))
|
||||
.andExpect(status().isOk()).andReturn());
|
||||
assertThat(cached.path("assembly")).isEqualTo(result.path("assembly"));
|
||||
assertThat(confirm(session, analysisId, 1).path("matchId").asText()).isEqualTo(result.path("matchId").asText());
|
||||
JsonNode accepted = data(mvc.perform(post("/api/robot-demand-matches/" + result.path("matchId").asText() + "/accept-degradation")
|
||||
.cookie(session.cookie()).contentType(MediaType.APPLICATION_JSON).content("{\"revision\":1,\"accepted\":true}"))
|
||||
.andExpect(status().isOk()).andReturn());
|
||||
assertThat(accepted.path("status").asText()).isEqualTo("partial");
|
||||
assertThat(accepted.path("missingParts")).isEqualTo(result.path("missingParts"));
|
||||
assertThat(accepted.path("components")).isEqualTo(result.path("components"));
|
||||
assertThat(accepted.path("assembly")).isEqualTo(result.path("assembly"));
|
||||
assertThat(accepted.path("degradationAccepted").asBoolean()).isTrue();
|
||||
assertThat(accepted.path("degradationAcceptanceRequired").asBoolean()).isFalse();
|
||||
|
||||
jdbc.update("UPDATE component SET urdf_files='[]' WHERE category='arm_r'");
|
||||
JsonNode invalidResources = data(mvc.perform(post("/api/robot-analyses/" + analysisId + "/rematch")
|
||||
.cookie(session.cookie()).contentType(MediaType.APPLICATION_JSON).content("{\"revision\":1,\"confirmed\":true}"))
|
||||
.andExpect(status().isOk()).andReturn());
|
||||
assertThat(invalidResources.path("status").asText()).isEqualTo("partial");
|
||||
assertThat(invalidResources.path("missingParts")).isEqualTo(result.path("missingParts"));
|
||||
assertThat(invalidResources.path("assembly").path("status").asText()).isEqualTo("blocked");
|
||||
assertThat(invalidResources.path("assembly").path("issues").findValuesAsText("code")).containsExactly("INCOMPLETE_RESOURCE_MANIFEST");
|
||||
assertThat(invalidResources.path("alternatives").get(1).path("items").get(0).path("assembly").path("status").asText()).isEqualTo("blocked");
|
||||
}
|
||||
|
||||
@Test void onlyTorsoCanBeDisplayedWhenAllRequestedChildPartsAreMissing() throws Exception {
|
||||
save("CW-TORSO", "torso_0", 0, "2", 0, "BASE", true);
|
||||
Session session = create();
|
||||
JsonNode parsed = submit(session, "m1", TEXT, List.of());
|
||||
JsonNode result = confirm(session, parsed.path("analysisId").asText(), 1);
|
||||
assertThat(result.path("status").asText()).isEqualTo("partial");
|
||||
assertThat(result.path("missingParts").findValuesAsText("category")).containsExactly("arm_r");
|
||||
assertThat(result.path("components")).hasSize(1);
|
||||
assertThat(result.path("degradationAcceptanceRequired").asBoolean()).isTrue();
|
||||
assertThat(result.path("assembly").path("status").asText()).isEqualTo("ready");
|
||||
assertThat(result.path("assembly").path("rootInstanceId").asText()).endsWith(":torso_0");
|
||||
assertThat(result.path("assembly").path("connections")).isEmpty();
|
||||
assertThat(result.path("assembly").path("issues")).isEmpty();
|
||||
}
|
||||
|
||||
@Test void noInventoryAndIncompleteResourceManifestReturnDiagnosableResults() throws Exception {
|
||||
Session session = create(); JsonNode parsed = submit(session, "m1", TEXT, List.of());
|
||||
JsonNode empty = confirm(session, parsed.path("analysisId").asText(), 1);
|
||||
|
||||
+2
-4
@@ -11,19 +11,17 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/** 依据明确的机械基准计算刚体变换;信息不足时返回 blocked,不补翻转/位移。 */
|
||||
/** 校验已有组件的安装与坐标;缺件及需求降级由匹配结果提示,不阻塞有效组件展示。 */
|
||||
public final class DemandAssemblyValidator {
|
||||
private final DemandProperties properties;
|
||||
public DemandAssemblyValidator(DemandProperties properties) { this.properties = properties; }
|
||||
|
||||
public Assembly validate(String matchId, RobotMatchResponse match, boolean degradationBlocked) {
|
||||
public Assembly validate(String matchId, RobotMatchResponse match) {
|
||||
List<Issue> issues = new ArrayList<>();
|
||||
List<Connection> connections = new ArrayList<>();
|
||||
Map<String, PublicComponentResponse> parts = new LinkedHashMap<>();
|
||||
match.parts().forEach((PublicComponentResponse part) -> parts.put(part.componentCode(), part));
|
||||
if (parts.isEmpty()) issues.add(new Issue("NO_COMPONENTS", null, null, "没有可用于装配的组件"));
|
||||
if (!match.missingParts().isEmpty()) issues.add(new Issue("MISSING_PARTS", null, null, "所需组件尚未齐全"));
|
||||
if (degradationBlocked) issues.add(new Issue("DEGRADATION_NOT_ACCEPTED", null, null, "部分硬要求未满足或未验证,请先确认是否接受该方案"));
|
||||
long torsoCount = match.parts().stream().filter((PublicComponentResponse part) -> "torso_0".equals(part.category())).count();
|
||||
if (!parts.isEmpty() && (torsoCount != 1 || !"torso_0".equals(match.rootCategory()))) {
|
||||
issues.add(new Issue("INVALID_TORSO_ROOT", "torso_0", null, "整机必须且只能包含一个躯干,并以躯干为根"));
|
||||
|
||||
+9
-7
@@ -41,8 +41,10 @@ public final class DemandMatchService {
|
||||
long started = System.nanoTime();
|
||||
RobotMatchResponse response = matching.matchConfirmed(project(analysis.result()), requirements.softFields(analysis.result()));
|
||||
ObjectNode result = build(matchId, analysis, response, false);
|
||||
log.info("确认需求匹配完成 requestId={} analysisId={} revision={} matchId={} selectedCount={} status={} assemblyStatus={} durationMs={}",
|
||||
RequestIdHolder.get(), analysis.analysisId(), analysis.revision(), matchId, response.parts().size(), result.path("status").asText(), result.path("assembly").path("status").asText(), (System.nanoTime() - started) / 1_000_000);
|
||||
log.info("确认需求匹配完成 requestId={} analysisId={} revision={} matchId={} selectedCount={} missingCount={} unmetCount={} status={} assemblyStatus={} assemblyIssueCodes={} durationMs={}",
|
||||
RequestIdHolder.get(), analysis.analysisId(), analysis.revision(), matchId, response.parts().size(), response.missingParts().size(),
|
||||
response.unmetRequirements().size(), result.path("status").asText(), result.path("assembly").path("status").asText(),
|
||||
result.path("assembly").path("issues").findValuesAsText("code"), (System.nanoTime() - started) / 1_000_000);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -51,7 +53,7 @@ public final class DemandMatchService {
|
||||
RobotMatchResponse snapshot = readSnapshot(result.path("snapshot"));
|
||||
verifyVersions(snapshot.parts());
|
||||
ArrayNode checks = requirements.check(analysis.result(), snapshot);
|
||||
result.set("assembly", assemblyWithResources(matchId, snapshot, false, result.path("components")));
|
||||
result.set("assembly", assemblyWithResources(matchId, snapshot, result.path("components")));
|
||||
result.put("degradationAcceptanceRequired", false).put("degradationAccepted", true);
|
||||
result.set("requirementChecks", checks);
|
||||
return result;
|
||||
@@ -75,7 +77,7 @@ public final class DemandMatchService {
|
||||
result.set("requirementChecks", checks);
|
||||
ArrayNode components = result.putArray("components");
|
||||
for (PublicComponentResponse part : response.parts()) components.add(component(matchId, part));
|
||||
result.set("assembly", assemblyWithResources(matchId, response, result.path("degradationAcceptanceRequired").asBoolean(), components));
|
||||
result.set("assembly", assemblyWithResources(matchId, response, components));
|
||||
ArrayNode alternatives = result.putArray("alternatives");
|
||||
for (RobotMatchResponse.Alternatives group : response.alternatives()) {
|
||||
ArrayNode items = alternatives.addObject().put("category", group.category()).putArray("items");
|
||||
@@ -98,7 +100,7 @@ public final class DemandMatchService {
|
||||
item.set("requirementChecks", replacementChecks);
|
||||
ArrayNode replacedResources = json.createArrayNode();
|
||||
for (JsonNode original : components) replacedResources.add(group.category().equals(original.path("component").path("category").asText()) ? replacedComponent : original);
|
||||
item.set("assembly", assemblyWithResources(matchId, replaced, downgrade, replacedResources));
|
||||
item.set("assembly", assemblyWithResources(matchId, replaced, replacedResources));
|
||||
item.put("degradationAcceptanceRequired", downgrade);
|
||||
}
|
||||
}
|
||||
@@ -141,8 +143,8 @@ public final class DemandMatchService {
|
||||
private void resourceIssue(ArrayNode issues, PublicComponentResponse part, String code, String message) {
|
||||
issues.addObject().put("code", code).put("category", part.category()).put("componentCode", part.componentCode()).put("message", message);
|
||||
}
|
||||
private JsonNode assemblyWithResources(String matchId, RobotMatchResponse response, boolean blocked, JsonNode components) {
|
||||
ObjectNode result = json.valueToTree(assembly.validate(matchId, response, blocked));
|
||||
private JsonNode assemblyWithResources(String matchId, RobotMatchResponse response, JsonNode components) {
|
||||
ObjectNode result = json.valueToTree(assembly.validate(matchId, response));
|
||||
for (JsonNode component : components) for (JsonNode issue : component.path("resourceIssues")) result.withArray("issues").add(issue);
|
||||
if (!result.path("issues").isEmpty()) result.put("status", "blocked");
|
||||
return result;
|
||||
|
||||
+1
-1
@@ -225,7 +225,7 @@ public class DemandRepository {
|
||||
if (current.revision() != revision || conversation.revision() != revision || !"ready".equals(current.status())) throw conflict("需求版本已更新,请重新匹配");
|
||||
Integer accepted = jdbc.queryForObject("SELECT degradation_accepted FROM robot_demand_match WHERE match_code=?", Integer.class, matchId);
|
||||
if (accepted != null && accepted == 1) return decode(jdbc.queryForObject("SELECT result_json FROM robot_demand_match WHERE match_code=?", String.class, matchId));
|
||||
// operation 在同一事务中验证旧组件版本,并且只解除降级确认阻塞,不重新挑选组件。
|
||||
// operation 在同一事务中验证旧组件版本、重新校验安装数据并记录接受降级,不重新挑选组件。
|
||||
JsonNode result = operation.match(matchId, current);
|
||||
jdbc.update("UPDATE robot_demand_match SET result_json=?,degradation_accepted=1,updated_at=? WHERE match_code=?", encode(result), timestamp(Instant.now()), matchId);
|
||||
return result;
|
||||
|
||||
+27
-6
@@ -24,7 +24,7 @@ class DemandAssemblyValidatorTest {
|
||||
ObjectNode child = info("ARM_ROOT");
|
||||
joint(child, "J_MOUNT", "ARM_ROOT", "MOUNT", "", 0, 1, 0);
|
||||
child.putObject("assembly").put("mountingFrame", "MOUNT").put("pairingConvention", "coincident_frames");
|
||||
DemandAssemblyValidator.Assembly result = validator.validate("DM-test", match(parent, child), false);
|
||||
DemandAssemblyValidator.Assembly result = validator.validate("DM-test", match(parent, child));
|
||||
assertThat(result.status()).isEqualTo("ready");
|
||||
List<Double> matrix = result.connections().get(0).childRootRelativeToParentRoot();
|
||||
assertThat(matrix.get(12)).isCloseTo(2, within(1e-10));
|
||||
@@ -38,7 +38,7 @@ class DemandAssemblyValidatorTest {
|
||||
ObjectNode parent = info("BASE"); joint(parent, "J_ARM", "BASE", "LINK_arm_r", "arm_r", 0, 0, 0);
|
||||
ObjectNode child = info("ARM_ROOT"); joint(child, "MOUNT", "ARM_ROOT", "C_MOUNT", "", 1, 0, Math.PI / 2);
|
||||
child.putObject("assembly").put("mountingFrame", "MOUNT").put("pairingConvention", "coincident_frames");
|
||||
List<Double> matrix = validator.validate("DM-test", match(parent, child), false).connections().get(0).childRootRelativeToParentRoot();
|
||||
List<Double> matrix = validator.validate("DM-test", match(parent, child)).connections().get(0).childRootRelativeToParentRoot();
|
||||
assertThat(matrix.get(12)).isCloseTo(0, within(1e-10));
|
||||
assertThat(matrix.get(13)).isCloseTo(1, within(1e-10));
|
||||
assertThat(matrix.get(1)).isCloseTo(-1, within(1e-10));
|
||||
@@ -63,22 +63,43 @@ class DemandAssemblyValidatorTest {
|
||||
frame.put("type", "revolute"); assertIssue(parent, child, "MOVABLE_INTERFACE_REQUIRES_STATE");
|
||||
frame.put("type", "fixed"); frame.remove("xyz"); assertIssue(parent, child, "INVALID_ORIGIN");
|
||||
frame.put("originExplicit", false);
|
||||
assertThat(validator.validate("DM-test", match(parent, child), false).status()).isEqualTo("ready");
|
||||
assertThat(validator.validate("DM-test", match(parent, child)).status()).isEqualTo("ready");
|
||||
}
|
||||
|
||||
@Test void assembliesWithNoTorsoOrTwoTorsosAreBlocked() {
|
||||
RobotMatchResponse valid = match(info("BASE"), info("ARM_ROOT"));
|
||||
List<PublicComponentResponse> duplicate = List.of(valid.parts().get(0), part("SECOND_TORSO", "torso_0", info("BASE_2")), valid.parts().get(1));
|
||||
RobotMatchResponse twoTorsos = new RobotMatchResponse("MATCHED", "torso_0", duplicate, List.of(), List.of(), valid.totals(), List.of(), List.of(), List.of(), false);
|
||||
DemandAssemblyValidator.Assembly result = validator.validate("DM-test", twoTorsos, false);
|
||||
DemandAssemblyValidator.Assembly result = validator.validate("DM-test", twoTorsos);
|
||||
assertThat(result.status()).isEqualTo("blocked");
|
||||
assertThat(result.issues()).extracting(DemandAssemblyValidator.Issue::code).contains("INVALID_TORSO_ROOT");
|
||||
RobotMatchResponse armRoot = new RobotMatchResponse("MATCHED", "arm_r", List.of(valid.parts().get(1)), List.of(), List.of(), valid.totals(), List.of(), List.of(), List.of(), false);
|
||||
assertThat(validator.validate("DM-test", armRoot, false).status()).isEqualTo("blocked");
|
||||
assertThat(validator.validate("DM-test", armRoot).status()).isEqualTo("blocked");
|
||||
}
|
||||
|
||||
@Test void missingRequestedPartsDoNotBlockExistingConnections() {
|
||||
ObjectNode parent = info("BASE"); joint(parent, "J_ARM", "BASE", "LINK_arm_r", "arm_r", 1, 0, 0);
|
||||
ObjectNode child = info("ARM_ROOT");
|
||||
child.putObject("assembly").put("mountingFrame", "ARM_ROOT").put("pairingConvention", "coincident_frames");
|
||||
RobotMatchResponse selected = match(parent, child);
|
||||
RobotMatchResponse partial = new RobotMatchResponse("PARTIAL", selected.rootCategory(), selected.parts(), selected.connections(), List.of(),
|
||||
selected.totals(), List.of(), List.of(), List.of(new RobotMatchResponse.MissingPart("head_0", "NO_COMPONENT")), false);
|
||||
|
||||
DemandAssemblyValidator.Assembly result = validator.validate("DM-test", partial);
|
||||
assertThat(result.status()).isEqualTo("ready");
|
||||
assertThat(result.issues()).isEmpty();
|
||||
assertThat(result.connections()).hasSize(1);
|
||||
assertThat(result.connections().get(0).childRootRelativeToParentRoot().get(12)).isEqualTo(1);
|
||||
|
||||
child.remove("assembly");
|
||||
DemandAssemblyValidator.Assembly invalid = validator.validate("DM-test", partial);
|
||||
assertThat(invalid.status()).isEqualTo("blocked");
|
||||
assertThat(invalid.connections()).isEmpty();
|
||||
assertThat(invalid.issues()).extracting(DemandAssemblyValidator.Issue::code).containsExactly("MISSING_MOUNTING_REFERENCE");
|
||||
}
|
||||
|
||||
private void assertIssue(ObjectNode parent, ObjectNode child, String code) {
|
||||
DemandAssemblyValidator.Assembly result = validator.validate("DM-test", match(parent, child), false);
|
||||
DemandAssemblyValidator.Assembly result = validator.validate("DM-test", match(parent, child));
|
||||
assertThat(result.status()).isEqualTo("blocked");
|
||||
assertThat(result.issues()).extracting(DemandAssemblyValidator.Issue::code).contains(code);
|
||||
assertThat(result.connections()).isEmpty();
|
||||
|
||||
Reference in New Issue
Block a user