品类新增,但是该了请求方法,需要改变id

master
20300 2024-03-08 21:29:56 +08:00
parent fecbad9105
commit 65238bdd40
5 changed files with 136 additions and 14 deletions

View File

@ -35,10 +35,10 @@ public class AttributeGroupController {
//获取属性组列表
@GetMapping("/getAttributeGroupList")
public Result<List<AttributeGroupResp>> getAttributeGroupList(@RequestParam("attributeName") String attributeName){
public Result<List<AttributeGroupResp>> getAttributeGroupList(@RequestParam("attributeGroupId") Integer attributeGroupId){
QueryWrapper<AttributeGroup> queryWrapper = new QueryWrapper<>();
if (attributeName!=null && !"".equals(attributeName)){
queryWrapper.like("name",attributeName);
if (attributeGroupId!=null && !"".equals(attributeGroupId) && attributeGroupId != 0){
queryWrapper.eq("id",attributeGroupId);
}
//这里得到的是属性组集合

View File

@ -30,10 +30,10 @@ public class AttributeInfoController {
//查询所有属性
@RequiresPermissions("product:attributeInfo:list")
@GetMapping("/list")
public Result<List<AttributeInfo>> getAttributeInfoList(@RequestParam("name") String name){
public Result<List<AttributeInfo>> getAttributeInfoList(@RequestParam("attributeId") Integer attributeId){
LambdaQueryWrapper<AttributeInfo> queryWrapper = new LambdaQueryWrapper<>();
if (StringUtils.isNotEmpty(name)){
queryWrapper.like(AttributeInfo::getName,name);
if (attributeId != null && !"".equals(attributeId) && attributeId != 0){
queryWrapper.eq(AttributeInfo::getId,attributeId);
}
List<AttributeInfo> list = attributeInfoService.list(queryWrapper);
return Result.success(list);

View File

@ -43,10 +43,10 @@ public class BrandInfoController {
}
@GetMapping("/getBrandList")
public Result<List<BrandInfo>> getBrandList(@RequestParam("likeName") String likeName){
public Result<List<BrandInfo>> getBrandList(@RequestParam("brandId") Integer brandId){
LambdaQueryWrapper<BrandInfo> wrapper = new LambdaQueryWrapper<>();
if (StringUtils.isNotEmpty(likeName)){
wrapper.like(BrandInfo::getName,likeName);
if (brandId != null && !"".equals(brandId) && brandId != 0){
wrapper.eq(BrandInfo::getId,brandId);
}
List<BrandInfo> list = brandInfoService.list(wrapper);
return Result.success(list);

View File

@ -3,18 +3,18 @@ package com.muyu.product.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.product.domain.AsCategoryAttribute;
import com.muyu.product.domain.AsCategoryAttributeGroup;
import com.muyu.product.domain.AsCategoryBrand;
import com.muyu.product.domain.CategoryInfo;
import com.muyu.product.domain.req.InsertCategoryReq;
import com.muyu.product.service.AsCategoryAttributeGroupService;
import com.muyu.product.service.AsCategoryAttributeService;
import com.muyu.product.service.AsCategoryBrandService;
import com.muyu.product.service.CategoryInfoService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -32,7 +32,7 @@ public class CategoryController {
@Autowired
private AsCategoryBrandService asCategoryBrandService;
@Autowired
private AsCategoryAttributeGroupService attributeGroupService;
private AsCategoryAttributeGroupService asCategoryAttributeGroupService;
@Autowired
private CategoryInfoService categoryInfoService;
@ -45,4 +45,37 @@ public class CategoryController {
List<CategoryInfo> list = categoryInfoService.list(queryWrapper);
return Result.success(list);
}
@PostMapping("/insertCategory")
public Result insertCategory(@RequestBody InsertCategoryReq insertCategoryReq){
if (insertCategoryReq == null){
return Result.error("未传入新增对象");
}
if (insertCategoryReq.getAttributeList().size()==0){
return Result.error("未选属性");
}
if (insertCategoryReq.getAttributeGroupList().size()==0){
return Result.error("未选属性组");
}
if (insertCategoryReq.getBrandList().size()==0){
return Result.error("未选品牌");
}
try {
CategoryInfo categoryInfo = InsertCategoryReq.builderCategoryInfo(insertCategoryReq);
categoryInfoService.save(categoryInfo);
insertCategoryReq.setId(categoryInfo.getId());
//品类属性
List<AsCategoryAttribute> asCategoryAttributes = InsertCategoryReq.builderAsCategoryAttribute(insertCategoryReq);
asCategoryAttributeService.saveBatch(asCategoryAttributes);
//品类属性组
List<AsCategoryAttributeGroup> asCategoryAttributeGroups = InsertCategoryReq.builderAsAttributeAttributeGroup(insertCategoryReq);
//品类品牌
asCategoryAttributeGroupService.saveBatch(asCategoryAttributeGroups);
List<AsCategoryBrand> asCategoryBrands = InsertCategoryReq.builderAsCategoryBrand(insertCategoryReq);
asCategoryBrandService.saveBatch(asCategoryBrands);
}catch (Exception e){
return Result.error("出错了哦!");
}
return Result.success();
}
}

View File

@ -0,0 +1,89 @@
package com.muyu.product.domain.req;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.product.domain.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @ClassName InsertCategoryReq
* @Description
* @Author ZHIHAO.DAI
* @Date 2024/3/8 20:27
*/
@Data
@ToString
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class InsertCategoryReq {
private Integer id;
private String image;
private String introduction;
private String name;
private Integer parentId;
private List<AttributeGroup> attributeGroupList;
private List<AttributeInfo> attributeList;
private List<BrandInfo> brandList;
//使用新增请求对象构建List<AsCategoryAttributeGroup>
public static List<AsCategoryAttributeGroup> builderAsAttributeAttributeGroup(InsertCategoryReq insertCategoryReq){
return (List<AsCategoryAttributeGroup>) insertCategoryReq.getAttributeGroupList()
.stream()
.map(attributeGroup ->
AsCategoryAttributeGroup
.builder()
.attributeGroupId(attributeGroup.getId())
.categoryId(insertCategoryReq.getId())
.createTime(new Date())
.createBy(SecurityUtils.getUsername())
.remark("")
.build()
).toList();
}
//使用请求对象构建 CategoryInfo
public static CategoryInfo builderCategoryInfo(InsertCategoryReq insertCategoryReq){
return CategoryInfo.builder()
.id(insertCategoryReq.getId())
.image(insertCategoryReq.getImage())
.name(insertCategoryReq.getName())
.parentId(insertCategoryReq.getParentId())
.introduction(insertCategoryReq.introduction)
.createBy(SecurityUtils.getUsername())
.createTime(new Date())
.build();
}
//使用请求对象构建List<AsCategoryBrand>
public static List<AsCategoryBrand> builderAsCategoryBrand(InsertCategoryReq insertCategoryReq){
return (List<AsCategoryBrand>) insertCategoryReq.getBrandList()
.stream()
.map(brandInfo -> AsCategoryBrand
.builder()
.brandId(brandInfo.getId())
.categoryId(insertCategoryReq.getId())
.remark("")
.createBy(SecurityUtils.getUsername())
.createTime(new Date())
.build()).toList();
}
//使用请求对象构建List<AsCategoryAttribute>
public static List<AsCategoryAttribute> builderAsCategoryAttribute(InsertCategoryReq insertCategoryReq){
return (List<AsCategoryAttribute>) insertCategoryReq.getAttributeList()
.stream()
.map(attributeInfo -> AsCategoryAttribute
.builder()
.attributeId(attributeInfo.getId())
.categoryId(insertCategoryReq.getId())
.createBy(SecurityUtils.getUsername())
.createTime(new Date())
.remark("")
.build()).toList();
}
}