This commit is contained in:
@@ -156,16 +156,12 @@ public class ProductController {
|
|||||||
@PostMapping("/categories/{categoryId}/attributes")
|
@PostMapping("/categories/{categoryId}/attributes")
|
||||||
public Result<Void> saveCategoryAttributes(
|
public Result<Void> saveCategoryAttributes(
|
||||||
@PathVariable String categoryId,
|
@PathVariable String categoryId,
|
||||||
@RequestBody Map<String, Object> body,
|
@RequestBody List attributes,
|
||||||
@RequestHeader(value = "X-User-Role", required = false) String role) {
|
@RequestHeader(value = "X-User-Role", required = false) String role) {
|
||||||
if (!"admin".equals(role)) {
|
if (!"admin".equals(role)) {
|
||||||
return Result.error("只有管理员可以操作");
|
return Result.error("只有管理员可以操作");
|
||||||
}
|
}
|
||||||
List attrs = (List) body.get("attributes");
|
categoryAttributeService.saveAttributes(categoryId, attributes);
|
||||||
if (attrs == null) {
|
|
||||||
attrs = (List) body.get("list");
|
|
||||||
}
|
|
||||||
categoryAttributeService.saveAttributes(categoryId, attrs);
|
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,13 @@ public class CategoryAttributeServiceImpl implements CategoryAttributeService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void saveAttributes(String categoryId, List<CategoryAttribute> attrs) {
|
public void saveAttributes(String categoryId, List<CategoryAttribute> attrs) {
|
||||||
|
System.out.println("=== saveAttributes called ===");
|
||||||
|
System.out.println("categoryId: " + categoryId);
|
||||||
|
System.out.println("attrs size: " + (attrs != null ? attrs.size() : 0));
|
||||||
|
if (attrs != null) {
|
||||||
|
attrs.forEach(a -> System.out.println(" attr: " + a.getName() + ", type=" + a.getAttrType() + ", unit=" + a.getUnit()));
|
||||||
|
}
|
||||||
|
|
||||||
// 删除旧属性
|
// 删除旧属性
|
||||||
categoryAttributeMapper.delete(new LambdaQueryWrapper<CategoryAttribute>()
|
categoryAttributeMapper.delete(new LambdaQueryWrapper<CategoryAttribute>()
|
||||||
.eq(CategoryAttribute::getCategoryId, categoryId));
|
.eq(CategoryAttribute::getCategoryId, categoryId));
|
||||||
@@ -44,6 +51,7 @@ public class CategoryAttributeServiceImpl implements CategoryAttributeService {
|
|||||||
categoryAttributeMapper.insert(attr);
|
categoryAttributeMapper.insert(attr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
System.out.println("=== saveAttributes done ===");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user