diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/ProductSkuController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/ProductSkuController.java index 132d68d94..ef6d8fcac 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/ProductSkuController.java +++ b/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; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*; +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuPageReqVO; +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuUpdateReqVO; import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; @@ -16,14 +17,11 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; -import java.io.IOException; import java.util.Collection; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; @Api(tags = "管理后台 - 商品 sku") @RestController @@ -84,16 +82,4 @@ public class ProductSkuController { return success(ProductSkuConvert.INSTANCE.convertPage(pageResult)); } - @GetMapping("/export-excel") - @ApiOperation("导出商品sku Excel") - @PreAuthorize("@ss.hasPermission('product:sku:export')") - @OperateLog(type = EXPORT) - public void exportSkuExcel(@Valid ProductSkuExportReqVO exportReqVO, - HttpServletResponse response) throws IOException { - List list = ProductSkuService.getSkuList(exportReqVO); - // 导出 Excel - List datas = ProductSkuConvert.INSTANCE.convertList02(list); - ExcelUtils.write(response, "商品sku.xls", "数据", ProductSkuExcelVO.class, datas); - } - } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java index 71bfa82bd..cfe393caf 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java +++ b/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; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuCreateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuPageReqVO; +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuRespVO; +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuUpdateReqVO; import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; @@ -16,14 +17,11 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; -import java.io.IOException; import java.util.Collection; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; @Api(tags = "管理后台 - 商品spu") @RestController @@ -83,16 +81,4 @@ public class ProductSpuController { return success(spuService.getSpuPage(pageVO)); } - @GetMapping("/export-excel") - @ApiOperation("导出商品spu Excel") - @PreAuthorize("@ss.hasPermission('product:spu:export')") - @OperateLog(type = EXPORT) - public void exportSpuExcel(@Valid SpuExportReqVO exportReqVO, - HttpServletResponse response) throws IOException { - List list = spuService.getSpuList(exportReqVO); - // 导出 Excel - List datas = ProductSpuConvert.INSTANCE.convertList02(list); - ExcelUtils.write(response, "商品spu.xls", "数据", SpuExcelVO.class, datas); - } - } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuBaseVO.java index 65a5f2a0e..e9c76805a 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuBaseVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuBaseVO.java @@ -1,9 +1,10 @@ package cn.iocoder.yudao.module.product.controller.admin.spu.vo; -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; -import javax.validation.constraints.*; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; +import java.util.List; /** * 商品spu Base VO,提供给添加、修改、详细的子 VO 使用 @@ -45,6 +46,6 @@ public class ProductSpuBaseVO { private Integer quantity; @ApiModelProperty(value = "上下架状态: 0 上架(开启) 1 下架(禁用)") - private Boolean status; + private Integer status; } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuExcelVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuExcelVO.java deleted file mode 100755 index 9e90acd3d..000000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuExcelVO.java +++ /dev/null @@ -1,53 +0,0 @@ -package cn.iocoder.yudao.module.product.controller.admin.spu.vo; - -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; - -import com.alibaba.excel.annotation.ExcelProperty; - -/** - * 商品spu Excel VO - * - * @author 芋道源码 - */ -@Data -public class SpuExcelVO { - - @ExcelProperty("主键") - private Integer id; - - @ExcelProperty("商品名称") - private String name; - - @ExcelProperty("卖点") - private String sellPoint; - - @ExcelProperty("描述") - private String description; - - @ExcelProperty("分类id") - private Long categoryId; - - @ExcelProperty("商品主图地址,* 数组,以逗号分隔,最多上传15张") - private List picUrls; - - @ExcelProperty("排序字段") - private Integer sort; - - @ExcelProperty("点赞初始人数") - private Integer likeCount; - - @ExcelProperty("价格 单位使用:分") - private Integer price; - - @ExcelProperty("库存数量") - private Integer quantity; - - @ExcelProperty("上下架状态: 0 上架(开启) 1 下架(禁用)") - private Boolean status; - - @ExcelProperty("创建时间") - private Date createTime; - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuExportReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuExportReqVO.java deleted file mode 100755 index 29a3086a2..000000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuExportReqVO.java +++ /dev/null @@ -1,49 +0,0 @@ -package cn.iocoder.yudao.module.product.controller.admin.spu.vo; - -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import org.springframework.format.annotation.DateTimeFormat; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@ApiModel(value = "管理后台 - 商品spu Excel 导出 Request VO", description = "参数和 SpuPageReqVO 是一致的") -@Data -public class SpuExportReqVO { - - @ApiModelProperty(value = "商品名称") - private String name; - - @ApiModelProperty(value = "卖点") - private String sellPoint; - - @ApiModelProperty(value = "描述") - private String description; - - @ApiModelProperty(value = "分类id") - private Long categoryId; - - @ApiModelProperty(value = "商品主图地址,* 数组,以逗号分隔,最多上传15张") - private List picUrls; - - @ApiModelProperty(value = "排序字段") - private Integer sort; - - @ApiModelProperty(value = "点赞初始人数") - private Integer likeCount; - - @ApiModelProperty(value = "价格 单位使用:分") - private Integer price; - - @ApiModelProperty(value = "库存数量") - private Integer quantity; - - @ApiModelProperty(value = "上下架状态: 0 上架(开启) 1 下架(禁用)") - private Boolean status; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @ApiModelProperty(value = "创建时间") - private Date[] createTime; - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppSpuPageRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppSpuPageRespVO.java index 0f77fd516..c0a0f0eb8 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppSpuPageRespVO.java +++ b/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 { private Integer quantity; @ApiModelProperty(value = "上下架状态: 0 上架(开启) 1 下架(禁用)") - private Boolean status; + private Integer status; } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/sku/ProductSkuConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/sku/ProductSkuConvert.java index 2f6bda8bb..e11f4785f 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/sku/ProductSkuConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/sku/ProductSkuConvert.java @@ -1,16 +1,16 @@ package cn.iocoder.yudao.module.product.convert.sku; -import java.util.*; - -import cn.hutool.json.JSONUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; - +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuExcelVO; +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuUpdateReqVO; +import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.mapstruct.Named; import org.mapstruct.factory.Mappers; -import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*; -import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; + +import java.util.List; /** * 商品sku Convert @@ -22,18 +22,13 @@ public interface ProductSkuConvert { ProductSkuConvert INSTANCE = Mappers.getMapper(ProductSkuConvert.class); - @Mapping(source = "properties", target = "properties", qualifiedByName = "translateStringFromList") ProductSkuDO convert(ProductSkuCreateReqVO bean); - @Mapping(source = "properties", target = "properties", qualifiedByName = "translateStringFromList") ProductSkuDO convert(ProductSkuUpdateReqVO bean); - @Mapping(source = "properties", target = "properties", qualifiedByName = "tokenizeToBeanArray") + @Mapping(source = "properties", target = "properties") ProductSkuRespVO convert(ProductSkuDO bean); - @Mapping(source = "properties", target = "properties", qualifiedByName = "tokenizeToExcelBeanArray") - ProductSkuExcelVO convertToExcelVO(ProductSkuDO bean); - List convertList(List list); List convertSkuDOList(List list); @@ -42,18 +37,4 @@ public interface ProductSkuConvert { List convertList02(List list); - @Named("tokenizeToBeanArray") - default List translatePropertyArrayFromString(String properties) { - return JSONUtil.toList(properties, ProductSkuBaseVO.Property.class); - } - - @Named("tokenizeToExcelBeanArray") - default List translateExcelPropertyArrayFromString(String properties) { - return JSONUtil.toList(properties, ProductSkuExcelVO.Property.class); - } - - @Named("translateStringFromList") - default String translatePropertyStringFromList(List properties) { - return JSONUtil.toJsonStr(properties); - } } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java index 30bc4a0fe..e267ba185 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java +++ b/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 { PageResult convertPage(PageResult page); - List convertList02(List list); - SpuPageReqVO convert(AppSpuPageReqVO bean); AppSpuPageRespVO convertAppResp(ProductSpuDO list); diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/sku/ProductSkuMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/sku/ProductSkuMapper.java index 2f2ced33c..756636687 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/sku/ProductSkuMapper.java +++ b/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; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuExportReqVO; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuPageReqVO; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import org.apache.ibatis.annotations.Mapper; @@ -24,7 +23,7 @@ public interface ProductSkuMapper extends BaseMapperX { .eqIfPresent(ProductSkuDO::getProperties, reqVO.getProperties()) .eqIfPresent(ProductSkuDO::getPrice, reqVO.getPrice()) .eqIfPresent(ProductSkuDO::getOriginalPrice, reqVO.getOriginalPrice()) - .eqIfPresent(ProductSkuDO::getCostPrice, reqVO.getCostPrice()) +// .eqIfPresent(ProductSkuDO::getCostPrice, reqVO.getCostPrice()) .eqIfPresent(ProductSkuDO::getBarCode, reqVO.getBarCode()) .eqIfPresent(ProductSkuDO::getPicUrl, reqVO.getPicUrl()) .eqIfPresent(ProductSkuDO::getStatus, reqVO.getStatus()) @@ -32,19 +31,6 @@ public interface ProductSkuMapper extends BaseMapperX { .orderByDesc(ProductSkuDO::getId)); } - default List selectList(ProductSkuExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .eqIfPresent(ProductSkuDO::getSpuId, reqVO.getSpuId()) - .eqIfPresent(ProductSkuDO::getProperties, reqVO.getProperties()) - .eqIfPresent(ProductSkuDO::getPrice, reqVO.getPrice()) - .eqIfPresent(ProductSkuDO::getOriginalPrice, reqVO.getOriginalPrice()) - .eqIfPresent(ProductSkuDO::getCostPrice, reqVO.getCostPrice()) - .eqIfPresent(ProductSkuDO::getBarCode, reqVO.getBarCode()) - .eqIfPresent(ProductSkuDO::getPicUrl, reqVO.getPicUrl()) - .eqIfPresent(ProductSkuDO::getStatus, reqVO.getStatus()) - .betweenIfPresent(ProductSkuDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(ProductSkuDO::getId)); - } // TODO @franky:方法名 selectList; 可以直接调用 selectList default List selectBySpuIds(List spuIds) { diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/spu/ProductSpuMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/spu/ProductSpuMapper.java index 72fb68b29..7487dd60c 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/spu/ProductSpuMapper.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/spu/ProductSpuMapper.java @@ -1,13 +1,11 @@ package cn.iocoder.yudao.module.product.dal.mysql.spu; -import java.util.*; - import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuPageReqVO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; import org.apache.ibatis.annotations.Mapper; -import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; /** * 商品spu Mapper @@ -25,25 +23,9 @@ public interface ProductSpuMapper extends BaseMapperX { .eqIfPresent(ProductSpuDO::getCategoryId, reqVO.getCategoryId()) .eqIfPresent(ProductSpuDO::getPicUrls, reqVO.getPicUrls()) .eqIfPresent(ProductSpuDO::getSort, reqVO.getSort()) - .eqIfPresent(ProductSpuDO::getLikeCount, reqVO.getLikeCount()) +// .eqIfPresent(ProductSpuDO::getLikeCount, reqVO.getLikeCount()) .eqIfPresent(ProductSpuDO::getPrice, reqVO.getPrice()) - .eqIfPresent(ProductSpuDO::getQuantity, reqVO.getQuantity()) - .eqIfPresent(ProductSpuDO::getStatus, reqVO.getStatus()) - .betweenIfPresent(ProductSpuDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(ProductSpuDO::getId)); - } - - default List selectList(SpuExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .likeIfPresent(ProductSpuDO::getName, reqVO.getName()) - .eqIfPresent(ProductSpuDO::getSellPoint, reqVO.getSellPoint()) - .eqIfPresent(ProductSpuDO::getDescription, reqVO.getDescription()) - .eqIfPresent(ProductSpuDO::getCategoryId, reqVO.getCategoryId()) - .eqIfPresent(ProductSpuDO::getPicUrls, reqVO.getPicUrls()) - .eqIfPresent(ProductSpuDO::getSort, reqVO.getSort()) - .eqIfPresent(ProductSpuDO::getLikeCount, reqVO.getLikeCount()) - .eqIfPresent(ProductSpuDO::getPrice, reqVO.getPrice()) - .eqIfPresent(ProductSpuDO::getQuantity, reqVO.getQuantity()) +// .eqIfPresent(ProductSpuDO::getQuantity, reqVO.getQuantity()) .eqIfPresent(ProductSpuDO::getStatus, reqVO.getStatus()) .betweenIfPresent(ProductSpuDO::getCreateTime, reqVO.getCreateTime()) .orderByDesc(ProductSpuDO::getId)); diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java index 0396506ef..1f5f191e1 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java @@ -64,14 +64,6 @@ public interface ProductSkuService { */ PageResult getSkuPage(ProductSkuPageReqVO pageReqVO); - /** - * 获得商品sku列表, 用于 Excel 导出 - * - * @param exportReqVO 查询条件 - * @return 商品sku列表 - */ - List getSkuList(ProductSkuExportReqVO exportReqVO); - /** * 对 sku 的组合的属性等进行合法性校验 * diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java index 91a60929b..d15aa5c47 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java +++ b/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 { return productSkuMapper.selectPage(pageReqVO); } - @Override - public List getSkuList(ProductSkuExportReqVO exportReqVO) { - return productSkuMapper.selectList(exportReqVO); - } - // TODO @franky:这个方法,貌似实现的还是有点问题哈。例如说,throw 异常,后面还执行逻辑~ // TODO @艿艿 咳咳,throw 那里我是偷懒省略了{},哈哈,我加上,然后我调试下,在优化下 @Override diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java index e66f93fd0..1cf9b79d4 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java @@ -1,12 +1,17 @@ package cn.iocoder.yudao.module.product.service.spu; -import java.util.*; -import javax.validation.*; -import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuCreateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuPageReqVO; +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuRespVO; +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuUpdateReqVO; import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageReqVO; import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageRespVO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; -import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import javax.validation.Valid; +import java.util.Collection; +import java.util.List; /** * 商品spu Service 接口 @@ -61,14 +66,6 @@ public interface ProductSpuService { */ PageResult getSpuPage(SpuPageReqVO pageReqVO); - /** - * 获得商品spu列表, 用于 Excel 导出 - * - * @param exportReqVO 查询条件 - * @return 商品spu列表 - */ - List getSpuList(SpuExportReqVO exportReqVO); - /** * 获得商品spu分页 * diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java index ea4afb2e7..49847f720 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java @@ -171,11 +171,6 @@ public class ProductSpuServiceImpl implements ProductSpuService { return spuVOs; } - @Override - public List getSpuList(SpuExportReqVO exportReqVO) { - return ProductSpuMapper.selectList(exportReqVO); - } - @Override public PageResult getSpuPage(AppSpuPageReqVO pageReqVO) { PageResult productSpuDOPageResult = ProductSpuMapper.selectPage(ProductSpuConvert.INSTANCE.convert(pageReqVO)); diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/sku/SkuServiceImplTest.java b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/sku/SkuServiceImplTest.java index 27d5e140b..8cd086e81 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/sku/SkuServiceImplTest.java +++ b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/sku/SkuServiceImplTest.java @@ -1,24 +1,23 @@ package cn.iocoder.yudao.module.product.service.sku; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuPageReqVO; +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuUpdateReqVO; +import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; +import cn.iocoder.yudao.module.product.dal.mysql.sku.ProductSkuMapper; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; import javax.annotation.Resource; -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; - -import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*; -import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; -import cn.iocoder.yudao.module.product.dal.mysql.sku.ProductSkuMapper; -import cn.iocoder.yudao.framework.common.pojo.PageResult; - -import org.springframework.context.annotation.Import; -import java.util.*; - -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS; import static org.junit.jupiter.api.Assertions.*; /** @@ -107,7 +106,7 @@ public class SkuServiceImplTest extends BaseDbUnitTest { o.setProperties(null); o.setPrice(null); o.setOriginalPrice(null); - o.setCostPrice(null); +// o.setCostPrice(null); o.setBarCode(null); o.setPicUrl(null); o.setStatus(null); @@ -123,7 +122,7 @@ public class SkuServiceImplTest extends BaseDbUnitTest { // 测试 originalPrice 不匹配 ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setOriginalPrice(null))); // 测试 costPrice 不匹配 - ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCostPrice(null))); +// ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCostPrice(null))); // 测试 barCode 不匹配 ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setBarCode(null))); // 测试 picUrl 不匹配 @@ -152,57 +151,4 @@ public class SkuServiceImplTest extends BaseDbUnitTest { assertPojoEquals(dbSku, pageResult.getList().get(0)); } - @Test - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 - public void testGetSkuList() { - // mock 数据 - ProductSkuDO dbSku = randomPojo(ProductSkuDO.class, o -> { // 等会查询到 - o.setSpuId(null); - o.setProperties(null); - o.setPrice(null); - o.setOriginalPrice(null); - o.setCostPrice(null); - o.setBarCode(null); - o.setPicUrl(null); - o.setStatus(null); - o.setCreateTime(null); - }); - ProductSkuMapper.insert(dbSku); - // 测试 spuId 不匹配 - ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setSpuId(null))); - // 测试 properties 不匹配 - ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setProperties(null))); - // 测试 price 不匹配 - ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setPrice(null))); - // 测试 originalPrice 不匹配 - ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setOriginalPrice(null))); - // 测试 costPrice 不匹配 - ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCostPrice(null))); - // 测试 barCode 不匹配 - ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setBarCode(null))); - // 测试 picUrl 不匹配 - ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setPicUrl(null))); - // 测试 status 不匹配 - ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setStatus(null))); - // 测试 createTime 不匹配 - ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCreateTime(null))); - // 准备参数 - ProductSkuExportReqVO reqVO = new ProductSkuExportReqVO(); - reqVO.setSpuId(null); - reqVO.setProperties(null); - reqVO.setPrice(null); - reqVO.setOriginalPrice(null); - reqVO.setCostPrice(null); - reqVO.setBarCode(null); - reqVO.setPicUrl(null); - reqVO.setStatus(null); - reqVO.setCreateTime(null); - - // 调用 - List list = ProductSkuService.getSkuList(reqVO); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbSku, list.get(0)); - } - } diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImplTest.java b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImplTest.java index fae41788f..ef2372ac9 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImplTest.java +++ b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImplTest.java @@ -1,30 +1,25 @@ package cn.iocoder.yudao.module.product.service.spu; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.mock.mockito.MockBean; - -import javax.annotation.Resource; - +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; - -import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuCreateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuPageReqVO; +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuRespVO; +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuUpdateReqVO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper; -import cn.iocoder.yudao.framework.common.pojo.PageResult; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; import javax.annotation.Resource; -import org.springframework.context.annotation.Import; -import java.util.*; -import static cn.hutool.core.util.RandomUtil.*; -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; /** * {@link ProductSpuServiceImpl} 的单元测试类 @@ -114,9 +109,9 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest { o.setCategoryId(null); o.setPicUrls(null); o.setSort(null); - o.setLikeCount(null); +// o.setLikeCount(null); o.setPrice(null); - o.setQuantity(null); +// o.setQuantity(null); o.setStatus(null); o.setCreateTime(null); }); @@ -134,11 +129,11 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest { // 测试 sort 不匹配 ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setSort(null))); // 测试 likeCount 不匹配 - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setLikeCount(null))); +// ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setLikeCount(null))); // 测试 price 不匹配 ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setPrice(null))); // 测试 quantity 不匹配 - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setQuantity(null))); +// ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setQuantity(null))); // 测试 status 不匹配 ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setStatus(null))); // 测试 createTime 不匹配 @@ -165,65 +160,4 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest { assertPojoEquals(dbSpu, pageResult.getList().get(0)); } - @Test - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 - public void testGetSpuList() { - // mock 数据 - ProductSpuDO dbSpu = randomPojo(ProductSpuDO.class, o -> { // 等会查询到 - o.setName(null); - o.setSellPoint(null); - o.setDescription(null); - o.setCategoryId(null); - o.setPicUrls(null); - o.setSort(null); - o.setLikeCount(null); - o.setPrice(null); - o.setQuantity(null); - o.setStatus(null); - o.setCreateTime(null); - }); - ProductSpuMapper.insert(dbSpu); - // 测试 name 不匹配 - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setName(null))); - // 测试 sellPoint 不匹配 - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setSellPoint(null))); - // 测试 description 不匹配 - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setDescription(null))); - // 测试 categoryId 不匹配 - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setCategoryId(null))); - // 测试 picUrls 不匹配 - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setPicUrls(null))); - // 测试 sort 不匹配 - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setSort(null))); - // 测试 likeCount 不匹配 - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setLikeCount(null))); - // 测试 price 不匹配 - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setPrice(null))); - // 测试 quantity 不匹配 - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setQuantity(null))); - // 测试 status 不匹配 - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setStatus(null))); - // 测试 createTime 不匹配 - ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setCreateTime(null))); - // 准备参数 - SpuExportReqVO reqVO = new SpuExportReqVO(); - reqVO.setName(null); - reqVO.setSellPoint(null); - reqVO.setDescription(null); - reqVO.setCategoryId(null); - reqVO.setPicUrls(null); - reqVO.setSort(null); - reqVO.setLikeCount(null); - reqVO.setPrice(null); - reqVO.setQuantity(null); - reqVO.setStatus(null); - reqVO.setCreateTime(null); - - // 调用 - List list = spuService.getSpuList(reqVO); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbSpu, list.get(0)); - } - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/cart/CartItemDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/cart/CartItemDO.java index 7f49a968e..2eed29cf9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/cart/CartItemDO.java +++ b/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 { // * 商品营销活动类型 // */ // private Integer activityType; + // TODO 芋艿:combination_id 拼团 ID + // TODO 芋艿:seckill_id 秒杀产品 ID + // TODO 芋艿:bargain_id 砍价 ID // ========= 优惠信息 END ========= - // TODO 芋艿:distribution_card_no + // TODO 芋艿:distribution_card_no 推广员 + // TODO 芋艿:is_pay 未购买、已购买 + // TODO 芋艿:is_new 是否立即购买 } diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java index 2fbb61c8b..1e77db1c8 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java +++ b/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 { // ========== 用户收件地址 1004004000 ========== ErrorCode ADDRESS_NOT_EXISTS = new ErrorCode(1004004000, "用户收件地址不存在"); - ErrorCode ADDRESS_FORBIDDEN = new ErrorCode(1004004001, "没有该操作权限"); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/AppAddressController.http b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/AppAddressController.http index 7f943448a..6bae7c7eb 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/AppAddressController.http +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/AppAddressController.http @@ -2,53 +2,53 @@ POST {{appApi}}//member/address/create Content-Type: application/json tenant-id: {{appTenentId}} -Authorization: Bearer 2510e2e4287346eb8e36353a55e27fd6 +Authorization: Bearer {{appToken}} { - "userId": "245", "name": "yunai", "mobile": "15601691300", - "areaCode": "610632", + "areaId": "610632", + "postCode": "200000", "detailAddress": "芋道源码 233 号 666 室", - "type": "1" + "defaulted": true } ### 请求 /update 接口 => 成功 PUT {{appApi}}//member/address/update Content-Type: application/json tenant-id: {{appTenentId}} -Authorization: Bearer 2510e2e4287346eb8e36353a55e27fd6 +Authorization: Bearer {{appToken}} { "id": "1", - "userId": "245", "name": "yunai888", "mobile": "15601691300", - "areaCode": "610632", + "areaId": "610632", + "postCode": "200000", "detailAddress": "芋道源码 233 号 666 室", - "type": "1" + "defaulted": false } ### 请求 /delete 接口 => 成功 DELETE {{appApi}}//member/address/delete?id=2 Content-Type: application/json tenant-id: {{appTenentId}} -Authorization: Bearer fa4848b001de4eae9faf516c0c8520f8 +Authorization: Bearer {{appToken}} ### 请求 /get 接口 => 成功 GET {{appApi}}//member/address/get?id=1 Content-Type: application/json tenant-id: {{appTenentId}} -Authorization: Bearer fa4848b001de4eae9faf516c0c8520f8 +Authorization: Bearer {{appToken}} ### 请求 /get-default 接口 => 成功 GET {{appApi}}//member/address/get-default Content-Type: application/json tenant-id: {{appTenentId}} -Authorization: Bearer fa4848b001de4eae9faf516c0c8520f8 +Authorization: Bearer {{appToken}} ### 请求 /list 接口 => 成功 GET {{appApi}}//member/address/list Content-Type: application/json tenant-id: {{appTenentId}} -Authorization: Bearer fa4848b001de4eae9faf516c0c8520f8 \ No newline at end of file +Authorization: Bearer {{appToken}} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressBaseVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressBaseVO.java index 81231a881..8cfbac7d2 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressBaseVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressBaseVO.java @@ -1,10 +1,10 @@ package cn.iocoder.yudao.module.member.controller.app.address.vo; -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.member.enums.AddressTypeEnum; -import lombok.*; -import io.swagger.annotations.*; -import javax.validation.constraints.*; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; /** * 用户收件地址 Base VO,提供给添加、修改、详细的子 VO 使用 @@ -21,17 +21,20 @@ public class AppAddressBaseVO { @NotNull(message = "手机号不能为空") private String mobile; - @ApiModelProperty(value = "地区编码", required = true) - @NotNull(message = "地区编码不能为空") - private Integer areaCode; + @ApiModelProperty(value = "地区编号", required = true) + @NotNull(message = "地区编号不能为空") + private Long areaId; + + @ApiModelProperty(value = "邮编", required = true) + @NotEmpty(message = "邮编不能为空") + private String postCode; @ApiModelProperty(value = "收件详细地址", required = true) @NotNull(message = "收件详细地址不能为空") private String detailAddress; - @ApiModelProperty(value = "地址类型", required = true) - @NotNull(message = "地址类型不能为空") - @InEnum(AddressTypeEnum.class) - private Integer type; + @ApiModelProperty(value = "是否默认地址", required = true) + @NotNull(message = "是否默认地址不能为空") + private Boolean defaulted; } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/address/AddressDO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/address/AddressDO.java index d470e8f90..467432460 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/address/AddressDO.java +++ b/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 { /** * 地区编号 */ - private Integer areaId; + private Long areaId; /** * 邮编 */ diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java index fc02e5879..80f78d41f 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java @@ -1,64 +1,22 @@ package cn.iocoder.yudao.module.member.dal.mysql.address; - import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.member.dal.dataobject.address.AddressDO; -import cn.iocoder.yudao.module.member.enums.AddressTypeEnum; import org.apache.ibatis.annotations.Mapper; import java.util.List; -/** - * 用户收件地址 Mapper - * - * @author 芋道源码 - */ @Mapper public interface AddressMapper extends BaseMapperX { - /** - * 获取当前地址 根据id和userId - * @param userId - * @param id - * @return - */ - default AddressDO getAddressByIdAndUserId(Long userId, Long id) { - QueryWrapperX queryWrapperX = new QueryWrapperX<>(); - queryWrapperX.eq("user_id", userId).eq("id", id); - return selectList(queryWrapperX).stream().findFirst().orElse(null); + default AddressDO selectByIdAndUserId(Long id, Long userId) { + return selectOne(AddressDO::getId, id, AddressDO::getUserId, userId); } - /** - * 获取地址列表 - * @param userId - * @param type - * @return - */ - default List selectListByUserIdAndType(Long userId, Integer type) { - QueryWrapperX queryWrapperX = new QueryWrapperX().eq("user_id", userId) - .eqIfPresent("type", type); - return selectList(queryWrapperX); - } - - /** - * 获取默认地址 - * @param userId - * @return - */ - default AddressDO getDefaultUserAddress(Long userId) { - List addressDOList = selectListByUserIdAndType(userId, AddressTypeEnum.DEFAULT.getType()); - return addressDOList.stream().findFirst().orElse(null); - } - - /** - * 获取默认地址 - * @param id - * @param addressTypeEnum - * @return - */ - default int updateTypeById(Long id, AddressTypeEnum addressTypeEnum) { - return updateById(new AddressDO().setId(id).setType(addressTypeEnum.getType())); + default List selectListByUserIdAndDefaulted(Long userId, Boolean defaulted) { + return selectList(new LambdaQueryWrapperX().eq(AddressDO::getUserId, userId) + .eqIfPresent(AddressDO::getDefaulted, defaulted)); } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java index e45b075fe..456a3d8ac 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java @@ -1,10 +1,11 @@ package cn.iocoder.yudao.module.member.service.address; -import java.util.*; -import javax.validation.*; -import cn.iocoder.yudao.module.member.controller.app.address.vo.*; +import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressCreateReqVO; +import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressUpdateReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.address.AddressDO; -import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import javax.validation.Valid; +import java.util.List; /** * 用户收件地址 Service 接口 @@ -55,5 +56,12 @@ public interface AddressService { */ List getAddressList(Long userId); + /** + * 获得用户默认的收件地址 + * + * @param userId 用户编号 + * @return 用户收件地址 + */ AddressDO getDefaultUserAddress(Long userId); + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java index a9cd91d59..bbcbbe592 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java @@ -1,23 +1,20 @@ package cn.iocoder.yudao.module.member.service.address; -import cn.iocoder.yudao.module.member.enums.AddressTypeEnum; -import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressCreateReqVO; +import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressUpdateReqVO; +import cn.iocoder.yudao.module.member.convert.address.AddressConvert; +import cn.iocoder.yudao.module.member.dal.dataobject.address.AddressDO; +import cn.iocoder.yudao.module.member.dal.mysql.address.AddressMapper; import org.springframework.stereotype.Service; - -import javax.annotation.Resource; - import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; -import java.util.*; -import cn.iocoder.yudao.module.member.controller.app.address.vo.*; -import cn.iocoder.yudao.module.member.dal.dataobject.address.AddressDO; - -import cn.iocoder.yudao.module.member.convert.address.AddressConvert; -import cn.iocoder.yudao.module.member.dal.mysql.address.AddressMapper; +import javax.annotation.Resource; +import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*; +import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.ADDRESS_NOT_EXISTS; /** * 用户收件地址 Service 实现类 @@ -35,18 +32,11 @@ public class AddressServiceImpl implements AddressService { @Transactional(rollbackFor = Exception.class) public Long createAddress(Long userId, AppAddressCreateReqVO createReqVO) { // 如果添加的是默认收件地址,则将原默认地址修改为非默认 - if (AddressTypeEnum.DEFAULT.getType().equals(createReqVO.getType())) { - //查询到一个,然后进行 update - List addressDOs = selectListByUserIdAndType(userId, AddressTypeEnum.DEFAULT.getType()); - AddressDO defaultUserAddress = addressMapper.getDefaultUserAddress(userId); - if (!CollectionUtils.isEmpty(addressDOs)) { - addressDOs.forEach(userAddressDO -> addressMapper.updateById(new AddressDO() - .setId(userAddressDO.getId()).setType(AddressTypeEnum.NORMAL.getType()))); - } - Optional.ofNullable(defaultUserAddress) - //更新为非默认 - .ifPresent( u -> addressMapper.updateTypeById(u.getId(), AddressTypeEnum.NORMAL)); + if (Boolean.TRUE.equals(createReqVO.getDefaulted())) { + List addresses = addressMapper.selectListByUserIdAndDefaulted(userId, true); + addresses.forEach(address -> addressMapper.updateById(new AddressDO().setId(address.getId()).setDefaulted(false))); } + // 插入 AddressDO address = AddressConvert.INSTANCE.convert(createReqVO); address.setUserId(userId); @@ -59,17 +49,15 @@ public class AddressServiceImpl implements AddressService { @Transactional(rollbackFor = Exception.class) public void updateAddress(Long userId, AppAddressUpdateReqVO updateReqVO) { // 校验存在,校验是否能够操作 - check(userId, updateReqVO.getId()); + validAddressExists(userId, updateReqVO.getId()); + // 如果修改的是默认收件地址,则将原默认地址修改为非默认 - if (AddressTypeEnum.DEFAULT.getType().equals(updateReqVO.getType())) { - //获取默认地址 - AddressDO defaultUserAddress = addressMapper.getDefaultUserAddress(userId); - Optional.ofNullable(defaultUserAddress) - //排除当前地址 - .filter(u -> !u.getId().equals(updateReqVO.getId())) - //更新为非默认 - .ifPresent( u -> addressMapper.updateTypeById(u.getId(), AddressTypeEnum.NORMAL)); + if (Boolean.TRUE.equals(updateReqVO.getDefaulted())) { + List addresses = addressMapper.selectListByUserIdAndDefaulted(userId, true); + addresses.stream().filter(u -> !u.getId().equals(updateReqVO.getId())) // 排除自己 + .forEach(address -> addressMapper.updateById(new AddressDO().setId(address.getId()).setDefaulted(false))); } + // 更新 AddressDO updateObj = AddressConvert.INSTANCE.convert(updateReqVO); addressMapper.updateById(updateObj); @@ -78,56 +66,32 @@ public class AddressServiceImpl implements AddressService { @Override public void deleteAddress(Long userId, Long id) { // 校验存在,校验是否能够操作 - check(userId, id); + validAddressExists(userId, id); // 删除 addressMapper.deleteById(id); } - /** - * 校验用户收件地址是不是属于该用户 - * - * @param userId 用户编号 - * @param userAddressId 用户收件地址 - */ - private void check(Long userId, Long userAddressId) { - AddressDO addressDO = getAddress(userId, userAddressId); - if(null == addressDO){ + private void validAddressExists(Long userId, Long id) { + AddressDO addressDO = getAddress(userId, id); + if (addressDO == null) { throw exception(ADDRESS_NOT_EXISTS); } - if (!addressDO.getUserId().equals(userId)) { - throw exception(ADDRESS_FORBIDDEN); - } } @Override public AddressDO getAddress(Long userId, Long id) { - return addressMapper.getAddressByIdAndUserId(userId, id); + return addressMapper.selectByIdAndUserId(id, userId); } @Override public List getAddressList(Long userId) { - return selectListByUserIdAndType(userId, null); + return addressMapper.selectListByUserIdAndDefaulted(userId, null); } - /** - * 获取默认地址 - * @param userId - * @return - */ @Override public AddressDO getDefaultUserAddress(Long userId) { - return addressMapper.getDefaultUserAddress(userId); + List addresses = addressMapper.selectListByUserIdAndDefaulted(userId, true); + return CollUtil.getFirst(addresses); } - /** - * 根据类型获取地址列表 - * @param userId - * @param type null则查询全部 - * @return - */ - public List selectListByUserIdAndType(Long userId, Integer type) { - return addressMapper.selectListByUserIdAndType(userId, type); - } - - } diff --git a/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImplTest.java b/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImplTest.java index eefa2e13e..6ddf80a0e 100644 --- a/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImplTest.java +++ b/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 import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressUpdateReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.address.AddressDO; import cn.iocoder.yudao.module.member.dal.mysql.address.AddressMapper; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Import; import javax.annotation.Resource; -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; -import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.ADDRESS_NOT_EXISTS; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; /** * {@link AddressServiceImpl} 的单元测试类 @@ -40,7 +38,7 @@ public class AddressServiceImplTest extends BaseDbUnitTest { AppAddressCreateReqVO reqVO = randomPojo(AppAddressCreateReqVO.class); // 调用 - Long addressId = addressService.createAddress(getLoginUserId(), reqVO); + Long addressId = addressService.createAddress(randomLongId(), reqVO); // 断言 assertNotNull(addressId); // 校验记录的属性是否正确 @@ -59,7 +57,7 @@ public class AddressServiceImplTest extends BaseDbUnitTest { }); // 调用 - addressService.updateAddress(getLoginUserId(), reqVO); + addressService.updateAddress(dbAddress.getUserId(), reqVO); // 校验是否更新正确 AddressDO address = addressMapper.selectById(reqVO.getId()); // 获取最新的 assertPojoEquals(reqVO, address); @@ -71,7 +69,7 @@ public class AddressServiceImplTest extends BaseDbUnitTest { AppAddressUpdateReqVO reqVO = randomPojo(AppAddressUpdateReqVO.class); // 调用, 并断言异常 - assertServiceException(() -> addressService.updateAddress(getLoginUserId(), reqVO), ADDRESS_NOT_EXISTS); + assertServiceException(() -> addressService.updateAddress(randomLongId(), reqVO), ADDRESS_NOT_EXISTS); } @Test @@ -83,7 +81,7 @@ public class AddressServiceImplTest extends BaseDbUnitTest { Long id = dbAddress.getId(); // 调用 - addressService.deleteAddress(getLoginUserId(), id); + addressService.deleteAddress(dbAddress.getUserId(), id); // 校验数据不存在了 assertNull(addressMapper.selectById(id)); } @@ -94,67 +92,7 @@ public class AddressServiceImplTest extends BaseDbUnitTest { Long id = randomLongId(); // 调用, 并断言异常 - assertServiceException(() -> addressService.deleteAddress(getLoginUserId(), id), ADDRESS_NOT_EXISTS); - } - - @Test - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 - public void ins() { - // mock 数据 - AddressDO dbAddress = randomPojo(AddressDO.class, o -> { // 等会查询到 - o.setUserId(null); - o.setName(null); - o.setMobile(null); - o.setAreaCode(null); - o.setDetailAddress(null); - o.setType(null); - o.setCreateTime(null); - }); - addressMapper.insert(dbAddress); - // 测试 userId 不匹配 - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setUserId(null))); - // 测试 name 不匹配 - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setName(null))); - // 测试 mobile 不匹配 - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setMobile(null))); - // 测试 areaCode 不匹配 - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setAreaCode(null))); - // 测试 detailAddress 不匹配 - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setDetailAddress(null))); - // 测试 type 不匹配 - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setType(null))); - // 测试 createTime 不匹配 - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setCreateTime(null))); - } - - @Test - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 - public void testGetAddressList() { - // mock 数据 - AddressDO dbAddress = randomPojo(AddressDO.class, o -> { // 等会查询到 - o.setUserId(null); - o.setName(null); - o.setMobile(null); - o.setAreaCode(null); - o.setDetailAddress(null); - o.setType(null); - o.setCreateTime(null); - }); - addressMapper.insert(dbAddress); - // 测试 userId 不匹配 - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setUserId(null))); - // 测试 name 不匹配 - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setName(null))); - // 测试 mobile 不匹配 - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setMobile(null))); - // 测试 areaCode 不匹配 - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setAreaCode(null))); - // 测试 detailAddress 不匹配 - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setDetailAddress(null))); - // 测试 type 不匹配 - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setType(null))); - // 测试 createTime 不匹配 - addressMapper.insert(cloneIgnoreId(dbAddress, o -> o.setCreateTime(null))); + assertServiceException(() -> addressService.deleteAddress(randomLongId(), id), ADDRESS_NOT_EXISTS); } } diff --git a/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/create_tables.sql b/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/create_tables.sql index 608a3bddf..b0347b058 100644 --- a/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/create_tables.sql +++ b/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/create_tables.sql @@ -35,15 +35,15 @@ CREATE TABLE IF NOT EXISTS "member_address" ( "user_id" bigint(20) NOT NULL, "name" varchar(10) NOT NULL, "mobile" varchar(20) NOT NULL, - "area_code" int(11) NOT NULL, + "area_id" bigint(20) NOT NULL, + "post_code" varchar(16) NOT NULL, "detail_address" varchar(250) NOT NULL, - "type" tinyint(4) NOT NULL, + "defaulted" bit NOT NULL, "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, "creator" varchar(64) DEFAULT '', "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, "deleted" bit NOT NULL DEFAULT FALSE, "updater" varchar(64) DEFAULT '', - "tenant_id" bigint(20) NOT NULL, PRIMARY KEY ("id") - ) COMMENT '用户收件地址'; +) COMMENT '用户收件地址';