同步下单时间给思迅流水
This commit is contained in:
parent
a6fb1c21b4
commit
eaa44aab1a
@ -57,4 +57,8 @@ public class ProductQuantityConsumption {
|
||||
@ApiModelProperty(value = "更新时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date updateTime;
|
||||
|
||||
@TableField(value = "sale_time",updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||
@ApiModelProperty(value = "下单时间")
|
||||
private Long saleTime;
|
||||
}
|
||||
|
||||
@ -1580,7 +1580,13 @@ public class ShopOrderReturnServiceImpl extends BaseServiceImpl<ShopOrderReturnM
|
||||
QueryWrapper<ShopOrderReturnItem> returnItemQueryWrapper = new QueryWrapper<>();
|
||||
returnItemQueryWrapper.in("return_id", return_ids);
|
||||
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)) {
|
||||
for (ShopOrderReturnItem returnItem : returnItems) {
|
||||
String order_id = returnItem.getOrder_id();
|
||||
@ -1631,9 +1637,13 @@ public class ShopOrderReturnServiceImpl extends BaseServiceImpl<ShopOrderReturnM
|
||||
// RMK 第三方数据同步相关:redis 新增返还思迅库存
|
||||
Map<String, Integer> stockDeltaMap = new HashMap<>();
|
||||
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());
|
||||
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 {
|
||||
logger.warn("退货数量为空,无法增加库存,订单项ID: {}", orderItemId);
|
||||
}
|
||||
|
||||
@ -1170,6 +1170,11 @@ public class SFExpressApiServiceImpl implements SFExpressApiService {
|
||||
String order_id = shopStoreSfOrder.getShop_order_id();
|
||||
itemQueryWrapper.eq("order_id", order_id);
|
||||
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)) {
|
||||
logger.info("顺丰发货商品扣减库存成功");
|
||||
}
|
||||
@ -1178,7 +1183,11 @@ public class SFExpressApiServiceImpl implements SFExpressApiService {
|
||||
Map<String, Integer> stockDeltaMap = new HashMap<>();
|
||||
String item_src_id = shopOrderItem.getItem_src_id();
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -1347,7 +1356,8 @@ public class SFExpressApiServiceImpl implements SFExpressApiService {
|
||||
Map<String, Integer> stockDeltaMap = new HashMap<>();
|
||||
String item_src_id = shopOrderItem.getItem_src_id();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -989,13 +989,16 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
||||
ProductQuantityConsumption productQuantityConsumption=new ProductQuantityConsumption();
|
||||
String productKey= (String) k;
|
||||
String[] productKeyArrys=productKey.split("-");
|
||||
if(productKeyArrys.length!=4){
|
||||
if(productKeyArrys.length<4){
|
||||
return;
|
||||
}
|
||||
String productNumber=productKeyArrys[0];
|
||||
String orderId=productKeyArrys[1];
|
||||
String unitPrice=productKeyArrys[2];
|
||||
String saleAmount=productKeyArrys[3];
|
||||
if(productKeyArrys.length==5){
|
||||
productQuantityConsumption.setSaleTime(Long.parseLong(productKeyArrys[4]));
|
||||
}
|
||||
productQuantityConsumption.setConsumeId(IdUtil.getSnowflakeNextIdStr());
|
||||
productQuantityConsumption.setOrderId(orderId);
|
||||
productQuantityConsumption.setProductNumber(productNumber);
|
||||
@ -1027,7 +1030,7 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
||||
continue;
|
||||
}
|
||||
String[] productKeyArrys=productKey.split("-");
|
||||
if(productKeyArrys.length!=3){
|
||||
if(productKeyArrys.length<3){
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
@ -1063,12 +1066,17 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
||||
cn.hutool.json.JSONArray array_item_spec = JSONUtil.parseArray(spuItem.getItem_spec());
|
||||
logger.info("array_item_spec:{}",array_item_spec);
|
||||
logger.info("key:{},Product_number:{}",key,itemId);
|
||||
String mapKey="";
|
||||
if(array_item_spec.isEmpty()){
|
||||
BigDecimal saleAmount=new BigDecimal(unitPrice).multiply(new BigDecimal(delta));
|
||||
if(saleAmount.compareTo(BigDecimal.ZERO)<0){
|
||||
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("存储无规格库存成功");
|
||||
continue;
|
||||
}
|
||||
@ -1089,8 +1097,12 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
||||
itemReturnAmount=itemReturnAmount.multiply(new BigDecimal("-1"));
|
||||
}
|
||||
// 使用 Redis 的 HINCRBY 保证原子性和高性能
|
||||
redisTemplate.opsForHash().increment(key, itemId+"-"+orderId+"-"+unitPriceBg.toPlainString()+"-"+itemReturnAmount.toPlainString(), itemQuaryty.doubleValue());
|
||||
logger.info("存储有规格库存成功",itemId+"-"+orderId+"-"+unitPriceBg.toPlainString());
|
||||
mapKey=itemId+"-"+orderId+"-"+unitPriceBg.toPlainString()+"-"+itemReturnAmount.toPlainString();
|
||||
if(productKeyArrys.length==4){
|
||||
mapKey=mapKey+"-"+productKeyArrys[3];
|
||||
}
|
||||
redisTemplate.opsForHash().increment(key, mapKey, itemQuaryty.doubleValue());
|
||||
logger.info("存储有规格库存成功mapKey:{},",mapKey);
|
||||
} catch (Exception e) {
|
||||
logger.error("库存累计失败,productKey={}, delta={}, error={}", productKey, delta, e.getMessage(), e);
|
||||
}
|
||||
|
||||
1
sql/shop/dev/20251119_dml.sql
Normal file
1
sql/shop/dev/20251119_dml.sql
Normal file
@ -0,0 +1 @@
|
||||
ALTER table product_quantity_consumption add sale_time bigint unsigned DEFAULT NULL COMMENT '下单时间';
|
||||
Loading…
Reference in New Issue
Block a user