import position

This commit is contained in:
mamoss 2025-03-15 03:45:37 +07:00
parent cd419686b0
commit 5a00f77744

View file

@ -2275,12 +2275,12 @@ export class ImportDataController extends Controller {
*/ */
@Post("mapposition-Officer") @Post("mapposition-Officer")
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 = await AppDataSource.getRepository(Profile)
.createQueryBuilder("OFFICER") .createQueryBuilder("profile")
// .where({ DEPARTMENT_CODE: "50" }) .leftJoinAndSelect("profile.current_holders", "posMaster")
// .skip(0) // .where({citizenId: "1720700018869"})
// .take(20) .where("posMaster.id IS NULL")
.getManyAndCount(); .getMany();
let rowCount = 0; let rowCount = 0;
let _null: any = null; let _null: any = null;
let type_: any = null; let type_: any = null;
@ -2289,26 +2289,19 @@ export class ImportDataController extends Controller {
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
}); });
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); console.log(rowCount);
const item = await AppDataSource.getRepository(OFFICER)
.createQueryBuilder("OFFICER")
.where({ CIT: _item.citizenId })
.getOne();
const existingProfile = await this.profileRepo.findOne({ if (item == null) {
where: { citizenId: item.CIT },
});
if (existingProfile == null) {
continue;
}
const posMasterCheck = await this.posMasterRepo.findOne({
where: { current_holderId: existingProfile.id },
});
if (posMasterCheck != null) {
continue; continue;
} }
let posMaster = new PosMaster(); let posMaster = new PosMaster();
let orgRoot = new OrgRoot(); let orgRoot = (await this.orgRootRepo.findOne({
if (item.DEPARTMENT_CODE != "50") {
orgRoot = (await this.orgRootRepo.findOne({
where: { where: {
DEPARTMENT_CODE: item.DEPARTMENT_CODE, DEPARTMENT_CODE: item.DEPARTMENT_CODE,
DIVISION_CODE: item.DIVISION_CODE, DIVISION_CODE: item.DIVISION_CODE,
@ -2317,7 +2310,6 @@ export class ImportDataController extends Controller {
orgRevisionId: orgRevision.id, orgRevisionId: orgRevision.id,
}, },
})) as OrgRoot; })) as OrgRoot;
}
if (orgRoot != null) { if (orgRoot != null) {
posMaster.orgRootId = orgRoot.id ?? _null; posMaster.orgRootId = orgRoot.id ?? _null;
} else { } else {
@ -2333,7 +2325,7 @@ export class ImportDataController extends Controller {
if (orgChild1 != null) { if (orgChild1 != null) {
posMaster.orgRootId = orgChild1.orgRootId ?? _null; posMaster.orgRootId = orgChild1.orgRootId ?? _null;
posMaster.orgChild1Id = orgChild1.id ?? _null; posMaster.orgChild1Id = orgChild1.id ?? _null;
} else { } else {
let orgChild2 = await this.orgChild2Repo.findOne({ let orgChild2 = await this.orgChild2Repo.findOne({
where: { where: {
DEPARTMENT_CODE: item.DEPARTMENT_CODE, DEPARTMENT_CODE: item.DEPARTMENT_CODE,
@ -2388,7 +2380,7 @@ export class ImportDataController extends Controller {
posMaster.isStaff = false; posMaster.isStaff = false;
posMaster.isDirector = false; posMaster.isDirector = false;
posMaster.isSit = false; posMaster.isSit = false;
posMaster.current_holderId = existingProfile.id; posMaster.current_holderId = _item.id;
posMaster.posMasterNo = item.SALARY == "" ? _null : Number(item.POS_NUM_CODE); posMaster.posMasterNo = item.SALARY == "" ? _null : Number(item.POS_NUM_CODE);
posMaster.orgRevisionId = orgRevision.id; posMaster.orgRevisionId = orgRevision.id;
posMaster.posMasterCreatedAt = new Date(); posMaster.posMasterCreatedAt = new Date();