Commit 8dd83f4a1c072ebcd378ac6cabeb44ba0b8b6e8a
Committed by
Gitee
!125 [feature/1.8.0-uniapp][用户收件地址] 表结构,接口开发
Merge pull request !125 from 臭小子/feature/1.8.0-uniapp
Showing
21 changed files
with
935 additions
and
2 deletions
sql/ruoyi-vue-pro.sql
| ... | ... | @@ -1924,6 +1924,28 @@ INSERT INTO `member_user` VALUES (246, '', '', 0, '15601691301', '$2a$10$KLvmwoU |
| 1924 | 1924 | COMMIT; |
| 1925 | 1925 | |
| 1926 | 1926 | -- ---------------------------- |
| 1927 | +-- Table structure for member_address | |
| 1928 | +-- ---------------------------- | |
| 1929 | +DROP TABLE IF EXISTS `member_address`; | |
| 1930 | +CREATE TABLE `member_address` ( | |
| 1931 | + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '收件地址编号', | |
| 1932 | + `user_id` bigint NOT NULL COMMENT '用户编号', | |
| 1933 | + `name` varchar(10) COLLATE utf8mb4_bin NOT NULL COMMENT '收件人名称', | |
| 1934 | + `mobile` varchar(20) COLLATE utf8mb4_bin NOT NULL COMMENT '手机号', | |
| 1935 | + `area_code` int(11) NOT NULL COMMENT '地区编码', | |
| 1936 | + `detail_address` varchar(250) COLLATE utf8mb4_bin NOT NULL COMMENT '收件详细地址', | |
| 1937 | + `type` tinyint(4) NOT NULL COMMENT '地址类型', | |
| 1938 | + `creator` varchar(64) DEFAULT '' COMMENT '创建者', | |
| 1939 | + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', | |
| 1940 | + `updater` varchar(64) DEFAULT '' COMMENT '更新者', | |
| 1941 | + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', | |
| 1942 | + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '删除状态', | |
| 1943 | + `tenant_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '租户编号', | |
| 1944 | + PRIMARY KEY (`id`) USING BTREE, | |
| 1945 | + KEY `idx_userId` (`user_id`) | |
| 1946 | +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='用户收件地址'; | |
| 1947 | + | |
| 1948 | +-- ---------------------------- | |
| 1927 | 1949 | -- Table structure for pay_app |
| 1928 | 1950 | -- ---------------------------- |
| 1929 | 1951 | DROP TABLE IF EXISTS `pay_app`; | ... | ... |
yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java
| ... | ... | @@ -21,4 +21,8 @@ public interface ErrorCodeConstants { |
| 21 | 21 | ErrorCode AUTH_TOKEN_EXPIRED = new ErrorCode(1004003004, "Token 已经过期"); |
| 22 | 22 | ErrorCode AUTH_THIRD_LOGIN_NOT_BIND = new ErrorCode(1004003005, "未绑定账号,需要进行绑定"); |
| 23 | 23 | |
| 24 | + // ========== 用户收件地址 1004004000 ========== | |
| 25 | + ErrorCode ADDRESS_NOT_EXISTS = new ErrorCode(1004004000, "用户收件地址不存在"); | |
| 26 | + ErrorCode ADDRESS_FORBIDDEN = new ErrorCode(1004004001, "没有该操作权限"); | |
| 27 | + | |
| 24 | 28 | } | ... | ... |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/AppAddressController.http
0 → 100644
| 1 | +### 请求 /create 接口 => 成功 | |
| 2 | +POST {{appApi}}//member/address/create | |
| 3 | +Content-Type: application/json | |
| 4 | +tenant-id: {{appTenentId}} | |
| 5 | +Authorization: Bearer 2510e2e4287346eb8e36353a55e27fd6 | |
| 6 | + | |
| 7 | +{ | |
| 8 | + "userId": "245", | |
| 9 | + "name": "yunai", | |
| 10 | + "mobile": "15601691300", | |
| 11 | + "areaCode": "610632", | |
| 12 | + "detailAddress": "芋道源码 233 号 666 室", | |
| 13 | + "type": "1" | |
| 14 | +} | |
| 15 | + | |
| 16 | +### 请求 /update 接口 => 成功 | |
| 17 | +PUT {{appApi}}//member/address/update | |
| 18 | +Content-Type: application/json | |
| 19 | +tenant-id: {{appTenentId}} | |
| 20 | +Authorization: Bearer 2510e2e4287346eb8e36353a55e27fd6 | |
| 21 | + | |
| 22 | +{ | |
| 23 | + "id": "1", | |
| 24 | + "userId": "245", | |
| 25 | + "name": "yunai888", | |
| 26 | + "mobile": "15601691300", | |
| 27 | + "areaCode": "610632", | |
| 28 | + "detailAddress": "芋道源码 233 号 666 室", | |
| 29 | + "type": "1" | |
| 30 | +} | |
| 31 | + | |
| 32 | +### 请求 /delete 接口 => 成功 | |
| 33 | +DELETE {{appApi}}//member/address/delete?id=2 | |
| 34 | +Content-Type: application/json | |
| 35 | +tenant-id: {{appTenentId}} | |
| 36 | +Authorization: Bearer fa4848b001de4eae9faf516c0c8520f8 | |
| 37 | + | |
| 38 | +### 请求 /get 接口 => 成功 | |
| 39 | +GET {{appApi}}//member/address/get?id=1 | |
| 40 | +Content-Type: application/json | |
| 41 | +tenant-id: {{appTenentId}} | |
| 42 | +Authorization: Bearer fa4848b001de4eae9faf516c0c8520f8 | |
| 43 | + | |
| 44 | +### 请求 /get-default 接口 => 成功 | |
| 45 | +GET {{appApi}}//member/address/get-default | |
| 46 | +Content-Type: application/json | |
| 47 | +tenant-id: {{appTenentId}} | |
| 48 | +Authorization: Bearer fa4848b001de4eae9faf516c0c8520f8 | |
| 49 | + | |
| 50 | +### 请求 /list 接口 => 成功 | |
| 51 | +GET {{appApi}}//member/address/list | |
| 52 | +Content-Type: application/json | |
| 53 | +tenant-id: {{appTenentId}} | |
| 54 | +Authorization: Bearer fa4848b001de4eae9faf516c0c8520f8 | |
| 0 | 55 | \ No newline at end of file | ... | ... |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/AppAddressController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.controller.app.address; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 5 | +import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressCreateReqVO; | |
| 6 | +import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressPageReqVO; | |
| 7 | +import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressRespVO; | |
| 8 | +import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressUpdateReqVO; | |
| 9 | +import cn.iocoder.yudao.module.member.convert.address.AddressConvert; | |
| 10 | +import cn.iocoder.yudao.module.member.dal.dataobject.address.AddressDO; | |
| 11 | +import cn.iocoder.yudao.module.member.service.address.AddressService; | |
| 12 | +import io.swagger.annotations.Api; | |
| 13 | +import io.swagger.annotations.ApiImplicitParam; | |
| 14 | +import io.swagger.annotations.ApiOperation; | |
| 15 | +import org.springframework.validation.annotation.Validated; | |
| 16 | +import org.springframework.web.bind.annotation.*; | |
| 17 | + | |
| 18 | +import javax.annotation.Resource; | |
| 19 | +import javax.validation.Valid; | |
| 20 | +import java.util.Collection; | |
| 21 | +import java.util.List; | |
| 22 | + | |
| 23 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 24 | +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | |
| 25 | + | |
| 26 | +@Api(tags = "用户 APP - 用户收件地址") | |
| 27 | +@RestController | |
| 28 | +@RequestMapping("/member/address") | |
| 29 | +@Validated | |
| 30 | +public class AppAddressController { | |
| 31 | + | |
| 32 | + @Resource | |
| 33 | + private AddressService addressService; | |
| 34 | + | |
| 35 | + @PostMapping("/create") | |
| 36 | + @ApiOperation("创建用户收件地址") | |
| 37 | + | |
| 38 | + public CommonResult<Long> createAddress(@Valid @RequestBody AppAddressCreateReqVO createReqVO) { | |
| 39 | + return success(addressService.createAddress(getLoginUserId(), createReqVO)); | |
| 40 | + } | |
| 41 | + | |
| 42 | + @PutMapping("/update") | |
| 43 | + @ApiOperation("更新用户收件地址") | |
| 44 | + | |
| 45 | + public CommonResult<Boolean> updateAddress(@Valid @RequestBody AppAddressUpdateReqVO updateReqVO) { | |
| 46 | + addressService.updateAddress(getLoginUserId(), updateReqVO); | |
| 47 | + return success(true); | |
| 48 | + } | |
| 49 | + | |
| 50 | + @DeleteMapping("/delete") | |
| 51 | + @ApiOperation("删除用户收件地址") | |
| 52 | + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) | |
| 53 | + | |
| 54 | + public CommonResult<Boolean> deleteAddress(@RequestParam("id") Long id) { | |
| 55 | + addressService.deleteAddress(getLoginUserId(), id); | |
| 56 | + return success(true); | |
| 57 | + } | |
| 58 | + | |
| 59 | + @GetMapping("/get") | |
| 60 | + @ApiOperation("获得用户收件地址") | |
| 61 | + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) | |
| 62 | + | |
| 63 | + public CommonResult<AppAddressRespVO> getAddress(@RequestParam("id") Long id) { | |
| 64 | + AddressDO address = addressService.getAddress(getLoginUserId(), id); | |
| 65 | + return success(AddressConvert.INSTANCE.convert(address)); | |
| 66 | + } | |
| 67 | + | |
| 68 | + @GetMapping("/get-default") | |
| 69 | + @ApiOperation("获得默认的用户收件地址") | |
| 70 | + | |
| 71 | + public CommonResult<AppAddressRespVO> getDefaultUserAddress() { | |
| 72 | + AddressDO address = addressService.getDefaultUserAddress(getLoginUserId()); | |
| 73 | + return success(AddressConvert.INSTANCE.convert(address)); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @GetMapping("/list") | |
| 77 | + @ApiOperation("获得用户收件地址列表") | |
| 78 | + | |
| 79 | + public CommonResult<List<AppAddressRespVO>> getAddressList() { | |
| 80 | + List<AddressDO> list = addressService.getAddressList(getLoginUserId()); | |
| 81 | + return success(AddressConvert.INSTANCE.convertList(list)); | |
| 82 | + } | |
| 83 | + | |
| 84 | +} | ... | ... |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/package-info.java deleted
| 1 | -package cn.iocoder.yudao.module.member.controller.app.address; |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressBaseVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.controller.app.address.vo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import io.swagger.annotations.*; | |
| 6 | +import javax.validation.constraints.*; | |
| 7 | + | |
| 8 | +/** | |
| 9 | +* 用户收件地址 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 10 | +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 11 | +*/ | |
| 12 | +@Data | |
| 13 | +public class AppAddressBaseVO { | |
| 14 | + | |
| 15 | + @ApiModelProperty(value = "收件人名称", required = true) | |
| 16 | + @NotNull(message = "收件人名称不能为空") | |
| 17 | + private String name; | |
| 18 | + | |
| 19 | + @ApiModelProperty(value = "手机号", required = true) | |
| 20 | + @NotNull(message = "手机号不能为空") | |
| 21 | + private String mobile; | |
| 22 | + | |
| 23 | + @ApiModelProperty(value = "地区编码", required = true) | |
| 24 | + @NotNull(message = "地区编码不能为空") | |
| 25 | + private Integer areaCode; | |
| 26 | + | |
| 27 | + @ApiModelProperty(value = "收件详细地址", required = true) | |
| 28 | + @NotNull(message = "收件详细地址不能为空") | |
| 29 | + private String detailAddress; | |
| 30 | + | |
| 31 | + @ApiModelProperty(value = "地址类型", required = true) | |
| 32 | + @NotNull(message = "地址类型不能为空") | |
| 33 | + private Integer type; | |
| 34 | + | |
| 35 | +} | ... | ... |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressCreateReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.controller.app.address.vo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import io.swagger.annotations.*; | |
| 6 | +import javax.validation.constraints.*; | |
| 7 | + | |
| 8 | +@ApiModel("用户 APP - 用户收件地址创建 Request VO") | |
| 9 | +@Data | |
| 10 | +@EqualsAndHashCode(callSuper = true) | |
| 11 | +@ToString(callSuper = true) | |
| 12 | +public class AppAddressCreateReqVO extends AppAddressBaseVO { | |
| 13 | + | |
| 14 | +} | ... | ... |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressExportReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.controller.app.address.vo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import io.swagger.annotations.*; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | + | |
| 9 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 10 | + | |
| 11 | +@ApiModel(value = "用户 APP - 用户收件地址 Excel 导出 Request VO", description = "参数和 AddressPageReqVO 是一致的") | |
| 12 | +@Data | |
| 13 | +public class AppAddressExportReqVO { | |
| 14 | + | |
| 15 | + @ApiModelProperty(value = "用户编号") | |
| 16 | + private Long userId; | |
| 17 | + | |
| 18 | + @ApiModelProperty(value = "收件人名称") | |
| 19 | + private String name; | |
| 20 | + | |
| 21 | + @ApiModelProperty(value = "手机号") | |
| 22 | + private String mobile; | |
| 23 | + | |
| 24 | + @ApiModelProperty(value = "地区编码") | |
| 25 | + private Integer areaCode; | |
| 26 | + | |
| 27 | + @ApiModelProperty(value = "收件详细地址") | |
| 28 | + private String detailAddress; | |
| 29 | + | |
| 30 | + @ApiModelProperty(value = "地址类型") | |
| 31 | + private Integer type; | |
| 32 | + | |
| 33 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 34 | + @ApiModelProperty(value = "开始创建时间") | |
| 35 | + private Date beginCreateTime; | |
| 36 | + | |
| 37 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 38 | + @ApiModelProperty(value = "结束创建时间") | |
| 39 | + private Date endCreateTime; | |
| 40 | + | |
| 41 | +} | ... | ... |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.controller.app.address.vo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import io.swagger.annotations.*; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | + | |
| 9 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 10 | + | |
| 11 | +@ApiModel("用户 APP - 用户收件地址分页 Request VO") | |
| 12 | +@Data | |
| 13 | +@EqualsAndHashCode(callSuper = true) | |
| 14 | +@ToString(callSuper = true) | |
| 15 | +public class AppAddressPageReqVO extends PageParam { | |
| 16 | + | |
| 17 | + @ApiModelProperty(value = "用户编号") | |
| 18 | + private Long userId; | |
| 19 | + | |
| 20 | + @ApiModelProperty(value = "收件人名称") | |
| 21 | + private String name; | |
| 22 | + | |
| 23 | + @ApiModelProperty(value = "手机号") | |
| 24 | + private String mobile; | |
| 25 | + | |
| 26 | + @ApiModelProperty(value = "地区编码") | |
| 27 | + private Integer areaCode; | |
| 28 | + | |
| 29 | + @ApiModelProperty(value = "收件详细地址") | |
| 30 | + private String detailAddress; | |
| 31 | + | |
| 32 | + @ApiModelProperty(value = "地址类型") | |
| 33 | + private Integer type; | |
| 34 | + | |
| 35 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 36 | + @ApiModelProperty(value = "开始创建时间") | |
| 37 | + private Date beginCreateTime; | |
| 38 | + | |
| 39 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 40 | + @ApiModelProperty(value = "结束创建时间") | |
| 41 | + private Date endCreateTime; | |
| 42 | + | |
| 43 | +} | ... | ... |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.controller.app.address.vo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import io.swagger.annotations.*; | |
| 6 | + | |
| 7 | +@ApiModel("用户 APP - 用户收件地址 Response VO") | |
| 8 | +@Data | |
| 9 | +@EqualsAndHashCode(callSuper = true) | |
| 10 | +@ToString(callSuper = true) | |
| 11 | +public class AppAddressRespVO extends AppAddressBaseVO { | |
| 12 | + | |
| 13 | + @ApiModelProperty(value = "编号", required = true) | |
| 14 | + private Long id; | |
| 15 | + | |
| 16 | + @ApiModelProperty(value = "创建时间", required = true) | |
| 17 | + private Date createTime; | |
| 18 | + | |
| 19 | +} | ... | ... |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressUpdateReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.controller.app.address.vo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import io.swagger.annotations.*; | |
| 6 | +import javax.validation.constraints.*; | |
| 7 | + | |
| 8 | +@ApiModel("用户 APP - 用户收件地址更新 Request VO") | |
| 9 | +@Data | |
| 10 | +@EqualsAndHashCode(callSuper = true) | |
| 11 | +@ToString(callSuper = true) | |
| 12 | +public class AppAddressUpdateReqVO extends AppAddressBaseVO { | |
| 13 | + | |
| 14 | + @ApiModelProperty(value = "编号", required = true) | |
| 15 | + @NotNull(message = "编号不能为空") | |
| 16 | + private Long id; | |
| 17 | + | |
| 18 | +} | ... | ... |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/convert/address/AddressConvert.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.convert.address; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | + | |
| 7 | +import org.mapstruct.Mapper; | |
| 8 | +import org.mapstruct.factory.Mappers; | |
| 9 | +import cn.iocoder.yudao.module.member.controller.app.address.vo.*; | |
| 10 | +import cn.iocoder.yudao.module.member.dal.dataobject.address.AddressDO; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 用户收件地址 Convert | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface AddressConvert { | |
| 19 | + | |
| 20 | + AddressConvert INSTANCE = Mappers.getMapper(AddressConvert.class); | |
| 21 | + | |
| 22 | + AddressDO convert(AppAddressCreateReqVO bean); | |
| 23 | + | |
| 24 | + AddressDO convert(AppAddressUpdateReqVO bean); | |
| 25 | + | |
| 26 | + AppAddressRespVO convert(AddressDO bean); | |
| 27 | + | |
| 28 | + List<AppAddressRespVO> convertList(List<AddressDO> list); | |
| 29 | + | |
| 30 | + PageResult<AppAddressRespVO> convertPage(PageResult<AddressDO> page); | |
| 31 | + | |
| 32 | +} | ... | ... |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/address/AddressDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.dal.dataobject.address; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 4 | +import cn.iocoder.yudao.module.member.enums.AddressTypeEnum; | |
| 5 | +import com.baomidou.mybatisplus.annotation.TableId; | |
| 6 | +import com.baomidou.mybatisplus.annotation.TableName; | |
| 7 | +import lombok.*; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 用户收件地址 DO | |
| 11 | + * | |
| 12 | + * @author 芋道源码 | |
| 13 | + */ | |
| 14 | +@TableName("member_address") | |
| 15 | +@Data | |
| 16 | +@EqualsAndHashCode(callSuper = true) | |
| 17 | +@ToString(callSuper = true) | |
| 18 | +@Builder | |
| 19 | +@NoArgsConstructor | |
| 20 | +@AllArgsConstructor | |
| 21 | +public class AddressDO extends BaseDO { | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * 编号 | |
| 25 | + */ | |
| 26 | + @TableId | |
| 27 | + private Long id; | |
| 28 | + /** | |
| 29 | + * 用户编号 | |
| 30 | + */ | |
| 31 | + private Long userId; | |
| 32 | + /** | |
| 33 | + * 收件人名称 | |
| 34 | + */ | |
| 35 | + private String name; | |
| 36 | + /** | |
| 37 | + * 手机号 | |
| 38 | + */ | |
| 39 | + private String mobile; | |
| 40 | + /** | |
| 41 | + * 地区编码 | |
| 42 | + */ | |
| 43 | + private Integer areaCode; | |
| 44 | + /** | |
| 45 | + * 收件详细地址 | |
| 46 | + */ | |
| 47 | + private String detailAddress; | |
| 48 | + /** | |
| 49 | + * 地址类型,主要分为默认地址,和普通地址 | |
| 50 | + * | |
| 51 | + * 外键 {@link AddressTypeEnum} | |
| 52 | + */ | |
| 53 | + private Integer type; | |
| 54 | + | |
| 55 | +} | ... | ... |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/address/package-info.java deleted
| 1 | -package cn.iocoder.yudao.module.member.dal.dataobject.address; |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.dal.mysql.address; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 8 | +import cn.iocoder.yudao.module.member.dal.dataobject.address.AddressDO; | |
| 9 | +import org.apache.ibatis.annotations.Mapper; | |
| 10 | +import cn.iocoder.yudao.module.member.controller.app.address.vo.*; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 用户收件地址 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface AddressMapper extends BaseMapperX<AddressDO> { | |
| 19 | + | |
| 20 | + default PageResult<AddressDO> selectPage(AppAddressPageReqVO reqVO) { | |
| 21 | + return selectPage(reqVO, new LambdaQueryWrapperX<AddressDO>() | |
| 22 | + .eqIfPresent(AddressDO::getUserId, reqVO.getUserId()) | |
| 23 | + .likeIfPresent(AddressDO::getName, reqVO.getName()) | |
| 24 | + .eqIfPresent(AddressDO::getMobile, reqVO.getMobile()) | |
| 25 | + .eqIfPresent(AddressDO::getAreaCode, reqVO.getAreaCode()) | |
| 26 | + .eqIfPresent(AddressDO::getDetailAddress, reqVO.getDetailAddress()) | |
| 27 | + .eqIfPresent(AddressDO::getType, reqVO.getType()) | |
| 28 | + .betweenIfPresent(AddressDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) | |
| 29 | + .orderByDesc(AddressDO::getId)); | |
| 30 | + } | |
| 31 | + | |
| 32 | + default List<AddressDO> selectList(AppAddressExportReqVO reqVO) { | |
| 33 | + return selectList(new LambdaQueryWrapperX<AddressDO>() | |
| 34 | + .eqIfPresent(AddressDO::getUserId, reqVO.getUserId()) | |
| 35 | + .likeIfPresent(AddressDO::getName, reqVO.getName()) | |
| 36 | + .eqIfPresent(AddressDO::getMobile, reqVO.getMobile()) | |
| 37 | + .eqIfPresent(AddressDO::getAreaCode, reqVO.getAreaCode()) | |
| 38 | + .eqIfPresent(AddressDO::getDetailAddress, reqVO.getDetailAddress()) | |
| 39 | + .eqIfPresent(AddressDO::getType, reqVO.getType()) | |
| 40 | + .betweenIfPresent(AddressDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) | |
| 41 | + .orderByDesc(AddressDO::getId)); | |
| 42 | + } | |
| 43 | + | |
| 44 | +} | ... | ... |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/enums/AddressTypeEnum.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.enums; | |
| 2 | + | |
| 3 | +import lombok.AllArgsConstructor; | |
| 4 | +import lombok.Getter; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * 用户收件地址的类型枚举 | |
| 8 | + */ | |
| 9 | +@Getter | |
| 10 | +@AllArgsConstructor | |
| 11 | +public enum AddressTypeEnum { | |
| 12 | + | |
| 13 | + DEFAULT(1, "默认收件地址"), | |
| 14 | + NORMAL(2, "普通收件地址"), // 即非默认收件笛之爱 | |
| 15 | + | |
| 16 | + ; | |
| 17 | + | |
| 18 | + private final Integer type; | |
| 19 | + private final String desc; | |
| 20 | + | |
| 21 | +} | |
| 0 | 22 | \ No newline at end of file | ... | ... |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.service.address; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | +import javax.validation.*; | |
| 5 | +import cn.iocoder.yudao.module.member.controller.app.address.vo.*; | |
| 6 | +import cn.iocoder.yudao.module.member.dal.dataobject.address.AddressDO; | |
| 7 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 用户收件地址 Service 接口 | |
| 11 | + * | |
| 12 | + * @author 芋道源码 | |
| 13 | + */ | |
| 14 | +public interface AddressService { | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * 创建用户收件地址 | |
| 18 | + * | |
| 19 | + * | |
| 20 | + * @param userId 用户编号 | |
| 21 | + * @param createReqVO 创建信息 | |
| 22 | + * @return 编号 | |
| 23 | + */ | |
| 24 | + Long createAddress(Long userId, @Valid AppAddressCreateReqVO createReqVO); | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * 更新用户收件地址 | |
| 28 | + * | |
| 29 | + * @param userId 用户编号 | |
| 30 | + * @param updateReqVO 更新信息 | |
| 31 | + */ | |
| 32 | + void updateAddress(Long userId, @Valid AppAddressUpdateReqVO updateReqVO); | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * 删除用户收件地址 | |
| 36 | + * | |
| 37 | + * @param userId 用户编号 | |
| 38 | + * @param id 编号 | |
| 39 | + */ | |
| 40 | + void deleteAddress(Long userId, Long id); | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * 获得用户收件地址 | |
| 44 | + * | |
| 45 | + * @param id 编号 | |
| 46 | + * @return 用户收件地址 | |
| 47 | + */ | |
| 48 | + AddressDO getAddress(Long id); | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * 获得用户收件地址列表 | |
| 52 | + * | |
| 53 | + * @param userId 用户编号 | |
| 54 | + * @return 用户收件地址列表 | |
| 55 | + */ | |
| 56 | + List<AddressDO> getAddressList(Long userId); | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * 获得用户收件地址分页 | |
| 60 | + * | |
| 61 | + * @param pageReqVO 分页查询 | |
| 62 | + * @return 用户收件地址分页 | |
| 63 | + */ | |
| 64 | + PageResult<AddressDO> getAddressPage(AppAddressPageReqVO pageReqVO); | |
| 65 | + | |
| 66 | + /** | |
| 67 | + * 获得用户收件地址列表, 用于 Excel 导出 | |
| 68 | + * | |
| 69 | + * @param exportReqVO 查询条件 | |
| 70 | + * @return 用户收件地址列表 | |
| 71 | + */ | |
| 72 | + List<AddressDO> getAddressList(AppAddressExportReqVO exportReqVO); | |
| 73 | + | |
| 74 | + /** | |
| 75 | + * 获得用户收件地址 | |
| 76 | + * | |
| 77 | + * @param userId 用户编号 | |
| 78 | + * @param id 编号 | |
| 79 | + * @return 用户收件地址 | |
| 80 | + */ | |
| 81 | + AddressDO getAddress(Long userId, Long id); | |
| 82 | + | |
| 83 | + AddressDO getDefaultUserAddress(Long userId); | |
| 84 | +} | ... | ... |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.service.address; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; | |
| 4 | +import cn.iocoder.yudao.module.member.enums.AddressTypeEnum; | |
| 5 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
| 6 | +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; | |
| 7 | +import org.checkerframework.checker.nullness.Opt; | |
| 8 | +import org.springframework.stereotype.Service; | |
| 9 | + | |
| 10 | +import javax.annotation.Nullable; | |
| 11 | +import javax.annotation.Resource; | |
| 12 | +import org.springframework.validation.annotation.Validated; | |
| 13 | + | |
| 14 | +import java.util.*; | |
| 15 | +import cn.iocoder.yudao.module.member.controller.app.address.vo.*; | |
| 16 | +import cn.iocoder.yudao.module.member.dal.dataobject.address.AddressDO; | |
| 17 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 18 | + | |
| 19 | +import cn.iocoder.yudao.module.member.convert.address.AddressConvert; | |
| 20 | +import cn.iocoder.yudao.module.member.dal.mysql.address.AddressMapper; | |
| 21 | + | |
| 22 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 23 | +import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*; | |
| 24 | + | |
| 25 | +/** | |
| 26 | + * 用户收件地址 Service 实现类 | |
| 27 | + * | |
| 28 | + * @author 芋道源码 | |
| 29 | + */ | |
| 30 | +@Service | |
| 31 | +@Validated | |
| 32 | +public class AddressServiceImpl implements AddressService { | |
| 33 | + | |
| 34 | + @Resource | |
| 35 | + private AddressMapper addressMapper; | |
| 36 | + | |
| 37 | + @Override | |
| 38 | + public Long createAddress(Long userId, AppAddressCreateReqVO createReqVO) { | |
| 39 | + // 如果添加的是默认收件地址,则将原默认地址修改为非默认 | |
| 40 | + if (AddressTypeEnum.DEFAULT.getType().equals(createReqVO.getType())) { | |
| 41 | + List<AddressDO> addressDOs = selectListByUserIdAndType(userId, AddressTypeEnum.DEFAULT.getType()); | |
| 42 | + if (!CollectionUtils.isEmpty(addressDOs)) { | |
| 43 | + addressDOs.forEach(userAddressDO -> addressMapper.updateById(new AddressDO() | |
| 44 | + .setId(userAddressDO.getId()).setType(AddressTypeEnum.NORMAL.getType()))); | |
| 45 | + } | |
| 46 | + } | |
| 47 | + // 插入 | |
| 48 | + AddressDO address = AddressConvert.INSTANCE.convert(createReqVO); | |
| 49 | + address.setUserId(userId); | |
| 50 | + addressMapper.insert(address); | |
| 51 | + // 返回 | |
| 52 | + return address.getId(); | |
| 53 | + } | |
| 54 | + | |
| 55 | + @Override | |
| 56 | + public void updateAddress(Long userId, AppAddressUpdateReqVO updateReqVO) { | |
| 57 | + // 校验存在,校验是否能够操作 | |
| 58 | + check(userId, updateReqVO.getId()); | |
| 59 | + // 如果修改的是默认收件地址,则将原默认地址修改为非默认 | |
| 60 | + if (AddressTypeEnum.DEFAULT.getType().equals(updateReqVO.getType())) { | |
| 61 | + List<AddressDO> addressDOs = selectListByUserIdAndType( | |
| 62 | + userId, AddressTypeEnum.DEFAULT.getType()); | |
| 63 | + if (!CollectionUtils.isEmpty(addressDOs)) { | |
| 64 | + addressDOs.stream().filter(userAddressDO -> !userAddressDO.getId().equals(updateReqVO.getId())) // 过滤掉更新的收件地址 | |
| 65 | + .forEach(userAddressDO -> addressMapper.updateById(new AddressDO() | |
| 66 | + .setId(userAddressDO.getId()).setType(AddressTypeEnum.NORMAL.getType()))); | |
| 67 | + } | |
| 68 | + } | |
| 69 | + // 更新 | |
| 70 | + AddressDO updateObj = AddressConvert.INSTANCE.convert(updateReqVO); | |
| 71 | + updateObj.setUserId(userId); | |
| 72 | + addressMapper.updateById(updateObj); | |
| 73 | + } | |
| 74 | + | |
| 75 | + @Override | |
| 76 | + public void deleteAddress(Long userId, Long id) { | |
| 77 | + // 校验存在,校验是否能够操作 | |
| 78 | + check(userId, id); | |
| 79 | + // 删除 | |
| 80 | + addressMapper.deleteById(id); | |
| 81 | + } | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * 校验用户收件地址是不是属于该用户 | |
| 85 | + * | |
| 86 | + * @param userId 用户编号 | |
| 87 | + * @param userAddressId 用户收件地址 | |
| 88 | + */ | |
| 89 | + private void check(Long userId, Long userAddressId) { | |
| 90 | + AddressDO addressDO = getAddress(userAddressId); | |
| 91 | + if(null == addressDO){ | |
| 92 | + throw exception(ADDRESS_NOT_EXISTS); | |
| 93 | + } | |
| 94 | + if (!addressDO.getUserId().equals(userId)) { | |
| 95 | + throw exception(ADDRESS_FORBIDDEN); | |
| 96 | + } | |
| 97 | + } | |
| 98 | + | |
| 99 | + @Override | |
| 100 | + public AddressDO getAddress(Long id) { | |
| 101 | + return addressMapper.selectById(id); | |
| 102 | + } | |
| 103 | + | |
| 104 | + @Override | |
| 105 | + public List<AddressDO> getAddressList(Long userId) { | |
| 106 | + return selectListByUserIdAndType(userId, null); | |
| 107 | + } | |
| 108 | + | |
| 109 | + @Override | |
| 110 | + public PageResult<AddressDO> getAddressPage(AppAddressPageReqVO pageReqVO) { | |
| 111 | + return addressMapper.selectPage(pageReqVO); | |
| 112 | + } | |
| 113 | + | |
| 114 | + @Override | |
| 115 | + public List<AddressDO> getAddressList(AppAddressExportReqVO exportReqVO) { | |
| 116 | + return addressMapper.selectList(exportReqVO); | |
| 117 | + } | |
| 118 | + | |
| 119 | + @Override | |
| 120 | + public AddressDO getAddress(Long userId, Long id) { | |
| 121 | + AddressDO address = getAddress(id); | |
| 122 | + check(userId, id); | |
| 123 | + return address; | |
| 124 | + } | |
| 125 | + | |
| 126 | + /** | |
| 127 | + * 获取默认地址 | |
| 128 | + * @param userId | |
| 129 | + * @return | |
| 130 | + */ | |
| 131 | + @Override | |
| 132 | + public AddressDO getDefaultUserAddress(Long userId) { | |
| 133 | + List<AddressDO> addressDOList = selectListByUserIdAndType(userId, AddressTypeEnum.DEFAULT.getType()); | |
| 134 | + return addressDOList.stream().findFirst().orElse(null); | |
| 135 | + } | |
| 136 | + | |
| 137 | + /** | |
| 138 | + * 根据类型获取地址列表 | |
| 139 | + * @param userId | |
| 140 | + * @param type null则查询全部 | |
| 141 | + * @return | |
| 142 | + */ | |
| 143 | + public List<AddressDO> selectListByUserIdAndType(Long userId, Integer type) { | |
| 144 | + QueryWrapperX<AddressDO> queryWrapperX = new QueryWrapperX<AddressDO>().eq("user_id", userId) | |
| 145 | + .eqIfPresent("type", type); | |
| 146 | + return addressMapper.selectList(queryWrapperX); | |
| 147 | + } | |
| 148 | + | |
| 149 | + | |
| 150 | +} | ... | ... |
yudao-module-member/yudao-module-member-impl/src/test/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImplTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.service.address; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | |
| 5 | +import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressCreateReqVO; | |
| 6 | +import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressExportReqVO; | |
| 7 | +import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressPageReqVO; | |
| 8 | +import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressUpdateReqVO; | |
| 9 | +import cn.iocoder.yudao.module.member.dal.dataobject.address.AddressDO; | |
| 10 | +import cn.iocoder.yudao.module.member.dal.mysql.address.AddressMapper; | |
| 11 | +import org.junit.jupiter.api.Disabled; | |
| 12 | +import org.junit.jupiter.api.Test; | |
| 13 | +import org.springframework.context.annotation.Import; | |
| 14 | + | |
| 15 | +import javax.annotation.Resource; | |
| 16 | +import java.util.List; | |
| 17 | + | |
| 18 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; | |
| 19 | +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | |
| 20 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | |
| 21 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | |
| 22 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; | |
| 23 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | |
| 24 | +import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.ADDRESS_NOT_EXISTS; | |
| 25 | +import static org.junit.jupiter.api.Assertions.*; | |
| 26 | + | |
| 27 | +/** | |
| 28 | +* {@link AddressServiceImpl} 的单元测试类 | |
| 29 | +* | |
| 30 | +* @author 芋道源码 | |
| 31 | +*/ | |
| 32 | +@Import(AddressServiceImpl.class) | |
| 33 | +public class AddressServiceImplTest extends BaseDbUnitTest { | |
| 34 | + | |
| 35 | + @Resource | |
| 36 | + private AddressServiceImpl addressService; | |
| 37 | + | |
| 38 | + @Resource | |
| 39 | + private AddressMapper addressMapper; | |
| 40 | + | |
| 41 | + @Test | |
| 42 | + public void testCreateAddress_success() { | |
| 43 | + // 准备参数 | |
| 44 | + AppAddressCreateReqVO reqVO = randomPojo(AppAddressCreateReqVO.class); | |
| 45 | + | |
| 46 | + // 调用 | |
| 47 | + Long addressId = addressService.createAddress(getLoginUserId(), reqVO); | |
| 48 | + // 断言 | |
| 49 | + assertNotNull(addressId); | |
| 50 | + // 校验记录的属性是否正确 | |
| 51 | + AddressDO address = addressMapper.selectById(addressId); | |
| 52 | + assertPojoEquals(reqVO, address); | |
| 53 | + } | |
| 54 | + | |
| 55 | + @Test | |
| 56 | + public void testUpdateAddress_success() { | |
| 57 | + // mock 数据 | |
| 58 | + AddressDO dbAddress = randomPojo(AddressDO.class); | |
| 59 | + addressMapper.insert(dbAddress);// @Sql: 先插入出一条存在的数据 | |
| 60 | + // 准备参数 | |
| 61 | + AppAddressUpdateReqVO reqVO = randomPojo(AppAddressUpdateReqVO.class, o -> { | |
| 62 | + o.setId(dbAddress.getId()); // 设置更新的 ID | |
| 63 | + }); | |
| 64 | + | |
| 65 | + // 调用 | |
| 66 | + addressService.updateAddress(getLoginUserId(), reqVO); | |
| 67 | + // 校验是否更新正确 | |
| 68 | + AddressDO address = addressMapper.selectById(reqVO.getId()); // 获取最新的 | |
| 69 | + assertPojoEquals(reqVO, address); | |
| 70 | + } | |
| 71 | + | |
| 72 | + @Test | |
| 73 | + public void testUpdateAddress_notExists() { | |
| 74 | + // 准备参数 | |
| 75 | + AppAddressUpdateReqVO reqVO = randomPojo(AppAddressUpdateReqVO.class); | |
| 76 | + | |
| 77 | + // 调用, 并断言异常 | |
| 78 | + assertServiceException(() -> addressService.updateAddress(getLoginUserId(), reqVO), ADDRESS_NOT_EXISTS); | |
| 79 | + } | |
| 80 | + | |
| 81 | + @Test | |
| 82 | + public void testDeleteAddress_success() { | |
| 83 | + // mock 数据 | |
| 84 | + AddressDO dbAddress = randomPojo(AddressDO.class); | |
| 85 | + addressMapper.insert(dbAddress);// @Sql: 先插入出一条存在的数据 | |
| 86 | + // 准备参数 | |
| 87 | + Long id = dbAddress.getId(); | |
| 88 | + | |
| 89 | + // 调用 | |
| 90 | + addressService.deleteAddress(getLoginUserId(), id); | |
| 91 | + // 校验数据不存在了 | |
| 92 | + assertNull(addressMapper.selectById(id)); | |
| 93 | + } | |
| 94 | + | |
| 95 | + @Test | |
| 96 | + public void testDeleteAddress_notExists() { | |
| 97 | + // 准备参数 | |
| 98 | + Long id = randomLongId(); | |
| 99 | + | |
| 100 | + // 调用, 并断言异常 | |
| 101 | + assertServiceException(() -> addressService.deleteAddress(getLoginUserId(), id), ADDRESS_NOT_EXISTS); | |
| 102 | + } | |
| 103 | + | |
| 104 | + @Test | |
| 105 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | |
| 106 | + public void ins() { | |
| 107 | + // mock 数据 | |
| 108 | + AddressDO dbAddress = randomPojo(AddressDO.class, o -> { // 等会查询到 | |
| 109 | + o.setUserId(null); | |
| 110 | + o.setName(null); | |
| 111 | + o.setMobile(null); | |
| 112 | + o.setAreaCode(null); | |
| 113 | + o.setDetailAddress(null); | |
| 114 | + o.setType(null); | |
| 115 | + o.setCreateTime(null); | |
| 116 | + }); | |
| 117 | + addressMapper.insert(dbAddress); | |
| 118 | + // 测试 userId 不匹配 | |
| 119 | + addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setUserId(null))); | |
| 120 | + // 测试 name 不匹配 | |
| 121 | + addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setName(null))); | |
| 122 | + // 测试 mobile 不匹配 | |
| 123 | + addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setMobile(null))); | |
| 124 | + // 测试 areaCode 不匹配 | |
| 125 | + addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setAreaCode(null))); | |
| 126 | + // 测试 detailAddress 不匹配 | |
| 127 | + addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setDetailAddress(null))); | |
| 128 | + // 测试 type 不匹配 | |
| 129 | + addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setType(null))); | |
| 130 | + // 测试 createTime 不匹配 | |
| 131 | + addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setCreateTime(null))); | |
| 132 | + // 准备参数 | |
| 133 | + AppAddressPageReqVO reqVO = new AppAddressPageReqVO(); | |
| 134 | + reqVO.setUserId(null); | |
| 135 | + reqVO.setName(null); | |
| 136 | + reqVO.setMobile(null); | |
| 137 | + reqVO.setAreaCode(null); | |
| 138 | + reqVO.setDetailAddress(null); | |
| 139 | + reqVO.setType(null); | |
| 140 | + reqVO.setBeginCreateTime(null); | |
| 141 | + reqVO.setEndCreateTime(null); | |
| 142 | + | |
| 143 | + // 调用 | |
| 144 | + PageResult<AddressDO> pageResult = addressService.getAddressPage(reqVO); | |
| 145 | + // 断言 | |
| 146 | + assertEquals(1, pageResult.getTotal()); | |
| 147 | + assertEquals(1, pageResult.getList().size()); | |
| 148 | + assertPojoEquals(dbAddress, pageResult.getList().get(0)); | |
| 149 | + } | |
| 150 | + | |
| 151 | + @Test | |
| 152 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | |
| 153 | + public void testGetAddressList() { | |
| 154 | + // mock 数据 | |
| 155 | + AddressDO dbAddress = randomPojo(AddressDO.class, o -> { // 等会查询到 | |
| 156 | + o.setUserId(null); | |
| 157 | + o.setName(null); | |
| 158 | + o.setMobile(null); | |
| 159 | + o.setAreaCode(null); | |
| 160 | + o.setDetailAddress(null); | |
| 161 | + o.setType(null); | |
| 162 | + o.setCreateTime(null); | |
| 163 | + }); | |
| 164 | + addressMapper.insert(dbAddress); | |
| 165 | + // 测试 userId 不匹配 | |
| 166 | + addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setUserId(null))); | |
| 167 | + // 测试 name 不匹配 | |
| 168 | + addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setName(null))); | |
| 169 | + // 测试 mobile 不匹配 | |
| 170 | + addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setMobile(null))); | |
| 171 | + // 测试 areaCode 不匹配 | |
| 172 | + addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setAreaCode(null))); | |
| 173 | + // 测试 detailAddress 不匹配 | |
| 174 | + addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setDetailAddress(null))); | |
| 175 | + // 测试 type 不匹配 | |
| 176 | + addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setType(null))); | |
| 177 | + // 测试 createTime 不匹配 | |
| 178 | + addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setCreateTime(null))); | |
| 179 | + // 准备参数 | |
| 180 | + AppAddressExportReqVO reqVO = new AppAddressExportReqVO(); | |
| 181 | + reqVO.setUserId(null); | |
| 182 | + reqVO.setName(null); | |
| 183 | + reqVO.setMobile(null); | |
| 184 | + reqVO.setAreaCode(null); | |
| 185 | + reqVO.setDetailAddress(null); | |
| 186 | + reqVO.setType(null); | |
| 187 | + reqVO.setBeginCreateTime(null); | |
| 188 | + reqVO.setEndCreateTime(null); | |
| 189 | + | |
| 190 | + // 调用 | |
| 191 | + List<AddressDO> list = addressService.getAddressList(reqVO); | |
| 192 | + // 断言 | |
| 193 | + assertEquals(1, list.size()); | |
| 194 | + assertPojoEquals(dbAddress, list.get(0)); | |
| 195 | + } | |
| 196 | + | |
| 197 | +} | ... | ... |
yudao-module-member/yudao-module-member-impl/src/test/resources/sql/clean.sql
yudao-module-member/yudao-module-member-impl/src/test/resources/sql/create_tables.sql
| ... | ... | @@ -30,3 +30,20 @@ CREATE TABLE IF NOT EXISTS "inf_file" ( |
| 30 | 30 | PRIMARY KEY ("id") |
| 31 | 31 | ) COMMENT '文件表'; |
| 32 | 32 | |
| 33 | +CREATE TABLE IF NOT EXISTS "member_address" ( | |
| 34 | + "id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 35 | + "user_id" bigint(20) NOT NULL, | |
| 36 | + "name" varchar(10) NOT NULL, | |
| 37 | + "mobile" varchar(20) NOT NULL, | |
| 38 | + "area_code" int(11) NOT NULL, | |
| 39 | + "detail_address" varchar(250) NOT NULL, | |
| 40 | + "type" tinyint(4) NOT NULL, | |
| 41 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 42 | + "creator" varchar(64) DEFAULT '', | |
| 43 | + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
| 44 | + "deleted" bit NOT NULL DEFAULT FALSE, | |
| 45 | + "updater" varchar(64) DEFAULT '', | |
| 46 | + "tenant_id" bigint(20) NOT NULL, | |
| 47 | + PRIMARY KEY ("id") | |
| 48 | + ) COMMENT '用户收件地址'; | |
| 49 | + | ... | ... |