diff --git a/src/controllers/WorkflowController.ts b/src/controllers/WorkflowController.ts index 766263a5..c9190cf9 100644 --- a/src/controllers/WorkflowController.ts +++ b/src/controllers/WorkflowController.ts @@ -1081,6 +1081,308 @@ export class WorkflowController extends Controller { return new HttpSuccess({ data: lists, total }); } } + /** + * + * + */ + @Put("commander-posexe/{type}") + async getProfilePlacementPosExe( + @Request() request: RequestWithUser, + @Path() type: string, + @Body() + body: { + isAct: boolean; + keyword: string; + page: number; + pageSize: number; + keycloakId?: string | null; + }, + ) { + let posMasterUser: PosMaster = new PosMaster(); + if (body.keycloakId) { + posMasterUser = (await this.posMasterRepo.findOne({ + where: { + orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + current_holder: { keycloak: body.keycloakId }, + }, + relations: ["current_holder", "current_holder.posType", "current_holder.posLevel"], + })) as PosMaster; + } else { + posMasterUser = (await this.posMasterRepo.findOne({ + where: { + orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + current_holder: { keycloak: request.user.sub }, + }, + relations: ["current_holder", "current_holder.posType", "current_holder.posLevel"], + })) as PosMaster; + } + + if (!posMasterUser || !posMasterUser.orgRootId) + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบตำแหน่งผู้ใช้งาน"); + + let condition: any = []; + + let conditionOfficer: any = { + isDirector: true, + isOfficer: true, + orgRevisionId: posMasterUser.orgRevisionId, + orgChild1Id: IsNull(), + }; + + if (type.trim().toUpperCase() == "OPERATE") { + condition.push({ + isDirector: true, + orgRootId: posMasterUser.orgRootId, + orgRevisionId: posMasterUser.orgRevisionId, + orgChild1Id: IsNull(), + }); + condition.push({ + isDirector: true, + orgRootId: posMasterUser.orgRootId, + orgRevisionId: posMasterUser.orgRevisionId, + orgChild1Id: posMasterUser.orgChild1Id, + orgChild2Id: IsNull(), + }); + condition.push({ + isDirector: true, + orgRootId: posMasterUser.orgRootId, + orgRevisionId: posMasterUser.orgRevisionId, + orgChild1Id: posMasterUser.orgChild1Id, + orgChild2Id: posMasterUser.orgChild2Id, + orgChild3Id: IsNull(), + }); + condition.push({ + isDirector: true, + orgRootId: posMasterUser.orgRootId, + orgRevisionId: posMasterUser.orgRevisionId, + orgChild1Id: posMasterUser.orgChild1Id, + orgChild2Id: posMasterUser.orgChild2Id, + orgChild3Id: posMasterUser.orgChild3Id, + orgChild4Id: IsNull(), + }); + condition.push({ + isDirector: true, + orgRootId: posMasterUser.orgRootId, + orgRevisionId: posMasterUser.orgRevisionId, + orgChild1Id: posMasterUser.orgChild1Id, + orgChild2Id: posMasterUser.orgChild2Id, + orgChild3Id: posMasterUser.orgChild3Id, + orgChild4Id: posMasterUser.orgChild4Id, + }); + } else { + condition = [ + { + isDirector: true, + orgRootId: posMasterUser.orgRootId, + orgRevisionId: posMasterUser.orgRevisionId, + }, + ]; + if ( + (posMasterUser.current_holder.posType.posTypeName == "ทั่วไป" && + posMasterUser.current_holder.posLevel.posLevelName == "ชำนาญงาน") || + (posMasterUser.current_holder.posType.posTypeName == "ทั่วไป" && + posMasterUser.current_holder.posLevel.posLevelName == "ปฏิบัติงาน") || + (posMasterUser.current_holder.posType.posTypeName == "วิชาการ" && + posMasterUser.current_holder.posLevel.posLevelName == "ปฏิบัติการ") || + (posMasterUser.current_holder.posType.posTypeName == "วิชาการ" && + posMasterUser.current_holder.posLevel.posLevelName == "ชำนาญการ") + ) { + condition = { + isDirector: true, + orgRootId: posMasterUser.orgRootId, + orgRevisionId: posMasterUser.orgRevisionId, + orgChild1Id: IsNull(), + orgChild2Id: IsNull(), + orgChild3Id: IsNull(), + orgChild4Id: IsNull(), + }; + } else if ( + (posMasterUser.current_holder.posType.posTypeName == "ทั่วไป" && + posMasterUser.current_holder.posLevel.posLevelName == "อาวุโส") || + (posMasterUser.current_holder.posType.posTypeName == "วิชาการ" && + posMasterUser.current_holder.posLevel.posLevelName == "ชำนาญการพิเศษ") || + (posMasterUser.current_holder.posType.posTypeName == "อำนวยการ" && + posMasterUser.current_holder.posLevel.posLevelName == "ต้น") + ) { + condition = { + isDirector: true, + isDeputy: true, + orgRevisionId: posMasterUser.orgRevisionId, + orgChild1Id: IsNull(), + orgChild2Id: IsNull(), + orgChild3Id: IsNull(), + orgChild4Id: IsNull(), + }; + } else { + } + } + + if (body.isAct == true) { + const [lists, total] = await AppDataSource.getRepository(viewDirectorActing) + .createQueryBuilder("viewDirectorActing") + .andWhere( + new Brackets((qb) => { + qb.orWhere(condition).orWhere(conditionOfficer); + }), + ) + .andWhere( + new Brackets((qb) => { + qb.orWhere( + body.keyword != null && body.keyword != "" + ? "CONCAT(viewDirectorActing.prefix,viewDirectorActing.firstName,' ',viewDirectorActing.lastName) LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "viewDirectorActing.citizenId LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "viewDirectorActing.position LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "viewDirectorActing.posLevel LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "viewDirectorActing.posType LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "viewDirectorActing.actFullName LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "viewDirectorActing.posNo LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "viewDirectorActing.posExecutiveName LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ); + }), + ) + .skip((body.page - 1) * body.pageSize) + .take(body.pageSize) + .getManyAndCount(); + lists.map((x) => ({ + ...x, + posExecutiveNameOrg: + x.posExecutiveName + + (x.orgChild4 ?? x.orgChild3 ?? x.orgChild2 ?? x.orgChild1 ?? x.orgRoot ?? ""), + })); + return new HttpSuccess({ data: lists, total }); + } else { + const [lists, total] = await AppDataSource.getRepository(viewDirector) + .createQueryBuilder("viewDirector") + .andWhere( + new Brackets((qb) => { + qb.orWhere(condition).orWhere(conditionOfficer); + }), + ) + .andWhere( + new Brackets((qb) => { + qb.orWhere( + body.keyword != null && body.keyword != "" + ? "CONCAT(viewDirector.prefix,viewDirector.firstName,' ',viewDirector.lastName) LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "viewDirector.citizenId LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "viewDirector.position LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "viewDirector.posLevel LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "viewDirector.posType LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "viewDirector.posNo LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "viewDirector.posExecutiveName LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ); + }), + ) + .skip((body.page - 1) * body.pageSize) + .take(body.pageSize) + .getManyAndCount(); + lists.map((x) => ({ + ...x, + posExecutiveNameOrg: + x.posExecutiveName + + (x.orgChild4 ?? x.orgChild3 ?? x.orgChild2 ?? x.orgChild1 ?? x.orgRoot ?? ""), + })); + return new HttpSuccess({ data: lists, total }); + } + } /** * API เช็ค สกจ diff --git a/src/entities/view/viewDirector.ts b/src/entities/view/viewDirector.ts index 0e756a2e..a13f9ebf 100644 --- a/src/entities/view/viewDirector.ts +++ b/src/entities/view/viewDirector.ts @@ -113,6 +113,16 @@ export class viewDirector { @ViewColumn() orgChild4Id: string; @ViewColumn() + orgRoot: string; + @ViewColumn() + orgChild1: string; + @ViewColumn() + orgChild2: string; + @ViewColumn() + orgChild3: string; + @ViewColumn() + orgChild4: string; + @ViewColumn() actFullNameId: string; @ViewColumn() actFullNameKeycloakId: string; diff --git a/src/entities/view/viewDirectorActing.ts b/src/entities/view/viewDirectorActing.ts index fb7eebde..bf99391b 100644 --- a/src/entities/view/viewDirectorActing.ts +++ b/src/entities/view/viewDirectorActing.ts @@ -99,6 +99,16 @@ export class viewDirectorActing { @ViewColumn() orgChild4Id: string; @ViewColumn() + orgRoot: string; + @ViewColumn() + orgChild1: string; + @ViewColumn() + orgChild2: string; + @ViewColumn() + orgChild3: string; + @ViewColumn() + orgChild4: string; + @ViewColumn() actFullNameId: string; @ViewColumn() actFullNameKeycloakId: string;