这里到完全的属性组

master
20300 2024-03-06 21:03:55 +08:00
parent 2f4bb745de
commit 6207ce4ba6
2 changed files with 39 additions and 5 deletions

View File

@ -58,13 +58,46 @@ public class AttributeGroupController {
} }
@PostMapping("/insertAttributeGroup") @PostMapping("/insertAttributeGroup")
public Result insertAttributeGroup(@RequestBody AttributeGroupReq attributeGroupReq){ 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<AsAttributeAttributeGroup> asAttributeAttributeGroupList = AsAttributeAttributeGroup.buildAttributeMiddle(attributeGroupReq);
boolean b = asAttributeAttributeGroupService.saveBatch(asAttributeAttributeGroupList);
if (b){
return Result.success();
}
return Result.error();
}
//修改属性组
AttributeGroup attributeGroup = AttributeGroup.BuildAttributeGroupByReq(attributeGroupReq); AttributeGroup attributeGroup = AttributeGroup.BuildAttributeGroupByReq(attributeGroupReq);
boolean save = attributeGroupService.save(attributeGroup); System.out.println(attributeGroup);
System.out.println("添加属性组之后返回的主键:"+attributeGroup.getId()); boolean b = attributeGroupService.updateById(attributeGroup);
attributeGroupReq.setAttributeGroupId(attributeGroup.getId()); //删除中间表
attributeGroupReq.setAttributeGroupId(attributeGroupReq.getAttributeGroupId());
QueryWrapper<AsAttributeAttributeGroup> queryWrapper = new QueryWrapper<>();
queryWrapper.in("attribute_group_id",attributeGroupReq.getAttributeGroupId());
asAttributeAttributeGroupService.remove(queryWrapper);
//重新得到添加中间表的数据
List<AsAttributeAttributeGroup> asAttributeAttributeGroupList = AsAttributeAttributeGroup.buildAttributeMiddle(attributeGroupReq); List<AsAttributeAttributeGroup> 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<AsAttributeAttributeGroup> groupQueryWrapper = new QueryWrapper<>();
groupQueryWrapper.eq("attribute_group_id",groupId);
boolean remove = asAttributeAttributeGroupService.remove(groupQueryWrapper);
if (remove){
return Result.success(); return Result.success();
} }
return Result.error(); return Result.error();

View File

@ -41,6 +41,7 @@ public class AttributeGroup extends BaseEntity {
public static AttributeGroup BuildAttributeGroupByReq(AttributeGroupReq attributeGroupReq){ public static AttributeGroup BuildAttributeGroupByReq(AttributeGroupReq attributeGroupReq){
return AttributeGroup.builder() return AttributeGroup.builder()
.id(attributeGroupReq.getAttributeGroupId())
.name(attributeGroupReq.getName()) .name(attributeGroupReq.getName())
.remark(attributeGroupReq.getRemark()) .remark(attributeGroupReq.getRemark())
.createBy(SecurityUtils.getUsername()) .createBy(SecurityUtils.getUsername())