商品自由属性
parent
49ff049004
commit
90bcce03e0
|
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package com.muyu.product.domain;
|
package com.muyu.product.domain;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.muyu.product.domain.resp.TempateAttributeModel;
|
import com.muyu.product.domain.model.TemplateAttributeModel;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
@ -49,9 +51,17 @@ public class AttributeInfo extends BaseEntity {
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|
||||||
|
public TemplateAttributeModel buildTemplateModel(){
|
||||||
|
return TemplateAttributeModel.builder()
|
||||||
|
.id(this.getId())
|
||||||
|
.code(this.getCode())
|
||||||
|
.name(this.getName())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询构造器
|
* 查询构造器
|
||||||
*/
|
*/
|
||||||
public static AttributeInfo queryBuild( AttributeInfoQueryReq attributeInfoQueryReq){
|
public static AttributeInfo queryBuild( AttributeInfoQueryReq attributeInfoQueryReq){
|
||||||
return AttributeInfo.builder()
|
return AttributeInfo.builder()
|
||||||
.name(attributeInfoQueryReq.getName())
|
.name(attributeInfoQueryReq.getName())
|
||||||
|
@ -60,8 +70,8 @@ public class AttributeInfo extends BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加构造器
|
* 添加构造器
|
||||||
*/
|
*/
|
||||||
public static AttributeInfo saveBuild(AttributeInfoSaveReq attributeInfoSaveReq){
|
public static AttributeInfo saveBuild(AttributeInfoSaveReq attributeInfoSaveReq){
|
||||||
return AttributeInfo.builder()
|
return AttributeInfo.builder()
|
||||||
.name(attributeInfoSaveReq.getName())
|
.name(attributeInfoSaveReq.getName())
|
||||||
|
@ -70,21 +80,14 @@ public class AttributeInfo extends BaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改构造器
|
* 修改构造器
|
||||||
*/
|
*/
|
||||||
public static AttributeInfo editBuild(Long id, AttributeInfoEditReq attributeInfoEditReq){
|
public static AttributeInfo editBuild(Long id, AttributeInfoEditReq attributeInfoEditReq){
|
||||||
return AttributeInfo.builder()
|
return AttributeInfo.builder()
|
||||||
.id(id)
|
.id(id)
|
||||||
.name(attributeInfoEditReq.getName())
|
.name(attributeInfoEditReq.getName())
|
||||||
.code(attributeInfoEditReq.getCode())
|
.code(attributeInfoEditReq.getCode())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TempateAttributeModel buildTemplateModel(){
|
|
||||||
return TempateAttributeModel.builder()
|
|
||||||
.id(this.getId())
|
|
||||||
.code(this.getCode())
|
|
||||||
.name(this.getName())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,8 @@ public class AttributeInfoController extends BaseController {
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@ApiOperation("新增商品属性")
|
@ApiOperation("新增商品属性")
|
||||||
public Result<String> add(@RequestBody AttributeInfoSaveReq attributeInfoSaveReq) {
|
public Result<String> add(@RequestBody AttributeInfoSaveReq attributeInfoSaveReq) {
|
||||||
return toAjax(attributeInfoService.save(AttributeInfo.saveBuild(attributeInfoSaveReq)));
|
AttributeInfo attributeInfo = AttributeInfo.saveBuild(attributeInfoSaveReq);
|
||||||
|
return attributeInfoService.save(attributeInfo) ? success(attributeInfo.getId()) : error();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
package com.muyu.product.controller;
|
package com.muyu.product.controller;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import com.muyu.common.security.utils.SecurityUtils;
|
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.model.CategoryInfoSaveModel;
|
||||||
import com.muyu.product.domain.resp.CategoryCommontElementResp;
|
import com.muyu.product.domain.resp.CategoryCommonElementResp;
|
||||||
import com.muyu.product.domain.resp.CategoryParentCommonElementResp;
|
import com.muyu.product.domain.resp.CategoryParentCommonElementResp;
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -24,6 +28,7 @@ import com.muyu.common.log.annotation.Log;
|
||||||
import com.muyu.common.log.enums.BusinessType;
|
import com.muyu.common.log.enums.BusinessType;
|
||||||
import com.muyu.common.security.annotation.RequiresPermissions;
|
import com.muyu.common.security.annotation.RequiresPermissions;
|
||||||
import com.muyu.product.domain.CategoryInfo;
|
import com.muyu.product.domain.CategoryInfo;
|
||||||
|
import com.muyu.product.domain.req.CategoryInfoQueryReq;
|
||||||
import com.muyu.product.domain.req.CategoryInfoSaveReq;
|
import com.muyu.product.domain.req.CategoryInfoSaveReq;
|
||||||
import com.muyu.product.domain.req.CategoryInfoEditReq;
|
import com.muyu.product.domain.req.CategoryInfoEditReq;
|
||||||
import com.muyu.product.service.CategoryInfoService;
|
import com.muyu.product.service.CategoryInfoService;
|
||||||
|
@ -65,14 +70,25 @@ public class CategoryInfoController extends BaseController {
|
||||||
util.exportExcel(response, list, "品类信息数据");
|
util.exportExcel(response, list, "品类信息数据");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取品类信息详细信息
|
||||||
|
*/
|
||||||
|
@ApiOperation("获取品类信息详细信息")
|
||||||
|
@RequiresPermissions("product:category:query")
|
||||||
|
@GetMapping(value = "/{id}")
|
||||||
|
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
|
||||||
|
public Result<CategoryInfo> getInfo(@PathVariable("id") Long id) {
|
||||||
|
return Result.success(categoryInfoService.getById(id));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取品类信息详细信息
|
* 获取品类信息详细信息
|
||||||
*/
|
*/
|
||||||
@ApiOperation("获取品类信息共有属性信息")
|
@ApiOperation("获取品类信息共有属性信息")
|
||||||
@RequiresPermissions("product:category:query")
|
@RequiresPermissions("product:category:query")
|
||||||
@GetMapping(value = "/getTemplateAttributeByCateGoryId/{CateGoryId}")
|
@GetMapping(value = "/getTemplateAttribute/{cateGoryId}")
|
||||||
@ApiImplicitParam(name = "cateGoryId", value = "cateGoryId", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
|
@ApiImplicitParam(name = "cateGoryId", value = "cateGoryId", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
|
||||||
public Result<CategoryCommontElementResp> getTemplateAttributeByCateGoryId(@PathVariable("cateGoryId") Long cateGoryId) {
|
public Result<CategoryCommonElementResp> getTemplateAttributeByCateGoryId(@PathVariable("cateGoryId") Long cateGoryId) {
|
||||||
return Result.success(categoryInfoService.getTemplateAttributeByCateGoryId(cateGoryId));
|
return Result.success(categoryInfoService.getTemplateAttributeByCateGoryId(cateGoryId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +101,7 @@ public class CategoryInfoController extends BaseController {
|
||||||
@ApiOperation("新增品类信息")
|
@ApiOperation("新增品类信息")
|
||||||
public Result<String> add(@RequestBody CategoryInfoSaveReq categoryInfoSaveReq) {
|
public Result<String> add(@RequestBody CategoryInfoSaveReq categoryInfoSaveReq) {
|
||||||
return toAjax(categoryInfoService.save(
|
return toAjax(categoryInfoService.save(
|
||||||
CategoryInfo.saveModelBuild(categoryInfoSaveReq)
|
CategoryInfoSaveModel.saveBuild(categoryInfoSaveReq, SecurityUtils::getUsername)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +113,6 @@ public class CategoryInfoController extends BaseController {
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
@ApiOperation("修改品类信息")
|
@ApiOperation("修改品类信息")
|
||||||
public Result<String> edit(@PathVariable Long id, @RequestBody CategoryInfoEditReq categoryInfoEditReq) {
|
public Result<String> edit(@PathVariable Long id, @RequestBody CategoryInfoEditReq categoryInfoEditReq) {
|
||||||
categoryInfoService.util(categoryInfoEditReq,id);
|
|
||||||
return toAjax(categoryInfoService.updateById(CategoryInfo.editBuild(id,categoryInfoEditReq)));
|
return toAjax(categoryInfoService.updateById(CategoryInfo.editBuild(id,categoryInfoEditReq)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +121,7 @@ public class CategoryInfoController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("product:category:remove")
|
@RequiresPermissions("product:category:remove")
|
||||||
@Log(title = "品类信息", businessType = BusinessType.DELETE)
|
@Log(title = "品类信息", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{ids}")
|
@DeleteMapping("/{ids}")
|
||||||
@ApiOperation("删除品类信息")
|
@ApiOperation("删除品类信息")
|
||||||
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = String.class, example = "1,2,3,4")
|
@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) {
|
public Result<String> remove(@PathVariable List<Long> ids) {
|
||||||
|
@ -126,6 +141,4 @@ public class CategoryInfoController extends BaseController {
|
||||||
) {
|
) {
|
||||||
return Result.success(categoryInfoService.parentCommonElement(categoryId));
|
return Result.success(categoryInfoService.parentCommonElement(categoryId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import com.muyu.product.domain.CategoryInfo;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.muyu.product.domain.model.CategoryInfoSaveModel;
|
import com.muyu.product.domain.model.CategoryInfoSaveModel;
|
||||||
import com.muyu.product.domain.req.CategoryInfoEditReq;
|
import com.muyu.product.domain.req.CategoryInfoEditReq;
|
||||||
import com.muyu.product.domain.resp.CategoryCommontElementResp;
|
import com.muyu.product.domain.resp.CategoryCommonElementResp;
|
||||||
import com.muyu.product.domain.resp.CategoryParentCommonElementResp;
|
import com.muyu.product.domain.resp.CategoryParentCommonElementResp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,5 +47,5 @@ public interface CategoryInfoService extends IService<CategoryInfo> {
|
||||||
* @param cateGoryId 品类Id
|
* @param cateGoryId 品类Id
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
CategoryCommontElementResp getTemplateAttributeByCateGoryId(Long cateGoryId);
|
CategoryCommonElementResp getTemplateAttributeByCateGoryId(Long cateGoryId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,25 @@
|
||||||
package com.muyu.product.service.impl;
|
package com.muyu.product.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.muyu.common.core.utils.ObjUtils;
|
||||||
|
import com.muyu.product.domain.*;
|
||||||
|
import com.muyu.product.domain.base.CategoryBase;
|
||||||
|
import com.muyu.product.domain.model.CategoryInfoSaveModel;
|
||||||
|
import com.muyu.product.domain.model.TemplateAttributeGroupModel;
|
||||||
|
import com.muyu.product.domain.model.TemplateAttributeModel;
|
||||||
|
import com.muyu.product.domain.req.CategoryInfoEditReq;
|
||||||
|
import com.muyu.product.domain.resp.CategoryCommonElementResp;
|
||||||
|
import com.muyu.product.domain.resp.CategoryParentCommonElementResp;
|
||||||
|
import com.muyu.product.mapper.CategoryInfoMapper;
|
||||||
|
import com.muyu.product.service.*;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -7,25 +27,6 @@ import java.util.Set;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
|
||||||
import com.muyu.common.core.utils.ObjUtils;
|
|
||||||
import com.muyu.product.domain.*;
|
|
||||||
import com.muyu.product.domain.base.CategoryBase;
|
|
||||||
import com.muyu.product.domain.model.CategoryInfoSaveModel;
|
|
||||||
import com.muyu.product.domain.req.CategoryInfoEditReq;
|
|
||||||
import com.muyu.product.domain.resp.CategoryCommontElementResp;
|
|
||||||
import com.muyu.product.domain.resp.CategoryParentCommonElementResp;
|
|
||||||
import com.muyu.product.domain.resp.TempateAttributeModel;
|
|
||||||
import com.muyu.product.domain.model.TemplateAttributeGroupModel;
|
|
||||||
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 品类信息Service业务层处理
|
* 品类信息Service业务层处理
|
||||||
*
|
*
|
||||||
|
@ -34,7 +35,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, CategoryInfo> implements CategoryInfoService {
|
public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, CategoryInfo> implements CategoryInfoService {
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AsCategoryAttributeService asCategoryAttributeService;
|
private AsCategoryAttributeService asCategoryAttributeService;
|
||||||
|
|
||||||
|
@ -48,19 +51,23 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
|
||||||
private AsAttributeGroupService asAttributeGroupService;
|
private AsAttributeGroupService asAttributeGroupService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AttributeInfoServiceImpl attributeInfoService;
|
private AttributeInfoService attributeInfoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BrandInfoService brandInfoService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AttributeGroupService attributeGroupService;
|
private AttributeGroupService attributeGroupService;
|
||||||
@Autowired
|
|
||||||
private BrandInfoService brandInfoService;
|
|
||||||
/**
|
/**
|
||||||
* 查询品类信息列表
|
* 查询品类信息列表
|
||||||
*
|
*
|
||||||
* @param categoryInfo 品类信息
|
* @param categoryInfo 品类信息
|
||||||
|
*
|
||||||
* @return 品类信息
|
* @return 品类信息
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<CategoryInfo> list(CategoryInfo categoryInfo) {
|
public List<CategoryInfo> list (CategoryInfo categoryInfo) {
|
||||||
LambdaQueryWrapper<CategoryInfo> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<CategoryInfo> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
|
||||||
|
|
||||||
|
@ -84,109 +91,69 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
|
||||||
queryWrapper.eq(CategoryInfo::getIntroduction, categoryInfo.getIntroduction());
|
queryWrapper.eq(CategoryInfo::getIntroduction, categoryInfo.getIntroduction());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return list(queryWrapper);
|
return list(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CategoryParentCommonElementResp parentCommonElement(Long categoryId) {
|
@Transactional
|
||||||
return CategoryParentCommonElementResp.builder()
|
public boolean save (CategoryInfoSaveModel categoryInfoSaveModel) {
|
||||||
.attributeInfoList(getCommon(categoryId,asCategoryAttributeService,attributeInfoService))
|
|
||||||
.attributeGroupList(getCommon(categoryId,asCategoryAttributeGroupService,attributeGroupService))
|
|
||||||
.brandInfoList(getCommon(categoryId,asCategoryBrandService,brandInfoService))
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getParentIdListByCateGoryId(List<Long> parentIdList,Long cateGoryId){
|
|
||||||
if (cateGoryId.equals(0L)){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
CategoryInfo categoryInfo = this.getById(cateGoryId);
|
|
||||||
parentIdList.add(categoryInfo.getParentId());
|
|
||||||
getParentIdListByCateGoryId(parentIdList,categoryInfo.getParentId());
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void util(CategoryInfoEditReq categoryInfoEditReq, Long groupId) {
|
|
||||||
// List<Long> cateGoryIdList = categoryInfoEditReq.getCateGoryIdList();
|
|
||||||
// // 删除现有的 AsCategoryAttribute 对象
|
|
||||||
// List<AsCategoryAttribute> existingAttributes = asCategoryAttributeService.list();
|
|
||||||
// List<Long> existingCategoryIds = existingAttributes.stream()
|
|
||||||
// .map(AsCategoryAttribute::getCategoryId)
|
|
||||||
// .collect(Collectors.toList());
|
|
||||||
// asCategoryAttributeService.removeBatchByIds(existingCategoryIds);
|
|
||||||
//
|
|
||||||
// // 保存新的 AsCategoryAttribute 对象
|
|
||||||
// List<AsCategoryAttribute> newAttributes = cateGoryIdList.stream()
|
|
||||||
// .map(categoryId -> new AsCategoryAttribute())
|
|
||||||
// .collect(Collectors.toList());
|
|
||||||
// asCategoryAttributeService.saveBatch(newAttributes);
|
|
||||||
AsCategoryAttribute categoryAttribute = AsCategoryAttribute.categoryAttribute(groupId);
|
|
||||||
List<AsCategoryAttribute> list = asCategoryAttributeService.list(categoryAttribute);
|
|
||||||
ArrayList<Long> longArrayList = new ArrayList<>();
|
|
||||||
for (AsCategoryAttribute asCategoryAttribute : list) {
|
|
||||||
longArrayList.add(asCategoryAttribute.getId());
|
|
||||||
}
|
|
||||||
asCategoryAttributeService.removeBatchByIds(longArrayList);
|
|
||||||
List<Long> goryIdList = categoryInfoEditReq.getCateGoryIdList();
|
|
||||||
asCategoryAttributeService.saveBatch(
|
|
||||||
goryIdList.stream()
|
|
||||||
.map(categoryId->AsCategoryAttribute.categoryBuild(groupId,categoryId))
|
|
||||||
.toList()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean save(CategoryInfoSaveModel categoryInfoSaveModel) {
|
|
||||||
CategoryInfo categoryInfo = CategoryInfo.saveModelBuild(categoryInfoSaveModel);
|
CategoryInfo categoryInfo = CategoryInfo.saveModelBuild(categoryInfoSaveModel);
|
||||||
boolean save = this.save(categoryInfo);
|
boolean save = this.save(categoryInfo);
|
||||||
Long categoryInfoId = categoryInfo.getId();
|
Long categoryInfoId = categoryInfo.getId();
|
||||||
List<Long> attributeIdList = categoryInfoSaveModel.getAttributeIdList();
|
List<Long> attributeIdList = categoryInfoSaveModel.getAttributeIdList();
|
||||||
if (attributeIdList!=null && !attributeIdList.isEmpty()){
|
if (attributeIdList != null && !attributeIdList.isEmpty()) {
|
||||||
asCategoryAttributeService.saveBatch(
|
asCategoryAttributeService.saveBatch(
|
||||||
attributeIdList.stream()
|
attributeIdList.stream()
|
||||||
.map(attributeId->AsCategoryAttribute.categoryBuild(categoryInfoId,attributeId))
|
.map(attributeId -> AsCategoryAttribute.categoryBuild(categoryInfoId, attributeId))
|
||||||
.toList()
|
.toList()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
List<Long> attributeGroupIdList = categoryInfoSaveModel.getAttributeGroupIdList();
|
List<Long> attributeGroupIdList = categoryInfoSaveModel.getAttributeGroupIdList();
|
||||||
if (attributeGroupIdList!=null && !attributeGroupIdList.isEmpty()){
|
if (attributeGroupIdList != null && !attributeGroupIdList.isEmpty()) {
|
||||||
asCategoryAttributeGroupService.saveBatch(
|
asCategoryAttributeGroupService.saveBatch(
|
||||||
attributeGroupIdList.stream()
|
attributeGroupIdList.stream()
|
||||||
.map(attributeGroupId -> AsCategoryAttributeGroup.categoryBuild(categoryInfoId,attributeGroupId))
|
.map(attributeGroupId -> AsCategoryAttributeGroup.categoryBuild(categoryInfoId, attributeGroupId))
|
||||||
.toList()
|
.toList()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
List<Long> brandIdList = categoryInfoSaveModel.getBrandIdList();
|
List<Long> brandIdList = categoryInfoSaveModel.getBrandIdList();
|
||||||
if (brandIdList!=null && !brandIdList.isEmpty()){
|
if (brandIdList != null && !brandIdList.isEmpty()) {
|
||||||
asCategoryBrandService.saveBatch(
|
asCategoryBrandService.saveBatch(
|
||||||
brandIdList.stream()
|
brandIdList.stream()
|
||||||
.map(brandId->AsCategoryBrand.categoryBuild(categoryInfoId,brandId))
|
.map(brandId -> AsCategoryBrand.categoryBuild(categoryInfoId, brandId))
|
||||||
.toList()
|
.toList()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return false;
|
return save;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过品类ID获取父级以上的属性组集合
|
||||||
|
*
|
||||||
|
* @param categoryId 品类ID
|
||||||
|
*
|
||||||
|
* @return 父级以上的属性组集合
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<AttributeGroup> getAttributeGroup(Long categoryId) {
|
public List<AttributeGroup> getAttributeGroup (Long categoryId) {
|
||||||
ArrayList<AttributeGroup> attributeGroupList = new ArrayList<>();
|
List<AttributeGroup> attributeGroupList = new ArrayList<>();
|
||||||
LambdaQueryWrapper<AsCategoryAttributeGroup> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<AsCategoryAttributeGroup> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.eq(AsCategoryAttributeGroup::getCategoryId,categoryId);
|
queryWrapper.eq(AsCategoryAttributeGroup::getCategoryId, categoryId);
|
||||||
List<AsCategoryAttributeGroup> asCategoryAttributeGroupList = asCategoryAttributeGroupService.list(queryWrapper);
|
List<AsCategoryAttributeGroup> asCategoryAttributeGroupList = asCategoryAttributeGroupService.list(queryWrapper);
|
||||||
if (asCategoryAttributeGroupList!=null && !asCategoryAttributeGroupList.isEmpty()){
|
if (asCategoryAttributeGroupList != null && !asCategoryAttributeGroupList.isEmpty()) {
|
||||||
asCategoryAttributeGroupList.stream()
|
List<Long> attributeGroupIdList = asCategoryAttributeGroupList.stream()
|
||||||
.map(AsCategoryAttributeGroup::getAttributeGroupId)
|
.map(AsCategoryAttributeGroup::getAttributeGroupId)
|
||||||
.toList();
|
.toList();
|
||||||
attributeGroupList.addAll(attributeGroupService.listByIds(attributeGroupList));
|
attributeGroupList.addAll(attributeGroupService.listByIds(attributeGroupIdList));
|
||||||
}
|
}
|
||||||
CategoryInfo categoryInfo = this.getById(categoryId);
|
CategoryInfo categoryInfo = this.getById(categoryId);
|
||||||
if (categoryInfo.getParentId()!=0){
|
if (categoryInfo.getParentId() != 0) {
|
||||||
if (attributeGroupList.isEmpty()){
|
if (attributeGroupList.isEmpty()) {
|
||||||
attributeGroupList.addAll(getAttributeGroup(categoryInfo.getParentId()));
|
attributeGroupList.addAll(getAttributeGroup(categoryInfo.getParentId()));
|
||||||
}else {
|
} else {
|
||||||
List<AttributeGroup> attributeGroups = getAttributeGroup(categoryInfo.getParentId());
|
List<AttributeGroup> attributeGroups = getAttributeGroup(categoryInfo.getParentId());
|
||||||
attributeGroups.forEach(attributeGroup -> {
|
attributeGroups.forEach(attributeGroup -> {
|
||||||
if (!attributeGroupList.contains(attributeGroup)){
|
if (!attributeGroupList.contains(attributeGroup)) {
|
||||||
attributeGroupList.add(attributeGroup);
|
attributeGroupList.add(attributeGroup);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -195,59 +162,70 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
|
||||||
return attributeGroupList;
|
return attributeGroupList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过品类ID获取父级以上的品牌集合
|
||||||
|
*
|
||||||
|
* @param categoryId 品类ID
|
||||||
|
*
|
||||||
|
* @return 父级以上的品牌集合
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<BrandInfo> getBrand(Long categoryId) {
|
public List<BrandInfo> getBrand (Long categoryId) {
|
||||||
ArrayList<BrandInfo> brandInfoList = new ArrayList<>();
|
List<BrandInfo> brandInfoList = new ArrayList<>();
|
||||||
LambdaQueryWrapper<AsCategoryBrand> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<AsCategoryBrand> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.eq(AsCategoryBrand::getCategoryId,categoryId);
|
queryWrapper.eq(AsCategoryBrand::getCategoryId, categoryId);
|
||||||
List<AsCategoryBrand> asCategoryBrandList = asCategoryBrandService.list(queryWrapper);
|
List<AsCategoryBrand> asCategoryBrandList = asCategoryBrandService.list(queryWrapper);
|
||||||
if (asCategoryBrandList!=null &&!asCategoryBrandList.isEmpty()){
|
if (asCategoryBrandList != null && !asCategoryBrandList.isEmpty()) {
|
||||||
List<Long> brandIdList = asCategoryBrandList.stream()
|
List<Long> brandIdList = asCategoryBrandList.stream()
|
||||||
.map(AsCategoryBrand::getBrandId)
|
.map(AsCategoryBrand::getBrandId)
|
||||||
.toList();
|
.toList();
|
||||||
brandInfoList.addAll(brandInfoService.listByIds(brandIdList));
|
brandInfoList.addAll(brandInfoService.listByIds(brandIdList));
|
||||||
}
|
}
|
||||||
CategoryInfo categoryInfo = this.getById(categoryId);
|
CategoryInfo categoryInfo = this.getById(categoryId);
|
||||||
if (categoryInfo.getParentId()!=0){
|
if (categoryInfo.getParentId() != 0) {
|
||||||
if (brandInfoList.isEmpty()){
|
if (brandInfoList.isEmpty()) {
|
||||||
brandInfoList.addAll(getBrand(categoryInfo.getParentId()));
|
brandInfoList.addAll(getBrand(categoryInfo.getParentId()));
|
||||||
}else {
|
} else {
|
||||||
List<BrandInfo> brandInfos = getBrand(categoryInfo.getParentId());
|
List<BrandInfo> brandInfos = getBrand(categoryInfo.getParentId());
|
||||||
brandInfos.forEach(brandInfo -> {
|
brandInfos.forEach(brandInfo -> {
|
||||||
if (!brandInfoList.contains(brandInfo)){
|
if (!brandInfoList.contains(brandInfo)) {
|
||||||
brandInfoList.add(brandInfo);
|
brandInfoList.add(brandInfo);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return brandInfoList;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过品类ID获取父级以上的属性集合
|
||||||
|
*
|
||||||
|
* @param categoryId 品类ID
|
||||||
|
*
|
||||||
|
* @return 父级以上的属性集合
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<AttributeInfo> getAttribute(Long categoryId) {
|
public List<AttributeInfo> getAttribute (Long categoryId) {
|
||||||
ArrayList<AttributeInfo> attributeInfoList = new ArrayList<>();
|
List<AttributeInfo> attributeInfoList = new ArrayList<>();
|
||||||
LambdaQueryWrapper<AsCategoryAttribute> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<AsCategoryAttribute> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.eq(AsCategoryAttribute::getCategoryId,categoryId);
|
queryWrapper.eq(AsCategoryAttribute::getCategoryId, categoryId);
|
||||||
List<AsCategoryAttribute> asCategoryAttributeList = asCategoryAttributeService.list(queryWrapper);
|
List<AsCategoryAttribute> asCategoryAttributeList = asCategoryAttributeService.list(queryWrapper);
|
||||||
if (asCategoryAttributeList!=null && !asCategoryAttributeList.isEmpty()){
|
if (asCategoryAttributeList != null && !asCategoryAttributeList.isEmpty()) {
|
||||||
List<Long> attributeIdList = asCategoryAttributeList.stream()
|
List<Long> attributeIdList = asCategoryAttributeList.stream()
|
||||||
.map(AsCategoryAttribute::getCategoryId)
|
.map(AsCategoryAttribute::getAttributeId)
|
||||||
.toList();
|
.toList();
|
||||||
attributeInfoList.addAll(attributeInfoService.listByIds(attributeIdList));
|
attributeInfoList.addAll(attributeInfoService.listByIds(attributeIdList));
|
||||||
}
|
}
|
||||||
CategoryInfo categoryInfo = this.getById(categoryId);
|
CategoryInfo categoryInfo = this.getById(categoryId);
|
||||||
if (categoryInfo.getParentId()!=0){
|
if (categoryInfo.getParentId() != 0) {
|
||||||
if (attributeInfoList.isEmpty()){
|
if (attributeInfoList.isEmpty()) {
|
||||||
attributeInfoList.addAll(getAttribute(categoryInfo.getParentId()));
|
attributeInfoList.addAll(getAttribute(categoryInfo.getParentId()));
|
||||||
}else {
|
} else {
|
||||||
List<AttributeInfo> attributeInfos = getAttribute(categoryInfo.getParentId());
|
List<AttributeInfo> attributeInfos = getAttribute(categoryInfo.getParentId());
|
||||||
attributeInfos.forEach(attributeInfosQurey -> {
|
attributeInfos.forEach(attributeInfoQuery -> {
|
||||||
if (!attributeInfoList.contains(attributeInfosQurey)){
|
if (!attributeInfoList.contains(attributeInfoQuery)) {
|
||||||
if (!attributeInfoList.contains(attributeInfosQurey)){
|
attributeInfoList.add(attributeInfoQuery);
|
||||||
attributeInfoList.add(attributeInfosQurey);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -257,15 +235,81 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CategoryParentCommonElementResp paretCoommonElement(Long categoryId) {
|
public CategoryParentCommonElementResp paretCoommonElement(Long categoryId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public <T, AS> List<T> getCommon (Long categoryId, IService<AS> iService, IService<T> bsiService) {
|
||||||
|
List<T> list = new ArrayList();
|
||||||
|
QueryWrapper<AS> asQueryWrapper = new QueryWrapper<>();
|
||||||
|
asQueryWrapper.eq("category_id", categoryId);
|
||||||
|
List<AS> asList = iService.list(asQueryWrapper);
|
||||||
|
if (asList != null && !asList.isEmpty()) {
|
||||||
|
List<Long> baseIdList = asList.stream()
|
||||||
|
.map(as -> {
|
||||||
|
if (as instanceof CategoryBase categoryBase) {
|
||||||
|
return categoryBase.getBaseId();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
})
|
||||||
|
.toList();
|
||||||
|
list.addAll(bsiService.listByIds(baseIdList));
|
||||||
|
}
|
||||||
|
CategoryInfo categoryInfo = this.getById(categoryId);
|
||||||
|
if (categoryInfo.getParentId() != 0) {
|
||||||
|
if (list.isEmpty()) {
|
||||||
|
list.addAll(getCommon(categoryInfo.getParentId(), iService, bsiService));
|
||||||
|
} else {
|
||||||
|
List<T> commonList = getCommon(categoryInfo.getParentId(), iService, bsiService);
|
||||||
|
commonList.forEach(common -> {
|
||||||
|
if (!list.contains(common)) {
|
||||||
|
list.add(common);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过品类ID获取父级以上的属性、属性组、品牌集合
|
||||||
|
*
|
||||||
|
* @param categoryId 品类ID
|
||||||
|
*
|
||||||
|
* @return 父级以上的属性、属性组、品牌集合
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public CategoryParentCommonElementResp parentCommonElement (Long categoryId) {
|
||||||
return CategoryParentCommonElementResp.builder()
|
return CategoryParentCommonElementResp.builder()
|
||||||
.attributeInfoList(getCommon(categoryId,asCategoryAttributeService,attributeInfoService))
|
.attributeInfoList(getCommon(categoryId, asCategoryAttributeService, attributeInfoService))
|
||||||
.attributeGroupList(getCommon(categoryId,asCategoryAttributeGroupService,attributeGroupService))
|
.attributeGroupList(getCommon(categoryId, asCategoryAttributeGroupService, attributeGroupService))
|
||||||
.brandInfoList(getCommon(categoryId,asCategoryBrandService,brandInfoService))
|
.brandInfoList(getCommon(categoryId, asCategoryBrandService, brandInfoService))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CategoryCommontElementResp getTemplateAttributeByCateGoryId(Long cateGoryId) {
|
public void util(CategoryInfoEditReq categoryInfoEditReq, Long id) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getParentIdListByCateGoryId(List<Long> parentIdList, Long cateGoryId){
|
||||||
|
if (cateGoryId.equals(0L)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CategoryInfo categoryInfo = this.getById(cateGoryId);
|
||||||
|
parentIdList.add(categoryInfo.getId());
|
||||||
|
getParentIdListByCateGoryId(parentIdList, categoryInfo.getParentId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过品类ID获取品类共有属性
|
||||||
|
*
|
||||||
|
* @param cateGoryId 品类ID
|
||||||
|
*
|
||||||
|
* @return 品类共有属性
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public CategoryCommonElementResp getTemplateAttributeByCateGoryId (Long cateGoryId) {
|
||||||
List<Long> cateGoryIdList = new ArrayList<>();
|
List<Long> cateGoryIdList = new ArrayList<>();
|
||||||
getParentIdListByCateGoryId(cateGoryIdList, cateGoryId);
|
getParentIdListByCateGoryId(cateGoryIdList, cateGoryId);
|
||||||
// 取出和品类相关联的属性组关系 - 中间表
|
// 取出和品类相关联的属性组关系 - 中间表
|
||||||
|
@ -299,147 +343,42 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
|
||||||
if (!attributeGroupModelList.isEmpty()){
|
if (!attributeGroupModelList.isEmpty()){
|
||||||
attributeIdSet.addAll(
|
attributeIdSet.addAll(
|
||||||
attributeGroupModelList.stream()
|
attributeGroupModelList.stream()
|
||||||
.flatMap((Function<TemplateAttributeGroupModel, Stream<TempateAttributeModel>>) templateAttributeGroupModel -> templateAttributeGroupModel.getAttributeList().stream())
|
.flatMap((Function<TemplateAttributeGroupModel, Stream<TemplateAttributeModel>>) templateAttributeGroupModel -> templateAttributeGroupModel.getAttributeList().stream())
|
||||||
.map(TempateAttributeModel::getId)
|
.map(TemplateAttributeModel::getId)
|
||||||
.toList()
|
.toList()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<TempateAttributeModel> tempateAttributeModelList=new ArrayList<>();
|
List<TemplateAttributeModel> templateAttributeModelList = new ArrayList<>();
|
||||||
LambdaQueryWrapper<AsCategoryAttribute> categoryAttributeQueryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<AsCategoryAttribute> categoryAttributeQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
categoryAttributeQueryWrapper.in(AsCategoryAttribute::getAttributeId,cateGoryIdList);
|
categoryAttributeQueryWrapper.in(AsCategoryAttribute::getCategoryId, cateGoryIdList);
|
||||||
List<AsCategoryAttribute> asCategoryAttributeList = asCategoryAttributeService.list(categoryAttributeQueryWrapper);
|
List<AsCategoryAttribute> asCategoryAttributeList = asCategoryAttributeService.list(categoryAttributeQueryWrapper);
|
||||||
if (asCategoryAttributeList!=null && asCategoryAttributeList.isEmpty()){
|
if (asCategoryAttributeList != null && !asCategoryAttributeList.isEmpty()){
|
||||||
List<Long> templateAttributeIdList = asCategoryAttributeList.stream()
|
List<Long> templateAttributeIdList = asCategoryAttributeList.stream()
|
||||||
.map(AsCategoryAttribute::getAttributeId)
|
.map(AsCategoryAttribute::getAttributeId)
|
||||||
.filter(templateAttributeId -> !attributeIdSet.contains(templateAttributeId))
|
.filter(templateAttributeId -> !attributeIdSet.contains(templateAttributeId))
|
||||||
.toList();
|
.toList();
|
||||||
tempateAttributeModelList =attributeInfoService.listByIds(
|
templateAttributeModelList = attributeInfoService.listByIds(templateAttributeIdList).stream()
|
||||||
templateAttributeIdList
|
.map(AttributeInfo::buildTemplateModel)
|
||||||
).stream().map(AttributeInfo::buildTemplateModel)
|
.toList();
|
||||||
.toList();
|
}
|
||||||
}
|
|
||||||
List<TempateAttributeModel> attributeModelList=new ArrayList<>();
|
|
||||||
|
|
||||||
if (!tempateAttributeModelList.isEmpty()){
|
List<TemplateAttributeModel> attributeModelList = new ArrayList<>();
|
||||||
|
|
||||||
|
if (!templateAttributeModelList.isEmpty()){
|
||||||
attributeIdSet.addAll(
|
attributeIdSet.addAll(
|
||||||
tempateAttributeModelList.stream().map(TempateAttributeModel::getId).toList()
|
templateAttributeModelList.stream().map(TemplateAttributeModel::getId).toList()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
LambdaQueryWrapper<AttributeInfo> attributeInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<AttributeInfo> attributeInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
attributeInfoLambdaQueryWrapper.notIn(!attributeIdSet.isEmpty(),AttributeInfo::getId,attributeIdSet);
|
attributeInfoLambdaQueryWrapper.notIn(!attributeIdSet.isEmpty(), AttributeInfo::getId, attributeIdSet);
|
||||||
attributeInfoService.list(attributeInfoLambdaQueryWrapper).stream().map(AttributeInfo::buildTemplateModel).toList();
|
attributeModelList = attributeInfoService.list(attributeInfoLambdaQueryWrapper).stream().map(AttributeInfo::buildTemplateModel).toList();
|
||||||
|
|
||||||
|
return CategoryCommonElementResp.builder()
|
||||||
return CategoryCommontElementResp.builder()
|
.templateAttributeGroupList(attributeGroupModelList)
|
||||||
.templateAttributeGroupList(null)
|
.templateAttributeList(templateAttributeModelList)
|
||||||
.templateAttributeList(null)
|
.attributeList(attributeModelList)
|
||||||
.attributeList(null)
|
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// @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(attributeGroupId -> AsCategoryAttributeGroup.categoryBuild(categoryInfoId, attributeGroupId))
|
|
||||||
// .toList()
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// List<Long> brandIdList = categoryInfoSaveModel.getBrandIdList();
|
|
||||||
// if (brandIdList != null && !brandIdList.isEmpty()){
|
|
||||||
// asCategoryBrandService.saveBatch(
|
|
||||||
// brandIdList.stream()
|
|
||||||
// .map(brandId -> AsCategoryBrand.categoryBuild(categoryInfoId, brandId))
|
|
||||||
// .toList()
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// return save;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public <T, AS> List<T> getCommon(Long categoryId, IService<AS> iService,
|
|
||||||
// IService<T> bsiservice) {
|
|
||||||
// List<T> list = new ArrayList<>();
|
|
||||||
// QueryWrapper<AS> asQueryWrapper = new QueryWrapper<>();
|
|
||||||
// asQueryWrapper.eq("attribute_id", categoryId);
|
|
||||||
// List<AS> asList = iService.list(asQueryWrapper);
|
|
||||||
// if (asList != null && !asList.isEmpty()) {
|
|
||||||
// List<Long> baseIdList = asList.stream().
|
|
||||||
// map(as -> {
|
|
||||||
// if (as instanceof CategoryBase categoryBase) {
|
|
||||||
// return categoryBase.getBaseId();
|
|
||||||
// }
|
|
||||||
// return null;
|
|
||||||
// })
|
|
||||||
// .toList();
|
|
||||||
// list.addAll(bsiservice.listByIds(baseIdList));
|
|
||||||
// }
|
|
||||||
// CategoryInfo categoryInfo = this.getById(categoryId);
|
|
||||||
// if (categoryInfo.getParentId() != 0) {
|
|
||||||
// if (list.isEmpty()) {
|
|
||||||
// list.addAll(getCommon(categoryInfo.getParentId(), iService, bsiservice));
|
|
||||||
// } else {
|
|
||||||
// List<T> commonList = getCommon(categoryInfo.getParentId(), iService, bsiservice);
|
|
||||||
// commonList.forEach(common -> {
|
|
||||||
// if (!list.contains(common)) {
|
|
||||||
// list.add(common);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return list;
|
|
||||||
// }
|
|
||||||
//T和AS是泛型类参数
|
|
||||||
public <T,AS> List<T> getCommon(Long categoryId,IService<AS> iService,
|
|
||||||
IService<T> bsiervice){
|
|
||||||
//初始化并创建一个空列表
|
|
||||||
ArrayList<T> list = new ArrayList<>();
|
|
||||||
//创建查询条件
|
|
||||||
QueryWrapper<AS> asQueryWrapper = new QueryWrapper<>();
|
|
||||||
asQueryWrapper.eq("attribute_id",categoryId);
|
|
||||||
List<AS> asList = iService.list(asQueryWrapper);
|
|
||||||
if (asList!=null && !asList.isEmpty()){
|
|
||||||
List<Long> baseIdList=asList.stream().
|
|
||||||
map(as -> {
|
|
||||||
if (as instanceof CategoryBase categoryBase){
|
|
||||||
return categoryBase.getBaseId();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
})
|
|
||||||
.toList();
|
|
||||||
list.addAll(bsiervice.listByIds(baseIdList));
|
|
||||||
|
|
||||||
}
|
|
||||||
CategoryInfo byId = this.getById(categoryId);
|
|
||||||
if (byId.getParentId()!=0){
|
|
||||||
if (list.isEmpty()){
|
|
||||||
list.addAll(getCommon(byId.getParentId(),iService,bsiervice));
|
|
||||||
}else {
|
|
||||||
List<T> commonList = getCommon(byId.getParentId(), iService, bsiervice);
|
|
||||||
commonList.forEach(common ->{
|
|
||||||
if (!list.contains(common)){
|
|
||||||
list.add(common);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue