|
@@ -11,6 +11,10 @@ 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.hisStore.domain.FsStoreProductAttrValueScrm;
|
|
|
+import com.fs.hisStore.domain.FsStoreProductScrm;
|
|
|
+import com.fs.hisStore.service.IFsStoreProductAttrValueScrmService;
|
|
|
+import com.fs.hisStore.service.IFsStoreProductScrmService;
|
|
|
import com.fs.voice.utils.StringUtil;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -29,9 +33,13 @@ public class JSTErpGoodsServiceImpl implements IErpGoodsService {
|
|
|
|
|
|
@Autowired
|
|
|
private IFsStoreProductService fsStoreProductService;
|
|
|
+ @Autowired
|
|
|
+ private IFsStoreProductScrmService fsStoreProductScrmService;
|
|
|
|
|
|
@Autowired
|
|
|
private IFsStoreProductAttrValueService fsStoreProductAttrValueService;
|
|
|
+ @Autowired
|
|
|
+ private IFsStoreProductAttrValueScrmService fsStoreProductAttrValueScrmService;
|
|
|
|
|
|
// 每次最大处理数量
|
|
|
private static final int BATCH_SIZE = 190;
|
|
@@ -52,6 +60,21 @@ public class JSTErpGoodsServiceImpl implements IErpGoodsService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public BaseResponse addGoodsScrm(ErpGoods goods) {
|
|
|
+ List<Long> storeProductIds = goods.getProductIdList();
|
|
|
+ JSONArray bulidJSONArray = buildGoodsScrm(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;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public ErpGoodsQueryResponse getGoods(ErpGoodsQueryRequert param) {
|
|
|
ProductQueryRequestDTO requestDTO = new ProductQueryRequestDTO();
|
|
@@ -77,11 +100,81 @@ public class JSTErpGoodsServiceImpl implements IErpGoodsService {
|
|
|
return erpGoodsQueryResponse;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ErpGoodsQueryResponse getGoodsScrm(ErpGoodsQueryRequert param) {
|
|
|
+ ProductQueryRequestDTO requestDTO = new ProductQueryRequestDTO();
|
|
|
+ requestDTO.setSkuIds(param.getCode());
|
|
|
+ ProductResponseDTO productResponseDTO = jstErpHttpService.queryGoods(requestDTO);
|
|
|
+ List<ProductResponseDTO.ProductInfo> datas = productResponseDTO.getDatas();
|
|
|
+ ErpGoodsQueryResponse erpGoodsQueryResponse = new ErpGoodsQueryResponse();
|
|
|
+ if (CollectionUtils.isNotEmpty(datas)) {
|
|
|
+ List<ErpGoods> erpGoodsList = new ArrayList<>();
|
|
|
+ for (ProductResponseDTO.ProductInfo data : datas) {
|
|
|
+ ErpGoods erpGoods = new ErpGoods();
|
|
|
+ erpGoods.setCode(data.getSkuCode());
|
|
|
+ erpGoods.setName(data.getName());
|
|
|
+ erpGoods.setSimple_name(data.getShortName());
|
|
|
+ erpGoods.setCategory_code(data.getCategory());
|
|
|
+ erpGoods.setCost_price(data.getCostPrice());
|
|
|
+ erpGoods.setSales_price(data.getSalePrice());
|
|
|
+ erpGoods.setPurchase_price(data.getMarketPrice());
|
|
|
+ erpGoodsList.add(erpGoods);
|
|
|
+ }
|
|
|
+ erpGoodsQueryResponse.setItems(erpGoodsList);
|
|
|
+ }
|
|
|
+ return erpGoodsQueryResponse;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public ErpGoodsStockQueryResponse getGoodsStock(ErpGoodsStockQueryRequert param) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ErpGoodsStockQueryResponse getGoodsStockScrm(ErpGoodsStockQueryRequert param) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 构建店铺商品上传的参数
|
|
|
+ *
|
|
|
+ * @param storeProductIds
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONArray buildGoodsScrm(List<Long> storeProductIds) {
|
|
|
+ JSONArray res = new JSONArray();
|
|
|
+ //商品
|
|
|
+ List<FsStoreProductScrm> fsStoreProductList = fsStoreProductScrmService.getStoreProductInProductIds(storeProductIds);
|
|
|
+ if (!fsStoreProductList.isEmpty()) {
|
|
|
+
|
|
|
+ Map<Long, FsStoreProductScrm> productMap = fsStoreProductList.stream().collect(Collectors.toMap(FsStoreProductScrm::getProductId, p -> p));
|
|
|
+ //商品规格List
|
|
|
+ List<FsStoreProductAttrValueScrm> fsStoreProductAttrValues = fsStoreProductAttrValueScrmService.getFsStoreProductAttrValueListInProductId(storeProductIds);
|
|
|
+
|
|
|
+ //按规格构建商品数据
|
|
|
+ fsStoreProductAttrValues.forEach(v -> {
|
|
|
+ JSONObject productJson = new JSONObject();
|
|
|
+ FsStoreProductScrm product = productMap.get(v.getProductId());
|
|
|
+ productJson.put("sku_id", v.getBarCode());//商品编码
|
|
|
+ productJson.put("i_id", v.getBarCode());//如果没有款式默认商品编码一致
|
|
|
+ productJson.put("name", v.getSku());//名称
|
|
|
+ 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", v.getImage());//图片地址(款图片)
|
|
|
+ productJson.put("pic_big", v.getImage());//大图地址
|
|
|
+ res.add(productJson);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ return res;
|
|
|
+ }
|
|
|
/**
|
|
|
* 构建店铺商品上传的参数
|
|
|
*
|