组件仅stepObjectKey 必填,拼装默认方案和替代候选均只选择具有非空 STEP、URDF 主文件键的组件
This commit is contained in:
@@ -132,12 +132,12 @@ OSS CORS 需允许前端源站的表单 POST。OSS 上传失败由前端按 OSS
|
||||
|
||||
### 4.1 表单字段
|
||||
|
||||
POST 和 PUT 使用扁平 JSON,字段约定相同:
|
||||
POST 和 PUT 使用扁平 JSON。新增业务字段仅 `stepObjectKey` 必填,仍须提交有效的 `uploadSessionToken`;全量修改保留名称、分类和 URDF 信息必填规则:
|
||||
|
||||
| 字段 | 类型 | 必填 / 默认值 / 限制 |
|
||||
| --- | --- | --- |
|
||||
| componentName | string | 必填,非空,最多 128 字符,允许同名 |
|
||||
| category | string | 必填,非空,最多 64 字符,自由分类 |
|
||||
| componentName | string | POST 可选,默认 `""`;PUT 必填、非空;最多 128 字符,允许同名 |
|
||||
| category | string | POST 可选,默认 `""`;PUT 必填、非空;最多 64 字符,自由分类 |
|
||||
| description | string | 默认 `""`,UTF-8 不超过 65535 字节 |
|
||||
| material | string | 默认 `""`,最多 128 字符 |
|
||||
| massKg | number | 默认 0,千克,非负 |
|
||||
@@ -147,13 +147,13 @@ POST 和 PUT 使用扁平 JSON,字段约定相同:
|
||||
| size | string | 默认 `""`,最多 128 字符,大小描述,可包含单位 |
|
||||
| torqueNm | number | 默认 0,单位 N·m,非负 |
|
||||
| bomList | JSON 对象或数组 | 默认 `[]`,内部结构自由 |
|
||||
| urdfInfo | JSON 对象或数组 | POST / PUT 均必填,内部结构自由,允许 `{}` 或 `[]` |
|
||||
| urdfInfo | JSON 对象或数组 | POST 可选,默认 `[]`;PUT 必填;内部结构自由,允许 `{}` 或 `[]` |
|
||||
| basicFields | 自定义字段数组 | 默认 `[]`,基本信息扩展字段 |
|
||||
| parameterFields | 自定义字段数组 | 默认 `[]`,零件参数扩展字段 |
|
||||
|
||||
质量和扭矩最多 12 位整数、6 位小数,与 `DECIMAL(18,6)` 一致;不要在数值中提交单位文本。可选字段省略或传 null 会恢复默认值。名称、分类、材质、功能、形状和大小会裁剪首尾空白。
|
||||
|
||||
`bomList` 和 `urdfInfo` 直接提交 JSON 对象或数组,不接受字符串化的 JSON、数字或布尔值。`bomList` 省略或为 null 时保存为空数组;`urdfInfo` 省略或为 null 时返回 422。两者内部字段不做固定结构校验,`urdfInfo` 由前端提供,不由后端解析 URDF 文件生成。
|
||||
`bomList` 和 `urdfInfo` 直接提交 JSON 对象或数组,不接受字符串化的 JSON、数字或布尔值。`bomList` 省略或为 null 时保存为空数组;新增时 `urdfInfo` 省略或为 null 也保存为空数组,修改时仍须提供 JSON 对象或数组。两者内部字段不做固定结构校验,`urdfInfo` 由前端提供,不由后端解析 URDF 文件生成。
|
||||
|
||||
自定义字段格式:
|
||||
|
||||
@@ -170,9 +170,9 @@ PUT 是全量表单更新,前端应提交完整表单,每次都必须提交
|
||||
|
||||
### 4.2 保存时的资源校验
|
||||
|
||||
新增必须同时提交 STEP 和 URDF 资源;修改可只替换一种,未提交的资源保持原引用。文件引用只能来自当前操作人、当前组件的有效令牌和对应目录。
|
||||
新增必须提交 STEP,URDF 可选,`urdfObjectKeys` 省略、为 null 或空数组均表示未上传 URDF;此时 `urdfPrefix`、`urdfMainObjectKey` 保存为 `""`,`urdfFiles` 保存为 `[]`。修改可只替换一种,未提交的资源保持原引用。文件引用只能来自当前操作人、当前组件的有效令牌和对应目录。
|
||||
|
||||
后端检查全部对象键合法、无重复、无路径越界且实际存在,按 OSS HEAD 返回的实际大小校验,不接受前端提供的文件大小。STEP 是直接位于 STEP 批次目录的一个非空 `.step` 或 `.stp` 文件。URDF 清单 1 至 1000 项,必须恰好包含一个非空 `.urdf` 主文件,不支持以 `.rfs` 为主文件;扩展名大小写均可。
|
||||
后端检查全部对象键合法、无重复、无路径越界且实际存在,按 OSS HEAD 返回的实际大小校验,不接受前端提供的文件大小。STEP 是直接位于 STEP 批次目录的一个非空 `.step` 或 `.stp` 文件。提交非空 URDF 清单时,清单须为 1 至 1000 项,必须恰好包含一个非空 `.urdf` 主文件,不支持以 `.rfs` 为主文件;扩展名大小写均可。
|
||||
|
||||
后端根据实际对象生成 `urdfPrefix`、`urdfMainObjectKey` 和 `urdfFiles`,清单保留请求顺序,元素为 `relativePath` 和 `sizeBytes`。无需提交这些数据库维护字段。
|
||||
|
||||
@@ -182,7 +182,16 @@ PUT 是全量表单更新,前端应提交完整表单,每次都必须提交
|
||||
|
||||
### 5.1 新增
|
||||
|
||||
`POST /admin-api/components`。编码由令牌读取,不接受前端指定编码。签名、直传成功后提交:
|
||||
`POST /admin-api/components`。编码由令牌读取,不接受前端指定编码。仅上传 STEP 后即可提交最小请求:
|
||||
|
||||
```json
|
||||
{
|
||||
"uploadSessionToken":"签名接口返回的令牌",
|
||||
"stepObjectKey":"cadworld_dev/components/CW-0123456789ABCDEF0123456789ABCDEF/step/abcdef0123456789abcdef0123456789/model.step"
|
||||
}
|
||||
```
|
||||
|
||||
其余业务字段按默认值保存,无需修改现有组件表结构;`bomList`、`urdfInfo` 虽为 NOT NULL,后端会显式写入空数组。需要填写元数据或上传 URDF 时,可提交完整请求:
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -341,8 +350,8 @@ function urdfRelativePath(file) {
|
||||
async function uploadAndSave(formValues, stepFile, urdfFiles, component = null) {
|
||||
// 新增传 {};编辑传已有组件 ID。编辑可仅替换 STEP 或 URDF。
|
||||
const files = Array.from(urdfFiles || []);
|
||||
if (!component && (!stepFile || files.length === 0)) {
|
||||
throw new Error('新增组件必须选择 STEP 文件和 URDF 文件夹');
|
||||
if (!component && !stepFile) {
|
||||
throw new Error('新增组件必须选择 STEP 文件');
|
||||
}
|
||||
const body = { ...formValues };
|
||||
if (component) body.version = component.version;
|
||||
|
||||
@@ -232,12 +232,70 @@ class AdminApiTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void jsonFieldsRejectInvalidContainersAndUrdfInfoIsRequiredOnEverySave() throws Exception {
|
||||
void createsWithOnlyStepAndTokenAndDefaultsOptionalFields() throws Exception {
|
||||
for (int variant = 0; variant < 3; variant++) {
|
||||
JsonNode session = sign(Map.of());
|
||||
String step = session.path("step").path("keyPrefix").asText() + "model.step";
|
||||
storage.simulateDirectUpload(step, "application/octet-stream", new byte[]{1, 2});
|
||||
Map<String, Object> body = new HashMap<>();
|
||||
body.put("uploadSessionToken", session.path("uploadSessionToken").asText());
|
||||
body.put("stepObjectKey", step);
|
||||
if (variant == 1) {
|
||||
for (String field : List.of("componentName", "category", "description", "material", "massKg",
|
||||
"degreesOfFreedom", "functionDescription", "shape", "size", "torqueNm", "bomList",
|
||||
"urdfInfo", "basicFields", "parameterFields", "urdfObjectKeys")) {
|
||||
body.put(field, null);
|
||||
}
|
||||
} else if (variant == 2) {
|
||||
body.put("componentName", " ");
|
||||
body.put("category", " ");
|
||||
body.put("urdfObjectKeys", List.of());
|
||||
}
|
||||
JsonNode created = create(body);
|
||||
assertThat(created.path("componentCode").asText()).isEqualTo(session.path("componentCode").asText());
|
||||
assertThat(created.path("stepObjectKey").asText()).isEqualTo(step);
|
||||
assertThat(created.path("stepUrl").asText()).endsWith("/model.step");
|
||||
for (String field : List.of("componentName", "category", "description", "material", "urdfPrefix",
|
||||
"urdfMainObjectKey", "urdfBaseUrl", "urdfUrl")) {
|
||||
assertThat(created.get(field)).isEqualTo(json.valueToTree(""));
|
||||
}
|
||||
for (String field : List.of("urdfInfo", "urdfFiles", "basicFields", "parameterFields")) {
|
||||
assertThat(created.get(field)).isEqualTo(json.createArrayNode());
|
||||
}
|
||||
assertComponentDefaults(created);
|
||||
assertThat(created.path("massKg").decimalValue()).isZero();
|
||||
Component stored = componentMapper.selectById(created.path("id").asLong());
|
||||
assertThat(stored.getBomList()).isEqualTo(json.createArrayNode());
|
||||
assertThat(stored.getUrdfInfo()).isEqualTo(json.createArrayNode());
|
||||
assertThat(stored.getUrdfFiles()).isEqualTo(json.createArrayNode());
|
||||
assertThat(stored.getUrdfPrefix()).isEmpty();
|
||||
assertThat(stored.getUrdfMainObjectKey()).isEmpty();
|
||||
}
|
||||
assertThat(count("component")).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
void stepAndUploadSessionRemainRequiredWhenOtherFieldsAreOmitted() throws Exception {
|
||||
JsonNode session = sign(Map.of());
|
||||
String step = session.path("step").path("keyPrefix").asText() + "model.step";
|
||||
storage.simulateDirectUpload(step, "application/octet-stream", new byte[]{1, 2});
|
||||
Map<String, Object> minimal = Map.of("uploadSessionToken", session.path("uploadSessionToken").asText(),
|
||||
"stepObjectKey", step);
|
||||
for (String field : minimal.keySet()) {
|
||||
Map<String, Object> body = new HashMap<>(minimal);
|
||||
body.remove(field);
|
||||
expectCreateError(body, 422, "INVALID_REQUEST");
|
||||
body.put(field, null);
|
||||
expectCreateError(body, 422, "INVALID_REQUEST");
|
||||
body.put(field, " ");
|
||||
expectCreateError(body, 422, "INVALID_REQUEST");
|
||||
}
|
||||
assertThat(count("component")).isZero();
|
||||
}
|
||||
|
||||
@Test
|
||||
void jsonFieldsRejectInvalidContainersAndUpdateStillRequiresUrdfInfo() throws Exception {
|
||||
Map<String,Object> body = uploaded();
|
||||
body.remove("urdfInfo");
|
||||
expectCreateError(body, 422, "INVALID_REQUEST");
|
||||
body.put("urdfInfo", json.nullNode());
|
||||
expectCreateError(body, 422, "INVALID_COMPONENT_FORM");
|
||||
for (String field : List.of("bomList", "urdfInfo")) {
|
||||
for (Object value : List.of("{\"name\":\"robot\"}", 6, true)) {
|
||||
body.put("urdfInfo", Map.of());
|
||||
|
||||
@@ -164,7 +164,7 @@ X-Request-Id: frontend-match-001
|
||||
|
||||
整机自由度和质量按选中组件字段求和,**不重复累加BOM,不从URDF再次计算**。质量为0视为未填写;只要一个组件质量未知,`totals.massKg=null`、`massComplete=false`,已知部分保存在 `knownMassKg`。不能据此宣布满足质量上限。功能命中表示元数据相关,不代表动力学验证。
|
||||
|
||||
拼装候选必须有 URDF 主文件,且 `urdfInfo` 是包含非空 `rootLink` 和 `frames` 数组的对象。父帧的 `interfaceType` 对应子角色,连接到子组件的 `rootLink`。结果为无环连通组合,每个端口最多使用一次。异常端口会被忽略,前端应使用返回的 `connections` 完成拼装。
|
||||
拼装候选必须同时有非空 `step_object_key` 和已上传的 URDF 主文件(非空 `urdf_main_object_key`),且 `urdfInfo` 是包含非空 `rootLink` 和 `frames` 数组的对象。仅上传 STEP 的组件可以查看详情,但不会进入默认方案或替代候选。父帧的 `interfaceType` 对应子角色,连接到子组件的 `rootLink`。结果为无环连通组合,每个端口最多使用一次。异常端口会被忽略,前端应使用返回的 `connections` 完成拼装。
|
||||
|
||||
`bomList` 和 `urdfInfo` 始终作为原始 JSON 返回,保留嵌套内容;详情里的 `urdfInfo` 也可能是其他对象或数组。接口匹配只评价元数据和连接类型,不验证机械承载或运动性能。
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ java -jar cadworld-api/target/cadworld-api-0.0.1-SNAPSHOT.jar
|
||||
|
||||
数值约束统一到 kg、N·m,支持明确单位换算与中文数字;自由度必须是 int32 非负整数,质量和扭矩遵循 decimal(18,6)。单位缺失、范围无法表示、相互冲突、对象不清楚等触发追问,不自动选一个值覆盖。`lt/gt/neq` 与非退化双边范围当前不投影为 `eq/gte/lte`。未指定属性不会填 0。图片视觉推断、模糊信息和反例不能投影成硬数值条件。
|
||||
|
||||
组件组合仍为 MySQL + 同义词词典 + Java 有界搜索。先按躯干单件硬要求、数值差距、偏好及功能/关键词相关性固定唯一躯干;评分相同后比较所需接口覆盖及编码。整机自由度和质量在后续组合求和评价。固定躯干后优先覆盖所需角色;在同等覆盖下,硬要求差距优先于偏好。先搜索其他部件硬条件满足的候选,再提供明确说明的降级结果,两轮共用同一个躯干;不以整机总量或覆盖率更换根。
|
||||
组件组合仍为 MySQL + 同义词词典 + Java 有界搜索。候选查询只扫描同时具有非空 `step_object_key` 和 `urdf_main_object_key` 的组件,只有 STEP 的组件不参与默认方案或替代候选;新增时可先仅上传 STEP,再通过管理端修改补齐 URDF 和元数据。先按躯干单件硬要求、数值差距、偏好及功能/关键词相关性固定唯一躯干;评分相同后比较所需接口覆盖及编码。整机自由度和质量在后续组合求和评价。固定躯干后优先覆盖所需角色;在同等覆盖下,硬要求差距优先于偏好。先搜索其他部件硬条件满足的候选,再提供明确说明的降级结果,两轮共用同一个躯干;不以整机总量或覆盖率更换根。
|
||||
|
||||
没有可用躯干时返回无匹配结果,不再尝试其他角色为根。一个角色只对应一个实例,躯干的中英文别名也归一化到同一个角色。除作为基础部件自动补入的躯干外,不补入其他未要求的中间连接件;一个实例的数量可验证,同角色多个实例的数量要求需要澄清,不会静默去重冒充数量达标。躯干替代项只用于替换当前唯一躯干。
|
||||
|
||||
|
||||
@@ -584,6 +584,8 @@ async function sendMessage(conversationId, message, onEvent, signal) {
|
||||
|
||||
### 躯干优先规则
|
||||
|
||||
拼装仅检索同时具备非空 `step_object_key` 和已上传 URDF 主文件(非空 `urdf_main_object_key`)的组件;确认、重新匹配和替代候选使用同一筛选规则。仅上传 STEP 的组件不会参与拼装。候选仍须满足 `urdfInfo.rootLink`、`frames` 及现有连接元数据规则,装配阶段继续校验安装基准和资源清单。
|
||||
|
||||
整机结果始终以 `torso_0` 为根,默认方案中的躯干只有一个。用户未单独提出躯干时,后端在规范化的 `requiredParts` 中补入 `torso_0` 并返回说明;原始对话和提取的用户条目保持其来源。明确要求“不要躯干”或多个同类躯干时会追问,不能直接确认拼装。
|
||||
|
||||
躯干先按自身硬条件、数值差距、偏好、整机功能文本与关键词相关性排序;这些条件相同后优先选择能接更多所需角色的接口集合,最后按编码稳定排序。整机自由度和质量目标在后续组合阶段评价,不直接当作躯干单件的数值要求。
|
||||
|
||||
@@ -18,6 +18,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -111,6 +113,34 @@ class DemandFlowApiTest {
|
||||
mvc.perform(get("/api/robot-demand-matches/" + match.path("matchId").asText()).cookie(session.cookie())).andExpect(status().isOk()).andExpect(jsonPath("$.data.snapshot").doesNotExist());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"step_object_key", "urdf_main_object_key"})
|
||||
void confirmAndRematchExcludeComponentsWithoutStepOrUploadedUrdf(String resourceColumn) throws Exception {
|
||||
components(true, 20);
|
||||
String originalKey = jdbc.queryForObject("SELECT " + resourceColumn + " FROM component WHERE component_code='CW-ARM-ALT'", String.class);
|
||||
jdbc.update("UPDATE component SET " + resourceColumn + "='' WHERE component_code='CW-ARM'");
|
||||
jdbc.update("UPDATE component SET " + resourceColumn + "=' ' WHERE component_code='CW-ARM-ALT'");
|
||||
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").findValuesAsText("componentCode")).containsExactly("CW-TORSO");
|
||||
assertThat(result.path("missingParts").findValuesAsText("category")).containsExactly("arm_r");
|
||||
assertThat(result.path("alternatives").findValuesAsText("componentCode")).doesNotContain("CW-ARM", "CW-ARM-ALT");
|
||||
mvc.perform(get("/api/components/CW-ARM")).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data.componentCode").value("CW-ARM"))
|
||||
.andExpect(jsonPath("$.data.id").doesNotExist());
|
||||
|
||||
jdbc.update("UPDATE component SET " + resourceColumn + "=? WHERE component_code='CW-ARM-ALT'", originalKey);
|
||||
JsonNode refreshed = 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(refreshed.path("status").asText()).isEqualTo("complete");
|
||||
assertThat(refreshed.path("components").findValuesAsText("componentCode")).containsExactly("CW-TORSO", "CW-ARM-ALT");
|
||||
assertThat(refreshed.path("alternatives").findValuesAsText("componentCode")).doesNotContain("CW-ARM");
|
||||
}
|
||||
|
||||
@Test void prefersRequirementsOnlyAfterHardRequirementsAndDoesNotRequireDegradationForPreferences() throws Exception {
|
||||
components(true, 20);
|
||||
jdbc.update("UPDATE component SET mass_kg=8,torque_nm=40 WHERE component_code='CW-ARM-ALT'");
|
||||
@@ -501,8 +531,9 @@ class DemandFlowApiTest {
|
||||
}
|
||||
if (mount) info.putObject("assembly").put("mountingFrame", root).put("pairingConvention", "coincident_frames");
|
||||
String prefix = "cadworld/components/" + code + "/urdf/batch/";
|
||||
jdbc.update("INSERT INTO component (component_code,component_name,category,description,mass_kg,degrees_of_freedom,torque_nm,bom_list,urdf_info,urdf_prefix,urdf_main_object_key,urdf_files) VALUES (?,?,?,'机器人',?,?,?,?,?,?,?,?)",
|
||||
code, code, category, mass, degrees, torque, "{\"nested\":{\"parts\":[\"BOLT\"]}}", info.toString(), prefix, prefix + "robot.urdf", "[{\"relativePath\":\"robot.urdf\",\"sizeBytes\":10},{\"relativePath\":\"meshes/a.stl\",\"sizeBytes\":20}]");
|
||||
jdbc.update("INSERT INTO component (component_code,component_name,category,description,mass_kg,degrees_of_freedom,torque_nm,bom_list,urdf_info,step_object_key,urdf_prefix,urdf_main_object_key,urdf_files) VALUES (?,?,?,'机器人',?,?,?,?,?,?,?,?,?)",
|
||||
code, code, category, mass, degrees, torque, "{\"nested\":{\"parts\":[\"BOLT\"]}}", info.toString(),
|
||||
"cadworld/components/" + code + "/step/batch/model.step", prefix, prefix + "robot.urdf", "[{\"relativePath\":\"robot.urdf\",\"sizeBytes\":10},{\"relativePath\":\"meshes/a.stl\",\"sizeBytes\":20}]");
|
||||
}
|
||||
private MockMultipartFile image() { return new MockMultipartFile("file", "private.png", "image/png", Base64.getDecoder().decode("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+j2ioAAAAASUVORK5CYII=")); }
|
||||
private static Path directory() { try { return Files.createTempDirectory("cadworld-demand-test-"); } catch (IOException exception) { throw new IllegalStateException(exception); } }
|
||||
|
||||
+4
-4
@@ -8,8 +8,8 @@ import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
public record CreateComponentRequest(
|
||||
@NotBlank @Size(max = 128) String componentName,
|
||||
@NotBlank @Size(max = 64) String category,
|
||||
@Size(max = 128) String componentName,
|
||||
@Size(max = 64) String category,
|
||||
String description,
|
||||
@Size(max = 128) String material,
|
||||
@DecimalMin("0") @Digits(integer = 12, fraction = 6) BigDecimal massKg,
|
||||
@@ -19,12 +19,12 @@ public record CreateComponentRequest(
|
||||
@Size(max = 128) String size,
|
||||
@DecimalMin("0") @Digits(integer = 12, fraction = 6) BigDecimal torqueNm,
|
||||
JsonNode bomList,
|
||||
@NotNull JsonNode urdfInfo,
|
||||
JsonNode urdfInfo,
|
||||
@Size(max = 100) List<@NotNull @Valid CustomField> basicFields,
|
||||
@Size(max = 100) List<@NotNull @Valid CustomField> parameterFields,
|
||||
@NotBlank @Size(max = 4096) String uploadSessionToken,
|
||||
@NotBlank @Size(max = 512) String stepObjectKey,
|
||||
@NotEmpty @Size(max = 1000) List<@NotBlank @Size(max = 512) String> urdfObjectKeys
|
||||
@Size(max = 1000) List<@NotBlank @Size(max = 512) String> urdfObjectKeys
|
||||
) implements ComponentForm {
|
||||
@Override public String toString() { return "CreateComponentRequest[redacted]"; }
|
||||
}
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ public class ComponentConverter {
|
||||
private final ObjectMapper objectMapper;
|
||||
private final ObjectStorageUrlResolver urls;
|
||||
|
||||
public void applyForm(Component component, ComponentForm form) {
|
||||
public void applyForm(Component component, ComponentForm form, boolean requireUrdfInfo) {
|
||||
component.setComponentName(text(form.componentName()));
|
||||
component.setCategory(text(form.category()));
|
||||
String description = form.description() == null ? "" : form.description();
|
||||
@@ -44,7 +44,7 @@ public class ComponentConverter {
|
||||
component.setSize(text(form.size()));
|
||||
component.setTorqueNm(number(form.torqueNm()));
|
||||
component.setBomList(jsonContainer(form.bomList(), "bomList", false));
|
||||
component.setUrdfInfo(jsonContainer(form.urdfInfo(), "urdfInfo", true));
|
||||
component.setUrdfInfo(jsonContainer(form.urdfInfo(), "urdfInfo", requireUrdfInfo));
|
||||
component.setBasicFields(objectMapper.valueToTree(fields(form.basicFields())));
|
||||
component.setParameterFields(objectMapper.valueToTree(fields(form.parameterFields())));
|
||||
}
|
||||
|
||||
+9
-4
@@ -14,6 +14,7 @@ import com.linkerbot.cadworld.dto.component.UpdateComponentRequest;
|
||||
import com.linkerbot.cadworld.entity.Component;
|
||||
import com.linkerbot.cadworld.mapper.ComponentMapper;
|
||||
import com.linkerbot.cadworld.service.ComponentService;
|
||||
import com.linkerbot.cadworld.service.impl.ComponentUploadSupport.VerifiedUrdf;
|
||||
import com.linkerbot.cadworld.service.support.ComponentUploadSessionSupport;
|
||||
import com.linkerbot.cadworld.service.support.ComponentUploadSessionTokenProvider.UploadSessionClaims;
|
||||
import java.util.List;
|
||||
@@ -58,7 +59,7 @@ public class ComponentServiceImpl implements ComponentService {
|
||||
snapshot(current);
|
||||
validateUpdate(current, request);
|
||||
replaceResources(userId, current, request);
|
||||
converter.applyForm(current, request);
|
||||
converter.applyForm(current, request, true);
|
||||
current.setVersion(request.version() + 1);
|
||||
ComponentResponse response = transactions.execute(status -> {
|
||||
int changed = componentMapper.update(current, new LambdaUpdateWrapper<Component>()
|
||||
@@ -121,13 +122,17 @@ public class ComponentServiceImpl implements ComponentService {
|
||||
OperationTargetHolder.set("COMPONENT", "", session.componentCode(), text(request.componentName()));
|
||||
Component component = new Component();
|
||||
component.setComponentCode(session.componentCode());
|
||||
converter.applyForm(component, request);
|
||||
converter.applyForm(component, request, false);
|
||||
component.setStepObjectKey(uploads.verifyStep(session, request.stepObjectKey()));
|
||||
converter.applyUrdf(component, uploads.verifyUrdf(session, request.urdfObjectKeys()));
|
||||
List<String> urdfObjectKeys = request.urdfObjectKeys() == null ? List.of() : request.urdfObjectKeys();
|
||||
VerifiedUrdf urdf = urdfObjectKeys.isEmpty()
|
||||
? new VerifiedUrdf("", "", List.of())
|
||||
: uploads.verifyUrdf(session, urdfObjectKeys);
|
||||
converter.applyUrdf(component, urdf);
|
||||
component.setVersion(1L);
|
||||
component.setDeleted(0);
|
||||
log.info("组件上传资源校验完成 componentCode={} urdfFileCount={} requestId={}",
|
||||
component.getComponentCode(), request.urdfObjectKeys().size(), RequestIdHolder.get());
|
||||
component.getComponentCode(), urdfObjectKeys.size(), RequestIdHolder.get());
|
||||
return component;
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -16,7 +16,8 @@ record AssemblyMetadata(String rootLink, List<Port> ports, int invalidPorts) {
|
||||
|
||||
static AssemblyMetadata read(Component component) {
|
||||
JsonNode info = component.getUrdfInfo();
|
||||
if (NormalizedMatchRequest.text(component.getUrdfMainObjectKey()).isEmpty() || info == null || !info.isObject()
|
||||
if (NormalizedMatchRequest.text(component.getStepObjectKey()).isEmpty()
|
||||
|| NormalizedMatchRequest.text(component.getUrdfMainObjectKey()).isEmpty() || info == null || !info.isObject()
|
||||
|| !info.path("rootLink").isTextual() || info.path("rootLink").asText().isBlank()
|
||||
|| !info.path("frames").isArray()) return null;
|
||||
Map<String, Integer> nameCounts = new HashMap<>();
|
||||
|
||||
+4
-1
@@ -33,6 +33,8 @@ public class PublicComponentQueryService {
|
||||
long cursor = 0;
|
||||
while (true) {
|
||||
List<Component> page = mapper.selectList(candidateFields().in(Component::getCategory, aliases)
|
||||
.isNotNull(Component::getStepObjectKey).ne(Component::getStepObjectKey, "")
|
||||
.isNotNull(Component::getUrdfMainObjectKey).ne(Component::getUrdfMainObjectKey, "")
|
||||
.gt(Component::getId, cursor).orderByAsc(Component::getId).last("LIMIT 200"));
|
||||
for (Component component : page) consumer.accept(component);
|
||||
if (page.size() < 200) return;
|
||||
@@ -65,7 +67,8 @@ public class PublicComponentQueryService {
|
||||
return new LambdaQueryWrapper<Component>().select(Component::getId, Component::getComponentCode,
|
||||
Component::getComponentName, Component::getCategory, Component::getDescription, Component::getMaterial,
|
||||
Component::getMassKg, Component::getDegreesOfFreedom, Component::getFunctionDescription, Component::getShape,
|
||||
Component::getSize, Component::getTorqueNm, Component::getUrdfInfo, Component::getUrdfMainObjectKey);
|
||||
Component::getSize, Component::getTorqueNm, Component::getUrdfInfo,
|
||||
Component::getStepObjectKey, Component::getUrdfMainObjectKey);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<Component> publicFields() {
|
||||
|
||||
Reference in New Issue
Block a user