新票务集合补充

This commit is contained in:
XinWei 2024-08-29 09:07:54 +08:00
parent b209a002fb
commit 2dba47b01b
5 changed files with 30 additions and 7 deletions

View File

@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.infra.dal.dataobject.checkticket;
import lombok.Data; import lombok.Data;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
@Document("checkticket") @Document("check_ticket_today")
//@Document("checktickettest") //@Document("checktickettest")
@Data @Data
public class CheckTicketToday { public class CheckTicketToday {

View File

@ -1,12 +1,22 @@
package cn.iocoder.yudao.module.infra.dal.mongodb.checkticket; 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 cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicketToday;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
@Repository @Repository
public interface CheckTicketTodayRepository extends MongoRepository<CheckTicketToday,String> { public interface CheckTicketTodayRepository extends MongoRepository<CheckTicketToday,String> {
/**
* 根据dataId数组查找
* @param dataIdList
* @return java.util.List<cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicket>
*/
@Query(value = "{ 'dataId': { $in: ?0 } }", fields = "{ 'dataId': 1, '_id': 0 }")
List<CheckTicket> findByDataIdIn(List<String> dataIdList);
} }

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.infra.dal.mongodb.saledata; 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.SaleData;
import cn.iocoder.yudao.module.infra.dal.dataobject.saledata.SaleDataToday; import cn.iocoder.yudao.module.infra.dal.dataobject.saledata.SaleDataToday;
import org.springframework.data.mongodb.repository.Aggregation; import org.springframework.data.mongodb.repository.Aggregation;
@ -61,5 +62,11 @@ public interface SaleDataTodayRepository extends MongoRepository<SaleDataToday,S
// //
// @Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'transactiontypeno': 1 }") // @Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'transactiontypeno': 1 }")
// List<SaleData> findAllByTransactiontypenoTime(String starTime, String endTime); // List<SaleData> findAllByTransactiontypenoTime(String starTime, String endTime);
/**
* 更具dataId查找售票记录
* @param dataIdList
* @return java.util.List<cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicket>
*/
@Query(value = "{ 'dataId': { $in: ?0 } }", fields = "{ 'dataId': 1, '_id': 0 }")
List<CheckTicket> findByDataIdIn(List<String> dataIdList);
} }

View File

@ -85,7 +85,10 @@ public class CheckTicketServiceImpl implements CheckTicketService {
// 把检票数据的dataId提取出来成数组 // 把检票数据的dataId提取出来成数组
List<String> dataIdList = checkTicketList.stream().map(CheckTicketToday::getDataId).collect(Collectors.toList()); List<String> dataIdList = checkTicketList.stream().map(CheckTicketToday::getDataId).collect(Collectors.toList());
// 获取重复的dataId // 获取重复的dataId
List<String> duplicatesDataId = this.checkDuplicatesByMongoDB(dataIdList); // 查询数据库中存在的 dataId
List<CheckTicket> existingTickets = checkTicketTodayRepository.findByDataIdIn(dataIdList);
// 把CheckTicket对象列表改为dataId字符串列表
List<String> duplicatesDataId = existingTickets.stream().map(CheckTicket::getDataId).collect(Collectors.toList());
// 对checkTicketList过滤掉重复的dataId对应的数据得到需要插入的不重复数据 // 对checkTicketList过滤掉重复的dataId对应的数据得到需要插入的不重复数据
List<CheckTicketToday> insertCheckTicketList = checkTicketList.stream().filter(ticket -> !duplicatesDataId.contains(ticket.getDataId())).collect(Collectors.toList()); List<CheckTicketToday> insertCheckTicketList = checkTicketList.stream().filter(ticket -> !duplicatesDataId.contains(ticket.getDataId())).collect(Collectors.toList());
try { try {

View File

@ -62,7 +62,7 @@ public class SaleDataServiceImpl implements SaleDataService {
try { try {
// 批量插入 // 批量插入
saleDataRepository.insert(insertSaleDataList); saleDataRepository.insert(insertSaleDataList);
} catch (MongoException e){ } catch (MongoException e) {
return null; return null;
} }
resultNum.add(insertSaleDataList.size()); resultNum.add(insertSaleDataList.size());
@ -76,13 +76,16 @@ public class SaleDataServiceImpl implements SaleDataService {
// 把检票数据的dataId提取出来成数组 // 把检票数据的dataId提取出来成数组
List<String> dataIdList = saleDataList.stream().map(SaleDataToday::getDataId).collect(Collectors.toList()); List<String> dataIdList = saleDataList.stream().map(SaleDataToday::getDataId).collect(Collectors.toList());
// 获取重复的dataId // 获取重复的dataId
List<String> duplicatesDataId = this.checkDuplicatesByMongoDB(dataIdList); // 查询数据库中存在的 dataId
List<CheckTicket> existingTickets = saleDataRepository.findByDataIdIn(dataIdList);
// 把CheckTicket对象列表改为dataId字符串列表
List<String> duplicatesDataId = existingTickets.stream().map(CheckTicket::getDataId).collect(Collectors.toList());
// 对checkTicketList过滤掉重复的dataId对应的数据得到需要插入的不重复数据 // 对checkTicketList过滤掉重复的dataId对应的数据得到需要插入的不重复数据
List<SaleDataToday> insertSaleDataList = saleDataList.stream().filter(saleData -> !duplicatesDataId.contains(saleData.getDataId())).collect(Collectors.toList()); List<SaleDataToday> insertSaleDataList = saleDataList.stream().filter(saleData -> !duplicatesDataId.contains(saleData.getDataId())).collect(Collectors.toList());
try { try {
// 批量插入 // 批量插入
saleDataTodayRepository.insert(insertSaleDataList); saleDataTodayRepository.insert(insertSaleDataList);
} catch (MongoException e){ } catch (MongoException e) {
return null; return null;
} }
resultNum.add(insertSaleDataList.size()); resultNum.add(insertSaleDataList.size());