清理 address 相关的代码

pull/10/head
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 '手机号'
) 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='用户收件地址';