|
@@ -4,14 +4,17 @@ import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.ym.mec.auth.api.entity.SysUser;
|
|
|
+import com.yonge.cooleshow.mall.common.exception.Asserts;
|
|
|
import com.yonge.cooleshow.mbg.mapper.*;
|
|
|
import com.yonge.cooleshow.mbg.model.*;
|
|
|
import com.yonge.cooleshow.portal.dao.PortalProductDao;
|
|
|
import com.yonge.cooleshow.portal.domain.PmsPortalProductDetail;
|
|
|
import com.yonge.cooleshow.portal.domain.PmsProductCategoryNode;
|
|
|
+import com.yonge.cooleshow.portal.domain.ProductStock;
|
|
|
import com.yonge.cooleshow.portal.dto.ProductCategorySmallVo;
|
|
|
import com.yonge.cooleshow.portal.dto.ProductSearchConditionVo;
|
|
|
import com.yonge.cooleshow.portal.dto.ShareProductVo;
|
|
|
+import com.yonge.cooleshow.portal.dto.StockOperateModel;
|
|
|
import com.yonge.cooleshow.portal.service.PmsPortalProductService;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -19,6 +22,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -48,6 +52,8 @@ public class PmsPortalProductServiceImpl implements PmsPortalProductService {
|
|
|
@Autowired
|
|
|
private PortalProductDao portalProductDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private PmsProductMapper pmsProductMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private PmsProductAttributeCategoryMapper productAttributeCategoryMapper;
|
|
@@ -209,6 +215,64 @@ public class PmsPortalProductServiceImpl implements PmsPortalProductService {
|
|
|
return shareProductVo;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void reduceStock(List<StockOperateModel> model, String stockType) {
|
|
|
+
|
|
|
+
|
|
|
+ List<ProductStock> productList = new ArrayList<>();
|
|
|
+ Map<Long, List<StockOperateModel>> collect = model.stream().collect(Collectors.groupingBy(
|
|
|
+ StockOperateModel::getProductId));
|
|
|
+ for (Map.Entry<Long, List<StockOperateModel>> entry : collect.entrySet()) {
|
|
|
+ ProductStock productStock = new ProductStock();
|
|
|
+ List<StockOperateModel> value = entry.getValue();
|
|
|
+ if (CollectionUtils.isEmpty(value)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ int sum = value.stream().mapToInt(StockOperateModel::getCount).sum();
|
|
|
+ productStock.setProductId(entry.getKey());
|
|
|
+ productStock.setStock(sum);
|
|
|
+ productList.add(productStock);
|
|
|
+ }
|
|
|
+ switch (stockType) {
|
|
|
+ case "lock" :
|
|
|
+
|
|
|
+ for (StockOperateModel stockOperateModel : model) {
|
|
|
+ int i = skuStockMapper.lockStock(stockOperateModel.getProductSkuId(), stockOperateModel.getCount());
|
|
|
+ if (i ==0) {
|
|
|
+ Asserts.fail("库存不足");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (ProductStock product : productList) {
|
|
|
+ if (product.getStock() > 0) {
|
|
|
+ int i = pmsProductMapper.lockStock(product.getProductId(), product.getStock());
|
|
|
+ if (i == 0) {
|
|
|
+ Asserts.fail("库存不足");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "unlock" :
|
|
|
+
|
|
|
+ portalProductDao.unlockSku(model);
|
|
|
+
|
|
|
+
|
|
|
+ portalProductDao.unlockProduct(productList);
|
|
|
+ break;
|
|
|
+ case "reduce" :
|
|
|
+
|
|
|
+ portalProductDao.reduceSku(model);
|
|
|
+
|
|
|
+
|
|
|
+ portalProductDao.updateProductStock(productList);
|
|
|
+ break;
|
|
|
+ default: break;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private List<PmsProductAttributeCategory> getHomeProductAttributeCategory() {
|
|
|
PmsProductAttributeCategoryExample example = new PmsProductAttributeCategoryExample();
|