|
@@ -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);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|