release: 修复收货地址bug

release-2024-04-25
huangyw 3 months ago
parent 084f72850a
commit 56c1d9401a

@ -88,12 +88,19 @@ public class UserinfoShippingAddressService {
UserLoginDto user = jwtUtil.getUser();
userinfoShippingAddress.setUserId(user.getUserId());
List<UserinfoShippingAddress> 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<UserinfoShippingAddress> 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);
}
}

Loading…
Cancel
Save