mis ผูกตำแหน่ง

This commit is contained in:
mamoss 2025-03-12 22:44:45 +07:00
parent 20ff14def9
commit 5e6fa4ff18

View file

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