品类获取父级所有的公共元素
parent
2a9c7ef879
commit
7e21256ab6
|
@ -0,0 +1,39 @@
|
|||
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;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @description: 类别父通用元素
|
||||
* @Date 2024-3-1 上午 11:02
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CategoryParentCommonElementResp {
|
||||
|
||||
/**
|
||||
* 属性集合
|
||||
*/
|
||||
private List<AttributeInfo> attributeInfoList;
|
||||
|
||||
/**
|
||||
* 属性组集合
|
||||
*/
|
||||
private List<AttributeGroup> attributeGroupList;
|
||||
|
||||
/**
|
||||
* 品牌集合
|
||||
*/
|
||||
private List<BrandInfo> brandInfoList;
|
||||
|
||||
}
|
|
@ -5,7 +5,11 @@ import java.util.function.Supplier;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.product.domain.AttributeGroup;
|
||||
import com.muyu.product.domain.AttributeInfo;
|
||||
import com.muyu.product.domain.BrandInfo;
|
||||
import com.muyu.product.domain.model.CategoryInfoSaveModel;
|
||||
import com.muyu.product.domain.resp.CategoryParentCommonElementResp;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -111,4 +115,18 @@ public class CategoryInfoController extends BaseController {
|
|||
public Result<String> remove(@PathVariable List<Long> ids) {
|
||||
return toAjax(categoryInfoService.removeBatchByIds(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过品类ID获取父级以上的属性、属性组、品牌集合
|
||||
* @param categoryId 品类ID
|
||||
* @return 父级以上的属性、属性组、品牌集合
|
||||
*/
|
||||
@GetMapping("/parentCommonElement/{categoryId}")
|
||||
@ApiOperation("通过品类ID获取父级以上的属性集合")
|
||||
@ApiImplicitParam(name = "categoryId", value = "categoryId", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class, example = "1")
|
||||
public Result<CategoryParentCommonElementResp> parentCommonElement(
|
||||
@PathVariable(value = "categoryId") Long categoryId
|
||||
) {
|
||||
return Result.success(categoryInfoService.parentCommonElement(categoryId));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
package com.muyu.product.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
import com.muyu.product.domain.resp.CategoryParentCommonElementResp;
|
||||
|
||||
/**
|
||||
* 品类信息Service接口
|
||||
|
@ -27,4 +32,31 @@ public interface CategoryInfoService extends IService<CategoryInfo> {
|
|||
*/
|
||||
public boolean save(CategoryInfoSaveModel categoryInfoSaveModel);
|
||||
|
||||
/**
|
||||
* 通过品类ID获取父级以上的属性组集合
|
||||
* @param categoryId 品类ID
|
||||
* @return 父级以上的属性组集合
|
||||
*/
|
||||
List<AttributeGroup> getAttributeGroup (Long categoryId);
|
||||
|
||||
/**
|
||||
* 通过品类ID获取父级以上的品牌集合
|
||||
* @param categoryId 品类ID
|
||||
* @return 父级以上的品牌集合
|
||||
*/
|
||||
List<BrandInfo> getBrand (Long categoryId);
|
||||
|
||||
/**
|
||||
* 通过品类ID获取父级以上的属性集合
|
||||
* @param categoryId 品类ID
|
||||
* @return 父级以上的属性集合
|
||||
*/
|
||||
List<AttributeInfo> getAttribute (Long categoryId);
|
||||
|
||||
/**
|
||||
* 通过品类ID获取父级以上的属性、属性组、品牌集合
|
||||
* @param categoryId 品类ID
|
||||
* @return 父级以上的属性、属性组、品牌集合
|
||||
*/
|
||||
CategoryParentCommonElementResp parentCommonElement (Long categoryId);
|
||||
}
|
||||
|
|
|
@ -1,21 +1,18 @@
|
|||
package com.muyu.product.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.muyu.common.core.utils.ObjUtils;
|
||||
import com.muyu.product.domain.AsCategoryAttribute;
|
||||
import com.muyu.product.domain.AsCategoryAttributeGroup;
|
||||
import com.muyu.product.domain.AsCategoryBrand;
|
||||
import com.muyu.product.domain.*;
|
||||
import com.muyu.product.domain.model.CategoryInfoSaveModel;
|
||||
import com.muyu.product.service.AsCategoryAttributeGroupService;
|
||||
import com.muyu.product.service.AsCategoryAttributeService;
|
||||
import com.muyu.product.service.AsCategoryBrandService;
|
||||
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;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -40,6 +37,15 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
|
|||
@Autowired
|
||||
private AsCategoryBrandService asCategoryBrandService;
|
||||
|
||||
@Autowired
|
||||
private AttributeInfoService attributeInfoService;
|
||||
|
||||
@Autowired
|
||||
private BrandInfoService brandInfoService;
|
||||
|
||||
@Autowired
|
||||
private AttributeGroupService attributeGroupService;
|
||||
|
||||
/**
|
||||
* 查询品类信息列表
|
||||
*
|
||||
|
@ -106,4 +112,126 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
|
|||
}
|
||||
return save;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过品类ID获取父级以上的属性组集合
|
||||
*
|
||||
* @param categoryId 品类ID
|
||||
*
|
||||
* @return 父级以上的属性组集合
|
||||
*/
|
||||
@Override
|
||||
public List<AttributeGroup> getAttributeGroup (Long categoryId) {
|
||||
List<AttributeGroup> attributeGroupList = new ArrayList<>();
|
||||
LambdaQueryWrapper<AsCategoryAttributeGroup> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(AsCategoryAttributeGroup::getCategoryId, categoryId);
|
||||
List<AsCategoryAttributeGroup> asCategoryAttributeGroupList = asCategoryAttributeGroupService.list(queryWrapper);
|
||||
if (asCategoryAttributeGroupList != null && !asCategoryAttributeGroupList.isEmpty()){
|
||||
List<Long> attributeGroupIdList = asCategoryAttributeGroupList.stream()
|
||||
.map(AsCategoryAttributeGroup::getAttributeGroupId)
|
||||
.toList();
|
||||
attributeGroupList.addAll(attributeGroupService.listByIds(attributeGroupIdList));
|
||||
}
|
||||
CategoryInfo categoryInfo = this.getById(categoryId);
|
||||
if (categoryInfo.getParentId() != 0){
|
||||
if (attributeGroupList.isEmpty()){
|
||||
attributeGroupList.addAll(getAttributeGroup(categoryInfo.getParentId()));
|
||||
}else {
|
||||
List<AttributeGroup> attributeGroups = getAttributeGroup(categoryInfo.getParentId());
|
||||
attributeGroups.forEach(attributeGroup -> {
|
||||
if (!attributeGroupList.contains(attributeGroup)){
|
||||
attributeGroupList.add(attributeGroup);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return attributeGroupList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过品类ID获取父级以上的品牌集合
|
||||
*
|
||||
* @param categoryId 品类ID
|
||||
*
|
||||
* @return 父级以上的品牌集合
|
||||
*/
|
||||
@Override
|
||||
public List<BrandInfo> getBrand (Long categoryId) {
|
||||
List<BrandInfo> brandInfoList = new ArrayList<>();
|
||||
LambdaQueryWrapper<AsCategoryBrand> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(AsCategoryBrand::getCategoryId, categoryId);
|
||||
List<AsCategoryBrand> asCategoryBrandList = asCategoryBrandService.list(queryWrapper);
|
||||
if (asCategoryBrandList != null && !asCategoryBrandList.isEmpty()){
|
||||
List<Long> brandIdList = asCategoryBrandList.stream()
|
||||
.map(AsCategoryBrand::getBrandId)
|
||||
.toList();
|
||||
brandInfoList.addAll(brandInfoService.listByIds(brandIdList));
|
||||
}
|
||||
CategoryInfo categoryInfo = this.getById(categoryId);
|
||||
if (categoryInfo.getParentId() != 0){
|
||||
if (brandInfoList.isEmpty()){
|
||||
brandInfoList.addAll(getBrand(categoryInfo.getParentId()));
|
||||
}else {
|
||||
List<BrandInfo> brandInfos = getBrand(categoryInfo.getParentId());
|
||||
brandInfos.forEach(brandInfo -> {
|
||||
if (!brandInfoList.contains(brandInfo)){
|
||||
brandInfoList.add(brandInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
return brandInfoList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过品类ID获取父级以上的属性集合
|
||||
*
|
||||
* @param categoryId 品类ID
|
||||
*
|
||||
* @return 父级以上的属性集合
|
||||
*/
|
||||
@Override
|
||||
public List<AttributeInfo> getAttribute (Long categoryId) {
|
||||
List<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()){
|
||||
attributeInfoList.addAll(getAttribute(categoryInfo.getParentId()));
|
||||
}else {
|
||||
List<AttributeInfo> attributeInfos = getAttribute(categoryInfo.getParentId());
|
||||
attributeInfos.forEach(attributeInfoQuery -> {
|
||||
if (!attributeInfoList.contains(attributeInfoQuery)){
|
||||
attributeInfoList.add(attributeInfoQuery);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return attributeInfoList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过品类ID获取父级以上的属性、属性组、品牌集合
|
||||
*
|
||||
* @param categoryId 品类ID
|
||||
*
|
||||
* @return 父级以上的属性、属性组、品牌集合
|
||||
*/
|
||||
@Override
|
||||
public CategoryParentCommonElementResp parentCommonElement (Long categoryId) {
|
||||
return CategoryParentCommonElementResp.builder()
|
||||
.attributeInfoList(this.getAttribute(categoryId))
|
||||
.attributeGroupList(this.getAttributeGroup(categoryId))
|
||||
.brandInfoList(this.getBrand(categoryId))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue