|
@@ -1,22 +1,54 @@
|
|
|
package com.fs.erp.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.erp.domain.ErpGoods;
|
|
|
import com.fs.erp.dto.*;
|
|
|
import com.fs.erp.http.JstErpHttpService;
|
|
|
import com.fs.erp.service.IErpGoodsService;
|
|
|
+import com.fs.his.domain.FsStoreProduct;
|
|
|
+import com.fs.his.domain.FsStoreProductAttrValue;
|
|
|
+import com.fs.his.service.IFsStoreProductAttrValueService;
|
|
|
+import com.fs.his.service.IFsStoreProductService;
|
|
|
+import com.fs.voice.utils.StringUtil;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service("JSTErpGoodsServiceImpl")
|
|
|
public class JSTErpGoodsServiceImpl implements IErpGoodsService {
|
|
|
@Autowired
|
|
|
private JstErpHttpService jstErpHttpService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFsStoreProductService fsStoreProductService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFsStoreProductAttrValueService fsStoreProductAttrValueService;
|
|
|
+
|
|
|
+ // 每次最大处理数量
|
|
|
+ private static final int BATCH_SIZE = 190;
|
|
|
+
|
|
|
@Override
|
|
|
public BaseResponse addGoods(ErpGoods goods) {
|
|
|
+ List<Long> storeProductIds = goods.getProductIdList();
|
|
|
+ JSONArray bulidJSONArray = buildGoods(storeProductIds);
|
|
|
+
|
|
|
+ //调用接口
|
|
|
+ for (int i = 0; i < bulidJSONArray.size(); i += BATCH_SIZE) {
|
|
|
+ JSONObject request=new JSONObject();
|
|
|
+ int end = Math.min(i + BATCH_SIZE, bulidJSONArray.size());
|
|
|
+ request.put("items",bulidJSONArray.subList(i, end));
|
|
|
+ jstErpHttpService.uploadGoods(request);
|
|
|
+ }
|
|
|
+
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -27,7 +59,7 @@ public class JSTErpGoodsServiceImpl implements IErpGoodsService {
|
|
|
ProductResponseDTO productResponseDTO = jstErpHttpService.queryGoods(requestDTO);
|
|
|
List<ProductResponseDTO.ProductInfo> datas = productResponseDTO.getDatas();
|
|
|
ErpGoodsQueryResponse erpGoodsQueryResponse = new ErpGoodsQueryResponse();
|
|
|
- if(CollectionUtils.isNotEmpty(datas)){
|
|
|
+ if (CollectionUtils.isNotEmpty(datas)) {
|
|
|
List<ErpGoods> erpGoodsList = new ArrayList<>();
|
|
|
for (ProductResponseDTO.ProductInfo data : datas) {
|
|
|
ErpGoods erpGoods = new ErpGoods();
|
|
@@ -49,4 +81,46 @@ public class JSTErpGoodsServiceImpl implements IErpGoodsService {
|
|
|
public ErpGoodsStockQueryResponse getGoodsStock(ErpGoodsStockQueryRequert param) {
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建店铺商品上传的参数
|
|
|
+ *
|
|
|
+ * @param storeProductIds
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONArray buildGoods(List<Long> storeProductIds) {
|
|
|
+ JSONArray res = new JSONArray();
|
|
|
+ //商品
|
|
|
+ List<FsStoreProduct> fsStoreProductList = fsStoreProductService.getStoreProductInProductIds(storeProductIds);
|
|
|
+ if (!fsStoreProductList.isEmpty()) {
|
|
|
+
|
|
|
+ Map<Long, FsStoreProduct> productMap = fsStoreProductList.stream().collect(Collectors.toMap(FsStoreProduct::getProductId, p -> p));
|
|
|
+ //商品规格List
|
|
|
+ List<FsStoreProductAttrValue> fsStoreProductAttrValues = fsStoreProductAttrValueService.getFsStoreProductAttrValueListInProductId(storeProductIds);
|
|
|
+
|
|
|
+ //按规格构建商品数据
|
|
|
+ fsStoreProductAttrValues.forEach(v -> {
|
|
|
+ JSONObject productJson = new JSONObject();
|
|
|
+ FsStoreProduct product = productMap.get(v.getProductId());
|
|
|
+ productJson.put("sku_id", product.getBarCode());//商品编码
|
|
|
+ productJson.put("i_id", v.getBrokerage());//款式编码
|
|
|
+ productJson.put("name", product.getProductName());//名称
|
|
|
+ productJson.put("short_name", product.getKeyword());//简称
|
|
|
+ if(StringUtils.isNotEmpty(product.getBrand())){
|
|
|
+ productJson.put("brand", product.getBrand());//品牌
|
|
|
+ }
|
|
|
+ productJson.put("weight", v.getWeight());//重量
|
|
|
+ productJson.put("s_price",v.getPrice());//基本售价
|
|
|
+ productJson.put("c_price", v.getCost());//成本
|
|
|
+ productJson.put("market_price", v.getOtPrice());//市场|吊牌价
|
|
|
+ productJson.put("unit", product.getUnitName());//单位
|
|
|
+ productJson.put("sku_pic", v.getImage());//商品图片
|
|
|
+ productJson.put("pic", product.getImgUrl());//图片地址(款图片)
|
|
|
+ productJson.put("pic_big", v.getImage());//大图地址
|
|
|
+ res.add(productJson);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ return res;
|
|
|
+ }
|
|
|
}
|