|
@@ -6,10 +6,10 @@ import com.ym.mec.common.dto.PmsProductDto;
|
|
|
import com.ym.mec.common.dto.PmsProductQueryParamDto;
|
|
|
import com.ym.mec.common.entity.GoodsSubModel;
|
|
|
import com.ym.mec.common.entity.GoodsSubStockModel;
|
|
|
+import com.ym.mec.common.entity.HttpResponseResult;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.web.WebFeignService;
|
|
|
import com.yonge.cooleshow.admin.dao.*;
|
|
|
-import com.yonge.cooleshow.admin.dao.*;
|
|
|
import com.yonge.cooleshow.admin.dto.HomeStatistical;
|
|
|
import com.yonge.cooleshow.admin.dto.PmsProductParam;
|
|
|
import com.yonge.cooleshow.admin.dto.PmsProductQueryParam;
|
|
@@ -27,7 +27,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
import java.lang.reflect.Method;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
@@ -146,6 +145,7 @@ public class PmsProductServiceImpl implements PmsProductService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public int update(Long id, PmsProductParam productParam) {
|
|
|
if (productParam.getPrice().compareTo(BigDecimal.ZERO) <=0 ) {
|
|
|
throw new BizException("商品价格不能小于等于0");
|
|
@@ -201,6 +201,7 @@ public class PmsProductServiceImpl implements PmsProductService {
|
|
|
List<PmsSkuStock> currSkuList = productParam.getSkuStockList();
|
|
|
//当前没有sku直接删除
|
|
|
if(CollUtil.isEmpty(currSkuList)){
|
|
|
+ syncProductStatus(Collections.singletonList(id), 0);
|
|
|
PmsSkuStockExample skuStockExample = new PmsSkuStockExample();
|
|
|
skuStockExample.createCriteria().andProductIdEqualTo(id);
|
|
|
skuStockMapper.deleteByExample(skuStockExample);
|
|
@@ -225,6 +226,8 @@ public class PmsProductServiceImpl implements PmsProductService {
|
|
|
}
|
|
|
//删除sku
|
|
|
if(CollUtil.isNotEmpty(removeSkuList)){
|
|
|
+ syncSkuStatus(0, removeSkuList);
|
|
|
+
|
|
|
List<Long> removeSkuIds = removeSkuList.stream().map(PmsSkuStock::getId).collect(Collectors.toList());
|
|
|
PmsSkuStockExample removeExample = new PmsSkuStockExample();
|
|
|
removeExample.createCriteria().andIdIn(removeSkuIds);
|
|
@@ -271,14 +274,8 @@ public class PmsProductServiceImpl implements PmsProductService {
|
|
|
|
|
|
@Override
|
|
|
public int updatePublishStatus(List<Long> ids, Integer publishStatus) {
|
|
|
- // 商品状态同步
|
|
|
- List<GoodsSubModel> collect = ids.stream().map(next -> {
|
|
|
- GoodsSubModel goodsSubModel = new GoodsSubModel();
|
|
|
- goodsSubModel.setMallGoodsId(next.intValue());
|
|
|
- goodsSubModel.setGoodsStatus(1 == publishStatus);
|
|
|
- return goodsSubModel;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- webFeignService.goodsStatusSynchronize(collect);
|
|
|
+
|
|
|
+ syncProductStatus(ids, publishStatus);
|
|
|
|
|
|
PmsProduct record = new PmsProduct();
|
|
|
record.setPublishStatus(publishStatus);
|
|
@@ -287,6 +284,33 @@ public class PmsProductServiceImpl implements PmsProductService {
|
|
|
return productMapper.updateByExampleSelective(record, example);
|
|
|
}
|
|
|
|
|
|
+ private void syncProductStatus(List<Long> ids, Integer publishStatus) {
|
|
|
+
|
|
|
+ // 查询商品的sku
|
|
|
+ PmsSkuStockExample skuStockExample = new PmsSkuStockExample();
|
|
|
+ skuStockExample.createCriteria().andProductIdIn(ids);
|
|
|
+ List<PmsSkuStock> pmsSkuStocks = skuStockMapper.selectByExample(skuStockExample);
|
|
|
+ syncSkuStatus(publishStatus, pmsSkuStocks);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void syncSkuStatus(Integer publishStatus, List<PmsSkuStock> pmsSkuStocks) {
|
|
|
+ if (CollectionUtils.isEmpty(pmsSkuStocks)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 商品状态同步
|
|
|
+ List<GoodsSubModel> collect = pmsSkuStocks.stream().map(o -> {
|
|
|
+ GoodsSubModel goodsSubModel = new GoodsSubModel();
|
|
|
+ goodsSubModel.setMallGoodsId(o.getProductId().intValue());
|
|
|
+ goodsSubModel.setSkuId(o.getId().intValue());
|
|
|
+ goodsSubModel.setGoodsStatus(publishStatus == 1);
|
|
|
+ return goodsSubModel;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ HttpResponseResult<Boolean> booleanHttpResponseResult = webFeignService.goodsStatusSynchronize(collect);
|
|
|
+ if (booleanHttpResponseResult.getCode() != 200) {
|
|
|
+ throw new BizException("商品状态同步失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public int updateRecommendStatus(List<Long> ids, Integer recommendStatus) {
|
|
|
PmsProduct record = new PmsProduct();
|
|
@@ -308,13 +332,7 @@ public class PmsProductServiceImpl implements PmsProductService {
|
|
|
@Override
|
|
|
public int updateDeleteStatus(List<Long> ids, Integer deleteStatus) {
|
|
|
if (1 == deleteStatus) {
|
|
|
- List<GoodsSubModel> collect = ids.stream().map(next -> {
|
|
|
- GoodsSubModel goodsSubModel = new GoodsSubModel();
|
|
|
- goodsSubModel.setMallGoodsId(next.intValue());
|
|
|
- goodsSubModel.setGoodsStatus(false);
|
|
|
- return goodsSubModel;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- webFeignService.goodsStatusSynchronize(collect);
|
|
|
+ syncProductStatus(ids, 0);
|
|
|
// 更新库存
|
|
|
PmsSkuStockExample example = new PmsSkuStockExample();
|
|
|
example.createCriteria().andProductIdIn(ids);
|