From 81288f8db30fe0770b891aad4adb088fa1bc0b3b Mon Sep 17 00:00:00 2001 From: harid Date: Fri, 6 Mar 2026 14:34:41 +0700 Subject: [PATCH] =?UTF-8?q?list=20=E0=B8=9B=E0=B8=A5=E0=B8=B1=E0=B8=94=20?= =?UTF-8?q?=E0=B9=81=E0=B8=A5=E0=B8=B0=E0=B8=A3=E0=B8=AD=E0=B8=87=E0=B8=9B?= =?UTF-8?q?=E0=B8=A5=E0=B8=B1=E0=B8=94=E0=B9=83=E0=B8=99=20popup=20?= =?UTF-8?q?=E0=B8=9C=E0=B8=B9=E0=B9=89=E0=B8=9A=E0=B8=B1=E0=B8=87=E0=B8=84?= =?UTF-8?q?=E0=B8=B1=E0=B8=9A=E0=B8=9A=E0=B8=B1=E0=B8=8D=E0=B8=8A=E0=B8=B2?= =?UTF-8?q?=20=E0=B9=81=E0=B8=A5=E0=B8=B0=E0=B8=9C=E0=B8=B9=E0=B9=89?= =?UTF-8?q?=E0=B8=A1=E0=B8=B5=E0=B8=AD=E0=B8=B3=E0=B8=99=E0=B8=B2=E0=B8=88?= =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 26 ++++++++++++++++++++++ src/controllers/WorkflowController.ts | 32 +++++++++++++++++++-------- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 5fbfa83b..a9436648 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -2998,12 +2998,35 @@ export class ProfileController extends Controller { // console.log(condition); // console.log("------------------"); // console.log(conditionNow); + + // Task #2342 list ปลัด และรองปลัดใน popup ผู้บังคับบัญชา และผู้มีอำนาจเพิ่ม + let conditionisDeputy: any = { + isDeputy: true, + isDirector: true, + orgChild1Id: IsNull(), + orgChild2Id: IsNull(), + orgChild3Id: IsNull(), + orgChild4Id: IsNull(), + id: Not(posMaster.current_holderId), + }; + const orgRoot = await this.orgRootRepo.findOne({ + select: { id: true, isDeputy: true }, + where: { + id: Not(posMaster.orgRootId ?? ""), + isDeputy: true, + orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + }, + }); + if (body.isAct == true) { const [lists, total] = await AppDataSource.getRepository(viewDirectorActing) .createQueryBuilder("viewDirectorActing") .andWhere( new Brackets((qb) => { qb.orWhere(condition).orWhere(conditionNow); + if (orgRoot && orgRoot.isDeputy) { + qb.orWhere(conditionisDeputy); + } }), ) .andWhere("viewDirectorActing.isProbation = :isProbation", { isProbation: false }) @@ -3069,6 +3092,9 @@ export class ProfileController extends Controller { .andWhere( new Brackets((qb) => { qb.orWhere(condition).orWhere(conditionNow); + if (orgRoot && orgRoot.isDeputy) { + qb.orWhere(conditionisDeputy); + } }), ) .andWhere("viewDirector.isProbation = :isProbation", { isProbation: false }) diff --git a/src/controllers/WorkflowController.ts b/src/controllers/WorkflowController.ts index d2438547..8e9d2cd4 100644 --- a/src/controllers/WorkflowController.ts +++ b/src/controllers/WorkflowController.ts @@ -22,7 +22,7 @@ import { viewDirectorActing } from "../entities/view/viewDirectorActing"; import { viewDirector } from "../entities/view/viewDirector"; import { ProfileEmployee } from "../entities/ProfileEmployee"; import { EmployeePosMaster } from "../entities/EmployeePosMaster"; - +import { OrgRoot } from "../entities/OrgRoot"; @Route("api/v1/org/workflow") @Tags("Workflow") @Security("bearerAuth") @@ -34,7 +34,7 @@ export class WorkflowController extends Controller { private stateUserCommentRepo = AppDataSource.getRepository(StateUserComment); private profileRepo = AppDataSource.getRepository(Profile); private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee); - + private orgRootRepo = AppDataSource.getRepository(OrgRoot); private metaWorkflowRepo = AppDataSource.getRepository(MetaWorkflow); private metaStateRepo = AppDataSource.getRepository(MetaState); private metaStateOperatorRepo = AppDataSource.getRepository(MetaStateOperator); @@ -898,6 +898,20 @@ export class WorkflowController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบตำแหน่งผู้ใช้งาน"); } + // Task #2342 list ปลัด และรองปลัดใน popup ผู้บังคับบัญชา และผู้มีอำนาจเพิ่ม + const roodIds = [posMasterUser.orgRootId]; + const orgRoot = await this.orgRootRepo.findOne({ + select: { id: true, isDeputy: true }, + where: { + id: Not(posMasterUser.orgRootId), + isDeputy: true, + orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + }, + }); + if (orgRoot && orgRoot.isDeputy) { + roodIds.push(orgRoot.id) + } + // 2. Pre-calculate conditions - ย้ายออกมาข้างนอก const posType = posMasterUser.current_holder?.posType?.posTypeName; const posLevel = posMasterUser.current_holder?.posLevel?.posLevelName; @@ -927,23 +941,23 @@ export class WorkflowController extends Controller { if (type.trim().toUpperCase() === "OPERATE" || body.type === "employee") { mainConditions = [ - { ...baseCondition, orgRootId: posMasterUser.orgRootId, orgChild1Id: IsNull() }, + { ...baseCondition, orgRootId: In(roodIds), orgChild1Id: IsNull() }, { ...baseCondition, - orgRootId: posMasterUser.orgRootId, + orgRootId: In(roodIds), orgChild1Id: posMasterUser.orgChild1Id, orgChild2Id: IsNull(), }, { ...baseCondition, - orgRootId: posMasterUser.orgRootId, + orgRootId: In(roodIds), orgChild1Id: posMasterUser.orgChild1Id, orgChild2Id: posMasterUser.orgChild2Id, orgChild3Id: IsNull(), }, { ...baseCondition, - orgRootId: posMasterUser.orgRootId, + orgRootId: In(roodIds), orgChild1Id: posMasterUser.orgChild1Id, orgChild2Id: posMasterUser.orgChild2Id, orgChild3Id: posMasterUser.orgChild3Id, @@ -951,7 +965,7 @@ export class WorkflowController extends Controller { }, { ...baseCondition, - orgRootId: posMasterUser.orgRootId, + orgRootId: In(roodIds), orgChild1Id: posMasterUser.orgChild1Id, orgChild2Id: posMasterUser.orgChild2Id, orgChild3Id: posMasterUser.orgChild3Id, @@ -962,7 +976,7 @@ export class WorkflowController extends Controller { mainConditions = [ { ...baseCondition, - orgRootId: posMasterUser.orgRootId, + orgRootId: In(roodIds), orgChild1Id: IsNull(), orgChild2Id: IsNull(), orgChild3Id: IsNull(), @@ -981,7 +995,7 @@ export class WorkflowController extends Controller { }, ]; } else { - mainConditions = [{ ...baseCondition, orgRootId: posMasterUser.orgRootId }]; + mainConditions = [{ ...baseCondition, orgRootId: In(roodIds) }]; } // 4. สร้าง optimized query builder