图库新增图片功能
This commit is contained in:
parent
70e5db0fcf
commit
c1dfffa26e
@ -21,7 +21,7 @@ import java.util.List;
|
|||||||
@ApiModel(value = "商品库的商品", description = "商品库的商品表")
|
@ApiModel(value = "商品库的商品", description = "商品库的商品表")
|
||||||
public class LibraryProduct implements Serializable {
|
public class LibraryProduct implements Serializable {
|
||||||
|
|
||||||
@TableId(value = "id", type = IdType.INPUT)
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
@ApiModelProperty(value = "商品ID", example = "1001")
|
@ApiModelProperty(value = "商品ID", example = "1001")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,18 @@ public class LibraryProductDTO implements Serializable {
|
|||||||
private String keywords;
|
private String keywords;
|
||||||
private String thumb;
|
private String thumb;
|
||||||
private BigDecimal price;
|
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<ProductImage> product_image_list;
|
private List<ProductImage> product_image_list;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -185,7 +185,7 @@ public class LibraryProductImpl extends BaseServiceImpl<LibraryProductMapper, Li
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = ApiException.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public CommonResult updateBatchLibraryProductDTO(List<LibraryProductDTO> products) {
|
public CommonResult updateBatchLibraryProductDTO(List<LibraryProductDTO> products) {
|
||||||
List<LibraryProduct> updateProductList = new ArrayList<>();
|
List<LibraryProduct> updateProductList = new ArrayList<>();
|
||||||
UserDto userDto=ContextUtil.getCurrentUser();
|
UserDto userDto=ContextUtil.getCurrentUser();
|
||||||
@ -193,18 +193,58 @@ public class LibraryProductImpl extends BaseServiceImpl<LibraryProductMapper, Li
|
|||||||
if(userDto.getRole_id()!=9){
|
if(userDto.getRole_id()!=9){
|
||||||
throw new ApiException("权限不足");
|
throw new ApiException("权限不足");
|
||||||
}
|
}
|
||||||
List<String> updateTableIds=new ArrayList<>();
|
// List<String> updateTableIds=new ArrayList<>();
|
||||||
List<LibraryProductImage> updateProductImageList=new ArrayList<>();
|
List<LibraryProductImage> updateProductImageList=new ArrayList<>();
|
||||||
List<LibraryProductImage> addProductImageList=new ArrayList<>();
|
List<LibraryProductImage> addProductImageList=new ArrayList<>();
|
||||||
|
|
||||||
products.forEach(product->{
|
products.forEach(product->{
|
||||||
if (null==product.getId()){
|
|
||||||
throw new ApiException("id is null");
|
|
||||||
}
|
|
||||||
LibraryProduct libraryProduct=new LibraryProduct();
|
LibraryProduct libraryProduct=new LibraryProduct();
|
||||||
libraryProduct.setId(product.getId());
|
|
||||||
libraryProduct.setName(product.getName());
|
libraryProduct.setName(product.getName());
|
||||||
libraryProduct.setThumb(product.getThumb());
|
libraryProduct.setThumb(product.getThumb());
|
||||||
libraryProduct.setBarcode(product.getBarcode());
|
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<LibraryProduct> 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()){
|
if(null!=product.getProduct_image_list()&&!product.getProduct_image_list().isEmpty()){
|
||||||
for(LibraryProductDTO.ProductImage productImage: product.getProduct_image_list()){
|
for(LibraryProductDTO.ProductImage productImage: product.getProduct_image_list()){
|
||||||
LibraryProductImage libraryProductImage=new LibraryProductImage();
|
LibraryProductImage libraryProductImage=new LibraryProductImage();
|
||||||
@ -215,31 +255,35 @@ public class LibraryProductImpl extends BaseServiceImpl<LibraryProductMapper, Li
|
|||||||
updateProductImageList.add(libraryProductImage);
|
updateProductImageList.add(libraryProductImage);
|
||||||
}else {
|
}else {
|
||||||
libraryProductImage.setImageUrl(productImage.getImageUrl());
|
libraryProductImage.setImageUrl(productImage.getImageUrl());
|
||||||
libraryProductImage.setProductId(productImage.getProductId());
|
Long productId=productImage.getProductId();
|
||||||
|
if(null==productId){
|
||||||
|
productId=libraryProduct.getId();
|
||||||
|
}
|
||||||
|
libraryProductImage.setProductId(productId);
|
||||||
libraryProductImage.setStatus(1);
|
libraryProductImage.setStatus(1);
|
||||||
libraryProductImage.setIsMain(false);
|
libraryProductImage.setIsMain(false);
|
||||||
addProductImageList.add(libraryProductImage);
|
addProductImageList.add(libraryProductImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateProductList.add(libraryProduct);
|
updateProductList.add(libraryProduct);
|
||||||
updateTableIds.add(ConstantRedis.Cache_NameSpace+"library_product:"+product.getId());
|
//updateTableIds.add(ConstantRedis.Cache_NameSpace+"library_product:"+product.getId());
|
||||||
});
|
});
|
||||||
boolean result=this.updateBatchById(updateProductList,updateProductList.size());
|
// boolean result=false;
|
||||||
|
//// if(!isAdd.get()){
|
||||||
|
//// result=this.updateBatchById(updateProductList,updateProductList.size());
|
||||||
|
//// }
|
||||||
if(!updateProductImageList.isEmpty()){
|
if(!updateProductImageList.isEmpty()){
|
||||||
libraryProductImageService.updateBatchById(updateProductImageList,updateProductImageList.size());
|
libraryProductImageService.updateBatchById(updateProductImageList,updateProductImageList.size());
|
||||||
}
|
}
|
||||||
if(!addProductImageList.isEmpty()){
|
if(!addProductImageList.isEmpty()){
|
||||||
libraryProductImageService.saveBatch(addProductImageList,addProductImageList.size());
|
libraryProductImageService.saveBatch(addProductImageList,addProductImageList.size());
|
||||||
}
|
}
|
||||||
|
// if(result){
|
||||||
if(result){
|
// redisService.del(updateTableIds);
|
||||||
redisService.del(updateTableIds);
|
// return CommonResult.success("保存成功");
|
||||||
return CommonResult.success("保存成功");
|
// }
|
||||||
}
|
return CommonResult.success("保存成功");
|
||||||
return CommonResult.failed("保存失败");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user