diff --git a/muyu-modules/muyu-product/src/main/java/com/muyu/product/controller/AttributeGroupController.java b/muyu-modules/muyu-product/src/main/java/com/muyu/product/controller/AttributeGroupController.java index 4ac1976..38722b8 100644 --- a/muyu-modules/muyu-product/src/main/java/com/muyu/product/controller/AttributeGroupController.java +++ b/muyu-modules/muyu-product/src/main/java/com/muyu/product/controller/AttributeGroupController.java @@ -58,13 +58,46 @@ public class AttributeGroupController { } @PostMapping("/insertAttributeGroup") public Result insertAttributeGroup(@RequestBody AttributeGroupReq attributeGroupReq){ + if (attributeGroupReq.getAttributeGroupId()==null || "".equals(attributeGroupReq.getAttributeGroupId())){ + AttributeGroup attributeGroup = AttributeGroup.BuildAttributeGroupByReq(attributeGroupReq); + boolean save = attributeGroupService.save(attributeGroup); + System.out.println("添加属性组之后返回的主键:"+attributeGroup.getId()); + + attributeGroupReq.setAttributeGroupId(attributeGroup.getId()); + List asAttributeAttributeGroupList = AsAttributeAttributeGroup.buildAttributeMiddle(attributeGroupReq); + boolean b = asAttributeAttributeGroupService.saveBatch(asAttributeAttributeGroupList); + if (b){ + return Result.success(); + } + return Result.error(); + } + //修改属性组 AttributeGroup attributeGroup = AttributeGroup.BuildAttributeGroupByReq(attributeGroupReq); - boolean save = attributeGroupService.save(attributeGroup); - System.out.println("添加属性组之后返回的主键:"+attributeGroup.getId()); - attributeGroupReq.setAttributeGroupId(attributeGroup.getId()); + System.out.println(attributeGroup); + boolean b = attributeGroupService.updateById(attributeGroup); + //删除中间表 + attributeGroupReq.setAttributeGroupId(attributeGroupReq.getAttributeGroupId()); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.in("attribute_group_id",attributeGroupReq.getAttributeGroupId()); + asAttributeAttributeGroupService.remove(queryWrapper); + //重新得到添加中间表的数据 List asAttributeAttributeGroupList = AsAttributeAttributeGroup.buildAttributeMiddle(attributeGroupReq); - boolean b = asAttributeAttributeGroupService.saveBatch(asAttributeAttributeGroupList); - if (b){ + //添加 + boolean boo = asAttributeAttributeGroupService.saveBatch(asAttributeAttributeGroupList); + if (boo){ + return Result.success(); + } + return Result.error(); + } + + //删除属性组,与属性中间表 + @GetMapping("/deleteAttributeById") + public Result deleteAttributeById(@RequestParam("groupId") Integer groupId){ + boolean b = attributeGroupService.removeById(groupId); + QueryWrapper groupQueryWrapper = new QueryWrapper<>(); + groupQueryWrapper.eq("attribute_group_id",groupId); + boolean remove = asAttributeAttributeGroupService.remove(groupQueryWrapper); + if (remove){ return Result.success(); } return Result.error(); diff --git a/muyu-modules/muyu-product/src/main/java/com/muyu/product/domain/AttributeGroup.java b/muyu-modules/muyu-product/src/main/java/com/muyu/product/domain/AttributeGroup.java index 9fb3b56..0c64425 100644 --- a/muyu-modules/muyu-product/src/main/java/com/muyu/product/domain/AttributeGroup.java +++ b/muyu-modules/muyu-product/src/main/java/com/muyu/product/domain/AttributeGroup.java @@ -41,6 +41,7 @@ public class AttributeGroup extends BaseEntity { public static AttributeGroup BuildAttributeGroupByReq(AttributeGroupReq attributeGroupReq){ return AttributeGroup.builder() + .id(attributeGroupReq.getAttributeGroupId()) .name(attributeGroupReq.getName()) .remark(attributeGroupReq.getRemark()) .createBy(SecurityUtils.getUsername())