|
|
@@ -12,6 +12,8 @@ import com.uas.platform.b2c.prod.commodity.model.Goods;
|
|
|
import com.uas.platform.b2c.prod.commodity.model.Product;
|
|
|
import com.uas.platform.b2c.prod.commodity.model.ProductDetail;
|
|
|
import com.uas.platform.b2c.prod.commodity.service.GoodsService;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
@@ -38,17 +40,23 @@ public class ProductDetailERPServiceImpl implements ProductDetailERPService {
|
|
|
@Autowired
|
|
|
private GoodsService goodsService;
|
|
|
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(ProductDetailERPServiceImpl.class);
|
|
|
+
|
|
|
@Override
|
|
|
public boolean uploadProductDetailERP(List<ProductDetailERP> productDetailERPList) {
|
|
|
List<ProductDetail> productDetails = new ArrayList<ProductDetail>();
|
|
|
Long enuu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
for (ProductDetailERP productDetailERP : productDetailERPList) {
|
|
|
ProductDetail productDetail = ModelConverter.convert(productDetailERP);
|
|
|
- List<Product> products = productDao.getProductByEnUUAndProdNum(enuu, productDetail.getCode());
|
|
|
- if (!CollectionUtils.isEmpty(products)) {
|
|
|
- productDetail.setProductId(products.get(0).getId());
|
|
|
+
|
|
|
+ ProductDetail productDetailExist = productDetailDao.findByProductId(productDetail.getProductId());
|
|
|
+ if (productDetailExist != null) {
|
|
|
+ List<Product> products = productDao.getProductByEnUUAndProdNum(enuu, productDetail.getCode());
|
|
|
+ if (!CollectionUtils.isEmpty(products)) {
|
|
|
+ productDetail.setProductId(products.get(0).getId());
|
|
|
+ }
|
|
|
+ productDetails.add(productDetail);
|
|
|
}
|
|
|
- productDetails.add(productDetail);
|
|
|
}
|
|
|
productDetailDao.save(productDetails);
|
|
|
return true;
|
|
|
@@ -58,12 +66,19 @@ public class ProductDetailERPServiceImpl implements ProductDetailERPService {
|
|
|
public void updateReserve(List<ProductDetailERP> productDetailERPList) {
|
|
|
List<ProductDetail> productDetails = new ArrayList<ProductDetail>();
|
|
|
Long enuu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
+ logger.info("size : " + productDetailERPList.size());
|
|
|
for (ProductDetailERP productDetailERP : productDetailERPList) {
|
|
|
List<Product> products = productDao.getProductByEnUUAndProdNum(enuu, productDetailERP.getCode());// 获取对应商城物料信息
|
|
|
if (!CollectionUtils.isEmpty(products)) {
|
|
|
ProductDetail productDetail = productDetailDao.findByProductId(products.get(0).getId());// 获取商城物料信息
|
|
|
+ if (productDetail == null) {// 如果物料交易详情为空,新增物料交易详情
|
|
|
+ productDetail = new ProductDetail();
|
|
|
+ productDetail.setProductId(products.get(0).getId());
|
|
|
+ }
|
|
|
+
|
|
|
if (products.get(0).getCmpUuId() != null) {// 如果为标准器件,更新在售商品信息
|
|
|
Double b2cReserve = goodsDao.getSumReserveByEnUUAndUuidAndStatus(enuu, products.get(0).getCmpUuId(), Status.AVAILABLE.value());
|
|
|
+ b2cReserve = b2cReserve == null ? 0 : b2cReserve;
|
|
|
Double erpReserve = productDetailERP.getReserve();
|
|
|
if (Double.compare(b2cReserve, erpReserve) > 0) {// 如果商城已上架数量大于erp空闲库存,下架部分在售商品
|
|
|
BigDecimal b2cDecimal = BigDecimal.valueOf(b2cReserve);
|