- 添加获取默认地址

pull/1/head
sin 2019-04-10 22:26:33 +08:00
parent 22d736050d
commit 90416d5431
4 changed files with 27 additions and 5 deletions

View File

@ -65,8 +65,15 @@ public class UserAddressController {
@GetMapping("address")
@ApiOperation(value = "获取地址")
public CommonResult getAddress(@RequestParam("id") Integer id) {
public CommonResult<UserAddressBO> getAddress(@RequestParam("id") Integer id) {
Integer userId = UserSecurityContextHolder.getContext().getUserId();
return userAddressService.getAddress(userId, id);
}
@GetMapping("default_address")
@ApiOperation(value = "获取默认地址")
public CommonResult<UserAddressBO> getDefaultAddress() {
Integer userId = UserSecurityContextHolder.getContext().getUserId();
return userAddressService.getDefaultAddress(userId);
}
}

View File

@ -24,4 +24,6 @@ public interface UserAddressService {
CommonResult<List<UserAddressBO>> addressList(Integer userId);
CommonResult<UserAddressBO> getAddress(Integer userId, Integer id);
CommonResult<UserAddressBO> getDefaultAddress(Integer userId);
}

View File

@ -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<UserAddressBO> getDefaultAddress(Integer userId) {
UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(
DeletedStatusEnum.DELETED_NO.getValue(),
userId,
UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue());
return CommonResult.success(UserAddressConvert.INSTANCE.convert(defaultUserAddress));
}
}

View File

@ -4,16 +4,16 @@
<sql id="FIELDS">
id, user_id, area_no, `name`, mobile, address,
create_time, update_time, deleted
create_time, update_time, has_default, deleted
</sql>
<insert id="insert" parameterType="UserAddressDO" useGeneratedKeys="true" keyProperty="id">
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}
)
</insert>
@ -35,6 +35,9 @@
<if test="userAddressDO.updateTime != null">
, update_time = #{userAddressDO.updateTime}
</if>
<if test="userAddressDO.hasDefault != null">
, has_default = #{userAddressDO.hasDefault}
</if>
<if test="userAddressDO.deleted != null">
, deleted = #{userAddressDO.deleted}
</if>