|
|
|
@ -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; |
|
|
|
@ -14,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springblade.common.constant.RabbitConstant; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.core.tool.utils.BeanUtil; |
|
|
|
|
import org.springblade.core.tool.utils.Func; |
|
|
|
|
import org.springblade.core.tool.utils.ObjectUtil; |
|
|
|
|
import org.springblade.system.entity.Tenant; |
|
|
|
|
import org.springblade.system.feign.ISysClient; |
|
|
|
@ -25,6 +27,8 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.function.Function; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
|
|
@RabbitListener(queues = RabbitConstant.BUSINESS_PRE_CONVERSION_DATA_QUEUE) |
|
|
|
@ -114,7 +118,7 @@ public class BusinessPreOrderDataQueueHandler {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void saveOtherDataBase(List<DistributionBusinessPreOrderEntity> dataResult, String maillName) { |
|
|
|
|
|
|
|
|
|
String method = "########################saveOtherDataBase"; |
|
|
|
|
R<Tenant> tenantByName = sysClient.getTenantByName(maillName); |
|
|
|
|
if(tenantByName.isSuccess()){ |
|
|
|
|
Tenant tenant = tenantByName.getData(); |
|
|
|
@ -122,19 +126,58 @@ public class BusinessPreOrderDataQueueHandler {
|
|
|
|
|
log.info(">>>>>>>>>>>>> BusinessPreOrderDataQueueHandler 租户不存在"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (DistributionBusinessPreOrderEntity distributionBusinessPreOrderEntity : dataResult) { |
|
|
|
|
distributionBusinessPreOrderEntity.setTenantId(tenant.getTenantId()); |
|
|
|
|
if (dataResult.isEmpty()) { |
|
|
|
|
log.info(method+"dataResult 参数错误"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DynamicDataSourceContextHolder.push(tenant.getTenantId()); |
|
|
|
|
|
|
|
|
|
List<DistributionBusinessPreOrderEntity> list = distributionBusinessPreOrderService.list(); |
|
|
|
|
|
|
|
|
|
distributionBusinessPreOrderService.saveBatch(dataResult); |
|
|
|
|
Map<Integer, List<DistributionBusinessPreOrderEntity>> map = dataResult.stream().collect(Collectors.groupingBy(DistributionBusinessPreOrderEntity::getInWarehouse)); |
|
|
|
|
if (Func.isNotEmpty(map.get(1))){ |
|
|
|
|
//存在需要进行删除的数据
|
|
|
|
|
List<DistributionBusinessPreOrderEntity> deleteList = map.get(1); |
|
|
|
|
if (!deleteList.isEmpty()) { |
|
|
|
|
Map<String, List<DistributionBusinessPreOrderEntity>> deletedMap = deleteList.stream().collect(Collectors.groupingBy(DistributionBusinessPreOrderEntity::getReservationCode)); |
|
|
|
|
deletedMap.forEach((k,v)->{ |
|
|
|
|
List<String> deletedPackageList = v.stream().map(DistributionBusinessPreOrderEntity::getOrderPackageCode).collect(Collectors.toList()); |
|
|
|
|
log.info("删除商家端数据>>>>reservationCode:{}",deletedPackageList); |
|
|
|
|
if (!deletedPackageList.isEmpty()){ |
|
|
|
|
//进行删除
|
|
|
|
|
Integer row = distributionBusinessPreOrderService.deleteBusinessPreOrder(k,deletedPackageList); |
|
|
|
|
log.info("删除商家端数据>>>>row:{}",row); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (Func.isNotEmpty(map.get(2))){ |
|
|
|
|
//存在可能变更的数据
|
|
|
|
|
List<DistributionBusinessPreOrderEntity> mapList = map.get(2); |
|
|
|
|
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.poll(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|