From 56c1d9401aba1e7117e6a9a09b477efa4c81e060 Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Tue, 5 Nov 2024 10:01:14 +0800 Subject: [PATCH] =?UTF-8?q?release:=20=E4=BF=AE=E5=A4=8D=E6=94=B6=E8=B4=A7?= =?UTF-8?q?=E5=9C=B0=E5=9D=80bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/UserinfoShippingAddressService.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserinfoShippingAddressService.java b/luoo_user/src/main/java/com/luoo/user/service/UserinfoShippingAddressService.java index 2aa9421..8eaf4a1 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserinfoShippingAddressService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserinfoShippingAddressService.java @@ -88,12 +88,19 @@ public class UserinfoShippingAddressService { UserLoginDto user = jwtUtil.getUser(); userinfoShippingAddress.setUserId(user.getUserId()); - List checkList = userinfoShippingAddressDao.findByUserIdAndAcquiesce(user.getUserId(), UserInfoShippingAddressEnums.DEFAULT_ADDRESS.getCode()); - if(checkList.isEmpty()) { + if (Objects.equals(UserInfoShippingAddressEnums.NORMAL_ADDRESS.getCode(), userinfoShippingAddress.getAcquiesce())) { + // 如果是非默认地址,直接保存即可 userinfoShippingAddressDao.save(userinfoShippingAddress); } else { - // 请勿重复添加默认地址! - throw new RuntimeException(ErrorConstants.DEFAULT_ADDRESS_CANNOT_BE_ADDED_AGAIN); + // 如果是默认地址,将原先的默认地址改为非默认地址 + List checkList = userinfoShippingAddressDao.findByUserIdAndAcquiesceAndIdIsNot(user.getUserId(), UserInfoShippingAddressEnums.DEFAULT_ADDRESS.getCode(), userinfoShippingAddress.getId()); + if(!checkList.isEmpty()) { + checkList.forEach(item -> { + item.setAcquiesce(UserInfoShippingAddressEnums.NORMAL_ADDRESS.getCode()); + userinfoShippingAddressDao.save(item); + }); + } + userinfoShippingAddressDao.save(userinfoShippingAddress); } }