|
|
@@ -903,9 +903,54 @@ export class DisabledPersonService extends GenericCrudService<DisabledPerson> {
|
|
|
// 排序
|
|
|
queryBuilder.orderBy('op.joinDate', 'DESC');
|
|
|
|
|
|
- // 获取总数
|
|
|
- const totalQuery = queryBuilder.clone();
|
|
|
- const total = await totalQuery.getCount();
|
|
|
+ // 获取总数 - 使用单独的查询,因为 getCount() 在有自定义 select 时会失败
|
|
|
+ const countQueryBuilder = orderPersonRepo.createQueryBuilder('op')
|
|
|
+ .innerJoin('op.person', 'person')
|
|
|
+ .innerJoin('op.order', 'order')
|
|
|
+ .leftJoin('order.company', 'company');
|
|
|
+
|
|
|
+ // 应用相同的筛选条件
|
|
|
+ if (gender) {
|
|
|
+ countQueryBuilder.andWhere('person.gender = :gender', { gender });
|
|
|
+ }
|
|
|
+ if (disabilityType) {
|
|
|
+ countQueryBuilder.andWhere('person.disabilityType = :disabilityType', { disabilityType });
|
|
|
+ }
|
|
|
+ if (disabilityLevel) {
|
|
|
+ countQueryBuilder.andWhere('person.disabilityLevel = :disabilityLevel', { disabilityLevel });
|
|
|
+ }
|
|
|
+ if (city) {
|
|
|
+ countQueryBuilder.andWhere('person.city = :city', { city });
|
|
|
+ }
|
|
|
+ if (district) {
|
|
|
+ countQueryBuilder.andWhere('person.district = :district', { district });
|
|
|
+ }
|
|
|
+ if (disabilityId) {
|
|
|
+ countQueryBuilder.andWhere('person.disabilityId = :disabilityId', { disabilityId });
|
|
|
+ }
|
|
|
+ if (companyId) {
|
|
|
+ countQueryBuilder.andWhere('order.companyId = :companyId', { companyId });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 年龄筛选:根据出生日期计算
|
|
|
+ if (minAge !== undefined || maxAge !== undefined) {
|
|
|
+ const today = new Date();
|
|
|
+ const minBirthDate = maxAge !== undefined
|
|
|
+ ? new Date(today.getFullYear() - maxAge - 1, today.getMonth(), today.getDate())
|
|
|
+ : undefined;
|
|
|
+ const maxBirthDate = minAge !== undefined
|
|
|
+ ? new Date(today.getFullYear() - minAge, today.getMonth(), today.getDate())
|
|
|
+ : undefined;
|
|
|
+
|
|
|
+ if (minBirthDate) {
|
|
|
+ countQueryBuilder.andWhere('person.birthDate <= :minBirthDate', { minBirthDate });
|
|
|
+ }
|
|
|
+ if (maxBirthDate) {
|
|
|
+ countQueryBuilder.andWhere('person.birthDate >= :maxBirthDate', { maxBirthDate });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const total = Number(await countQueryBuilder.getCount()) || 0;
|
|
|
|
|
|
// 分页
|
|
|
queryBuilder.offset((page - 1) * limit).limit(limit);
|
|
|
@@ -913,19 +958,19 @@ export class DisabledPersonService extends GenericCrudService<DisabledPerson> {
|
|
|
// 执行查询
|
|
|
const rawResults = await queryBuilder.getRawMany();
|
|
|
|
|
|
- // 转换结果格式
|
|
|
+ // 转换结果格式,确保字段类型正确
|
|
|
const data = rawResults.map((row: any) => ({
|
|
|
- personId: row.personid,
|
|
|
- name: row.name,
|
|
|
- gender: row.gender,
|
|
|
- disabilityType: row.disabilitytype,
|
|
|
- disabilityLevel: row.disabilitylevel,
|
|
|
- disabilityId: row.disabilityid,
|
|
|
- city: row.city,
|
|
|
- district: row.district,
|
|
|
- companyName: row.companyname,
|
|
|
- orderId: row.orderid,
|
|
|
- joinDate: row.joindate
|
|
|
+ personId: Number(row.personid) || 0,
|
|
|
+ name: String(row.name || ''),
|
|
|
+ gender: String(row.gender || ''),
|
|
|
+ disabilityType: String(row.disabilitytype || ''),
|
|
|
+ disabilityLevel: String(row.disabilitylevel || ''),
|
|
|
+ disabilityId: String(row.disabilityid || ''),
|
|
|
+ city: String(row.city || ''),
|
|
|
+ district: row.district || null,
|
|
|
+ companyName: String(row.companyname || ''),
|
|
|
+ orderId: Number(row.orderid) || 0,
|
|
|
+ joinDate: row.joindate ? new Date(row.joindate) : new Date()
|
|
|
}));
|
|
|
|
|
|
return { data, total };
|