From 90416d5431b7f7cb9ba4b14efbddfe002014b328 Mon Sep 17 00:00:00 2001 From: sin <2943460818@qq.com> Date: Wed, 10 Apr 2019 22:26:33 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/users/UserAddressController.java | 9 ++++++++- .../cn/iocoder/mall/user/api/UserAddressService.java | 2 ++ .../user/biz/service/UserAddressServiceImpl.java | 12 +++++++++++- .../src/main/resources/mapper/UserAddress.xml | 9 ++++++--- 4 files changed, 27 insertions(+), 5 deletions(-) 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}