完善商品管理

pull/2/head
puhui999 2023-05-04 01:32:25 +08:00
parent c233ce1a20
commit 810c7ed040
9 changed files with 257 additions and 79 deletions

View File

@ -165,17 +165,18 @@ COMMIT;
DROP TABLE IF EXISTS `product_property`; DROP TABLE IF EXISTS `product_property`;
CREATE TABLE `product_property` ( CREATE TABLE `product_property` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '', `id` bigint NOT NULL AUTO_INCREMENT COMMENT '',
`name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '', `name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '',
`status` tinyint NULL DEFAULT NULL COMMENT ' 0 1 ', `status` tinyint DEFAULT NULL COMMENT ' 0 1 ',
`create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '', `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '',
`update_time` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '', `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '',
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '', `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '', `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '',
`tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '', `tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '',
`deleted` bit(1) NOT NULL DEFAULT b'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, PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_name`(`name`(32) ASC) USING BTREE COMMENT '' KEY `idx_name` (`name`(32)) USING BTREE COMMENT ''
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = ''; ) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='';
-- ---------------------------- -- ----------------------------
-- Records of product_property -- Records of product_property
@ -189,17 +190,18 @@ COMMIT;
DROP TABLE IF EXISTS `product_property_value`; DROP TABLE IF EXISTS `product_property_value`;
CREATE TABLE `product_property_value` ( CREATE TABLE `product_property_value` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '', `id` bigint NOT NULL AUTO_INCREMENT COMMENT '',
`property_id` bigint NULL DEFAULT NULL COMMENT 'id', `property_id` bigint DEFAULT NULL COMMENT 'id',
`name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '', `name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '',
`status` tinyint NULL DEFAULT NULL COMMENT ' 1 2 ', `status` tinyint DEFAULT NULL COMMENT ' 1 2 ',
`create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '', `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '',
`update_time` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '', `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '',
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '', `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '', `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '',
`tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '', `tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '',
`deleted` bit(1) NOT NULL DEFAULT b'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 PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = ''; ) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='';
-- ---------------------------- -- ----------------------------
-- Records of product_property_value -- 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 (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 `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);

View File

@ -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;
}

View File

@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.List; 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.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -54,6 +55,14 @@ public class ProductSpuController {
return success(true); return success(true);
} }
@PutMapping("/updateStatus")
@Operation(summary = "更新商品 SPU Status")
@PreAuthorize("@ss.hasPermission('product:spu:update')")
public CommonResult<Boolean> updateStatus(@Valid @RequestBody ProductSpuUpdateStatusReqVO updateReqVO) {
productSpuService.updateStatus(updateReqVO);
return success(true);
}
@DeleteMapping("/delete") @DeleteMapping("/delete")
@Operation(summary = "删除商品 SPU") @Operation(summary = "删除商品 SPU")
@Parameter(name = "id", description = "编号", required = true, example = "1024") @Parameter(name = "id", description = "编号", required = true, example = "1024")
@ -85,5 +94,11 @@ public class ProductSpuController {
public CommonResult<PageResult<ProductSpuPageRespVO>> getSpuPage(@Valid ProductSpuPageReqVO pageVO) { public CommonResult<PageResult<ProductSpuPageRespVO>> getSpuPage(@Valid ProductSpuPageReqVO pageVO) {
return success(ProductSpuConvert.INSTANCE.convertPage(productSpuService.getSpuPage(pageVO))); return success(ProductSpuConvert.INSTANCE.convertPage(productSpuService.getSpuPage(pageVO)));
} }
@GetMapping("/tabsCount")
@Operation(summary = "获得商品 SPU tabsCount")
@PreAuthorize("@ss.hasPermission('product:spu:query')")
public CommonResult<Map<Integer, Long>> getTabsCount() {
return success(productSpuService.getTabsCount());
}
} }

View File

@ -5,6 +5,11 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; 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") @Schema(description = "管理后台 - 商品 SPU 分页 Request VO")
@Data @Data
@ -15,7 +20,11 @@ public class ProductSpuPageReqVO extends PageParam {
@Schema(description = "商品名称", example = "yutou") @Schema(description = "商品名称", example = "yutou")
private String name; private String name;
@Schema(description = "分类编号", example = "1") @Schema(description = "前端请求的tab类型", example = "1")
private Long categoryId; 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;
} }

View File

@ -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;
}

View File

@ -1,14 +1,20 @@
package cn.iocoder.yudao.module.product.dal.mysql.spu; 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.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; 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.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.admin.spu.vo.ProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO; 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.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 com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
@ -20,29 +26,51 @@ import java.util.Set;
@Mapper @Mapper
public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> { public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> {
//default PageResult<ProductSpuDO> selectPage(ProductSpuPageReqVO reqVO) {
// return selectPage(reqVO, new LambdaQueryWrapperX<ProductSpuDO>()
// .likeIfPresent(ProductSpuDO::getName, reqVO.getName())
// .orderByDesc(ProductSpuDO::getSort));
//}
default PageResult<ProductSpuDO> selectPage(ProductSpuPageReqVO reqVO) { default PageResult<ProductSpuDO> selectPage(ProductSpuPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ProductSpuDO>() return selectPage(reqVO, new LambdaQueryWrapperX<ProductSpuDO>()
// 商品名称
.likeIfPresent(ProductSpuDO::getName, reqVO.getName()) .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)); .orderByDesc(ProductSpuDO::getSort));
} }
default PageResult<ProductSpuDO> selectPage(ProductSpuPageReqVO reqVO, Set<Long> alarmStockSpuIds) { /**
return selectPage(reqVO, new LambdaQueryWrapperX<ProductSpuDO>() * SPU App 使
.likeIfPresent(ProductSpuDO::getName, reqVO.getName()) */
.eqIfPresent(ProductSpuDO::getCategoryId, reqVO.getCategoryId()) default PageResult<ProductSpuDO> selectPage(AppProductSpuPageReqVO pageReqVO, Set<Long> categoryIds) {
.inIfPresent(ProductSpuDO::getId, alarmStockSpuIds) // 库存告警
.orderByDesc(ProductSpuDO::getSort));
}
default PageResult<ProductSpuDO> selectPage(AppProductSpuPageReqVO pageReqVO, Integer status) {
LambdaQueryWrapperX<ProductSpuDO> query = new LambdaQueryWrapperX<ProductSpuDO>() LambdaQueryWrapperX<ProductSpuDO> query = new LambdaQueryWrapperX<ProductSpuDO>()
.eqIfPresent(ProductSpuDO::getCategoryId, pageReqVO.getCategoryId()) .likeIfPresent(ProductSpuDO::getName, pageReqVO.getKeyword()) // 关键字匹配,目前只匹配商品名
.eqIfPresent(ProductSpuDO::getStatus, status); .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)) { if (Objects.equals(pageReqVO.getSortField(), AppProductSpuPageReqVO.SORT_FIELD_SALES_COUNT)) {
} else 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",
query.orderBy(true, pageReqVO.getSortAsc(), ProductSpuDO::getSalesCount); 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); return selectPage(pageReqVO, query);
} }

View File

@ -75,7 +75,7 @@ public interface ProductSpuService {
List<ProductSpuDO> getSpuList(); List<ProductSpuDO> getSpuList();
/** /**
* SPU * SPU 使
* *
* @param pageReqVO * @param pageReqVO
* @return spu * @return spu
@ -83,13 +83,12 @@ public interface ProductSpuService {
PageResult<ProductSpuDO> getSpuPage(ProductSpuPageReqVO pageReqVO); PageResult<ProductSpuDO> getSpuPage(ProductSpuPageReqVO pageReqVO);
/** /**
* SPU * SPU App 使
* *
* @param pageReqVO * @param pageReqVO
* @param status
* @return SPU * @return SPU
*/ */
PageResult<ProductSpuDO> getSpuPage(AppProductSpuPageReqVO pageReqVO, Integer status); PageResult<ProductSpuDO> getSpuPage(AppProductSpuPageReqVO pageReqVO);
/** /**
* SPU * SPU
@ -105,4 +104,18 @@ public interface ProductSpuService {
* @return {@link ProductSpuDetailRespVO} * @return {@link ProductSpuDetailRespVO}
*/ */
ProductSpuDetailRespVO getSpuDetail(Long id); ProductSpuDetailRespVO getSpuDetail(Long id);
/**
*
*
* @param updateReqVO
*/
void updateStatus(ProductSpuUpdateStatusReqVO updateReqVO);
/**
* spuCount
*
* @return {@link Map}<{@link Integer}, {@link Integer}>
*/
Map<Integer, Long> getTabsCount();
} }

View File

@ -1,14 +1,15 @@
package cn.iocoder.yudao.module.product.service.spu; package cn.iocoder.yudao.module.product.service.spu;
import cn.hutool.core.collection.CollUtil; 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.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; 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.ProductSkuCreateOrUpdateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; 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.*;
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.app.spu.vo.AppProductSpuPageReqVO; 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.sku.ProductSkuConvert;
import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; 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.dataobject.spu.ProductSpuDO;
import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper; 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.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.brand.ProductBrandService;
import cn.iocoder.yudao.module.product.service.category.ProductCategoryService; 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.ProductPropertyValueService;
import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO; import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO;
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; 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.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -62,7 +65,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
public Long createSpu(ProductSpuCreateReqVO createReqVO) { public Long createSpu(ProductSpuCreateReqVO createReqVO) {
// 校验分类 TODO 暂不清楚为什么只能选择第三层的结点 // 校验分类 TODO 暂不清楚为什么只能选择第三层的结点
//validateCategory(createReqVO.getCategoryId()); //validateCategory(createReqVO.getCategoryId());
// 校验品牌 TODO 暂不校验 // 校验品牌 TODO 暂不校验,前端没有做品牌选择
//brandService.validateProductBrand(createReqVO.getBrandId()); //brandService.validateProductBrand(createReqVO.getBrandId());
List<ProductSkuCreateOrUpdateReqVO> skuSaveReqList = createReqVO.getSkus(); List<ProductSkuCreateOrUpdateReqVO> skuSaveReqList = createReqVO.getSkus();
@ -84,14 +87,13 @@ public class ProductSpuServiceImpl implements ProductSpuService {
public void updateSpu(ProductSpuUpdateReqVO updateReqVO) { public void updateSpu(ProductSpuUpdateReqVO updateReqVO) {
// 校验 SPU 是否存在 // 校验 SPU 是否存在
validateSpuExists(updateReqVO.getId()); validateSpuExists(updateReqVO.getId());
// 校验分类 // 校验分类 TODO 暂不清楚为什么只能选择第三层的结点
validateCategory(updateReqVO.getCategoryId()); //validateCategory(updateReqVO.getCategoryId());
// 校验品牌 // 校验品牌 TODO 暂不校验,前端没有做品牌选择
brandService.validateProductBrand(updateReqVO.getBrandId()); //brandService.validateProductBrand(updateReqVO.getBrandId());
// 校验SKU // 校验SKU
List<ProductSkuCreateOrUpdateReqVO> skuSaveReqList = updateReqVO.getSkus(); List<ProductSkuCreateOrUpdateReqVO> skuSaveReqList = updateReqVO.getSkus();
productSkuService.validateSkuList(skuSaveReqList, updateReqVO.getSpecType()); productSkuService.validateSkuList(skuSaveReqList, updateReqVO.getSpecType());
// 更新 SPU // 更新 SPU
ProductSpuDO updateObj = ProductSpuConvert.INSTANCE.convert(updateReqVO); ProductSpuDO updateObj = ProductSpuConvert.INSTANCE.convert(updateReqVO);
initSpuFromSkus(updateObj, skuSaveReqList); initSpuFromSkus(updateObj, skuSaveReqList);
@ -176,21 +178,13 @@ public class ProductSpuServiceImpl implements ProductSpuService {
@Override @Override
public PageResult<ProductSpuDO> getSpuPage(ProductSpuPageReqVO pageReqVO) { public PageResult<ProductSpuDO> getSpuPage(ProductSpuPageReqVO pageReqVO) {
// 库存告警的 SPU 编号的集合 TODO 一个接口一个接口来 return productSpuMapper.selectPage(pageReqVO);
Set<Long> 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);
} }
@Override @Override
public PageResult<ProductSpuDO> getSpuPage(AppProductSpuPageReqVO pageReqVO, Integer status) { public PageResult<ProductSpuDO> getSpuPage(AppProductSpuPageReqVO pageReqVO) {
return productSpuMapper.selectPage(pageReqVO, status); //return productSpuMapper.selectPage(pageReqVO); TODO 有差异接口接受参数类型不对
return null;
} }
@Override @Override
@ -211,15 +205,45 @@ public class ProductSpuServiceImpl implements ProductSpuService {
List<ProductSkuDO> skus = productSkuService.getSkuListBySpuId(spu.getId()); List<ProductSkuDO> skus = productSkuService.getSkuListBySpuId(spu.getId());
if (CollUtil.isNotEmpty(skus)){ if (CollUtil.isNotEmpty(skus)){
List<ProductSkuRespVO> skuRespVoS = ProductSkuConvert.INSTANCE.convertList(skus); List<ProductSkuRespVO> skuRespVoS = ProductSkuConvert.INSTANCE.convertList(skus);
// 非多规格,不需要处理
if (ObjectUtil.equal(productSpuDetailRespVO.getSpecType(), true)) {
// 获取所有的属性值id // 获取所有的属性值id
Set<Long> valueIds = skus.stream().flatMap(p -> p.getProperties().stream()).map(ProductSkuDO.Property::getValueId).collect(Collectors.toSet()); Set<Long> valueIds = skus.stream().flatMap(p -> p.getProperties().stream()).map(ProductSkuDO.Property::getValueId).collect(Collectors.toSet());
List<ProductPropertyValueDetailRespBO> valueDetailList = productPropertyValueService.getPropertyValueDetailList(valueIds); List<ProductPropertyValueDetailRespBO> valueDetailList = productPropertyValueService.getPropertyValueDetailList(valueIds);
Map<Long, String> stringMap = valueDetailList.stream().collect(Collectors.toMap(ProductPropertyValueDetailRespBO::getValueId, ProductPropertyValueDetailRespBO::getValueName)); Map<Long, String> 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()))); skuRespVoS.stream().flatMap(p -> p.getProperties().stream()).forEach(item ->item.setValueName(stringMap.get(item.getValueId())));
}
productSpuDetailRespVO.setSkus(skuRespVoS); productSpuDetailRespVO.setSkus(skuRespVoS);
} }
return productSpuDetailRespVO; 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<Integer, Long> getTabsCount() {
Map<Integer, Long> 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<ProductSpuDO>().le(ProductSpuDO::getStock, 10)));
// 查询回收站中的商品数量
map.put(ProductSpuTabTypeEnum.RECYCLE_BIN.getType(),productSpuMapper.selectCount(ProductSpuDO::getStatus, ProductSpuStatusEnum.RECYCLE.getStatus()));
return map;
}
} }

View File

@ -189,7 +189,7 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest {
}); });
productSpuMapper.insert(createReqVO); productSpuMapper.insert(createReqVO);
Set<Long> alarmStockSpuIds = SetUtils.asSet(createReqVO.getId()); //Set<Long> alarmStockSpuIds = SetUtils.asSet(createReqVO.getId()); TODO 查询接口已改变没有使用到这个变量
List<ProductSkuDO> productSpuDOS = Arrays.asList(randomPojo(ProductSkuDO.class, o -> { List<ProductSkuDO> productSpuDOS = Arrays.asList(randomPojo(ProductSkuDO.class, o -> {
o.setSpuId(createReqVO.getId()); o.setSpuId(createReqVO.getId());
@ -204,7 +204,7 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest {
//productSpuPageReqVO.setAlarmStock(true); //productSpuPageReqVO.setAlarmStock(true);
PageResult<ProductSpuDO> spuPage = productSpuService.getSpuPage(productSpuPageReqVO); PageResult<ProductSpuDO> spuPage = productSpuService.getSpuPage(productSpuPageReqVO);
PageResult<ProductSpuPageRespVO> result = ProductSpuConvert.INSTANCE.convertPage(productSpuMapper.selectPage(productSpuPageReqVO, alarmStockSpuIds)); PageResult<ProductSpuPageRespVO> result = ProductSpuConvert.INSTANCE.convertPage(productSpuMapper.selectPage(productSpuPageReqVO));
Assertions.assertIterableEquals(result.getList(), spuPage.getList()); Assertions.assertIterableEquals(result.getList(), spuPage.getList());
assertEquals(spuPage.getTotal(), result.getTotal()); assertEquals(spuPage.getTotal(), result.getTotal());
} }
@ -249,14 +249,15 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest {
// 调用 // 调用
ProductSpuPageReqVO productSpuPageReqVO = new ProductSpuPageReqVO(); ProductSpuPageReqVO productSpuPageReqVO = new ProductSpuPageReqVO();
// TODO 已暂时没有相关属性,等用到时再添加
//productSpuPageReqVO.setAlarmStock(false); //productSpuPageReqVO.setAlarmStock(false);
//productSpuPageReqVO.setBrandId(brandId); //productSpuPageReqVO.setBrandId(brandId);
//productSpuPageReqVO.setStatus(ProductSpuStatusEnum.ENABLE.getStatus()); //productSpuPageReqVO.setStatus(ProductSpuStatusEnum.ENABLE.getStatus());
productSpuPageReqVO.setCategoryId(categoryId); //productSpuPageReqVO.setCategoryId(categoryId);
PageResult<ProductSpuDO> spuPage = productSpuService.getSpuPage(productSpuPageReqVO); PageResult<ProductSpuDO> spuPage = productSpuService.getSpuPage(productSpuPageReqVO);
PageResult<ProductSpuPageRespVO> result = ProductSpuConvert.INSTANCE.convertPage(productSpuMapper.selectPage(productSpuPageReqVO, (Set<Long>) null)); PageResult<ProductSpuPageRespVO> result = ProductSpuConvert.INSTANCE.convertPage(productSpuMapper.selectPage(productSpuPageReqVO));
assertEquals(result, spuPage); assertEquals(result, spuPage);
} }