xin
2 hours ago 501eba8c1c5b58fb3e5f442dcf892a460148e0c0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.oying.modules.pc.product.service.impl;
 
import cn.hutool.core.collection.CollectionUtil;
import com.oying.modules.pc.product.domain.ProductLabel;
import com.oying.modules.pc.product.domain.dto.ProductImageCreateRequest;
import com.oying.modules.pc.product.domain.dto.ProductMerchantUpdateRequest;
import com.oying.modules.pc.product.service.ProductImageService;
import com.oying.modules.pc.product.service.ProductLabelService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import java.util.List;
import java.util.stream.Collectors;
 
@Slf4j
@Service
@RequiredArgsConstructor
public class ProductMerchantLabelUpdateProcessor {
 
    private final ProductLabelService productLabelService;
 
    public void processLabelsUpdate(ProductMerchantUpdateRequest request) {
        if (CollectionUtil.isNotEmpty(request.getDeletedLabelIds())) {
            productLabelService.deleteAll(request.getDeletedLabelIds());
        }
        if (CollectionUtil.isNotEmpty(request.getUpdatedLabels())) {
            productLabelService.batchUpdate(request.getUpdatedLabels());
        }
        if (CollectionUtil.isNotEmpty(request.getNewLabels())) {
            List<ProductLabel> newLabels = request.getNewLabels().stream().peek(i-> i.setProductId(request.getProductId())).collect(Collectors.toList());
            productLabelService.batchCreate(newLabels);
        }
    }
 
}