import ตำแหน่ง

This commit is contained in:
kittapath 2025-03-13 14:53:55 +07:00
parent 7b955739ba
commit f1f7412db0
3 changed files with 160 additions and 132 deletions

View file

@ -540,12 +540,12 @@ export class EmployeeTempPositionController extends Controller {
},
relations: ["orgRoot"],
});
if (chk_SName0 != null) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
);
}
// if (chk_SName0 != null) {
// throw new HttpError(
// HttpStatusCode.INTERNAL_SERVER_ERROR,
// "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
// );
// }
const chk_SName1 = await this.employeeTempPosMasterRepository.findOne({
where: {
@ -556,12 +556,12 @@ export class EmployeeTempPositionController extends Controller {
},
relations: ["orgChild1"],
});
if (chk_SName1 != null) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
);
}
// if (chk_SName1 != null) {
// throw new HttpError(
// HttpStatusCode.INTERNAL_SERVER_ERROR,
// "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
// );
// }
const chk_SName2 = await this.employeeTempPosMasterRepository.findOne({
where: {
@ -572,12 +572,12 @@ export class EmployeeTempPositionController extends Controller {
},
relations: ["orgChild2"],
});
if (chk_SName2 != null) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
);
}
// if (chk_SName2 != null) {
// throw new HttpError(
// HttpStatusCode.INTERNAL_SERVER_ERROR,
// "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
// );
// }
const chk_SName3 = await this.employeeTempPosMasterRepository.findOne({
where: {
@ -588,12 +588,12 @@ export class EmployeeTempPositionController extends Controller {
},
relations: ["orgChild3"],
});
if (chk_SName3 != null) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
);
}
// if (chk_SName3 != null) {
// throw new HttpError(
// HttpStatusCode.INTERNAL_SERVER_ERROR,
// "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
// );
// }
const chk_SName4 = await this.employeeTempPosMasterRepository.findOne({
where: {
@ -603,12 +603,12 @@ export class EmployeeTempPositionController extends Controller {
},
relations: ["orgChild4"],
});
if (chk_SName4 != null) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
);
}
// if (chk_SName4 != null) {
// throw new HttpError(
// HttpStatusCode.INTERNAL_SERVER_ERROR,
// "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
// );
// }
const before = null;
posMaster.createdUserId = request.user.sub;
posMaster.createdFullName = request.user.name;
@ -749,12 +749,12 @@ export class EmployeeTempPositionController extends Controller {
},
relations: ["orgRoot"],
});
if (chk_SName0 != null) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
);
}
// if (chk_SName0 != null) {
// throw new HttpError(
// HttpStatusCode.INTERNAL_SERVER_ERROR,
// "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
// );
// }
const chk_SName1 = await this.employeeTempPosMasterRepository.findOne({
where: {
@ -766,12 +766,12 @@ export class EmployeeTempPositionController extends Controller {
},
relations: ["orgChild1"],
});
if (chk_SName1 != null) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
);
}
// if (chk_SName1 != null) {
// throw new HttpError(
// HttpStatusCode.INTERNAL_SERVER_ERROR,
// "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
// );
// }
const chk_SName2 = await this.employeeTempPosMasterRepository.findOne({
where: {
@ -783,12 +783,12 @@ export class EmployeeTempPositionController extends Controller {
},
relations: ["orgChild2"],
});
if (chk_SName2 != null) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
);
}
// if (chk_SName2 != null) {
// throw new HttpError(
// HttpStatusCode.INTERNAL_SERVER_ERROR,
// "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
// );
// }
const chk_SName3 = await this.employeeTempPosMasterRepository.findOne({
where: {
@ -800,12 +800,12 @@ export class EmployeeTempPositionController extends Controller {
},
relations: ["orgChild3"],
});
if (chk_SName3 != null) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
);
}
// if (chk_SName3 != null) {
// throw new HttpError(
// HttpStatusCode.INTERNAL_SERVER_ERROR,
// "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
// );
// }
const chk_SName4 = await this.employeeTempPosMasterRepository.findOne({
where: {
@ -816,12 +816,12 @@ export class EmployeeTempPositionController extends Controller {
},
relations: ["orgChild4"],
});
if (chk_SName4 != null) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
);
}
// if (chk_SName4 != null) {
// throw new HttpError(
// HttpStatusCode.INTERNAL_SERVER_ERROR,
// "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
// );
// }
const before = structuredClone(posMaster);
posMaster.createdUserId = request.user.sub; //สงสัยว่าทำให้ bug แก้ไขไม่ได้
posMaster.createdFullName = request.user.name;

View file

@ -2277,11 +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" })
// .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;
@ -2305,77 +2305,84 @@ export class ImportDataController extends Controller {
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) {
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,
},
})) 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,
},
})) 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;
posMaster.orgChild2Id = orgChild2?.id ?? _null;
posMaster.orgChild3Id = orgChild3?.id ?? _null;
let orgRoot = new OrgRoot();
if (item.DEPARTMENT_CODE != "50") {
orgRoot = (await this.orgRootRepo.findOne({
where: {
DEPARTMENT_CODE: item.DEPARTMENT_CODE,
DIVISION_CODE: item.DIVISION_CODE,
SECTION_CODE: item.SECTION_CODE,
JOB_CODE: item.JOB_CODE,
orgRevisionId: orgRevision.id,
},
})) as OrgRoot;
}
if (orgRoot != null) {
posMaster.orgRootId = orgRoot.id ?? _null;
} else {
let orgChild1 = await this.orgChild1Repo.findOne({
where: {
DEPARTMENT_CODE: item.DEPARTMENT_CODE,
DIVISION_CODE: item.DIVISION_CODE,
SECTION_CODE: item.SECTION_CODE,
JOB_CODE: item.JOB_CODE,
orgRevisionId: orgRevision.id,
},
});
if (orgChild1 != null) {
posMaster.orgRootId = orgChild1.orgRootId ?? _null;
posMaster.orgChild1Id = orgChild1.id ?? _null;
} else {
let orgChild2 = await this.orgChild2Repo.findOne({
where: {
DEPARTMENT_CODE: item.DEPARTMENT_CODE,
DIVISION_CODE: item.DIVISION_CODE,
SECTION_CODE: item.SECTION_CODE,
JOB_CODE: item.JOB_CODE,
orgRevisionId: orgRevision.id,
},
});
if (orgChild2 != null) {
posMaster.orgRootId = orgChild2.orgRootId ?? _null;
posMaster.orgChild1Id = orgChild2.orgChild1Id ?? _null;
posMaster.orgChild2Id = orgChild2.id ?? _null;
} else {
let orgChild3 = await this.orgChild3Repo.findOne({
where: {
DEPARTMENT_CODE: item.DEPARTMENT_CODE,
DIVISION_CODE: item.DIVISION_CODE,
SECTION_CODE: item.SECTION_CODE,
JOB_CODE: item.JOB_CODE,
orgRevisionId: orgRevision.id,
},
});
if (orgChild3 != null) {
posMaster.orgRootId = orgChild3.orgRootId ?? _null;
posMaster.orgChild1Id = orgChild3.orgChild1Id ?? _null;
posMaster.orgChild2Id = orgChild3.orgChild2Id ?? _null;
posMaster.orgChild3Id = orgChild3.id ?? _null;
} else {
let orgChild4 = await this.orgChild4Repo.findOne({
where: {
DEPARTMENT_CODE: item.DEPARTMENT_CODE,
DIVISION_CODE: item.DIVISION_CODE,
SECTION_CODE: item.SECTION_CODE,
JOB_CODE: item.JOB_CODE,
orgRevisionId: orgRevision.id,
},
});
if (orgChild4 != null) {
posMaster.orgRootId = orgChild4.id ?? _null;
posMaster.orgChild1Id = orgChild4.id ?? _null;
posMaster.orgChild2Id = orgChild4.id ?? _null;
posMaster.orgChild3Id = orgChild4.id ?? _null;
posMaster.orgChild4Id = orgChild4.id ?? _null;
}
}
}
}
}
posMaster.statusReport = "PENDING";
posMaster.isCondition = false;
posMaster.isStaff = false;

View file

@ -117,6 +117,13 @@ export class OFFICER {
})
DIVISION_NAME: string;
@Column({
nullable: true,
type: "text",
default: null,
})
DIVISION_CODE: string;
@Column({
nullable: true,
type: "text",
@ -124,6 +131,13 @@ export class OFFICER {
})
SECTION_NAME: string;
@Column({
nullable: true,
type: "text",
default: null,
})
SECTION_CODE: string;
@Column({
nullable: true,
type: "text",
@ -131,6 +145,13 @@ export class OFFICER {
})
JOB_NAME: string;
@Column({
nullable: true,
type: "text",
default: null,
})
JOB_CODE: string;
@Column({
nullable: true,
type: "text",