售票查询按性别统计数量 增加身份证非空判断
This commit is contained in:
parent
c672fb03fd
commit
019a3f5be7
@ -36,12 +36,43 @@ public interface SaleDataTodayRepository extends MongoRepository<SaleDataToday,S
|
|||||||
|
|
||||||
@Aggregation(pipeline = {
|
@Aggregation(pipeline = {
|
||||||
"{$match: {sddate: { $gte: ?0, $lte: ?1 }}}",
|
"{$match: {sddate: { $gte: ?0, $lte: ?1 }}}",
|
||||||
"{$project: {certLength: {$strLenCP: '$certificateno'}, secondLastChar: {$substrCP: ['$certificateno', {$subtract: [{$strLenCP: '$certificateno'}, 2]}, 1]}}}",
|
"{$project: {" +
|
||||||
"{$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}}}",
|
// 使用 $ifNull 处理 certficateno 为 null 或空字符串的情况
|
||||||
"{$project: {_id: 0, maleCount: 1, femaleCount: 1, maleRatio: {$divide: ['$maleCount', '$totalCount']}}}"
|
" certLength: {$strLenCP: {$ifNull: ['$certificateno', '']}}, " +
|
||||||
|
// 获取倒数第二个字符,并处理 certficateno 为 null 或长度小于 2 的情况
|
||||||
|
" secondLastChar: {$cond: {" +
|
||||||
|
" if: {$gte: [{$strLenCP: {$ifNull: ['$certificateno', '']}}, 2]}," +
|
||||||
|
" then: {$substrCP: [" +
|
||||||
|
" {$ifNull: ['$certificateno', '']}," +
|
||||||
|
" {$subtract: [{$strLenCP: {$ifNull: ['$certificateno', '']}}, 2]}, 1" +
|
||||||
|
" ]}, " +
|
||||||
|
" else: '0'" + // 如果 certficateno 长度小于 2,返回 '0'
|
||||||
|
" }}" +
|
||||||
|
"}}",
|
||||||
|
"{$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);
|
AggregationVO findAllByCertificatenoSDTime(String starTime, String endTime);
|
||||||
|
|
||||||
|
|
||||||
@Aggregation(pipeline = {
|
@Aggregation(pipeline = {
|
||||||
"{$match: {sddate: { $gte: ?0, $lte: ?1 }}}",
|
"{$match: {sddate: { $gte: ?0, $lte: ?1 }}}",
|
||||||
"{$match: {certificateno: {$regex: '^.{18}$'}}}",
|
"{$match: {certificateno: {$regex: '^.{18}$'}}}",
|
||||||
|
Loading…
Reference in New Issue
Block a user