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> }) {
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;