Browse Source

完善自动同步商品到企云商城(云悦生活的商城)的逻辑,加入规格表、规格项目表、规格价格表

zhangwl 2 weeks ago
parent
commit
6b41123171

+ 141 - 0
src/main/java/zs/payment/entity/mysql/ImsEweiShopGoodsOption.java

@@ -0,0 +1,141 @@
+package zs.payment.entity.mysql;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+/**
+ * 商品规格选项
+ */
+@Setter
+@Getter
+@NoArgsConstructor
+@TableName("ims_ewei_shop_goods_option")
+public class ImsEweiShopGoodsOption {
+    //create table ims_ewei_shop_goods_option
+    //(
+    //    id                int auto_increment
+    //        primary key,
+    //    uniacid           int            default 0    null,
+    //    goodsid           int(10)        default 0    null,
+    //    title             varchar(255)   default ''   null,
+    //    thumb             varchar(60)    default ''   null,
+    //    productprice      decimal(10, 2) default 0.00 null,
+    //    marketprice       decimal(10, 2) default 0.00 null,
+    //    costprice         decimal(10, 2) default 0.00 null,
+    //    stock             int            default 0    null,
+    //    weight            decimal(10, 2) default 0.00 null,
+    //    displayorder      int            default 0    null,
+    //    specs             text                        null,
+    //    skuId             varchar(255)   default ''   null,
+    //    goodssn           varchar(255)   default ''   null,
+    //    productsn         varchar(255)   default ''   null,
+    //    `virtual`         int            default 0    null,
+    //    exchange_stock    int            default 0    null,
+    //    exchange_postage  decimal(10, 2) default 0.00 not null,
+    //    presellprice      decimal(10, 2) default 0.00 not null,
+    //    day               int(3)                      not null,
+    //    allfullbackprice  decimal(10, 2)              not null,
+    //    fullbackprice     decimal(10, 2)              not null,
+    //    allfullbackratio  decimal(10, 2)              null,
+    //    fullbackratio     decimal(10, 2)              null,
+    //    isfullback        tinyint(3)                  not null,
+    //    islive            int                         not null,
+    //    liveprice         decimal(10, 2) default 0.00 not null,
+    //    cycelbuy_periodic varchar(20)    default ''   not null,
+    //    sku_id            int            default 0    null comment '云商城规格id'
+    //)
+
+    @TableId(type = IdType.AUTO)
+    private Long id;
+
+    //所属企云商城的id
+    private Integer uniacid;
+
+    //商品id
+    private Integer goodsid;
+
+    //规格标题
+    private String title;
+
+    //缩略图
+    private String thumb;
+
+    //销售价
+    private BigDecimal productprice;
+
+    //市场价
+    private BigDecimal marketprice;
+
+    //成本价
+    private BigDecimal costprice;
+
+    //库存
+    private Integer stock;
+
+    //重量
+    private BigDecimal weight;
+
+    //排序
+    private Integer displayorder;
+
+    //规格内容
+    private String specs;
+
+    //SKU id ,存储芸信的商品规格id,下单与获取运费验证是否可售等使用这个
+    private String skuId;
+
+    //商品编号
+    private String goodssn;
+
+    //货品编号
+    private String productsn;
+
+    //是否虚拟
+    private Integer virtual;
+
+    //兑换库存
+    private Integer exchange_stock;
+
+    //兑换邮费
+    private BigDecimal exchange_postage;
+
+    //预售价
+    private BigDecimal presellprice;
+
+    //天数
+    private Integer day;
+
+    //全返总价
+    private BigDecimal allfullbackprice;
+
+    //全返价
+    private BigDecimal fullbackprice;
+
+    //全返总比例
+    private BigDecimal allfullbackratio;
+
+    //全返比例
+    private BigDecimal fullbackratio;
+
+    //是否全返
+    private Integer isfullback;
+
+    //是否直播
+    private Integer islive;
+
+    //直播价
+    private BigDecimal liveprice;
+
+    //周期购周期
+    private String cycelbuy_periodic;
+
+    //云商城规格id
+    private Integer sku_id;
+
+}

+ 55 - 0
src/main/java/zs/payment/entity/mysql/ImsEweiShopGoodsSpec.java

@@ -0,0 +1,55 @@
+package zs.payment.entity.mysql;
+
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * 商品规格
+ */
+@Setter
+@Getter
+@NoArgsConstructor
+@TableName("ims_ewei_shop_goods_spec")
+public class ImsEweiShopGoodsSpec {
+    //create table ims_ewei_shop_goods_spec
+    //(
+    //    id           int auto_increment
+    //        primary key,
+    //    uniacid      int           default 0  null,
+    //    goodsid      int           default 0  null,
+    //    title        varchar(50)   default '' null,
+    //    description  varchar(1000) default '' null,
+    //    displaytype  tinyint(3)    default 0  null,
+    //    content      text                     null,
+    //    displayorder int           default 0  null,
+    //    propId       varchar(255)  default '' null,
+    //    iscycelbuy   tinyint(1)    default 0  not null,
+    //    yunspecid    int                      null comment '云商城id',
+    //    src_id       int                      null comment '复制原来id'
+    //)
+
+    @TableId(type = IdType.AUTO)
+    private Long id;
+
+    //所属企云商城的id
+    private Integer uniacid;
+
+    private Integer goodsid;
+    private String title;
+    private String description;
+    private Integer displaytype;
+    private String content;
+    private Integer displayorder;
+    private String propId;
+    private Integer iscycelbuy;
+    private Integer yunspecid;
+    private Integer src_id;
+
+
+
+}

+ 57 - 0
src/main/java/zs/payment/entity/mysql/ImsEweiShopGoodsSpecItem.java

@@ -0,0 +1,57 @@
+package zs.payment.entity.mysql;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * 商品规格项
+ */
+@Setter
+@Getter
+@NoArgsConstructor
+@TableName("ims_ewei_shop_goods_spec_item")
+public class ImsEweiShopGoodsSpecItem {
+
+    //create table ims_ewei_shop_goods_spec_item
+    //(
+    //    id                int auto_increment
+    //        primary key,
+    //    uniacid           int          default 0  null,
+    //    specid            int          default 0  null,
+    //    title             varchar(255) default '' null,
+    //    thumb             varchar(255) default '' null,
+    //    `show`            int          default 0  null,
+    //    displayorder      int          default 0  null,
+    //    valueId           varchar(255) default '' null,
+    //    `virtual`         int          default 0  null,
+    //    cycelbuy_periodic varchar(20)  default '' not null,
+    //    yunspecitemid     int          default 0  null comment '云商城id'
+    //)
+
+    @TableId(type = IdType.AUTO)
+    private Long id;
+
+    // 所属企云商城的id
+    private Integer uniacid;
+//关联规格id
+    private Integer specid;
+    //规格项名称
+    private String title;
+    //缩略图
+    private String thumb;
+    //是否显示,默认1
+    private Integer show;
+    //排序 ,默认0
+    private Integer displayorder;
+    private String valueId;
+    //是否虚拟
+    private Integer virtual;
+    private String cycelbuy_periodic;
+    // 云商城id
+    private Integer yunspecitemid;
+
+}

+ 9 - 0
src/main/java/zs/payment/mapper/ImsEweiShopGoodsOptionMapper.java

@@ -0,0 +1,9 @@
+package zs.payment.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import zs.payment.entity.mysql.ImsEweiShopGoodsOption;
+
+@Mapper
+public interface ImsEweiShopGoodsOptionMapper extends BaseMapper<ImsEweiShopGoodsOption> {
+}

+ 10 - 0
src/main/java/zs/payment/mapper/ImsEweiShopGoodsSpecItemMapper.java

@@ -0,0 +1,10 @@
+package zs.payment.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import zs.payment.entity.mysql.ImsEweiShopGoodsSpecItem;
+
+@Mapper
+public interface ImsEweiShopGoodsSpecItemMapper extends BaseMapper<ImsEweiShopGoodsSpecItem> {
+
+}

+ 9 - 0
src/main/java/zs/payment/mapper/ImsEweiShopGoodsSpecMapper.java

@@ -0,0 +1,9 @@
+package zs.payment.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import zs.payment.entity.mysql.ImsEweiShopGoodsSpec;
+
+@Mapper
+public interface ImsEweiShopGoodsSpecMapper extends BaseMapper<ImsEweiShopGoodsSpec> {
+}

+ 70 - 9
src/main/java/zs/payment/messages/KafkaConsumer.java

@@ -11,13 +11,16 @@ import org.springframework.kafka.annotation.KafkaListener;
 import org.springframework.stereotype.Component;
 
 import zs.payment.dto.OrderDetailDTO;
-import zs.payment.entity.mysql.ImsEweiShopCategory;
-import zs.payment.entity.mysql.ImsEweiShopGoods;
+import zs.payment.dto.SkuDTO;
+import zs.payment.entity.mysql.*;
 import zs.payment.enums.ProductSupplyRedis;
 import zs.payment.req.ProductDetailReq;
 import zs.payment.resp.Result;
 import zs.payment.service.Imseweishopgoods.ImsEweiShopGoodsService;
 import zs.payment.service.imseweishopcategory.ImsEweiShopCategoryService;
+import zs.payment.service.imseweishopgoodsoption.ImsEweiShopGoodsOptionService;
+import zs.payment.service.imseweishopgoodsspec.ImsEweiShopGoodsSpecService;
+import zs.payment.service.imseweishopgoodsspecitem.ImsEweiShopGoodsSpecItemService;
 import zs.payment.service.paysupply.PaySupplyService;
 import zs.payment.utils.RedisUtils;
 import zs.payment.utils.TimeUtils;
@@ -39,8 +42,17 @@ public class KafkaConsumer {
 
     @Autowired
     private ImsEweiShopCategoryService imsEweiShopCategoryService;
+    //商品表
     @Autowired
     private ImsEweiShopGoodsService imsEweiShopGoodsService;
+    //规格
+    @Autowired
+    private ImsEweiShopGoodsSpecService imsEweiShopGoodsSpecService;
+    //规格项目
+    @Autowired
+    private ImsEweiShopGoodsSpecItemService  imsEweiShopGoodsSpecItemService;
+    @Autowired
+    private ImsEweiShopGoodsOptionService imsEweiShopGoodsOptionService;
 
 
     /**
@@ -76,11 +88,12 @@ public class KafkaConsumer {
      * @param messsage
      */
     @KafkaListener(
-        topics = "goods.after",
+        topics = "goods.alter",
         groupId = "pay2-group"
     )
-    public void goodsAfter(String messsage) {
+    public void goodsAlter(String messsage) {
 
+        log.info("---准备开始商品入库---");
         JSONObject jsonObject = JSONObject.parseObject(messsage);
         int productId = jsonObject.getIntValue("product_id");
         ProductDetailReq req=new ProductDetailReq();
@@ -101,6 +114,7 @@ public class KafkaConsumer {
 
                 Boolean b = redisUtils.sismember(ProductSupplyRedis.SYNC_SUPPLY_ID, dto.getId().toString());
                 if (!b){
+                    Integer uniacid=463;
 
                     //第一级
                     Long pcate=0L;
@@ -190,16 +204,63 @@ public class KafkaConsumer {
                     //商品条码
                     goods.setProductsn(dto.getBarcode());
                     //默认发布给云悦生活
-                    goods.setUniacid(463);
-                    imsEweiShopGoodsService.save(goods);
+                    goods.setUniacid(uniacid);
+                    //创建商品表
+                    boolean b2 = imsEweiShopGoodsService.save(goods);
 
-                }
+                    if (!b2){
+                        log.error("商品{}创建失败",productId);
+                        return;
+                    }
 
+                    //创建规格
+                    ImsEweiShopGoodsSpec goodsSpec=new ImsEweiShopGoodsSpec();
+                    goodsSpec.setTitle("规格");
+                    goodsSpec.setUniacid(uniacid);
+                    goodsSpec.setGoodsid(goods.getId().intValue());
+
+                    boolean b3 = imsEweiShopGoodsSpecService.save(goodsSpec);
+
+
+                    for (int i = 0; i < dto.getSkus().size(); i++) {
+                        SkuDTO sku = dto.getSkus().get(i);
+                        ImsEweiShopGoodsSpecItem goodsSpecItem = new ImsEweiShopGoodsSpecItem();
+                        goodsSpecItem.setShow(1);
+                        goodsSpecItem.setUniacid(uniacid);
+                        goodsSpecItem.setSpecid(goodsSpec.getId().intValue());
+                        goodsSpecItem.setTitle(sku.getTitle());
+                        goodsSpecItem.setDisplayorder(i);
+
+                        //创建规格项目
+                        imsEweiShopGoodsSpecItemService.save(goodsSpecItem);
+
+                        //创建规格项目的价格
+                        ImsEweiShopGoodsOption goodsOption=new  ImsEweiShopGoodsOption();
+                        goodsOption.setTitle(sku.getTitle());
+                        goodsOption.setUniacid(uniacid);
+                        goodsOption.setGoodsid(goods.getId().intValue());
+                        goodsOption.setSpecs(goodsSpecItem.getId().toString());
+                        //原价
+                        goodsOption.setProductprice(new BigDecimal(sku.getOrigin_price()/100));
+                        //指导价
+                        goodsOption.setMarketprice(new BigDecimal(sku.getGuide_price()/100));
+                        //成本价
+                        goodsOption.setCostprice(new BigDecimal(sku.getCost_price()/100));
+                        goodsOption.setStock(sku.getStock());
+                        goodsOption.setWeight(new BigDecimal(sku.getWeight()));
+                        //下单与获取运费验证是否可售等使用这个
+                        goodsOption.setSkuId(sku.getId().toString());
+                        goodsOption.setGoodssn(sku.getSn());
+                        //预售价 = 售价
+                        goodsOption.setPresellprice(new BigDecimal(sku.getPrice()/100));
+                        imsEweiShopGoodsOptionService.save(goodsOption);
+                    }
+                }
 
             });
-            log.info("=======productId:{} feed pool refill end=======",ids);
+            log.info("=======productId:{} goodsAlter end=======",ids);
         }else {
-            log.error("kafka consumer goods.after 商品详情查询失败");
+            log.error("kafka consumer goods.alter 商品{}详情查询失败",productId);
         }
 
 

+ 7 - 0
src/main/java/zs/payment/service/imseweishopgoodsoption/ImsEweiShopGoodsOptionService.java

@@ -0,0 +1,7 @@
+package zs.payment.service.imseweishopgoodsoption;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import zs.payment.entity.mysql.ImsEweiShopGoodsOption;
+
+public interface ImsEweiShopGoodsOptionService extends IService<ImsEweiShopGoodsOption> {
+}

+ 14 - 0
src/main/java/zs/payment/service/imseweishopgoodsoption/impl/ImsEweiShopGoodsOptionServiceImpl.java

@@ -0,0 +1,14 @@
+package zs.payment.service.imseweishopgoodsoption.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.Setter;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import zs.payment.entity.mysql.ImsEweiShopGoodsOption;
+import zs.payment.mapper.ImsEweiShopGoodsOptionMapper;
+import zs.payment.service.imseweishopgoodsoption.ImsEweiShopGoodsOptionService;
+
+@Slf4j
+@Service
+public class ImsEweiShopGoodsOptionServiceImpl extends ServiceImpl<ImsEweiShopGoodsOptionMapper, ImsEweiShopGoodsOption> implements ImsEweiShopGoodsOptionService {
+}

+ 7 - 0
src/main/java/zs/payment/service/imseweishopgoodsspec/ImsEweiShopGoodsSpecService.java

@@ -0,0 +1,7 @@
+package zs.payment.service.imseweishopgoodsspec;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import zs.payment.entity.mysql.ImsEweiShopGoodsSpec;
+
+public interface ImsEweiShopGoodsSpecService extends IService<ImsEweiShopGoodsSpec> {
+}

+ 14 - 0
src/main/java/zs/payment/service/imseweishopgoodsspec/impl/ImsEweiShopGoodsSpecServiceImpl.java

@@ -0,0 +1,14 @@
+package zs.payment.service.imseweishopgoodsspec.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import zs.payment.entity.mysql.ImsEweiShopGoodsSpec;
+import zs.payment.mapper.ImsEweiShopGoodsSpecMapper;
+import zs.payment.service.imseweishopgoodsspec.ImsEweiShopGoodsSpecService;
+
+@Slf4j
+@Service
+public class ImsEweiShopGoodsSpecServiceImpl extends ServiceImpl<ImsEweiShopGoodsSpecMapper, ImsEweiShopGoodsSpec> implements ImsEweiShopGoodsSpecService {
+
+}

+ 7 - 0
src/main/java/zs/payment/service/imseweishopgoodsspecitem/ImsEweiShopGoodsSpecItemService.java

@@ -0,0 +1,7 @@
+package zs.payment.service.imseweishopgoodsspecitem;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import zs.payment.entity.mysql.ImsEweiShopGoodsSpecItem;
+
+public interface ImsEweiShopGoodsSpecItemService extends IService<ImsEweiShopGoodsSpecItem> {
+}

+ 14 - 0
src/main/java/zs/payment/service/imseweishopgoodsspecitem/impl/ImsEweiShopGoodsSpecItemServiceImpl.java

@@ -0,0 +1,14 @@
+package zs.payment.service.imseweishopgoodsspecitem.impl;
+
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import zs.payment.entity.mysql.ImsEweiShopGoodsSpecItem;
+import zs.payment.mapper.ImsEweiShopGoodsSpecItemMapper;
+import zs.payment.service.imseweishopgoodsspecitem.ImsEweiShopGoodsSpecItemService;
+
+@Slf4j
+@Service
+public class ImsEweiShopGoodsSpecItemServiceImpl extends ServiceImpl<ImsEweiShopGoodsSpecItemMapper, ImsEweiShopGoodsSpecItem> implements ImsEweiShopGoodsSpecItemService {
+}