|
@@ -158,48 +158,4 @@ public class ProductController {
|
|
|
}
|
|
}
|
|
|
return Result.success(result);
|
|
return Result.success(result);
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
- String name = spec.get("name");
|
|
|
|
|
- String value = spec.get("value");
|
|
|
|
|
- if (name == null || value == null) continue;
|
|
|
|
|
-
|
|
|
|
|
- if (!nameToGroupId.containsKey(name)) {
|
|
|
|
|
- nameToGroupId.put(name, groupId++);
|
|
|
|
|
- Map<String, Object> grp = new HashMap<>();
|
|
|
|
|
- grp.put("groupId", nameToGroupId.get(name));
|
|
|
|
|
- grp.put("groupName", name);
|
|
|
|
|
- grp.put("options", new ArrayList<Map<String, Object>>());
|
|
|
|
|
- groups.add(grp);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- Map<String, Object> option = new HashMap<>();
|
|
|
|
|
- option.put("id", sku.getId());
|
|
|
|
|
- option.put("groupId", nameToGroupId.get(name));
|
|
|
|
|
- option.put("name", value);
|
|
|
|
|
- option.put("skuId", sku.getId());
|
|
|
|
|
- option.put("price", sku.getPrice());
|
|
|
|
|
- option.put("stock", sku.getStock());
|
|
|
|
|
- option.put("enabled", sku.getEnabled());
|
|
|
|
|
-
|
|
|
|
|
- for (Map<String, Object> g : groups) {
|
|
|
|
|
- if (g.get("groupId").equals(nameToGroupId.get(name))) {
|
|
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
|
|
- List<Map<String, Object>> opts = (List<Map<String, Object>>) g.get("options");
|
|
|
|
|
- boolean exists = opts.stream().anyMatch(o ->
|
|
|
|
|
- value.equals(o.get("name")) && sku.getId().equals(o.get("skuId")));
|
|
|
|
|
- if (!exists) {
|
|
|
|
|
- opts.add(option);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.warn("parse specs JSON failed for sku {}: {}", sku.getId(), e.getMessage());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- result.put(productId.toString(), groups);
|
|
|
|
|
- }
|
|
|
|
|
- return Result.success(result);
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|