Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2025-03-13 15:56:02 +07:00
commit a8b646ddeb
6 changed files with 200 additions and 135 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

@ -60,7 +60,7 @@ import { ProfileFamilyFather } from "../entities/ProfileFamilyFather";
import Extension from "../interfaces/extension";
import { ProfileInsignia } from "../entities/ProfileInsignia";
import { ProfileLeave } from "../entities/ProfileLeave";
import { updateName } from "../keycloak";
import { updateName, deleteUser } from "../keycloak";
import permission from "../interfaces/permission";
import { PosMasterAct } from "../entities/PosMasterAct";
import axios from "axios";
@ -9405,6 +9405,7 @@ export class ProfileController extends Controller {
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(profile);
let _null:any = null;
profile.isLeave = requestBody.isLeave;
profile.leaveReason = requestBody.leaveReason;
profile.dateLeave = requestBody.dateLeave;
@ -9412,6 +9413,17 @@ export class ProfileController extends Controller {
await removeProfileInOrganize(profile.id, "OFFICER");
}
profile.leaveType = "RETIRE_DECEASED";
profile.position = _null;
profile.posLevelId = _null;
profile.posTypeId = _null;
if (profile.keycloak != null) {
const delUserKeycloak = await deleteUser(profile.keycloak);
if (delUserKeycloak) {
profile.keycloak = _null;
profile.roleKeycloaks = [];
profile.isActive = false;
}
}
await this.profileRepo.save(profile, { data: request });
setLogDataDiff(request, { before, after: profile });

View file

@ -68,6 +68,7 @@ import permission from "../interfaces/permission";
import axios from "axios";
import { Position } from "../entities/Position";
import { EmployeePosition } from "../entities/EmployeePosition";
import { deleteUser } from "../keycloak";
@Route("api/v1/org/profile-employee")
@Tags("ProfileEmployee")
@Security("bearerAuth")
@ -4113,13 +4114,24 @@ export class ProfileEmployeeController extends Controller {
where: { id: id },
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
let _null:any = null;
profile.isLeave = requestBody.isLeave;
profile.leaveReason = requestBody.leaveReason;
profile.dateLeave = requestBody.dateLeave;
if (requestBody.isLeave == true) {
await removeProfileInOrganize(profile.id, "EMPLOYEE");
}
profile.position = _null;
profile.posLevelId = _null;
profile.posTypeId = _null;
if (profile.keycloak != null) {
const delUserKeycloak = await deleteUser(profile.keycloak);
if (delUserKeycloak) {
profile.keycloak = _null;
profile.roleKeycloaks = [];
profile.isActive = false;
}
}
profile.leaveType = "RETIRE_DECEASED";
await this.profileRepo.save(profile);

View file

@ -66,6 +66,7 @@ import { ProfileInsignia } from "../entities/ProfileInsignia";
import { ProfileLeave } from "../entities/ProfileLeave";
import permission from "../interfaces/permission";
import axios from "axios";
import { deleteUser } from "../keycloak";
@Route("api/v1/org/profile-temp")
@Tags("ProfileEmployee")
@Security("bearerAuth")
@ -3201,13 +3202,25 @@ export class ProfileEmployeeTempController extends Controller {
where: { id: id },
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
let _null:any = null;
profile.isLeave = requestBody.isLeave;
profile.leaveReason = requestBody.leaveReason;
profile.dateLeave = requestBody.dateLeave;
if (requestBody.isLeave == true) {
await removeProfileInOrganize(profile.id, "EMPLOYEE");
}
profile.leaveType = "RETIRE_DECEASED";
profile.position = _null;
profile.posLevelId = _null;
profile.posTypeId = _null;
if (profile.keycloak != null) {
const delUserKeycloak = await deleteUser(profile.keycloak);
if (delUserKeycloak) {
profile.keycloak = _null;
profile.roleKeycloaks = [];
profile.isActive = false;
}
}
await this.profileRepo.save(profile);
return new HttpSuccess();

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",