@ -44,6 +44,7 @@ import org.springframework.transaction.support.TransactionTemplate;
import javax.annotation.Resource ;
import javax.annotation.Resource ;
import java.util.* ;
import java.util.* ;
import java.util.function.Function ;
import java.util.stream.Collectors ;
import java.util.stream.Collectors ;
import java.util.stream.Stream ;
import java.util.stream.Stream ;
@ -282,7 +283,12 @@ public class StoreProductServiceImpl extends ServiceImpl<StoreProductDao, StoreP
throw new CrmebException ( "单规格商品属性值不能大于1" ) ;
throw new CrmebException ( "单规格商品属性值不能大于1" ) ;
}
}
}
}
if ( request . getOrderProductNums ( ) = = null ) {
request . setOrderProductNums ( 1 ) ;
}
if ( request . getUserProductNums ( ) = = null ) {
request . setUserProductNums ( 1 ) ;
}
StoreProduct storeProduct = new StoreProduct ( ) ;
StoreProduct storeProduct = new StoreProduct ( ) ;
BeanUtils . copyProperties ( request , storeProduct ) ;
BeanUtils . copyProperties ( request , storeProduct ) ;
storeProduct . setId ( null ) ;
storeProduct . setId ( null ) ;
@ -360,7 +366,7 @@ public class StoreProductServiceImpl extends ServiceImpl<StoreProductDao, StoreP
StoreProductDescription spd = new StoreProductDescription ( ) ;
StoreProductDescription spd = new StoreProductDescription ( ) ;
spd . setDescription ( request . getContent ( ) . length ( ) > 0 ? systemAttachmentService . clearPrefix ( request . getContent ( ) ) : "" ) ;
spd . setDescription ( request . getContent ( ) . length ( ) > 0 ? systemAttachmentService . clearPrefix ( request . getContent ( ) ) : "" ) ;
spd . setType ( Constants . PRODUCT_TYPE_NORMAL ) ;
spd . setType ( Constants . PRODUCT_TYPE_NORMAL ) ;
checkExistThirdPartySkuNo ( new ArrayList < > ( ) , attrValueList , null ) ;
Boolean execute = transactionTemplate . execute ( e - > {
Boolean execute = transactionTemplate . execute ( e - > {
save ( storeProduct ) ;
save ( storeProduct ) ;
@ -386,7 +392,35 @@ public class StoreProductServiceImpl extends ServiceImpl<StoreProductDao, StoreP
return execute ;
return execute ;
}
}
private void checkExistThirdPartySkuNo ( List < StoreProductAttrValue > attrValueAddList , List < StoreProductAttrValue > attrValueUpdateList , StoreProduct storeProduct ) {
List < StoreProductAttrValue > allAttrValueAddList = CollUtil . newArrayList ( ) ;
allAttrValueAddList . addAll ( attrValueAddList ) ;
allAttrValueAddList . addAll ( attrValueUpdateList ) ;
List < String > distinctSku = allAttrValueAddList . stream ( ) . map ( StoreProductAttrValue : : getBarCode ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
if ( distinctSku . size ( ) ! = allAttrValueAddList . size ( ) ) {
throw new CrmebException ( "商品重复,请重新选择" ) ;
}
Map < String , XsSkuInfo > skuInfoMap = xsbuyDao . selectBySkuNos ( distinctSku ) . stream ( ) . collect ( Collectors . toMap ( XsSkuInfo : : getSkuNo , Function . identity ( ) , ( v1 , v2 ) - > v1 ) ) ;
List < StoreProductAttrValue > list = storeProductAttrValueService . list ( new LambdaQueryWrapper < StoreProductAttrValue > ( ) . in ( StoreProductAttrValue : : getBarCode , distinctSku ) . eq ( StoreProductAttrValue : : getIsDel , 0 ) ) ;
if ( CollUtil . isNotEmpty ( list ) ) {
for ( StoreProductAttrValue storeProductAttrValue : list ) {
XsSkuInfo xsSkuInfo = skuInfoMap . get ( storeProductAttrValue . getBarCode ( ) ) ;
if ( xsSkuInfo = = null ) {
throw new CrmebException ( String . format ( "商品编码未找到:%s" , storeProductAttrValue . getBarCode ( ) ) ) ;
}
if ( storeProduct = = null ) {
String msg = String . format ( "商品编号所填%s/%s已在商品id为%s中出现过" , xsSkuInfo . getSkuName ( ) , xsSkuInfo . getSkuNo ( ) , storeProductAttrValue . getProductId ( ) ) ;
throw new CrmebException ( msg ) ;
} else {
if ( storeProductAttrValue . getId ( ) . equals ( storeProduct . getId ( ) ) ) {
String msg = String . format ( "商品编号所填%s/%s已在商品id为%s中出现过" , xsSkuInfo . getSkuName ( ) , xsSkuInfo . getSkuNo ( ) , storeProductAttrValue . getProductId ( ) ) ;
throw new CrmebException ( msg ) ;
}
}
}
}
}
/ * *
/ * *
* 商品sku
* 商品sku
* @param attrValue json字符串
* @param attrValue json字符串
@ -454,7 +488,12 @@ public class StoreProductServiceImpl extends ServiceImpl<StoreProductDao, StoreP
throw new CrmebException ( "单规格商品属性值不能大于1" ) ;
throw new CrmebException ( "单规格商品属性值不能大于1" ) ;
}
}
}
}
if ( storeProductRequest . getOrderProductNums ( ) = = null ) {
storeProductRequest . setOrderProductNums ( 1 ) ;
}
if ( storeProductRequest . getUserProductNums ( ) = = null ) {
storeProductRequest . setUserProductNums ( 1 ) ;
}
StoreProduct tempProduct = getById ( storeProductRequest . getId ( ) ) ;
StoreProduct tempProduct = getById ( storeProductRequest . getId ( ) ) ;
if ( ObjectUtil . isNull ( tempProduct ) ) {
if ( ObjectUtil . isNull ( tempProduct ) ) {
throw new CrmebException ( "商品不存在" ) ;
throw new CrmebException ( "商品不存在" ) ;
@ -539,7 +578,7 @@ public class StoreProductServiceImpl extends ServiceImpl<StoreProductDao, StoreP
spd . setDescription ( storeProductRequest . getContent ( ) . length ( ) > 0 ? systemAttachmentService . clearPrefix ( storeProductRequest . getContent ( ) ) : "" ) ;
spd . setDescription ( storeProductRequest . getContent ( ) . length ( ) > 0 ? systemAttachmentService . clearPrefix ( storeProductRequest . getContent ( ) ) : "" ) ;
spd . setType ( Constants . PRODUCT_TYPE_NORMAL ) ;
spd . setType ( Constants . PRODUCT_TYPE_NORMAL ) ;
spd . setProductId ( storeProduct . getId ( ) ) ;
spd . setProductId ( storeProduct . getId ( ) ) ;
checkExistThirdPartySkuNo ( attrValueAddList , attrValueUpdateList , tempProduct ) ;
Boolean execute = transactionTemplate . execute ( e - > {
Boolean execute = transactionTemplate . execute ( e - > {
dao . updateById ( storeProduct ) ;
dao . updateById ( storeProduct ) ;