Browse Source

商家端数据保存和删除

master
汤建军 11 months ago
parent
commit
49992551c9
  1. 38
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/BusinessPreOrderDataQueueHandler.java

38
blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/BusinessPreOrderDataQueueHandler.java

@ -2,6 +2,7 @@ package com.logpm.distribution.receiver;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.logpm.business.entity.DistributionBusinessPreOrderEntity;
import com.logpm.distribution.entity.DistributionDeliveryListEntity;
import com.logpm.distribution.entity.DistributionParcelListEntity;
@ -128,6 +129,7 @@ public class BusinessPreOrderDataQueueHandler {
if (dataResult.isEmpty()) {
log.info(method+"dataResult 参数错误");
}
DynamicDataSourceContextHolder.push(tenant.getTenantId());
Map<Integer, List<DistributionBusinessPreOrderEntity>> map = dataResult.stream().collect(Collectors.groupingBy(DistributionBusinessPreOrderEntity::getInWarehouse));
if (Func.isNotEmpty(map.get(1))){
//存在需要进行删除的数据
@ -148,19 +150,33 @@ public class BusinessPreOrderDataQueueHandler {
if (Func.isNotEmpty(map.get(2))){
//存在可能变更的数据
List<DistributionBusinessPreOrderEntity> mapList = map.get(2);
for (DistributionBusinessPreOrderEntity distributionBusinessPreOrderEntity : mapList) {
distributionBusinessPreOrderEntity.setTenantId(tenant.getTenantId());
Map<String, List<DistributionBusinessPreOrderEntity>> saveData = mapList.stream().collect(Collectors.groupingBy(DistributionBusinessPreOrderEntity::getReservationCode));
List<DistributionBusinessPreOrderEntity> existData= new ArrayList<>();
if (!saveData.isEmpty()) {
//查询是否存在重复
saveData.forEach((k,v)->{
List<DistributionBusinessPreOrderEntity> list = distributionBusinessPreOrderService.list(Wrappers.<DistributionBusinessPreOrderEntity>query().lambda()
.eq(DistributionBusinessPreOrderEntity::getReservationCode, k)
.in(DistributionBusinessPreOrderEntity::getOrderPackageCode, v.stream().map(DistributionBusinessPreOrderEntity::getOrderPackageCode).collect(Collectors.toList()))
);
if (!list.isEmpty()) {
//已经存在数据
existData.addAll(list);
}
});
}
if (!existData.isEmpty()){
//二者比较取差集
mapList = mapList.stream().filter(m -> !existData.stream().map(DistributionBusinessPreOrderEntity::getOrderPackageCode).collect(Collectors.toList()).contains(m.getOrderPackageCode())).collect(Collectors.toList());
}
if (!mapList.isEmpty()){
for (DistributionBusinessPreOrderEntity distributionBusinessPreOrderEntity : mapList) {
distributionBusinessPreOrderEntity.setTenantId(tenant.getTenantId());
}
distributionBusinessPreOrderService.saveBatch(mapList);
}
DynamicDataSourceContextHolder.push(tenant.getTenantId());
distributionBusinessPreOrderService.saveBatch(mapList);
DynamicDataSourceContextHolder.poll();
}
// for (DistributionBusinessPreOrderEntity distributionBusinessPreOrderEntity : dataResult) {
// distributionBusinessPreOrderEntity.setTenantId(tenant.getTenantId());
// }
// DynamicDataSourceContextHolder.push(tenant.getTenantId());
DynamicDataSourceContextHolder.poll();
}

Loading…
Cancel
Save