清理 address 相关的代码

This commit is contained in:
YunaiV 2022-08-01 23:39:58 +08:00
parent 2c28e11631
commit 193110e456
13 changed files with 0 additions and 726 deletions

View File

@ -1,39 +0,0 @@
package cn.iocoder.mall.userservice.enums.address;
import cn.iocoder.common.framework.core.IntArrayValuable;
import java.util.Arrays;
/**
* 用户收件地址的类型枚举
*/
public enum UserAddressType implements IntArrayValuable {
DEFAULT(1, "默认收件地址"),
NORMAL(2, "普通收件地址"), // 即非默认收件笛之爱
;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(UserAddressType::getType).toArray();
private final Integer type;
private final String desc;
UserAddressType(Integer type, String desc) {
this.type = type;
this.desc = desc;
}
public Integer getType() {
return type;
}
public String getDesc() {
return desc;
}
@Override
public int[] array() {
return ARRAYS;
}
}

View File

@ -1,39 +0,0 @@
package cn.iocoder.mall.userservice.rpc.address;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressCreateReqDTO;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressRespDTO;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressUpdateReqDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
/**
* 用户收件地址 Rpc 接口
*/
@FeignClient("user-service")
public interface UserAddressFeign {
@PostMapping("/user/address/createUserAddress")
public CommonResult<Integer> createUserAddress(@RequestBody UserAddressCreateReqDTO createDTO);
@PostMapping("/user/address/updateUserAddress")
public CommonResult<Boolean> updateUserAddress(@RequestBody UserAddressUpdateReqDTO updateDTO);
@GetMapping("/user/address/deleteUserAddress")
public CommonResult<Boolean> deleteUserAddress(@RequestParam("userAddressId") Integer userAddressId);
@GetMapping("/user/address/getUserAddress")
public CommonResult<UserAddressRespDTO> getUserAddress(@RequestParam("userAddressId")Integer userAddressId) ;
@GetMapping("/user/address/listUserAddressesByIds")
public CommonResult<List<UserAddressRespDTO>> listUserAddresses(@RequestParam("userAddressIds")List<Integer> userAddressIds) ;
@GetMapping("/user/address/listUserAddresses")
public CommonResult<List<UserAddressRespDTO>> listUserAddresses(@RequestParam("userId")Integer userId, @RequestParam("type")Integer type);
}

View File

@ -1,48 +0,0 @@
package cn.iocoder.mall.userservice.rpc.address.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* 用户收件地址创建 Request DTO
*/
@Data
@Accessors(chain = true)
public class UserAddressCreateReqDTO implements Serializable {
/**
* 用户编号
*/
@NotNull(message = "用户编号不能为空")
private Integer userId;
/**
* 收件人名称
*/
@NotEmpty(message = "收件人名称不能为空")
private String name;
/**
* 手机号
*/
@NotEmpty(message = "手机号不能为空")
private String mobile;
/**
* 地区编码
*/
@NotNull(message = "地区编码不能为空")
private Integer areaCode;
/**
* 收件详细地址
*/
@NotEmpty(message = "收件详细地址不能为空")
private String detailAddress;
/**
* 地址类型
*/
@NotNull(message = "地址类型不能为空")
private Integer type;
}

View File

@ -1,49 +0,0 @@
package cn.iocoder.mall.userservice.rpc.address.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
* 用户收件地址 Response DTO
*/
@Data
@Accessors(chain = true)
public class UserAddressRespDTO implements Serializable {
/**
* 收件地址编号
*/
private Integer id;
/**
* 用户编号
*/
private Integer userId;
/**
* 收件人名称
*/
private String name;
/**
* 手机号
*/
private String mobile;
/**
* 地区编码
*/
private Integer areaCode;
/**
* 收件详细地址
*/
private String detailAddress;
/**
* 地址类型
*/
private Integer type;
/**
* 创建时间
*/
private Date createTime;
}

View File

@ -1,60 +0,0 @@
package cn.iocoder.mall.userservice.rpc.address.dto;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.common.framework.validator.Mobile;
import cn.iocoder.mall.userservice.enums.address.UserAddressType;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* 用户收件地址更新 Request DTO
*/
@Data
@Accessors(chain = true)
public class UserAddressUpdateReqDTO implements Serializable {
/**
* 收件地址编号
*/
@NotNull(message = "收件地址编号不能为空")
private Integer id;
/**
* 用户编号
*
* TODO 正在讨论
*/
@NotNull(message = "用户编号不能为空")
private Integer userId;
/**
* 收件人名称
*/
@NotEmpty(message = "收件人名称不能为空")
private String name;
/**
* 手机号
*/
@NotEmpty(message = "手机号不能为空")
@Mobile
private String mobile;
/**
* 地区编码
*/
@NotNull(message = "地区编码不能为空")
private Integer areaCode;
/**
* 收件详细地址
*/
@NotEmpty(message = "收件详细地址不能为空")
private String detailAddress;
/**
* 地址类型
*/
@NotNull(message = "地址类型不能为空")
@InEnum(value = UserAddressType.class, message = "地址类型必须是 {value}")
private Integer type;
}

View File

@ -1,54 +0,0 @@
package cn.iocoder.mall.userservice.controller;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.userservice.manager.address.UserAddressManager;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressCreateReqDTO;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressRespDTO;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressUpdateReqDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import static cn.iocoder.common.framework.vo.CommonResult.success;
@RestController
@RequestMapping("/user/address")
public class UserAddressController {
@Autowired
private UserAddressManager userAddressManager;
@PostMapping("createUserAddress")
public CommonResult<Integer> createUserAddress(@RequestBody UserAddressCreateReqDTO createDTO) {
return success(userAddressManager.createUserAddress(createDTO));
}
@PostMapping("updateUserAddress")
public CommonResult<Boolean> updateUserAddress(@RequestBody UserAddressUpdateReqDTO updateDTO) {
userAddressManager.updateUserAddress(updateDTO);
return success(true);
}
@GetMapping("deleteUserAddress")
public CommonResult<Boolean> deleteUserAddress(@RequestParam("userAddressId") Integer userAddressId) {
userAddressManager.deleteUserAddress(userAddressId);
return success(true);
}
@GetMapping("getUserAddress")
public CommonResult<UserAddressRespDTO> getUserAddress(@RequestParam("userAddressId")Integer userAddressId) {
return success(userAddressManager.getUserAddress(userAddressId));
}
@GetMapping("listUserAddressesByIds")
public CommonResult<List<UserAddressRespDTO>> listUserAddresses(@RequestParam("userAddressIds")List<Integer> userAddressIds) {
return success(userAddressManager.listUserAddresses(userAddressIds));
}
@GetMapping("listUserAddresses")
public CommonResult<List<UserAddressRespDTO>> listUserAddresses(@RequestParam("userId")Integer userId, @RequestParam("type")Integer type) {
return success(userAddressManager.listUserAddresses(userId, type));
}
}

View File

@ -1,55 +0,0 @@
package cn.iocoder.mall.userservice.dal.mysql.dataobject.address;
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
import cn.iocoder.mall.userservice.enums.address.UserAddressType;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* 用户收件地址
*
* idx_userId 索引基于 {@link #userId} 字段
*
* @author Sin
* @time 2019-04-06 13:22
*/
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
@TableName("user_address")
public class UserAddressDO extends DeletableDO {
/**
* 编号
*/
private Integer id;
/**
* 用户编号
*/
private Integer userId;
/**
* 收件人名称
*/
private String name;
/**
* 收件手机号
*/
private String mobile;
/**
* 地区编码
*/
private Integer areaCode;
/**
* 收件详细地址
*/
private String detailAddress;
/**
* 地址类型主要分为默认地址和普通地址
*
* 外键 {@link UserAddressType}
*/
private Integer type;
}

View File

@ -1,86 +0,0 @@
package cn.iocoder.mall.userservice.manager.address;
import cn.iocoder.mall.userservice.convert.address.UserAddressConvert;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressCreateReqDTO;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressRespDTO;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressUpdateReqDTO;
import cn.iocoder.mall.userservice.service.address.UserAddressService;
import cn.iocoder.mall.userservice.service.address.bo.UserAddressBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 用户收件地址 Manager
*/
@Service
public class UserAddressManager {
@Autowired
private UserAddressService userAddressService;
/**
* 创建用户收件地址
*
* @param createDTO 创建用户收件地址 DTO
* @return 用户收件地址
*/
public Integer createUserAddress(UserAddressCreateReqDTO createDTO) {
UserAddressBO userAddressBO = userAddressService.createUserAddress(UserAddressConvert.INSTANCE.convert(createDTO));
return userAddressBO.getId();
}
/**
* 更新用户收件地址
*
* @param updateDTO 更新用户收件地址 DTO
*/
public void updateUserAddress(UserAddressUpdateReqDTO updateDTO) {
userAddressService.updateUserAddress(UserAddressConvert.INSTANCE.convert(updateDTO));
}
/**
* 删除用户收件地址
*
* @param userAddressId 用户收件地址编号
*/
public void deleteUserAddress(Integer userAddressId) {
userAddressService.deleteUserAddress(userAddressId);
}
/**
* 获得用户收件地址
*
* @param userAddressId 用户收件地址编号
* @return 用户收件地址
*/
public UserAddressRespDTO getUserAddress(Integer userAddressId) {
UserAddressBO userAddressBO = userAddressService.getUserAddress(userAddressId);
return UserAddressConvert.INSTANCE.convert(userAddressBO);
}
/**
* 获得用户收件地址列表
*
* @param userAddressIds 用户收件地址编号列表
* @return 用户收件地址列表
*/
public List<UserAddressRespDTO> listUserAddresses(List<Integer> userAddressIds) {
List<UserAddressBO> userAddressBOs = userAddressService.listUserAddresses(userAddressIds);
return UserAddressConvert.INSTANCE.convertList02(userAddressBOs);
}
/**
* 获取指定用户的收件地址列表
*
* @param userId 用户编号
* @param type 地址类型
* @return 收件地址列表
*/
public List<UserAddressRespDTO> listUserAddresses(Integer userId, Integer type) {
List<UserAddressBO> userAddressBOs = userAddressService.listUserAddresses(userId, type);
return UserAddressConvert.INSTANCE.convertList02(userAddressBOs);
}
}

View File

@ -1,130 +0,0 @@
package cn.iocoder.mall.userservice.service.address;
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
import cn.iocoder.common.framework.util.CollectionUtils;
import cn.iocoder.mall.userservice.convert.address.UserAddressConvert;
import cn.iocoder.mall.userservice.dal.mysql.dataobject.address.UserAddressDO;
import cn.iocoder.mall.userservice.dal.mysql.mapper.address.UserAddressMapper;
import cn.iocoder.mall.userservice.enums.address.UserAddressType;
import cn.iocoder.mall.userservice.service.address.bo.UserAddressBO;
import cn.iocoder.mall.userservice.service.address.bo.UserAddressCreateBO;
import cn.iocoder.mall.userservice.service.address.bo.UserAddressUpdateBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
import java.util.List;
import static cn.iocoder.mall.userservice.enums.UserErrorCodeConstants.USER_ADDRESS_NOT_FOUND;
/**
* 用户收件地址 Service
*/
@Service
@Validated
public class UserAddressService {
@Autowired
private UserAddressMapper userAddressMapper;
/**
* 创建用户收件地址
*
* @param createBO 创建用户收件地址 BO
* @return 用户收件地址
*/
@Transactional
public UserAddressBO createUserAddress(@Valid UserAddressCreateBO createBO) {
// 如果添加的是默认收件地址则将原默认地址修改为非默认
if (UserAddressType.DEFAULT.getType().equals(createBO.getType())) {
List<UserAddressDO> addressDOs = userAddressMapper.selectListByUserIdAndType(
createBO.getUserId(), UserAddressType.DEFAULT.getType());
if (!CollectionUtils.isEmpty(addressDOs)) {
addressDOs.forEach(userAddressDO -> userAddressMapper.updateById(new UserAddressDO()
.setId(userAddressDO.getId()).setType(UserAddressType.DEFAULT.getType())));
}
}
// 插入到数据库
UserAddressDO userAddressDO = UserAddressConvert.INSTANCE.convert(createBO);
userAddressMapper.insert(userAddressDO);
// 返回
return UserAddressConvert.INSTANCE.convert(userAddressDO);
}
/**
* 更新用户收件地址
*
* @param updateBO 更新用户收件地址 BO
*/
@Transactional
public void updateUserAddress(@Valid UserAddressUpdateBO updateBO) {
// 校验更新的用户收件地址是否存在
if (userAddressMapper.selectById(updateBO.getId()) == null) {
throw ServiceExceptionUtil.exception(USER_ADDRESS_NOT_FOUND);
}
// 如果修改的是默认收件地址则将原默认地址修改为非默认
if (UserAddressType.DEFAULT.getType().equals(updateBO.getType())) {
List<UserAddressDO> addressDOs = userAddressMapper.selectListByUserIdAndType(
updateBO.getUserId(), UserAddressType.DEFAULT.getType());
if (!CollectionUtils.isEmpty(addressDOs)) {
addressDOs.stream().filter(userAddressDO -> userAddressDO.getId().equals(updateBO.getId())) // 过滤掉更新的收件地址
.forEach(userAddressDO -> userAddressMapper.updateById(new UserAddressDO()
.setId(userAddressDO.getId()).setType(UserAddressType.DEFAULT.getType())));
}
}
// 更新到数据库
UserAddressDO updateObject = UserAddressConvert.INSTANCE.convert(updateBO);
userAddressMapper.updateById(updateObject);
}
/**
* 删除用户收件地址
*
* @param userAddressId 用户收件地址编号
*/
public void deleteUserAddress(Integer userAddressId) {
// 校验删除的用户收件地址是否存在
if (userAddressMapper.selectById(userAddressId) == null) {
throw ServiceExceptionUtil.exception(USER_ADDRESS_NOT_FOUND);
}
// 标记删除
userAddressMapper.deleteById(userAddressId);
}
/**
* 获得用户收件地址
*
* @param userAddressId 用户收件地址编号
* @return 用户收件地址
*/
public UserAddressBO getUserAddress(Integer userAddressId) {
UserAddressDO userAddressDO = userAddressMapper.selectById(userAddressId);
return UserAddressConvert.INSTANCE.convert(userAddressDO);
}
/**
* 获得用户收件地址列表
*
* @param userAddressIds 用户收件地址编号列表
* @return 用户收件地址列表
*/
public List<UserAddressBO> listUserAddresses(List<Integer> userAddressIds) {
List<UserAddressDO> userAddressDOs = userAddressMapper.selectBatchIds(userAddressIds);
return UserAddressConvert.INSTANCE.convertList(userAddressDOs);
}
/**
* 获取指定用户的收件地址列表
*
* @param userId 用户编号
* @param type 地址类型
* @return 收件地址列表
*/
public List<UserAddressBO> listUserAddresses(Integer userId, Integer type) {
List<UserAddressDO> userAddressDOs = userAddressMapper.selectListByUserIdAndType(userId, type);
return UserAddressConvert.INSTANCE.convertList(userAddressDOs);
}
}

View File

@ -1,48 +0,0 @@
package cn.iocoder.mall.userservice.service.address.bo;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* 用户收件地址 BO
*/
@Data
@Accessors(chain = true)
public class UserAddressBO {
/**
* 收件地址编号
*/
private Integer id;
/**
* 用户编号
*/
private Integer userId;
/**
* 收件人名称
*/
private String name;
/**
* 手机号
*/
private String mobile;
/**
* 地区编码
*/
private Integer areaCode;
/**
* 收件详细地址
*/
private String detailAddress;
/**
* 地址类型
*/
private Integer type;
/**
* 创建时间
*/
private Date createTime;
}

View File

@ -1,49 +0,0 @@
package cn.iocoder.mall.userservice.service.address.bo;
import cn.iocoder.common.framework.validator.Mobile;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* 用户收件地址创建 BO
*/
@Data
@Accessors(chain = true)
public class UserAddressCreateBO {
/**
* 用户编号
*/
@NotNull(message = "用户编号不能为空")
private Integer userId;
/**
* 收件人名称
*/
@NotEmpty(message = "收件人名称不能为空")
private String name;
/**
* 手机号
*/
@NotEmpty(message = "手机号不能为空")
@Mobile
private String mobile;
/**
* 地区编码
*/
@NotNull(message = "地区编码不能为空")
private Integer areaCode;
/**
* 收件详细地址
*/
@NotEmpty(message = "收件详细地址不能为空")
private String detailAddress;
/**
* 地址类型
*/
@NotNull(message = "地址类型不能为空")
private Integer type;
}

View File

@ -1,52 +0,0 @@
package cn.iocoder.mall.userservice.service.address.bo;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* 用户收件地址更新 BO
*/
@Data
@Accessors(chain = true)
public class UserAddressUpdateBO {
/**
* 收件地址编号
*/
@NotNull(message = "收件地址编号不能为空")
private Integer id;
/**
* 用户编号
*/
@NotNull(message = "用户编号不能为空")
private Integer userId;
/**
* 收件人名称
*/
@NotEmpty(message = "收件人名称不能为空")
private String name;
/**
* 手机号
*/
@NotEmpty(message = "手机号不能为空")
private String mobile;
/**
* 地区编码
*/
@NotNull(message = "地区编码不能为空")
private Integer areaCode;
/**
* 收件详细地址
*/
@NotEmpty(message = "收件详细地址不能为空")
private String detailAddress;
/**
* 地址类型
*/
@NotNull(message = "地址类型不能为空")
private Integer type;
}

View File

@ -38,20 +38,3 @@ CREATE TABLE `user_sms_code` (
KEY `idx_mobile` (`mobile`) USING BTREE COMMENT '手机号' KEY `idx_mobile` (`mobile`) USING BTREE COMMENT '手机号'
) ENGINE=InnoDB AUTO_INCREMENT=445 DEFAULT CHARSET=utf8mb4 COMMENT='手机验证码'; ) ENGINE=InnoDB AUTO_INCREMENT=445 DEFAULT CHARSET=utf8mb4 COMMENT='手机验证码';
-- ----------------------------
-- Table structure for user_sms_code
-- ----------------------------
CREATE TABLE `user_address` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '收件地址编号',
`user_id` int(11) NOT NULL COMMENT '用户编号',
`name` varchar(10) COLLATE utf8mb4_bin NOT NULL COMMENT '收件人名称',
`mobile` varchar(20) COLLATE utf8mb4_bin NOT NULL COMMENT '手机号',
`area_code` int(11) NOT NULL COMMENT '地区编码',
`detail_address` varchar(250) COLLATE utf8mb4_bin NOT NULL COMMENT '收件详细地址',
`type` tinyint(4) NOT NULL COMMENT '地址类型',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '删除状态',
PRIMARY KEY (`id`) USING BTREE,
KEY `idx_userId` (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='用户收件地址';