From 810c7ed040242de3672494d6c366532757a70d9e Mon Sep 17 00:00:00 2001 From: puhui999 Date: Thu, 4 May 2023 01:32:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=95=86=E5=93=81=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/optional/mall.sql | 87 +++++++++++++------ .../enums/spu/ProductSpuTabTypeEnum.java | 27 ++++++ .../admin/spu/ProductSpuController.java | 15 ++++ .../admin/spu/vo/ProductSpuPageReqVO.java | 13 ++- .../spu/vo/ProductSpuUpdateStatusReqVO.java | 26 ++++++ .../dal/mysql/spu/ProductSpuMapper.java | 58 +++++++++---- .../service/spu/ProductSpuService.java | 21 ++++- .../service/spu/ProductSpuServiceImpl.java | 80 +++++++++++------ .../spu/ProductSpuServiceImplTest.java | 9 +- 9 files changed, 257 insertions(+), 79 deletions(-) create mode 100644 yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/spu/ProductSpuTabTypeEnum.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuUpdateStatusReqVO.java diff --git a/sql/mysql/optional/mall.sql b/sql/mysql/optional/mall.sql index 0e8483155..6a4b73e54 100644 --- a/sql/mysql/optional/mall.sql +++ b/sql/mysql/optional/mall.sql @@ -163,19 +163,20 @@ COMMIT; -- Table structure for product_property -- ---------------------------- DROP TABLE IF EXISTS `product_property`; -CREATE TABLE `product_property` ( - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', - `name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '规格名称', - `status` tinyint NULL DEFAULT NULL COMMENT '状态: 0 开启 ,1 禁用', - `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `update_time` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '创建人', - `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '更新人', - `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号', - `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', - PRIMARY KEY (`id`) USING BTREE, - INDEX `idx_name`(`name`(32) ASC) USING BTREE COMMENT '规格名称索引' -) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '规格名称'; +CREATE TABLE `product_property` ( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', + `name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '规格名称', + `status` tinyint DEFAULT NULL COMMENT '状态: 0 开启 ,1 禁用', + `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '创建人', + `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '更新人', + `tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '租户编号', + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', + `remark` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '备注', + PRIMARY KEY (`id`) USING BTREE, + KEY `idx_name` (`name`(32)) USING BTREE COMMENT '规格名称索引' +) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='规格名称'; -- ---------------------------- -- Records of product_property @@ -187,19 +188,20 @@ COMMIT; -- Table structure for product_property_value -- ---------------------------- DROP TABLE IF EXISTS `product_property_value`; -CREATE TABLE `product_property_value` ( - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', - `property_id` bigint NULL DEFAULT NULL COMMENT '规格键id', - `name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '规格值名字', - `status` tinyint NULL DEFAULT NULL COMMENT '状态: 1 开启 ,2 禁用', - `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `update_time` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '创建人', - `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '更新人', - `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号', - `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', - PRIMARY KEY (`id`) USING BTREE -) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '规格值'; +CREATE TABLE `product_property_value` ( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', + `property_id` bigint DEFAULT NULL COMMENT '规格键id', + `name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '规格值名字', + `status` tinyint DEFAULT NULL COMMENT '状态: 1 开启 ,2 禁用', + `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '创建人', + `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '更新人', + `tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '租户编号', + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', + `remark` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '备注', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='规格值'; -- ---------------------------- -- Records of product_property_value @@ -325,3 +327,36 @@ INSERT INTO `ruoyi-vue-pro`.`system_menu` (`id`, `name`, `permission`, `type`, ` INSERT INTO `ruoyi-vue-pro`.`system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2028, 'Banner更新', 'market:banner:update', 3, 3, 2025, '', '', '', 0, b'1', b'1', '', '2022-08-01 14:56:14', '', '2022-08-01 14:56:14', b'0'); INSERT INTO `ruoyi-vue-pro`.`system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2029, 'Banner删除', 'market:banner:delete', 3, 4, 2025, '', '', '', 0, b'1', b'1', '', '2022-08-01 14:56:14', '', '2022-08-01 14:56:14', b'0'); +INSERT INTO `system_dict_data`(`sort`,`label`,`value`,`dict_type`,`status`,`color_type`,`css_class`,`remark`,`creator`,`create_time`,`updater`,`update_time`,`deleted`) VALUES + (1,'打',2,'product_unit',0,'','','',1, NOW(),1, NOW(),0), + (1,'盒',3,'product_unit',0,'','','',1, NOW(),1, NOW(),0), + (1,'袋',4,'product_unit',0,'','','',1, NOW(),1, NOW(),0), + (1,'箱',5,'product_unit',0,'','','',1, NOW(),1, NOW(),0), + (1,'套',6,'product_unit',0,'','','',1, NOW(),1, NOW(),0), + (1,'包',7,'product_unit',0,'','','',1, NOW(),1, NOW(),0), + (1,'双',8,'product_unit',0,'','','',1, NOW(),1, NOW(),0), + (1,'卷',9,'product_unit',0,'','','',1, NOW(),1, NOW(),0), + (1,'张',10,'product_unit',0,'','','',1, NOW(),1, NOW(),0), + (1,'克',11,'product_unit',0,'','','',1, NOW(),1, NOW(),0), + (1,'千克',12,'product_unit',0,'','','',1, NOW(),1, NOW(),0), + (1,'毫克',13,'product_unit',0,'','','',1, NOW(),1, NOW(),0), + (1,'微克',14,'product_unit',0,'','','',1, NOW(),1, NOW(),0), + (1,'吨',15,'product_unit',0,'','','',1, NOW(),1, NOW(),0), + (1,'升',16,'product_unit',0,'','','',1, NOW(),1, NOW(),0), + (1,'毫升',17,'product_unit',0,'','','',1, NOW(),1, NOW(),0), + (1, '平方米', 18, 'product_unit', 0, '', '', '', 1, NOW(), 1, NOW(), 0), + (1, '平方千米', 19, 'product_unit', 0, '', '', '', 1, NOW(), 1, NOW(), 0), + (1, '平方英里', 20, 'product_unit', 0, '', '', '', 1, NOW(), 1, NOW(), 0), + (1, '平方码', 21, 'product_unit', 0, '', '', '', 1, NOW(), 1, NOW(), 0), + (1, '平方英尺', 22, 'product_unit', 0, '', '', '', 1, NOW(), 1, NOW(), 0), + (1, '立方米', 23, 'product_unit', 0, '', '', '', 1, NOW(), 1, NOW(), 0), + (1, '立方厘米', 24, 'product_unit', 0, '', '', '', 1, NOW(), 1, NOW(), 0), + (1, '立方英寸', 25, 'product_unit', 0, '', '', '', 1, NOW(), 1, NOW(), 0), + (1, '米', 26, 'product_unit', 0, '', '', '', 1, NOW(), 1, NOW(), 0), + (1, '千米', 27, 'product_unit', 0, '', '', '', 1, NOW(), 1, NOW(), 0), + (1, '厘米', 28, 'product_unit', 0, '', '', '', 1, NOW(), 1, NOW(), 0), + (1, '毫米', 29, 'product_unit', 0, '', '', '', 1, NOW(), 1, NOW(), 0), + (1, '英寸', 30, 'product_unit', 0, '', '', '', 1, NOW(), 1, NOW(), 0), + (1, '英尺', 31, 'product_unit', 0, '', '', '', 1, NOW(), 1, NOW(), 0), + (1, '码', 32, 'product_unit', 0, '', '', '', 1, NOW(), 1, NOW(), 0), + (1,'个',1,'product_unit',0,'','','',1, NOW(),1, NOW(),0); \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/spu/ProductSpuTabTypeEnum.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/spu/ProductSpuTabTypeEnum.java new file mode 100644 index 000000000..13dfc1a06 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/spu/ProductSpuTabTypeEnum.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.product.enums.spu; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 商品spu标签枚举类型 + * + * @author HUIHUI + */ +@Getter +@AllArgsConstructor +public enum ProductSpuTabTypeEnum { + FOR_SALE(0,"出售中商品"), + IN_WAREHOUSE(1,"仓库中商品"), + SOLD_OUT(2,"已售空商品"), + ALERT_STOCK(3,"警戒库存"), + RECYCLE_BIN(4,"商品回收站"); + /** + * 状态 + */ + private final Integer type; + /** + * 状态名 + */ + private final String name; +} 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 2e2871faa..3a4923bbe 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 @@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; import java.util.List; +import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -54,6 +55,14 @@ public class ProductSpuController { return success(true); } + @PutMapping("/updateStatus") + @Operation(summary = "更新商品 SPU Status") + @PreAuthorize("@ss.hasPermission('product:spu:update')") + public CommonResult updateStatus(@Valid @RequestBody ProductSpuUpdateStatusReqVO updateReqVO) { + productSpuService.updateStatus(updateReqVO); + return success(true); + } + @DeleteMapping("/delete") @Operation(summary = "删除商品 SPU") @Parameter(name = "id", description = "编号", required = true, example = "1024") @@ -85,5 +94,11 @@ public class ProductSpuController { public CommonResult> getSpuPage(@Valid ProductSpuPageReqVO pageVO) { return success(ProductSpuConvert.INSTANCE.convertPage(productSpuService.getSpuPage(pageVO))); } + @GetMapping("/tabsCount") + @Operation(summary = "获得商品 SPU tabsCount") + @PreAuthorize("@ss.hasPermission('product:spu:query')") + public CommonResult> getTabsCount() { + return success(productSpuService.getTabsCount()); + } } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuPageReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuPageReqVO.java index 91cd54ab2..cee193637 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuPageReqVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuPageReqVO.java @@ -5,6 +5,11 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; @Schema(description = "管理后台 - 商品 SPU 分页 Request VO") @Data @@ -15,7 +20,11 @@ public class ProductSpuPageReqVO extends PageParam { @Schema(description = "商品名称", example = "yutou") private String name; - @Schema(description = "分类编号", example = "1") - private Long categoryId; + @Schema(description = "前端请求的tab类型", example = "1") + private Integer tabType; + + @Schema(description = "创建时间", example = "[2022-07-01 00:00:00,2022-07-01 23:59:59]") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuUpdateStatusReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuUpdateStatusReqVO.java new file mode 100644 index 000000000..9838dd610 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuUpdateStatusReqVO.java @@ -0,0 +1,26 @@ +package cn.iocoder.yudao.module.product.controller.admin.spu.vo; + +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import java.util.List; + +@Schema(description = "管理后台 - 商品 SPU Status 更新 Request VO") +@Data +public class ProductSpuUpdateStatusReqVO{ + + @Schema(description = "商品编号", required = true, example = "1") + @NotNull(message = "商品编号不能为空") + private Long id; + + @Schema(description = "商品状态", required = true, example = "1") + @NotNull(message = "商品状态不能为空") + private Integer status; + + +} 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 6ac1e8611..f3101ab4e 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,14 +1,20 @@ package cn.iocoder.yudao.module.product.dal.mysql.spu; +import cn.hutool.core.util.ObjUtil; +import cn.hutool.core.util.StrUtil; 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.framework.mybatis.core.util.MyBatisUtils; import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReqVO; import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; +import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; +import cn.iocoder.yudao.module.product.enums.spu.ProductSpuTabTypeEnum; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; +import java.util.Map; import java.util.Objects; import java.util.Set; @@ -20,29 +26,51 @@ import java.util.Set; @Mapper public interface ProductSpuMapper extends BaseMapperX { + //default PageResult selectPage(ProductSpuPageReqVO reqVO) { + // return selectPage(reqVO, new LambdaQueryWrapperX() + // .likeIfPresent(ProductSpuDO::getName, reqVO.getName()) + // .orderByDesc(ProductSpuDO::getSort)); + //} default PageResult selectPage(ProductSpuPageReqVO reqVO) { return selectPage(reqVO, new LambdaQueryWrapperX() + // 商品名称 .likeIfPresent(ProductSpuDO::getName, reqVO.getName()) - .eqIfPresent(ProductSpuDO::getCategoryId, reqVO.getCategoryId()) + .betweenIfPresent(ProductSpuDO::getCreateTime, reqVO.getCreateTime()) + // 出售中商品 + .eq(ProductSpuTabTypeEnum.FOR_SALE.getType().equals(reqVO.getTabType()),ProductSpuDO::getStatus,ProductSpuStatusEnum.ENABLE.getStatus()) + // 仓储中商品 + .eq(ProductSpuTabTypeEnum.IN_WAREHOUSE.getType().equals(reqVO.getTabType()),ProductSpuDO::getStatus,ProductSpuStatusEnum.DISABLE.getStatus()) + // 已售空商品 + .eq(ProductSpuTabTypeEnum.SOLD_OUT.getType().equals(reqVO.getTabType()),ProductSpuDO::getStock,0) + // TODO 警戒库存暂时为 10,后期需要使用常量或者数据库配置替换 + .le(ProductSpuTabTypeEnum.ALERT_STOCK.getType().equals(reqVO.getTabType()),ProductSpuDO::getStock,10) + // 回收站 + .eq(ProductSpuTabTypeEnum.RECYCLE_BIN.getType().equals(reqVO.getTabType()),ProductSpuDO::getStatus,ProductSpuStatusEnum.RECYCLE.getStatus()) .orderByDesc(ProductSpuDO::getSort)); } - default PageResult selectPage(ProductSpuPageReqVO reqVO, Set alarmStockSpuIds) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .likeIfPresent(ProductSpuDO::getName, reqVO.getName()) - .eqIfPresent(ProductSpuDO::getCategoryId, reqVO.getCategoryId()) - .inIfPresent(ProductSpuDO::getId, alarmStockSpuIds) // 库存告警 - .orderByDesc(ProductSpuDO::getSort)); - } - - default PageResult selectPage(AppProductSpuPageReqVO pageReqVO, Integer status) { + /** + * 获得商品 SPU 分页,提供给用户 App 使用 + */ + default PageResult selectPage(AppProductSpuPageReqVO pageReqVO, Set categoryIds) { LambdaQueryWrapperX query = new LambdaQueryWrapperX() - .eqIfPresent(ProductSpuDO::getCategoryId, pageReqVO.getCategoryId()) - .eqIfPresent(ProductSpuDO::getStatus, status); + .likeIfPresent(ProductSpuDO::getName, pageReqVO.getKeyword()) // 关键字匹配,目前只匹配商品名 + .inIfPresent(ProductSpuDO::getCategoryId, categoryIds); // 分类 + query.eq(ProductSpuDO::getStatus, ProductSpuStatusEnum.ENABLE.getStatus()) // 上架状态 + .gt(ProductSpuDO::getStock, 0); // 有库存 + // 推荐类型的过滤条件 + if (ObjUtil.equal(pageReqVO.getRecommendType(), AppProductSpuPageReqVO.RECOMMEND_TYPE_HOT)) { + query.eq(ProductSpuDO::getRecommendHot, true); + } // 排序逻辑 - if (Objects.equals(pageReqVO.getSortField(), AppProductSpuPageReqVO.SORT_FIELD_PRICE)) { - } else if (Objects.equals(pageReqVO.getSortField(), AppProductSpuPageReqVO.SORT_FIELD_SALES_COUNT)) { - query.orderBy(true, pageReqVO.getSortAsc(), ProductSpuDO::getSalesCount); + if (Objects.equals(pageReqVO.getSortField(), AppProductSpuPageReqVO.SORT_FIELD_SALES_COUNT)) { + query.last(String.format(" ORDER BY (sales_count + virtual_sales_count) %s, sort DESC, id DESC", + pageReqVO.getSortAsc() ? "ASC" : "DESC")); + } else if (Objects.equals(pageReqVO.getSortField(), AppProductSpuPageReqVO.SORT_FIELD_PRICE)) { + query.orderBy(true, pageReqVO.getSortAsc(), ProductSpuDO::getPrice) + .orderByDesc(ProductSpuDO::getSort).orderByDesc(ProductSpuDO::getId); + } else { + query.orderByDesc(ProductSpuDO::getSort).orderByDesc(ProductSpuDO::getId); } return selectPage(pageReqVO, query); } 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 f088a7e79..4b0444018 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 @@ -75,7 +75,7 @@ public interface ProductSpuService { List getSpuList(); /** - * 获得商品 SPU 分页 + * 获得商品 SPU 分页,提供给挂你兰后台使用 * * @param pageReqVO 分页查询 * @return 商品spu分页 @@ -83,13 +83,12 @@ public interface ProductSpuService { PageResult getSpuPage(ProductSpuPageReqVO pageReqVO); /** - * 获得商品 SPU 分页 + * 获得商品 SPU 分页,提供给用户 App 使用 * * @param pageReqVO 分页查询 - * @param status 状态 * @return 商品 SPU 分页 */ - PageResult getSpuPage(AppProductSpuPageReqVO pageReqVO, Integer status); + PageResult getSpuPage(AppProductSpuPageReqVO pageReqVO); /** * 更新商品 SPU 库存(增量) @@ -105,4 +104,18 @@ public interface ProductSpuService { * @return {@link ProductSpuDetailRespVO} */ ProductSpuDetailRespVO getSpuDetail(Long id); + + /** + * 更新状态 + * + * @param updateReqVO 更新请求签证官 + */ + void updateStatus(ProductSpuUpdateStatusReqVO updateReqVO); + + /** + * 获取spu列表标签对应的Count数量 + * + * @return {@link Map}<{@link Integer}, {@link Integer}> + */ + Map getTabsCount(); } 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 4355f05ab..23421c988 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 @@ -1,14 +1,15 @@ package cn.iocoder.yudao.module.product.service.spu; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; -import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuCreateReqVO; -import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuDetailRespVO; -import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReqVO; -import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuUpdateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO; import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; @@ -16,11 +17,13 @@ import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper; import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; +import cn.iocoder.yudao.module.product.enums.spu.ProductSpuTabTypeEnum; import cn.iocoder.yudao.module.product.service.brand.ProductBrandService; import cn.iocoder.yudao.module.product.service.category.ProductCategoryService; import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService; import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO; import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -62,7 +65,7 @@ public class ProductSpuServiceImpl implements ProductSpuService { public Long createSpu(ProductSpuCreateReqVO createReqVO) { // 校验分类 TODO 暂不清楚为什么只能选择第三层的结点 //validateCategory(createReqVO.getCategoryId()); - // 校验品牌 TODO 暂不校验 + // 校验品牌 TODO 暂不校验,前端没有做品牌选择 //brandService.validateProductBrand(createReqVO.getBrandId()); List skuSaveReqList = createReqVO.getSkus(); @@ -84,14 +87,13 @@ public class ProductSpuServiceImpl implements ProductSpuService { public void updateSpu(ProductSpuUpdateReqVO updateReqVO) { // 校验 SPU 是否存在 validateSpuExists(updateReqVO.getId()); - // 校验分类 - validateCategory(updateReqVO.getCategoryId()); - // 校验品牌 - brandService.validateProductBrand(updateReqVO.getBrandId()); + // 校验分类 TODO 暂不清楚为什么只能选择第三层的结点 + //validateCategory(updateReqVO.getCategoryId()); + // 校验品牌 TODO 暂不校验,前端没有做品牌选择 + //brandService.validateProductBrand(updateReqVO.getBrandId()); // 校验SKU List skuSaveReqList = updateReqVO.getSkus(); productSkuService.validateSkuList(skuSaveReqList, updateReqVO.getSpecType()); - // 更新 SPU ProductSpuDO updateObj = ProductSpuConvert.INSTANCE.convert(updateReqVO); initSpuFromSkus(updateObj, skuSaveReqList); @@ -176,21 +178,13 @@ public class ProductSpuServiceImpl implements ProductSpuService { @Override public PageResult getSpuPage(ProductSpuPageReqVO pageReqVO) { - // 库存告警的 SPU 编号的集合 TODO 一个接口一个接口来 - Set alarmStockSpuIds = null; - //if (Boolean.TRUE.equals(pageReqVO.getAlarmStock())) { - // alarmStockSpuIds = CollectionUtils.convertSet(productSkuService.getSkuListByAlarmStock(), ProductSkuDO::getSpuId); - // if (CollUtil.isEmpty(alarmStockSpuIds)) { - // return PageResult.empty(); - // } - //} - // 分页查询 - return productSpuMapper.selectPage(pageReqVO, alarmStockSpuIds); + return productSpuMapper.selectPage(pageReqVO); } @Override - public PageResult getSpuPage(AppProductSpuPageReqVO pageReqVO, Integer status) { - return productSpuMapper.selectPage(pageReqVO, status); + public PageResult getSpuPage(AppProductSpuPageReqVO pageReqVO) { + //return productSpuMapper.selectPage(pageReqVO); TODO 有差异接口接受参数类型不对 + return null; } @Override @@ -211,15 +205,45 @@ public class ProductSpuServiceImpl implements ProductSpuService { List skus = productSkuService.getSkuListBySpuId(spu.getId()); if (CollUtil.isNotEmpty(skus)){ List skuRespVoS = ProductSkuConvert.INSTANCE.convertList(skus); - // 获取所有的属性值id - Set valueIds = skus.stream().flatMap(p -> p.getProperties().stream()).map(ProductSkuDO.Property::getValueId).collect(Collectors.toSet()); - List valueDetailList = productPropertyValueService.getPropertyValueDetailList(valueIds); - Map stringMap = valueDetailList.stream().collect(Collectors.toMap(ProductPropertyValueDetailRespBO::getValueId, ProductPropertyValueDetailRespBO::getValueName)); - // 设置属性值名称 - skuRespVoS.stream().flatMap(p -> p.getProperties().stream()).forEach(item ->item.setValueName(stringMap.get(item.getValueId()))); + // 非多规格,不需要处理 + if (ObjectUtil.equal(productSpuDetailRespVO.getSpecType(), true)) { + // 获取所有的属性值id + Set valueIds = skus.stream().flatMap(p -> p.getProperties().stream()).map(ProductSkuDO.Property::getValueId).collect(Collectors.toSet()); + List valueDetailList = productPropertyValueService.getPropertyValueDetailList(valueIds); + Map stringMap = valueDetailList.stream().collect(Collectors.toMap(ProductPropertyValueDetailRespBO::getValueId, ProductPropertyValueDetailRespBO::getValueName)); + // 设置属性值名称 + skuRespVoS.stream().flatMap(p -> p.getProperties().stream()).forEach(item ->item.setValueName(stringMap.get(item.getValueId()))); + } productSpuDetailRespVO.setSkus(skuRespVoS); } return productSpuDetailRespVO; } + @Override + @Transactional(rollbackFor = Exception.class) + public void updateStatus(ProductSpuUpdateStatusReqVO updateReqVO) { + // 校验存在 + validateSpuExists(updateReqVO.getId()); + // 更新状态 + ProductSpuDO productSpuDO = productSpuMapper.selectById(updateReqVO.getId()).setStatus(updateReqVO.getStatus()); + productSpuMapper.updateById(productSpuDO); + + } + + @Override + public Map getTabsCount() { + Map map = new HashMap<>(); + // 查询销售中的商品数量 + map.put(ProductSpuTabTypeEnum.FOR_SALE.getType(), productSpuMapper.selectCount(ProductSpuDO::getStatus, ProductSpuStatusEnum.ENABLE.getStatus())); + // 查询仓库中的商品数量 + map.put(ProductSpuTabTypeEnum.IN_WAREHOUSE.getType(),productSpuMapper.selectCount(ProductSpuDO::getStatus, ProductSpuStatusEnum.DISABLE.getStatus())); + // 查询售空的商品数量 + map.put(ProductSpuTabTypeEnum.SOLD_OUT.getType(),productSpuMapper.selectCount(ProductSpuDO::getStock, 0)); + // 查询触发警戒库存的商品数量 TODO 警戒库存暂时为 10,后期需要使用常量或者数据库配置替换 + map.put(ProductSpuTabTypeEnum.ALERT_STOCK.getType(),productSpuMapper.selectCount(new LambdaQueryWrapperX().le(ProductSpuDO::getStock, 10))); + // 查询回收站中的商品数量 + map.put(ProductSpuTabTypeEnum.RECYCLE_BIN.getType(),productSpuMapper.selectCount(ProductSpuDO::getStatus, ProductSpuStatusEnum.RECYCLE.getStatus())); + return map; + } + } 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 d6e1bdb4e..bd61c4e93 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 @@ -189,7 +189,7 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest { }); productSpuMapper.insert(createReqVO); - Set alarmStockSpuIds = SetUtils.asSet(createReqVO.getId()); + //Set alarmStockSpuIds = SetUtils.asSet(createReqVO.getId()); TODO 查询接口已改变没有使用到这个变量 List productSpuDOS = Arrays.asList(randomPojo(ProductSkuDO.class, o -> { o.setSpuId(createReqVO.getId()); @@ -204,7 +204,7 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest { //productSpuPageReqVO.setAlarmStock(true); PageResult spuPage = productSpuService.getSpuPage(productSpuPageReqVO); - PageResult result = ProductSpuConvert.INSTANCE.convertPage(productSpuMapper.selectPage(productSpuPageReqVO, alarmStockSpuIds)); + PageResult result = ProductSpuConvert.INSTANCE.convertPage(productSpuMapper.selectPage(productSpuPageReqVO)); Assertions.assertIterableEquals(result.getList(), spuPage.getList()); assertEquals(spuPage.getTotal(), result.getTotal()); } @@ -249,14 +249,15 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest { // 调用 ProductSpuPageReqVO productSpuPageReqVO = new ProductSpuPageReqVO(); + // TODO 已暂时没有相关属性,等用到时再添加 //productSpuPageReqVO.setAlarmStock(false); //productSpuPageReqVO.setBrandId(brandId); //productSpuPageReqVO.setStatus(ProductSpuStatusEnum.ENABLE.getStatus()); - productSpuPageReqVO.setCategoryId(categoryId); + //productSpuPageReqVO.setCategoryId(categoryId); PageResult spuPage = productSpuService.getSpuPage(productSpuPageReqVO); - PageResult result = ProductSpuConvert.INSTANCE.convertPage(productSpuMapper.selectPage(productSpuPageReqVO, (Set) null)); + PageResult result = ProductSpuConvert.INSTANCE.convertPage(productSpuMapper.selectPage(productSpuPageReqVO)); assertEquals(result, spuPage); }