同步下单时间给思迅流水

This commit is contained in:
liyj 2025-11-19 10:59:08 +08:00
parent da449a5921
commit 4259a7e454
5 changed files with 47 additions and 10 deletions

View File

@ -57,4 +57,8 @@ public class ProductQuantityConsumption {
@ApiModelProperty(value = "更新时间") @ApiModelProperty(value = "更新时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime; private Date updateTime;
@TableField(value = "sale_time",updateStrategy = FieldStrategy.NOT_EMPTY)
@ApiModelProperty(value = "下单时间")
private Long saleTime;
} }

View File

@ -1580,7 +1580,13 @@ public class ShopOrderReturnServiceImpl extends BaseServiceImpl<ShopOrderReturnM
QueryWrapper<ShopOrderReturnItem> returnItemQueryWrapper = new QueryWrapper<>(); QueryWrapper<ShopOrderReturnItem> returnItemQueryWrapper = new QueryWrapper<>();
returnItemQueryWrapper.in("return_id", return_ids); returnItemQueryWrapper.in("return_id", return_ids);
List<ShopOrderReturnItem> returnItems = orderReturnItemService.find(returnItemQueryWrapper); List<ShopOrderReturnItem> returnItems = orderReturnItemService.find(returnItemQueryWrapper);
QueryWrapper<ShopOrderReturn> shopOrderReturnQueryWrapper= new QueryWrapper<>();
shopOrderReturnQueryWrapper.in("return_id", return_ids);
List<ShopOrderReturn> shopOrderReturnList= shopOrderReturnService.find(shopOrderReturnQueryWrapper);
Map<String,Long> shopOrderReturnMap=new HashMap<>();
if(!shopOrderReturnList.isEmpty()){
shopOrderReturnMap=shopOrderReturnList.stream().collect(Collectors.toMap(ShopOrderReturn::getReturn_id, s->s.getUpdated_at().getTime()));
}
if (CollUtil.isNotEmpty(returnItems)) { if (CollUtil.isNotEmpty(returnItems)) {
for (ShopOrderReturnItem returnItem : returnItems) { for (ShopOrderReturnItem returnItem : returnItems) {
String order_id = returnItem.getOrder_id(); String order_id = returnItem.getOrder_id();
@ -1631,9 +1637,13 @@ public class ShopOrderReturnServiceImpl extends BaseServiceImpl<ShopOrderReturnM
// RMK 第三方数据同步相关redis 新增返还思迅库存 // RMK 第三方数据同步相关redis 新增返还思迅库存
Map<String, Integer> stockDeltaMap = new HashMap<>(); Map<String, Integer> stockDeltaMap = new HashMap<>();
String item_src_id = productItem.getItem_src_id(); String item_src_id = productItem.getItem_src_id();
stockDeltaMap.put(item_src_id + "-" + shopOrderItem.getOrder_id() + "-" + shopOrderItem.getItem_unit_price(), returnNum); String mapKey=item_src_id + "-" + shopOrderItem.getOrder_id() + "-" + shopOrderItem.getItem_unit_price();
if(null!=shopOrderReturnMap.get(returnItem.getReturn_id())){
mapKey=mapKey+"-" + shopOrderReturnMap.get(returnItem.getReturn_id());
}
stockDeltaMap.put(mapKey, returnNum);
syncThirdDataService.incrProductStockToRedis(stockDeltaMap, returnItem.getReturn_item_subtotal()); syncThirdDataService.incrProductStockToRedis(stockDeltaMap, returnItem.getReturn_item_subtotal());
logger.info("退货返回给思迅,存入redis成功,item_src_id:{},订单号:{},数量:{}", item_src_id, shopOrderReturn.getOrder_id(), returnNum); logger.info("退货返回给思迅,存入redis成功,item_src_id:{},订单号:{},数量:{},mapKey:{}", item_src_id, shopOrderReturn.getOrder_id(), returnNum,mapKey);
} else { } else {
logger.warn("退货数量为空无法增加库存订单项ID: {}", orderItemId); logger.warn("退货数量为空无法增加库存订单项ID: {}", orderItemId);
} }

View File

@ -1170,6 +1170,11 @@ public class SFExpressApiServiceImpl implements SFExpressApiService {
String order_id = shopStoreSfOrder.getShop_order_id(); String order_id = shopStoreSfOrder.getShop_order_id();
itemQueryWrapper.eq("order_id", order_id); itemQueryWrapper.eq("order_id", order_id);
List<ShopOrderItem> order_item_rows = shopOrderItemService.find(itemQueryWrapper); List<ShopOrderItem> order_item_rows = shopOrderItemService.find(itemQueryWrapper);
ShopOrderBase shopOrderBase=shopOrderBaseService.get(order_id);
String saleTimeStr=null;
if(null!=shopOrderBase){
saleTimeStr= String.valueOf(shopOrderBase.getOrder_time().getTime());
}
if (picking(order_item_rows)) { if (picking(order_item_rows)) {
logger.info("顺丰发货商品扣减库存成功"); logger.info("顺丰发货商品扣减库存成功");
} }
@ -1178,7 +1183,11 @@ public class SFExpressApiServiceImpl implements SFExpressApiService {
Map<String, Integer> stockDeltaMap = new HashMap<>(); Map<String, Integer> stockDeltaMap = new HashMap<>();
String item_src_id = shopOrderItem.getItem_src_id(); String item_src_id = shopOrderItem.getItem_src_id();
Integer order_item_quantity = shopOrderItem.getOrder_item_quantity(); Integer order_item_quantity = shopOrderItem.getOrder_item_quantity();
stockDeltaMap.put(item_src_id + "-" + shopStoreSfOrder.getShop_order_id()+"-"+shopOrderItem.getItem_unit_price(), -order_item_quantity); String mapKey=item_src_id + "-" + shopStoreSfOrder.getShop_order_id()+"-"+shopOrderItem.getItem_unit_price();
if(StringUtils.isNotEmpty(saleTimeStr)){
mapKey=mapKey+"-"+saleTimeStr;
}
stockDeltaMap.put(mapKey, -order_item_quantity);
syncThirdDataService.incrProductStockToRedis(stockDeltaMap,null); syncThirdDataService.incrProductStockToRedis(stockDeltaMap,null);
} }
} }
@ -1347,7 +1356,8 @@ public class SFExpressApiServiceImpl implements SFExpressApiService {
Map<String, Integer> stockDeltaMap = new HashMap<>(); Map<String, Integer> stockDeltaMap = new HashMap<>();
String item_src_id = shopOrderItem.getItem_src_id(); String item_src_id = shopOrderItem.getItem_src_id();
Integer order_item_quantity = shopOrderItem.getOrder_item_quantity(); Integer order_item_quantity = shopOrderItem.getOrder_item_quantity();
stockDeltaMap.put(item_src_id + "-" + shopOrderItem.getOrder_id()+"-"+shopOrderItem.getItem_unit_price(), -order_item_quantity); String mapKey=item_src_id + "-" + shopOrderItem.getOrder_id()+"-"+shopOrderItem.getItem_unit_price()+"-"+shopOrderBase.getOrder_time().getTime();
stockDeltaMap.put(mapKey, -order_item_quantity);
syncThirdDataService.incrProductStockToRedis(stockDeltaMap,null); syncThirdDataService.incrProductStockToRedis(stockDeltaMap,null);
} }
} }

View File

@ -989,13 +989,16 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
ProductQuantityConsumption productQuantityConsumption=new ProductQuantityConsumption(); ProductQuantityConsumption productQuantityConsumption=new ProductQuantityConsumption();
String productKey= (String) k; String productKey= (String) k;
String[] productKeyArrys=productKey.split("-"); String[] productKeyArrys=productKey.split("-");
if(productKeyArrys.length!=4){ if(productKeyArrys.length<4){
return; return;
} }
String productNumber=productKeyArrys[0]; String productNumber=productKeyArrys[0];
String orderId=productKeyArrys[1]; String orderId=productKeyArrys[1];
String unitPrice=productKeyArrys[2]; String unitPrice=productKeyArrys[2];
String saleAmount=productKeyArrys[3]; String saleAmount=productKeyArrys[3];
if(productKeyArrys.length==5){
productQuantityConsumption.setSaleTime(Long.parseLong(productKeyArrys[4]));
}
productQuantityConsumption.setConsumeId(IdUtil.getSnowflakeNextIdStr()); productQuantityConsumption.setConsumeId(IdUtil.getSnowflakeNextIdStr());
productQuantityConsumption.setOrderId(orderId); productQuantityConsumption.setOrderId(orderId);
productQuantityConsumption.setProductNumber(productNumber); productQuantityConsumption.setProductNumber(productNumber);
@ -1027,7 +1030,7 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
continue; continue;
} }
String[] productKeyArrys=productKey.split("-"); String[] productKeyArrys=productKey.split("-");
if(productKeyArrys.length!=3){ if(productKeyArrys.length<3){
continue; continue;
} }
try { try {
@ -1063,12 +1066,17 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
cn.hutool.json.JSONArray array_item_spec = JSONUtil.parseArray(spuItem.getItem_spec()); cn.hutool.json.JSONArray array_item_spec = JSONUtil.parseArray(spuItem.getItem_spec());
logger.info("array_item_spec:{}",array_item_spec); logger.info("array_item_spec:{}",array_item_spec);
logger.info("key:{},Product_number:{}",key,itemId); logger.info("key:{},Product_number:{}",key,itemId);
String mapKey="";
if(array_item_spec.isEmpty()){ if(array_item_spec.isEmpty()){
BigDecimal saleAmount=new BigDecimal(unitPrice).multiply(new BigDecimal(delta)); BigDecimal saleAmount=new BigDecimal(unitPrice).multiply(new BigDecimal(delta));
if(saleAmount.compareTo(BigDecimal.ZERO)<0){ if(saleAmount.compareTo(BigDecimal.ZERO)<0){
saleAmount=saleAmount.multiply(new BigDecimal("-1")); saleAmount=saleAmount.multiply(new BigDecimal("-1"));
} }
redisTemplate.opsForHash().increment(key, itemId+"-"+orderId+"-"+unitPrice+"-"+saleAmount.toPlainString(), delta.doubleValue()); mapKey=itemId+"-"+orderId+"-"+unitPrice+"-"+saleAmount.toPlainString();
if(productKeyArrys.length==4){
mapKey=mapKey+"-"+productKeyArrys[3];
}
redisTemplate.opsForHash().increment(key,mapKey, delta.doubleValue());
logger.info("存储无规格库存成功"); logger.info("存储无规格库存成功");
continue; continue;
} }
@ -1089,8 +1097,12 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
itemReturnAmount=itemReturnAmount.multiply(new BigDecimal("-1")); itemReturnAmount=itemReturnAmount.multiply(new BigDecimal("-1"));
} }
// 使用 Redis HINCRBY 保证原子性和高性能 // 使用 Redis HINCRBY 保证原子性和高性能
redisTemplate.opsForHash().increment(key, itemId+"-"+orderId+"-"+unitPriceBg.toPlainString()+"-"+itemReturnAmount.toPlainString(), itemQuaryty.doubleValue()); mapKey=itemId+"-"+orderId+"-"+unitPriceBg.toPlainString()+"-"+itemReturnAmount.toPlainString();
logger.info("存储有规格库存成功",itemId+"-"+orderId+"-"+unitPriceBg.toPlainString()); if(productKeyArrys.length==4){
mapKey=mapKey+"-"+productKeyArrys[3];
}
redisTemplate.opsForHash().increment(key, mapKey, itemQuaryty.doubleValue());
logger.info("存储有规格库存成功mapKey:{},",mapKey);
} catch (Exception e) { } catch (Exception e) {
logger.error("库存累计失败productKey={}, delta={}, error={}", productKey, delta, e.getMessage(), e); logger.error("库存累计失败productKey={}, delta={}, error={}", productKey, delta, e.getMessage(), e);
} }

View File

@ -0,0 +1 @@
ALTER table product_quantity_consumption add sale_time bigint unsigned DEFAULT NULL COMMENT '下单时间';