แก้คิวรี่ให้ไว

This commit is contained in:
mamoss 2025-07-24 12:36:45 +07:00
parent 91c8e37647
commit 0f5afcd0c7

View file

@ -1110,14 +1110,14 @@ export class ProfileController extends Controller {
: null, : null,
disciplineDetail: item.detail ?? null, disciplineDetail: item.detail ?? null,
refNo: Extension.ToThaiNumber(item.refCommandNo) ?? null, refNo: Extension.ToThaiNumber(item.refCommandNo) ?? null,
level: item.level ?? "" level: item.level ?? "",
})) }))
: [ : [
{ {
disciplineYear: "-", disciplineYear: "-",
disciplineDetail: "-", disciplineDetail: "-",
refNo: "-", refNo: "-",
level: "-" level: "-",
}, },
]; ];
@ -1402,8 +1402,9 @@ export class ProfileController extends Controller {
where: { profileId: id }, where: { profileId: id },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const history = profileHistory.length > 0 const history =
? profileHistory.map(item => ({ profileHistory.length > 0
? profileHistory.map((item) => ({
birthDateOld: item.birthDateOld birthDateOld: item.birthDateOld
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.birthDateOld)) ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.birthDateOld))
: "", : "",
@ -1415,8 +1416,8 @@ export class ProfileController extends Controller {
{ {
birthDateOld: "-", birthDateOld: "-",
birthDate: "-", birthDate: "-",
} },
] ];
const position_raw = await this.salaryRepo.find({ const position_raw = await this.salaryRepo.find({
where: { where: {
@ -1565,15 +1566,16 @@ export class ProfileController extends Controller {
: "", : "",
pointSum: item.pointSum ? Extension.ToThaiNumber(item.pointSum.toString()) : "", pointSum: item.pointSum ? Extension.ToThaiNumber(item.pointSum.toString()) : "",
pointSumTh: item.pointSum ? Extension.textPoint(item.pointSum) : "", pointSumTh: item.pointSum ? Extension.textPoint(item.pointSum) : "",
level: item.pointSum < 60.00 level:
item.pointSum < 60.0
? "ต้องปรับปรุง (คะแนนต่ำกว่าร้อยละ ๖๐.)" ? "ต้องปรับปรุง (คะแนนต่ำกว่าร้อยละ ๖๐.)"
: item.pointSum <= 69.99 && item.pointSum >= 60.00 : item.pointSum <= 69.99 && item.pointSum >= 60.0
? "พอใช้ (คะแนนร้อยละ ๖๐. - ๖๙.๙๙)" ? "พอใช้ (คะแนนร้อยละ ๖๐. - ๖๙.๙๙)"
: item.pointSum <= 79.99 && item.pointSum >= 70.00 : item.pointSum <= 79.99 && item.pointSum >= 70.0
? "ดี (คะแนนร้อยละ ๗๐. - ๗๙.๙๙)" ? "ดี (คะแนนร้อยละ ๗๐. - ๗๙.๙๙)"
: item.pointSum <= 89.99 && item.pointSum >= 80.00 : item.pointSum <= 89.99 && item.pointSum >= 80.0
? "ดีมาก (คะแนนร้อยละ ๘๐. - ๘๙.๙๙)" ? "ดีมาก (คะแนนร้อยละ ๘๐. - ๘๙.๙๙)"
: "ดีเด่น (คะแนนร้อยละ ๙๐. ขึ้นไป)" : "ดีเด่น (คะแนนร้อยละ ๙๐. ขึ้นไป)",
})) }))
: [ : [
{ {
@ -1583,7 +1585,7 @@ export class ProfileController extends Controller {
point2: "-", point2: "-",
pointSum: "-", pointSum: "-",
pointSumTh: "-", pointSumTh: "-",
level: "-" level: "-",
}, },
]; ];
const profileAbility_raw = await this.profileAbilityRepo.find({ const profileAbility_raw = await this.profileAbilityRepo.find({
@ -6118,109 +6120,67 @@ export class ProfileController extends Controller {
if (!findRevision) { if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
} }
// 1. เลือกเฉพาะ field ที่จำเป็น
const [record, total] = await this.profileRepo const [record, total] = await this.profileRepo
.createQueryBuilder("profile") .createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel") .select([
.leftJoinAndSelect("profile.posType", "posType") "profile.id",
.leftJoinAndSelect("profile.current_holders", "current_holders") "profile.prefix",
.leftJoinAndSelect("current_holders.positions", "positions") "profile.rank",
.leftJoinAndSelect("positions.posExecutive", "posExecutive") "profile.firstName",
.leftJoinAndSelect("current_holders.orgRevision", "orgRevision") "profile.lastName",
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot") "profile.citizenId",
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1") "profile.position",
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2") "profile.avatar",
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3") "profile.avatarName",
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4") "profile.dateAppoint",
"posLevel.id",
"posLevel.posLevelName",
"posType.id",
"posType.posTypeName",
"current_holders.id",
"current_holders.posMasterNo",
"current_holders.orgRevisionId",
"current_holders.orgRootId",
"current_holders.orgChild1Id",
"current_holders.orgChild2Id",
"current_holders.orgChild3Id",
"current_holders.orgChild4Id",
"orgRoot.id",
"orgRoot.orgRootName",
"orgRoot.orgRootShortName",
"orgRoot.orgRootOrder",
"orgChild1.id",
"orgChild1.orgChild1Name",
"orgChild1.orgChild1ShortName",
"orgChild1.orgChild1Order",
"orgChild2.id",
"orgChild2.orgChild2Name",
"orgChild2.orgChild2ShortName",
"orgChild2.orgChild2Order",
"orgChild3.id",
"orgChild3.orgChild3Name",
"orgChild3.orgChild3ShortName",
"orgChild3.orgChild3Order",
"orgChild4.id",
"orgChild4.orgChild4Name",
"orgChild4.orgChild4ShortName",
"orgChild4.orgChild4Order",
])
.leftJoin("profile.posLevel", "posLevel")
.leftJoin("profile.posType", "posType")
.leftJoin("profile.current_holders", "current_holders")
.leftJoin("current_holders.orgRoot", "orgRoot")
.leftJoin("current_holders.orgChild1", "orgChild1")
.leftJoin("current_holders.orgChild2", "orgChild2")
.leftJoin("current_holders.orgChild3", "orgChild3")
.leftJoin("current_holders.orgChild4", "orgChild4")
.where(node && nodeId ? "current_holders.orgRevisionId = :orgRevisionId" : "1=1", { .where(node && nodeId ? "current_holders.orgRevisionId = :orgRevisionId" : "1=1", {
orgRevisionId: node && nodeId ? findRevision.id : undefined, orgRevisionId: node && nodeId ? findRevision.id : undefined,
}) })
.andWhere( // ...existing .andWhere เงื่อนไขเดิม...
_data.root != undefined && _data.root != null .andWhere(nodeCondition, { nodeId: nodeId })
? _data.root[0] != null
? `current_holders.orgRootId IN (:...root)`
: `current_holders.orgRootId is null`
: "1=1",
{
root: _data.root,
},
)
.andWhere(
_data.child1 != undefined && _data.child1 != null
? _data.child1[0] != null
? `current_holders.orgChild1Id IN (:...child1)`
: `current_holders.orgChild1Id is null`
: "1=1",
{
child1: _data.child1,
},
)
.andWhere(
_data.child2 != undefined && _data.child2 != null
? _data.child2[0] != null
? `current_holders.orgChild2Id IN (:...child2)`
: `current_holders.orgChild2Id is null`
: "1=1",
{
child2: _data.child2,
},
)
.andWhere(
_data.child3 != undefined && _data.child3 != null
? _data.child3[0] != null
? `current_holders.orgChild3Id IN (:...child3)`
: `current_holders.orgChild3Id is null`
: "1=1",
{
child3: _data.child3,
},
)
.andWhere(
_data.child4 != undefined && _data.child4 != null
? _data.child4[0] != null
? `current_holders.orgChild4Id IN (:...child4)`
: `current_holders.orgChild4Id is null`
: "1=1",
{
child4: _data.child4,
},
)
.andWhere(
posType != undefined && posType != null && posType != ""
? "posType.posTypeName LIKE :keyword1"
: "1=1",
{
keyword1: `${posType}`,
},
)
.andWhere(
posLevel != undefined && posLevel != null && posLevel != ""
? "posLevel.posLevelName LIKE :keyword2"
: "1=1",
{
keyword2: `${posLevel}`,
},
)
.andWhere(
isProbation != undefined && isProbation != null
? `profile.isProbation = ${isProbation}`
: "1=1",
)
.andWhere(
isRetire != undefined && isRetire != null
? isRetire == false
? // ? `profile.dateLeave IS NULL`
`profile.isLeave IS FALSE`
: isRetire == true && retireType != undefined && retireType != null
? // ? `profile.dateLeave IS NOT NULL AND profile.leaveType = '${retireType}'`
// : `profile.dateLeave IS NOT NULL`
`profile.isLeave IS TRUE AND profile.leaveType = '${retireType}'`
: `profile.isLeave IS TRUE`
: "1=1",
)
.andWhere(nodeCondition, {
nodeId: nodeId,
})
.andWhere( .andWhere(
new Brackets((qb) => { new Brackets((qb) => {
qb.orWhere( qb.orWhere(
@ -6233,8 +6193,6 @@ export class ProfileController extends Controller {
); );
}), }),
) )
// .orderBy("current_holders.posMasterNo", "ASC")
// .orderBy(`${sortBy}`, sort)
.addSelect("CASE WHEN current_holders.posMasterNo IS NULL THEN 1 ELSE 0 END", "sort_order") .addSelect("CASE WHEN current_holders.posMasterNo IS NULL THEN 1 ELSE 0 END", "sort_order")
.orderBy("sort_order", "ASC") .orderBy("sort_order", "ASC")
.addOrderBy("orgRoot.orgRootOrder", sort) .addOrderBy("orgRoot.orgRootOrder", sort)
@ -6247,91 +6205,9 @@ export class ProfileController extends Controller {
.take(pageSize) .take(pageSize)
.getManyAndCount(); .getManyAndCount();
const data = await Promise.all( // 2. map ข้อมูลแบบ flat ไม่ต้องวนซ้ำซ้อน
record.map((_data) => { const data = record.map((_data) => {
const posExecutive = // ...map เฉพาะ field ที่จำเป็น...
_data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.positions.length ==
0 ||
_data.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions.find((x: any) => x.positionIsSelected == true) == null ||
_data.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions.find((x: any) => x.positionIsSelected == true)?.posExecutive == null
? null
: _data.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions.find((x: any) => x.positionIsSelected == true)?.posExecutive
?.posExecutiveName;
const shortName =
_data.current_holders.length == 0
? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 !=
null
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName} ${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild3 != null
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName} ${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild2 != null
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName} ${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild1 != null
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName} ${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) !=
null &&
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgRoot != null
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName} ${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: null;
const root =
_data.current_holders.length == 0 ||
(_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null)
? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
const child1 =
_data.current_holders == null ||
_data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1;
const child2 =
_data.current_holders == null ||
_data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2;
const child3 =
_data.current_holders == null ||
_data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3;
const child4 =
_data.current_holders == null ||
_data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4;
let _root = root?.orgRootName;
let _child1 = child1?.orgChild1Name;
let _child2 = child2?.orgChild2Name;
let _child3 = child3?.orgChild3Name;
let _child4 = child4?.orgChild4Name;
return { return {
id: _data.id, id: _data.id,
avatar: _data.avatar, avatar: _data.avatar,
@ -6342,27 +6218,27 @@ export class ProfileController extends Controller {
firstName: _data.firstName, firstName: _data.firstName,
lastName: _data.lastName, lastName: _data.lastName,
citizenId: _data.citizenId, citizenId: _data.citizenId,
posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName, posLevel: _data.posLevel?.posLevelName ?? null,
posType: _data.posType == null ? null : _data.posType.posTypeName, posType: _data.posType?.posTypeName ?? null,
posLevelId: _data.posLevel == null ? null : _data.posLevel.id, posLevelId: _data.posLevel?.id ?? null,
posTypeId: _data.posType == null ? null : _data.posType.id, posTypeId: _data.posType?.id ?? null,
position: _data.position, position: _data.position,
posExecutive: posExecutive, posNo: _data.current_holders?.[0]?.posMasterNo ?? null,
posNo: shortName, rootId: _data.current_holders?.[0]?.orgRootId ?? null,
rootId: root == null ? null : root.id, root: _data.current_holders?.[0]?.orgRoot?.orgRootName ?? null,
root: root == null ? null : root.orgRootName, orgRootShortName: _data.current_holders?.[0]?.orgRoot?.orgRootShortName ?? null,
rootDnaId: root == null ? null : root.ancestorDNA, orgRevisionId: _data.current_holders?.[0]?.orgRevisionId ?? null,
orgRootShortName: root == null ? null : root.orgRootShortName, org: [
orgRevisionId: root == null ? null : root.orgRevisionId, _data.current_holders?.[0]?.orgChild4?.orgChild4Name,
org: _data.current_holders?.[0]?.orgChild3?.orgChild3Name,
(_child4 == null ? "" : _child4 + "\n") + _data.current_holders?.[0]?.orgChild2?.orgChild2Name,
(_child3 == null ? "" : _child3 + "\n") + _data.current_holders?.[0]?.orgChild1?.orgChild1Name,
(_child2 == null ? "" : _child2 + "\n") + _data.current_holders?.[0]?.orgRoot?.orgRootName ?? _data.current_holders?.[0]?.orgRoot,
(_child1 == null ? "" : _child1 + "\n") + ]
(_root == null ? "" : _root), .filter((name) => !!name)
.join("\n"),
}; };
}), });
);
return new HttpSuccess({ data: data, total }); return new HttpSuccess({ data: data, total });
} }