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()) .brandId(projectInfoEditReq.getBrandId())
.build(); .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()) .image(projectSkuInfoSaveReq.getImage())
.build(); .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 @AllArgsConstructor
public class ProductSkuModel { public class ProductSkuModel {
/** sku */ /** sku */
@ApiModelProperty(name = "sku", value = "sku", required = true) @ApiModelProperty(name = "sku", value = "sku", required = true)
private String sku; private String sku;

View File

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

View File

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

View File

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

View File

@ -3,6 +3,7 @@ package com.muyu.product.service;
import java.util.List; import java.util.List;
import com.muyu.product.domain.ProjectInfo; import com.muyu.product.domain.ProjectInfo;
import com.baomidou.mybatisplus.extension.service.IService; 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.req.ProjectInfoSaveReq;
import com.muyu.product.domain.resp.ProjectDetailResp; import com.muyu.product.domain.resp.ProjectDetailResp;
@ -34,4 +35,12 @@ public interface ProjectInfoService extends IService<ProjectInfo> {
* @return * @return
*/ */
ProjectDetailResp getDetailInfo (Long id); 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)){ if (cateGoryId.equals(0L)){
return; return;
} }
CategoryInfo categoryInfo = this.getById(cateGoryId); CategoryInfo categoryInfo = this.getById(cateGoryId); //category_info品类信息表
parentIdList.add(categoryInfo.getId()); if (categoryInfo!=null){
getParentIdListByCateGoryId(parentIdList, categoryInfo.getParentId()); parentIdList.add(categoryInfo.getId());
getParentIdListByCateGoryId(parentIdList, categoryInfo.getParentId());
}
} }
/** /**
@ -414,28 +416,30 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
@Override @Override
public CategoryCommonElementResp getTemplateAttributeByCateGoryId (Long cateGoryId) { public CategoryCommonElementResp getTemplateAttributeByCateGoryId (Long cateGoryId) {
List<Long> cateGoryIdList = new ArrayList<>(); List<Long> cateGoryIdList = new ArrayList<>();
getParentIdListByCateGoryId(cateGoryIdList, cateGoryId); getParentIdListByCateGoryId(cateGoryIdList, cateGoryId); //品类信息id
// 取出和品类相关联的属性组关系 - 中间表 // 取出和品类相关联的属性组关系 - 中间表 as_category_attribute_group and category_info
LambdaQueryWrapper<AsCategoryAttributeGroup> asCategoryAttributeGroupLambdaQueryWrapper = new LambdaQueryWrapper<>(){{ LambdaQueryWrapper<AsCategoryAttributeGroup> asCategoryAttributeGroupLambdaQueryWrapper = new LambdaQueryWrapper<>(){{
in(AsCategoryAttributeGroup::getCategoryId, cateGoryIdList); in(AsCategoryAttributeGroup::getCategoryId, cateGoryIdList);
}}; }};
// 属性组中间表属性组id
List<AsCategoryAttributeGroup> categoryAttributeGroupList = asCategoryAttributeGroupService.list(asCategoryAttributeGroupLambdaQueryWrapper); List<AsCategoryAttributeGroup> categoryAttributeGroupList = asCategoryAttributeGroupService.list(asCategoryAttributeGroupLambdaQueryWrapper);
//属性组表信息 属性与组中间表
List<TemplateAttributeGroupModel> attributeGroupModelList = categoryAttributeGroupList.stream() List<TemplateAttributeGroupModel> attributeGroupModelList = categoryAttributeGroupList.stream()
.map(AsCategoryAttributeGroup::getAttributeGroupId) .map(AsCategoryAttributeGroup::getAttributeGroupId)//属性组中间表 取出属性组表去重id-getAttributeGroupId
.distinct() .distinct()
.map(attributeGroupId -> TemplateAttributeGroupModel.attributeGroupBuild( .map(attributeGroupId -> TemplateAttributeGroupModel.attributeGroupBuild(
attributeGroupService.getById(attributeGroupId), attributeGroupService.getById(attributeGroupId),//用去重后的属性组表id查找 attributeGroup
applyAttributeGroupId -> { applyAttributeGroupId -> {
LambdaQueryWrapper<AsAttributeGroup> asAttributeGroupQueryWrapper = new LambdaQueryWrapper<>() {{ LambdaQueryWrapper<AsAttributeGroup> asAttributeGroupQueryWrapper = new LambdaQueryWrapper<>() {{
eq(AsAttributeGroup::getGroupId, applyAttributeGroupId); eq(AsAttributeGroup::getGroupId, applyAttributeGroupId);
}}; }};
List<Long> attributeIdList = asAttributeGroupService.list(asAttributeGroupQueryWrapper).stream() List<Long> attributeIdList = asAttributeGroupService.list(asAttributeGroupQueryWrapper).stream()//取出属性与组中间表的商品属性id
.map(AsAttributeGroup::getAttributeId) .map(AsAttributeGroup::getAttributeId)
.toList(); .toList();
if (attributeIdList.isEmpty()) { if (attributeIdList.isEmpty()) {
return new ArrayList<>(); return new ArrayList<>();
} }
return attributeInfoService.listByIds(attributeIdList).stream() return attributeInfoService.listByIds(attributeIdList).stream()//取出属性与组中间表的商品属性id查找商品属性表
.map(AttributeInfo::buildTemplateModel) .map(AttributeInfo::buildTemplateModel)
.toList(); .toList();
} }
@ -443,7 +447,7 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
.filter(TemplateAttributeGroupModel::isEffective) .filter(TemplateAttributeGroupModel::isEffective)
.toList(); .toList();
// 查重集合 // 查重集合
Set<Long> attributeIdSet = new HashSet<>(); Set<Long> attributeIdSet = new HashSet<>(); // 商品属性表id
// 获取组内所有的属性Id // 获取组内所有的属性Id
if (!attributeGroupModelList.isEmpty()){ if (!attributeGroupModelList.isEmpty()){
attributeIdSet.addAll( attributeIdSet.addAll(
@ -453,26 +457,25 @@ public class CategoryInfoServiceImpl extends ServiceImpl<CategoryInfoMapper, Cat
.toList() .toList()
); );
} }
//查找商品属性表信息
List<TemplateAttributeModel> templateAttributeModelList = new ArrayList<>(); List<TemplateAttributeModel> templateAttributeModelList = new ArrayList<>();
LambdaQueryWrapper<AsCategoryAttribute> categoryAttributeQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<AsCategoryAttribute> categoryAttributeQueryWrapper = new LambdaQueryWrapper<>();
categoryAttributeQueryWrapper.in(AsCategoryAttribute::getCategoryId, 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() //商品属性表id 过滤后的attribute_info品类属性表id
.map(AsCategoryAttribute::getAttributeId) .map(AsCategoryAttribute::getAttributeId)
.filter(templateAttributeId -> !attributeIdSet.contains(templateAttributeId)) .filter(templateAttributeId -> !attributeIdSet.contains(templateAttributeId))
.toList(); .toList();
templateAttributeModelList = attributeInfoService.listByIds(templateAttributeIdList).stream() templateAttributeModelList = attributeInfoService.listByIds(templateAttributeIdList).stream()// 过滤后的品类属性中间表的商品属性id查找商品属性
.map(AttributeInfo::buildTemplateModel) .map(AttributeInfo::buildTemplateModel)
.toList(); .toList();
} }
List<TemplateAttributeModel> attributeModelList = new ArrayList<>(); List<TemplateAttributeModel> attributeModelList = new ArrayList<>();
if (!templateAttributeModelList.isEmpty()){ if (!templateAttributeModelList.isEmpty()){
attributeIdSet.addAll( 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.Arrays;
import java.util.List; 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.core.utils.ObjUtils;
import com.muyu.common.security.utils.SecurityUtils; import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.product.domain.*; import com.muyu.product.domain.*;
import com.muyu.product.domain.model.*; 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.req.ProjectInfoSaveReq;
import com.muyu.product.domain.resp.CategoryCommonElementResp; import com.muyu.product.domain.resp.CategoryCommonElementResp;
import com.muyu.product.domain.resp.ProjectDetailResp; import com.muyu.product.domain.resp.ProjectDetailResp;
@ -229,4 +231,41 @@ public class ProjectInfoServiceImpl extends ServiceImpl<ProjectInfoMapper, Proje
.attributeGroupList(templateAttributeGroupList) .attributeGroupList(templateAttributeGroupList)
.build(); .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());
}
} }