品类添加

master
DongZeLiang 2024-02-29 17:02:46 +08:00
parent 5f4785bf7c
commit 2a9c7ef879
10 changed files with 205 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 categoryBuild(Long categoryInfoId, Long attributeGroupId) {
return AsCategoryAttributeGroup.builder()
.attributeGroupId(attributeGroupId)
.categoryId(categoryInfoId)
.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 categoryBuild(Long categoryInfoId, Long brandId) {
return AsCategoryBrand.builder()
.brandId(brandId)
.categoryId(categoryInfoId)
.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,10 @@ 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.Function;
import java.util.function.Supplier;
/**
* category_info
*
@ -72,12 +77,15 @@ 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();
}
@ -94,4 +102,15 @@ public class CategoryInfo extends TreeEntity {
.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,78 @@
package com.muyu.product.domain.model;
import com.muyu.common.core.web.domain.TreeEntity;
import com.muyu.product.domain.CategoryInfo;
import com.muyu.product.domain.req.CategoryInfoSaveReq;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
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;
/**
* category_info
*
* @author DongZeLiang
* @date 2024-02-27
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class CategoryInfoSaveModel extends TreeEntity {
private static final long serialVersionUID = 1L;
/** 品类名称 */
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
*
@ -48,4 +50,18 @@ public class CategoryInfoSaveReq extends TreeEntity {
@ApiModelProperty(name = "介绍", value = "介绍")
private String introduction;
/**
* ID
*/
private List<Long> attributeGroupIdList;
/**
* ID
*/
private List<Long> attributeIdList;
/**
* ID
*/
private List<Long> brandIdList;
}

View File

@ -1,8 +1,11 @@
package com.muyu.product.controller;
import java.util.List;
import java.util.function.Supplier;
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 +84,9 @@ 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)
));
}
/**

View File

@ -3,6 +3,7 @@ package com.muyu.product.service;
import java.util.List;
import com.muyu.product.domain.CategoryInfo;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.product.domain.model.CategoryInfoSaveModel;
/**
* Service
@ -19,4 +20,11 @@ public interface CategoryInfoService extends IService<CategoryInfo> {
*/
public List<CategoryInfo> list(CategoryInfo categoryInfo);
/**
*
* @param categoryInfoSaveModel
* @return
*/
public boolean save(CategoryInfoSaveModel categoryInfoSaveModel);
}

View File

@ -64,10 +64,14 @@ public class AttributeInfoServiceImpl extends ServiceImpl<AttributeInfoMapper, A
}
LambdaQueryWrapper<AsAttributeGroup> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AsAttributeGroup::getGroupId, groupId);
return this.listByIds(
asAttributeGroupService.list(queryWrapper).stream()
List<Long> list = asAttributeGroupService.list(queryWrapper).stream()
.map(AsAttributeGroup::getAttributeId)
.toList()
.toList();
if (list == null || list.isEmpty()){
return null;
}
return this.listByIds(
list
);
}
}

View File

@ -3,13 +3,22 @@ package com.muyu.product.service.impl;
import java.util.List;
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.model.CategoryInfoSaveModel;
import com.muyu.product.service.AsCategoryAttributeGroupService;
import com.muyu.product.service.AsCategoryAttributeService;
import com.muyu.product.service.AsCategoryBrandService;
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;
/**
* Service
@ -21,6 +30,16 @@ 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;
/**
*
*
@ -52,10 +71,39 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
queryWrapper.eq(CategoryInfo::getIntroduction, categoryInfo.getIntroduction());
}
return list(queryWrapper);
}
@Override
@Transactional
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;
}
}