From 3870e1a4839d583c416661039f4e5f01a16d0275 Mon Sep 17 00:00:00 2001 From: lijiaqi Date: Thu, 21 Nov 2024 09:12:38 +0800 Subject: [PATCH] =?UTF-8?q?feat(product):=20=E6=B7=BB=E5=8A=A0=E4=BE=9B?= =?UTF-8?q?=E5=BA=94=E5=95=86=E4=BF=A1=E6=81=AF=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=AF=BC=E5=85=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 GetProductBo 和 QueryProductBo 中添加供应商 ID 和名称字段 - 在 Product 实体中添加供应商 ID 字段 - 更新商品导入功能,支持导入供应商编号并进行供应商存在性校验 - 在创建商品时,普通商品类型必须选择供应商- 优化商品查询接口,支持按供应商 ID 查询 --- .../bo/product/info/GetProductBo.java | 25 +++++++++++++----- .../bo/product/info/QueryProductBo.java | 24 +++++++++++++---- .../xingyun/basedata/entity/Product.java | 7 +++++ .../excel/product/ProductImportListener.java | 15 ++++++++++- .../excel/product/ProductImportModel.java | 9 +++++++ .../impl/product/ProductServiceImpl.java | 26 ++++++++++++++++--- .../vo/product/info/CreateProductVo.java | 6 +++++ .../vo/product/info/QueryProductVo.java | 6 +++++ .../mappers/product/ProductMapper.xml | 3 +++ 9 files changed, 104 insertions(+), 17 deletions(-) diff --git a/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/bo/product/info/GetProductBo.java b/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/bo/product/info/GetProductBo.java index 740abdc..c97daf3 100644 --- a/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/bo/product/info/GetProductBo.java +++ b/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/bo/product/info/GetProductBo.java @@ -2,20 +2,16 @@ package com.lframework.xingyun.basedata.bo.product.info; import com.lframework.starter.common.constants.StringPool; import com.lframework.starter.common.utils.CollectionUtil; +import com.lframework.starter.common.utils.ObjectUtil; import com.lframework.starter.web.annotations.convert.EnumConvert; import com.lframework.starter.web.bo.BaseBo; import com.lframework.starter.web.common.utils.ApplicationUtil; import com.lframework.xingyun.basedata.dto.product.ProductPropertyRelationDto; -import com.lframework.xingyun.basedata.entity.Product; -import com.lframework.xingyun.basedata.entity.ProductBrand; -import com.lframework.xingyun.basedata.entity.ProductBundle; -import com.lframework.xingyun.basedata.entity.ProductCategory; -import com.lframework.xingyun.basedata.entity.ProductPurchase; -import com.lframework.xingyun.basedata.entity.ProductRetail; -import com.lframework.xingyun.basedata.entity.ProductSale; +import com.lframework.xingyun.basedata.entity.*; import com.lframework.xingyun.basedata.enums.ColumnType; import com.lframework.xingyun.basedata.enums.ProductType; import com.lframework.xingyun.basedata.service.product.*; +import com.lframework.xingyun.basedata.service.supplier.SupplierService; import io.swagger.annotations.ApiModelProperty; import java.math.BigDecimal; import java.util.ArrayList; @@ -171,6 +167,18 @@ public class GetProductBo extends BaseBo { @ApiModelProperty("库存") private BigDecimal stock; + /** + * 供应商ID + */ + @ApiModelProperty("供应商ID") + private String supplierId; + + /** + * 供应商名称 + */ + @ApiModelProperty("供应商名称") + private String supplierName; + public GetProductBo() { } @@ -244,6 +252,9 @@ public class GetProductBo extends BaseBo { } ProductService productService = ApplicationUtil.getBean(ProductService.class); this.stock = productService.getStock(dto.getId()); + SupplierService supplierService = ApplicationUtil.getBean(SupplierService.class); + Supplier supplier = supplierService.findById(dto.getSupplierId()); + this.supplierName = ObjectUtil.isNotNull(supplier) ? supplier.getName() : ""; } @Data diff --git a/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/bo/product/info/QueryProductBo.java b/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/bo/product/info/QueryProductBo.java index fb57e46..dbd24d3 100644 --- a/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/bo/product/info/QueryProductBo.java +++ b/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/bo/product/info/QueryProductBo.java @@ -1,19 +1,17 @@ package com.lframework.xingyun.basedata.bo.product.info; -import cn.hutool.core.util.ObjectUtil; import com.fasterxml.jackson.annotation.JsonFormat; import com.lframework.starter.common.constants.StringPool; +import com.lframework.starter.common.utils.ObjectUtil; import com.lframework.starter.web.annotations.convert.EnumConvert; import com.lframework.starter.web.bo.BaseBo; import com.lframework.starter.web.common.utils.ApplicationUtil; -import com.lframework.xingyun.basedata.entity.Product; -import com.lframework.xingyun.basedata.entity.ProductBrand; -import com.lframework.xingyun.basedata.entity.ProductCategory; -import com.lframework.xingyun.basedata.entity.ProductSale; +import com.lframework.xingyun.basedata.entity.*; import com.lframework.xingyun.basedata.service.product.ProductBrandService; import com.lframework.xingyun.basedata.service.product.ProductCategoryService; import com.lframework.xingyun.basedata.service.product.ProductSaleService; import com.lframework.xingyun.basedata.service.product.ProductService; +import com.lframework.xingyun.basedata.service.supplier.SupplierService; import io.swagger.annotations.ApiModelProperty; import java.math.BigDecimal; @@ -105,6 +103,18 @@ public class QueryProductBo extends BaseBo { @ApiModelProperty("库存") private BigDecimal stock; + /** + * 供应商ID + */ + @ApiModelProperty("供应商ID") + private String supplierId; + + /** + * 供应商名称 + */ + @ApiModelProperty("供应商名称") + private String supplierName; + public QueryProductBo() { } @@ -131,5 +141,9 @@ public class QueryProductBo extends BaseBo { ProductService productService = ApplicationUtil.getBean(ProductService.class); this.stock = productService.getStock(dto.getId()); + + SupplierService supplierService = ApplicationUtil.getBean(SupplierService.class); + Supplier supplier = supplierService.findById(dto.getSupplierId()); + this.supplierName = ObjectUtil.isNotNull(supplier) ? supplier.getName() : ""; } } diff --git a/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/entity/Product.java b/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/entity/Product.java index 8c3ed0c..9d37a35 100644 --- a/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/entity/Product.java +++ b/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/entity/Product.java @@ -8,6 +8,8 @@ import com.lframework.starter.web.dto.BaseDto; import com.lframework.xingyun.basedata.enums.ProductType; import java.math.BigDecimal; import java.time.LocalDateTime; + +import io.swagger.annotations.ApiModelProperty; import lombok.Data; /** @@ -141,4 +143,9 @@ public class Product extends BaseEntity implements BaseDto { */ @TableField(fill = FieldFill.INSERT_UPDATE) private LocalDateTime updateTime; + + /** + * 供应商ID + */ + private String supplierId; } diff --git a/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/excel/product/ProductImportListener.java b/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/excel/product/ProductImportListener.java index f209fdf..467e853 100644 --- a/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/excel/product/ProductImportListener.java +++ b/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/excel/product/ProductImportListener.java @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.lframework.starter.common.constants.PatternPool; import com.lframework.starter.common.exceptions.impl.DefaultClientException; import com.lframework.starter.common.utils.NumberUtil; +import com.lframework.starter.common.utils.ObjectUtil; import com.lframework.starter.common.utils.RegUtil; import com.lframework.starter.common.utils.StringUtil; import com.lframework.starter.web.common.utils.ApplicationUtil; @@ -15,6 +16,7 @@ import com.lframework.starter.web.utils.IdUtil; import com.lframework.xingyun.basedata.entity.Product; import com.lframework.xingyun.basedata.entity.ProductBrand; import com.lframework.xingyun.basedata.entity.ProductCategory; +import com.lframework.xingyun.basedata.entity.Supplier; import com.lframework.xingyun.basedata.enums.ProductType; import com.lframework.xingyun.basedata.service.product.ProductBrandService; import com.lframework.xingyun.basedata.service.product.ProductCategoryService; @@ -22,6 +24,7 @@ import com.lframework.xingyun.basedata.service.product.ProductPurchaseService; import com.lframework.xingyun.basedata.service.product.ProductRetailService; import com.lframework.xingyun.basedata.service.product.ProductSaleService; import com.lframework.xingyun.basedata.service.product.ProductService; +import com.lframework.xingyun.basedata.service.supplier.SupplierService; import com.lframework.xingyun.basedata.vo.product.purchase.CreateProductPurchaseVo; import com.lframework.xingyun.basedata.vo.product.retail.CreateProductRetailVo; import com.lframework.xingyun.basedata.vo.product.sale.CreateProductSaleVo; @@ -190,12 +193,16 @@ public class ProductImportListener extends ExcelImportListener datas = this.getDatas(); for (int i = 0; i < datas.size(); i++) { @@ -206,11 +213,17 @@ public class ProductImportListener extends ExcelImportListener 0) { throw new DefaultClientException("第" + (i + 1) + "行“商品SKU编号”重复,请重新输入"); } + Wrapper checkSupplierWrapper = Wrappers.lambdaQuery(Supplier.class) + .eq(Supplier::getCode, data.getSupplierCode()); + Supplier checkSupplier = supplierService.getOne(checkSupplierWrapper); + if(ObjectUtil.isNull(checkSupplier)){ + throw new DefaultClientException("第" + (i + 1) + "行“供应商编号”不存在,请检查"); + } Product record = new Product(); record.setId(IdUtil.getId()); - + record.setSupplierId(checkSupplier.getId()); record.setCode(data.getCode()); record.setName(data.getName()); if (StringUtil.isNotBlank(data.getShortName())) { diff --git a/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/excel/product/ProductImportModel.java b/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/excel/product/ProductImportModel.java index bb0c6de..d2317e2 100644 --- a/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/excel/product/ProductImportModel.java +++ b/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/excel/product/ProductImportModel.java @@ -5,6 +5,8 @@ import com.alibaba.excel.annotation.ExcelProperty; import com.lframework.starter.web.annotations.excel.ExcelRequired; import com.lframework.starter.web.components.excel.ExcelModel; import java.math.BigDecimal; + +import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data @@ -36,6 +38,13 @@ public class ProductImportModel implements ExcelModel { @ExcelProperty("简称") private String shortName; + /** + * 供应商编号 + */ + @ExcelRequired + @ExcelProperty("供应商编号") + private String supplierCode; + /** * SKU编号 */ diff --git a/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/impl/product/ProductServiceImpl.java b/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/impl/product/ProductServiceImpl.java index 51754d6..b872bf4 100644 --- a/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/impl/product/ProductServiceImpl.java +++ b/xingyun-basedata/src/main/java/com/lframework/xingyun/basedata/impl/product/ProductServiceImpl.java @@ -18,10 +18,7 @@ import com.lframework.starter.web.utils.IdUtil; import com.lframework.starter.web.utils.JsonUtil; import com.lframework.starter.web.utils.PageHelperUtil; import com.lframework.starter.web.utils.PageResultUtil; -import com.lframework.xingyun.basedata.entity.Product; -import com.lframework.xingyun.basedata.entity.ProductBundle; -import com.lframework.xingyun.basedata.entity.ProductProperty; -import com.lframework.xingyun.basedata.entity.ProductPropertyItem; +import com.lframework.xingyun.basedata.entity.*; import com.lframework.xingyun.basedata.enums.ColumnType; import com.lframework.xingyun.basedata.enums.ProductCategoryNodeType; import com.lframework.xingyun.basedata.enums.ProductType; @@ -34,6 +31,7 @@ import com.lframework.xingyun.basedata.service.product.ProductPurchaseService; import com.lframework.xingyun.basedata.service.product.ProductRetailService; import com.lframework.xingyun.basedata.service.product.ProductSaleService; import com.lframework.xingyun.basedata.service.product.ProductService; +import com.lframework.xingyun.basedata.service.supplier.SupplierService; import com.lframework.xingyun.basedata.vo.product.info.CreateProductVo; import com.lframework.xingyun.basedata.vo.product.info.ProductPropertyRelationVo; import com.lframework.xingyun.basedata.vo.product.info.QueryProductSelectorVo; @@ -90,6 +88,9 @@ public class ProductServiceImpl extends BaseMpServiceImpl query(Integer pageIndex, Integer pageSize, QueryProductVo vo) { @@ -214,16 +215,33 @@ public class ProductServiceImpl extends BaseMpServiceImpl + + AND g.supplier_id = #{vo.supplierId} + ORDER BY g.code