diff --git a/src/main/java/com/spring/modules/customer/controller/CustomerAddressController.java b/src/main/java/com/spring/modules/customer/controller/CustomerAddressController.java index bffdae06..6035b499 100644 --- a/src/main/java/com/spring/modules/customer/controller/CustomerAddressController.java +++ b/src/main/java/com/spring/modules/customer/controller/CustomerAddressController.java @@ -64,7 +64,7 @@ public class CustomerAddressController { } /** - * @description: 客户联系人删除 + * @description: 客户联系地址删除 * @author: fengyuan_yang * @date: 2023/9/4 13:29 * @param: [data] diff --git a/src/main/java/com/spring/modules/customer/service/impl/CustomerAddressServiceImpl.java b/src/main/java/com/spring/modules/customer/service/impl/CustomerAddressServiceImpl.java index 4ee8f03c..8c99ace5 100644 --- a/src/main/java/com/spring/modules/customer/service/impl/CustomerAddressServiceImpl.java +++ b/src/main/java/com/spring/modules/customer/service/impl/CustomerAddressServiceImpl.java @@ -3,6 +3,7 @@ package com.spring.modules.customer.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.spring.modules.customer.entity.CustomerAddressEntity; +import com.spring.modules.customer.entity.CustomerContactEntity; import com.spring.modules.customer.mapper.CustomerAddressMapper; import com.spring.modules.customer.service.CustomerAddressService; import com.spring.modules.customer.vo.CustomerAddressVo; @@ -43,6 +44,12 @@ public class CustomerAddressServiceImpl extends ServiceImpl wrapper = new QueryWrapper<>(); - wrapper.eq("site", data.getSite()); - wrapper.eq("customer_no", data.getCustomerNo()); - List list = customerAddressMapper.selectList(wrapper); - boolean bool = list.stream().anyMatch(a -> "Y".equals(a.getPrimaryAddress())); - if (bool){ - throw new RuntimeException("已存在主联系地址!"); + // 判断之前是否为主联系人 + CustomerAddressEntity customerAddress = customerAddressMapper.selectById(data); + // 如果不是,就判断是否已存在主联系人 + if (!"Y".equals(customerAddress.getPrimaryAddress())) { + if (queryPrimaryAddress(data)){ + throw new RuntimeException("已存在主联系地址!"); + } } } customerAddressMapper.updateById(data); } /** - * @description: 客户联系人删除 + * @description: 客户联系地址删除 * @author: fengyuan_yang * @date: 2023/9/4 16:32 * @param: [data] @@ -78,10 +85,28 @@ public class CustomerAddressServiceImpl extends ServiceImpl ids = data.getAddressList().stream() .map(a -> a.getAddressId()) .collect(Collectors.toList()); customerAddressMapper.deleteBatchIds(ids); } + + /** + * @description: 判断是否已存在主联系地址 + * @author: fengyuan_yang + * @date: 2023/9/7 14:12 + * @param: [data] + * @return: java.lang.Boolean + **/ + public Boolean queryPrimaryAddress(CustomerAddressEntity data) { + // 获取客户的联系地址列表 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("site", data.getSite()); + wrapper.eq("customer_no", data.getCustomerNo()); + List list = customerAddressMapper.selectList(wrapper); + // 判断是否已有主联系地址 + boolean bool = list.stream().anyMatch(a -> "Y".equals(a.getPrimaryAddress())); + return bool; + } } diff --git a/src/main/java/com/spring/modules/customer/service/impl/CustomerContactServiceImpl.java b/src/main/java/com/spring/modules/customer/service/impl/CustomerContactServiceImpl.java index ebae8616..538337cb 100644 --- a/src/main/java/com/spring/modules/customer/service/impl/CustomerContactServiceImpl.java +++ b/src/main/java/com/spring/modules/customer/service/impl/CustomerContactServiceImpl.java @@ -43,6 +43,12 @@ public class CustomerContactServiceImpl extends ServiceImpl wrapper = new QueryWrapper<>(); - wrapper.eq("site", data.getSite()); - wrapper.eq("customer_no", data.getCustomerNo()); - List list = customerContactMapper.selectList(wrapper); - boolean bool = list.stream().anyMatch(a -> "Y".equals(a.getPrimaryContact())); - if (bool){ - throw new RuntimeException("已存在主联系人!"); + // 判断之前是否为主联系人 + CustomerContactEntity customerContact = customerContactMapper.selectById(data); + // 如果不是,就判断是否已存在主联系人 + if (!"Y".equals(customerContact.getPrimaryContact())) { + if (queryPrimaryContact(data)){ + throw new RuntimeException("已存在主联系人!"); + } } } customerContactMapper.updateById(data); @@ -84,4 +90,22 @@ public class CustomerContactServiceImpl extends ServiceImpl wrapper = new QueryWrapper<>(); + wrapper.eq("site", data.getSite()); + wrapper.eq("customer_no", data.getCustomerNo()); + List list = customerContactMapper.selectList(wrapper); + // 判断是否已有主联系人 + boolean bool = list.stream().anyMatch(a -> "Y".equals(a.getPrimaryContact())); + return bool; + } } diff --git a/src/main/java/com/spring/modules/customer/service/impl/CustomerInformationServiceImpl.java b/src/main/java/com/spring/modules/customer/service/impl/CustomerInformationServiceImpl.java index 5bb1d88e..89430e45 100644 --- a/src/main/java/com/spring/modules/customer/service/impl/CustomerInformationServiceImpl.java +++ b/src/main/java/com/spring/modules/customer/service/impl/CustomerInformationServiceImpl.java @@ -42,24 +42,6 @@ public class CustomerInformationServiceImpl extends ServiceImpl updateContactWrapper = new UpdateWrapper<>(); - updateContactWrapper.eq("site", data.getSite()); - updateContactWrapper.eq("customer_no", data.getCustomerNo()); - updateContactWrapper.eq("primary_contact", data.getPrimaryContact()); - customerContactMapper.update(customerContactData, updateContactWrapper); - // 编辑主联系地址 - + // 1. 编辑客户主联系人 + // 1.1 判断联系人姓名是否修改 + Map columnMap = new HashMap<>(); + columnMap.put("site", data.getSite()); + columnMap.put("customer_no", data.getCustomerNo()); + columnMap.put("primary_contact", data.getPrimaryContact()); + List contactList = customerContactMapper.selectByMap(columnMap); + if (contactList.size() > 0 && contactList.get(0) != null && StringUtils.isNotBlank(data.getContactName())) { + // 1.2 修改主联系人 + if (!contactList.get(0).getContactName().equals(data.getContactName())) { + CustomerContactEntity customerContactData = getCustomerContactData(data); + customerContactData.setUpdateBy(data.getUpdateBy()); + UpdateWrapper updateContactWrapper = new UpdateWrapper<>(); + updateContactWrapper.eq("site", data.getSite()); + updateContactWrapper.eq("customer_no", data.getCustomerNo()); + updateContactWrapper.eq("primary_contact", data.getPrimaryContact()); + customerContactMapper.update(customerContactData, updateContactWrapper); + } + } + // 2. 编辑主联系地址 + // 2.1 判断联系地址姓名是否修改 + columnMap.remove("primary_contact"); + columnMap.put("primary_address", "Y"); + List addressList = customerAddressMapper.selectByMap(columnMap); + if (addressList.size() > 0 && addressList.get(0) != null && StringUtils.isNotBlank(data.getAddressName())) { + // 2.2 修改主联系地址 + if (!addressList.get(0).getAddressName().equals(data.getAddressName())) { + CustomerAddressEntity customerAddressData = new CustomerAddressEntity(); + customerAddressData.setUpdateBy(data.getUpdateBy()); + customerAddressData.setAddressName(data.getAddressName()); + UpdateWrapper updateAddressWrapper = new UpdateWrapper<>(); + updateAddressWrapper.eq("site", data.getSite()); + updateAddressWrapper.eq("customer_no", data.getCustomerNo()); + updateAddressWrapper.eq("primary_address", data.getPrimaryAddress()); + customerAddressMapper.update(customerAddressData, updateAddressWrapper); + } + } } /** @@ -149,4 +158,22 @@ public class CustomerInformationServiceImpl extends ServiceImpl