@ -162,6 +162,9 @@ public class BusinessPreOrderDataQueueHandler {
// 更新删除状态
distributionBusinessPreOrderService . deleteLogic ( temsp ) ;
}
for ( DistributionBusinessPreOrderEntity distributionBusinessPreOrderEntity : dataResult ) {
distributionBusinessPreOrderEntity . setTenantId ( tenant . getTenantId ( ) ) ;
}
// 执行保存操作
distributionBusinessPreOrderService . saveBatch ( dataResult ) ;
@ -172,71 +175,71 @@ 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 ( ) ;
if ( ObjectUtil . isEmpty ( tenant ) ) {
log . info ( ">>>>>>>>>>>>> BusinessPreOrderDataQueueHandler 租户不存在" ) ;
return ;
}
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 ) ) ) {
//存在需要进行删除的数据
List < DistributionBusinessPreOrderEntity > deleteList = map . get ( 0 ) ;
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 ( 0 ) ) ) {
//存在可能变更的数据
List < DistributionBusinessPreOrderEntity > mapList = map . get ( 0 ) ;
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 ( ) ;
}
}
// public void saveOtherDataBase(List<DistributionBusinessPreOrderEntity> dataResult, String maillName) {
// String method = "########################saveOtherDataBase";
// R<Tenant> tenantByName = sysClient.getTenantByName(maillName);
// if (tenantByName.isSuccess()) {
// Tenant tenant = tenantByName.getData();
// if (ObjectUtil.isEmpty(tenant)) {
// log.info( ">>>>>>>>>>>>> BusinessPreOrderDataQueueHandler 租户不存在");
// return;
// }
// 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))) {
// //存在需要进行删除的数据
// List<DistributionBusinessPreOrderEntity> deleteList = map.get(0);
// 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(0))) {
// //存在可能变更的数据
// List<DistributionBusinessPreOrderEntity> mapList = map.get(0);
// 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();
//
// }
//
//
// }
}