商品修改 商品分组

This commit is contained in:
2026-04-28 15:58:32 +08:00
parent 36687abe0f
commit 04ed3a5f5b
2 changed files with 32 additions and 0 deletions

View File

@@ -43,6 +43,11 @@ public class ProductDTO implements Serializable {
*/
@NotNull(message = "商品分类不能为空", groups = DefaultGroup.class)
private Long categoryId;
/**
* 商品分组
*/
private List<Long> proGroupIds;
/**
* 商品分类名称
*/

View File

@@ -449,6 +449,8 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
List<ProdConsRelationDTO> 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<ProductMapper, Product> impl
entity.setRelatedRecommend(dto.getRelatedRecommendStr());
super.save(entity);
dto.setId(entity.getId());
List<Long> groupIds = dto.getProGroupIds();
if (CollUtil.isNotEmpty(groupIds)) {
List<ProdGroupRelation> 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<ProdSkuDTO> skuList = dto.getSkuList();
if (CollUtil.isNotEmpty(skuList)) {
List<ProdSku> prodSkuList = new ArrayList<>();
@@ -556,6 +570,19 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
List<Long> list = skuList.stream().map(ProdSkuDTO::getId).filter(Objects::nonNull).distinct().toList();
skuIdList.removeAll(list);
}
List<Long> groupIds = dto.getProGroupIds();
if (CollUtil.isNotEmpty(groupIds)) {
prodGroupRelationMapper.deleteByQuery(query().eq(ProdGroupRelation::getProductId, entity.getId()));
List<ProdGroupRelation> 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());