- 修改结构:用户地址

This commit is contained in:
cherishsince 2020-05-01 10:43:58 +08:00
parent 4e6d3ff382
commit c40b43eda4
15 changed files with 726 additions and 0 deletions

View File

@ -0,0 +1,46 @@
package cn.iocoder.mall.system.biz.bo.user;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* 用户地址
*
* @author Sin
* @time 2019-04-06 13:28
*/
@Data
@Accessors(chain = true)
public class UserAddressBO implements Serializable {
/**
* 编号
*/
private Integer id;
/**
* 用户编号
*/
private Integer userId;
/**
* 收件区域编号
*/
private String areaNo;
/**
* 收件人名称
*/
private String name;
/**
* 收件手机号
*/
private String mobile;
/**
* 收件详细地址
*/
private String address;
/**
* 是否默认
*/
private Integer hasDefault;
}

View File

@ -0,0 +1,35 @@
package cn.iocoder.mall.system.biz.convert.user;
import cn.iocoder.mall.system.biz.bo.user.UserAddressBO;
import cn.iocoder.mall.system.biz.dataobject.user.UserAddressDO;
import cn.iocoder.mall.system.biz.dto.user.UserAddressAddDTO;
import cn.iocoder.mall.system.biz.dto.user.UserAddressUpdateDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 用户地址 convert
*
* @author Sin
* @time 2019-04-06 13:38
*/
@Mapper
public interface UserAddressConvert {
UserAddressConvert INSTANCE = Mappers.getMapper(UserAddressConvert.class);
@Mappings({})
UserAddressDO convert(UserAddressAddDTO userAddressAddDTO);
@Mappings({})
UserAddressDO convert(UserAddressUpdateDTO userAddressUpdateDTO);
@Mappings({})
UserAddressBO convert(UserAddressDO userAddressDO);
@Mappings({})
List<UserAddressBO> convertUserAddressBOList(List<UserAddressDO> userAddressDOList);
}

View File

@ -0,0 +1,40 @@
package cn.iocoder.mall.system.biz.dao.user;
import cn.iocoder.mall.system.biz.dataobject.user.UserAddressDO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* 用户 地址
*
* @author Sin
* @time 2019-04-06 13:29
*/
@Repository
public interface UserAddressMapper {
int insert(UserAddressDO userAddressDO);
int updateById(
@Param("id") Integer id,
@Param("userAddressDO") UserAddressDO userAddressDO
);
List<UserAddressDO> selectByUserIdAndDeleted(
Integer deleted,
Integer userId
);
UserAddressDO selectByUserIdAndId(
Integer userId,
Integer id
);
UserAddressDO selectHasDefault(
Integer deleted,
Integer userId,
Integer hasDefault
);
}

View File

@ -0,0 +1,46 @@
package cn.iocoder.mall.system.biz.dataobject.user;
import cn.iocoder.mall.mybatis.dataobject.DeletableDO;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* 用户地址信息
*
* @author Sin
* @time 2019-04-06 13:22
*/
@Data
@Accessors(chain = true)
public class UserAddressDO extends DeletableDO {
/**
* 编号
*/
private Integer id;
/**
* 用户编号
*/
private Integer userId;
/**
* 收件区域编号
*/
private String areaNo;
/**
* 收件人名称
*/
private String name;
/**
* 收件手机号
*/
private String mobile;
/**
* 收件详细地址
*/
private String address;
/**
* 是否为默认
*/
private Integer hasDefault;
}

View File

@ -0,0 +1,45 @@
package cn.iocoder.mall.system.biz.dto.user;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* 用户地址 add
*
* @author Sin
* @time 2019-04-06 13:25
*/
@Data
@Accessors(chain = true)
public class UserAddressAddDTO implements Serializable {
/**
* 收件区域编号
*/
private Integer userId;
/**
* 收件区域编号
*/
private String areaNo;
/**
* 收件人名称
*/
private String name;
/**
* 收件手机号
*/
private String mobile;
/**
* 收件详细地址
*/
private String address;
/**
* 是否默认
*
* - 1 不是
* - 2
*/
private Integer hasDefault;
}

View File

@ -0,0 +1,46 @@
package cn.iocoder.mall.system.biz.dto.user;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* 用户地址 更新
*
* @author Sin
* @time 2019-04-06 13:28
*/
@Data
@Accessors(chain = true)
public class UserAddressUpdateDTO implements Serializable {
/**
* 编号
*/
private Integer id;
/**
* 用户编号
*/
private Integer userId;
/**
* 收件区域编号
*/
private String areaNo;
/**
* 收件人名称
*/
private String name;
/**
* 收件手机号
*/
private String mobile;
/**
* 收件详细地址
*/
private String address;
/**
* 是否默认地址
*/
private Integer hasDefault;
}

View File

@ -0,0 +1,30 @@
package cn.iocoder.mall.system.biz.enums;
/**
* 用户地址 - 用户默认地址
*
* @author Sin
* @time 2019-04-10 22:02
*/
public enum UserAddressHasDefaultEnum {
DEFAULT_ADDRESS_NO (1, "不是默认地址"),
DEFAULT_ADDRESS_YES (2, "不是默认地址")
;
private final int value;
private final String name;
UserAddressHasDefaultEnum(int value, String name) {
this.value = value;
this.name = name;
}
public int getValue() {
return value;
}
public String getName() {
return name;
}
}

View File

@ -0,0 +1,28 @@
package cn.iocoder.mall.system.biz.service.user;
import cn.iocoder.mall.system.biz.bo.user.UserAddressBO;
import cn.iocoder.mall.system.biz.dto.user.UserAddressAddDTO;
import cn.iocoder.mall.system.biz.dto.user.UserAddressUpdateDTO;
import java.util.List;
/**
* 用户地址
*
* @author Sin
* @time 2019-04-06 13:24
*/
public interface UserAddressService {
void addAddress(UserAddressAddDTO userAddressAddDTO);
void updateAddress(UserAddressUpdateDTO userAddressAddDTO);
void removeAddress(Integer userId, Integer addressId);
List<UserAddressBO> addressList(Integer userId);
UserAddressBO getAddress(Integer userId, Integer id);
UserAddressBO getDefaultAddress(Integer userId);
}

View File

@ -0,0 +1,155 @@
package cn.iocoder.mall.system.biz.service.user;
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum;
import cn.iocoder.mall.system.biz.bo.user.UserAddressBO;
import cn.iocoder.mall.system.biz.convert.user.UserAddressConvert;
import cn.iocoder.mall.system.biz.dao.user.UserAddressMapper;
import cn.iocoder.mall.system.biz.dataobject.user.UserAddressDO;
import cn.iocoder.mall.system.biz.dto.user.UserAddressAddDTO;
import cn.iocoder.mall.system.biz.dto.user.UserAddressUpdateDTO;
import cn.iocoder.mall.system.biz.enums.UserAddressHasDefaultEnum;
import cn.iocoder.mall.system.biz.enums.UserErrorCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
/**
* 用户地址
*
* @author Sin
* @time 2019-04-06 13:26
*/
@Service
public class UserAddressServiceImpl implements UserAddressService {
@Autowired
private UserAddressMapper userAddressMapper;
@Override
@Transactional
public void addAddress(UserAddressAddDTO userAddressAddDTO) {
UserAddressDO userAddressDO = UserAddressConvert.INSTANCE.convert(userAddressAddDTO);
userAddressDO.setCreateTime(new Date());
userAddressDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
// 检查是否设置为默认地址
if (UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue() == userAddressAddDTO.getHasDefault()) {
UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(
DeletedStatusEnum.DELETED_NO.getValue(),
userAddressAddDTO.getUserId(), UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue());
if (defaultUserAddress != null) {
userAddressMapper.updateById(defaultUserAddress.getId(),
new UserAddressDO()
.setHasDefault(UserAddressHasDefaultEnum.DEFAULT_ADDRESS_NO.getValue())
);
}
}
userAddressMapper.insert(userAddressDO);
}
@Override
public void updateAddress(UserAddressUpdateDTO userAddressAddDTO) {
UserAddressDO userAddress = userAddressMapper
.selectByUserIdAndId(userAddressAddDTO.getUserId(), userAddressAddDTO.getId());
if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) {
throw ServiceExceptionUtil.exception(UserErrorCodeEnum.USER_ADDRESS_IS_DELETED.getCode());
}
if (userAddress == null) {
throw ServiceExceptionUtil.exception(UserErrorCodeEnum.USER_ADDRESS_NOT_EXISTENT.getCode());
}
// 检查是否设置为默认地址
if (UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue() == userAddressAddDTO.getHasDefault()) {
UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(
DeletedStatusEnum.DELETED_NO.getValue(),
userAddressAddDTO.getUserId(), UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue());
if (defaultUserAddress != null && !userAddressAddDTO.getId().equals(defaultUserAddress.getId())) {
userAddressMapper.updateById(defaultUserAddress.getId(),
new UserAddressDO()
.setHasDefault(UserAddressHasDefaultEnum.DEFAULT_ADDRESS_NO.getValue())
);
}
}
UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(
DeletedStatusEnum.DELETED_NO.getValue(),
userAddressAddDTO.getUserId(), UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue());
if (defaultUserAddress != null && !userAddressAddDTO.getId().equals(defaultUserAddress.getId())) {
userAddressMapper.updateById(defaultUserAddress.getId(),
new UserAddressDO()
.setHasDefault(UserAddressHasDefaultEnum.DEFAULT_ADDRESS_NO.getValue())
);
}
UserAddressDO userAddressDO = UserAddressConvert.INSTANCE.convert(userAddressAddDTO);
userAddressDO.setUpdateTime(new Date());
userAddressMapper.updateById(userAddressDO.getId(), userAddressDO);
}
@Override
public void removeAddress(Integer userId, Integer addressId) {
UserAddressDO userAddress = userAddressMapper.selectByUserIdAndId(userId, addressId);
if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) {
// skip
return;
}
if (userAddress == null) {
throw ServiceExceptionUtil.exception(UserErrorCodeEnum.USER_ADDRESS_NOT_EXISTENT.getCode());
}
userAddressMapper.updateById(
addressId,
(UserAddressDO) new UserAddressDO()
.setDeleted(DeletedStatusEnum.DELETED_YES.getValue())
);
}
@Override
public List<UserAddressBO> addressList(Integer userId) {
List<UserAddressDO> userAddressDOList = userAddressMapper
.selectByUserIdAndDeleted(DeletedStatusEnum.DELETED_NO.getValue(), userId);
List<UserAddressBO> userAddressBOList = UserAddressConvert
.INSTANCE.convertUserAddressBOList(userAddressDOList);
return userAddressBOList;
}
@Override
public UserAddressBO getAddress(Integer userId, Integer id) {
UserAddressDO userAddress = userAddressMapper.selectByUserIdAndId(userId, id);
if (userAddress == null) {
throw ServiceExceptionUtil.exception(UserErrorCodeEnum.USER_GET_ADDRESS_NOT_EXISTS.getCode());
}
if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) {
throw ServiceExceptionUtil.exception(UserErrorCodeEnum.USER_ADDRESS_IS_DELETED.getCode());
}
UserAddressBO userAddressBO = UserAddressConvert.INSTANCE.convert(userAddress);
return userAddressBO;
}
@Override
public UserAddressBO getDefaultAddress(Integer userId) {
UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(
DeletedStatusEnum.DELETED_NO.getValue(),
userId,
UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue());
return UserAddressConvert.INSTANCE.convert(defaultUserAddress);
}
}

View File

@ -0,0 +1,28 @@
package cn.iocoder.mall.system.rpc.api.user;
import cn.iocoder.mall.system.rpc.request.user.UserAddressAddRequest;
import cn.iocoder.mall.system.rpc.request.user.UserAddressUpdateRequest;
import cn.iocoder.mall.system.rpc.response.user.UserAddressResponse;
import java.util.List;
/**
* 用户地址 RPC
*
* author: sin
* time: 2020/5/1 10:26 上午
*/
public interface UserAddressRPC {
void addAddress(UserAddressAddRequest userAddressAddRequest);
void updateAddress(UserAddressUpdateRequest userAddressUpdateRequest);
void removeAddress(Integer userId, Integer addressId);
List<UserAddressResponse> addressList(Integer userId);
UserAddressResponse getAddress(Integer userId, Integer id);
UserAddressResponse getDefaultAddress(Integer userId);
}

View File

@ -0,0 +1,45 @@
package cn.iocoder.mall.system.rpc.request.user;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* 用户地址 add
*
* @author Sin
* @time 2019-04-06 13:25
*/
@Data
@Accessors(chain = true)
public class UserAddressAddRequest implements Serializable {
/**
* 收件区域编号
*/
private Integer userId;
/**
* 收件区域编号
*/
private String areaNo;
/**
* 收件人名称
*/
private String name;
/**
* 收件手机号
*/
private String mobile;
/**
* 收件详细地址
*/
private String address;
/**
* 是否默认
*
* - 1 不是
* - 2
*/
private Integer hasDefault;
}

View File

@ -0,0 +1,46 @@
package cn.iocoder.mall.system.rpc.request.user;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* 用户地址 更新
*
* @author Sin
* @time 2019-04-06 13:28
*/
@Data
@Accessors(chain = true)
public class UserAddressUpdateRequest implements Serializable {
/**
* 编号
*/
private Integer id;
/**
* 用户编号
*/
private Integer userId;
/**
* 收件区域编号
*/
private String areaNo;
/**
* 收件人名称
*/
private String name;
/**
* 收件手机号
*/
private String mobile;
/**
* 收件详细地址
*/
private String address;
/**
* 是否默认地址
*/
private Integer hasDefault;
}

View File

@ -0,0 +1,46 @@
package cn.iocoder.mall.system.rpc.response.user;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* 用户地址
*
* @author Sin
* @time 2019-04-06 13:28
*/
@Data
@Accessors(chain = true)
public class UserAddressResponse implements Serializable {
/**
* 编号
*/
private Integer id;
/**
* 用户编号
*/
private Integer userId;
/**
* 收件区域编号
*/
private String areaNo;
/**
* 收件人名称
*/
private String name;
/**
* 收件手机号
*/
private String mobile;
/**
* 收件详细地址
*/
private String address;
/**
* 是否默认
*/
private Integer hasDefault;
}

View File

@ -0,0 +1,41 @@
package cn.iocoder.mall.system.rpc.convert.user;
import cn.iocoder.mall.system.biz.bo.user.UserAddressBO;
import cn.iocoder.mall.system.biz.dataobject.user.UserAddressDO;
import cn.iocoder.mall.system.biz.dto.user.UserAddressAddDTO;
import cn.iocoder.mall.system.biz.dto.user.UserAddressUpdateDTO;
import cn.iocoder.mall.system.rpc.request.user.UserAddressAddRequest;
import cn.iocoder.mall.system.rpc.request.user.UserAddressUpdateRequest;
import cn.iocoder.mall.system.rpc.response.user.UserAddressResponse;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* user address convert
*
* author: sin
* time: 2020/5/1 10:30 上午
*/
@Mapper
public interface UserAddressRPCConvert {
UserAddressRPCConvert INSTANCE = Mappers.getMapper(UserAddressRPCConvert.class);
@Mappings({})
UserAddressAddDTO convert(UserAddressAddRequest userAddressAddRequest);
@Mappings({})
UserAddressUpdateDTO convert(UserAddressUpdateRequest userAddressUpdateRequest);
@Mappings({})
UserAddressResponse convert(UserAddressBO userAddressBO);
@Mappings({})
List<UserAddressResponse> convert(List<UserAddressBO> addressBOS);
}

View File

@ -0,0 +1,49 @@
package cn.iocoder.mall.system.rpc.rpc.user;
import cn.iocoder.mall.system.biz.service.user.UserAddressService;
import cn.iocoder.mall.system.rpc.api.user.UserAddressRPC;
import cn.iocoder.mall.system.rpc.convert.user.UserAddressRPCConvert;
import cn.iocoder.mall.system.rpc.request.user.UserAddressAddRequest;
import cn.iocoder.mall.system.rpc.request.user.UserAddressUpdateRequest;
import cn.iocoder.mall.system.rpc.response.user.UserAddressResponse;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
@Service(version = "${dubbo.provider.UserAddressRPC.version}", validation = "true")
public class UserAddressRPCImpl implements UserAddressRPC {
@Autowired
private UserAddressService userAddressService;
@Override
public void addAddress(UserAddressAddRequest userAddressAddRequest) {
userAddressService.addAddress(UserAddressRPCConvert.INSTANCE.convert(userAddressAddRequest));
}
@Override
public void updateAddress(UserAddressUpdateRequest userAddressUpdateRequest) {
userAddressService.updateAddress(UserAddressRPCConvert.INSTANCE.convert(userAddressUpdateRequest));
}
@Override
public void removeAddress(Integer userId, Integer addressId) {
userAddressService.removeAddress(userId, addressId);
}
@Override
public List<UserAddressResponse> addressList(Integer userId) {
return UserAddressRPCConvert.INSTANCE.convert(userAddressService.addressList(userId));
}
@Override
public UserAddressResponse getAddress(Integer userId, Integer id) {
return UserAddressRPCConvert.INSTANCE.convert(userAddressService.getAddress(userId, id));
}
@Override
public UserAddressResponse getDefaultAddress(Integer userId) {
return UserAddressRPCConvert.INSTANCE.convert(userAddressService.getDefaultAddress(userId));
}
}