|
|
@@ -6,7 +6,7 @@ import { DisabledPhoto } from '../entities/disabled-photo.entity';
|
|
|
import { DisabledRemark } from '../entities/disabled-remark.entity';
|
|
|
import { DisabledVisit } from '../entities/disabled-visit.entity';
|
|
|
import { File } from '@d8d/file-module';
|
|
|
-import{ OrderPerson, OrderPersonAsset } from '@d8d/allin-order-module';
|
|
|
+import { OrderPerson, OrderPersonAsset } from '@d8d/allin-order-module';
|
|
|
import { WorkStatus, getWorkStatusLabel } from '@d8d/allin-enums';
|
|
|
|
|
|
// 前端专用的工作状态中文标签映射(与mini-ui保持一致)
|
|
|
@@ -101,6 +101,31 @@ export class DisabledPersonService extends GenericCrudService<DisabledPerson> {
|
|
|
relations: ['bankCards', 'bankCards.bankName', 'bankCards.file', 'bankCards.file.uploadUser', 'photos', 'photos.file', 'photos.file.uploadUser', 'remarks', 'visits', 'guardianPhones', 'phones']
|
|
|
});
|
|
|
|
|
|
+ if (!person) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加载最新的订单和公司信息
|
|
|
+ const orderPersonRepo = this.dataSource.getRepository(OrderPerson);
|
|
|
+ const latestOrderPerson = await orderPersonRepo
|
|
|
+ .createQueryBuilder('op')
|
|
|
+ .innerJoinAndSelect('op.order', 'order')
|
|
|
+ .leftJoinAndSelect('order.company', 'company')
|
|
|
+ .where('op.personId = :personId', { personId: id })
|
|
|
+ .orderBy('op.joinDate', 'DESC')
|
|
|
+ .getOne();
|
|
|
+
|
|
|
+ // 将公司信息附加到残疾人对象(使用类型断言避免 TypeScript 错误)
|
|
|
+ if (latestOrderPerson?.order?.company) {
|
|
|
+ (person as any).currentCompanyId = latestOrderPerson.order.company.id;
|
|
|
+ (person as any).currentCompany = {
|
|
|
+ id: latestOrderPerson.order.company.id,
|
|
|
+ companyName: latestOrderPerson.order.company.companyName,
|
|
|
+ contactPerson: latestOrderPerson.order.company.contactPerson,
|
|
|
+ contactPhone: latestOrderPerson.order.company.contactPhone,
|
|
|
+ address: latestOrderPerson.order.company.address
|
|
|
+ };
|
|
|
+ }
|
|
|
|
|
|
return person;
|
|
|
}
|
|
|
@@ -174,14 +199,30 @@ export class DisabledPersonService extends GenericCrudService<DisabledPerson> {
|
|
|
if (data.length > 0) {
|
|
|
const personIds = data.map(p => p.id);
|
|
|
|
|
|
- const [bankCards, photos, remarks, visits] = await Promise.all([
|
|
|
+ const [bankCards, photos, remarks, visits, latestOrderPersons] = await Promise.all([
|
|
|
this.bankCardRepository.find({ where: { personId: In(personIds) } }),
|
|
|
this.photoRepository.find({
|
|
|
where: { personId: In(personIds) },
|
|
|
relations: ['file']
|
|
|
}),
|
|
|
this.remarkRepository.find({ where: { personId: In(personIds) } }),
|
|
|
- this.visitRepository.find({ where: { personId: In(personIds) } })
|
|
|
+ this.visitRepository.find({ where: { personId: In(personIds) } }),
|
|
|
+ // 加载每个残疾人的最新订单和公司信息
|
|
|
+ this.dataSource.getRepository(OrderPerson)
|
|
|
+ .createQueryBuilder('op')
|
|
|
+ .innerJoin('op.order', 'order')
|
|
|
+ .leftJoin('order.company', 'company')
|
|
|
+ .select([
|
|
|
+ 'op.personId',
|
|
|
+ 'company.id',
|
|
|
+ 'company.companyName',
|
|
|
+ 'company.contactPerson',
|
|
|
+ 'company.contactPhone',
|
|
|
+ 'company.address'
|
|
|
+ ])
|
|
|
+ .where('op.personId IN (:...personIds)', { personIds })
|
|
|
+ .orderBy('op.joinDate', 'DESC')
|
|
|
+ .getRawMany()
|
|
|
]);
|
|
|
|
|
|
|
|
|
@@ -190,6 +231,7 @@ export class DisabledPersonService extends GenericCrudService<DisabledPerson> {
|
|
|
const photosMap = new Map<number, DisabledPhoto[]>();
|
|
|
const remarksMap = new Map<number, DisabledRemark[]>();
|
|
|
const visitsMap = new Map<number, DisabledVisit[]>();
|
|
|
+ const companyMap = new Map<number, any>();
|
|
|
|
|
|
for (const card of bankCards) {
|
|
|
const cards = bankCardsMap.get(card.personId) || [];
|
|
|
@@ -215,12 +257,33 @@ export class DisabledPersonService extends GenericCrudService<DisabledPerson> {
|
|
|
visitsMap.set(visit.personId, visits);
|
|
|
}
|
|
|
|
|
|
+ // 处理公司信息(只保留每个残疾人的第一个/最新公司)
|
|
|
+ for (const row of latestOrderPersons) {
|
|
|
+ const personId = row.op_person_id; // PostgreSQL 返回的列名格式
|
|
|
+ if (!companyMap.has(personId) && row.company_company_id) {
|
|
|
+ companyMap.set(personId, {
|
|
|
+ id: row.company_company_id,
|
|
|
+ companyName: row.company_company_name,
|
|
|
+ contactPerson: row.company_contact_person,
|
|
|
+ contactPhone: row.company_contact_phone,
|
|
|
+ address: row.company_address
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 将关联数据附加到每个残疾人
|
|
|
for (const person of data) {
|
|
|
person.bankCards = bankCardsMap.get(person.id) || [];
|
|
|
person.photos = photosMap.get(person.id) || [];
|
|
|
person.remarks = remarksMap.get(person.id) || [];
|
|
|
person.visits = visitsMap.get(person.id) || [];
|
|
|
+
|
|
|
+ // 添加公司信息
|
|
|
+ const company = companyMap.get(person.id);
|
|
|
+ if (company) {
|
|
|
+ (person as any).currentCompanyId = company.id;
|
|
|
+ (person as any).currentCompany = company;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -236,6 +299,31 @@ export class DisabledPersonService extends GenericCrudService<DisabledPerson> {
|
|
|
relations: ['bankCards', 'photos', 'photos.file', 'remarks', 'visits', 'guardianPhones', 'phones']
|
|
|
});
|
|
|
|
|
|
+ if (!person) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加载最新的订单和公司信息
|
|
|
+ const orderPersonRepo = this.dataSource.getRepository(OrderPerson);
|
|
|
+ const latestOrderPerson = await orderPersonRepo
|
|
|
+ .createQueryBuilder('op')
|
|
|
+ .innerJoinAndSelect('op.order', 'order')
|
|
|
+ .leftJoinAndSelect('order.company', 'company')
|
|
|
+ .where('op.personId = :personId', { personId: person.id })
|
|
|
+ .orderBy('op.joinDate', 'DESC')
|
|
|
+ .getOne();
|
|
|
+
|
|
|
+ // 将公司信息附加到残疾人对象
|
|
|
+ if (latestOrderPerson?.order?.company) {
|
|
|
+ (person as any).currentCompanyId = latestOrderPerson.order.company.id;
|
|
|
+ (person as any).currentCompany = {
|
|
|
+ id: latestOrderPerson.order.company.id,
|
|
|
+ companyName: latestOrderPerson.order.company.companyName,
|
|
|
+ contactPerson: latestOrderPerson.order.company.contactPerson,
|
|
|
+ contactPhone: latestOrderPerson.order.company.contactPhone,
|
|
|
+ address: latestOrderPerson.order.company.address
|
|
|
+ };
|
|
|
+ }
|
|
|
|
|
|
return person;
|
|
|
}
|