|
|
@@ -1,16 +1,19 @@
|
|
|
package com.yami.shop.service.hb.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.yami.shop.bean.dto.hb.HBBaseReq;
|
|
|
import com.yami.shop.bean.model.Product;
|
|
|
+import com.yami.shop.bean.model.ShopDetail;
|
|
|
+import com.yami.shop.bean.model.ShopProd;
|
|
|
import com.yami.shop.bean.model.Sku;
|
|
|
import com.yami.shop.common.util.hb.HBR;
|
|
|
import com.yami.shop.dao.ProductMapper;
|
|
|
+import com.yami.shop.dao.ShopDetailMapper;
|
|
|
+import com.yami.shop.dao.ShopProdMapper;
|
|
|
import com.yami.shop.dao.SkuMapper;
|
|
|
import com.yami.shop.service.hb.IGoodsService;
|
|
|
import com.yami.shop.utils.HBSignUtil;
|
|
|
@@ -20,8 +23,8 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
import static com.yami.shop.common.util.HttpUtil.post;
|
|
|
@@ -37,27 +40,29 @@ import static com.yami.shop.common.util.HttpUtil.post;
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
-@Transactional(readOnly = true)
|
|
|
public class HBGoodsService implements IGoodsService {
|
|
|
private final HBSignUtil hbSignUtil;
|
|
|
private final ProductMapper productMapper;
|
|
|
private final SkuMapper skuMapper;
|
|
|
+ private final ShopProdMapper shopProdMapper;
|
|
|
+ private final ShopDetailMapper shopDetailMapper;
|
|
|
|
|
|
@Override
|
|
|
- @Transactional
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public HBR addHBGoods(JSONObject hbRequest) {
|
|
|
- try {
|
|
|
- String bodyStr = hbRequest.getString("body");
|
|
|
- log.info("商品信息,body:{}", bodyStr);
|
|
|
- JSONObject bodyJson = JSON.parseObject(bodyStr);
|
|
|
- JSONArray productList = bodyJson.getJSONArray("productList");
|
|
|
- List<Product> spuList = new ArrayList<>();
|
|
|
- List<Sku> skuList = new ArrayList<>();
|
|
|
-
|
|
|
- for (Object product : productList) {
|
|
|
- JSONObject jsonObject = JSON.parseObject(product.toString());
|
|
|
- String outSkuId = jsonObject.getString("outSkuId");
|
|
|
- String goodsInfoStr = selectHBGoodsInfo(outSkuId);
|
|
|
+ String bodyStr = hbRequest.getString("body");
|
|
|
+ log.info("商品信息,body:{}", bodyStr);
|
|
|
+ JSONObject bodyJson = JSON.parseObject(bodyStr);
|
|
|
+ JSONArray productList = bodyJson.getJSONArray("productList");
|
|
|
+
|
|
|
+ for (Object product : productList) {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(product.toString());
|
|
|
+ Long prodId;
|
|
|
+ //判断海博传过来的是单规格还是多规格
|
|
|
+ if (ObjectUtil.isEmpty(jsonObject.getString("multiSpec"))) {
|
|
|
+ log.info("===================进入普通商品操作===================");
|
|
|
+ String goodsInfoStr = selectHBGoodsInfo(jsonObject.getString("outSkuId"));
|
|
|
+
|
|
|
JSONObject goodsInfoJson = JSON.parseObject(goodsInfoStr);
|
|
|
|
|
|
// 2. 逐层解析获取productHostInfoDTOS数组
|
|
|
@@ -71,33 +76,76 @@ public class HBGoodsService implements IGoodsService {
|
|
|
JSONObject productInfo = productHostInfoDTOS.getJSONObject(i);
|
|
|
|
|
|
// 创建并填充Product对象
|
|
|
- Product Product = createProductFromProductInfo(productInfo);
|
|
|
- // 创建并填充Sku对象
|
|
|
- Sku Sku = createSkuFromProductInfo(productInfo);
|
|
|
- Sku.setProdId(Product.getProdId()); // 设置关联关系
|
|
|
-
|
|
|
+ Product productInfoById = productMapper.selectByHbSpuId(productInfo.getLong("spuId"));
|
|
|
+ if (ObjectUtil.isNotEmpty(productInfoById) && productInfoById.getIsDelete() == 0) {
|
|
|
+ prodId = productInfoById.getProdId();
|
|
|
+ log.info("商品spuID={},spuName={}已经存在无需添加", productInfo.getLong("spuId"), productInfo.getString("spuName"));
|
|
|
+
|
|
|
+ } else {
|
|
|
+ Product productAdd = createProductFromProductInfo(productInfo);
|
|
|
+ setSpuMapper(productInfo, productAdd);
|
|
|
+ //添加到数据库
|
|
|
+ productMapper.insert(productAdd);
|
|
|
+ prodId = productAdd.getProdId();
|
|
|
+ log.info("SPU创建成功: prodId={}, hbSpuId={}, spuName={}", productAdd.getProdId(), productAdd.getProdId(), productAdd.getProdName());
|
|
|
+ }
|
|
|
+
|
|
|
+ Sku skuId = skuMapper.selectByHbSkuId(productInfo.getLong("skuId"));
|
|
|
+ if (ObjectUtil.isNotEmpty(skuId) && skuId.getIsDelete() == 0) {
|
|
|
+ log.info("商品skuId={},skuName={}已经存在无需添加", productInfo.getLong("skuId"), productInfo.getString("skuName"));
|
|
|
+ } else {
|
|
|
+ // 创建并填充Sku对象
|
|
|
+ Sku sku = createSkuFromProductInfo(productInfo);
|
|
|
+ sku.setProdId(prodId);
|
|
|
+ skuMapper.insert(sku);
|
|
|
+ log.info("SKU创建成功: skuId={}, skuName={}", sku.getSkuId(), sku.getSkuName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.info("===================进入多规格商品操作===================");
|
|
|
+ String selectHBGoodsSpuInfo = selectHBGoodsSpuInfo(jsonObject.getString("spuId"));
|
|
|
+ JSONObject goodsInfoJson = JSON.parseObject(selectHBGoodsSpuInfo);
|
|
|
+ // 2. 逐层解析获取productHostInfoDTOS数组
|
|
|
+ JSONObject result = goodsInfoJson.getJSONObject("result");
|
|
|
+ JSONObject innerResult = result.getJSONObject("result");
|
|
|
+ JSONArray productHostInfoDTOS = innerResult.getJSONArray("productSpuHostInfoDTOList");
|
|
|
|
|
|
- //添加到数据库
|
|
|
- productMapper.insert(Product);
|
|
|
- skuMapper.insert(Sku);
|
|
|
+ for (Object productHostInfoDTO : productHostInfoDTOS) {
|
|
|
+ JSONObject productInfo = JSON.parseObject(productHostInfoDTO.toString());
|
|
|
|
|
|
- spuList.add(Product);
|
|
|
- skuList.add(Sku);
|
|
|
|
|
|
- log.info("SPU创建成功: spuId={}, spuName={}", Product.getProdId(), Product.getProdName());
|
|
|
- log.info("SKU创建成功: skuId={}, skuName={}", Sku.getSkuId(), Sku.getSkuName());
|
|
|
+ // 创建并填充Product对象
|
|
|
+ Product productInfoById = productMapper.selectByHbSpuId(productInfo.getLong("spuId"));
|
|
|
+ if (ObjectUtil.isNotEmpty(productInfoById) && productInfoById.getIsDelete() == 0) {
|
|
|
+ log.info("商品spuID={},spuName={}已经存在无需添加", productInfo.getLong("spuId"), productInfo.getString("spuName"));
|
|
|
+ prodId = productInfoById.getProdId();
|
|
|
+ } else {
|
|
|
+ // 创建并填充Product对象
|
|
|
+ Product productAdd = createProductFromProductInfo(productInfo);
|
|
|
+ setSpuSpecMapper(productInfo, productAdd);
|
|
|
+ //添加到数据库
|
|
|
+ productMapper.insert(productAdd);
|
|
|
+ prodId = productAdd.getProdId();
|
|
|
+ log.info("生成的商品ID: {}", productAdd.getProdId());
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONArray skuList = productInfo.getJSONArray("skuList");
|
|
|
+ for (Object o : skuList) {
|
|
|
+ JSONObject jsonObjectSku = JSON.parseObject(o.toString());
|
|
|
+
|
|
|
+ Sku skuId = skuMapper.selectByHbSkuId(jsonObjectSku.getLong("skuId"));
|
|
|
+ if (ObjectUtil.isNotEmpty(skuId) && skuId.getIsDelete() == 0) {
|
|
|
+ log.info("商品skuId={},skuName={}已经存在无需添加", productInfo.getLong("skuId"), productInfo.getString("skuName"));
|
|
|
+ } else {
|
|
|
+ Sku sku = createSkuFromProductInfo(jsonObjectSku);
|
|
|
+ sku.setProdId(prodId);
|
|
|
+ skuMapper.insert(sku);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- // 这里可以保存到数据库
|
|
|
- // ProductService.saveBatch(spuList);
|
|
|
- // SkuService.saveBatch(skuList);
|
|
|
-
|
|
|
- return HBR.success("商品信息处理成功,共处理 " + spuList.size() + " 个SPU和SKU");
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("处理商品信息失败:{}", e.getMessage(), e);
|
|
|
- return HBR.error("处理商品信息失败: " + e.getMessage());
|
|
|
}
|
|
|
+ return HBR.success("商品信息处理成功");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -131,6 +179,7 @@ public class HBGoodsService implements IGoodsService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public HBR updateGoodsPrice(JSONObject hbRequest) {
|
|
|
try {
|
|
|
String bodyStr = hbRequest.getString("body");
|
|
|
@@ -138,9 +187,39 @@ public class HBGoodsService implements IGoodsService {
|
|
|
JSONObject bodyJson = JSON.parseObject(bodyStr);
|
|
|
JSONArray requestList = bodyJson.getJSONArray("requestList");
|
|
|
for (Object request : requestList) {
|
|
|
- JSONObject jsonObject = JSON.parseObject((String) request);
|
|
|
+ JSONObject jsonObject = JSON.parseObject(request.toString());
|
|
|
Long skuId = jsonObject.getLong("skuId");
|
|
|
+ Double currentPrice = jsonObject.getDouble("currentPrice");
|
|
|
+ String stationId = jsonObject.getString("stationId");//海博门店编码
|
|
|
+ ShopDetail shopDetail = shopDetailMapper.selectByHbStationId(stationId);
|
|
|
+ if (ObjectUtil.isEmpty(shopDetail)) {
|
|
|
+ log.error("系统找不到对应的门店(门店编码:{})信息", stationId);
|
|
|
+ return HBR.error("系统找不到对应的门店(门店编码:" + stationId + ")信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ //改变单品价格
|
|
|
+ Sku sku = skuMapper.selectByHbSkuId(skuId);
|
|
|
+ if (ObjectUtil.isEmpty(sku)) {
|
|
|
+ log.error("更改价格系统找不到对应商品(单品):{}", skuId);
|
|
|
+ return HBR.error("更改价格系统找不到对应商品(单品):" + skuId);
|
|
|
+ }
|
|
|
|
|
|
+ ShopProd shopProd = shopProdMapper.selectByShopAndProd(sku.getSkuId(), shopDetail.getShopId());
|
|
|
+ if (ObjectUtil.isEmpty(shopProd)) {
|
|
|
+ ShopProd shopProdInfo = new ShopProd();
|
|
|
+ shopProdInfo.setShopId(shopDetail.getShopId());
|
|
|
+ shopProdInfo.setShopProdPrice(currentPrice == null ? 0.0 : currentPrice);
|
|
|
+ shopProdInfo.setSkuId(sku.getSkuId());
|
|
|
+ shopProdInfo.setIsDelete(0);
|
|
|
+ shopProdInfo.setRecTime(new Date());
|
|
|
+ shopProdMapper.insert(shopProdInfo);
|
|
|
+ log.info("门店对应商品系统不存在直接添加");
|
|
|
+ } else {
|
|
|
+ shopProd.setShopProdPrice(currentPrice == null ? 0.0 : currentPrice);
|
|
|
+ shopProd.setUpdateTime(new Date());
|
|
|
+ shopProdMapper.updateById(shopProd);
|
|
|
+ log.info("库存更改成功");
|
|
|
+ }
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.error("商品失败:{}", e.getMessage(), e);
|
|
|
@@ -151,12 +230,48 @@ public class HBGoodsService implements IGoodsService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public HBR updateGoodsStock(JSONObject hbRequest) {
|
|
|
try {
|
|
|
String bodyStr = hbRequest.getString("body");
|
|
|
log.info("商品库存变动,body:{}", bodyStr);
|
|
|
JSONObject bodyJson = JSON.parseObject(bodyStr); // 使用Fastjson的解析方法
|
|
|
- String outStationNo = bodyJson.getString("outStationNo");
|
|
|
+ JSONArray requestList = bodyJson.getJSONArray("requestList");
|
|
|
+ for (Object request : requestList) {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(request.toString());
|
|
|
+ Long skuId = jsonObject.getLong("skuId");
|
|
|
+ String stationId = jsonObject.getString("stationId");//海博门店编码
|
|
|
+ ShopDetail shopDetail = shopDetailMapper.selectByHbStationId(stationId);
|
|
|
+ if (shopDetail == null) {
|
|
|
+ log.error("系统找不到对应的门店信息(门店编码:{})", stationId);
|
|
|
+ return HBR.error("系统找不到对应的门店信息(门店编码:" + stationId + ")");
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer currentStock = jsonObject.getInteger("currentStock");
|
|
|
+ //改变单品库存
|
|
|
+ Sku sku = skuMapper.selectByHbSkuId(skuId);
|
|
|
+ if (ObjectUtil.isEmpty(sku)) {
|
|
|
+ log.error("系统找不到对应商品(单品):{}", skuId);
|
|
|
+ return HBR.error("系统找不到对应商品(单品):" + skuId);
|
|
|
+ }
|
|
|
+
|
|
|
+ ShopProd shopProd = shopProdMapper.selectByShopAndProd(sku.getSkuId(), shopDetail.getShopId());
|
|
|
+ if (ObjectUtil.isEmpty(shopProd)) {
|
|
|
+ ShopProd shopProdInfo = new ShopProd();
|
|
|
+ shopProdInfo.setShopId(shopDetail.getShopId());
|
|
|
+ shopProdInfo.setShopProdStocks(currentStock);
|
|
|
+ shopProdInfo.setSkuId(sku.getSkuId());
|
|
|
+ shopProdInfo.setIsDelete(0);
|
|
|
+ shopProdInfo.setRecTime(new Date());
|
|
|
+ shopProdMapper.insert(shopProdInfo);
|
|
|
+ log.info("库存添加成功");
|
|
|
+ } else {
|
|
|
+ shopProd.setShopProdStocks(currentStock);
|
|
|
+ shopProd.setUpdateTime(new Date());
|
|
|
+ shopProdMapper.updateById(shopProd);
|
|
|
+ log.info("库存更改成功");
|
|
|
+ }
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
log.error("商品失败:{}", e.getMessage(), e);
|
|
|
return HBR.error("未知异常");
|
|
|
@@ -169,6 +284,20 @@ public class HBGoodsService implements IGoodsService {
|
|
|
public void deleteGoods(JSONObject hbRequest) {
|
|
|
String bodyStr = hbRequest.getString("body");
|
|
|
log.info("商品删除,body:{}", bodyStr);
|
|
|
+
|
|
|
+ JSONObject bodyJson = JSON.parseObject(bodyStr);
|
|
|
+ JSONArray requestList = bodyJson.getJSONArray("productList");
|
|
|
+ for (Object request : requestList) {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(request.toString());
|
|
|
+ Long skuId = jsonObject.getLong("skuId");
|
|
|
+ Sku sku = skuMapper.selectByHbSkuId(skuId);
|
|
|
+ if (ObjectUtil.isEmpty(sku)) {
|
|
|
+ log.error("系统找不到删除对应商品(单品):{}", skuId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ sku.setIsDelete(1);
|
|
|
+ skuMapper.updateById(sku);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -196,6 +325,35 @@ public class HBGoodsService implements IGoodsService {
|
|
|
return post;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 多规格查询
|
|
|
+ *
|
|
|
+ * @param spuId 海博多规格商品编码
|
|
|
+ */
|
|
|
+ public String selectHBGoodsSpuInfo(String spuId) {
|
|
|
+
|
|
|
+ HBBaseReq<Object> build = HBBaseReq.create();
|
|
|
+ build.setAppId(hbSignUtil.getAppId());
|
|
|
+
|
|
|
+ JSONObject skuItem = new JSONObject();
|
|
|
+// skuItem.put("skuId", "1328633"); // 海博商品编码
|
|
|
+ skuItem.put("spuId", spuId); // 商家商品编码
|
|
|
+ // 2. 创建商品列表并添加SKU对象
|
|
|
+ List<JSONObject> productList = new ArrayList<>();
|
|
|
+ productList.add(skuItem);
|
|
|
+ // 3. 构建外层请求体
|
|
|
+ JSONObject requestBody = new JSONObject();
|
|
|
+ requestBody.put("productList", productList);
|
|
|
+ // 4. 将整个JSON对象序列化为字符串并设置
|
|
|
+ build.setBody(JSON.toJSONString(requestBody));
|
|
|
+
|
|
|
+ build.setSign(hbSignUtil.signMd5(build));
|
|
|
+ log.info("post 多规格商品查询请求参数:{}", JSON.toJSONString(build));
|
|
|
+ String post = post(hbSignUtil.getHBHost() + "/api/product/getSpus", build);
|
|
|
+ log.info("post 多规格商品查询结果:{}", post);
|
|
|
+ return post;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public String getSelfSkuStatus() {
|
|
|
@@ -205,8 +363,6 @@ public class HBGoodsService implements IGoodsService {
|
|
|
List<JSONObject> onlineProductDTO = new ArrayList();
|
|
|
jsonObject.put("skuId", "0");//海博商品编码
|
|
|
jsonObject.put("stationId", "0");//海博门店编码
|
|
|
-// jsonObject.put("outStationNo", "0");//商家门店编码
|
|
|
-// jsonObject.put("outSkuId", "0");//商家商品编码
|
|
|
onlineProductDTO.add(jsonObject);
|
|
|
build.setBody(JSON.toJSONString(onlineProductDTO));
|
|
|
build.setSign(hbSignUtil.signMd5(build));
|
|
|
@@ -216,139 +372,110 @@ public class HBGoodsService implements IGoodsService {
|
|
|
return post;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public IPage<Product> selectGoodsPage(Integer pageNum, Integer pageSize,Product product) {
|
|
|
- // 1. 构建分页对象
|
|
|
- Page<Product> page = new Page<>(pageNum, pageSize);
|
|
|
-
|
|
|
- // 2. 构建查询条件
|
|
|
- LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
-
|
|
|
- if (product != null) {
|
|
|
- queryWrapper.like(StringUtils.isNotBlank(product.getProdName()),
|
|
|
- Product::getProdName, product.getProdName());
|
|
|
- queryWrapper.eq(product.getCategoryId() != null,
|
|
|
- Product::getCategoryId, product.getCategoryId());
|
|
|
- queryWrapper.eq(product.getBrandId() != null,
|
|
|
- Product::getBrandId, product.getBrandId());
|
|
|
- queryWrapper.eq(product.getStatus() != null,
|
|
|
- Product::getStatus, product.getStatus());
|
|
|
- }
|
|
|
-
|
|
|
- // 3. 添加排序
|
|
|
- queryWrapper.orderByDesc(Product::getCreateTime);
|
|
|
-
|
|
|
- // 4. 执行分页查询
|
|
|
- IPage<Product> ProductPage = productMapper.selectPage(page, queryWrapper);
|
|
|
- List<Product> records = ProductPage.getRecords();
|
|
|
- for (Product record : records) {
|
|
|
-
|
|
|
- LambdaQueryWrapper<Sku> skuQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- skuQueryWrapper.like(Sku::getProdId, record.getProdId());
|
|
|
-
|
|
|
- // 3. 添加排序
|
|
|
- skuQueryWrapper.orderByDesc(Sku::getRecTime);
|
|
|
- record.setSkuList(skuMapper.selectList(skuQueryWrapper));
|
|
|
- }
|
|
|
- return ProductPage;
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 从productInfo创建Product对象
|
|
|
*/
|
|
|
private Product createProductFromProductInfo(JSONObject productInfo) {
|
|
|
- Product Product = new Product();
|
|
|
-
|
|
|
- // 设置默认值
|
|
|
+ Product product = new Product();
|
|
|
// 直接映射字段
|
|
|
- Product.setProdId(productInfo.getLong("spuId"));
|
|
|
- Product.setProdName(productInfo.getString("spuName"));
|
|
|
-
|
|
|
+ product.setProdId(productInfo.getLong("spuId"));
|
|
|
+ product.setProdName(productInfo.getString("spuName"));
|
|
|
+// Product.setShopId(productInfo.getString("shopId"));
|
|
|
+
|
|
|
+ product.setBrief(productInfo.getString("sellPoint"));//简要描述,卖点等
|
|
|
+ product.setVideo(productInfo.getString(""));//商品视频
|
|
|
+ product.setStatus(1);
|
|
|
+ product.setVersion(1);
|
|
|
+ product.setProdType(0);//(0普通商品 1拼团 2秒杀 3积分)
|
|
|
+ product.setCreateTime(new Date());
|
|
|
+ product.setUpdateTime(new Date());
|
|
|
+ product.setPutawayTime(new Date());
|
|
|
+ product.setBrandId(productInfo.getLong("brandId"));//品牌ID
|
|
|
+ product.setBrandName(productInfo.getString("brandName"));//品牌名称
|
|
|
+ product.setCategoryId(productInfo.getLong("frontCategoryCode")); // 分类转换
|
|
|
+ product.setHbFrontCategoryId(productInfo.getLong("frontCategoryCode"));//后台类目平台对应ID
|
|
|
// 需要转换或默认值的字段
|
|
|
- Product.setCategoryId(convertCategoryCodeToId(productInfo.getString("frontCategoryCode"))); // 分类转换
|
|
|
- Product.setBrandId(convertBrandToId(productInfo.getString("brandName"))); // 品牌转换
|
|
|
+// Product.setTotalStocks(productInfo.getString(""));//总库存
|
|
|
+// Product.setDeliveryMode(productInfo.getString(""));//配送方式
|
|
|
+// Product.setDeliveryTemplateId(productInfo.getString(""));//运费模板id
|
|
|
|
|
|
- // 其他可能需要处理的字段
|
|
|
- if (productInfo.containsKey("desc")) {
|
|
|
-// Product.setDesc(productInfo.getString("desc"));
|
|
|
- }
|
|
|
+ convertCategoryCodeToId(productInfo.getJSONArray("relationFrontCategories")); // 一品多类目
|
|
|
|
|
|
- return Product;
|
|
|
+ log.info("商品数据详情{}", product);
|
|
|
+ return product;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 从productInfo创建Sku对象
|
|
|
+ * 海博(普通)商品
|
|
|
*/
|
|
|
- private Sku createSkuFromProductInfo(JSONObject productInfo) {
|
|
|
- Sku Sku = new Sku();
|
|
|
- // 直接映射字段
|
|
|
- Sku.setSkuId(productInfo.getLong("skuId"));
|
|
|
- Sku.setProdId(productInfo.getLong("spuId"));
|
|
|
- Sku.setSkuCode(productInfo.getString("skuId")); // 使用海博skuId作为skuCode
|
|
|
- Sku.setSkuName(productInfo.getString("skuName"));
|
|
|
- Sku.setPic(productInfo.getString("images"));//sku图片
|
|
|
-
|
|
|
- // 数值类型字段处理
|
|
|
- Sku.setPrice(productInfo.getDouble("basicPrice") != null ?
|
|
|
- productInfo.getDouble("basicPrice") : Double.NaN);
|
|
|
- Sku.setActualStocks(productInfo.getInteger("initStock") != null ?
|
|
|
- productInfo.getInteger("initStock") : 0);
|
|
|
-
|
|
|
- // 重量和体积转换(需要根据实际数据格式处理)
|
|
|
- if (productInfo.containsKey("weight")) {
|
|
|
- try {
|
|
|
- String weightStr = productInfo.getString("weight");
|
|
|
- Sku.setWeight(Double.NaN);
|
|
|
- } catch (Exception e) {
|
|
|
- log.warn("重量格式转换失败: {}", productInfo.getString("weight"));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 状态处理
|
|
|
- Integer status = productInfo.getInteger("flag");
|
|
|
- if (status != null && status == 0) {
|
|
|
- Sku.setStatus(0); // 停售
|
|
|
- } else {
|
|
|
- Sku.setStatus(1); // 正常
|
|
|
- }
|
|
|
-
|
|
|
- // 其他字段映射
|
|
|
- if (productInfo.containsKey("spec")) {
|
|
|
- // spec字段可能包含规格信息,可以用于skuName或单独存储
|
|
|
- Sku.setSkuName(Sku.getSkuName() + " " + productInfo.getString("spec"));
|
|
|
- }
|
|
|
-
|
|
|
- if (productInfo.containsKey("unit")) {
|
|
|
- // 单位信息可以用于skuName
|
|
|
- Sku.setSkuName(Sku.getSkuName() + "(" + productInfo.getString("unit") + ")");
|
|
|
- }
|
|
|
+ private void setSpuMapper(JSONObject productInfo, Product product) {
|
|
|
+ product.setPic(productInfo.getString("spuMainImage"));//商品主图
|
|
|
+ product.setHbStatus(1);//海博商品类型(1-普通商品,2-多规格商品)
|
|
|
+ product.setImgs(productInfo.getString("spuImages"));//商品图片,以,分割
|
|
|
+ }
|
|
|
|
|
|
- return Sku;
|
|
|
+ /**
|
|
|
+ * 海博(多规格)商品
|
|
|
+ */
|
|
|
+ private void setSpuSpecMapper(JSONObject productInfo, Product product) {
|
|
|
+ product.setPic(productInfo.getString("mainImage"));//商品主图
|
|
|
+ product.setHbStatus(2);//海博商品类型(1-普通商品,2-多规格商品)
|
|
|
+ product.setImgs(productInfo.getString("images"));//商品图片,以,分割
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 分类代码转换(需要根据实际业务实现)
|
|
|
+ * 从productInfo创建Sku对象
|
|
|
*/
|
|
|
- private Long convertCategoryCodeToId(String categoryCode) {
|
|
|
- // 这里需要根据您的分类映射关系实现
|
|
|
- // 例如:从数据库或配置文件中根据categoryCode查找对应的categoryId
|
|
|
- if ("101101".equals(categoryCode)) {
|
|
|
- return 1L; // 每日坚果分类ID
|
|
|
- } else if ("101000".equals(categoryCode)) {
|
|
|
- return 2L; // 坚果分类ID
|
|
|
- }
|
|
|
- return 0L; // 默认分类
|
|
|
+ private Sku createSkuFromProductInfo(JSONObject productInfo) {
|
|
|
+ log.info("创建Sku对象数据==========={}===========", productInfo);
|
|
|
+ Sku sku = new Sku();
|
|
|
+ // 直接映射字段
|
|
|
+ sku.setSkuId(productInfo.getLong("skuId"));//单品id - 关联海博同步
|
|
|
+ sku.setProdId(productInfo.getLong("spuId"));//商品id - 关联海博同步
|
|
|
+ sku.setSkuName(productInfo.getString("skuName"));//单品名称
|
|
|
+ sku.setProdName(productInfo.getString("spuName"));//商品名称
|
|
|
+ sku.setModelId(productInfo.getString("upc")); // 商品条码
|
|
|
+ sku.setPartyCode(productInfo.getString("outSkuId"));//商家商品编码
|
|
|
+ sku.setSkuCode(productInfo.getString("outSkuId"));//商家商品编码
|
|
|
+// Sku.setVolume(productInfo.getString(""));//体积
|
|
|
+ sku.setStatus(1);
|
|
|
+ sku.setIsDelete(0);
|
|
|
+ sku.setVersion(0);
|
|
|
+ String images = StringUtils.isEmpty(productInfo.getString("images")) ? productInfo.getString("skuMainImage") : productInfo.getString("images");
|
|
|
+ sku.setPic(images);//sku图片
|
|
|
+ sku.setWeightUnit(productInfo.getString("unit"));//单位
|
|
|
+ // 商品原价
|
|
|
+ sku.setOriPrice(productInfo.getDouble("basicPrice") != null ?
|
|
|
+ productInfo.getDouble("basicPrice") : null);
|
|
|
+ //实际库存
|
|
|
+ sku.setActualStocks(productInfo.getInteger("initStock") == null ? 0 :
|
|
|
+ productInfo.getInteger("initStock"));
|
|
|
+
|
|
|
+ sku.setRecTime(new Date());
|
|
|
+ sku.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ // 重量
|
|
|
+ Double weightStr = productInfo.getDouble("weight");
|
|
|
+ sku.setWeight(weightStr == null ? 0.0 : weightStr);
|
|
|
+
|
|
|
+ //体积
|
|
|
+ sku.setVolume(0.0);
|
|
|
+ sku.setStatus(1); // 状态默认正常
|
|
|
+ log.info("单品数据详情{}", sku);
|
|
|
+ return sku;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 品牌名称转换(需要根据实际业务实现)
|
|
|
+ * 分类处理
|
|
|
*/
|
|
|
- private Long convertBrandToId(String brandName) {
|
|
|
- // 这里需要根据您的品牌映射关系实现
|
|
|
- if ("沃隆".equals(brandName)) {
|
|
|
- return 1L; // 沃隆品牌ID
|
|
|
+ private void convertCategoryCodeToId(JSONArray categoryCode) {
|
|
|
+ for (Object o : categoryCode) {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(o.toString());
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
- return 0L; // 默认品牌
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|