From 3be191f8e992e02bb86953b8fc36a6444bffec47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=85=95=E4=B8=8B?= <484014559@qq.com> Date: Wed, 28 Aug 2024 17:29:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A5=A8=E5=8A=A1=E6=8A=BD=E6=95=B0=E6=94=B9?= =?UTF-8?q?=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../checkticket/CheckTicketToday.java | 21 ++++++ .../dataobject/saledata/SaleDataToday.java | 27 ++++++++ .../CheckTicketTodayRepository.java | 28 ++++++++ .../saledata/SaleDataTodayRepository.java | 68 +++++++++++++++++++ .../checkticket/CheckTicketServiceImpl.java | 7 +- .../service/saledata/SaleDataServiceImpl.java | 6 +- .../checkticket/CheckTicketToday.java | 21 ++++++ .../dataobject/saledata/SaleDataToday.java | 27 ++++++++ .../CheckTicketTodayRepository.java | 12 ++++ .../saledata/SaleDataTodayRepository.java | 65 ++++++++++++++++++ .../job/ticketing/TicketDataMigration.java | 6 +- .../checkticket/CheckTicketService.java | 2 + .../checkticket/CheckTicketServiceImpl.java | 24 +++++++ .../service/saledata/SaleDataService.java | 2 + .../service/saledata/SaleDataServiceImpl.java | 43 +++++++----- 15 files changed, 331 insertions(+), 28 deletions(-) create mode 100644 ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/dataobject/checkticket/CheckTicketToday.java create mode 100644 ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/dataobject/saledata/SaleDataToday.java create mode 100644 ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/mongodb/checkticket/CheckTicketTodayRepository.java create mode 100644 ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/mongodb/saledata/SaleDataTodayRepository.java create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/checkticket/CheckTicketToday.java create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/saledata/SaleDataToday.java create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mongodb/checkticket/CheckTicketTodayRepository.java create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mongodb/saledata/SaleDataTodayRepository.java diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/dataobject/checkticket/CheckTicketToday.java b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/dataobject/checkticket/CheckTicketToday.java new file mode 100644 index 000000000..dd9ae3274 --- /dev/null +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/dataobject/checkticket/CheckTicketToday.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.datacenter.dal.dataobject.checkticket; + +import lombok.Data; +import org.springframework.data.mongodb.core.mapping.Document; + +@Document("check_ticket_today") +//@Document("checktickettest") +@Data +public class CheckTicketToday { + private String id; + private String dataId; + private String checkstation; + private String checkstationname; + private String ticket; + private String checkticketdate; + private String checktickettime; + private Integer personcount; + private String sdshipping; + private String salepropetyvaluename; + +} \ No newline at end of file diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/dataobject/saledata/SaleDataToday.java b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/dataobject/saledata/SaleDataToday.java new file mode 100644 index 000000000..0fbe52906 --- /dev/null +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/dataobject/saledata/SaleDataToday.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.datacenter.dal.dataobject.saledata; + +import lombok.Data; +import org.springframework.data.mongodb.core.mapping.Document; + +import java.math.BigDecimal; + +@Document("sale_data_today") +@Data +public class SaleDataToday { + private String id; + private String dataId; + private String sdno; + private String transactiontypeno; + private String sddate; + private String sdtime; + private BigDecimal amount; + private Integer quantity; + private String certificatetype; + private String certificateno; + private String itemtype; + private String itemtypename; + private String item; + private String itemname; + private String productbatchno; + private String salepropetyvaluename; +} diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/mongodb/checkticket/CheckTicketTodayRepository.java b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/mongodb/checkticket/CheckTicketTodayRepository.java new file mode 100644 index 000000000..17199a002 --- /dev/null +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/mongodb/checkticket/CheckTicketTodayRepository.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.module.datacenter.dal.mongodb.checkticket; + + +import cn.iocoder.yudao.module.datacenter.dal.dataobject.checkticket.CheckTicket; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +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 { + @Query("{'name': {'$regex': '?0', '$options': 'i'}}") + Page findByName(String q, PageRequest pageable); + + @Query("{'checkticketdate':{'$gte': ?0, '$lt': ?1}}") + List countByCheckticketdateBetween(String starTime, String endTime); + + @Query("{'checktickettime':{'$gte': ?0, '$lt': ?1},'checkticketdate':{'$dt': ?2}}") + List findByTimestampBetweenAndCheckticketdate(String startTime, String endTime,String day); + + List findByCheckticketdateAndChecktickettimeBetween(String day,String startTime, String endTime); + + @Query("{'checkticketdate':{'$gte': ?0, '$lt': ?1} , 'checktickettime':{'$gte': ?2, '$lt': ?3}}") + List findByCheckticketdateBetweenAndChecktickettimeBetween(String startTime, String endTime,String beingTime, String resultTime); +} diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/mongodb/saledata/SaleDataTodayRepository.java b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/mongodb/saledata/SaleDataTodayRepository.java new file mode 100644 index 000000000..549cebd70 --- /dev/null +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/dal/mongodb/saledata/SaleDataTodayRepository.java @@ -0,0 +1,68 @@ +package cn.iocoder.yudao.module.datacenter.dal.mongodb.saledata; + + +import cn.iocoder.yudao.module.datacenter.controller.app.saledata.vo.AgeVo; +import cn.iocoder.yudao.module.datacenter.controller.app.saledata.vo.AggregationVO; +import cn.iocoder.yudao.module.datacenter.controller.app.saledata.vo.SaleDataItemTypeVo; +import cn.iocoder.yudao.module.datacenter.dal.dataobject.saledata.SaleData; +import cn.iocoder.yudao.module.datacenter.dal.dataobject.saledata.SaleDataToday; +import org.springframework.data.mongodb.repository.Aggregation; +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 SaleDataTodayRepository extends MongoRepository { + /*@Query("{'name': {'$regex': '?0', '$options': 'i'}}") + Page findByName(String q, PageRequest pageable);*/ + int countBySddate(String day); + + @Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'sddate': 1 }") + List countBySddateToTime(String starTime, String endTime); + + +// @Query("{ 'sddate' : { $gte: ?0, $lte: ?1 } }") + @Query(value = "{ 'sddate': { $gte: ?0, $lte: ?1 } }", fields = "{ 'certificateno': 1, 'amount': 1}") + ListfindBySddateBetween(String begin,String end); + + @Aggregation(pipeline = { + "{$project: {certLength: {$strLenCP: '$certificateno'}, secondLastChar: {$substrCP: ['$certificateno', {$subtract: [{$strLenCP: '$certificateno'}, 2]}, 1]}}}", + "{$group: {_id: null, maleCount: {$sum: {$cond: {if: {$eq: [{$mod: [{$toInt: '$secondLastChar'}, 2]}, 1]}, then: 1, else: 0}}}, femaleCount: {$sum: {$cond: {if: {$eq: [{$mod: [{$toInt: '$secondLastChar'}, 2]}, 0]}, then: 1, else: 0}}}, totalCount: {$sum: 1}}}", + "{$project: {_id: 0, maleCount: 1, femaleCount: 1, maleRatio: {$divide: ['$maleCount', '$totalCount']}}}" + }) + AggregationVO findAllByCertificateno(); + + @Aggregation(pipeline = { + "{$match: {sddate: { $gte: ?0, $lte: ?1 }}}", + "{$project: {certLength: {$strLenCP: '$certificateno'}, secondLastChar: {$substrCP: ['$certificateno', {$subtract: [{$strLenCP: '$certificateno'}, 2]}, 1]}}}", + "{$group: {_id: null, maleCount: {$sum: {$cond: {if: {$eq: [{$mod: [{$toInt: '$secondLastChar'}, 2]}, 1]}, then: 1, else: 0}}}, femaleCount: {$sum: {$cond: {if: {$eq: [{$mod: [{$toInt: '$secondLastChar'}, 2]}, 0]}, then: 1, else: 0}}}, totalCount: {$sum: 1}}}", + "{$project: {_id: 0, maleCount: 1, femaleCount: 1, maleRatio: {$divide: ['$maleCount', '$totalCount']}}}" + }) + AggregationVO findAllByCertificatenoSDTime(String starTime, String endTime); + + @Aggregation(pipeline = { + "{$match: {sddate: { $gte: ?0, $lte: ?1 }}}", + "{$match: {certificateno: {$regex: '^.{18}$'}}}", + "{$project: {birthYear: {$toInt: {$substr: ['$certificateno', 6, 4]}}, currentYear: {$year: '$$NOW'}}}", + "{$addFields: {age: {$subtract: ['$currentYear', '$birthYear']}}}", + "{$group: {_id: null, one: {$sum: {$cond: [{$lte: ['$age', 20]}, 1, 0]}}, " + + "two: {$sum: {$cond: [{$and: [{$gt: ['$age', 20]}, {$lte: ['$age', 30]}]}, 1, 0]}}, " + + "three: {$sum: {$cond: [{$and: [{$gt: ['$age', 30]}, {$lte: ['$age', 40]}]}, 1, 0]}}, " + + "four: {$sum: {$cond: [{$and: [{$gt: ['$age', 40]}, {$lte: ['$age', 50]}]}, 1, 0]}}, " + + "five: {$sum: {$cond: [{$and: [{$gt: ['$age', 50]}, {$lte: ['$age', 60]}]}, 1, 0]}}, " + + "six: {$sum: {$cond: [{$gt: ['$age', 60]}, 1, 0]}}}}" + }) + AgeVo findByAge(String starTime, String endTime); + + @Query(value = "{}", fields = "{ 'itemtypename': 1 }") + List findAllByItemtypename(); + + @Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'itemname': 1 }") + List findAllByItemtypenameTime(String starTime, String endTime); + + @Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'transactiontypeno': 1 }") + List findAllByTransactiontypenoTime(String starTime, String endTime); + +} diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/checkticket/CheckTicketServiceImpl.java b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/checkticket/CheckTicketServiceImpl.java index 19697e226..c7f192eed 100644 --- a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/checkticket/CheckTicketServiceImpl.java +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/checkticket/CheckTicketServiceImpl.java @@ -1,10 +1,8 @@ package cn.iocoder.yudao.module.datacenter.service.checkticket; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.datacenter.controller.app.saledata.vo.AggregationVO; import cn.iocoder.yudao.module.datacenter.dal.dataobject.checkticket.CheckTicket; -import cn.iocoder.yudao.module.datacenter.dal.mongodb.checkticket.CheckTicketRepository; +import cn.iocoder.yudao.module.datacenter.dal.mongodb.checkticket.CheckTicketTodayRepository; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -17,7 +15,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; /** * 检票 Service 实现类 @@ -29,7 +26,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU public class CheckTicketServiceImpl implements CheckTicketService { @Resource - private CheckTicketRepository checkTicketRepository; + private CheckTicketTodayRepository checkTicketRepository; @Override diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/saledata/SaleDataServiceImpl.java b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/saledata/SaleDataServiceImpl.java index bb0dfdd87..946dbe961 100644 --- a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/saledata/SaleDataServiceImpl.java +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/service/saledata/SaleDataServiceImpl.java @@ -8,7 +8,7 @@ import cn.iocoder.yudao.module.datacenter.controller.app.saledata.vo.AgeVo; import cn.iocoder.yudao.module.datacenter.controller.app.saledata.vo.AggregationVO; import cn.iocoder.yudao.module.datacenter.controller.app.saledata.vo.SaleDataItemTypeVo; import cn.iocoder.yudao.module.datacenter.dal.dataobject.saledata.SaleData; -import cn.iocoder.yudao.module.datacenter.dal.mongodb.saledata.SaleDataRepository; +import cn.iocoder.yudao.module.datacenter.dal.mongodb.saledata.SaleDataTodayRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -16,8 +16,6 @@ import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; @@ -32,7 +30,7 @@ import java.util.stream.Collectors; public class SaleDataServiceImpl implements SaleDataService { @Autowired - private SaleDataRepository saleDataRepository; + private SaleDataTodayRepository saleDataRepository; public String publicMethod(String endTime){ // 创建 DateTimeFormatter 实例以解析指定日期的格式 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 new file mode 100644 index 000000000..f829ef142 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/checkticket/CheckTicketToday.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.infra.dal.dataobject.checkticket; + +import lombok.Data; +import org.springframework.data.mongodb.core.mapping.Document; + +@Document("checkticket") +//@Document("checktickettest") +@Data +public class CheckTicketToday { + private String id; + private String dataId; + private String checkstation; + private String checkstationname; + private String ticket; + private String checkticketdate; + private String checktickettime; + private Integer personcount; + private String sdshipping; + private String salepropetyvaluename; + +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/saledata/SaleDataToday.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/saledata/SaleDataToday.java new file mode 100644 index 000000000..63500c3f4 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/saledata/SaleDataToday.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.infra.dal.dataobject.saledata; + +import lombok.Data; +import org.springframework.data.mongodb.core.mapping.Document; + +import java.math.BigDecimal; + +@Document("sale_data_today") +@Data +public class SaleDataToday { + private String id; + private String dataId; + private String sdno; + private String transactiontypeno; + private String sddate; + private String sdtime; + private BigDecimal amount; + private Integer quantity; + private String certificatetype; + private String certificateno; + private String itemtype; + private String itemtypename; + private String item; + private String itemname; + private String productbatchno; + private String salepropetyvaluename; +} 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 new file mode 100644 index 000000000..387af83b2 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mongodb/checkticket/CheckTicketTodayRepository.java @@ -0,0 +1,12 @@ +package cn.iocoder.yudao.module.infra.dal.mongodb.checkticket; + + +import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicketToday; +import org.springframework.data.mongodb.repository.MongoRepository; +import org.springframework.stereotype.Repository; + + +@Repository +public interface CheckTicketTodayRepository extends MongoRepository { + +} 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 new file mode 100644 index 000000000..e9515a7a8 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mongodb/saledata/SaleDataTodayRepository.java @@ -0,0 +1,65 @@ +package cn.iocoder.yudao.module.infra.dal.mongodb.saledata; + + +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; +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 SaleDataTodayRepository extends MongoRepository { +// /*@Query("{'name': {'$regex': '?0', '$options': 'i'}}") +// Page findByName(String q, PageRequest pageable);*/ +// int countBySddate(String day); +// +// @Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'sddate': 1 }") +// List countBySddateToTime(String starTime, String endTime); +// +// +//// @Query("{ 'sddate' : { $gte: ?0, $lte: ?1 } }") +// @Query(value = "{ 'sddate': { $gte: ?0, $lte: ?1 } }", fields = "{ 'certificateno': 1, 'amount': 1}") +// ListfindBySddateBetween(String begin, String end); +// +// @Aggregation(pipeline = { +// "{$project: {certLength: {$strLenCP: '$certificateno'}, secondLastChar: {$substrCP: ['$certificateno', {$subtract: [{$strLenCP: '$certificateno'}, 2]}, 1]}}}", +// "{$group: {_id: null, maleCount: {$sum: {$cond: {if: {$eq: [{$mod: [{$toInt: '$secondLastChar'}, 2]}, 1]}, then: 1, else: 0}}}, femaleCount: {$sum: {$cond: {if: {$eq: [{$mod: [{$toInt: '$secondLastChar'}, 2]}, 0]}, then: 1, else: 0}}}, totalCount: {$sum: 1}}}", +// "{$project: {_id: 0, maleCount: 1, femaleCount: 1, maleRatio: {$divide: ['$maleCount', '$totalCount']}}}" +// }) +// AggregationVO findAllByCertificateno(); +// +// @Aggregation(pipeline = { +// "{$match: {sddate: { $gte: ?0, $lte: ?1 }}}", +// "{$project: {certLength: {$strLenCP: '$certificateno'}, secondLastChar: {$substrCP: ['$certificateno', {$subtract: [{$strLenCP: '$certificateno'}, 2]}, 1]}}}", +// "{$group: {_id: null, maleCount: {$sum: {$cond: {if: {$eq: [{$mod: [{$toInt: '$secondLastChar'}, 2]}, 1]}, then: 1, else: 0}}}, femaleCount: {$sum: {$cond: {if: {$eq: [{$mod: [{$toInt: '$secondLastChar'}, 2]}, 0]}, then: 1, else: 0}}}, totalCount: {$sum: 1}}}", +// "{$project: {_id: 0, maleCount: 1, femaleCount: 1, maleRatio: {$divide: ['$maleCount', '$totalCount']}}}" +// }) +// AggregationVO findAllByCertificatenoSDTime(String starTime, String endTime); +// +// @Aggregation(pipeline = { +// "{$match: {sddate: { $gte: ?0, $lte: ?1 }}}", +// "{$match: {certificateno: {$regex: '^.{18}$'}}}", +// "{$project: {birthYear: {$toInt: {$substr: ['$certificateno', 6, 4]}}, currentYear: {$year: '$$NOW'}}}", +// "{$addFields: {age: {$subtract: ['$currentYear', '$birthYear']}}}", +// "{$group: {_id: null, one: {$sum: {$cond: [{$lte: ['$age', 20]}, 1, 0]}}, " + +// "two: {$sum: {$cond: [{$and: [{$gt: ['$age', 20]}, {$lte: ['$age', 30]}]}, 1, 0]}}, " + +// "three: {$sum: {$cond: [{$and: [{$gt: ['$age', 30]}, {$lte: ['$age', 40]}]}, 1, 0]}}, " + +// "four: {$sum: {$cond: [{$and: [{$gt: ['$age', 40]}, {$lte: ['$age', 50]}]}, 1, 0]}}, " + +// "five: {$sum: {$cond: [{$and: [{$gt: ['$age', 50]}, {$lte: ['$age', 60]}]}, 1, 0]}}, " + +// "six: {$sum: {$cond: [{$gt: ['$age', 60]}, 1, 0]}}}}" +// }) +// AgeVo findByAge(String starTime, String endTime); +// +// @Query(value = "{}", fields = "{ 'itemtypename': 1 }") +// List findAllByItemtypename(); +// +// @Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'itemname': 1 }") +// List findAllByItemtypenameTime(String starTime, String endTime); +// +// @Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'transactiontypeno': 1 }") +// List findAllByTransactiontypenoTime(String starTime, String endTime); + +} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/job/ticketing/TicketDataMigration.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/job/ticketing/TicketDataMigration.java index cc903849e..4dfea2874 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/job/ticketing/TicketDataMigration.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/job/ticketing/TicketDataMigration.java @@ -7,8 +7,10 @@ import cn.iocoder.yudao.framework.common.util.date.TickingDateUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicket; import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicketDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicketToday; import cn.iocoder.yudao.module.infra.dal.dataobject.saledata.SaleData; import cn.iocoder.yudao.module.infra.dal.dataobject.saledata.SaleDataDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.saledata.SaleDataToday; import cn.iocoder.yudao.module.infra.dal.mongodb.checkticket.CheckTicketRepository; import cn.iocoder.yudao.module.infra.dal.mongodb.saledata.SaleDataRepository; import cn.iocoder.yudao.module.infra.dal.mysql.checkticket.CheckTicketMapper; @@ -148,7 +150,7 @@ public class TicketDataMigration { for (; pageNumber <= totalPages; pageNumber++) { ticketingSamplingRespVO = this.getUrlResponseData(SALE_DATA_SERVICE, SALE_DATA_METHOD, TickingDateUtils.getNowDayFormat(), pageNumber); mapList = ticketingSamplingRespVO.getDataMapList(); - List resultNum = saleDataService.insertByMongoDB(BeanUtils.toBean(mapList, SaleData.class)); + List resultNum = saleDataService.insertTodayByMongoDB(BeanUtils.toBean(mapList, SaleDataToday.class)); if (resultNum == null) { XxlJobHelper.log("数据批量插入异常!", pageNumber); } else { @@ -179,7 +181,7 @@ public class TicketDataMigration { for (; pageNumber <= totalPages; pageNumber++) { ticketingSamplingRespVO = this.getUrlResponseData(CHECK_TICKET_SERVICE, CHECK_TICKET_METHOD, date, pageNumber); mapList = ticketingSamplingRespVO.getDataMapList(); - List resultNum = checkTicketService.insertByMongoDB(BeanUtils.toBean(mapList, CheckTicket.class)); + List resultNum = checkTicketService.insertTodayByMongoDB(BeanUtils.toBean(mapList, CheckTicketToday.class)); if (resultNum == null) { XxlJobHelper.log("数据批量插入异常!", pageNumber); } else { diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/checkticket/CheckTicketService.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/checkticket/CheckTicketService.java index 6ccc56fb7..31d33386d 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/checkticket/CheckTicketService.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/checkticket/CheckTicketService.java @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.infra.controller.checkticket.vo.CheckTicketSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicket; import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicketDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicketToday; import javax.validation.Valid; import java.util.List; @@ -37,4 +38,5 @@ public interface CheckTicketService { * @return java.util.List 插入数据和重复数据 */ List insertByMongoDB(List checkTicketList); + List insertTodayByMongoDB(List checkTicketList); } \ No newline at end of file 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 6a1ad4081..25717b942 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 @@ -5,7 +5,9 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicket; import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicketDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicketToday; import cn.iocoder.yudao.module.infra.dal.mongodb.checkticket.CheckTicketRepository; +import cn.iocoder.yudao.module.infra.dal.mongodb.checkticket.CheckTicketTodayRepository; import cn.iocoder.yudao.module.infra.dal.mysql.checkticket.CheckTicketMapper; import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.Slave; @@ -38,6 +40,8 @@ public class CheckTicketServiceImpl implements CheckTicketService { private CheckTicketMapper checkTicketMapper; @Resource private CheckTicketRepository checkTicketRepository; + @Resource + private CheckTicketTodayRepository checkTicketTodayRepository; @Override public Long createCheckTicket(CheckTicketDO checkTicketDO) { @@ -75,4 +79,24 @@ public class CheckTicketServiceImpl implements CheckTicketService { return resultNum; } + @Override + public List insertTodayByMongoDB(List checkTicketList) { + List resultNum = new ArrayList<>(2); + // 把检票数据的dataId提取出来成数组 + List dataIdList = checkTicketList.stream().map(CheckTicketToday::getDataId).collect(Collectors.toList()); + // 获取重复的dataId + List duplicatesDataId = this.checkDuplicatesByMongoDB(dataIdList); + // 对checkTicketList过滤掉重复的dataId对应的数据,得到需要插入的不重复数据 + List insertCheckTicketList = checkTicketList.stream().filter(ticket -> !duplicatesDataId.contains(ticket.getDataId())).collect(Collectors.toList()); + try { + // 批量插入 + checkTicketTodayRepository.insert(insertCheckTicketList); + } catch (MongoException e){ + return null; + } + resultNum.add(insertCheckTicketList.size()); + resultNum.add(duplicatesDataId.size()); + return resultNum; + } + } \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/saledata/SaleDataService.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/saledata/SaleDataService.java index 04136ae06..9890d22a0 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/saledata/SaleDataService.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/saledata/SaleDataService.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.infra.controller.saledata.vo.SaleDataSaveReqVO; 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.SaleDataDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.saledata.SaleDataToday; import javax.validation.Valid; import java.math.BigDecimal; @@ -40,4 +41,5 @@ public interface SaleDataService { * @return java.util.List */ List insertByMongoDB(List saleDataList); + List insertTodayByMongoDB(List saleDataList); } \ No newline at end of file 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 753439d02..6e0c0dfaf 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 @@ -1,35 +1,20 @@ package cn.iocoder.yudao.module.infra.service.saledata; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.framework.common.util.ticket.IdCardUtil; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.infra.controller.saledata.vo.SaleDataSaveReqVO; 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.SaleDataDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.saledata.SaleDataToday; import cn.iocoder.yudao.module.infra.dal.mongodb.saledata.SaleDataRepository; +import cn.iocoder.yudao.module.infra.dal.mongodb.saledata.SaleDataTodayRepository; import cn.iocoder.yudao.module.infra.dal.mysql.saledata.SaleDataMapper; -import com.baomidou.dynamic.datasource.annotation.DS; -import com.baomidou.dynamic.datasource.annotation.Slave; -import com.mongodb.DuplicateKeyException; import com.mongodb.MongoException; -import org.springframework.data.domain.Example; -import org.springframework.data.domain.ExampleMatcher; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.math.BigDecimal; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; -import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.exact; - /** * 售票 Service 实现类 @@ -41,6 +26,10 @@ import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatc public class SaleDataServiceImpl implements SaleDataService { @Resource private SaleDataRepository saleDataRepository; + + @Resource + private SaleDataTodayRepository saleDataTodayRepository; + @Resource private SaleDataMapper saleDataMapper; @@ -81,5 +70,25 @@ public class SaleDataServiceImpl implements SaleDataService { return resultNum; } + @Override + public List insertTodayByMongoDB(List saleDataList) { + List resultNum = new ArrayList<>(2); + // 把检票数据的dataId提取出来成数组 + List dataIdList = saleDataList.stream().map(SaleDataToday::getDataId).collect(Collectors.toList()); + // 获取重复的dataId + List duplicatesDataId = this.checkDuplicatesByMongoDB(dataIdList); + // 对checkTicketList过滤掉重复的dataId对应的数据,得到需要插入的不重复数据 + List insertSaleDataList = saleDataList.stream().filter(saleData -> !duplicatesDataId.contains(saleData.getDataId())).collect(Collectors.toList()); + try { + // 批量插入 + saleDataTodayRepository.insert(insertSaleDataList); + } catch (MongoException e){ + return null; + } + resultNum.add(insertSaleDataList.size()); + resultNum.add(duplicatesDataId.size()); + return resultNum; + } + } \ No newline at end of file -- 2.45.2