feat:商品修改

master
meng 2024-11-17 17:00:26 +08:00
parent c93a7e0b97
commit b175af47bd
9 changed files with 101 additions and 23 deletions

View File

@ -147,5 +147,18 @@ public class ProjectInfo extends BaseEntity {
.brandId(projectInfoEditReq.getBrandId())
.build();
}
/**
*
*/
public static ProjectInfo editProductBuild(Long id, ProjectInfoSaveReq projectInfoSaveReq){
return ProjectInfo.builder()
.id(id)
.name(projectInfoSaveReq.getProjectAddModel().getName())
.brandId(projectInfoSaveReq.getProjectAddModel().getBrandId())
.image(projectInfoSaveReq.getProjectAddModel().getImage())
.status(projectInfoSaveReq.getProjectAddModel().getStatus())
.type(projectInfoSaveReq.getProjectAddModel().getType())
.ruleId(projectInfoSaveReq.getProjectAddModel().getRuleId())
.build();
}
}

View File

@ -91,6 +91,18 @@ public class ProjectSkuInfo extends BaseEntity {
.image(projectSkuInfoSaveReq.getImage())
.build();
}
/**
*
*/
public static ProjectSkuInfo saveProductBuild(ProductSkuModel productSkuModel,Supplier<Long> projectId){
return ProjectSkuInfo.builder()
.projectId(projectId.get())
.sku(productSkuModel.getSku())
.stock(productSkuModel.getStock())
.price(productSkuModel.getPrice())
.image(productSkuModel.getImage())
.build();
}
/**
*

View File

@ -20,6 +20,7 @@ import java.math.BigDecimal;
@AllArgsConstructor
public class ProductSkuModel {
/** sku */
@ApiModelProperty(name = "sku", value = "sku", required = true)
private String sku;

View File

@ -24,7 +24,7 @@ import java.util.function.Supplier;
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class TemplateAttributeGroupModel extends BaseEntity {
private Long id;
/**
*
*/
@ -49,9 +49,9 @@ public class TemplateAttributeGroupModel extends BaseEntity {
* @param attributeList
* @return
*/
public static TemplateAttributeGroupModel attributeGroupBuild(AttributeGroup attributeGroup,
Function<Long, List<TemplateAttributeModel>> attributeList){
public static TemplateAttributeGroupModel attributeGroupBuild(AttributeGroup attributeGroup, Function<Long, List<TemplateAttributeModel>> attributeList){
return TemplateAttributeGroupModel.builder()
.id(attributeGroup.getId())
.groupName(attributeGroup.getName())
.attributeList(attributeList.apply(attributeGroup.getId()))
.build();

View File

@ -26,7 +26,7 @@ public class CategoryCommonElementResp extends BaseEntity {
private List<TemplateAttributeGroupModel> templateAttributeGroupList;
/**
*
*
*/
private List<TemplateAttributeModel> templateAttributeList;

View File

@ -120,8 +120,9 @@ public class ProjectInfoController extends BaseController {
@Log(title = "商品信息", businessType = BusinessType.UPDATE)
@PutMapping("/{id}")
@ApiOperation("修改商品信息")
public Result<String> edit(@PathVariable Long id, @RequestBody ProjectInfoEditReq projectInfoEditReq) {
return toAjax(projectInfoService.updateById(ProjectInfo.editBuild(id,projectInfoEditReq)));
public Result edit(@PathVariable Long id, @RequestBody ProjectInfoSaveReq projectInfoSaveReq) {
projectInfoService.updateProductById(id,projectInfoSaveReq);
return Result.success();
}
/**

View File

@ -3,6 +3,7 @@ package com.muyu.product.service;
import java.util.List;
import com.muyu.product.domain.ProjectInfo;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.product.domain.req.ProjectInfoEditReq;
import com.muyu.product.domain.req.ProjectInfoSaveReq;
import com.muyu.product.domain.resp.ProjectDetailResp;
@ -34,4 +35,12 @@ public interface ProjectInfoService extends IService<ProjectInfo> {
* @return
*/
ProjectDetailResp getDetailInfo (Long id);
/**
*
* @param id
* @param projectInfoSaveReq
* @return
*/
void updateProductById(Long id, ProjectInfoSaveReq projectInfoSaveReq);
}

View File

@ -399,9 +399,11 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
if (cateGoryId.equals(0L)){
return;
}
CategoryInfo categoryInfo = this.getById(cateGoryId);
parentIdList.add(categoryInfo.getId());
getParentIdListByCateGoryId(parentIdList, categoryInfo.getParentId());
CategoryInfo categoryInfo = this.getById(cateGoryId); //category_info品类信息表
if (categoryInfo!=null){
parentIdList.add(categoryInfo.getId());
getParentIdListByCateGoryId(parentIdList, categoryInfo.getParentId());
}
}
/**
@ -414,28 +416,30 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
@Override
public CategoryCommonElementResp getTemplateAttributeByCateGoryId (Long cateGoryId) {
List<Long> cateGoryIdList = new ArrayList<>();
getParentIdListByCateGoryId(cateGoryIdList, cateGoryId);
// 取出和品类相关联的属性组关系 - 中间表
getParentIdListByCateGoryId(cateGoryIdList, cateGoryId); //品类信息id
// 取出和品类相关联的属性组关系 - 中间表 as_category_attribute_group and category_info
LambdaQueryWrapper<AsCategoryAttributeGroup> asCategoryAttributeGroupLambdaQueryWrapper = new LambdaQueryWrapper<>(){{
in(AsCategoryAttributeGroup::getCategoryId, cateGoryIdList);
}};
// 属性组中间表属性组id
List<AsCategoryAttributeGroup> categoryAttributeGroupList = asCategoryAttributeGroupService.list(asCategoryAttributeGroupLambdaQueryWrapper);
//属性组表信息 属性与组中间表
List<TemplateAttributeGroupModel> attributeGroupModelList = categoryAttributeGroupList.stream()
.map(AsCategoryAttributeGroup::getAttributeGroupId)
.map(AsCategoryAttributeGroup::getAttributeGroupId)//属性组中间表 取出属性组表去重id-getAttributeGroupId
.distinct()
.map(attributeGroupId -> TemplateAttributeGroupModel.attributeGroupBuild(
attributeGroupService.getById(attributeGroupId),
attributeGroupService.getById(attributeGroupId),//用去重后的属性组表id查找 attributeGroup
applyAttributeGroupId -> {
LambdaQueryWrapper<AsAttributeGroup> asAttributeGroupQueryWrapper = new LambdaQueryWrapper<>() {{
eq(AsAttributeGroup::getGroupId, applyAttributeGroupId);
}};
List<Long> attributeIdList = asAttributeGroupService.list(asAttributeGroupQueryWrapper).stream()
List<Long> attributeIdList = asAttributeGroupService.list(asAttributeGroupQueryWrapper).stream()//取出属性与组中间表的商品属性id
.map(AsAttributeGroup::getAttributeId)
.toList();
if (attributeIdList.isEmpty()) {
return new ArrayList<>();
}
return attributeInfoService.listByIds(attributeIdList).stream()
return attributeInfoService.listByIds(attributeIdList).stream()//取出属性与组中间表的商品属性id查找商品属性表
.map(AttributeInfo::buildTemplateModel)
.toList();
}
@ -443,7 +447,7 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
.filter(TemplateAttributeGroupModel::isEffective)
.toList();
// 查重集合
Set<Long> attributeIdSet = new HashSet<>();
Set<Long> attributeIdSet = new HashSet<>(); // 商品属性表id
// 获取组内所有的属性Id
if (!attributeGroupModelList.isEmpty()){
attributeIdSet.addAll(
@ -453,26 +457,25 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
.toList()
);
}
//查找商品属性表信息
List<TemplateAttributeModel> templateAttributeModelList = new ArrayList<>();
LambdaQueryWrapper<AsCategoryAttribute> categoryAttributeQueryWrapper = new LambdaQueryWrapper<>();
categoryAttributeQueryWrapper.in(AsCategoryAttribute::getCategoryId, cateGoryIdList);
List<AsCategoryAttribute> asCategoryAttributeList = asCategoryAttributeService.list(categoryAttributeQueryWrapper);
List<AsCategoryAttribute> asCategoryAttributeList = asCategoryAttributeService.list(categoryAttributeQueryWrapper); //品类属性中间表
if (asCategoryAttributeList != null && !asCategoryAttributeList.isEmpty()){
List<Long> templateAttributeIdList = asCategoryAttributeList.stream()
List<Long> templateAttributeIdList = asCategoryAttributeList.stream() //商品属性表id 过滤后的attribute_info品类属性表id
.map(AsCategoryAttribute::getAttributeId)
.filter(templateAttributeId -> !attributeIdSet.contains(templateAttributeId))
.toList();
templateAttributeModelList = attributeInfoService.listByIds(templateAttributeIdList).stream()
templateAttributeModelList = attributeInfoService.listByIds(templateAttributeIdList).stream()// 过滤后的品类属性中间表的商品属性id查找商品属性
.map(AttributeInfo::buildTemplateModel)
.toList();
}
List<TemplateAttributeModel> attributeModelList = new ArrayList<>();
if (!templateAttributeModelList.isEmpty()){
attributeIdSet.addAll(
templateAttributeModelList.stream().map(TemplateAttributeModel::getId).toList()
templateAttributeModelList.stream().map(TemplateAttributeModel::getId).toList()//商品属性表id
);
}

View File

@ -4,10 +4,12 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.alibaba.nacos.shaded.com.google.common.base.Supplier;
import com.muyu.common.core.utils.ObjUtils;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.product.domain.*;
import com.muyu.product.domain.model.*;
import com.muyu.product.domain.req.ProjectInfoEditReq;
import com.muyu.product.domain.req.ProjectInfoSaveReq;
import com.muyu.product.domain.resp.CategoryCommonElementResp;
import com.muyu.product.domain.resp.ProjectDetailResp;
@ -229,4 +231,41 @@ public class ProjectInfoServiceImpl extends ServiceImpl<ProjectInfoMapper, Proje
.attributeGroupList(templateAttributeGroupList)
.build();
}
/**
*
* @param id
* @param projectInfoSaveReq
*
* @return
*/
@Override
public void updateProductById(Long id, ProjectInfoSaveReq projectInfoSaveReq) {
//修改商品信息表
boolean b = this.updateById(ProjectInfo.editProductBuild(id, projectInfoSaveReq));
if (b){
//修改商品规格sku表
updSku(id,projectInfoSaveReq);
//修改商品属性中间表
updProduct(id,projectInfoSaveReq);
}
}
//修改商品属性中间表
private void updProduct(Long id, ProjectInfoSaveReq projectInfoSaveReq) {
//删除商品属性中间表
LambdaQueryWrapper<AsProductAttributeInfo> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(AsProductAttributeInfo::getProductId,id);
this.asProductAttributeInfoService.remove(wrapper);
//添加商品属性中间表
asProductAttributeInfoService.saveBatch(projectInfoSaveReq.getAttrValueList().stream().map(attrValueModel -> AsProductAttributeInfo.attrValueModelBuild(attrValueModel,()-> id)).toList());
}
//修改商品规格sku表
private void updSku(Long id, ProjectInfoSaveReq projectInfoSaveReq) {
//删除商品规格sku中间表
LambdaQueryWrapper<ProjectSkuInfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(ProjectSkuInfo::getProjectId,id);
this.projectSkuInfoService.remove(queryWrapper);
//两家商品规格中间表
projectSkuInfoService.saveBatch(projectInfoSaveReq.getProductSkuList().stream().map(productSkuModel -> ProjectSkuInfo.saveProductBuild(productSkuModel,()->id)).toList());
}
}