diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index ca8689c7..8f029255 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -2277,10 +2277,11 @@ export class ImportDataController extends Controller { async MapPositionOfficer(@Request() request: { user: Record }) { const [officer, total] = await AppDataSource.getRepository(OFFICER) .createQueryBuilder("OFFICER") + .where({ DEPARTMENT_CODE: "50" }) // .skip(0) // .take(20) .getManyAndCount(); - let rowCount = 0; + let rowCount = 0; let _null: any = null; let type_: any = null; let level_: any = null; @@ -2290,6 +2291,7 @@ export class ImportDataController extends Controller { if (orgRevision == null) return new HttpSuccess(); for await (const item of officer) { rowCount++; + console.log(rowCount); const existingProfile = await this.profileRepo.findOne({ where: { citizenId: item.CIT }, @@ -2297,42 +2299,78 @@ export class ImportDataController extends Controller { if (existingProfile == null) { continue; } - const orgRoot = await this.orgRootRepo.findOne({ - where: { orgRootName: item.DEPARTMENT_NAME, orgRevisionId: orgRevision.id }, + const posMasterCheck = await this.posMasterRepo.findOne({ + where: { current_holderId: existingProfile.id }, }); - if (orgRoot == null) { + if (posMasterCheck != null) { continue; } - const orgChild1 = await this.orgChild1Repo.findOne({ - where: { - orgChild1Name: item.DIVISION_NAME, - orgRoot: { orgRootName: item.DEPARTMENT_NAME }, - orgRevisionId: orgRevision.id, - }, - }); - const orgChild2 = await this.orgChild2Repo.findOne({ - where: { - orgChild2Name: item.SECTION_NAME, - orgChild1: { + let orgRoot = new OrgRoot(); + let orgChild1 = new OrgChild1(); + let orgChild2 = new OrgChild2(); + let orgChild3 = new OrgChild3(); + if ((item.DEPARTMENT_CODE = "50")) { + orgRoot = (await this.orgRootRepo.findOne({ + where: { orgRootName: item.DIVISION_NAME, orgRevisionId: orgRevision.id }, + })) as OrgRoot; + if (orgRoot == null) { + continue; + } + orgChild1 = (await this.orgChild1Repo.findOne({ + where: { + orgChild1Name: item.SECTION_NAME, + orgRoot: { orgRootName: item.DIVISION_NAME }, + orgRevisionId: orgRevision.id, + }, + })) as OrgChild1; + orgChild2 = (await this.orgChild2Repo.findOne({ + where: { + orgChild2Name: item.JOB_NAME, + orgChild1: { + orgChild1Name: item.SECTION_NAME, + orgRoot: { orgRootName: item.DIVISION_NAME }, + }, + orgRevisionId: orgRevision.id, + }, + })) as OrgChild2; + } else { + orgRoot = (await this.orgRootRepo.findOne({ + where: { orgRootName: item.DEPARTMENT_NAME, orgRevisionId: orgRevision.id }, + })) as OrgRoot; + if (orgRoot == null) { + continue; + } + orgChild1 = (await this.orgChild1Repo.findOne({ + where: { orgChild1Name: item.DIVISION_NAME, orgRoot: { orgRootName: item.DEPARTMENT_NAME }, + orgRevisionId: orgRevision.id, }, - orgRevisionId: orgRevision.id, - }, - }); - const orgChild3 = await this.orgChild3Repo.findOne({ - where: { - orgChild3Name: item.JOB_NAME, - orgChild2: { + })) as OrgChild1; + orgChild2 = (await this.orgChild2Repo.findOne({ + where: { orgChild2Name: item.SECTION_NAME, orgChild1: { orgChild1Name: item.DIVISION_NAME, orgRoot: { orgRootName: item.DEPARTMENT_NAME }, }, + orgRevisionId: orgRevision.id, }, - orgRevisionId: orgRevision.id, - }, - }); + })) as OrgChild2; + orgChild3 = (await this.orgChild3Repo.findOne({ + where: { + orgChild3Name: item.JOB_NAME, + orgChild2: { + orgChild2Name: item.SECTION_NAME, + orgChild1: { + orgChild1Name: item.DIVISION_NAME, + orgRoot: { orgRootName: item.DEPARTMENT_NAME }, + }, + }, + orgRevisionId: orgRevision.id, + }, + })) as OrgChild3; + } let posMaster = new PosMaster(); posMaster.orgRootId = orgRoot?.id ?? _null; posMaster.orgChild1Id = orgChild1?.id ?? _null;