Status: review
作为企业管理员, 我在企业小程序的数据统计页查看"在职人数"时, 我希望显示的人数与首页仪表板保持一致, 以便准确了解企业当前在职人员情况。
当前问题: 企业小程序首页仪表板和数据统计页显示的在职人数不一致:
根本原因: 两个 API 使用了不同的统计口径(统计字段):
首页 API (/company/overview)
order_person.work_status = 'working' 进行统计数据统计页 API (/statistics/employment-count)
disabled_person.job_status = 1 进行统计影响范围: 企业用户无法准确了解在职人数,影响数据分析和业务决策。
技术细节:
order_person.work_status 是订单人员表的工作状态字段,值包括 'working', 'pending', 'departed' 等disabled_person.job_status 是残疾人表的工作状态字段,值是数字类型(1=在职,0=离职)Given 企业小程序数据统计页
When 调用 /statistics/employment-count API
Then 返回的 count 值应与首页 /company/overview API 返回的在职人数一致
Given getEmploymentCount 方法被调用
When 方法执行统计查询
Then 应使用 orderPersonRepository 和 work_status = 'working' 进行过滤
And 不应再使用 disabledPersonRepository 和 job_status = 1
Given 其他统计接口如平均薪资、在职率等 When 调用这些接口 Then 应该正常工作,不受此次修改影响
Given 修改完成后 When 运行数据统计页 E2E 测试 Then 所有测试应该通过
statistics.service.ts 中的 getEmploymentCount() 方法/company/overview API 的统计逻辑(参考实现)getEmploymentCount() 方法disabledPersonRepository 改为使用 orderPersonRepositoryjobStatus = 1 改为 workStatus = 'working'getAverageSalary() 相关测试getEmploymentRate() 相关测试getNewCount() 相关测试getEmploymentCount() 的正确性allin-packages/statistics-module/src/services/statistics.service.tsgetEmploymentCount() (行 388-413)/company/overview API 的统计逻辑// 当前实现(错误)
async getEmploymentCount(companyId: number): Promise<{
companyId: number;
count: number;
}> {
const personIds = await this.getCompanyDisabledPersonIds(companyId);
if (personIds.length === 0) {
return { companyId, count: 0 };
}
const currentCount = await this.disabledPersonRepository
.createQueryBuilder('dp')
.where('dp.id IN (:...personIds)', { personIds })
.andWhere('dp.jobStatus = :jobStatus', { jobStatus: 1 }) // 错误的过滤条件
.getCount();
return { companyId, count: currentCount };
}
// 修复后的实现(正确)
async getEmploymentCount(companyId: number): Promise<{
companyId: number;
count: number;
}> {
// 直接从 orderPerson 表统计,无需先获取 personIds
const currentCount = await this.orderPersonRepository
.createQueryBuilder('op')
.innerJoin('op.order', 'order')
.where('order.companyId = :companyId', { companyId })
.andWhere('op.workStatus = :workStatus', { workStatus: 'working' }) // 正确的过滤条件
.getCount();
return { companyId, count: currentCount };
}
表结构理解:
order_person 表: 订单人员关联表,记录人员与订单的关系和工作状态disabled_person 表: 残疾人基础信息表work_status (order_person): 字符串枚举 ('working', 'pending', 'departed')job_status (disabled_person): 数字类型 (1=在职, 0=离职)统计口径选择:
order_person.work_status = 'working' 是正确的统计口径性能考虑:
单元测试:
getEmploymentCount() 返回正确的 count集成测试:
E2E 测试:
allin-packages/statistics-module/src/services/statistics.service.ts - 统计服务实现allin-packages/statistics-module/src/routes/statistics.routes.ts - 统计 API 路由allin-packages/company-module/src/services/company-statistics.service.ts - 首页统计服务(参考实现)Claude (d8d-model)
N/A
statistics.service.ts 的 getEmploymentCount() 方法disabledPerson.jobStatus = 1 改为 orderPerson.workStatus = 'working'/company/overview API 使用相同的统计口径主要修改文件:
allin-packages/statistics-module/src/services/statistics.service.ts (修改 getEmploymentCount 方法)