This commit is contained in:
harid 2025-12-23 16:00:04 +07:00
parent f605f59b6e
commit 8083d9a0ae
4 changed files with 225 additions and 199 deletions

View file

@ -10821,114 +10821,124 @@ export class ProfileController extends Controller {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
let findProfile: any;
let total: any;
const skip = (page - 1) * pageSize;
const take = pageSize;
let queryLike = "1=1";
switch (body.fieldName) {
case "citizenId":
[findProfile, total] = await this.profileRepo.findAndCount({
where: {
keycloak: IsNull(),
citizenId: Like(`%${body.keyword}%`),
},
relations: ["posType", "posLevel", "current_holders"],
skip,
take,
});
queryLike = "profile.citizenId LIKE :keyword";
break;
case "fullName":
[findProfile, total] = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.posType", "posType")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.where("profile.keycloak IS NULL")
.andWhere(
"CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword",
{ keyword: `%${body.keyword}%` }
)
.skip(skip)
.take(take)
.getManyAndCount();
queryLike =
"CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword";
break;
case "firstname":
[findProfile, total] = await this.profileRepo.findAndCount({
where: {
keycloak: IsNull(),
firstName: Like(`%${body.keyword}%`),
},
relations: ["posType", "posLevel", "current_holders"],
skip,
take,
});
case "firstName":
queryLike = "profile.firstName LIKE :keyword";
break;
case "lastname":
[findProfile, total] = await this.profileRepo.findAndCount({
where: {
keycloak: IsNull(),
lastName: Like(`%${body.keyword}%`),
},
relations: ["posType", "posLevel", "current_holders"],
skip,
take,
});
case "lastName":
queryLike = "profile.lastName LIKE :keyword";
break;
default:
[findProfile, total] = await this.profileRepo.findAndCount({
where: {
keycloak: IsNull(),
},
relations: ["posType", "posLevel", "current_holders"],
skip,
take,
});
queryLike = "1=1";
break;
}
let query = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.posType", "posType")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.where("profile.keycloak IS NULL")
.andWhere(
new Brackets((qb) => {
qb.orWhere(body.keyword ? queryLike : "1=1", { keyword: `%${body.keyword}%` });
}),
);
const [findProfile, total] = await query
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
const mapDataProfile = await Promise.all(
findProfile.map(async (item: Profile) => {
const fullName = `${item.prefix} ${item.firstName} ${item.lastName}`;
const shortName =
item.current_holders.length == 0
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 !=
null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
let shortName = null;
let root = null;
let posMasterNo = null;
if (item.isLeave == false) {
shortName =
item.current_holders.length == 0
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3 !=
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 !=
null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild2 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3 !=
null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild1 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) !=
null &&
?.orgChild2 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgRoot != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: null;
const root =
item.current_holders.length == 0 ||
(item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null)
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
const posMasterNo = item.current_holders?.find(
(x) => x.orgRevisionId == findRevision.id,
)?.posMasterNo;
?.orgChild1 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) !=
null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgRoot != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: null;
root =
item.current_holders.length == 0 ||
(item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null)
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
root = root == null ? null : root.orgRootName;
posMasterNo = item.current_holders?.find(
(x) => x.orgRevisionId == findRevision.id,
)?.posMasterNo;
}
else {
const profileSalary = await this.salaryRepo
.createQueryBuilder("s")
.where("s.profileId = :profileId", { profileId: item.id })
.andWhere("s.commandCode IN (:...codes)", {
codes: ["0","9","1","2","3","4","8","10","11","12","13","14","15","16"],
})
.orderBy("s.order", "DESC")
.addOrderBy("s.createdAt", "DESC")
.take(2)
.getMany();
if (profileSalary.length > 0) {
shortName = item.isRetirement
? profileSalary.length > 1
? `${profileSalary[1]?.posNoAbb} ${profileSalary[1]?.posNo}`
: `${profileSalary[0]?.posNoAbb} ${profileSalary[0]?.posNo}`
: `${profileSalary[0]?.posNoAbb} ${profileSalary[0]?.posNo}`;
posMasterNo = item.isRetirement
? profileSalary.length > 1
? profileSalary[1]?.posNo
: profileSalary[0]?.posNo
: profileSalary[0]?.posNo;
root = item.isRetirement
? profileSalary.length > 1
? profileSalary[1]?.orgRoot
: profileSalary[0]?.orgRoot
: profileSalary[0]?.orgRoot;
}
}
const latestProfileEducation = await this.profileEducationRepo.findOne({
where: { profileId: item.id },
@ -10952,7 +10962,7 @@ export class ProfileController extends Controller {
positionType: item.posTypeId,
positionTypeName: item.posType?.posTypeName,
posNo: shortName,
organization: root == null ? null : root.orgRootName,
organization: root,
salary: item.amount,
posMasterNo: posMasterNo ?? null,
posTypeId: item.posTypeId,