|
|
@@ -2441,6 +2441,8 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
Product productInfo = new Product();
|
|
|
CommodityInOutbound inOutbound = null;
|
|
|
+ // 是否需要增加出入库记录
|
|
|
+ boolean needAddInventory = false;
|
|
|
// 物料存在,更新
|
|
|
List<V_ProductPrivate> existProducts = v_productPrivateDao.findProductByPcmpcodeAndPbrandenAndEnUU(product.getCmpCode(), product.getBrand(), enUU);
|
|
|
if (CollectionUtils.isNotEmpty(existProducts)) {
|
|
|
@@ -2451,12 +2453,19 @@ public class ProductServiceImpl implements ProductService {
|
|
|
} else {
|
|
|
// 物料不存在,新增操作
|
|
|
productInfo = product;
|
|
|
+ needAddInventory = true;
|
|
|
}
|
|
|
if (null == productInfo.getStandard()) {
|
|
|
- productInfo.setStandard(IntegerConstant.NO_SHORT);
|
|
|
+ // 判断传入的数据是否是标准的
|
|
|
+ ResultMap criterionResultMap = checkCriterion(product);
|
|
|
+ if (Objects.equals(CodeType.ERROR.code(), criterionResultMap.getCode())) {
|
|
|
+ productInfo.setStandard(IntegerConstant.NO_SHORT);
|
|
|
+ } else {
|
|
|
+ productInfo.setStandard(IntegerConstant.YES_SHORT);
|
|
|
+ }
|
|
|
}
|
|
|
if (StringUtilB2C.isEmpty(productInfo.getProdNum())) {
|
|
|
- String code = "PNUM" + StringUtilB2C.getRandomNumber(6);
|
|
|
+ String code = "PNUM" + createNumberService.getTimeNumber("trade$product_import_num", 8);
|
|
|
productInfo.setProdNum(code);
|
|
|
}
|
|
|
// 最小包装数默认为1
|
|
|
@@ -2470,18 +2479,9 @@ public class ProductServiceImpl implements ProductService {
|
|
|
// 设置库存信息
|
|
|
assignmentGoods(goods, productInfo);
|
|
|
// 保存到商城私有库
|
|
|
- List<ProductPrivate> productPrivates = productPrivateDao.findByPrId(productInfo.getId());
|
|
|
- if (CollectionUtils.isEmpty(productPrivates)) {
|
|
|
- ProductPrivate productPrivate = new ProductPrivate(productInfo.getId());
|
|
|
- productPrivate.setAttach(product.getAttachment());
|
|
|
- productPrivate.setB2cEnabled(IntegerConstant.YES_SHORT);
|
|
|
- productPrivateDao.save(productPrivate);
|
|
|
- } else {
|
|
|
- ProductPrivate productPrivate = productPrivates.get(0);
|
|
|
- if (null == productPrivate.getB2cEnabled() || Objects.equals(IntegerConstant.NO_SHORT, productPrivate.getB2cEnabled())) {
|
|
|
- productPrivate.setB2cEnabled(IntegerConstant.YES_SHORT);
|
|
|
- productPrivateDao.save(productPrivate);
|
|
|
- }
|
|
|
+ addToPrivate(productInfo, product);
|
|
|
+ if (needAddInventory) {
|
|
|
+ inOutbound = initCommodityInOut(productInfo, goods);
|
|
|
}
|
|
|
// 保存出入库信息
|
|
|
if (null != inOutbound) {
|
|
|
@@ -2496,6 +2496,48 @@ public class ProductServiceImpl implements ProductService {
|
|
|
return ResultMap.success();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 新增库存记录
|
|
|
+ *
|
|
|
+ * @param productInfo 物料信息
|
|
|
+ * @return CommodityInOutbound
|
|
|
+ */
|
|
|
+ private CommodityInOutbound initCommodityInOut(Product productInfo, Goods goods) {
|
|
|
+ CommodityInOutbound inOutbound = new CommodityInOutbound(InOutBoundType.OTHER_INBOUND);
|
|
|
+ if (!StringUtils.isEmpty(goods.getQtyPrice())) {
|
|
|
+ goods = Goods.productConvertGoods(goods, productInfo);
|
|
|
+ goods.setReserve(productInfo.getErpReserve());
|
|
|
+ goods = goodsDao.save(goods);
|
|
|
+ logger.info("上架商品库存操作", "卖家中心单个物料上传进行入库操作", "增加库存: " + productInfo.getErpReserve(), goods.getCode(), goods.getId());
|
|
|
+ }
|
|
|
+ InOutboundDetail inOutboundDetail = new InOutboundDetail(productInfo);
|
|
|
+ Set<InOutboundDetail> detailSet = new HashSet<>();
|
|
|
+ detailSet.add(inOutboundDetail);
|
|
|
+ inOutbound.setInOutboundDetails(detailSet);
|
|
|
+ return inOutbound;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存到商城私有库
|
|
|
+ *
|
|
|
+ * @param productInfo
|
|
|
+ * @param product
|
|
|
+ */
|
|
|
+ private void addToPrivate(Product productInfo, Product product) {
|
|
|
+ List<ProductPrivate> productPrivates = productPrivateDao.findByPrId(productInfo.getId());
|
|
|
+ if (CollectionUtils.isEmpty(productPrivates)) {
|
|
|
+ ProductPrivate productPrivate = new ProductPrivate(productInfo.getId());
|
|
|
+ productPrivate.setAttach(product.getAttachment());
|
|
|
+ productPrivateDao.save(productPrivate);
|
|
|
+ } else {
|
|
|
+ ProductPrivate productPrivate = productPrivates.get(0);
|
|
|
+ if (null == productPrivate.getB2cEnabled() || Objects.equals(IntegerConstant.NO_SHORT, productPrivate.getB2cEnabled())) {
|
|
|
+ productPrivate.setB2cEnabled(IntegerConstant.YES_SHORT);
|
|
|
+ productPrivateDao.save(productPrivate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 校验传入的物料信息
|
|
|
*
|
|
|
@@ -2621,7 +2663,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
Goods goods = goodsList.get(0);
|
|
|
Double reserve = goods.getReserve() != null ? goods.getReserve() : 0D + addQty;
|
|
|
goods.setReserve(reserve);
|
|
|
- goodsDao.save(goods);
|
|
|
+ goods = goodsDao.save(goods);
|
|
|
logger.info("上架商品库存操作", "卖家中心单个物料上传进行入库操作", "增加库存: " + addQty, goods.getCode(), goods.getId());
|
|
|
} else if (InOutBoundType.OTHER_OUTBOUND.equals(type)) {
|
|
|
// 出库
|
|
|
@@ -2708,7 +2750,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
if (size == 1) {
|
|
|
GoodsQtyPrice qtyPrice = goods.getOriginalPrices().get(0);
|
|
|
// 前端设置的默认值,不用保存
|
|
|
- if (null == qtyPrice.getPrice()) {
|
|
|
+ if (null == qtyPrice.getUSDPrice() && null == qtyPrice.getRMBPrice()) {
|
|
|
goods.setQtyPrice("");
|
|
|
}
|
|
|
} else if (size > 1) {
|
|
|
@@ -2722,7 +2764,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
throw new IllegalOperatorException("第 " + errMsg.toString() + " 行价格未填写");
|
|
|
}
|
|
|
}
|
|
|
- if (!StringUtils.isEmpty(qtyPrices)) {
|
|
|
+ if (!StringUtils.isEmpty(qtyPrices) && !StringUtils.isEmpty(goods.getQtyPrice())) {
|
|
|
if (CollectionUtils.isNotEmpty(goods.getOriginalPrices())) {
|
|
|
qtyPrices.forEach(qtyPrice -> {
|
|
|
// 分段数量不能超过最大数量
|
|
|
@@ -2735,16 +2777,11 @@ public class ProductServiceImpl implements ProductService {
|
|
|
qtyPrices.get(0).setStart(startQty);
|
|
|
}
|
|
|
goods.setQtyPrice(JSON.toJSONString(qtyPrices));
|
|
|
+ goodsService.setGoodsDefault(goods);
|
|
|
+ boolean autoPublish = goods.getAutoPublish() == null ? true : goods.getAutoPublish();
|
|
|
+ goods.setAutoPublish(autoPublish);
|
|
|
+ goods = goodsDao.save(goods);
|
|
|
+ logger.info("上架商品", "新增上架商品", "通过卖家中心单个物料上传新增上架商品", goods.getCode(), goods.getId());
|
|
|
}
|
|
|
- goodsService.setGoodsDefault(goods);
|
|
|
- boolean autoPublish = goods.getAutoPublish() == null ? true : goods.getAutoPublish();
|
|
|
- goods.setAutoPublish(autoPublish);
|
|
|
- StoreIn storeIn = storeInService.findByEnUU(SystemSession.getUser().getEnterprise().getUu());
|
|
|
- if (storeIn != null && storeIn.getStatus() == StoreStatus.OPENED) {
|
|
|
- goods.setStoreid(storeIn.getUuid());
|
|
|
- goods.setStoreName(storeIn.getStoreName());
|
|
|
- }
|
|
|
- goods = goodsDao.save(goods);
|
|
|
- logger.info("上架商品", "新增上架商品", "通过卖家中心单个物料上传新增上架商品", goods.getCode(), goods.getId());
|
|
|
}
|
|
|
}
|