Commit 4ce76e82fc4ae01c5f3ce979e20fa71dcb245fa9

Authored by YunaiV
1 parent 96e2a27d

mall:完善收件地址

Showing 26 changed files with 161 additions and 609 deletions
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/ProductSkuController.java
... ... @@ -2,9 +2,10 @@ package cn.iocoder.yudao.module.product.controller.admin.sku;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5   -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
6   -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
7   -import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*;
  5 +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO;
  6 +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuPageReqVO;
  7 +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO;
  8 +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuUpdateReqVO;
8 9 import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
9 10 import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
10 11 import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
... ... @@ -16,14 +17,11 @@ import org.springframework.validation.annotation.Validated;
16 17 import org.springframework.web.bind.annotation.*;
17 18  
18 19 import javax.annotation.Resource;
19   -import javax.servlet.http.HttpServletResponse;
20 20 import javax.validation.Valid;
21   -import java.io.IOException;
22 21 import java.util.Collection;
23 22 import java.util.List;
24 23  
25 24 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
26   -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
27 25  
28 26 @Api(tags = "管理后台 - 商品 sku")
29 27 @RestController
... ... @@ -84,16 +82,4 @@ public class ProductSkuController {
84 82 return success(ProductSkuConvert.INSTANCE.convertPage(pageResult));
85 83 }
86 84  
87   - @GetMapping("/export-excel")
88   - @ApiOperation("导出商品sku Excel")
89   - @PreAuthorize("@ss.hasPermission('product:sku:export')")
90   - @OperateLog(type = EXPORT)
91   - public void exportSkuExcel(@Valid ProductSkuExportReqVO exportReqVO,
92   - HttpServletResponse response) throws IOException {
93   - List<ProductSkuDO> list = ProductSkuService.getSkuList(exportReqVO);
94   - // 导出 Excel
95   - List<ProductSkuExcelVO> datas = ProductSkuConvert.INSTANCE.convertList02(list);
96   - ExcelUtils.write(response, "商品sku.xls", "数据", ProductSkuExcelVO.class, datas);
97   - }
98   -
99 85 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java
... ... @@ -2,9 +2,10 @@ package cn.iocoder.yudao.module.product.controller.admin.spu;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5   -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
6   -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
7   -import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
  5 +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuCreateReqVO;
  6 +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuPageReqVO;
  7 +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuRespVO;
  8 +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuUpdateReqVO;
8 9 import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert;
9 10 import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
10 11 import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
... ... @@ -16,14 +17,11 @@ import org.springframework.validation.annotation.Validated;
16 17 import org.springframework.web.bind.annotation.*;
17 18  
18 19 import javax.annotation.Resource;
19   -import javax.servlet.http.HttpServletResponse;
20 20 import javax.validation.Valid;
21   -import java.io.IOException;
22 21 import java.util.Collection;
23 22 import java.util.List;
24 23  
25 24 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
26   -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
27 25  
28 26 @Api(tags = "管理后台 - 商品spu")
29 27 @RestController
... ... @@ -83,16 +81,4 @@ public class ProductSpuController {
83 81 return success(spuService.getSpuPage(pageVO));
84 82 }
85 83  
86   - @GetMapping("/export-excel")
87   - @ApiOperation("导出商品spu Excel")
88   - @PreAuthorize("@ss.hasPermission('product:spu:export')")
89   - @OperateLog(type = EXPORT)
90   - public void exportSpuExcel(@Valid SpuExportReqVO exportReqVO,
91   - HttpServletResponse response) throws IOException {
92   - List<ProductSpuDO> list = spuService.getSpuList(exportReqVO);
93   - // 导出 Excel
94   - List<SpuExcelVO> datas = ProductSpuConvert.INSTANCE.convertList02(list);
95   - ExcelUtils.write(response, "商品spu.xls", "数据", SpuExcelVO.class, datas);
96   - }
97   -
98 84 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuBaseVO.java
1 1 package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
2 2  
3   -import lombok.*;
4   -import java.util.*;
5   -import io.swagger.annotations.*;
6   -import javax.validation.constraints.*;
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +
  6 +import javax.validation.constraints.NotNull;
  7 +import java.util.List;
7 8  
8 9 /**
9 10 * 商品spu Base VO,提供给添加、修改、详细的子 VO 使用
... ... @@ -45,6 +46,6 @@ public class ProductSpuBaseVO {
45 46 private Integer quantity;
46 47  
47 48 @ApiModelProperty(value = "上下架状态: 0 上架(开启) 1 下架(禁用)")
48   - private Boolean status;
  49 + private Integer status;
49 50  
50 51 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuExcelVO.java deleted
1   -package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
2   -
3   -import lombok.*;
4   -import java.util.*;
5   -import io.swagger.annotations.*;
6   -
7   -import com.alibaba.excel.annotation.ExcelProperty;
8   -
9   -/**
10   - * 商品spu Excel VO
11   - *
12   - * @author 芋道源码
13   - */
14   -@Data
15   -public class SpuExcelVO {
16   -
17   - @ExcelProperty("主键")
18   - private Integer id;
19   -
20   - @ExcelProperty("商品名称")
21   - private String name;
22   -
23   - @ExcelProperty("卖点")
24   - private String sellPoint;
25   -
26   - @ExcelProperty("描述")
27   - private String description;
28   -
29   - @ExcelProperty("分类id")
30   - private Long categoryId;
31   -
32   - @ExcelProperty("商品主图地址,* 数组,以逗号分隔,最多上传15张")
33   - private List<String> picUrls;
34   -
35   - @ExcelProperty("排序字段")
36   - private Integer sort;
37   -
38   - @ExcelProperty("点赞初始人数")
39   - private Integer likeCount;
40   -
41   - @ExcelProperty("价格 单位使用:分")
42   - private Integer price;
43   -
44   - @ExcelProperty("库存数量")
45   - private Integer quantity;
46   -
47   - @ExcelProperty("上下架状态: 0 上架(开启) 1 下架(禁用)")
48   - private Boolean status;
49   -
50   - @ExcelProperty("创建时间")
51   - private Date createTime;
52   -
53   -}
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuExportReqVO.java deleted
1   -package cn.iocoder.yudao.module.product.controller.admin.spu.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 = "管理后台 - 商品spu Excel 导出 Request VO", description = "参数和 SpuPageReqVO 是一致的")
12   -@Data
13   -public class SpuExportReqVO {
14   -
15   - @ApiModelProperty(value = "商品名称")
16   - private String name;
17   -
18   - @ApiModelProperty(value = "卖点")
19   - private String sellPoint;
20   -
21   - @ApiModelProperty(value = "描述")
22   - private String description;
23   -
24   - @ApiModelProperty(value = "分类id")
25   - private Long categoryId;
26   -
27   - @ApiModelProperty(value = "商品主图地址,* 数组,以逗号分隔,最多上传15张")
28   - private List<String> picUrls;
29   -
30   - @ApiModelProperty(value = "排序字段")
31   - private Integer sort;
32   -
33   - @ApiModelProperty(value = "点赞初始人数")
34   - private Integer likeCount;
35   -
36   - @ApiModelProperty(value = "价格 单位使用:分")
37   - private Integer price;
38   -
39   - @ApiModelProperty(value = "库存数量")
40   - private Integer quantity;
41   -
42   - @ApiModelProperty(value = "上下架状态: 0 上架(开启) 1 下架(禁用)")
43   - private Boolean status;
44   -
45   - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
46   - @ApiModelProperty(value = "创建时间")
47   - private Date[] createTime;
48   -
49   -}
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppSpuPageRespVO.java
... ... @@ -47,6 +47,6 @@ public class AppSpuPageRespVO {
47 47 private Integer quantity;
48 48  
49 49 @ApiModelProperty(value = "上下架状态: 0 上架(开启) 1 下架(禁用)")
50   - private Boolean status;
  50 + private Integer status;
51 51  
52 52 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/sku/ProductSkuConvert.java
1 1 package cn.iocoder.yudao.module.product.convert.sku;
2 2  
3   -import java.util.*;
4   -
5   -import cn.hutool.json.JSONUtil;
6 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
7   -
  4 +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO;
  5 +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuExcelVO;
  6 +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO;
  7 +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuUpdateReqVO;
  8 +import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
8 9 import org.mapstruct.Mapper;
9 10 import org.mapstruct.Mapping;
10   -import org.mapstruct.Named;
11 11 import org.mapstruct.factory.Mappers;
12   -import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*;
13   -import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
  12 +
  13 +import java.util.List;
14 14  
15 15 /**
16 16 * 商品sku Convert
... ... @@ -22,18 +22,13 @@ public interface ProductSkuConvert {
22 22  
23 23 ProductSkuConvert INSTANCE = Mappers.getMapper(ProductSkuConvert.class);
24 24  
25   - @Mapping(source = "properties", target = "properties", qualifiedByName = "translateStringFromList")
26 25 ProductSkuDO convert(ProductSkuCreateReqVO bean);
27 26  
28   - @Mapping(source = "properties", target = "properties", qualifiedByName = "translateStringFromList")
29 27 ProductSkuDO convert(ProductSkuUpdateReqVO bean);
30 28  
31   - @Mapping(source = "properties", target = "properties", qualifiedByName = "tokenizeToBeanArray")
  29 + @Mapping(source = "properties", target = "properties")
32 30 ProductSkuRespVO convert(ProductSkuDO bean);
33 31  
34   - @Mapping(source = "properties", target = "properties", qualifiedByName = "tokenizeToExcelBeanArray")
35   - ProductSkuExcelVO convertToExcelVO(ProductSkuDO bean);
36   -
37 32 List<ProductSkuRespVO> convertList(List<ProductSkuDO> list);
38 33  
39 34 List<ProductSkuDO> convertSkuDOList(List<ProductSkuCreateReqVO> list);
... ... @@ -42,18 +37,4 @@ public interface ProductSkuConvert {
42 37  
43 38 List<ProductSkuExcelVO> convertList02(List<ProductSkuDO> list);
44 39  
45   - @Named("tokenizeToBeanArray")
46   - default List<ProductSkuBaseVO.Property> translatePropertyArrayFromString(String properties) {
47   - return JSONUtil.toList(properties, ProductSkuBaseVO.Property.class);
48   - }
49   -
50   - @Named("tokenizeToExcelBeanArray")
51   - default List<ProductSkuExcelVO.Property> translateExcelPropertyArrayFromString(String properties) {
52   - return JSONUtil.toList(properties, ProductSkuExcelVO.Property.class);
53   - }
54   -
55   - @Named("translateStringFromList")
56   - default String translatePropertyStringFromList(List<ProductSkuBaseVO.Property> properties) {
57   - return JSONUtil.toJsonStr(properties);
58   - }
59 40 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java
... ... @@ -30,8 +30,6 @@ public interface ProductSpuConvert {
30 30  
31 31 PageResult<SpuRespVO> convertPage(PageResult<ProductSpuDO> page);
32 32  
33   - List<SpuExcelVO> convertList02(List<ProductSpuDO> list);
34   -
35 33 SpuPageReqVO convert(AppSpuPageReqVO bean);
36 34  
37 35 AppSpuPageRespVO convertAppResp(ProductSpuDO list);
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/sku/ProductSkuMapper.java
... ... @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.product.dal.mysql.sku;
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
5 5 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
6   -import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuExportReqVO;
7 6 import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuPageReqVO;
8 7 import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
9 8 import org.apache.ibatis.annotations.Mapper;
... ... @@ -24,7 +23,7 @@ public interface ProductSkuMapper extends BaseMapperX&lt;ProductSkuDO&gt; {
24 23 .eqIfPresent(ProductSkuDO::getProperties, reqVO.getProperties())
25 24 .eqIfPresent(ProductSkuDO::getPrice, reqVO.getPrice())
26 25 .eqIfPresent(ProductSkuDO::getOriginalPrice, reqVO.getOriginalPrice())
27   - .eqIfPresent(ProductSkuDO::getCostPrice, reqVO.getCostPrice())
  26 +// .eqIfPresent(ProductSkuDO::getCostPrice, reqVO.getCostPrice())
28 27 .eqIfPresent(ProductSkuDO::getBarCode, reqVO.getBarCode())
29 28 .eqIfPresent(ProductSkuDO::getPicUrl, reqVO.getPicUrl())
30 29 .eqIfPresent(ProductSkuDO::getStatus, reqVO.getStatus())
... ... @@ -32,19 +31,6 @@ public interface ProductSkuMapper extends BaseMapperX&lt;ProductSkuDO&gt; {
32 31 .orderByDesc(ProductSkuDO::getId));
33 32 }
34 33  
35   - default List<ProductSkuDO> selectList(ProductSkuExportReqVO reqVO) {
36   - return selectList(new LambdaQueryWrapperX<ProductSkuDO>()
37   - .eqIfPresent(ProductSkuDO::getSpuId, reqVO.getSpuId())
38   - .eqIfPresent(ProductSkuDO::getProperties, reqVO.getProperties())
39   - .eqIfPresent(ProductSkuDO::getPrice, reqVO.getPrice())
40   - .eqIfPresent(ProductSkuDO::getOriginalPrice, reqVO.getOriginalPrice())
41   - .eqIfPresent(ProductSkuDO::getCostPrice, reqVO.getCostPrice())
42   - .eqIfPresent(ProductSkuDO::getBarCode, reqVO.getBarCode())
43   - .eqIfPresent(ProductSkuDO::getPicUrl, reqVO.getPicUrl())
44   - .eqIfPresent(ProductSkuDO::getStatus, reqVO.getStatus())
45   - .betweenIfPresent(ProductSkuDO::getCreateTime, reqVO.getCreateTime())
46   - .orderByDesc(ProductSkuDO::getId));
47   - }
48 34  
49 35 // TODO @franky:方法名 selectList; 可以直接调用 selectList
50 36 default List<ProductSkuDO> selectBySpuIds(List<Long> spuIds) {
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/spu/ProductSpuMapper.java
1 1 package cn.iocoder.yudao.module.product.dal.mysql.spu;
2 2  
3   -import java.util.*;
4   -
5 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6   -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
7 4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  5 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  6 +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuPageReqVO;
8 7 import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
9 8 import org.apache.ibatis.annotations.Mapper;
10   -import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
11 9  
12 10 /**
13 11 * 商品spu Mapper
... ... @@ -25,25 +23,9 @@ public interface ProductSpuMapper extends BaseMapperX&lt;ProductSpuDO&gt; {
25 23 .eqIfPresent(ProductSpuDO::getCategoryId, reqVO.getCategoryId())
26 24 .eqIfPresent(ProductSpuDO::getPicUrls, reqVO.getPicUrls())
27 25 .eqIfPresent(ProductSpuDO::getSort, reqVO.getSort())
28   - .eqIfPresent(ProductSpuDO::getLikeCount, reqVO.getLikeCount())
29   - .eqIfPresent(ProductSpuDO::getPrice, reqVO.getPrice())
30   - .eqIfPresent(ProductSpuDO::getQuantity, reqVO.getQuantity())
31   - .eqIfPresent(ProductSpuDO::getStatus, reqVO.getStatus())
32   - .betweenIfPresent(ProductSpuDO::getCreateTime, reqVO.getCreateTime())
33   - .orderByDesc(ProductSpuDO::getId));
34   - }
35   -
36   - default List<ProductSpuDO> selectList(SpuExportReqVO reqVO) {
37   - return selectList(new LambdaQueryWrapperX<ProductSpuDO>()
38   - .likeIfPresent(ProductSpuDO::getName, reqVO.getName())
39   - .eqIfPresent(ProductSpuDO::getSellPoint, reqVO.getSellPoint())
40   - .eqIfPresent(ProductSpuDO::getDescription, reqVO.getDescription())
41   - .eqIfPresent(ProductSpuDO::getCategoryId, reqVO.getCategoryId())
42   - .eqIfPresent(ProductSpuDO::getPicUrls, reqVO.getPicUrls())
43   - .eqIfPresent(ProductSpuDO::getSort, reqVO.getSort())
44   - .eqIfPresent(ProductSpuDO::getLikeCount, reqVO.getLikeCount())
  26 +// .eqIfPresent(ProductSpuDO::getLikeCount, reqVO.getLikeCount())
45 27 .eqIfPresent(ProductSpuDO::getPrice, reqVO.getPrice())
46   - .eqIfPresent(ProductSpuDO::getQuantity, reqVO.getQuantity())
  28 +// .eqIfPresent(ProductSpuDO::getQuantity, reqVO.getQuantity())
47 29 .eqIfPresent(ProductSpuDO::getStatus, reqVO.getStatus())
48 30 .betweenIfPresent(ProductSpuDO::getCreateTime, reqVO.getCreateTime())
49 31 .orderByDesc(ProductSpuDO::getId));
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java
... ... @@ -65,14 +65,6 @@ public interface ProductSkuService {
65 65 PageResult<ProductSkuDO> getSkuPage(ProductSkuPageReqVO pageReqVO);
66 66  
67 67 /**
68   - * 获得商品sku列表, 用于 Excel 导出
69   - *
70   - * @param exportReqVO 查询条件
71   - * @return 商品sku列表
72   - */
73   - List<ProductSkuDO> getSkuList(ProductSkuExportReqVO exportReqVO);
74   -
75   - /**
76 68 * 对 sku 的组合的属性等进行合法性校验
77 69 *
78 70 * @param list sku组合的集合
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java
... ... @@ -84,11 +84,6 @@ public class ProductSkuServiceImpl implements ProductSkuService {
84 84 return productSkuMapper.selectPage(pageReqVO);
85 85 }
86 86  
87   - @Override
88   - public List<ProductSkuDO> getSkuList(ProductSkuExportReqVO exportReqVO) {
89   - return productSkuMapper.selectList(exportReqVO);
90   - }
91   -
92 87 // TODO @franky:这个方法,貌似实现的还是有点问题哈。例如说,throw 异常,后面还执行逻辑~
93 88 // TODO @艿艿 咳咳,throw 那里我是偷懒省略了{},哈哈,我加上,然后我调试下,在优化下
94 89 @Override
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java
1 1 package cn.iocoder.yudao.module.product.service.spu;
2 2  
3   -import java.util.*;
4   -import javax.validation.*;
5   -import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuCreateReqVO;
  5 +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuPageReqVO;
  6 +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuRespVO;
  7 +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuUpdateReqVO;
6 8 import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageReqVO;
7 9 import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageRespVO;
8 10 import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
9   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
  11 +
  12 +import javax.validation.Valid;
  13 +import java.util.Collection;
  14 +import java.util.List;
10 15  
11 16 /**
12 17 * 商品spu Service 接口
... ... @@ -62,14 +67,6 @@ public interface ProductSpuService {
62 67 PageResult<SpuRespVO> getSpuPage(SpuPageReqVO pageReqVO);
63 68  
64 69 /**
65   - * 获得商品spu列表, 用于 Excel 导出
66   - *
67   - * @param exportReqVO 查询条件
68   - * @return 商品spu列表
69   - */
70   - List<ProductSpuDO> getSpuList(SpuExportReqVO exportReqVO);
71   -
72   - /**
73 70 * 获得商品spu分页
74 71 *
75 72 * @param pageReqVO 分页查询
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java
... ... @@ -172,11 +172,6 @@ public class ProductSpuServiceImpl implements ProductSpuService {
172 172 }
173 173  
174 174 @Override
175   - public List<ProductSpuDO> getSpuList(SpuExportReqVO exportReqVO) {
176   - return ProductSpuMapper.selectList(exportReqVO);
177   - }
178   -
179   - @Override
180 175 public PageResult<AppSpuPageRespVO> getSpuPage(AppSpuPageReqVO pageReqVO) {
181 176 PageResult<ProductSpuDO> productSpuDOPageResult = ProductSpuMapper.selectPage(ProductSpuConvert.INSTANCE.convert(pageReqVO));
182 177 PageResult<AppSpuPageRespVO> pageResult = new PageResult<>();
... ...
yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/sku/SkuServiceImplTest.java
1 1 package cn.iocoder.yudao.module.product.service.sku;
2 2  
3   -import org.junit.jupiter.api.Disabled;
4   -import org.junit.jupiter.api.Test;
5   -
6   -import javax.annotation.Resource;
7   -
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
8 4 import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
9   -
10   -import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*;
  5 +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO;
  6 +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuPageReqVO;
  7 +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuUpdateReqVO;
11 8 import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
12 9 import cn.iocoder.yudao.module.product.dal.mysql.sku.ProductSkuMapper;
13   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
14   -
  10 +import org.junit.jupiter.api.Disabled;
  11 +import org.junit.jupiter.api.Test;
15 12 import org.springframework.context.annotation.Import;
16   -import java.util.*;
17 13  
18   -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
19   -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
20   -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
21   -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
  14 +import javax.annotation.Resource;
  15 +
  16 +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
  17 +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
  18 +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
  19 +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
  20 +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS;
22 21 import static org.junit.jupiter.api.Assertions.*;
23 22  
24 23 /**
... ... @@ -107,7 +106,7 @@ public class SkuServiceImplTest extends BaseDbUnitTest {
107 106 o.setProperties(null);
108 107 o.setPrice(null);
109 108 o.setOriginalPrice(null);
110   - o.setCostPrice(null);
  109 +// o.setCostPrice(null);
111 110 o.setBarCode(null);
112 111 o.setPicUrl(null);
113 112 o.setStatus(null);
... ... @@ -123,7 +122,7 @@ public class SkuServiceImplTest extends BaseDbUnitTest {
123 122 // 测试 originalPrice 不匹配
124 123 ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setOriginalPrice(null)));
125 124 // 测试 costPrice 不匹配
126   - ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCostPrice(null)));
  125 +// ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCostPrice(null)));
127 126 // 测试 barCode 不匹配
128 127 ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setBarCode(null)));
129 128 // 测试 picUrl 不匹配
... ... @@ -152,57 +151,4 @@ public class SkuServiceImplTest extends BaseDbUnitTest {
152 151 assertPojoEquals(dbSku, pageResult.getList().get(0));
153 152 }
154 153  
155   - @Test
156   - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
157   - public void testGetSkuList() {
158   - // mock 数据
159   - ProductSkuDO dbSku = randomPojo(ProductSkuDO.class, o -> { // 等会查询到
160   - o.setSpuId(null);
161   - o.setProperties(null);
162   - o.setPrice(null);
163   - o.setOriginalPrice(null);
164   - o.setCostPrice(null);
165   - o.setBarCode(null);
166   - o.setPicUrl(null);
167   - o.setStatus(null);
168   - o.setCreateTime(null);
169   - });
170   - ProductSkuMapper.insert(dbSku);
171   - // 测试 spuId 不匹配
172   - ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setSpuId(null)));
173   - // 测试 properties 不匹配
174   - ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setProperties(null)));
175   - // 测试 price 不匹配
176   - ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setPrice(null)));
177   - // 测试 originalPrice 不匹配
178   - ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setOriginalPrice(null)));
179   - // 测试 costPrice 不匹配
180   - ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCostPrice(null)));
181   - // 测试 barCode 不匹配
182   - ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setBarCode(null)));
183   - // 测试 picUrl 不匹配
184   - ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setPicUrl(null)));
185   - // 测试 status 不匹配
186   - ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setStatus(null)));
187   - // 测试 createTime 不匹配
188   - ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCreateTime(null)));
189   - // 准备参数
190   - ProductSkuExportReqVO reqVO = new ProductSkuExportReqVO();
191   - reqVO.setSpuId(null);
192   - reqVO.setProperties(null);
193   - reqVO.setPrice(null);
194   - reqVO.setOriginalPrice(null);
195   - reqVO.setCostPrice(null);
196   - reqVO.setBarCode(null);
197   - reqVO.setPicUrl(null);
198   - reqVO.setStatus(null);
199   - reqVO.setCreateTime(null);
200   -
201   - // 调用
202   - List<ProductSkuDO> list = ProductSkuService.getSkuList(reqVO);
203   - // 断言
204   - assertEquals(1, list.size());
205   - assertPojoEquals(dbSku, list.get(0));
206   - }
207   -
208 154 }
... ...
yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImplTest.java
1 1 package cn.iocoder.yudao.module.product.service.spu;
2 2  
3   -import org.junit.jupiter.api.Disabled;
4   -import org.junit.jupiter.api.Test;
5   -import org.springframework.boot.test.mock.mockito.MockBean;
6   -
7   -import javax.annotation.Resource;
8   -
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
9 4 import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
10   -
11   -import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
  5 +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuCreateReqVO;
  6 +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuPageReqVO;
  7 +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuRespVO;
  8 +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuUpdateReqVO;
12 9 import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
13 10 import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper;
14   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
  11 +import org.junit.jupiter.api.Disabled;
  12 +import org.junit.jupiter.api.Test;
  13 +import org.springframework.context.annotation.Import;
15 14  
16 15 import javax.annotation.Resource;
17   -import org.springframework.context.annotation.Import;
18   -import java.util.*;
19   -
20   -import static cn.hutool.core.util.RandomUtil.*;
21   -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
22   -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
23   -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
24   -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
25   -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
  16 +
  17 +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
  18 +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
  19 +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
  20 +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
  21 +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS;
26 22 import static org.junit.jupiter.api.Assertions.*;
27   -import static org.mockito.Mockito.*;
28 23  
29 24 /**
30 25 * {@link ProductSpuServiceImpl} 的单元测试类
... ... @@ -114,9 +109,9 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest {
114 109 o.setCategoryId(null);
115 110 o.setPicUrls(null);
116 111 o.setSort(null);
117   - o.setLikeCount(null);
  112 +// o.setLikeCount(null);
118 113 o.setPrice(null);
119   - o.setQuantity(null);
  114 +// o.setQuantity(null);
120 115 o.setStatus(null);
121 116 o.setCreateTime(null);
122 117 });
... ... @@ -134,11 +129,11 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest {
134 129 // 测试 sort 不匹配
135 130 ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setSort(null)));
136 131 // 测试 likeCount 不匹配
137   - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setLikeCount(null)));
  132 +// ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setLikeCount(null)));
138 133 // 测试 price 不匹配
139 134 ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setPrice(null)));
140 135 // 测试 quantity 不匹配
141   - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setQuantity(null)));
  136 +// ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setQuantity(null)));
142 137 // 测试 status 不匹配
143 138 ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setStatus(null)));
144 139 // 测试 createTime 不匹配
... ... @@ -165,65 +160,4 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest {
165 160 assertPojoEquals(dbSpu, pageResult.getList().get(0));
166 161 }
167 162  
168   - @Test
169   - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
170   - public void testGetSpuList() {
171   - // mock 数据
172   - ProductSpuDO dbSpu = randomPojo(ProductSpuDO.class, o -> { // 等会查询到
173   - o.setName(null);
174   - o.setSellPoint(null);
175   - o.setDescription(null);
176   - o.setCategoryId(null);
177   - o.setPicUrls(null);
178   - o.setSort(null);
179   - o.setLikeCount(null);
180   - o.setPrice(null);
181   - o.setQuantity(null);
182   - o.setStatus(null);
183   - o.setCreateTime(null);
184   - });
185   - ProductSpuMapper.insert(dbSpu);
186   - // 测试 name 不匹配
187   - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setName(null)));
188   - // 测试 sellPoint 不匹配
189   - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setSellPoint(null)));
190   - // 测试 description 不匹配
191   - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setDescription(null)));
192   - // 测试 categoryId 不匹配
193   - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setCategoryId(null)));
194   - // 测试 picUrls 不匹配
195   - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setPicUrls(null)));
196   - // 测试 sort 不匹配
197   - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setSort(null)));
198   - // 测试 likeCount 不匹配
199   - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setLikeCount(null)));
200   - // 测试 price 不匹配
201   - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setPrice(null)));
202   - // 测试 quantity 不匹配
203   - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setQuantity(null)));
204   - // 测试 status 不匹配
205   - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setStatus(null)));
206   - // 测试 createTime 不匹配
207   - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setCreateTime(null)));
208   - // 准备参数
209   - SpuExportReqVO reqVO = new SpuExportReqVO();
210   - reqVO.setName(null);
211   - reqVO.setSellPoint(null);
212   - reqVO.setDescription(null);
213   - reqVO.setCategoryId(null);
214   - reqVO.setPicUrls(null);
215   - reqVO.setSort(null);
216   - reqVO.setLikeCount(null);
217   - reqVO.setPrice(null);
218   - reqVO.setQuantity(null);
219   - reqVO.setStatus(null);
220   - reqVO.setCreateTime(null);
221   -
222   - // 调用
223   - List<ProductSpuDO> list = spuService.getSpuList(reqVO);
224   - // 断言
225   - assertEquals(1, list.size());
226   - assertPojoEquals(dbSpu, list.get(0));
227   - }
228   -
229 163 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/cart/CartItemDO.java
... ... @@ -82,9 +82,14 @@ public class CartItemDO extends BaseDO {
82 82 // * 商品营销活动类型
83 83 // */
84 84 // private Integer activityType;
  85 + // TODO 芋艿:combination_id 拼团 ID
  86 + // TODO 芋艿:seckill_id 秒杀产品 ID
  87 + // TODO 芋艿:bargain_id 砍价 ID
85 88  
86 89 // ========= 优惠信息 END =========
87 90  
88   - // TODO 芋艿:distribution_card_no
  91 + // TODO 芋艿:distribution_card_no 推广员
  92 + // TODO 芋艿:is_pay 未购买、已购买
  93 + // TODO 芋艿:is_new 是否立即购买
89 94  
90 95 }
... ...
yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java
... ... @@ -22,6 +22,5 @@ public interface ErrorCodeConstants {
22 22  
23 23 // ========== 用户收件地址 1004004000 ==========
24 24 ErrorCode ADDRESS_NOT_EXISTS = new ErrorCode(1004004000, "用户收件地址不存在");
25   - ErrorCode ADDRESS_FORBIDDEN = new ErrorCode(1004004001, "没有该操作权限");
26 25  
27 26 }
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/AppAddressController.http
... ... @@ -2,53 +2,53 @@
2 2 POST {{appApi}}//member/address/create
3 3 Content-Type: application/json
4 4 tenant-id: {{appTenentId}}
5   -Authorization: Bearer 2510e2e4287346eb8e36353a55e27fd6
  5 +Authorization: Bearer {{appToken}}
6 6  
7 7 {
8   - "userId": "245",
9 8 "name": "yunai",
10 9 "mobile": "15601691300",
11   - "areaCode": "610632",
  10 + "areaId": "610632",
  11 + "postCode": "200000",
12 12 "detailAddress": "芋道源码 233 号 666 室",
13   - "type": "1"
  13 + "defaulted": true
14 14 }
15 15  
16 16 ### 请求 /update 接口 => 成功
17 17 PUT {{appApi}}//member/address/update
18 18 Content-Type: application/json
19 19 tenant-id: {{appTenentId}}
20   -Authorization: Bearer 2510e2e4287346eb8e36353a55e27fd6
  20 +Authorization: Bearer {{appToken}}
21 21  
22 22 {
23 23 "id": "1",
24   - "userId": "245",
25 24 "name": "yunai888",
26 25 "mobile": "15601691300",
27   - "areaCode": "610632",
  26 + "areaId": "610632",
  27 + "postCode": "200000",
28 28 "detailAddress": "芋道源码 233 号 666 室",
29   - "type": "1"
  29 + "defaulted": false
30 30 }
31 31  
32 32 ### 请求 /delete 接口 => 成功
33 33 DELETE {{appApi}}//member/address/delete?id=2
34 34 Content-Type: application/json
35 35 tenant-id: {{appTenentId}}
36   -Authorization: Bearer fa4848b001de4eae9faf516c0c8520f8
  36 +Authorization: Bearer {{appToken}}
37 37  
38 38 ### 请求 /get 接口 => 成功
39 39 GET {{appApi}}//member/address/get?id=1
40 40 Content-Type: application/json
41 41 tenant-id: {{appTenentId}}
42   -Authorization: Bearer fa4848b001de4eae9faf516c0c8520f8
  42 +Authorization: Bearer {{appToken}}
43 43  
44 44 ### 请求 /get-default 接口 => 成功
45 45 GET {{appApi}}//member/address/get-default
46 46 Content-Type: application/json
47 47 tenant-id: {{appTenentId}}
48   -Authorization: Bearer fa4848b001de4eae9faf516c0c8520f8
  48 +Authorization: Bearer {{appToken}}
49 49  
50 50 ### 请求 /list 接口 => 成功
51 51 GET {{appApi}}//member/address/list
52 52 Content-Type: application/json
53 53 tenant-id: {{appTenentId}}
54   -Authorization: Bearer fa4848b001de4eae9faf516c0c8520f8
55 54 \ No newline at end of file
  55 +Authorization: Bearer {{appToken}}
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressBaseVO.java
1 1 package cn.iocoder.yudao.module.member.controller.app.address.vo;
2 2  
3   -import cn.iocoder.yudao.framework.common.validation.InEnum;
4   -import cn.iocoder.yudao.module.member.enums.AddressTypeEnum;
5   -import lombok.*;
6   -import io.swagger.annotations.*;
7   -import javax.validation.constraints.*;
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +
  6 +import javax.validation.constraints.NotEmpty;
  7 +import javax.validation.constraints.NotNull;
8 8  
9 9 /**
10 10 * 用户收件地址 Base VO,提供给添加、修改、详细的子 VO 使用
... ... @@ -21,17 +21,20 @@ public class AppAddressBaseVO {
21 21 @NotNull(message = "手机号不能为空")
22 22 private String mobile;
23 23  
24   - @ApiModelProperty(value = "地区编码", required = true)
25   - @NotNull(message = "地区编码不能为空")
26   - private Integer areaCode;
  24 + @ApiModelProperty(value = "地区编号", required = true)
  25 + @NotNull(message = "地区编号不能为空")
  26 + private Long areaId;
  27 +
  28 + @ApiModelProperty(value = "邮编", required = true)
  29 + @NotEmpty(message = "邮编不能为空")
  30 + private String postCode;
27 31  
28 32 @ApiModelProperty(value = "收件详细地址", required = true)
29 33 @NotNull(message = "收件详细地址不能为空")
30 34 private String detailAddress;
31 35  
32   - @ApiModelProperty(value = "地址类型", required = true)
33   - @NotNull(message = "地址类型不能为空")
34   - @InEnum(AddressTypeEnum.class)
35   - private Integer type;
  36 + @ApiModelProperty(value = "是否默认地址", required = true)
  37 + @NotNull(message = "是否默认地址不能为空")
  38 + private Boolean defaulted;
36 39  
37 40 }
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/address/AddressDO.java
... ... @@ -39,7 +39,7 @@ public class AddressDO extends BaseDO {
39 39 /**
40 40 * 地区编号
41 41 */
42   - private Integer areaId;
  42 + private Long areaId;
43 43 /**
44 44 * 邮编
45 45 */
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java
1 1 package cn.iocoder.yudao.module.member.dal.mysql.address;
2 2  
3   -
4 3 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
5   -import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
  4 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
6 5 import cn.iocoder.yudao.module.member.dal.dataobject.address.AddressDO;
7   -import cn.iocoder.yudao.module.member.enums.AddressTypeEnum;
8 6 import org.apache.ibatis.annotations.Mapper;
9 7  
10 8 import java.util.List;
11 9  
12   -/**
13   - * 用户收件地址 Mapper
14   - *
15   - * @author 芋道源码
16   - */
17 10 @Mapper
18 11 public interface AddressMapper extends BaseMapperX<AddressDO> {
19 12  
20   - /**
21   - * 获取当前地址 根据id和userId
22   - * @param userId
23   - * @param id
24   - * @return
25   - */
26   - default AddressDO getAddressByIdAndUserId(Long userId, Long id) {
27   - QueryWrapperX<AddressDO> queryWrapperX = new QueryWrapperX<>();
28   - queryWrapperX.eq("user_id", userId).eq("id", id);
29   - return selectList(queryWrapperX).stream().findFirst().orElse(null);
30   - }
31   -
32   - /**
33   - * 获取地址列表
34   - * @param userId
35   - * @param type
36   - * @return
37   - */
38   - default List<AddressDO> selectListByUserIdAndType(Long userId, Integer type) {
39   - QueryWrapperX<AddressDO> queryWrapperX = new QueryWrapperX<AddressDO>().eq("user_id", userId)
40   - .eqIfPresent("type", type);
41   - return selectList(queryWrapperX);
42   - }
43   -
44   - /**
45   - * 获取默认地址
46   - * @param userId
47   - * @return
48   - */
49   - default AddressDO getDefaultUserAddress(Long userId) {
50   - List<AddressDO> addressDOList = selectListByUserIdAndType(userId, AddressTypeEnum.DEFAULT.getType());
51   - return addressDOList.stream().findFirst().orElse(null);
  13 + default AddressDO selectByIdAndUserId(Long id, Long userId) {
  14 + return selectOne(AddressDO::getId, id, AddressDO::getUserId, userId);
52 15 }
53 16  
54   - /**
55   - * 获取默认地址
56   - * @param id
57   - * @param addressTypeEnum
58   - * @return
59   - */
60   - default int updateTypeById(Long id, AddressTypeEnum addressTypeEnum) {
61   - return updateById(new AddressDO().setId(id).setType(addressTypeEnum.getType()));
  17 + default List<AddressDO> selectListByUserIdAndDefaulted(Long userId, Boolean defaulted) {
  18 + return selectList(new LambdaQueryWrapperX<AddressDO>().eq(AddressDO::getUserId, userId)
  19 + .eqIfPresent(AddressDO::getDefaulted, defaulted));
62 20 }
63 21  
64 22 }
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java
1 1 package cn.iocoder.yudao.module.member.service.address;
2 2  
3   -import java.util.*;
4   -import javax.validation.*;
5   -import cn.iocoder.yudao.module.member.controller.app.address.vo.*;
  3 +import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressCreateReqVO;
  4 +import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressUpdateReqVO;
6 5 import cn.iocoder.yudao.module.member.dal.dataobject.address.AddressDO;
7   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +
  7 +import javax.validation.Valid;
  8 +import java.util.List;
8 9  
9 10 /**
10 11 * 用户收件地址 Service 接口
... ... @@ -55,5 +56,12 @@ public interface AddressService {
55 56 */
56 57 List<AddressDO> getAddressList(Long userId);
57 58  
  59 + /**
  60 + * 获得用户默认的收件地址
  61 + *
  62 + * @param userId 用户编号
  63 + * @return 用户收件地址
  64 + */
58 65 AddressDO getDefaultUserAddress(Long userId);
  66 +
59 67 }
... ...
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java
1 1 package cn.iocoder.yudao.module.member.service.address;
2 2  
3   -import cn.iocoder.yudao.module.member.enums.AddressTypeEnum;
4   -import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
  3 +import cn.hutool.core.collection.CollUtil;
  4 +import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressCreateReqVO;
  5 +import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressUpdateReqVO;
  6 +import cn.iocoder.yudao.module.member.convert.address.AddressConvert;
  7 +import cn.iocoder.yudao.module.member.dal.dataobject.address.AddressDO;
  8 +import cn.iocoder.yudao.module.member.dal.mysql.address.AddressMapper;
5 9 import org.springframework.stereotype.Service;
6   -
7   -import javax.annotation.Resource;
8   -
9 10 import org.springframework.transaction.annotation.Transactional;
10 11 import org.springframework.validation.annotation.Validated;
11 12  
12   -import java.util.*;
13   -import cn.iocoder.yudao.module.member.controller.app.address.vo.*;
14   -import cn.iocoder.yudao.module.member.dal.dataobject.address.AddressDO;
15   -
16   -import cn.iocoder.yudao.module.member.convert.address.AddressConvert;
17   -import cn.iocoder.yudao.module.member.dal.mysql.address.AddressMapper;
  13 +import javax.annotation.Resource;
  14 +import java.util.List;
18 15  
19 16 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
20   -import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*;
  17 +import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.ADDRESS_NOT_EXISTS;
21 18  
22 19 /**
23 20 * 用户收件地址 Service 实现类
... ... @@ -35,18 +32,11 @@ public class AddressServiceImpl implements AddressService {
35 32 @Transactional(rollbackFor = Exception.class)
36 33 public Long createAddress(Long userId, AppAddressCreateReqVO createReqVO) {
37 34 // 如果添加的是默认收件地址,则将原默认地址修改为非默认
38   - if (AddressTypeEnum.DEFAULT.getType().equals(createReqVO.getType())) {
39   - //查询到一个,然后进行 update
40   - List<AddressDO> addressDOs = selectListByUserIdAndType(userId, AddressTypeEnum.DEFAULT.getType());
41   - AddressDO defaultUserAddress = addressMapper.getDefaultUserAddress(userId);
42   - if (!CollectionUtils.isEmpty(addressDOs)) {
43   - addressDOs.forEach(userAddressDO -> addressMapper.updateById(new AddressDO()
44   - .setId(userAddressDO.getId()).setType(AddressTypeEnum.NORMAL.getType())));
45   - }
46   - Optional.ofNullable(defaultUserAddress)
47   - //更新为非默认
48   - .ifPresent( u -> addressMapper.updateTypeById(u.getId(), AddressTypeEnum.NORMAL));
  35 + if (Boolean.TRUE.equals(createReqVO.getDefaulted())) {
  36 + List<AddressDO> addresses = addressMapper.selectListByUserIdAndDefaulted(userId, true);
  37 + addresses.forEach(address -> addressMapper.updateById(new AddressDO().setId(address.getId()).setDefaulted(false)));
49 38 }
  39 +
50 40 // 插入
51 41 AddressDO address = AddressConvert.INSTANCE.convert(createReqVO);
52 42 address.setUserId(userId);
... ... @@ -59,17 +49,15 @@ public class AddressServiceImpl implements AddressService {
59 49 @Transactional(rollbackFor = Exception.class)
60 50 public void updateAddress(Long userId, AppAddressUpdateReqVO updateReqVO) {
61 51 // 校验存在,校验是否能够操作
62   - check(userId, updateReqVO.getId());
  52 + validAddressExists(userId, updateReqVO.getId());
  53 +
63 54 // 如果修改的是默认收件地址,则将原默认地址修改为非默认
64   - if (AddressTypeEnum.DEFAULT.getType().equals(updateReqVO.getType())) {
65   - //获取默认地址
66   - AddressDO defaultUserAddress = addressMapper.getDefaultUserAddress(userId);
67   - Optional.ofNullable(defaultUserAddress)
68   - //排除当前地址
69   - .filter(u -> !u.getId().equals(updateReqVO.getId()))
70   - //更新为非默认
71   - .ifPresent( u -> addressMapper.updateTypeById(u.getId(), AddressTypeEnum.NORMAL));
  55 + if (Boolean.TRUE.equals(updateReqVO.getDefaulted())) {
  56 + List<AddressDO> addresses = addressMapper.selectListByUserIdAndDefaulted(userId, true);
  57 + addresses.stream().filter(u -> !u.getId().equals(updateReqVO.getId())) // 排除自己
  58 + .forEach(address -> addressMapper.updateById(new AddressDO().setId(address.getId()).setDefaulted(false)));
72 59 }
  60 +
73 61 // 更新
74 62 AddressDO updateObj = AddressConvert.INSTANCE.convert(updateReqVO);
75 63 addressMapper.updateById(updateObj);
... ... @@ -78,56 +66,32 @@ public class AddressServiceImpl implements AddressService {
78 66 @Override
79 67 public void deleteAddress(Long userId, Long id) {
80 68 // 校验存在,校验是否能够操作
81   - check(userId, id);
  69 + validAddressExists(userId, id);
82 70 // 删除
83 71 addressMapper.deleteById(id);
84 72 }
85 73  
86   - /**
87   - * 校验用户收件地址是不是属于该用户
88   - *
89   - * @param userId 用户编号
90   - * @param userAddressId 用户收件地址
91   - */
92   - private void check(Long userId, Long userAddressId) {
93   - AddressDO addressDO = getAddress(userId, userAddressId);
94   - if(null == addressDO){
  74 + private void validAddressExists(Long userId, Long id) {
  75 + AddressDO addressDO = getAddress(userId, id);
  76 + if (addressDO == null) {
95 77 throw exception(ADDRESS_NOT_EXISTS);
96 78 }
97   - if (!addressDO.getUserId().equals(userId)) {
98   - throw exception(ADDRESS_FORBIDDEN);
99   - }
100 79 }
101 80  
102 81 @Override
103 82 public AddressDO getAddress(Long userId, Long id) {
104   - return addressMapper.getAddressByIdAndUserId(userId, id);
  83 + return addressMapper.selectByIdAndUserId(id, userId);
105 84 }
106 85  
107 86 @Override
108 87 public List<AddressDO> getAddressList(Long userId) {
109   - return selectListByUserIdAndType(userId, null);
  88 + return addressMapper.selectListByUserIdAndDefaulted(userId, null);
110 89 }
111 90  
112   - /**
113   - * 获取默认地址
114   - * @param userId
115   - * @return
116   - */
117 91 @Override
118 92 public AddressDO getDefaultUserAddress(Long userId) {
119   - return addressMapper.getDefaultUserAddress(userId);
120   - }
121   -
122   - /**
123   - * 根据类型获取地址列表
124   - * @param userId
125   - * @param type null则查询全部
126   - * @return
127   - */
128   - public List<AddressDO> selectListByUserIdAndType(Long userId, Integer type) {
129   - return addressMapper.selectListByUserIdAndType(userId, type);
  93 + List<AddressDO> addresses = addressMapper.selectListByUserIdAndDefaulted(userId, true);
  94 + return CollUtil.getFirst(addresses);
130 95 }
131 96  
132   -
133 97 }
... ...
yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImplTest.java
... ... @@ -5,20 +5,18 @@ import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressCreate
5 5 import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressUpdateReqVO;
6 6 import cn.iocoder.yudao.module.member.dal.dataobject.address.AddressDO;
7 7 import cn.iocoder.yudao.module.member.dal.mysql.address.AddressMapper;
8   -import org.junit.jupiter.api.Disabled;
9 8 import org.junit.jupiter.api.Test;
10 9 import org.springframework.context.annotation.Import;
11 10  
12 11 import javax.annotation.Resource;
13 12  
14   -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
15   -import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
16 13 import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
17 14 import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
18 15 import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
19 16 import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
20 17 import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.ADDRESS_NOT_EXISTS;
21   -import static org.junit.jupiter.api.Assertions.*;
  18 +import static org.junit.jupiter.api.Assertions.assertNotNull;
  19 +import static org.junit.jupiter.api.Assertions.assertNull;
22 20  
23 21 /**
24 22 * {@link AddressServiceImpl} 的单元测试类
... ... @@ -40,7 +38,7 @@ public class AddressServiceImplTest extends BaseDbUnitTest {
40 38 AppAddressCreateReqVO reqVO = randomPojo(AppAddressCreateReqVO.class);
41 39  
42 40 // 调用
43   - Long addressId = addressService.createAddress(getLoginUserId(), reqVO);
  41 + Long addressId = addressService.createAddress(randomLongId(), reqVO);
44 42 // 断言
45 43 assertNotNull(addressId);
46 44 // 校验记录的属性是否正确
... ... @@ -59,7 +57,7 @@ public class AddressServiceImplTest extends BaseDbUnitTest {
59 57 });
60 58  
61 59 // 调用
62   - addressService.updateAddress(getLoginUserId(), reqVO);
  60 + addressService.updateAddress(dbAddress.getUserId(), reqVO);
63 61 // 校验是否更新正确
64 62 AddressDO address = addressMapper.selectById(reqVO.getId()); // 获取最新的
65 63 assertPojoEquals(reqVO, address);
... ... @@ -71,7 +69,7 @@ public class AddressServiceImplTest extends BaseDbUnitTest {
71 69 AppAddressUpdateReqVO reqVO = randomPojo(AppAddressUpdateReqVO.class);
72 70  
73 71 // 调用, 并断言异常
74   - assertServiceException(() -> addressService.updateAddress(getLoginUserId(), reqVO), ADDRESS_NOT_EXISTS);
  72 + assertServiceException(() -> addressService.updateAddress(randomLongId(), reqVO), ADDRESS_NOT_EXISTS);
75 73 }
76 74  
77 75 @Test
... ... @@ -83,7 +81,7 @@ public class AddressServiceImplTest extends BaseDbUnitTest {
83 81 Long id = dbAddress.getId();
84 82  
85 83 // 调用
86   - addressService.deleteAddress(getLoginUserId(), id);
  84 + addressService.deleteAddress(dbAddress.getUserId(), id);
87 85 // 校验数据不存在了
88 86 assertNull(addressMapper.selectById(id));
89 87 }
... ... @@ -94,67 +92,7 @@ public class AddressServiceImplTest extends BaseDbUnitTest {
94 92 Long id = randomLongId();
95 93  
96 94 // 调用, 并断言异常
97   - assertServiceException(() -> addressService.deleteAddress(getLoginUserId(), id), ADDRESS_NOT_EXISTS);
98   - }
99   -
100   - @Test
101   - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
102   - public void ins() {
103   - // mock 数据
104   - AddressDO dbAddress = randomPojo(AddressDO.class, o -> { // 等会查询到
105   - o.setUserId(null);
106   - o.setName(null);
107   - o.setMobile(null);
108   - o.setAreaCode(null);
109   - o.setDetailAddress(null);
110   - o.setType(null);
111   - o.setCreateTime(null);
112   - });
113   - addressMapper.insert(dbAddress);
114   - // 测试 userId 不匹配
115   - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setUserId(null)));
116   - // 测试 name 不匹配
117   - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setName(null)));
118   - // 测试 mobile 不匹配
119   - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setMobile(null)));
120   - // 测试 areaCode 不匹配
121   - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setAreaCode(null)));
122   - // 测试 detailAddress 不匹配
123   - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setDetailAddress(null)));
124   - // 测试 type 不匹配
125   - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setType(null)));
126   - // 测试 createTime 不匹配
127   - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setCreateTime(null)));
128   - }
129   -
130   - @Test
131   - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
132   - public void testGetAddressList() {
133   - // mock 数据
134   - AddressDO dbAddress = randomPojo(AddressDO.class, o -> { // 等会查询到
135   - o.setUserId(null);
136   - o.setName(null);
137   - o.setMobile(null);
138   - o.setAreaCode(null);
139   - o.setDetailAddress(null);
140   - o.setType(null);
141   - o.setCreateTime(null);
142   - });
143   - addressMapper.insert(dbAddress);
144   - // 测试 userId 不匹配
145   - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setUserId(null)));
146   - // 测试 name 不匹配
147   - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setName(null)));
148   - // 测试 mobile 不匹配
149   - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setMobile(null)));
150   - // 测试 areaCode 不匹配
151   - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setAreaCode(null)));
152   - // 测试 detailAddress 不匹配
153   - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setDetailAddress(null)));
154   - // 测试 type 不匹配
155   - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setType(null)));
156   - // 测试 createTime 不匹配
157   - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setCreateTime(null)));
  95 + assertServiceException(() -> addressService.deleteAddress(randomLongId(), id), ADDRESS_NOT_EXISTS);
158 96 }
159 97  
160 98 }
... ...
yudao-module-member/yudao-module-member-biz/src/test/resources/sql/create_tables.sql
... ... @@ -35,15 +35,15 @@ CREATE TABLE IF NOT EXISTS &quot;member_address&quot; (
35 35 "user_id" bigint(20) NOT NULL,
36 36 "name" varchar(10) NOT NULL,
37 37 "mobile" varchar(20) NOT NULL,
38   - "area_code" int(11) NOT NULL,
  38 + "area_id" bigint(20) NOT NULL,
  39 + "post_code" varchar(16) NOT NULL,
39 40 "detail_address" varchar(250) NOT NULL,
40   - "type" tinyint(4) NOT NULL,
  41 + "defaulted" bit NOT NULL,
41 42 "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
42 43 "creator" varchar(64) DEFAULT '',
43 44 "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
44 45 "deleted" bit NOT NULL DEFAULT FALSE,
45 46 "updater" varchar(64) DEFAULT '',
46   - "tenant_id" bigint(20) NOT NULL,
47 47 PRIMARY KEY ("id")
48   - ) COMMENT '用户收件地址';
  48 +) COMMENT '用户收件地址';
49 49  
... ...