|
|
@@ -62,6 +62,7 @@ import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.jdbc.core.StatementCallback;
|
|
|
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
@@ -161,6 +162,9 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Autowired
|
|
|
private StoreInService storeInService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
|
|
|
+
|
|
|
@Autowired
|
|
|
private UASBatchPutOnPropertyService uasBatchPutOnPropertyService;
|
|
|
|
|
|
@@ -1226,18 +1230,27 @@ public class ProductServiceImpl implements ProductService {
|
|
|
// List<Goods> goodses = productDetailPutOn(sourceAppNotPutOn, storeName, storeid, currency, property);
|
|
|
// goodsList.addAll(goodses);
|
|
|
// }
|
|
|
-
|
|
|
- List<Product> sourceAppNotPutOn = productDao.findByEnUUAndSourceAppNotPutOn(uu, StringConstant.ERP);
|
|
|
- if (sourceAppNotPutOn.size() == 0) {
|
|
|
+ String sql = "select pr_id from products where pr_batchcount = 0 and pr_sourceapp = 'ERP' and pr_reserve <> 0 and pr_reserve is not null and pr_b2cenabled = 1 and pr_enuu = (:enuu) and pr_id not in (select DISTINCT go_productid from trade$goods where go_productid is not null);";
|
|
|
+ Map<String, Long> map = new HashMap<>();
|
|
|
+ map.put("enuu", uu);
|
|
|
+ List<Long> longList = namedParameterJdbcTemplate.queryForList(sql, map, Long.class);
|
|
|
+ if (longList.size() == 0) {
|
|
|
return new ResultMap(CodeType.OK.code(), "没有可上架的信息", null);
|
|
|
}
|
|
|
+ List<Product> sourceAppNotPutOn = productDao.findProductInIds(longList);
|
|
|
+ List<ProductDetail> productDetails = productDetailDao.findByProductIds(longList);
|
|
|
+ for (Product product : sourceAppNotPutOn) {
|
|
|
+ for (ProductDetail detail : productDetails) {
|
|
|
+ if (product.getId().longValue() == detail.getProductId().longValue()) {
|
|
|
+ product.setProductDetail(detail);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
List<Goods> goodses = productDetailPutOn(sourceAppNotPutOn, storeName, storeid, currency, property);
|
|
|
goodsList.addAll(goodses);
|
|
|
List<Goods> result = new ArrayList<Goods>();
|
|
|
- goodsService.publishByBatch(goodsList, uuids, result);
|
|
|
- for (String uuid : uuids) {
|
|
|
- goodsService.updateComponentTradeInfos(uuid);
|
|
|
- }
|
|
|
+ goodsService.publishERPProductByBatch(goodsList, uuids, result);
|
|
|
List<Product> list = new ArrayList<>();
|
|
|
for (Goods goods : result) {
|
|
|
for (Product product : sourceAppNotPutOn) {
|
|
|
@@ -1248,6 +1261,9 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
}
|
|
|
productDao.save(list);
|
|
|
+ for (String uuid : uuids) {
|
|
|
+ goodsService.updateComponentTradeInfos(uuid);
|
|
|
+ }
|
|
|
String message = "";
|
|
|
if (result.size() != 0) {
|
|
|
message = "成功上架" + result.size() + "个";
|
|
|
@@ -1262,11 +1278,20 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 产品信息转 库存信息
|
|
|
+ *
|
|
|
+ * @param products 上架的产品
|
|
|
+ * @param storeName 店铺名称
|
|
|
+ * @param storeid 店铺id
|
|
|
+ * @param currency 币别信息
|
|
|
+ * @param property 批量上架的配置信息
|
|
|
+ * @return
|
|
|
+ */
|
|
|
private List<Goods> productDetailPutOn(List<Product> products, String storeName, String storeid, String currency, UASBatchPutOnProperty property) {
|
|
|
List<Goods> goodses = new ArrayList<>();
|
|
|
for (Product product : products) {
|
|
|
- ProductDetail productDetail = productDetailDao.findByProductId(product.getId());
|
|
|
- ResultMap resultMap = productsConvertGoods(product, productDetail, storeName, storeid, currency, property);
|
|
|
+ ResultMap resultMap = productsConvertGoods(product, storeName, storeid, currency, property);
|
|
|
if (resultMap.getCode() == CodeType.OK.code()) {
|
|
|
goodses.add((Goods) resultMap.getData());
|
|
|
}
|
|
|
@@ -1278,10 +1303,10 @@ public class ProductServiceImpl implements ProductService {
|
|
|
* 物料转 goods 信息
|
|
|
*
|
|
|
* @param product
|
|
|
- * @param detail
|
|
|
* @return
|
|
|
*/
|
|
|
- private ResultMap productsConvertGoods(Product product, ProductDetail detail, String storeName, String storeid, String currency, UASBatchPutOnProperty property) {
|
|
|
+ private ResultMap productsConvertGoods(Product product, String storeName, String storeid, String currency, UASBatchPutOnProperty property) {
|
|
|
+ ProductDetail detail = product.getProductDetail();
|
|
|
Goods g = new Goods();
|
|
|
g.setProductid(product.getId());
|
|
|
g.setUnit(product.getUnit());
|
|
|
@@ -1300,45 +1325,47 @@ public class ProductServiceImpl implements ProductService {
|
|
|
g.setMaxDelivery(property.getMaxDelivery());
|
|
|
g.setMinDelivery(property.getMinDelivery());
|
|
|
g.setProdNum(product.getProdNum());
|
|
|
- g.setTag(StringConstant.INIT_TAG);
|
|
|
+ List<String> tags = goodsDao.findTagByProductid(product.getId());
|
|
|
+ Integer i = 1;
|
|
|
+ String tag = StringConstant.SELF_TAG;
|
|
|
+ while(tags.contains(tag + i)) {
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ g.setTag(tag + i);
|
|
|
g.setBreakUp(Boolean.FALSE);
|
|
|
g.setReserve(product.getErpReserve());
|
|
|
+ String packaging = (detail == null || detail.getPackaging() == null) ? product.getPackaging(): detail.getPackaging();
|
|
|
+ packaging = (packaging == null) ? StringConstant.DEFAULTPACKAGING : packaging;
|
|
|
+ g.setPackaging(packaging);
|
|
|
|
|
|
- g.setPackaging((detail == null || detail.getPackaging() == null) ? product.getPackaging(): detail.getPackaging());
|
|
|
- if (g.getPackaging() == null) {
|
|
|
- g.setPackaging(StringConstant.DEFAULTPACKAGING);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- g.setProduceDate((detail == null || detail.getProduceDate() == null) ? product.getProduceDate() : detail.getProduceDate());
|
|
|
- if (g.getProduceDate() == null) {
|
|
|
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
- String format = formatter.format(new Date());
|
|
|
+ String produceDate = (detail == null || detail.getProduceDate() == null) ? product.getProduceDate() : detail.getProduceDate();
|
|
|
+ if (produceDate == null) {
|
|
|
+ String format = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
|
|
g.setProduceDate(format);
|
|
|
+ } else {
|
|
|
+ g.setProduceDate(produceDate);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- g.setMinPackQty((detail == null || detail.getMinPackQty() == null) ? product.getMinPackQty() : detail.getMinPackQty());
|
|
|
- g.setMinBuyQty(detail != null ? detail.getMinBuyQty() : null);
|
|
|
- int minPackQty = NumberUtil.compare(g.getMinPackQty(), DoubleConstant.zero);
|
|
|
- int minBuyQty = NumberUtil.compare(g.getMinBuyQty(), DoubleConstant.zero);
|
|
|
- if (minPackQty == 0 && minBuyQty == 0) {
|
|
|
+ Double minPackQty = (detail == null || detail.getMinPackQty() == null) ? product.getMinPackQty() : detail.getMinPackQty();
|
|
|
+ Double minBuyQty = detail != null ? detail.getMinBuyQty() : null;
|
|
|
+ int minPackQtyCom = NumberUtil.compare(minPackQty, DoubleConstant.zero);
|
|
|
+ int minBuyQtyCom = NumberUtil.compare(minBuyQty, DoubleConstant.zero);
|
|
|
+ if (minPackQtyCom == 0 && minBuyQtyCom == 0) {
|
|
|
return new ResultMap(CodeType.NOT_COMPLETE_INFO, "上架必填信息缺失");
|
|
|
} else {
|
|
|
- if (minPackQty == 0 || minBuyQty == 0) {
|
|
|
- Double d = minBuyQty == 0 ? g.getMinPackQty() : g.getMinBuyQty();
|
|
|
- g.setMinBuyQty(d);
|
|
|
- g.setMinPackQty(d);
|
|
|
- }
|
|
|
- double remainder = g.getMinBuyQty() % g.getMinPackQty();
|
|
|
- if (NumberUtil.compare(remainder, DoubleConstant.zero) != 0) {
|
|
|
- g.setMinBuyQty(NumberUtil.sub(g.getMinBuyQty(), remainder));
|
|
|
+ if (minPackQtyCom == 0 || minBuyQtyCom == 0) {
|
|
|
+ minPackQty = minBuyQtyCom == 0 ? minPackQty : minBuyQty;
|
|
|
+ minBuyQty = minPackQty;
|
|
|
}
|
|
|
- int k = NumberUtil.compare(g.getMinBuyQty(), g.getMinPackQty());
|
|
|
+ double remainder = minBuyQty % minPackQty;
|
|
|
+ minBuyQty = NumberUtil.sub(minBuyQty, remainder);
|
|
|
+ int k = NumberUtil.compare(minBuyQty, minPackQty);
|
|
|
if (k < 0) {
|
|
|
- g.setMinBuyQty(g.getMinPackQty());
|
|
|
+ minBuyQty = minPackQty;
|
|
|
}
|
|
|
}
|
|
|
+ g.setMinPackQty(minPackQty);
|
|
|
+ g.setMinBuyQty(minBuyQty);
|
|
|
double price = NumberUtil.mul(detail.getPrice(), property.getFluctuateRate());
|
|
|
price = NumberUtil.fractionNumCeil(price, IntegerConstant.PRICE_FRACTION);
|
|
|
List<GoodsQtyPrice> list = new ArrayList<>();
|