Browse Source

批量同步到自研系统

zhangwl 6 days ago
parent
commit
caa7c957d5

+ 21 - 9
src/main/java/zs/payment/controller/YxSupplyChannelManualController.java

@@ -4,10 +4,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 
 
 
 
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import zs.payment.dao.OrderCallbackDao;
 import zs.payment.dao.OrderCallbackDao;
 import zs.payment.entity.OrderCallback;
 import zs.payment.entity.OrderCallback;
@@ -143,11 +140,10 @@ public class YxSupplyChannelManualController {
             }
             }
             JSONObject json=new JSONObject();
             JSONObject json=new JSONObject();
             json.put("product_id", productId);
             json.put("product_id", productId);
-            // 商品变更,有可能是加入到选品库了
-            if (CallbackMessageType.GOODS_ALTER.equalsIgnoreCase(messageType)){
-
-                //添加商品
-                kafkaProducer.sendMessage(CallbackMessageType.GOODS_ALTER, json.toJSONString());
+            // 商品删除
+            if (CallbackMessageType.GOODS_DELETE.equalsIgnoreCase(messageType)){
+                //删除商品
+                kafkaProducer.sendMessage(CallbackMessageType.GOODS_DELETE, json.toJSONString());
             }
             }
             // 当商品下架的时候,更新商品为下架
             // 当商品下架的时候,更新商品为下架
             if (CallbackMessageType.GOODS_UNDERCARRIAGE.equalsIgnoreCase(messageType)){
             if (CallbackMessageType.GOODS_UNDERCARRIAGE.equalsIgnoreCase(messageType)){
@@ -155,6 +151,12 @@ public class YxSupplyChannelManualController {
                 kafkaProducer.sendMessage(CallbackMessageType.GOODS_UNDERCARRIAGE, json.toJSONString());
                 kafkaProducer.sendMessage(CallbackMessageType.GOODS_UNDERCARRIAGE, json.toJSONString());
             }
             }
 
 
+            // 当商品上架的时候,若已同步,则更新商品为上架
+            if (CallbackMessageType.GOODS_ON_SALE.equalsIgnoreCase(messageType)){
+                //更新商品下架,状态变更,
+                kafkaProducer.sendMessage(CallbackMessageType.GOODS_ON_SALE, json.toJSONString());
+            }
+
         }
         }
 
 
         //售后通过
         //售后通过
@@ -176,4 +178,14 @@ public class YxSupplyChannelManualController {
     }
     }
 
 
 
 
+    /**
+     * 同步到自研系统上
+     * @return
+     */
+    @GetMapping("/syncToQiyun")
+    public Result syncToQiyun() {
+        return paySupplyService.syncToQiyun();
+    }
+
+
 }
 }

+ 7 - 1
src/main/java/zs/payment/entity/mysql/ImsEweiShopGoods.java

@@ -133,7 +133,7 @@ public class ImsEweiShopGoods {
     private String commission;
     private String commission;
     // 得分
     // 得分
     private BigDecimal score;
     private BigDecimal score;
-    // 抓取产品信息ID/星链导入商品spuid,共富商城第三方商品id
+    // 抓取产品信息ID/星链导入商品spuid,共富商城第三方商品id, 芸信供应链id
     private String catch_id;
     private String catch_id;
     // 抓取产品地址/共富商城第三方商品链接
     // 抓取产品地址/共富商城第三方商品链接
     private String catch_url;
     private String catch_url;
@@ -506,4 +506,10 @@ public class ImsEweiShopGoods {
     private String level_reward_jfb;
     private String level_reward_jfb;
     // 商品类别:0线上商品 1线下商品
     // 商品类别:0线上商品 1线下商品
     private Integer kind;
     private Integer kind;
+
+    //============以下是供应链需求,新增字段========================
+    //商品供应来源 芸信yunxin
+    private String supply_source;
+    //供应链的商品id
+    private String supply_id;
 }
 }

+ 2 - 0
src/main/java/zs/payment/enums/CallbackMessageType.java

@@ -11,6 +11,8 @@ public interface CallbackMessageType {
     String GOODS_ON_SALE="goods.on.sale";
     String GOODS_ON_SALE="goods.on.sale";
     //商品删除
     //商品删除
     String GOODS_DELETE="goods.delete";
     String GOODS_DELETE="goods.delete";
+    //自定义-商品同步到自研系统
+    String GOODS_SYNC="goods.sync";
 
 
     //=============订单======================
     //=============订单======================
     //订单取消
     //订单取消

+ 106 - 62
src/main/java/zs/payment/messages/KafkaConsumer.java

@@ -1,5 +1,6 @@
 package zs.payment.messages;
 package zs.payment.messages;
 
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 
 
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -51,13 +52,14 @@ public class KafkaConsumer {
     private ImsEweiShopGoodsSpecService imsEweiShopGoodsSpecService;
     private ImsEweiShopGoodsSpecService imsEweiShopGoodsSpecService;
     //规格项目
     //规格项目
     @Autowired
     @Autowired
-    private ImsEweiShopGoodsSpecItemService  imsEweiShopGoodsSpecItemService;
+    private ImsEweiShopGoodsSpecItemService imsEweiShopGoodsSpecItemService;
     @Autowired
     @Autowired
     private ImsEweiShopGoodsOptionService imsEweiShopGoodsOptionService;
     private ImsEweiShopGoodsOptionService imsEweiShopGoodsOptionService;
 
 
 
 
     /**
     /**
      * 商品下架
      * 商品下架
+     *
      * @param messsage
      * @param messsage
      */
      */
     @KafkaListener(
     @KafkaListener(
@@ -68,20 +70,68 @@ public class KafkaConsumer {
         JSONObject jsonObject = JSONObject.parseObject(messsage);
         JSONObject jsonObject = JSONObject.parseObject(messsage);
         int productId = jsonObject.getIntValue("product_id");
         int productId = jsonObject.getIntValue("product_id");
 
 
-        // 更新商品状态为下架   update ims_ewei_shop_goods set  status = 0 where catch_id=productId
-
-        boolean b = imsEweiShopGoodsService.update(
-            new LambdaUpdateWrapper<ImsEweiShopGoods>()
-                .set(ImsEweiShopGoods::getStatus, 0)
-                .eq(ImsEweiShopGoods::getCatch_id, String.valueOf(productId))
-        );
-        if (!b){
-            log.error("--------商品{}下架状态修改失败--------", productId);
+        // 更新商品状态为下架   update ims_ewei_shop_goods set  status = 0 where catch_source=yunxin and catch_id=productId
+        Boolean b = redisUtils.sismember(ProductSupplyRedis.SYNC_SUPPLY_ID, productId + "");
+        if (b) {
+            b = imsEweiShopGoodsService.updateStatusBySupplyId(String.valueOf(productId), "yunxin", 0);
+            if (!b) {
+                log.error("--------商品{}下架状态修改失败--------", productId);
+            }
         }
         }
+    }
 
 
+
+    /**
+     * 商品上架
+     *
+     * @param messsage
+     */
+    @KafkaListener(
+        topics = "goods.on.sale",
+        groupId = "pay2-group"
+    )
+    public void goodsOnSale(String messsage) {
+        JSONObject jsonObject = JSONObject.parseObject(messsage);
+        int productId = jsonObject.getIntValue("product_id");
+
+        // 更新商品状态为上架   update ims_ewei_shop_goods set  status = 1 where catch_source=yunxin and catch_id=productId
+        Boolean b = redisUtils.sismember(ProductSupplyRedis.SYNC_SUPPLY_ID, productId + "");
+        if (b) {
+            b = imsEweiShopGoodsService.updateStatusBySupplyId(String.valueOf(productId), "yunxin", 1);
+            if (!b) {
+                log.error("--------商品{}上架状态修改失败--------", productId);
+            }
+        }
     }
     }
 
 
 
 
+    /**
+     * 商品删除
+     *
+     * @param messsage
+     */
+    @KafkaListener(
+        topics = "goods.delete",
+        groupId = "pay2-group"
+    )
+    public void goodsDelete(String messsage) {
+        JSONObject jsonObject = JSONObject.parseObject(messsage);
+        int productId = jsonObject.getIntValue("product_id");
+
+        // 更新商品状态为下架   update ims_ewei_shop_goods set  status = 0 where catch_source=yunxin and catch_id=productId
+        Boolean b = redisUtils.sismember(ProductSupplyRedis.SYNC_SUPPLY_ID, productId + "");
+        if (b) {
+            b = imsEweiShopGoodsService.deleteBySupplyId(String.valueOf(productId), "yunxin");
+            if (!b) {
+                log.error("--------商品{}删除状态修改失败--------", productId);
+            } else {
+                //删除key
+                redisUtils.srem(ProductSupplyRedis.SYNC_SUPPLY_ID, productId + "");
+            }
+        }
+
+    }
+
 
 
     /**
     /**
      * 商品添加
      * 商品添加
@@ -89,18 +139,15 @@ public class KafkaConsumer {
      * @param messsage
      * @param messsage
      */
      */
     @KafkaListener(
     @KafkaListener(
-        topics = "goods.alter",
+        topics = "goods.sync",
         groupId = "pay2-group"
         groupId = "pay2-group"
     )
     )
-    @Transactional(rollbackFor =  Exception.class)
+    @Transactional(rollbackFor = Exception.class)
     public void goodsAlter(String messsage) {
     public void goodsAlter(String messsage) {
 
 
-        log.info("---准备开始商品入库---");
-        JSONObject jsonObject = JSONObject.parseObject(messsage);
-        int productId = jsonObject.getIntValue("product_id");
-        ProductDetailReq req=new ProductDetailReq();
-        List<Integer>  ids=new ArrayList<>();
-        ids.add(productId);
+        log.info("---准备开始商品入库{}---",messsage);
+        List<Integer> ids = JSONArray.parseArray(messsage, Integer.class);
+        ProductDetailReq req = new ProductDetailReq();
         req.setIds(ids);
         req.setIds(ids);
         Result result = paySupplyService.detailList(req);
         Result result = paySupplyService.detailList(req);
 
 
@@ -115,43 +162,45 @@ public class KafkaConsumer {
                 //todo 先查看该商品编号是否已同步企云商城。若没同步,则判断商品分类是否存在。不存在则创建
                 //todo 先查看该商品编号是否已同步企云商城。若没同步,则判断商品分类是否存在。不存在则创建
 
 
                 Boolean b = redisUtils.sismember(ProductSupplyRedis.SYNC_SUPPLY_ID, dto.getId().toString());
                 Boolean b = redisUtils.sismember(ProductSupplyRedis.SYNC_SUPPLY_ID, dto.getId().toString());
-                if (!b){
-                    Integer uniacid=463;
+                if (!b) {
+                    //不存在,则需要添加
+
+                    Integer uniacid = 463;
 
 
                     //第一级
                     //第一级
-                    Long pcate=0L;
+                    Long pcate = 0L;
                     //第二级
                     //第二级
-                    Long ccate=0L;
+                    Long ccate = 0L;
                     //第三级
                     //第三级
-                    Long tcate=0L;
+                    Long tcate = 0L;
 
 
                     //未同步,则判断商品分类
                     //未同步,则判断商品分类
-                    ImsEweiShopCategory category1 = imsEweiShopCategoryService.selectByName(dto.getCategory_1().getName(), dto.getCategory_1().getLevel(),0L,uniacid);
-                    if (!Optional.ofNullable(category1).isPresent()){
+                    ImsEweiShopCategory category1 = imsEweiShopCategoryService.selectByName(dto.getCategory_1().getName(), dto.getCategory_1().getLevel(), 0L, uniacid);
+                    if (!Optional.ofNullable(category1).isPresent()) {
                         //创建新的商品分类
                         //创建新的商品分类
-                        category1=new ImsEweiShopCategory();
+                        category1 = new ImsEweiShopCategory();
                         category1.setLevel(1);
                         category1.setLevel(1);
                         category1.setName(dto.getCategory_1().getName());
                         category1.setName(dto.getCategory_1().getName());
                         category1.setParentId(0);
                         category1.setParentId(0);
                         category1.setUniacId(uniacid);
                         category1.setUniacId(uniacid);
                         imsEweiShopCategoryService.save(category1);
                         imsEweiShopCategoryService.save(category1);
                     }
                     }
-                    pcate=category1.getId();
+                    pcate = category1.getId();
                     // 存在,再查询商品分类第二级
                     // 存在,再查询商品分类第二级
-                    ImsEweiShopCategory category2 = imsEweiShopCategoryService.selectByName(dto.getCategory_2().getName(), dto.getCategory_2().getLevel(),pcate,uniacid);
-                    if (!Optional.ofNullable(category2).isPresent()){
-                        category2=new ImsEweiShopCategory();
+                    ImsEweiShopCategory category2 = imsEweiShopCategoryService.selectByName(dto.getCategory_2().getName(), dto.getCategory_2().getLevel(), pcate, uniacid);
+                    if (!Optional.ofNullable(category2).isPresent()) {
+                        category2 = new ImsEweiShopCategory();
                         category2.setLevel(2);
                         category2.setLevel(2);
                         category2.setName(dto.getCategory_2().getName());
                         category2.setName(dto.getCategory_2().getName());
                         category2.setParentId(pcate.intValue());
                         category2.setParentId(pcate.intValue());
                         category2.setUniacId(uniacid);
                         category2.setUniacId(uniacid);
                         imsEweiShopCategoryService.save(category2);
                         imsEweiShopCategoryService.save(category2);
                     }
                     }
-                    ccate=category2.getId();
+                    ccate = category2.getId();
 
 
                     // 再查询商品分类第三级
                     // 再查询商品分类第三级
-                    ImsEweiShopCategory category3 = imsEweiShopCategoryService.selectByName(dto.getCategory_3().getName(), dto.getCategory_3().getLevel(),ccate,uniacid);
-                    if (!Optional.ofNullable(category3).isPresent()){
+                    ImsEweiShopCategory category3 = imsEweiShopCategoryService.selectByName(dto.getCategory_3().getName(), dto.getCategory_3().getLevel(), ccate, uniacid);
+                    if (!Optional.ofNullable(category3).isPresent()) {
                         category3 = new ImsEweiShopCategory();
                         category3 = new ImsEweiShopCategory();
                         category3.setLevel(3);
                         category3.setLevel(3);
                         category3.setName(dto.getCategory_3().getName());
                         category3.setName(dto.getCategory_3().getName());
@@ -159,11 +208,10 @@ public class KafkaConsumer {
                         category3.setUniacId(uniacid);
                         category3.setUniacId(uniacid);
                         imsEweiShopCategoryService.save(category3);
                         imsEweiShopCategoryService.save(category3);
                     }
                     }
-                    tcate=category3.getId();
-
+                    tcate = category3.getId();
 
 
                     //todo 创建商品
                     //todo 创建商品
-                    ImsEweiShopGoods goods=new  ImsEweiShopGoods();
+                    ImsEweiShopGoods goods = new ImsEweiShopGoods();
                     //直接作为推荐商品展示
                     //直接作为推荐商品展示
                     goods.setIsrecommand(1);
                     goods.setIsrecommand(1);
                     //商品分类
                     //商品分类
@@ -184,11 +232,11 @@ public class KafkaConsumer {
                     goods.setUnit(dto.getUnit());
                     goods.setUnit(dto.getUnit());
                     goods.setContent(dto.getDetail_images());
                     goods.setContent(dto.getDetail_images());
                     //================价格====================
                     //================价格====================
-                    goods.setProductprice(new BigDecimal(dto.getGuide_price()/100));
-                    goods.setMarketprice(new BigDecimal(dto.getMarket_price()/100));
+                    goods.setProductprice(new BigDecimal(dto.getGuide_price() / 100));
+                    goods.setMarketprice(new BigDecimal(dto.getMarket_price() / 100));
                     goods.setCostprice(new BigDecimal(0));
                     goods.setCostprice(new BigDecimal(0));
-                    goods.setCost_of_price(new BigDecimal(dto.getCost_price()/100));
-                    goods.setOriginalprice(new BigDecimal(dto.getOrigin_price()/100));
+                    goods.setCost_of_price(new BigDecimal(dto.getCost_price() / 100));
+                    goods.setOriginalprice(new BigDecimal(dto.getOrigin_price() / 100));
 
 
                     goods.setTotal(dto.getStock());
                     goods.setTotal(dto.getStock());
                     // 0 拍下减库存 1 付款减库存 2 永久不减
                     // 0 拍下减库存 1 付款减库存 2 永久不减
@@ -199,13 +247,13 @@ public class KafkaConsumer {
                     goods.setIshot(0);
                     goods.setIshot(0);
                     goods.setIsdiscount(0);
                     goods.setIsdiscount(0);
                     //商品来源
                     //商品来源
-                    goods.setCatch_source("yunxin");
+                    goods.setSupply_source("yunxin");
                     //芸信商城的商品主键
                     //芸信商城的商品主键
-                    goods.setCatch_id(dto.getId().toString());
+                    goods.setSupply_id(dto.getId().toString());
 //                    goods.setCates("");
 //                    goods.setCates("");
                     //数据库里的时间戳是秒级
                     //数据库里的时间戳是秒级
-                    goods.setCreatetime(TimeUtils.getLongFromCurrentTime()/1000);
-                    goods.setUpdatetime(TimeUtils.getLongFromCurrentTime()/1000);
+                    goods.setCreatetime(TimeUtils.getLongFromCurrentTime() / 1000);
+                    goods.setUpdatetime(TimeUtils.getLongFromCurrentTime() / 1000);
                     goods.setDeleted(0);
                     goods.setDeleted(0);
                     //多商户id
                     //多商户id
                     goods.setMerchid(0);
                     goods.setMerchid(0);
@@ -222,13 +270,13 @@ public class KafkaConsumer {
                     //创建商品表
                     //创建商品表
                     boolean b2 = imsEweiShopGoodsService.save(goods);
                     boolean b2 = imsEweiShopGoodsService.save(goods);
 
 
-                    if (!b2){
-                        log.error("商品{}创建失败",productId);
+                    if (!b2) {
+                        log.error("商品{}创建失败", dto.getId().toString());
                         return;
                         return;
                     }
                     }
 
 
                     //创建规格
                     //创建规格
-                    ImsEweiShopGoodsSpec goodsSpec=new ImsEweiShopGoodsSpec();
+                    ImsEweiShopGoodsSpec goodsSpec = new ImsEweiShopGoodsSpec();
                     goodsSpec.setTitle("规格");
                     goodsSpec.setTitle("规格");
                     goodsSpec.setUniacid(uniacid);
                     goodsSpec.setUniacid(uniacid);
                     goodsSpec.setGoodsid(goods.getId().intValue());
                     goodsSpec.setGoodsid(goods.getId().intValue());
@@ -249,19 +297,19 @@ public class KafkaConsumer {
                         boolean b4 = imsEweiShopGoodsSpecItemService.save(goodsSpecItem);
                         boolean b4 = imsEweiShopGoodsSpecItemService.save(goodsSpecItem);
 
 
                         //创建规格项目的价格
                         //创建规格项目的价格
-                        ImsEweiShopGoodsOption goodsOption=new  ImsEweiShopGoodsOption();
+                        ImsEweiShopGoodsOption goodsOption = new ImsEweiShopGoodsOption();
                         goodsOption.setTitle(sku.getTitle());
                         goodsOption.setTitle(sku.getTitle());
                         goodsOption.setUniacid(uniacid);
                         goodsOption.setUniacid(uniacid);
                         goodsOption.setGoodsid(goods.getId().intValue());
                         goodsOption.setGoodsid(goods.getId().intValue());
                         goodsOption.setSpecs(goodsSpecItem.getId().toString());
                         goodsOption.setSpecs(goodsSpecItem.getId().toString());
                         //原价,可用于打折,最大价格
                         //原价,可用于打折,最大价格
-                        goodsOption.setProductprice(new BigDecimal(sku.getGuide_price()/100));
+                        goodsOption.setProductprice(new BigDecimal(sku.getGuide_price() / 100));
                         //现价 不能大于原价
                         //现价 不能大于原价
-                        goodsOption.setMarketprice(new BigDecimal(sku.getGuide_price()/100));
+                        goodsOption.setMarketprice(new BigDecimal(sku.getGuide_price() / 100));
                         //成本价
                         //成本价
-                        goodsOption.setCostprice(new BigDecimal(sku.getCost_price()/100));
+                        goodsOption.setCostprice(new BigDecimal(sku.getCost_price() / 100));
                         //预售价 = 售价
                         //预售价 = 售价
-                        goodsOption.setPresellprice(new BigDecimal(sku.getPrice()/100));
+                        goodsOption.setPresellprice(new BigDecimal(sku.getPrice() / 100));
 
 
                         goodsOption.setStock(sku.getStock());
                         goodsOption.setStock(sku.getStock());
                         goodsOption.setWeight(new BigDecimal(sku.getWeight()));
                         goodsOption.setWeight(new BigDecimal(sku.getWeight()));
@@ -276,28 +324,24 @@ public class KafkaConsumer {
                         goodsOption.setIslive(0);
                         goodsOption.setIslive(0);
                         goodsOption.setLiveprice(new BigDecimal(0));
                         goodsOption.setLiveprice(new BigDecimal(0));
                         //企云商城的商品重量为0时,金额为0
                         //企云商城的商品重量为0时,金额为0
-                        goodsOption.setWeight(sku.getWeight()==0?new BigDecimal(1):new BigDecimal(sku.getWeight()));
+                        goodsOption.setWeight(sku.getWeight() == 0 ? new BigDecimal(1) : new BigDecimal(sku.getWeight()));
 
 
                         boolean b5 = imsEweiShopGoodsOptionService.save(goodsOption);
                         boolean b5 = imsEweiShopGoodsOptionService.save(goodsOption);
                     }
                     }
                     redisUtils.sadd(ProductSupplyRedis.SYNC_SUPPLY_ID, dto.getId().toString());
                     redisUtils.sadd(ProductSupplyRedis.SYNC_SUPPLY_ID, dto.getId().toString());
-                }else{
-                    log.error("====商品{}已同步过=====",productId);
+                } else {
+                    log.error("====商品{}已同步过=====", dto.getId().toString());
 
 
                 }
                 }
 
 
             });
             });
-            log.info("=======productId:{} goodsAlter end=======",ids);
-        }else {
-            log.error("kafka consumer goods.alter 商品{}详情查询失败",productId);
+            log.info("=======productId:{} goodsAlter end=======", ids);
+        } else {
+            log.error("kafka consumer goods.alter 商品{}详情查询失败", messsage);
         }
         }
 
 
 
 
-
-
-
     }
     }
 
 
 
 
-
 }
 }

+ 9 - 0
src/main/java/zs/payment/service/Imseweishopgoods/ImsEweiShopGoodsService.java

@@ -4,4 +4,13 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import zs.payment.entity.mysql.ImsEweiShopGoods;
 import zs.payment.entity.mysql.ImsEweiShopGoods;
 
 
 public interface ImsEweiShopGoodsService extends IService<ImsEweiShopGoods> {
 public interface ImsEweiShopGoodsService extends IService<ImsEweiShopGoods> {
+
+
+    //根据供应链的商品id查询数据库内是否存在已下架的商品
+    ImsEweiShopGoods getBySupplyId(String supplyId,String supplySource);
+
+    Boolean updateStatusBySupplyId(String supplyId,String supplySource,Integer status);
+
+    Boolean deleteBySupplyId(String supplyId,String supplySource);
+
 }
 }

+ 22 - 0
src/main/java/zs/payment/service/Imseweishopgoods/impl/ImsEweiShopGoodsServiceImpl.java

@@ -1,6 +1,7 @@
 package zs.payment.service.Imseweishopgoods.impl;
 package zs.payment.service.Imseweishopgoods.impl;
 
 
 
 
+
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
@@ -13,5 +14,26 @@ import zs.payment.service.Imseweishopgoods.ImsEweiShopGoodsService;
 public class ImsEweiShopGoodsServiceImpl  extends ServiceImpl<ImsEweiShopGoodsMapper, ImsEweiShopGoods> implements ImsEweiShopGoodsService {
 public class ImsEweiShopGoodsServiceImpl  extends ServiceImpl<ImsEweiShopGoodsMapper, ImsEweiShopGoods> implements ImsEweiShopGoodsService {
 
 
 
 
+    @Override
+    public ImsEweiShopGoods getBySupplyId(String supplyId,String supplySource) {
+
+        return lambdaQuery().eq(ImsEweiShopGoods::getStatus,0)
+            .eq(ImsEweiShopGoods::getSupply_id,supplyId)
+            .eq(ImsEweiShopGoods::getSupply_source,supplySource).one();
+    }
+
+    @Override
+    public Boolean updateStatusBySupplyId(String supplyId, String supplySource, Integer status) {
+
+        return  lambdaUpdate().set(ImsEweiShopGoods::getStatus, status)
+            .eq(ImsEweiShopGoods::getSupply_source, supplySource)
+            .eq(ImsEweiShopGoods::getSupply_id, supplyId).update();
+    }
 
 
+    @Override
+    public Boolean deleteBySupplyId(String supplyId, String supplySource) {
+        return lambdaUpdate().set(ImsEweiShopGoods::getDeleted, 1)
+            .eq(ImsEweiShopGoods::getSupply_source, supplySource)
+            .eq(ImsEweiShopGoods::getSupply_id, supplyId).update();
+    }
 }
 }

+ 6 - 0
src/main/java/zs/payment/service/paysupply/PaySupplyService.java

@@ -30,4 +30,10 @@ public interface PaySupplyService {
     Result afterSalesCreate(AfterSalesOrderReq req);
     Result afterSalesCreate(AfterSalesOrderReq req);
 
 
     Result getMyStorageIdsList(StoragePageReq req);
     Result getMyStorageIdsList(StoragePageReq req);
+
+    /**
+     * 将选品库里的商品,同步到自研系统中
+     * @return
+     */
+    Result syncToQiyun();
 }
 }

+ 92 - 7
src/main/java/zs/payment/service/paysupply/impl/PaySupplyServiceImpl.java

@@ -380,15 +380,100 @@ public class PaySupplyServiceImpl implements PaySupplyService {
         if (respJson.getIntValue("code") != 0) {
         if (respJson.getIntValue("code") != 0) {
             return Result.fail(respJson.getString("msg"));
             return Result.fail(respJson.getString("msg"));
         }
         }
-        //把选品库中的商品同步到企云商城中
+        //把选品库中的商品同步到企云商城中 list:[2932,9600]
         JSONArray array = respJson.getJSONObject("data").getJSONArray("list");
         JSONArray array = respJson.getJSONObject("data").getJSONArray("list");
-        for (int i = 0; i < array.size(); i++) {
-            JSONObject json=new JSONObject();
-            json.put("product_id", array.getInteger(i));
-            kafkaProducer.sendMessage(CallbackMessageType.GOODS_ALTER, json.toJSONString());
-        }
-
+        kafkaProducer.sendMessage(CallbackMessageType.GOODS_SYNC, array.toString());
 
 
         return Result.success(respJson.getJSONObject("data"));
         return Result.success(respJson.getJSONObject("data"));
     }
     }
+
+    @Override
+    public Result syncToQiyun() {
+        Result tokenResult = fetchAndCacheToken();
+        if (!tokenResult.isSuccess()) {
+            log.error("syncToQiyun: 获取token失败");
+            return Result.fail("获取token失败");
+        }
+        String token = (String) tokenResult.getBody().get("token");
+
+        int page = 1;
+        int pageSize = 50;
+        int total = 0;
+        boolean isFirstPage = true;
+
+        try {
+            while (true) {
+                Map<String, Object> params = new HashMap<>();
+                params.put("page", page);
+                params.put("pageSize", pageSize);
+                params.put("create_sort", "desc");
+
+                Map<String, String> headers = new HashMap<>();
+                headers.put("x-token", token);
+
+                String resp = HttpUtil.restTemplatePost(
+                    prefixUrl + "/supplyapi/app/product/storage/getMyStorageIdsList",
+                    params,
+                    headers
+                );
+
+                JSONObject respJson = JSONObject.parseObject(resp);
+                if (respJson.getIntValue("code") != 0) {
+                    log.error("syncToQiyun: 调用选品库列表接口失败,page={},msg={}", page, respJson.getString("msg"));
+                    return Result.fail("调用选品库列表接口失败: " + respJson.getString("msg"));
+                }
+
+                JSONObject data = respJson.getJSONObject("data");
+                JSONArray array = data.getJSONArray("list");
+
+                if (isFirstPage) {
+                    total = data.getIntValue("total");
+                    isFirstPage = false;
+                }
+
+                if (array != null && !array.isEmpty()) {
+                    if (!sendKafkaMessageWithRetry(array.toString())) {
+                        log.error("syncToQiyun: Kafka发送失败,page={},已重试3次", page);
+                        return Result.fail("Kafka发送失败,第" + page + "页数据发送失败");
+                    }
+                    log.info("syncToQiyun: 成功发送第{}页数据,共{}条", page, array.size());
+                }
+
+                int currentPage = data.getIntValue("page");
+                int currentPageSize = data.getIntValue("pageSize");
+                int nextPage = currentPage + 1;
+
+                if (nextPage * currentPageSize > total) {
+                    break;
+                }
+
+                page = nextPage;
+            }
+
+            log.info("syncToQiyun: 所有商品数据同步完成,总计{}条", total);
+            return Result.success(true);
+
+        } catch (Exception e) {
+            log.error("syncToQiyun: 执行异常", e);
+            return Result.fail("执行异常: " + e.getMessage());
+        }
+    }
+
+    private boolean sendKafkaMessageWithRetry(String message) {
+        int maxRetries = 3;
+
+        for (int retryCount = 0; retryCount < maxRetries; retryCount++) {
+            try {
+                kafkaProducer.sendMessage(CallbackMessageType.GOODS_SYNC, message);
+                return true;
+            } catch (Exception e) {
+                log.warn("syncToQiyun: Kafka发送失败,第{}次重试", retryCount + 1);
+                if (retryCount == maxRetries - 1) {
+                    log.error("syncToQiyun: Kafka发送失败,已达到最大重试次数3次,消息内容: {}", message, e);
+                    return false;
+                }
+            }
+        }
+        return false;
+    }
 }
 }

+ 19 - 0
src/main/java/zs/payment/utils/RedisUtils.java

@@ -120,10 +120,29 @@ public class RedisUtils {
         });
         });
     }
     }
 
 
+    /**
+     *
+     * 添加
+     * redis> SADD myset "one"
+     * @param key
+     * @param members
+     * @return
+     */
     public long sadd(String key, String... members) {
     public long sadd(String key, String... members) {
         return Redis.withCluster(ecoCluster, jedis -> jedis.sadd(key, members));
         return Redis.withCluster(ecoCluster, jedis -> jedis.sadd(key, members));
     }
     }
 
 
+    /**
+     * 删除
+     * redis> SREM myset "one"
+     * @param key
+     * @param members
+     * @return
+     */
+    public long srem(String key,String... members){
+        return Redis.withCluster(ecoCluster,jedis -> jedis.srem(key,members));
+    }
+
     public Set<String> smembers(String key) {
     public Set<String> smembers(String key) {
         return  Redis.withCluster(ecoCluster, jedis -> jedis.smembers(key));
         return  Redis.withCluster(ecoCluster, jedis -> jedis.smembers(key));
     }
     }