商品模块属性组增删改
parent
7310116a85
commit
e8392009d0
|
@ -45,4 +45,10 @@ public class AsCategoryAttribute extends BaseEntity {
|
|||
private Long attributeId;
|
||||
|
||||
|
||||
public static AsCategoryAttribute categoryBuild(Long categoryInfoId,Long attributeId){
|
||||
return AsCategoryAttribute.builder()
|
||||
.categoryId(categoryInfoId)
|
||||
.attributeId(attributeId)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,4 +45,10 @@ public class AsCategoryAttributeGroup extends BaseEntity {
|
|||
private Long attributeGroupId;
|
||||
|
||||
|
||||
public static AsCategoryAttributeGroup categoryAttributeGroup(Long categoryId,Long attributeGroupId){
|
||||
return AsCategoryAttributeGroup.builder()
|
||||
.categoryId(categoryId)
|
||||
.attributeGroupId(attributeGroupId)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,4 +44,10 @@ public class AsCategoryBrand extends BaseEntity {
|
|||
@ApiModelProperty(name = "品牌id", value = "品牌id", required = true)
|
||||
private Long brandId;
|
||||
|
||||
public static AsCategoryBrand categoryBrand(Long categoryId,Long brandId){
|
||||
return AsCategoryBrand.builder()
|
||||
.categoryId(categoryId)
|
||||
.brandId(brandId)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.muyu.product.domain;
|
|||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.muyu.product.domain.model.CategoryInfoSaveModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
@ -15,6 +16,9 @@ import com.muyu.product.domain.req.CategoryInfoSaveReq;
|
|||
import com.muyu.product.domain.req.CategoryInfoEditReq;
|
||||
import com.muyu.common.core.web.domain.TreeEntity;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* 品类信息对象 category_info
|
||||
*
|
||||
|
@ -72,13 +76,27 @@ public class CategoryInfo extends TreeEntity {
|
|||
/**
|
||||
* 添加构造器
|
||||
*/
|
||||
public static CategoryInfo saveBuild(CategoryInfoSaveReq categoryInfoSaveReq){
|
||||
public static CategoryInfo saveBuild(CategoryInfoSaveReq categoryInfoSaveReq, Supplier<String> supplier){
|
||||
return CategoryInfo.builder()
|
||||
.name(categoryInfoSaveReq.getName())
|
||||
.image(categoryInfoSaveReq.getImage())
|
||||
.start(categoryInfoSaveReq.getStart())
|
||||
.introduction(categoryInfoSaveReq.getIntroduction())
|
||||
.parentId(categoryInfoSaveReq.getParentId())
|
||||
.createBy(supplier.get())
|
||||
.createTime(new Date())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static CategoryInfo saveModelBuild(CategoryInfoSaveModel categoryInfoSaveModel){
|
||||
return CategoryInfo.builder()
|
||||
.name(categoryInfoSaveModel.getName())
|
||||
.image(categoryInfoSaveModel.getImage())
|
||||
.start(categoryInfoSaveModel.getStart())
|
||||
.introduction(categoryInfoSaveModel.getIntroduction())
|
||||
.parentId(categoryInfoSaveModel.getParentId())
|
||||
.createBy(categoryInfoSaveModel.getCreateBy())
|
||||
.createTime(new Date())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package com.muyu.product.domain.model;
|
||||
|
||||
import com.muyu.common.core.web.domain.TreeEntity;
|
||||
import com.muyu.product.domain.req.CategoryInfoSaveReq;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @ClassName CategoryInfoSaveModel
|
||||
* @Description 描述
|
||||
* @Author Xin.Yao
|
||||
* @Date 2024/3/3 8:52
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class CategoryInfoSaveModel extends TreeEntity {
|
||||
private String name;
|
||||
private String image;
|
||||
private String start;
|
||||
private String introduction;
|
||||
|
||||
/**
|
||||
* 商品属性组关联ID
|
||||
*/
|
||||
private List<Long> attributeGroupIdList;
|
||||
/**
|
||||
* 商品属性关联ID
|
||||
*/
|
||||
private List<Long> attributeIdList;
|
||||
|
||||
/**
|
||||
* 商品品牌组关联ID
|
||||
*/
|
||||
private List<Long> brandIdList;
|
||||
|
||||
/**
|
||||
* 添加构造器
|
||||
*/
|
||||
public static CategoryInfoSaveModel saveBuild(CategoryInfoSaveReq categoryInfoSaveReq, Supplier<String> supplier){
|
||||
return CategoryInfoSaveModel.builder()
|
||||
.name(categoryInfoSaveReq.getName())
|
||||
.image(categoryInfoSaveReq.getImage())
|
||||
.start(categoryInfoSaveReq.getStart())
|
||||
.introduction(categoryInfoSaveReq.getIntroduction())
|
||||
.parentId(categoryInfoSaveReq.getParentId())
|
||||
.attributeGroupIdList(categoryInfoSaveReq.getAttributeGroupIdList())
|
||||
.attributeIdList(categoryInfoSaveReq.getAttributeIdList())
|
||||
.brandIdList(categoryInfoSaveReq.getBrandIdList())
|
||||
.createBy(supplier.get())
|
||||
.createTime(new Date())
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -8,6 +8,8 @@ import lombok.experimental.SuperBuilder;
|
|||
import io.swagger.annotations.*;
|
||||
import com.muyu.common.core.web.domain.TreeEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 品类信息对象 category_info
|
||||
*
|
||||
|
@ -49,4 +51,7 @@ public class CategoryInfoSaveReq extends TreeEntity {
|
|||
private String introduction;
|
||||
|
||||
|
||||
private List<Long> attributeGroupIdList;
|
||||
private List<Long> attributeIdList;
|
||||
private List<Long> brandIdList;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package com.muyu.product.domain.resp;
|
||||
|
||||
import com.muyu.product.domain.AttributeGroup;
|
||||
import com.muyu.product.domain.AttributeInfo;
|
||||
import com.muyu.product.domain.BrandInfo;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName CategoryParentCommonElementResp
|
||||
* @Description 描述
|
||||
* @Author Xin.Yao
|
||||
* @Date 2024/3/3 8:15
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CategoryParentCommonElementResp {
|
||||
|
||||
/**
|
||||
* 属性集合
|
||||
*/
|
||||
private List<AttributeInfo> attributeInfoList;
|
||||
/**
|
||||
* 属性组集合
|
||||
*/
|
||||
private List<AttributeGroup> attributeGroupList;
|
||||
/**
|
||||
* 品牌集合
|
||||
*/
|
||||
private List<BrandInfo> brandInfoList;
|
||||
}
|
|
@ -112,6 +112,7 @@ public class AttributeGroupController extends BaseController {
|
|||
@ApiOperation("删除属性组")
|
||||
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1,2,3,4")
|
||||
public Result<String> remove(@PathVariable List<Long> ids) {
|
||||
System.out.println();
|
||||
return toAjax(attributeGroupService.removeBatchByIds(ids));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package com.muyu.product.controller;
|
|||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.product.domain.model.CategoryInfoSaveModel;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -81,7 +83,8 @@ public class CategoryInfoController extends BaseController {
|
|||
@PostMapping
|
||||
@ApiOperation("新增品类信息")
|
||||
public Result<String> add(@RequestBody CategoryInfoSaveReq categoryInfoSaveReq) {
|
||||
return toAjax(categoryInfoService.save(CategoryInfo.saveBuild(categoryInfoSaveReq)));
|
||||
return toAjax(categoryInfoService.save(
|
||||
CategoryInfoSaveModel.saveBuild(categoryInfoSaveReq, SecurityUtils::getUsername)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,4 +109,15 @@ public class CategoryInfoController extends BaseController {
|
|||
public Result<String> remove(@PathVariable List<Long> ids) {
|
||||
return toAjax(categoryInfoService.removeBatchByIds(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过品类id查找包括父级属性集合,属性组集合以及品牌集合
|
||||
*/
|
||||
@GetMapping("/parentCommonElement/{categoryId}")
|
||||
@ApiOperation("通过品类id查找包括父级属性集合,属性组集合以及品牌集合")
|
||||
@ApiImplicitParam(name = "categoryId", value = "categoryId", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1")
|
||||
public Result parentCommonElement(@PathVariable(value = "categoryId") Long categoryId){
|
||||
return categoryInfoService.parentCommonElement(categoryId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
package com.muyu.product.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.product.domain.AttributeGroup;
|
||||
import com.muyu.product.domain.AttributeInfo;
|
||||
import com.muyu.product.domain.BrandInfo;
|
||||
import com.muyu.product.domain.CategoryInfo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.product.domain.model.CategoryInfoSaveModel;
|
||||
|
||||
/**
|
||||
* 品类信息Service接口
|
||||
|
@ -19,4 +25,31 @@ public interface CategoryInfoService extends IService<CategoryInfo> {
|
|||
*/
|
||||
public List<CategoryInfo> list(CategoryInfo categoryInfo);
|
||||
|
||||
/**
|
||||
*通过品类id查找包括父级属性集合,属性组集合以及品牌集合
|
||||
* @param categoryId
|
||||
* @return 父级以上属性,属性组,品牌集合
|
||||
*/
|
||||
Result parentCommonElement(Long categoryId);
|
||||
|
||||
/**
|
||||
* 通过品类id获取属性组集合
|
||||
* @param categoryId
|
||||
* @return 属性组集合
|
||||
*/
|
||||
List<AttributeGroup> getAttributeGroupList(Long categoryId);
|
||||
/**
|
||||
* 通过品类id获取属性集合
|
||||
* @param categoryId
|
||||
* @return 属性集合
|
||||
*/
|
||||
List<AttributeInfo> getAttributeInfoList(Long categoryId);
|
||||
/**
|
||||
* 通过品类id获取品牌集合
|
||||
* @param categoryId
|
||||
* @return 品牌集合
|
||||
*/
|
||||
List<BrandInfo> getBrandInfoList(Long categoryId);
|
||||
|
||||
public boolean save(CategoryInfoSaveModel categoryInfoSaveModel);
|
||||
}
|
||||
|
|
|
@ -68,12 +68,11 @@ public class AttributeInfoServiceImpl extends ServiceImpl<AttributeInfoMapper, A
|
|||
List<Long> longs = asAttributeGroupService.list(queryWrapper).stream()
|
||||
.map(AsAttributeGroup::getAttributeId)
|
||||
.toList();
|
||||
System.out.println("====="+longs.toString());
|
||||
List<Long> longs1 = new ArrayList<>();
|
||||
if(longs ==null || longs.isEmpty()){
|
||||
return null;
|
||||
}
|
||||
return this.listByIds(
|
||||
asAttributeGroupService.list(queryWrapper).stream()
|
||||
.map(AsAttributeGroup::getAttributeId)
|
||||
.toList()
|
||||
longs
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
package com.muyu.product.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.ObjUtils;
|
||||
import com.muyu.product.domain.*;
|
||||
import com.muyu.product.domain.model.CategoryInfoSaveModel;
|
||||
import com.muyu.product.domain.resp.CategoryParentCommonElementResp;
|
||||
import com.muyu.product.service.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.muyu.product.mapper.CategoryInfoMapper;
|
||||
import com.muyu.product.domain.CategoryInfo;
|
||||
import com.muyu.product.service.CategoryInfoService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
|
||||
|
@ -21,6 +26,25 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
@Service
|
||||
public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, CategoryInfo> implements CategoryInfoService {
|
||||
|
||||
@Autowired
|
||||
private AsCategoryAttributeService asCategoryAttributeService;
|
||||
|
||||
@Autowired
|
||||
private AsCategoryAttributeGroupService asCategoryAttributeGroupService;
|
||||
|
||||
@Autowired
|
||||
private AsCategoryBrandService asCategoryBrandService;
|
||||
|
||||
@Autowired
|
||||
private AttributeInfoService attributeInfoService;
|
||||
|
||||
@Autowired
|
||||
private AsAttributeGroupService asAttributeGroupService;
|
||||
|
||||
@Autowired
|
||||
private BrandInfoService brandInfoService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询品类信息列表
|
||||
*
|
||||
|
@ -58,4 +82,91 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
|
|||
|
||||
return list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result parentCommonElement(Long categoryId) {
|
||||
return Result.success(CategoryParentCommonElementResp.builder()
|
||||
.attributeGroupList(getAttributeGroupList(categoryId))
|
||||
.attributeInfoList(getAttributeInfoList(categoryId))
|
||||
.brandInfoList(getBrandInfoList(categoryId))
|
||||
.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过品类id获取属性组集合
|
||||
* @param categoryId
|
||||
* @return 属性组集合
|
||||
*/
|
||||
@Override
|
||||
public List<AttributeGroup> getAttributeGroupList(Long categoryId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过品类id获取属性集合
|
||||
* @param categoryId
|
||||
* @return 属性集合
|
||||
*/
|
||||
@Override
|
||||
public List<AttributeInfo> getAttributeInfoList(Long categoryId) {
|
||||
ArrayList<AttributeInfo> attributeInfoList = new ArrayList<>();
|
||||
LambdaQueryWrapper<AsCategoryAttribute> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(AsCategoryAttribute::getCategoryId,categoryId);
|
||||
List<AsCategoryAttribute> asCategoryAttributeList = asCategoryAttributeService.list(queryWrapper);
|
||||
if (asCategoryAttributeList != null && asCategoryAttributeList.isEmpty()){
|
||||
List<Long> attributeIdList = asCategoryAttributeList.stream()
|
||||
.map(AsCategoryAttribute::getAttributeId)
|
||||
.toList();
|
||||
attributeInfoList.addAll(attributeInfoService.listByIds(attributeIdList));
|
||||
}
|
||||
CategoryInfo categoryInfo = this.getById(categoryId);
|
||||
if (categoryInfo.getParentId() !=0){
|
||||
if (attributeInfoList.isEmpty()){
|
||||
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过品类id获取品牌集合
|
||||
* @param categoryId
|
||||
* @return 品牌集合
|
||||
*/
|
||||
@Override
|
||||
public List<BrandInfo> getBrandInfoList(Long categoryId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(CategoryInfoSaveModel categoryInfoSaveModel) {
|
||||
CategoryInfo categoryInfo = CategoryInfo.saveModelBuild(categoryInfoSaveModel);
|
||||
boolean save = this.save(categoryInfo);
|
||||
Long categoryInfoId = categoryInfo.getId();
|
||||
List<Long> attributeIdList = categoryInfoSaveModel.getAttributeIdList();
|
||||
if (attributeIdList != null && !attributeIdList.isEmpty()){
|
||||
asCategoryAttributeService.saveBatch(
|
||||
attributeIdList.stream()
|
||||
.map(attributeId -> AsCategoryAttribute.categoryBuild(categoryInfoId,attributeId))
|
||||
.toList()
|
||||
);
|
||||
}
|
||||
List<Long> attributeGroupIdList = categoryInfoSaveModel.getAttributeGroupIdList();
|
||||
if (attributeGroupIdList != null && !attributeGroupIdList.isEmpty()){
|
||||
asCategoryAttributeGroupService.saveBatch(
|
||||
attributeGroupIdList.stream()
|
||||
.map(attributeGrooupId -> AsCategoryAttributeGroup.categoryAttributeGroup(categoryInfoId,attributeGrooupId))
|
||||
.toList()
|
||||
);
|
||||
}
|
||||
List<Long> brandIdList = categoryInfoSaveModel.getBrandIdList();
|
||||
if (brandIdList != null && !brandIdList.isEmpty()){
|
||||
asCategoryBrandService.saveBatch(
|
||||
brandIdList.stream()
|
||||
.map(brandId -> AsCategoryBrand.categoryBrand(categoryInfoId,brandId))
|
||||
.toList()
|
||||
);
|
||||
}
|
||||
return save;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue