From 47f7f4d55ea8d79d135973c4a098bd30f12e3f9a Mon Sep 17 00:00:00 2001 From: harid Date: Mon, 9 Feb 2026 17:50:53 +0700 Subject: [PATCH 1/4] optimize sort #2260 --- src/controllers/OrganizationController.ts | 233 +++++++++++++++------- 1 file changed, 166 insertions(+), 67 deletions(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index e9e4dc5d..39602bc7 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -7149,75 +7149,174 @@ export class OrganizationController extends Controller { */ @Get("root/search/sort") async searchSortRootLevelType(@Request() request: RequestWithUser) { - const root1 = await this.orgRootRepository.find({ - where: { - orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, - DEPARTMENT_CODE: Not("50"), - }, - order: { isDeputy: "DESC", orgRootOrder: "ASC" }, - select: ["orgRootName"], - }); - const root2 = await this.orgRootRepository.find({ - where: { - orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, - DEPARTMENT_CODE: "50", - }, - order: { orgRootName: "ASC" }, - select: ["orgRootName"], - }); - const root = [...root1, ...root2]; + // const root1 = await this.orgRootRepository.find({ + // where: { + // orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + // DEPARTMENT_CODE: Not("50"), + // }, + // order: { isDeputy: "DESC", orgRootOrder: "ASC" }, + // select: ["orgRootName"], + // }); + // const root2 = await this.orgRootRepository.find({ + // where: { + // orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + // DEPARTMENT_CODE: "50", + // }, + // order: { orgRootName: "ASC" }, + // select: ["orgRootName"], + // }); + // const root = [...root1, ...root2]; + + // const child1 = await this.child1Repository.find({ + // where: { + // orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + // }, + // order: { orgChild1Order: "ASC" }, + // select: ["orgChild1Name"], + // }); + // const child2 = await this.child2Repository.find({ + // where: { + // orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + // }, + // order: { orgChild2Order: "ASC" }, + // select: ["orgChild2Name"], + // }); + // const child3 = await this.child3Repository.find({ + // where: { + // orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + // }, + // order: { orgChild3Order: "ASC" }, + // select: ["orgChild3Name"], + // }); + // const child4 = await this.child4Repository.find({ + // where: { + // orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + // }, + // order: { orgChild4Order: "ASC" }, + // select: ["orgChild4Name"], + // }); + // const hospital = await this.child1Repository.find({ + // where: [ + // { + // orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + // orgRoot: { isDeputy: true }, + // }, + // { + // orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + // orgChild1RankSub: "HOSPITAL", + // }, + // ], + // select: ["orgChild1Name"], + // }); + // const posType = await this.posTypeRepository.find({ + // order: { posTypeRank: "DESC" }, + // select: ["posTypeName"], + // }); + // const posLevel = await this.posLevelRepository.find({ + // order: { posLevelRank: "DESC" }, + // select: ["posLevelName"], + // }); + + const [ + roots, + child1, + child2, + child3, + child4, + hospital, + posType, + posLevel, + ] = await Promise.all([ + + // ===== ROOT ===== + this.orgRootRepository + .createQueryBuilder("root") + .innerJoin("root.orgRevision", "rev") + .select([ + "root.orgRootName AS orgRootName", + ]) + .where("rev.orgRevisionIsDraft = false") + .andWhere("rev.orgRevisionIsCurrent = true") + .orderBy( + "CASE WHEN root.DEPARTMENT_CODE = '50' THEN 1 ELSE 0 END", + "ASC", + ) + .addOrderBy("root.isDeputy", "DESC") + .addOrderBy("root.orgRootOrder", "ASC") + .addOrderBy("root.orgRootName", "ASC") + .getRawMany(), + + // ===== CHILD 1 ===== + this.child1Repository + .createQueryBuilder("c1") + .innerJoin("c1.orgRevision", "rev") + .select("c1.orgChild1Name", "orgChild1Name") + .where("rev.orgRevisionIsDraft = false") + .andWhere("rev.orgRevisionIsCurrent = true") + .orderBy("c1.orgChild1Order", "ASC") + .getRawMany(), + + // ===== CHILD 2 ===== + this.child2Repository + .createQueryBuilder("c2") + .innerJoin("c2.orgRevision", "rev") + .select("c2.orgChild2Name", "orgChild2Name") + .where("rev.orgRevisionIsDraft = false") + .andWhere("rev.orgRevisionIsCurrent = true") + .orderBy("c2.orgChild2Order", "ASC") + .getRawMany(), + + // ===== CHILD 3 ===== + this.child3Repository + .createQueryBuilder("c3") + .innerJoin("c3.orgRevision", "rev") + .select("c3.orgChild3Name", "orgChild3Name") + .where("rev.orgRevisionIsDraft = false") + .andWhere("rev.orgRevisionIsCurrent = true") + .orderBy("c3.orgChild3Order", "ASC") + .getRawMany(), + + // ===== CHILD 4 ===== + this.child4Repository + .createQueryBuilder("c4") + .innerJoin("c4.orgRevision", "rev") + .select("c4.orgChild4Name", "orgChild4Name") + .where("rev.orgRevisionIsDraft = false") + .andWhere("rev.orgRevisionIsCurrent = true") + .orderBy("c4.orgChild4Order", "ASC") + .getRawMany(), + + // ===== HOSPITAL ===== + this.child1Repository + .createQueryBuilder("c1") + .innerJoin("c1.orgRevision", "rev") + .leftJoin("c1.orgRoot", "root") + .select("c1.orgChild1Name", "orgChild1Name") + .where("rev.orgRevisionIsDraft = false") + .andWhere("rev.orgRevisionIsCurrent = true") + .andWhere( + "(root.isDeputy = true OR c1.orgChild1RankSub = :rank)", + { rank: "HOSPITAL" }, + ) + .getRawMany(), + + // ===== POSITION TYPE ===== + this.posTypeRepository + .createQueryBuilder("pt") + .select("pt.posTypeName", "posTypeName") + .orderBy("pt.posTypeRank", "DESC") + .getRawMany(), + + // ===== POSITION LEVEL ===== + this.posLevelRepository + .createQueryBuilder("pl") + .select("pl.posLevelName", "posLevelName") + .orderBy("pl.posLevelRank", "DESC") + .getRawMany(), + ]); - const child1 = await this.child1Repository.find({ - where: { - orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, - }, - order: { orgChild1Order: "ASC" }, - select: ["orgChild1Name"], - }); - const child2 = await this.child2Repository.find({ - where: { - orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, - }, - order: { orgChild2Order: "ASC" }, - select: ["orgChild2Name"], - }); - const child3 = await this.child3Repository.find({ - where: { - orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, - }, - order: { orgChild3Order: "ASC" }, - select: ["orgChild3Name"], - }); - const child4 = await this.child4Repository.find({ - where: { - orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, - }, - order: { orgChild4Order: "ASC" }, - select: ["orgChild4Name"], - }); - const hospital = await this.child1Repository.find({ - where: [ - { - orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, - orgRoot: { isDeputy: true }, - }, - { - orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, - orgChild1RankSub: "HOSPITAL", - }, - ], - select: ["orgChild1Name"], - }); - const posType = await this.posTypeRepository.find({ - order: { posTypeRank: "DESC" }, - select: ["posTypeName"], - }); - const posLevel = await this.posLevelRepository.find({ - order: { posLevelRank: "DESC" }, - select: ["posLevelName"], - }); return new HttpSuccess({ - root: root.map((x) => x.orgRootName), + root: roots.map((x) => x.orgRootName), child1: child1.map((x) => x.orgChild1Name), child2: child2.map((x) => x.orgChild2Name), child3: child3.map((x) => x.orgChild3Name), From d6bb9be93d4565b759f4aa5770927f81a04dad55 Mon Sep 17 00:00:00 2001 From: harid Date: Tue, 10 Feb 2026 10:44:58 +0700 Subject: [PATCH 2/4] =?UTF-8?q?comment=20=E0=B8=AB=E0=B9=89=E0=B8=B2?= =?UTF-8?q?=E0=B8=A1=E0=B8=A5=E0=B8=9A=E0=B9=80=E0=B8=88=E0=B9=89=E0=B8=B2?= =?UTF-8?q?=E0=B8=AB=E0=B8=99=E0=B9=89=E0=B8=B2=E0=B8=97=E0=B8=B5=E0=B9=88?= =?UTF-8?q?=E0=B8=A5=E0=B8=B3=E0=B8=94=E0=B8=B1=E0=B8=9A=E0=B8=97=E0=B8=B5?= =?UTF-8?q?=E0=B9=88=201=20#2220?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandOperatorController.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/controllers/CommandOperatorController.ts b/src/controllers/CommandOperatorController.ts index f1cac92a..1a461ab3 100644 --- a/src/controllers/CommandOperatorController.ts +++ b/src/controllers/CommandOperatorController.ts @@ -187,13 +187,13 @@ export class CommandOperatorController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบเจ้าหน้าที่ดำเนินการ"); } - // 2. ห้ามลบ orderNo = 1 - if (operator.orderNo === 1) { - throw new HttpError( - HttpStatusCode.BAD_REQUEST, - "ไม่สามารถลบเจ้าหน้าที่ลำดับที่ 1 ได้" - ); - } + // // 2. ห้ามลบ orderNo = 1 + // if (operator.orderNo === 1) { + // throw new HttpError( + // HttpStatusCode.BAD_REQUEST, + // "ไม่สามารถลบเจ้าหน้าที่ลำดับที่ 1 ได้" + // ); + // } const removedOrderNo = operator.orderNo; From ecfb65e159301bf72c97c35531a78adbf4583ee5 Mon Sep 17 00:00:00 2001 From: harid Date: Tue, 10 Feb 2026 11:33:50 +0700 Subject: [PATCH 3/4] Fix Script #2292 --- src/controllers/ProfileSalaryTempController.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/ProfileSalaryTempController.ts b/src/controllers/ProfileSalaryTempController.ts index 6ea1713c..7835d4cf 100644 --- a/src/controllers/ProfileSalaryTempController.ts +++ b/src/controllers/ProfileSalaryTempController.ts @@ -1431,7 +1431,7 @@ export class ProfileSalaryTempController extends Controller { profileEmployeeId: x.profileEmployeeId, dateStart: x.commandDateAffect, dateEnd: null, - posNo: x.posNo, + posNo: `${x.posNoAbb} ${x.posNo}`, position: x.positionName, commandId: x.commandId, refCommandNo: x.commandNo, @@ -1455,7 +1455,7 @@ export class ProfileSalaryTempController extends Controller { dateEnd: null, commandId: x.commandId, commandNo: x.commandNo, - commandName: x.commandName, + commandName: x.commandName ?? "ให้ช่วยราชการ", refCommandDate: x.commandDateSign, refId: x.refId, status: "DONE", From 19d7799b5a23ac479e267cb8557ef484de63b04f Mon Sep 17 00:00:00 2001 From: harid Date: Tue, 10 Feb 2026 13:19:09 +0700 Subject: [PATCH 4/4] Fix Script #2292 --- src/controllers/ProfileSalaryTempController.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/ProfileSalaryTempController.ts b/src/controllers/ProfileSalaryTempController.ts index 7835d4cf..33d6a835 100644 --- a/src/controllers/ProfileSalaryTempController.ts +++ b/src/controllers/ProfileSalaryTempController.ts @@ -1434,7 +1434,7 @@ export class ProfileSalaryTempController extends Controller { posNo: `${x.posNoAbb} ${x.posNo}`, position: x.positionName, commandId: x.commandId, - refCommandNo: x.commandNo, + refCommandNo: `${x.commandNo}/${x.commandYear}`, refCommandDate: x.commandDateAffect, status: false, isDeleted: false, @@ -1454,7 +1454,7 @@ export class ProfileSalaryTempController extends Controller { dateStart: x.commandDateAffect, dateEnd: null, commandId: x.commandId, - commandNo: x.commandNo, + commandNo: `${x.commandNo}/${x.commandYear}`, commandName: x.commandName ?? "ให้ช่วยราชการ", refCommandDate: x.commandDateSign, refId: x.refId,