mis ผูกตำแหน่ง

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

View file

@ -2277,6 +2277,7 @@ 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();
@ -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,20 +2299,55 @@ 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 (posMasterCheck != null) {
continue;
}
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) { if (orgRoot == null) {
continue; continue;
} }
const orgChild1 = await this.orgChild1Repo.findOne({ 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: { 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;
const orgChild2 = await this.orgChild2Repo.findOne({ orgChild2 = (await this.orgChild2Repo.findOne({
where: { where: {
orgChild2Name: item.SECTION_NAME, orgChild2Name: item.SECTION_NAME,
orgChild1: { orgChild1: {
@ -2319,8 +2356,8 @@ export class ImportDataController extends Controller {
}, },
orgRevisionId: orgRevision.id, orgRevisionId: orgRevision.id,
}, },
}); })) as OrgChild2;
const orgChild3 = await this.orgChild3Repo.findOne({ orgChild3 = (await this.orgChild3Repo.findOne({
where: { where: {
orgChild3Name: item.JOB_NAME, orgChild3Name: item.JOB_NAME,
orgChild2: { orgChild2: {
@ -2332,7 +2369,8 @@ export class ImportDataController extends Controller {
}, },
orgRevisionId: orgRevision.id, 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;