|  | @@ -4,17 +4,13 @@ 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.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.ShopSku;
 | 
	
		
			
				|  |  | -import com.yami.shop.bean.model.Sku;
 | 
	
		
			
				|  |  | +import com.yami.shop.bean.model.*;
 | 
	
		
			
				|  |  |  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.ShopSkuMapper;
 | 
	
		
			
				|  |  | -import com.yami.shop.dao.SkuMapper;
 | 
	
		
			
				|  |  | +import com.yami.shop.dao.*;
 | 
	
		
			
				|  |  |  import com.yami.shop.service.hb.IHBGoodsService;
 | 
	
		
			
				|  |  | +import com.yami.shop.service.impl.FrontCategoryService;
 | 
	
		
			
				|  |  |  import com.yami.shop.utils.HBSignUtil;
 | 
	
		
			
				|  |  |  import lombok.AllArgsConstructor;
 | 
	
		
			
				|  |  |  import lombok.extern.slf4j.Slf4j;
 | 
	
	
		
			
				|  | @@ -45,6 +41,8 @@ public class HBGoodsService implements IHBGoodsService {
 | 
	
		
			
				|  |  |      private final SkuMapper skuMapper;
 | 
	
		
			
				|  |  |      private final ShopSkuMapper shopSkuMapper;
 | 
	
		
			
				|  |  |      private final ShopDetailMapper shopDetailMapper;
 | 
	
		
			
				|  |  | +    private final FrontCategoryMapper frontCategoryMapper;
 | 
	
		
			
				|  |  | +    private final CategoryProdMapper categoryProdMapper;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
	
		
			
				|  | @@ -75,25 +73,33 @@ public class HBGoodsService implements IHBGoodsService {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                      // 创建并填充Product对象
 | 
	
		
			
				|  |  |                      hbSpuId = productInfo.getString("spuId");
 | 
	
		
			
				|  |  | +                    Product productAdd = createProductFromProductInfo(productInfo);
 | 
	
		
			
				|  |  | +                    setSpuMapper(productInfo, productAdd);
 | 
	
		
			
				|  |  |                      Product productInfoById = productMapper.selectByHbSpuId(hbSpuId);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |                      if (ObjectUtil.isNotEmpty(productInfoById) && productInfoById.getIsDelete() == 0) {
 | 
	
		
			
				|  |  |                          prodId = productInfoById.getProdId();
 | 
	
		
			
				|  |  | -                        log.info("商品spuID={},spuName={}已经存在无需添加", productInfo.getLong("spuId"), productInfo.getString("spuName"));
 | 
	
		
			
				|  |  | +                        log.info("商品spuID={},spuName={}已经存在,修改商品", productInfo.getLong("spuId"), productInfo.getString("spuName"));
 | 
	
		
			
				|  |  | +                        productAdd.setProdId(productInfoById.getProdId());
 | 
	
		
			
				|  |  | +                        productMapper.updateById(productAdd);
 | 
	
		
			
				|  |  |                      } else {
 | 
	
		
			
				|  |  | -                        Product productAdd = createProductFromProductInfo(productInfo);
 | 
	
		
			
				|  |  | -                        setSpuMapper(productInfo, productAdd);
 | 
	
		
			
				|  |  |                          //添加到数据库
 | 
	
		
			
				|  |  | +                        log.info("创建商品spu: {}", productAdd);
 | 
	
		
			
				|  |  |                          productMapper.insert(productAdd);
 | 
	
		
			
				|  |  |                          prodId = productAdd.getProdId();
 | 
	
		
			
				|  |  |                          log.info("SPU创建成功: prodId={}, hbSpuId={}, spuName={}", productAdd.getProdId(), productAdd.getProdId(), productAdd.getProdName());
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +                    convertCategoryCodeToId(productInfo.getJSONArray("relationFrontCategories"), productAdd.getProdId()); // 一品多类目
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |                      Sku skuId = skuMapper.selectByHbSkuId(productInfo.getString("skuId"));
 | 
	
		
			
				|  |  |                      if (ObjectUtil.isNotEmpty(skuId) && skuId.getIsDelete() == 0) {
 | 
	
		
			
				|  |  | -                        log.info("商品skuId={},skuName={}已经存在无需添加", productInfo.getString("skuId"), productInfo.getString("skuName"));
 | 
	
		
			
				|  |  | +                        skuId.setSkuId(skuId.getSkuId());
 | 
	
		
			
				|  |  | +                        skuMapper.updateById(skuId);
 | 
	
		
			
				|  |  | +                        log.info("商品skuId={},skuName={}已经存在,修改数据", productInfo.getString("skuId"), productInfo.getString("skuName"));
 | 
	
		
			
				|  |  |                      } else {
 | 
	
		
			
				|  |  |                          // 创建并填充Sku对象
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |                          Sku sku = createSkuFromProductInfo(productInfo);
 | 
	
		
			
				|  |  |                          sku.setProdId(prodId);
 | 
	
		
			
				|  |  |                          sku.setHbSpuId(hbSpuId);
 | 
	
	
		
			
				|  | @@ -114,38 +120,42 @@ public class HBGoodsService implements IHBGoodsService {
 | 
	
		
			
				|  |  |                  for (Object productHostInfoDTO : productHostInfoDTOS) {
 | 
	
		
			
				|  |  |                      JSONObject productInfo = JSON.parseObject(productHostInfoDTO.toString());
 | 
	
		
			
				|  |  |                      // 创建并填充Product对象
 | 
	
		
			
				|  |  | +                    Product productAdd = createProductFromProductInfo(productInfo);
 | 
	
		
			
				|  |  | +                    setSpuSpecMapper(productInfo, productAdd);
 | 
	
		
			
				|  |  | +                    // 创建并填充Product对象
 | 
	
		
			
				|  |  |                      Product productInfoById = productMapper.selectByHbSpuId(hbSpuId);
 | 
	
		
			
				|  |  |                      if (ObjectUtil.isNotEmpty(productInfoById) && productInfoById.getIsDelete() == 0) {
 | 
	
		
			
				|  |  | -                        log.info("商品spuID={},spuName={}已经存在无需添加", productInfo.getLong("spuId"), productInfo.getString("spuName"));
 | 
	
		
			
				|  |  |                          prodId = productInfoById.getProdId();
 | 
	
		
			
				|  |  | +                        log.info("商品spuID={},spuName={}已经存在,修改商品", productInfo.getLong("spuId"), productInfo.getString("spuName"));
 | 
	
		
			
				|  |  | +                        productAdd.setProdId(productInfoById.getProdId());
 | 
	
		
			
				|  |  | +                        productMapper.updateById(productAdd);
 | 
	
		
			
				|  |  |                      } else {
 | 
	
		
			
				|  |  | -                        // 创建并填充Product对象
 | 
	
		
			
				|  |  | -                        Product productAdd = createProductFromProductInfo(productInfo);
 | 
	
		
			
				|  |  | -                        setSpuSpecMapper(productInfo, productAdd);
 | 
	
		
			
				|  |  |                          //添加到数据库
 | 
	
		
			
				|  |  |                          productMapper.insert(productAdd);
 | 
	
		
			
				|  |  |                          prodId = productAdd.getProdId();
 | 
	
		
			
				|  |  |                          log.info("生成的商品ID: {}", productAdd.getProdId());
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | +                    convertCategoryCodeToId(productInfo.getJSONArray("relationFrontCategories"), productAdd.getProdId()); // 一品多类目
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                      JSONArray skuList = productInfo.getJSONArray("skuList");
 | 
	
		
			
				|  |  |                      for (Object o : skuList) {
 | 
	
		
			
				|  |  |                          JSONObject jsonObjectSku = JSON.parseObject(o.toString());
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +                        Sku sku = createSkuFromProductInfo(jsonObjectSku);
 | 
	
		
			
				|  |  | +                        sku.setProdId(prodId);
 | 
	
		
			
				|  |  | +                        sku.setHbSpuId(hbSpuId);
 | 
	
		
			
				|  |  |                          Sku skuId = skuMapper.selectByHbSkuId(jsonObjectSku.getString("skuId"));
 | 
	
		
			
				|  |  |                          if (ObjectUtil.isNotEmpty(skuId) && skuId.getIsDelete() == 0) {
 | 
	
		
			
				|  |  | +                            skuId.setSkuId(skuId.getSkuId());
 | 
	
		
			
				|  |  | +                            skuMapper.updateById(skuId);
 | 
	
		
			
				|  |  |                              log.info("商品skuId={},skuName={}已经存在无需添加", productInfo.getLong("skuId"), productInfo.getString("skuName"));
 | 
	
		
			
				|  |  |                          } else {
 | 
	
		
			
				|  |  | -                            Sku sku = createSkuFromProductInfo(jsonObjectSku);
 | 
	
		
			
				|  |  | -                            sku.setProdId(prodId);
 | 
	
		
			
				|  |  | -                            sku.setHbSpuId(hbSpuId);
 | 
	
		
			
				|  |  |                              skuMapper.insert(sku);
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        return HBR.success("商品信息处理成功");
 | 
	
		
			
				|  |  | +        return HBR.success();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
	
		
			
				|  | @@ -174,7 +184,8 @@ public class HBGoodsService implements IHBGoodsService {
 | 
	
		
			
				|  |  |              String stationId = bodyJson.getString("stationId");
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              String selfSkuStatus = getSelfSkuStatus(skuId, stationId);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +            log.info("商品状态变更查询:{}", selfSkuStatus);
 | 
	
		
			
				|  |  | +            //处理商品状态
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          } catch (Exception e) {
 | 
	
	
		
			
				|  | @@ -217,6 +228,7 @@ public class HBGoodsService implements IHBGoodsService {
 | 
	
		
			
				|  |  |                      shopSkuInfo.setShopId(shopDetail.getShopId());
 | 
	
		
			
				|  |  |                      shopSkuInfo.setShopSkuPrice(currentPrice == null ? 0.0 : currentPrice);
 | 
	
		
			
				|  |  |                      shopSkuInfo.setSkuId(sku.getSkuId());
 | 
	
		
			
				|  |  | +                    shopSkuInfo.setSpuId(sku.getProdId());
 | 
	
		
			
				|  |  |                      shopSkuInfo.setIsDelete(0);
 | 
	
		
			
				|  |  |                      shopSkuInfo.setRecTime(new Date());
 | 
	
		
			
				|  |  |                      shopSkuMapper.insert(shopSkuInfo);
 | 
	
	
		
			
				|  | @@ -225,7 +237,7 @@ public class HBGoodsService implements IHBGoodsService {
 | 
	
		
			
				|  |  |                      shopSku.setShopSkuPrice(currentPrice == null ? 0.0 : currentPrice);
 | 
	
		
			
				|  |  |                      shopSku.setUpdateTime(new Date());
 | 
	
		
			
				|  |  |                      shopSkuMapper.updateById(shopSku);
 | 
	
		
			
				|  |  | -                    log.info("库存更改成功");
 | 
	
		
			
				|  |  | +                    log.info("价格更改成功");
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          } catch (Exception e) {
 | 
	
	
		
			
				|  | @@ -339,6 +351,7 @@ public class HBGoodsService implements IHBGoodsService {
 | 
	
		
			
				|  |  |       *
 | 
	
		
			
				|  |  |       * @param spuId 海博多规格商品编码
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  |      public String selectHBGoodsSpuInfo(String spuId) {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          HBBaseReq<Object> build = HBBaseReq.create();
 | 
	
	
		
			
				|  | @@ -366,6 +379,7 @@ public class HBGoodsService implements IHBGoodsService {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 商品-门店品售卖状态查询接口
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  |       * @return 门店品售卖状态信息
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      public String getSelfSkuStatus(String skuId, String stationId) {
 | 
	
	
		
			
				|  | @@ -391,6 +405,7 @@ public class HBGoodsService implements IHBGoodsService {
 | 
	
		
			
				|  |  |      private Product createProductFromProductInfo(JSONObject productInfo) {
 | 
	
		
			
				|  |  |          Product product = new Product();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        log.info("productInfo:{}", productInfo);
 | 
	
		
			
				|  |  |          // 直接映射字段
 | 
	
		
			
				|  |  |          product.setHbSpuId(productInfo.getLong("spuId"));
 | 
	
		
			
				|  |  |          product.setProdName(productInfo.getString("spuName"));
 | 
	
	
		
			
				|  | @@ -406,19 +421,24 @@ public class HBGoodsService implements IHBGoodsService {
 | 
	
		
			
				|  |  |          product.setBrandId(productInfo.getLong("brandId"));
 | 
	
		
			
				|  |  |          //品牌名称
 | 
	
		
			
				|  |  |          product.setBrandName(productInfo.getString("brandName"));
 | 
	
		
			
				|  |  | +        product.setBrandName(productInfo.getString("brandName"));
 | 
	
		
			
				|  |  | +        String descText = productInfo.getString("descText");
 | 
	
		
			
				|  |  | +        if (StringUtils.isEmpty(descText)) {
 | 
	
		
			
				|  |  | +            product.setContent("<p>暂无商品详情</p>");
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            product.setContent(descText);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          // 分类转换
 | 
	
		
			
				|  |  |          product.setCategoryId(productInfo.getLong("frontCategoryCode"));
 | 
	
		
			
				|  |  |          //后台类目平台对应ID
 | 
	
		
			
				|  |  |  //        product.setHbFrontCategoryId(productInfo.getLong("frontCategoryCode"));
 | 
	
		
			
				|  |  | -        product.setPic(productInfo.getString("spuMainImage"));
 | 
	
		
			
				|  |  | -        product.setImgs(productInfo.getString("spuImages"));
 | 
	
		
			
				|  |  | +//        product.setPic(productInfo.getString("spuMainImage"));
 | 
	
		
			
				|  |  | +//        product.setImgs(productInfo.getString("spuImages"));
 | 
	
		
			
				|  |  |          // 需要转换或默认值的字段
 | 
	
		
			
				|  |  |  //        Product.setTotalStocks(productInfo.getString(""));//总库存
 | 
	
		
			
				|  |  |  //        Product.setDeliveryMode(productInfo.getString(""));//配送方式
 | 
	
		
			
				|  |  |  //        Product.setDeliveryTemplateId(productInfo.getString(""));//运费模板id
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        convertCategoryCodeToId(productInfo.getJSONArray("relationFrontCategories")); // 一品多类目
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          log.info("商品数据详情{}", product);
 | 
	
		
			
				|  |  |          return product;
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -427,18 +447,20 @@ public class HBGoodsService implements IHBGoodsService {
 | 
	
		
			
				|  |  |       * 海博(普通)商品
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      private void setSpuMapper(JSONObject productInfo, Product product) {
 | 
	
		
			
				|  |  | -        product.setPic(productInfo.getString("spuMainImage"));//商品主图
 | 
	
		
			
				|  |  | +        product.setPic(productInfo.getString("mainImage"));//商品主图
 | 
	
		
			
				|  |  |          product.setHbStatus(1);//海博商品类型(1-普通商品,2-多规格商品)
 | 
	
		
			
				|  |  | -        product.setImgs(productInfo.getString("spuImages"));//商品图片,以,分割
 | 
	
		
			
				|  |  | +        product.setImgs(productInfo.getString("images"));//商品图片,以,分割
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 海博(多规格)商品
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      private void setSpuSpecMapper(JSONObject productInfo, Product product) {
 | 
	
		
			
				|  |  | -        product.setPic(productInfo.getString("mainImage"));//商品主图
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        product.setPic(productInfo.getString("spuMainImage"));//商品主图
 | 
	
		
			
				|  |  |          product.setHbStatus(2);//海博商品类型(1-普通商品,2-多规格商品)
 | 
	
		
			
				|  |  | -        product.setImgs(productInfo.getString("images"));//商品图片,以,分割
 | 
	
		
			
				|  |  | +        product.setImgs(productInfo.getString("spuImages"));//商品图片,以,分割
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
	
		
			
				|  | @@ -460,8 +482,8 @@ public class HBGoodsService implements IHBGoodsService {
 | 
	
		
			
				|  |  |          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图片
 | 
	
		
			
				|  |  | +//        String images = StringUtils.isEmpty(productInfo.getString("images")) ? productInfo.getString("skuMainImage") : productInfo.getString("images");
 | 
	
		
			
				|  |  | +        sku.setPic(productInfo.getString("mainImage"));//sku图片
 | 
	
		
			
				|  |  |          sku.setWeightUnit(productInfo.getString("unit"));//单位
 | 
	
		
			
				|  |  |          // 商品原价
 | 
	
		
			
				|  |  |          sku.setOriPrice(productInfo.getDouble("basicPrice") != null ?
 | 
	
	
		
			
				|  | @@ -487,10 +509,33 @@ public class HBGoodsService implements IHBGoodsService {
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 分类处理
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    private void convertCategoryCodeToId(JSONArray categoryCode) {
 | 
	
		
			
				|  |  | +    private void convertCategoryCodeToId(JSONArray categoryCode, Long spuId) {
 | 
	
		
			
				|  |  | +        log.info("新增商品分类处理{}", categoryCode);
 | 
	
		
			
				|  |  |          for (Object o : categoryCode) {
 | 
	
		
			
				|  |  |              JSONObject jsonObject = JSON.parseObject(o.toString());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +            String ztFrontCategoryCodeLevel = jsonObject.getString("ztFrontCategoryCodeLevel2");
 | 
	
		
			
				|  |  | +            if (StringUtils.isEmpty(ztFrontCategoryCodeLevel)) {
 | 
	
		
			
				|  |  | +                ztFrontCategoryCodeLevel = jsonObject.getString("ztFrontCategoryCode");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +//            FrontCategory frontCategory = frontCategoryMapper.selectOne(new LambdaQueryWrapper<FrontCategory>()
 | 
	
		
			
				|  |  | +//                    .eq(FrontCategory::getCode, ztFrontCategoryCodeLevel));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            CategoryProd categoryProd = new CategoryProd();
 | 
	
		
			
				|  |  | +            categoryProd.setCode(ztFrontCategoryCodeLevel);
 | 
	
		
			
				|  |  | +            categoryProd.setProdId(spuId);
 | 
	
		
			
				|  |  | +            categoryProd.setIsDelete(0);
 | 
	
		
			
				|  |  | +            CategoryProd integer = categoryProdMapper.selectOne(new LambdaQueryWrapper<CategoryProd>()
 | 
	
		
			
				|  |  | +                    .eq(CategoryProd::getProdId, spuId)
 | 
	
		
			
				|  |  | +                    .eq(CategoryProd::getIsDelete, 0)
 | 
	
		
			
				|  |  | +                    .eq(CategoryProd::getCode, ztFrontCategoryCodeLevel));
 | 
	
		
			
				|  |  | +            if (integer != null) {
 | 
	
		
			
				|  |  | +                categoryProd.setId(integer.getId());
 | 
	
		
			
				|  |  | +                categoryProdMapper.updateById(categoryProd);
 | 
	
		
			
				|  |  | +                log.info("商品对应分类已存在{}", categoryProd);
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                categoryProdMapper.insert(categoryProd);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 |