| | |
| | | .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 |
| | |
| | | @Override |
| | | public void assignCustomer(CustomerDto customerDto) { |
| | | Customer customer = customerMapper.selectById(customerDto.getId()); |
| | | if (customer.getType() == 1 && customer.getIsAssigned() == 0) { // 公海且可分配 |
| | | if (customer.getType() == 1 ) { // 公海且可分配 |
| | | customer.setIsAssigned(1); |
| | | customer.setUsageStatus(1L); |
| | | customer.setUsageUser(customerDto.getUsageUser()); |