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(); UserLoginDto user = jwtUtil.getUser();
userinfoShippingAddress.setUserId(user.getUserId()); userinfoShippingAddress.setUserId(user.getUserId());
List<UserinfoShippingAddress> checkList = userinfoShippingAddressDao.findByUserIdAndAcquiesce(user.getUserId(), UserInfoShippingAddressEnums.DEFAULT_ADDRESS.getCode()); if (Objects.equals(UserInfoShippingAddressEnums.NORMAL_ADDRESS.getCode(), userinfoShippingAddress.getAcquiesce())) {
if(checkList.isEmpty()) { // 如果是非默认地址,直接保存即可
userinfoShippingAddressDao.save(userinfoShippingAddress); userinfoShippingAddressDao.save(userinfoShippingAddress);
} else { } 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