Status: done
作为企业管理员, 我在企业小程序的数据统计页查看统计数据时, 我希望所有统计卡片和分布图显示的数据保持一致, 以便准确了解企业当前在职人员的统计信息。
当前问题: 企业小程序数据统计页面存在数据不一致问题:
根本原因: statistics.service.ts 中的分布统计方法缺少 jobStatus = 1 过滤条件:
getDisabilityTypeDistribution() - 缺少 jobStatus 过滤getGenderDistribution() - 缺少 jobStatus 过滤getAgeDistribution() - 缺少 jobStatus 过滤getHouseholdDistribution() - 缺少 jobStatus 过滤getSalaryDistribution() - 缺少 jobStatus 过滤影响范围: 企业用户无法准确了解在职人员的统计分布,影响数据分析和业务决策。
原型设计意图:
Given 企业小程序数据统计页 When 查看残疾类型分布图表时 Then 应仅统计 jobStatus=1 的在职人员 And 分布图总和应与"在职人数"卡片一致 Example: 在职人数 2 人,残疾类型分布总和也应是 2 人
Given 企业小程序数据统计页 When 查看性别分布图表时 Then 应仅统计 jobStatus=1 的在职人员 And 分布图总和应与"在职人数"卡片一致
Given 企业小程序数据统计页 When 查看年龄分布图表时 Then 应仅统计 jobStatus=1 的在职人员 And 分布图总和应与"在职人数"卡片一致
Given 企业小程序数据统计页 When 查看户籍省份分布图表时 Then 应仅统计 jobStatus=1 的在职人员 And 分布图总和应与"在职人数"卡片一致
Given 企业小程序数据统计页 When 查看薪资分布图表时 Then 应仅统计 jobStatus=1 的在职人员 And 分布图总和应与"在职人数"卡片一致
Given 企业小程序数据统计页 When 查看在职状态统计图表时 Then 应统计所有人员(在职+待入职+离职) And 展示各种状态的人数分布 Note: 此图表用于展示完整的状态分布,不应过滤
Given 企业小程序数据统计页 When 运行 E2E 测试时 Then 应验证所有分布图总和与在职人数一致 And 应验证在职状态统计图包含所有状态的人员
statistics.service.ts 中的分布统计方法getEmploymentCount() 方法的过滤逻辑(参考实现)getJobStatusDistribution() 方法的逻辑(应不过滤)getDisabilityTypeDistribution() 方法jobStatus = 1 过滤条件getEmploymentCount() 的实现方式getGenderDistribution() 方法jobStatus = 1 过滤条件getAgeDistribution() 方法jobStatus = 1 过滤条件getHouseholdDistribution() 方法jobStatus = 1 过滤条件getSalaryDistribution() 方法jobStatus = 1 过滤条件op.person 而非 op.disabledPersongetJobStatusDistribution() 方法不添加过滤Epic 13: 跨端数据同步测试 (Epic E)
需要修复的文件:
allin-packages/statistics-module/src/services/statistics.service.ts参考实现(正确过滤的示例):
// getEmploymentCount() 方法 - 正确过滤 jobStatus = 1
async getEmploymentCount(companyId: number, query: YearMonthQuery = {}): Promise<{
companyId: number;
count: number;
previousCount: number;
change: number;
}> {
// ... 其他代码 ...
// 当月在职人数 - 正确过滤
const currentCount = await this.disabledPersonRepository
.createQueryBuilder('dp')
.where('dp.id IN (:...personIds)', { personIds })
.andWhere('dp.jobStatus = :jobStatus', { jobStatus: 1 })
.getCount();
}
需要修复的方法示例:
// getDisabilityTypeDistribution() - 当前缺少过滤
async getDisabilityTypeDistribution(companyId: number): Promise<{
companyId: number;
stats: StatItem[];
total: number;
}> {
const personIds = await this.getCompanyDisabledPersonIds(companyId);
// 当前代码 - 缺少 jobStatus 过滤
const query = this.disabledPersonRepository
.createQueryBuilder('dp')
.select('dp.disabilityType', 'key')
.addSelect('COUNT(dp.id)', 'value')
.where('dp.id IN (:...personIds)', { personIds })
.andWhere('dp.disabilityType IS NOT NULL')
// 需要添加: .andWhere('dp.jobStatus = :jobStatus', { jobStatus: 1 })
.groupBy('dp.disabilityType');
}
getSalaryDistribution() 方法使用 orderPersonRepository 而非 disabledPersonRepository,需要通过关联过滤:
// getSalaryDistribution() - 需要 join disabledPerson 表
async getSalaryDistribution(companyId: number): Promise<{
companyId: number;
stats: StatItem[];
total: number;
}> {
// 当前代码
const query = this.orderPersonRepository
.createQueryBuilder('op')
.innerJoin('op.order', 'order')
.innerJoin('op.disabledPerson', 'dp') // 需要 join disabledPerson
.select('op.salaryDetail', 'salary')
.where('order.companyId = :companyId', { companyId })
.andWhere('op.salaryDetail IS NOT NULL')
.andWhere('op.salaryDetail > 0')
// 需要添加: .andWhere('dp.jobStatus = :jobStatus', { jobStatus: 1 })
}
企业小程序:
/#/mini/pages/yongren/statistics/index验证场景:
预期结果:
Created by user request via BMM create-story workflow
Implementation phase - no debug yet
问题修复: 修复了企业小程序数据统计页面分布图与在职人数卡片数据不一致问题。之前分布图统计了所有关联人员(包含离职人员),而"在职人数"卡片正确过滤了 jobStatus=1 的在职人员。
修改的方法:
getDisabilityTypeDistribution() - 添加 jobStatus=1 过滤getGenderDistribution() - 添加 jobStatus=1 过滤getAgeDistribution() - 添加 jobStatus=1 过滤getHouseholdDistribution() - 添加 jobStatus=1 过滤getSalaryDistribution() - 添加 jobStatus=1 过滤,并修复关系名称(op.person)额外修复:
getNewCount() 方法中的相同问题(op.disabledPerson → op.person)getSalaryDistribution() 方法的关系名称问题验证:
已修改的文件:
allin-packages/statistics-module/src/services/statistics.service.ts具体修改:
getDisabilityTypeDistribution() 添加 .andWhere('dp.jobStatus = :jobStatus', { jobStatus: 1 })getGenderDistribution() 添加 .andWhere('dp.jobStatus = :jobStatus', { jobStatus: 1 })getAgeDistribution() 添加 .andWhere('dp.jobStatus = :jobStatus', { jobStatus: 1 })getHouseholdDistribution() 添加 .andWhere('dp.jobStatus = :jobStatus', { jobStatus: 1 })getSalaryDistribution() 添加 .innerJoin('op.person', 'dp') 和 .andWhere('dp.jobStatus = :jobStatus', { jobStatus: 1 })getNewCount() 修复关系名称 op.disabledPerson → op.person