liyong
2026-05-07 1492ffd32e43d0294cc6ac9a4f4389cd50d91fe9
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.ruoyi.basic.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.dto.CustomerContactDto;
import com.ruoyi.basic.mapper.CustomerContactMapper;
import com.ruoyi.basic.pojo.CustomerContact;
import com.ruoyi.basic.service.CustomerContactService;
import com.ruoyi.common.utils.bean.BeanUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 客户联系人表 服务实现类
 * </p>
 *
 * @author 芯导软件(江苏)有限公司
 * @since 2026-05-07 03:46:40
 */
@Service
@RequiredArgsConstructor
public class CustomerContactServiceImpl extends ServiceImpl<CustomerContactMapper, CustomerContact> implements CustomerContactService {
 
    private final CustomerContactMapper customerContactMapper;
    @Override
    public IPage<CustomerContactDto> listPage(Page<CustomerContactDto> page, CustomerContactDto customerContactDto) {
        return customerContactMapper.listPage(page,customerContactDto);
    }
 
    @Override
    public Boolean add(CustomerContactDto customerContact) {
        List<Long> idList = customerContact.getCustomerIdList();
        if (idList != null && !idList.isEmpty()) {
            String result = idList.stream()
                    .filter(Objects::nonNull)
                    .distinct()
                    .map(String::valueOf) // 将 Long 转换为 String
                    .collect(Collectors.joining(","));
            customerContact.setCustomerId(result);
    }
        return save(customerContact);
 
    }
 
    @Override
    public Boolean updateCustomerContact(CustomerContactDto customerContact) {
        List<Long> idList = customerContact.getCustomerIdList();
        if (idList != null && !idList.isEmpty()) {
            String result = idList.stream()
                    .filter(Objects::nonNull)
                    .distinct()
                    .map(String::valueOf) // 将 Long 转换为 String
                    .collect(Collectors.joining(","));
            customerContact.setCustomerId(result);
        }
        return updateById(customerContact);
    }
 
    @Override
    public CustomerContactDto getCustomerContactDtoById(Long id) {
        CustomerContact byId = getById(id);
        CustomerContactDto customerContactDto = new CustomerContactDto();
        BeanUtils.copyProperties(byId, customerContactDto);
        if (byId != null && byId.getCustomerId() != null && !byId.getCustomerId().isEmpty()) {
            List<Long> idList = Arrays.stream(byId.getCustomerId().split(","))
                    .map(String::trim) // 去除可能的空格
                    .filter(s -> !s.isEmpty()) // 过滤空字符串
                    .map(Long::parseLong) // 转换为 Long
                    .collect(Collectors.toList());
            customerContactDto.setCustomerIdList(idList);
        } else {
            customerContactDto.setCustomerIdList(new ArrayList<>());
        }
        return customerContactDto;
    }
}