品类新增,但是该了请求方法,需要改变id
parent
fecbad9105
commit
65238bdd40
|
@ -35,10 +35,10 @@ public class AttributeGroupController {
|
||||||
|
|
||||||
//获取属性组列表
|
//获取属性组列表
|
||||||
@GetMapping("/getAttributeGroupList")
|
@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<>();
|
QueryWrapper<AttributeGroup> queryWrapper = new QueryWrapper<>();
|
||||||
if (attributeName!=null && !"".equals(attributeName)){
|
if (attributeGroupId!=null && !"".equals(attributeGroupId) && attributeGroupId != 0){
|
||||||
queryWrapper.like("name",attributeName);
|
queryWrapper.eq("id",attributeGroupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
//这里得到的是属性组集合
|
//这里得到的是属性组集合
|
||||||
|
|
|
@ -30,10 +30,10 @@ public class AttributeInfoController {
|
||||||
//查询所有属性
|
//查询所有属性
|
||||||
@RequiresPermissions("product:attributeInfo:list")
|
@RequiresPermissions("product:attributeInfo:list")
|
||||||
@GetMapping("/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<>();
|
LambdaQueryWrapper<AttributeInfo> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
if (StringUtils.isNotEmpty(name)){
|
if (attributeId != null && !"".equals(attributeId) && attributeId != 0){
|
||||||
queryWrapper.like(AttributeInfo::getName,name);
|
queryWrapper.eq(AttributeInfo::getId,attributeId);
|
||||||
}
|
}
|
||||||
List<AttributeInfo> list = attributeInfoService.list(queryWrapper);
|
List<AttributeInfo> list = attributeInfoService.list(queryWrapper);
|
||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
|
|
|
@ -43,10 +43,10 @@ public class BrandInfoController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/getBrandList")
|
@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<>();
|
LambdaQueryWrapper<BrandInfo> wrapper = new LambdaQueryWrapper<>();
|
||||||
if (StringUtils.isNotEmpty(likeName)){
|
if (brandId != null && !"".equals(brandId) && brandId != 0){
|
||||||
wrapper.like(BrandInfo::getName,likeName);
|
wrapper.eq(BrandInfo::getId,brandId);
|
||||||
}
|
}
|
||||||
List<BrandInfo> list = brandInfoService.list(wrapper);
|
List<BrandInfo> list = brandInfoService.list(wrapper);
|
||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
|
|
|
@ -3,18 +3,18 @@ package com.muyu.product.controller;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.core.utils.StringUtils;
|
import com.muyu.common.core.utils.StringUtils;
|
||||||
|
import com.muyu.product.domain.AsCategoryAttribute;
|
||||||
import com.muyu.product.domain.AsCategoryAttributeGroup;
|
import com.muyu.product.domain.AsCategoryAttributeGroup;
|
||||||
|
import com.muyu.product.domain.AsCategoryBrand;
|
||||||
import com.muyu.product.domain.CategoryInfo;
|
import com.muyu.product.domain.CategoryInfo;
|
||||||
|
import com.muyu.product.domain.req.InsertCategoryReq;
|
||||||
import com.muyu.product.service.AsCategoryAttributeGroupService;
|
import com.muyu.product.service.AsCategoryAttributeGroupService;
|
||||||
import com.muyu.product.service.AsCategoryAttributeService;
|
import com.muyu.product.service.AsCategoryAttributeService;
|
||||||
import com.muyu.product.service.AsCategoryBrandService;
|
import com.muyu.product.service.AsCategoryBrandService;
|
||||||
import com.muyu.product.service.CategoryInfoService;
|
import com.muyu.product.service.CategoryInfoService;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ public class CategoryController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private AsCategoryBrandService asCategoryBrandService;
|
private AsCategoryBrandService asCategoryBrandService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private AsCategoryAttributeGroupService attributeGroupService;
|
private AsCategoryAttributeGroupService asCategoryAttributeGroupService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private CategoryInfoService categoryInfoService;
|
private CategoryInfoService categoryInfoService;
|
||||||
|
|
||||||
|
@ -45,4 +45,37 @@ public class CategoryController {
|
||||||
List<CategoryInfo> list = categoryInfoService.list(queryWrapper);
|
List<CategoryInfo> list = categoryInfoService.list(queryWrapper);
|
||||||
return Result.success(list);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue