diff --git a/mall-common/src/main/java/com/suisung/mall/common/modules/library/LibraryProduct.java b/mall-common/src/main/java/com/suisung/mall/common/modules/library/LibraryProduct.java index 8824bbff..15a93cf0 100644 --- a/mall-common/src/main/java/com/suisung/mall/common/modules/library/LibraryProduct.java +++ b/mall-common/src/main/java/com/suisung/mall/common/modules/library/LibraryProduct.java @@ -21,7 +21,7 @@ import java.util.List; @ApiModel(value = "商品库的商品", description = "商品库的商品表") public class LibraryProduct implements Serializable { - @TableId(value = "id", type = IdType.INPUT) + @TableId(value = "id", type = IdType.AUTO) @ApiModelProperty(value = "商品ID", example = "1001") private Long id; diff --git a/mall-common/src/main/java/com/suisung/mall/common/pojo/dto/LibraryProductDTO.java b/mall-common/src/main/java/com/suisung/mall/common/pojo/dto/LibraryProductDTO.java index 526db52c..c5ba8e7b 100644 --- a/mall-common/src/main/java/com/suisung/mall/common/pojo/dto/LibraryProductDTO.java +++ b/mall-common/src/main/java/com/suisung/mall/common/pojo/dto/LibraryProductDTO.java @@ -26,7 +26,18 @@ public class LibraryProductDTO implements Serializable { private String keywords; private String thumb; private BigDecimal price; - + private String sname; + private String title; + private String category_1st; + private String category_2nd; + private String category; + private String brand; + private String spec; + private String made_in; + private String weight; + private String weight_unit; + private String selling_point; + private String intro; private List product_image_list; /** diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/library/service/impl/LibraryProductImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/library/service/impl/LibraryProductImpl.java index f0ef5b6a..45beb56b 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/library/service/impl/LibraryProductImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/library/service/impl/LibraryProductImpl.java @@ -185,7 +185,7 @@ public class LibraryProductImpl extends BaseServiceImpl products) { List updateProductList = new ArrayList<>(); UserDto userDto=ContextUtil.getCurrentUser(); @@ -193,18 +193,58 @@ public class LibraryProductImpl extends BaseServiceImpl updateTableIds=new ArrayList<>(); + // List updateTableIds=new ArrayList<>(); List updateProductImageList=new ArrayList<>(); List addProductImageList=new ArrayList<>(); + products.forEach(product->{ - if (null==product.getId()){ - throw new ApiException("id is null"); - } LibraryProduct libraryProduct=new LibraryProduct(); - libraryProduct.setId(product.getId()); + libraryProduct.setName(product.getName()); libraryProduct.setThumb(product.getThumb()); libraryProduct.setBarcode(product.getBarcode()); + if(null==product.getId()){ + if(StringUtils.isEmpty(libraryProduct.getName())){ + throw new ApiException("商品名称不能为空"); + } + if(StringUtils.isEmpty(libraryProduct.getThumb())){ + throw new ApiException("商品主图不能为空"); + } + QueryWrapper queryWrapper = new QueryWrapper<>(); + if(StringUtils.isNotEmpty(product.getBarcode())){ + queryWrapper.eq("barcode",product.getBarcode()); + long countbarcode= this.count(queryWrapper); + if(countbarcode>0){ + throw new ApiException("存在相同条码的商品"); + } + } + queryWrapper.clear(); + queryWrapper.eq("name",product.getName()); + long countName= this.count(queryWrapper); + if(countName>0){ + throw new ApiException("存在相同名称的商品"); + } + libraryProduct.setSname(product.getSname()); + libraryProduct.setTitle(product.getTitle()); + libraryProduct.setCategory_1st(product.getCategory_1st()); + libraryProduct.setCategory_2nd(product.getCategory_2nd()); + libraryProduct.setCategory(product.getCategory()); + libraryProduct.setBrand(product.getBrand()); + libraryProduct.setSpec(product.getSpec()); + libraryProduct.setMade_in(product.getMade_in()); + libraryProduct.setWeight(product.getWeight()); + libraryProduct.setWeight_unit(product.getWeight_unit()); + libraryProduct.setSelling_point(product.getSelling_point()); + libraryProduct.setIntro(product.getIntro()); + libraryProduct.setPrice(product.getPrice()); + libraryProduct.setKeywords(product.getKeywords()); + libraryProduct.setSource("handle"); + libraryProduct.setStatus(1); + this.saveOrUpdate(libraryProduct); + }else { + libraryProduct.setId(product.getId()); + this.edit(libraryProduct); + } if(null!=product.getProduct_image_list()&&!product.getProduct_image_list().isEmpty()){ for(LibraryProductDTO.ProductImage productImage: product.getProduct_image_list()){ LibraryProductImage libraryProductImage=new LibraryProductImage(); @@ -215,31 +255,35 @@ public class LibraryProductImpl extends BaseServiceImpl