品类添加
parent
5f4785bf7c
commit
2a9c7ef879
|
@ -45,4 +45,10 @@ public class AsCategoryAttribute extends BaseEntity {
|
||||||
private Long attributeId;
|
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;
|
private Long attributeGroupId;
|
||||||
|
|
||||||
|
|
||||||
|
public static AsCategoryAttributeGroup categoryBuild(Long categoryInfoId, Long attributeGroupId) {
|
||||||
|
return AsCategoryAttributeGroup.builder()
|
||||||
|
.attributeGroupId(attributeGroupId)
|
||||||
|
.categoryId(categoryInfoId)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,4 +44,10 @@ public class AsCategoryBrand extends BaseEntity {
|
||||||
@ApiModelProperty(name = "品牌id", value = "品牌id", required = true)
|
@ApiModelProperty(name = "品牌id", value = "品牌id", required = true)
|
||||||
private Long brandId;
|
private Long brandId;
|
||||||
|
|
||||||
|
public static AsCategoryBrand categoryBuild(Long categoryInfoId, Long brandId) {
|
||||||
|
return AsCategoryBrand.builder()
|
||||||
|
.brandId(brandId)
|
||||||
|
.categoryId(categoryInfoId)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.muyu.product.domain;
|
||||||
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.model.CategoryInfoSaveModel;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
@ -15,6 +16,10 @@ import com.muyu.product.domain.req.CategoryInfoSaveReq;
|
||||||
import com.muyu.product.domain.req.CategoryInfoEditReq;
|
import com.muyu.product.domain.req.CategoryInfoEditReq;
|
||||||
import com.muyu.common.core.web.domain.TreeEntity;
|
import com.muyu.common.core.web.domain.TreeEntity;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 品类信息对象 category_info
|
* 品类信息对象 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()
|
return CategoryInfo.builder()
|
||||||
.name(categoryInfoSaveReq.getName())
|
.name(categoryInfoSaveReq.getName())
|
||||||
.image(categoryInfoSaveReq.getImage())
|
.image(categoryInfoSaveReq.getImage())
|
||||||
.start(categoryInfoSaveReq.getStart())
|
.start(categoryInfoSaveReq.getStart())
|
||||||
.introduction(categoryInfoSaveReq.getIntroduction())
|
.introduction(categoryInfoSaveReq.getIntroduction())
|
||||||
|
.parentId(categoryInfoSaveReq.getParentId())
|
||||||
|
.createBy(supplier.get())
|
||||||
|
.createTime(new Date())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,4 +102,15 @@ public class CategoryInfo extends TreeEntity {
|
||||||
.build();
|
.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,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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -8,6 +8,8 @@ import lombok.experimental.SuperBuilder;
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import com.muyu.common.core.web.domain.TreeEntity;
|
import com.muyu.common.core.web.domain.TreeEntity;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 品类信息对象 category_info
|
* 品类信息对象 category_info
|
||||||
*
|
*
|
||||||
|
@ -48,4 +50,18 @@ public class CategoryInfoSaveReq extends TreeEntity {
|
||||||
@ApiModelProperty(name = "介绍", value = "介绍")
|
@ApiModelProperty(name = "介绍", value = "介绍")
|
||||||
private String introduction;
|
private String introduction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品属性组关联ID
|
||||||
|
*/
|
||||||
|
private List<Long> attributeGroupIdList;
|
||||||
|
/**
|
||||||
|
* 商品属性关联ID
|
||||||
|
*/
|
||||||
|
private List<Long> attributeIdList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品品牌组关联ID
|
||||||
|
*/
|
||||||
|
private List<Long> brandIdList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
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.product.domain.model.CategoryInfoSaveModel;
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
@ -81,7 +84,9 @@ public class CategoryInfoController extends BaseController {
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@ApiOperation("新增品类信息")
|
@ApiOperation("新增品类信息")
|
||||||
public Result<String> add(@RequestBody CategoryInfoSaveReq categoryInfoSaveReq) {
|
public Result<String> add(@RequestBody CategoryInfoSaveReq categoryInfoSaveReq) {
|
||||||
return toAjax(categoryInfoService.save(CategoryInfo.saveBuild(categoryInfoSaveReq)));
|
return toAjax(categoryInfoService.save(
|
||||||
|
CategoryInfoSaveModel.saveBuild(categoryInfoSaveReq, SecurityUtils::getUsername)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.muyu.product.service;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.muyu.product.domain.CategoryInfo;
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 品类信息Service接口
|
* 品类信息Service接口
|
||||||
|
@ -19,4 +20,11 @@ public interface CategoryInfoService extends IService<CategoryInfo> {
|
||||||
*/
|
*/
|
||||||
public List<CategoryInfo> list(CategoryInfo categoryInfo);
|
public List<CategoryInfo> list(CategoryInfo categoryInfo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存
|
||||||
|
* @param categoryInfoSaveModel 保存品类模型
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
public boolean save(CategoryInfoSaveModel categoryInfoSaveModel);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,10 +64,14 @@ public class AttributeInfoServiceImpl extends ServiceImpl<AttributeInfoMapper, A
|
||||||
}
|
}
|
||||||
LambdaQueryWrapper<AsAttributeGroup> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<AsAttributeGroup> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.eq(AsAttributeGroup::getGroupId, groupId);
|
queryWrapper.eq(AsAttributeGroup::getGroupId, groupId);
|
||||||
|
List<Long> list = asAttributeGroupService.list(queryWrapper).stream()
|
||||||
|
.map(AsAttributeGroup::getAttributeId)
|
||||||
|
.toList();
|
||||||
|
if (list == null || list.isEmpty()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return this.listByIds(
|
return this.listByIds(
|
||||||
asAttributeGroupService.list(queryWrapper).stream()
|
list
|
||||||
.map(AsAttributeGroup::getAttributeId)
|
|
||||||
.toList()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,22 @@ package com.muyu.product.service.impl;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.muyu.common.core.utils.ObjUtils;
|
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 lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.muyu.product.mapper.CategoryInfoMapper;
|
import com.muyu.product.mapper.CategoryInfoMapper;
|
||||||
import com.muyu.product.domain.CategoryInfo;
|
import com.muyu.product.domain.CategoryInfo;
|
||||||
import com.muyu.product.service.CategoryInfoService;
|
import com.muyu.product.service.CategoryInfoService;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 品类信息Service业务层处理
|
* 品类信息Service业务层处理
|
||||||
|
@ -21,6 +30,16 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
@Service
|
@Service
|
||||||
public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, CategoryInfo> implements CategoryInfoService {
|
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());
|
queryWrapper.eq(CategoryInfo::getIntroduction, categoryInfo.getIntroduction());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return list(queryWrapper);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue