diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/UserAddressController.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/UserAddressController.java index d2ceb0623..15482399e 100644 --- a/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/UserAddressController.java +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/UserAddressController.java @@ -65,8 +65,15 @@ public class UserAddressController { @GetMapping("address") @ApiOperation(value = "获取地址") - public CommonResult getAddress(@RequestParam("id") Integer id) { + public CommonResult getAddress(@RequestParam("id") Integer id) { Integer userId = UserSecurityContextHolder.getContext().getUserId(); return userAddressService.getAddress(userId, id); } + + @GetMapping("default_address") + @ApiOperation(value = "获取默认地址") + public CommonResult getDefaultAddress() { + Integer userId = UserSecurityContextHolder.getContext().getUserId(); + return userAddressService.getDefaultAddress(userId); + } } diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/UserAddressService.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/UserAddressService.java index 275c993c2..cec76af71 100644 --- a/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/UserAddressService.java +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/api/UserAddressService.java @@ -24,4 +24,6 @@ public interface UserAddressService { CommonResult> addressList(Integer userId); CommonResult getAddress(Integer userId, Integer id); + + CommonResult getDefaultAddress(Integer userId); } diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/UserAddressServiceImpl.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/UserAddressServiceImpl.java index 0c0cef806..d2c4ced7e 100644 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/UserAddressServiceImpl.java +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/UserAddressServiceImpl.java @@ -84,7 +84,6 @@ public class UserAddressServiceImpl implements UserAddressService { } } - UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault( DeletedStatusEnum.DELETED_NO.getValue(), userAddressAddDTO.getUserId(), UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue()); @@ -149,4 +148,15 @@ public class UserAddressServiceImpl implements UserAddressService { UserAddressBO userAddressBO = UserAddressConvert.INSTANCE.convert(userAddress); return CommonResult.success(userAddressBO); } + + @Override + public CommonResult getDefaultAddress(Integer userId) { + + UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault( + DeletedStatusEnum.DELETED_NO.getValue(), + userId, + UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue()); + + return CommonResult.success(UserAddressConvert.INSTANCE.convert(defaultUserAddress)); + } } diff --git a/user/user-service-impl/src/main/resources/mapper/UserAddress.xml b/user/user-service-impl/src/main/resources/mapper/UserAddress.xml index 277caa851..20432b8f6 100644 --- a/user/user-service-impl/src/main/resources/mapper/UserAddress.xml +++ b/user/user-service-impl/src/main/resources/mapper/UserAddress.xml @@ -4,16 +4,16 @@ id, user_id, area_no, `name`, mobile, address, - create_time, update_time, deleted + create_time, update_time, has_default, deleted INSERT INTO user_address ( user_id, area_no, `name`, mobile, address, - create_time, update_time, deleted + create_time, update_time, has_default, deleted ) VALUES ( #{userId}, #{areaNo}, #{name}, #{mobile}, #{address}, - #{createTime}, #{updateTime}, #{deleted} + #{createTime}, #{updateTime}, #{hasDefault}, #{deleted} ) @@ -35,6 +35,9 @@ , update_time = #{userAddressDO.updateTime} + + , has_default = #{userAddressDO.hasDefault} + , deleted = #{userAddressDO.deleted}