商品模块属性组增删改

product
yaoxin 2024-03-03 14:08:48 +08:00
parent 7310116a85
commit e8392009d0
12 changed files with 308 additions and 9 deletions

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}

View File

@ -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();
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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));
}
}

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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
);
}
}

View File

@ -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;
}
}