From 2dba47b01b58d2ab691c7a6e4d0c65f9bb837c8f Mon Sep 17 00:00:00 2001 From: XinWei <2718030729@qq.com> Date: Thu, 29 Aug 2024 09:07:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E7=A5=A8=E5=8A=A1=E9=9B=86=E5=90=88?= =?UTF-8?q?=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dal/dataobject/checkticket/CheckTicketToday.java | 2 +- .../checkticket/CheckTicketTodayRepository.java | 12 +++++++++++- .../mongodb/saledata/SaleDataTodayRepository.java | 9 ++++++++- .../service/checkticket/CheckTicketServiceImpl.java | 5 ++++- .../infra/service/saledata/SaleDataServiceImpl.java | 9 ++++++--- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/checkticket/CheckTicketToday.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/checkticket/CheckTicketToday.java index f829ef142..cc21a87b6 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/checkticket/CheckTicketToday.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/checkticket/CheckTicketToday.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.infra.dal.dataobject.checkticket; import lombok.Data; import org.springframework.data.mongodb.core.mapping.Document; -@Document("checkticket") +@Document("check_ticket_today") //@Document("checktickettest") @Data public class CheckTicketToday { diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mongodb/checkticket/CheckTicketTodayRepository.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mongodb/checkticket/CheckTicketTodayRepository.java index 387af83b2..62b8d6d70 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mongodb/checkticket/CheckTicketTodayRepository.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mongodb/checkticket/CheckTicketTodayRepository.java @@ -1,12 +1,22 @@ package cn.iocoder.yudao.module.infra.dal.mongodb.checkticket; +import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicket; import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicketToday; import org.springframework.data.mongodb.repository.MongoRepository; +import org.springframework.data.mongodb.repository.Query; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface CheckTicketTodayRepository extends MongoRepository { - + /** + * 根据dataId数组查找 + * @param dataIdList + * @return java.util.List + */ + @Query(value = "{ 'dataId': { $in: ?0 } }", fields = "{ 'dataId': 1, '_id': 0 }") + List findByDataIdIn(List dataIdList); } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mongodb/saledata/SaleDataTodayRepository.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mongodb/saledata/SaleDataTodayRepository.java index e9515a7a8..a46d82954 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mongodb/saledata/SaleDataTodayRepository.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mongodb/saledata/SaleDataTodayRepository.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.infra.dal.mongodb.saledata; +import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicket; import cn.iocoder.yudao.module.infra.dal.dataobject.saledata.SaleData; import cn.iocoder.yudao.module.infra.dal.dataobject.saledata.SaleDataToday; import org.springframework.data.mongodb.repository.Aggregation; @@ -61,5 +62,11 @@ public interface SaleDataTodayRepository extends MongoRepository findAllByTransactiontypenoTime(String starTime, String endTime); - + /** + * 更具dataId查找售票记录 + * @param dataIdList + * @return java.util.List + */ + @Query(value = "{ 'dataId': { $in: ?0 } }", fields = "{ 'dataId': 1, '_id': 0 }") + List findByDataIdIn(List dataIdList); } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/checkticket/CheckTicketServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/checkticket/CheckTicketServiceImpl.java index 25717b942..bea649292 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/checkticket/CheckTicketServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/checkticket/CheckTicketServiceImpl.java @@ -85,7 +85,10 @@ public class CheckTicketServiceImpl implements CheckTicketService { // 把检票数据的dataId提取出来成数组 List dataIdList = checkTicketList.stream().map(CheckTicketToday::getDataId).collect(Collectors.toList()); // 获取重复的dataId - List duplicatesDataId = this.checkDuplicatesByMongoDB(dataIdList); + // 查询数据库中存在的 dataId + List existingTickets = checkTicketTodayRepository.findByDataIdIn(dataIdList); + // 把CheckTicket对象列表改为dataId字符串列表 + List duplicatesDataId = existingTickets.stream().map(CheckTicket::getDataId).collect(Collectors.toList()); // 对checkTicketList过滤掉重复的dataId对应的数据,得到需要插入的不重复数据 List insertCheckTicketList = checkTicketList.stream().filter(ticket -> !duplicatesDataId.contains(ticket.getDataId())).collect(Collectors.toList()); try { diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/saledata/SaleDataServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/saledata/SaleDataServiceImpl.java index 6e0c0dfaf..45e81208b 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/saledata/SaleDataServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/saledata/SaleDataServiceImpl.java @@ -62,7 +62,7 @@ public class SaleDataServiceImpl implements SaleDataService { try { // 批量插入 saleDataRepository.insert(insertSaleDataList); - } catch (MongoException e){ + } catch (MongoException e) { return null; } resultNum.add(insertSaleDataList.size()); @@ -76,13 +76,16 @@ public class SaleDataServiceImpl implements SaleDataService { // 把检票数据的dataId提取出来成数组 List dataIdList = saleDataList.stream().map(SaleDataToday::getDataId).collect(Collectors.toList()); // 获取重复的dataId - List duplicatesDataId = this.checkDuplicatesByMongoDB(dataIdList); + // 查询数据库中存在的 dataId + List existingTickets = saleDataRepository.findByDataIdIn(dataIdList); + // 把CheckTicket对象列表改为dataId字符串列表 + List duplicatesDataId = existingTickets.stream().map(CheckTicket::getDataId).collect(Collectors.toList()); // 对checkTicketList过滤掉重复的dataId对应的数据,得到需要插入的不重复数据 List insertSaleDataList = saleDataList.stream().filter(saleData -> !duplicatesDataId.contains(saleData.getDataId())).collect(Collectors.toList()); try { // 批量插入 saleDataTodayRepository.insert(insertSaleDataList); - } catch (MongoException e){ + } catch (MongoException e) { return null; } resultNum.add(insertSaleDataList.size());