diff --git a/cash-common/cash-common-service/src/main/java/com/czg/product/dto/ProductDTO.java b/cash-common/cash-common-service/src/main/java/com/czg/product/dto/ProductDTO.java index defc4f704..e782fd3e6 100644 --- a/cash-common/cash-common-service/src/main/java/com/czg/product/dto/ProductDTO.java +++ b/cash-common/cash-common-service/src/main/java/com/czg/product/dto/ProductDTO.java @@ -43,6 +43,11 @@ public class ProductDTO implements Serializable { */ @NotNull(message = "商品分类不能为空", groups = DefaultGroup.class) private Long categoryId; + /** + * 商品分组 + */ + private List proGroupIds; + /** * 商品分类名称 */ diff --git a/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ProductServiceImpl.java b/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ProductServiceImpl.java index 9127371be..aad24b992 100644 --- a/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ProductServiceImpl.java +++ b/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ProductServiceImpl.java @@ -449,6 +449,8 @@ public class ProductServiceImpl extends ServiceImpl impl List consList = prodConsRelationService.selectListByProdId(dto.getId()); dto.setConsList(consList); dto.setRelatedRecommendJson(getRelateProductList(dto.getRelatedRecommend())); + dto.setProGroupIds(prodGroupRelationMapper.selectListByQueryAs(query().select(ProdGroupRelation::getProdGroupId) + .eq(ProdGroupRelation::getProductId, dto.getId()), Long.class)); return dto; } @@ -478,6 +480,18 @@ public class ProductServiceImpl extends ServiceImpl impl entity.setRelatedRecommend(dto.getRelatedRecommendStr()); super.save(entity); dto.setId(entity.getId()); + List groupIds = dto.getProGroupIds(); + if (CollUtil.isNotEmpty(groupIds)) { + List prodGroupRelations = new ArrayList<>(); + for (Long groupId : groupIds) { + ProdGroupRelation prodGroupRelation = new ProdGroupRelation(); + prodGroupRelation.setProductId(entity.getId()); + prodGroupRelation.setProdGroupId(groupId); + prodGroupRelations.add(prodGroupRelation); + } + prodGroupRelationMapper.insertBatch(prodGroupRelations); + } + List skuList = dto.getSkuList(); if (CollUtil.isNotEmpty(skuList)) { List prodSkuList = new ArrayList<>(); @@ -556,6 +570,19 @@ public class ProductServiceImpl extends ServiceImpl impl List list = skuList.stream().map(ProdSkuDTO::getId).filter(Objects::nonNull).distinct().toList(); skuIdList.removeAll(list); } + List groupIds = dto.getProGroupIds(); + if (CollUtil.isNotEmpty(groupIds)) { + prodGroupRelationMapper.deleteByQuery(query().eq(ProdGroupRelation::getProductId, entity.getId())); + List prodGroupRelations = new ArrayList<>(); + for (Long groupId : groupIds) { + ProdGroupRelation prodGroupRelation = new ProdGroupRelation(); + prodGroupRelation.setProductId(entity.getId()); + prodGroupRelation.setProdGroupId(groupId); + prodGroupRelations.add(prodGroupRelation); + } + prodGroupRelationMapper.insertBatch(prodGroupRelations); + } + ProdConsBindDTO prodConsBindDTO = new ProdConsBindDTO(); prodConsBindDTO.setId(dto.getId()); prodConsBindDTO.setConsList(dto.getConsList());