|
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ym.mec.biz.dal.dao.*;
|
|
|
import com.ym.mec.biz.dal.dto.BasicUserDto;
|
|
|
+import com.ym.mec.biz.dal.dto.ComplementGoodsDto;
|
|
|
import com.ym.mec.biz.dal.dto.GoodsSellDto;
|
|
|
import com.ym.mec.biz.dal.entity.Goods;
|
|
|
import com.ym.mec.biz.dal.entity.GoodsProcurement;
|
|
@@ -14,11 +15,14 @@ import com.ym.mec.biz.dal.page.GoodsQuery;
|
|
|
import com.ym.mec.biz.dal.page.GoodsQueryInfo;
|
|
|
import com.ym.mec.biz.service.*;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
+import com.ym.mec.common.dto.PmsProductDto;
|
|
|
+import com.ym.mec.common.dto.PmsProductQueryParamDto;
|
|
|
import com.ym.mec.common.entity.UploadReturnBean;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.service.IdGeneratorService;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
import com.ym.mec.common.tenant.TenantContextHolder;
|
|
|
+import com.ym.mec.mall.MallFeignService;
|
|
|
import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
|
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
|
import com.ym.mec.util.excel.POIUtil;
|
|
@@ -36,6 +40,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.io.InputStream;
|
|
|
import java.math.BigDecimal;
|
|
@@ -65,6 +70,8 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
private SellOrderDao sellOrderDao;
|
|
|
@Autowired
|
|
|
private OrganizationDao organizationDao;
|
|
|
+ @Resource
|
|
|
+ private MallFeignService mallFeignService;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Integer, Goods> getDAO() {
|
|
@@ -154,24 +161,35 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void addGoods(Goods goods, Integer operatorId) {
|
|
|
if(StringUtils.isBlank(goods.getSn())){
|
|
|
throw new BizException("请指定商品货号");
|
|
|
}
|
|
|
+ if(StringUtils.isEmpty(goods.getComplementGoodsJson())){
|
|
|
+ throw new BizException("请指定子商品");
|
|
|
+ }
|
|
|
Goods existsGood = goodsDao.lockBySn(goods.getSn());
|
|
|
if(Objects.nonNull(existsGood)){
|
|
|
throw new BizException("商品货号重复");
|
|
|
- }else{
|
|
|
- if(Objects.isNull(goods.getStockCount())){
|
|
|
- goods.setStockCount(0);
|
|
|
- }
|
|
|
- if(Objects.isNull(goods.getTaxStockCount())){
|
|
|
- goods.setTaxStockCount(0);
|
|
|
- }
|
|
|
- goods.setSellCount(0);
|
|
|
- goodsDao.insert(goods);
|
|
|
}
|
|
|
+ List<ComplementGoodsDto> complementGoods = JSON.parseArray(goods.getComplementGoodsJson(), ComplementGoodsDto.class);
|
|
|
+ //获取最小的库存数
|
|
|
+ String skuIds = complementGoods.stream().map(e -> e.getSkuStockId().toString()).collect(Collectors.joining(","));
|
|
|
+ PmsProductQueryParamDto paramDto = new PmsProductQueryParamDto();
|
|
|
+ paramDto.setSkuStockIds(skuIds);
|
|
|
+ paramDto.setPublishStatus(1);
|
|
|
+ paramDto.setPageSize(1000);
|
|
|
+ paramDto.setPageNum(1);
|
|
|
+ List<PmsProductDto> productList = mallFeignService.getProductList(paramDto).getRows();
|
|
|
+ if(CollectionUtils.isEmpty(productList)){
|
|
|
+ throw new BizException("子商品不存在");
|
|
|
+ }
|
|
|
+ //获取最小库存数量
|
|
|
+ Integer stock = productList.stream().map(PmsProductDto::getStock).min(Integer::compareTo).get();
|
|
|
+ goods.setStockCount(stock);
|
|
|
+ goods.setSellCount(0);
|
|
|
+ goodsDao.insert(goods);
|
|
|
}
|
|
|
|
|
|
@Override
|