liyong
2026-05-15 0578c6c76f13e367b5dc7d0882efe3c69ca4cb0e
src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java
@@ -364,11 +364,55 @@
                    .eq(CustomerUser::getCustomerId, id)
            );
        }
        // 删除客户对应的联系人关联
        removeCustomerContactsByCustomerIds(idList);
        // 删除客户主表数据
        return customerMapper.deleteBatchIds(idList);
    }
    private void removeCustomerContactsByCustomerIds(List<Long> customerIds) {
        if (CollectionUtils.isEmpty(customerIds)) {
            return;
        }
        List<CustomerContact> customerContacts = customerContactMapper.selectList(new QueryWrapper<>());
        if (CollectionUtils.isEmpty(customerContacts)) {
            return;
        }
        Set<Long> customerIdSet = customerIds.stream()
                .filter(Objects::nonNull)
                .collect(Collectors.toSet());
        for (CustomerContact customerContact : customerContacts) {
            String contactCustomerIds = customerContact.getCustomerId();
            if (StringUtils.isEmpty(contactCustomerIds)) {
                continue;
            }
            String updatedCustomerIds = Arrays.stream(contactCustomerIds.split(","))
                    .map(String::trim)
                    .filter(StringUtils::isNotEmpty)
                    .filter(id -> {
                        Long parsedId = parseCustomerId(id);
                        return parsedId == null || !customerIdSet.contains(parsedId);
                    })
                    .distinct()
                    .collect(Collectors.joining(","));
            if (StringUtils.isEmpty(updatedCustomerIds)) {
                customerContactMapper.deleteById(customerContact.getId());
            } else if (!updatedCustomerIds.equals(contactCustomerIds)) {
                customerContact.setCustomerId(updatedCustomerIds);
                customerContactMapper.updateById(customerContact);
            }
        }
    }
    private Long parseCustomerId(String customerId) {
        try {
            return Long.valueOf(customerId);
        } catch (NumberFormatException e) {
            return null;
        }
    }
    @Override
    public List<Customer> selectCustomerListByIds(Long[] ids) {
        LambdaQueryWrapper<Customer> queryWrapper = new LambdaQueryWrapper<>();