|
|
|
@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.Objects; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@Service |
|
|
|
@ -47,17 +48,26 @@ public class CustomerAddressServiceImpl extends ServiceImpl<CustomerAddressMappe |
|
|
|
@Override |
|
|
|
public void customerAddressSave(CustomerAddressEntity data) { |
|
|
|
// 判断地址下的默认地址是否已存在 |
|
|
|
customerAddressMapper.selectList(new QueryWrapper<CustomerAddressEntity>() |
|
|
|
.eq("site", data.getSite()) |
|
|
|
.eq("customer_no", data.getCustomerNo()) |
|
|
|
.eq("address_type", data.getAddressType()) |
|
|
|
.eq("address_name", data.getAddressName()) |
|
|
|
.eq("default_address", data.getDefaultAddress())) |
|
|
|
.stream() |
|
|
|
.findAny() |
|
|
|
.ifPresent(a -> { |
|
|
|
throw new RuntimeException("该地址已存在这个默认地址!"); |
|
|
|
}); |
|
|
|
// customerAddressMapper.selectList(new QueryWrapper<CustomerAddressEntity>() |
|
|
|
// .eq("site", data.getSite()) |
|
|
|
// .eq("customer_no", data.getCustomerNo()) |
|
|
|
// .eq("address_type", data.getAddressType()) |
|
|
|
// .eq("address_name", data.getAddressName()) |
|
|
|
// .eq("default_address", data.getDefaultAddress())) |
|
|
|
// .stream() |
|
|
|
// .findAny() |
|
|
|
// .ifPresent(a -> { |
|
|
|
// throw new RuntimeException("该地址已存在这个默认地址!"); |
|
|
|
// }); |
|
|
|
if ("Y".equals(data.getDefaultAddress())) { |
|
|
|
List<CustomerAddressEntity> addressList = customerAddressMapper.selectList(new QueryWrapper<CustomerAddressEntity>().eq("site", data.getSite()).eq("customer_no", data.getCustomerNo())); |
|
|
|
if (!addressList.isEmpty()) { |
|
|
|
boolean b = addressList.stream().anyMatch(a -> "Y".equals(a.getDefaultAddress())); |
|
|
|
if (b) { |
|
|
|
throw new RuntimeException("该客户已存在默认地址!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
customerAddressMapper.insert(data); |
|
|
|
} |
|
|
|
|
|
|
|
@ -71,17 +81,26 @@ public class CustomerAddressServiceImpl extends ServiceImpl<CustomerAddressMappe |
|
|
|
@Override |
|
|
|
public void customerAddressEdit(CustomerAddressEntity data) { |
|
|
|
// 判断地址下的默认地址是否已存在 |
|
|
|
customerAddressMapper.selectList(new QueryWrapper<CustomerAddressEntity>() |
|
|
|
.eq("site", data.getSite()) |
|
|
|
.eq("customer_no", data.getCustomerNo()) |
|
|
|
.eq("address_type", data.getAddressType()) |
|
|
|
.eq("address_name", data.getAddressName()) |
|
|
|
.eq("default_address", data.getDefaultAddress())) |
|
|
|
.stream() |
|
|
|
.findAny() |
|
|
|
.ifPresent(a -> { |
|
|
|
throw new RuntimeException("该地址已存在这个默认地址!"); |
|
|
|
}); |
|
|
|
// customerAddressMapper.selectList(new QueryWrapper<CustomerAddressEntity>() |
|
|
|
// .eq("site", data.getSite()) |
|
|
|
// .eq("customer_no", data.getCustomerNo()) |
|
|
|
// .eq("address_type", data.getAddressType()) |
|
|
|
// .eq("address_name", data.getAddressName()) |
|
|
|
// .eq("default_address", data.getDefaultAddress())) |
|
|
|
// .stream() |
|
|
|
// .findAny() |
|
|
|
// .ifPresent(a -> { |
|
|
|
// throw new RuntimeException("该地址已存在这个默认地址!"); |
|
|
|
// }); |
|
|
|
if ("Y".equals(data.getDefaultAddress())) { |
|
|
|
List<CustomerAddressEntity> addressList = customerAddressMapper.selectList(new QueryWrapper<CustomerAddressEntity>().eq("site", data.getSite()).eq("customer_no", data.getCustomerNo())); |
|
|
|
if (!addressList.isEmpty()) { |
|
|
|
List<CustomerAddressEntity> collect = addressList.stream().filter(a -> "Y".equals(a.getDefaultAddress()) && !Objects.equals(a.getAddressId(), data.getAddressId())).collect(Collectors.toList()); |
|
|
|
if (!collect.isEmpty()) { |
|
|
|
throw new RuntimeException("该客户已存在默认地址!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
customerAddressMapper.updateById(data); |
|
|
|
} |
|
|
|
|
|
|
|
|