|
@@ -4,6 +4,7 @@ import { OrderPerson } from '@d8d/allin-order-module/entities';
|
|
|
import { EmploymentOrder } from '@d8d/allin-order-module/entities';
|
|
import { EmploymentOrder } from '@d8d/allin-order-module/entities';
|
|
|
import { SalaryRange, StatItem, HouseholdStatItem } from '../schemas/statistics.schema';
|
|
import { SalaryRange, StatItem, HouseholdStatItem } from '../schemas/statistics.schema';
|
|
|
import { AreaEntity } from '@d8d/geo-areas';
|
|
import { AreaEntity } from '@d8d/geo-areas';
|
|
|
|
|
+import { WorkStatusLabels } from '@d8d/allin-enums';
|
|
|
|
|
|
|
|
export class StatisticsService {
|
|
export class StatisticsService {
|
|
|
private readonly disabledPersonRepository: Repository<DisabledPerson>;
|
|
private readonly disabledPersonRepository: Repository<DisabledPerson>;
|
|
@@ -231,6 +232,7 @@ export class StatisticsService {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取在职状态分布统计
|
|
* 获取在职状态分布统计
|
|
|
|
|
+ * 使用 orderPerson.workStatus 枚举进行统计,反映实际的工作状态多样性
|
|
|
* @param companyId 企业ID
|
|
* @param companyId 企业ID
|
|
|
* @returns 在职状态分布统计结果
|
|
* @returns 在职状态分布统计结果
|
|
|
*/
|
|
*/
|
|
@@ -239,35 +241,22 @@ export class StatisticsService {
|
|
|
stats: StatItem[];
|
|
stats: StatItem[];
|
|
|
total: number;
|
|
total: number;
|
|
|
}> {
|
|
}> {
|
|
|
- const personIds = await this.getCompanyDisabledPersonIds(companyId);
|
|
|
|
|
-
|
|
|
|
|
- if (personIds.length === 0) {
|
|
|
|
|
- return {
|
|
|
|
|
- companyId,
|
|
|
|
|
- stats: [],
|
|
|
|
|
- total: 0
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const query = this.disabledPersonRepository
|
|
|
|
|
- .createQueryBuilder('dp')
|
|
|
|
|
- .select('dp.jobStatus', 'key')
|
|
|
|
|
- .addSelect('COUNT(dp.id)', 'value')
|
|
|
|
|
- .where('dp.id IN (:...personIds)', { personIds })
|
|
|
|
|
- .andWhere('dp.jobStatus IS NOT NULL')
|
|
|
|
|
- .groupBy('dp.jobStatus');
|
|
|
|
|
|
|
+ // 直接从 orderPerson 表统计,基于 workStatus 分组
|
|
|
|
|
+ const query = this.orderPersonRepository
|
|
|
|
|
+ .createQueryBuilder('op')
|
|
|
|
|
+ .innerJoin('op.order', 'order')
|
|
|
|
|
+ .select('op.workStatus', 'key')
|
|
|
|
|
+ .addSelect('COUNT(DISTINCT op.personId)', 'value') // 使用 DISTINCT 避免重复计数
|
|
|
|
|
+ .where('order.companyId = :companyId', { companyId })
|
|
|
|
|
+ .andWhere('op.workStatus IS NOT NULL')
|
|
|
|
|
+ .groupBy('op.workStatus');
|
|
|
|
|
|
|
|
const rawStats = await query.getRawMany();
|
|
const rawStats = await query.getRawMany();
|
|
|
const total = rawStats.reduce((sum, item) => sum + parseInt(item.value), 0);
|
|
const total = rawStats.reduce((sum, item) => sum + parseInt(item.value), 0);
|
|
|
|
|
|
|
|
- // jobStatus映射:0-未在职,1-已在职
|
|
|
|
|
- const jobStatusMap: Record<number, string> = {
|
|
|
|
|
- 0: '未在职',
|
|
|
|
|
- 1: '已在职'
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
|
|
+ // 使用 WorkStatusLabels 映射枚举值到中文友好名称
|
|
|
const stats = rawStats.map(item => ({
|
|
const stats = rawStats.map(item => ({
|
|
|
- key: jobStatusMap[item.key] || `未知(${item.key})`,
|
|
|
|
|
|
|
+ key: WorkStatusLabels[item.key as keyof typeof WorkStatusLabels] || item.key, // 未知状态显示原始值
|
|
|
value: parseInt(item.value),
|
|
value: parseInt(item.value),
|
|
|
percentage: total > 0 ? (parseInt(item.value) / total) * 100 : 0
|
|
percentage: total > 0 ? (parseInt(item.value) / total) * 100 : 0
|
|
|
}));
|
|
}));
|