|
@@ -2,7 +2,7 @@ import { DataSource, Repository } from 'typeorm';
|
|
|
import { DisabledPerson } from '@d8d/allin-disability-module/entities';
|
|
import { DisabledPerson } from '@d8d/allin-disability-module/entities';
|
|
|
import { OrderPerson } from '@d8d/allin-order-module/entities';
|
|
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 { AgeGroup, SalaryRange, StatItem, HouseholdStatItem, YearMonthQuery } from '../schemas/statistics.schema';
|
|
|
|
|
|
|
+import { SalaryRange, StatItem, HouseholdStatItem, YearMonthQuery } from '../schemas/statistics.schema';
|
|
|
|
|
|
|
|
export class StatisticsService {
|
|
export class StatisticsService {
|
|
|
private readonly disabledPersonRepository: Repository<DisabledPerson>;
|
|
private readonly disabledPersonRepository: Repository<DisabledPerson>;
|
|
@@ -58,6 +58,7 @@ export class StatisticsService {
|
|
|
.addSelect('COUNT(dp.id)', 'value')
|
|
.addSelect('COUNT(dp.id)', 'value')
|
|
|
.where('dp.id IN (:...personIds)', { personIds })
|
|
.where('dp.id IN (:...personIds)', { personIds })
|
|
|
.andWhere('dp.disabilityType IS NOT NULL')
|
|
.andWhere('dp.disabilityType IS NOT NULL')
|
|
|
|
|
+ .andWhere('dp.jobStatus = :jobStatus', { jobStatus: 1 })
|
|
|
.groupBy('dp.disabilityType');
|
|
.groupBy('dp.disabilityType');
|
|
|
|
|
|
|
|
const rawStats = await query.getRawMany();
|
|
const rawStats = await query.getRawMany();
|
|
@@ -102,6 +103,7 @@ export class StatisticsService {
|
|
|
.addSelect('COUNT(dp.id)', 'value')
|
|
.addSelect('COUNT(dp.id)', 'value')
|
|
|
.where('dp.id IN (:...personIds)', { personIds })
|
|
.where('dp.id IN (:...personIds)', { personIds })
|
|
|
.andWhere('dp.gender IS NOT NULL')
|
|
.andWhere('dp.gender IS NOT NULL')
|
|
|
|
|
+ .andWhere('dp.jobStatus = :jobStatus', { jobStatus: 1 })
|
|
|
.groupBy('dp.gender');
|
|
.groupBy('dp.gender');
|
|
|
|
|
|
|
|
const rawStats = await query.getRawMany();
|
|
const rawStats = await query.getRawMany();
|
|
@@ -153,7 +155,8 @@ export class StatisticsService {
|
|
|
END`, 'age_group'
|
|
END`, 'age_group'
|
|
|
)
|
|
)
|
|
|
.where('dp.id IN (:...personIds)', { personIds })
|
|
.where('dp.id IN (:...personIds)', { personIds })
|
|
|
- .andWhere('dp.birth_date IS NOT NULL');
|
|
|
|
|
|
|
+ .andWhere('dp.birth_date IS NOT NULL')
|
|
|
|
|
+ .andWhere('dp.jobStatus = :jobStatus', { jobStatus: 1 });
|
|
|
|
|
|
|
|
const rawAgeData = await ageQuery.getRawMany();
|
|
const rawAgeData = await ageQuery.getRawMany();
|
|
|
|
|
|
|
@@ -167,7 +170,7 @@ export class StatisticsService {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
rawAgeData.forEach(item => {
|
|
rawAgeData.forEach(item => {
|
|
|
- if (item.age_group && ageStats.hasOwnProperty(item.age_group)) {
|
|
|
|
|
|
|
+ if (item.age_group && Object.prototype.hasOwnProperty.call(ageStats, item.age_group)) {
|
|
|
ageStats[item.age_group as typeof ageGroups[number]]++;
|
|
ageStats[item.age_group as typeof ageGroups[number]]++;
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -213,6 +216,7 @@ export class StatisticsService {
|
|
|
.addSelect('COUNT(dp.id)', 'value')
|
|
.addSelect('COUNT(dp.id)', 'value')
|
|
|
.where('dp.id IN (:...personIds)', { personIds })
|
|
.where('dp.id IN (:...personIds)', { personIds })
|
|
|
.andWhere('dp.province IS NOT NULL')
|
|
.andWhere('dp.province IS NOT NULL')
|
|
|
|
|
+ .andWhere('dp.jobStatus = :jobStatus', { jobStatus: 1 })
|
|
|
.groupBy('dp.province, dp.city');
|
|
.groupBy('dp.province, dp.city');
|
|
|
|
|
|
|
|
const rawStats = await query.getRawMany();
|
|
const rawStats = await query.getRawMany();
|
|
@@ -293,14 +297,16 @@ export class StatisticsService {
|
|
|
stats: StatItem[];
|
|
stats: StatItem[];
|
|
|
total: number;
|
|
total: number;
|
|
|
}> {
|
|
}> {
|
|
|
- // 获取企业关联的订单人员薪资数据
|
|
|
|
|
|
|
+ // 获取企业关联的订单人员薪资数据(仅在职人员)
|
|
|
const query = this.orderPersonRepository
|
|
const query = this.orderPersonRepository
|
|
|
.createQueryBuilder('op')
|
|
.createQueryBuilder('op')
|
|
|
.innerJoin('op.order', 'order')
|
|
.innerJoin('op.order', 'order')
|
|
|
|
|
+ .innerJoin('op.person', 'dp')
|
|
|
.select('op.salaryDetail', 'salary')
|
|
.select('op.salaryDetail', 'salary')
|
|
|
.where('order.companyId = :companyId', { companyId })
|
|
.where('order.companyId = :companyId', { companyId })
|
|
|
.andWhere('op.salaryDetail IS NOT NULL')
|
|
.andWhere('op.salaryDetail IS NOT NULL')
|
|
|
- .andWhere('op.salaryDetail > 0');
|
|
|
|
|
|
|
+ .andWhere('op.salaryDetail > 0')
|
|
|
|
|
+ .andWhere('dp.jobStatus = :jobStatus', { jobStatus: 1 });
|
|
|
|
|
|
|
|
const rawSalaries = await query.getRawMany();
|
|
const rawSalaries = await query.getRawMany();
|
|
|
|
|
|
|
@@ -375,21 +381,21 @@ export class StatisticsService {
|
|
|
}> {
|
|
}> {
|
|
|
const { year, month } = query;
|
|
const { year, month } = query;
|
|
|
const now = new Date();
|
|
const now = new Date();
|
|
|
- const targetYear = year ?? now.getFullYear();
|
|
|
|
|
- const targetMonth = month ?? now.getMonth() + 1;
|
|
|
|
|
|
|
+ const _targetYear = year ?? now.getFullYear();
|
|
|
|
|
+ const _targetMonth = month ?? now.getMonth() + 1;
|
|
|
|
|
|
|
|
// 计算上个月
|
|
// 计算上个月
|
|
|
const previousDate = new Date(targetYear, targetMonth - 2, 1);
|
|
const previousDate = new Date(targetYear, targetMonth - 2, 1);
|
|
|
- const previousYear = previousDate.getFullYear();
|
|
|
|
|
- const previousMonth = previousDate.getMonth() + 1;
|
|
|
|
|
|
|
+ const _previousYear = previousDate.getFullYear();
|
|
|
|
|
+ const _previousMonth = previousDate.getMonth() + 1;
|
|
|
|
|
|
|
|
// 构建日期范围(当月)
|
|
// 构建日期范围(当月)
|
|
|
- const startDate = new Date(targetYear, targetMonth - 1, 1);
|
|
|
|
|
- const endDate = new Date(targetYear, targetMonth, 0, 23, 59, 59);
|
|
|
|
|
|
|
+ const _startDate = new Date(targetYear, targetMonth - 1, 1);
|
|
|
|
|
+ const _endDate = new Date(targetYear, targetMonth, 0, 23, 59, 59);
|
|
|
|
|
|
|
|
// 构建日期范围(上月)
|
|
// 构建日期范围(上月)
|
|
|
- const previousStartDate = new Date(previousYear, previousMonth - 1, 1);
|
|
|
|
|
- const previousEndDate = new Date(previousYear, previousMonth, 0, 23, 59, 59);
|
|
|
|
|
|
|
+ const _previousStartDate = new Date(previousYear, previousMonth - 1, 1);
|
|
|
|
|
+ const _previousEndDate = new Date(previousYear, previousMonth, 0, 23, 59, 59);
|
|
|
|
|
|
|
|
// 获取在职人员(jobStatus = 1)
|
|
// 获取在职人员(jobStatus = 1)
|
|
|
const personIds = await this.getCompanyDisabledPersonIds(companyId);
|
|
const personIds = await this.getCompanyDisabledPersonIds(companyId);
|
|
@@ -435,13 +441,13 @@ export class StatisticsService {
|
|
|
}> {
|
|
}> {
|
|
|
const { year, month } = query;
|
|
const { year, month } = query;
|
|
|
const now = new Date();
|
|
const now = new Date();
|
|
|
- const targetYear = year ?? now.getFullYear();
|
|
|
|
|
- const targetMonth = month ?? now.getMonth() + 1;
|
|
|
|
|
|
|
+ const _targetYear = year ?? now.getFullYear();
|
|
|
|
|
+ const _targetMonth = month ?? now.getMonth() + 1;
|
|
|
|
|
|
|
|
// 计算上个月
|
|
// 计算上个月
|
|
|
const previousDate = new Date(targetYear, targetMonth - 2, 1);
|
|
const previousDate = new Date(targetYear, targetMonth - 2, 1);
|
|
|
- const previousYear = previousDate.getFullYear();
|
|
|
|
|
- const previousMonth = previousDate.getMonth() + 1;
|
|
|
|
|
|
|
+ const _previousYear = previousDate.getFullYear();
|
|
|
|
|
+ const _previousMonth = previousDate.getMonth() + 1;
|
|
|
|
|
|
|
|
// 获取企业关联的订单人员薪资数据(当月)
|
|
// 获取企业关联的订单人员薪资数据(当月)
|
|
|
const salaryQuery = this.orderPersonRepository
|
|
const salaryQuery = this.orderPersonRepository
|
|
@@ -492,8 +498,8 @@ export class StatisticsService {
|
|
|
}> {
|
|
}> {
|
|
|
const { year, month } = query;
|
|
const { year, month } = query;
|
|
|
const now = new Date();
|
|
const now = new Date();
|
|
|
- const targetYear = year ?? now.getFullYear();
|
|
|
|
|
- const targetMonth = month ?? now.getMonth() + 1;
|
|
|
|
|
|
|
+ const _targetYear = year ?? now.getFullYear();
|
|
|
|
|
+ const _targetMonth = month ?? now.getMonth() + 1;
|
|
|
|
|
|
|
|
// 获取企业关联的残疾人员ID列表
|
|
// 获取企业关联的残疾人员ID列表
|
|
|
const personIds = await this.getCompanyDisabledPersonIds(companyId);
|
|
const personIds = await this.getCompanyDisabledPersonIds(companyId);
|
|
@@ -545,27 +551,27 @@ export class StatisticsService {
|
|
|
}> {
|
|
}> {
|
|
|
const { year, month } = query;
|
|
const { year, month } = query;
|
|
|
const now = new Date();
|
|
const now = new Date();
|
|
|
- const targetYear = year ?? now.getFullYear();
|
|
|
|
|
- const targetMonth = month ?? now.getMonth() + 1;
|
|
|
|
|
|
|
+ const _targetYear = year ?? now.getFullYear();
|
|
|
|
|
+ const _targetMonth = month ?? now.getMonth() + 1;
|
|
|
|
|
|
|
|
// 计算上个月
|
|
// 计算上个月
|
|
|
const previousDate = new Date(targetYear, targetMonth - 2, 1);
|
|
const previousDate = new Date(targetYear, targetMonth - 2, 1);
|
|
|
- const previousYear = previousDate.getFullYear();
|
|
|
|
|
- const previousMonth = previousDate.getMonth() + 1;
|
|
|
|
|
|
|
+ const _previousYear = previousDate.getFullYear();
|
|
|
|
|
+ const _previousMonth = previousDate.getMonth() + 1;
|
|
|
|
|
|
|
|
// 构建日期范围(当月)
|
|
// 构建日期范围(当月)
|
|
|
- const startDate = new Date(targetYear, targetMonth - 1, 1);
|
|
|
|
|
- const endDate = new Date(targetYear, targetMonth, 0, 23, 59, 59);
|
|
|
|
|
|
|
+ const _startDate = new Date(targetYear, targetMonth - 1, 1);
|
|
|
|
|
+ const _endDate = new Date(targetYear, targetMonth, 0, 23, 59, 59);
|
|
|
|
|
|
|
|
// 构建日期范围(上月)
|
|
// 构建日期范围(上月)
|
|
|
- const previousStartDate = new Date(previousYear, previousMonth - 1, 1);
|
|
|
|
|
- const previousEndDate = new Date(previousYear, previousMonth, 0, 23, 59, 59);
|
|
|
|
|
|
|
+ const _previousStartDate = new Date(previousYear, previousMonth - 1, 1);
|
|
|
|
|
+ const _previousEndDate = new Date(previousYear, previousMonth, 0, 23, 59, 59);
|
|
|
|
|
|
|
|
// 获取当月新增人数(通过订单创建时间)
|
|
// 获取当月新增人数(通过订单创建时间)
|
|
|
const currentCount = await this.employmentOrderRepository
|
|
const currentCount = await this.employmentOrderRepository
|
|
|
.createQueryBuilder('eo')
|
|
.createQueryBuilder('eo')
|
|
|
.innerJoin('eo.orderPersons', 'op')
|
|
.innerJoin('eo.orderPersons', 'op')
|
|
|
- .innerJoin('op.disabledPerson', 'dp')
|
|
|
|
|
|
|
+ .innerJoin('op.person', 'dp')
|
|
|
.where('eo.companyId = :companyId', { companyId })
|
|
.where('eo.companyId = :companyId', { companyId })
|
|
|
.andWhere('eo.createdAt >= :startDate', { startDate })
|
|
.andWhere('eo.createdAt >= :startDate', { startDate })
|
|
|
.andWhere('eo.createdAt <= :endDate', { endDate })
|
|
.andWhere('eo.createdAt <= :endDate', { endDate })
|
|
@@ -576,7 +582,7 @@ export class StatisticsService {
|
|
|
const previousCount = await this.employmentOrderRepository
|
|
const previousCount = await this.employmentOrderRepository
|
|
|
.createQueryBuilder('eo')
|
|
.createQueryBuilder('eo')
|
|
|
.innerJoin('eo.orderPersons', 'op')
|
|
.innerJoin('eo.orderPersons', 'op')
|
|
|
- .innerJoin('op.disabledPerson', 'dp')
|
|
|
|
|
|
|
+ .innerJoin('op.person', 'dp')
|
|
|
.where('eo.companyId = :companyId', { companyId })
|
|
.where('eo.companyId = :companyId', { companyId })
|
|
|
.andWhere('eo.createdAt >= :startDate', { startDate: previousStartDate })
|
|
.andWhere('eo.createdAt >= :startDate', { startDate: previousStartDate })
|
|
|
.andWhere('eo.createdAt <= :endDate', { endDate: previousEndDate })
|
|
.andWhere('eo.createdAt <= :endDate', { endDate: previousEndDate })
|