From 3f3ec27abdfa9f5155112b4a11464d041c04328e Mon Sep 17 00:00:00 2001 From: kittapath Date: Wed, 23 Oct 2024 00:31:00 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=AD=E0=B8=AD=E0=B8=81=E0=B8=84=E0=B8=B3?= =?UTF-8?q?=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 40 +++--- src/controllers/PosMasterActController.ts | 114 +++++++++++++++++- src/controllers/PositionController.ts | 2 +- src/controllers/ProfileController.ts | 108 ++++++++++++++++- src/controllers/ProfileEditController.ts | 1 + .../ProfileEditEmployeeController.ts | 1 + src/entities/PosMasterAct.ts | 7 ++ ...1729617727307-update_root_add_isdeputy1.ts | 14 +++ 8 files changed, 268 insertions(+), 19 deletions(-) create mode 100644 src/migration/1729617727307-update_root_add_isdeputy1.ts diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 31375858..f8e0176d 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -1329,10 +1329,10 @@ export class CommandController extends Controller { persons: { refId: string; profileId?: string | null; - citizenId: string; - prefix: string; - firstName: string; - lastName: string; + citizenId: string | null; + prefix: string | null; + firstName: string | null; + lastName: string | null; }[]; }, @Request() request: RequestWithUser, @@ -2704,6 +2704,14 @@ export class CommandController extends Controller { }[]; }, ) { + const posMasters = await this.posMasterActRepository.find({ + where: { id: In(body.refIds.map((x) => x.refId)) }, + }); + const data = posMasters.map((_data) => ({ + ..._data, + statusReport: "PENDING", + })); + await this.posMasterActRepository.save(data); return new HttpSuccess(); } @Post("command40/officer/report") @@ -2714,12 +2722,12 @@ export class CommandController extends Controller { refIds: string[]; }, ) { - // const profile = await this.profileEmployeeRepository.find({ where: { id: In(body.refIds) } }); - // const data = profile.map((_data) => ({ - // ..._data, - // statusTemp: "DONE", - // })); - // await this.profileEmployeeRepository.save(data); + const posMasters = await this.posMasterActRepository.find({ where: { id: In(body.refIds) } }); + const data = posMasters.map((_data) => ({ + ..._data, + statusReport: "REPORT", + })); + await this.posMasterActRepository.save(data); return new HttpSuccess(); } @Post("command40/officer/delete") @@ -2730,12 +2738,12 @@ export class CommandController extends Controller { refIds: string[]; }, ) { - // const profile = await this.profileEmployeeRepository.find({ where: { id: In(body.refIds) } }); - // const data = profile.map((_data) => ({ - // ..._data, - // statusTemp: "WAITTING", - // })); - // await this.profileEmployeeRepository.save(data); + const posMasters = await this.posMasterActRepository.find({ where: { id: In(body.refIds) } }); + const data = posMasters.map((_data) => ({ + ..._data, + statusReport: "PENDING", + })); + await this.posMasterActRepository.save(data); return new HttpSuccess(); } @Post("command40/officer/report/attachment") diff --git a/src/controllers/PosMasterActController.ts b/src/controllers/PosMasterActController.ts index 48c07468..6f2b7cc5 100644 --- a/src/controllers/PosMasterActController.ts +++ b/src/controllers/PosMasterActController.ts @@ -17,7 +17,7 @@ import HttpStatusCode from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { PosMasterAct } from "../entities/PosMasterAct"; import { PosMaster } from "../entities/PosMaster"; -import { LessThan, MoreThan } from "typeorm"; +import { Brackets, LessThan, MoreThan } from "typeorm"; import { OrgRevision } from "../entities/OrgRevision"; import Extension from "../interfaces/extension"; @@ -390,4 +390,116 @@ export class PosMasterActController extends Controller { ); return new HttpSuccess(data); } + + /** + * API รายชื่อตามกลุ่มในรักษาการแทน + * + * @summary รายชื่อตามกลุ่มในรักษาการแทน + * + */ + @Post("report/draft") + async reportDraft( + @Body() + body: { + type: string; + rootId: string; + }, + ) { + let conditionGroup = ""; + if (body.type.trim().toUpperCase() == "GROUP1.1") { + conditionGroup = + "(posType.posTypeName = 'ทั่วไป' AND posLevel.posLevelName = 'ชำนาญงาน') OR (posType.posTypeName = 'ทั่วไป' AND posLevel.posLevelName = 'ปฏิบัติงาน') OR (posType.posTypeName = 'วิชาการ' AND posLevel.posLevelName = 'ปฏิบัติการ') OR (posType.posTypeName = 'วิชาการ' AND posLevel.posLevelName = 'ชำนาญการ')"; + } else if (body.type.trim().toUpperCase() == "GROUP1.2") { + conditionGroup = + "(posType.posTypeName = 'ทั่วไป' AND posLevel.posLevelName = 'อาวุโส') OR (posType.posTypeName = 'วิชาการ' AND posLevel.posLevelName = 'ชำนาญการพิเศษ') OR (posType.posTypeName = 'อำนวยการ' AND posLevel.posLevelName = 'ต้น')"; + } else if (body.type.trim().toUpperCase() == "GROUP2") { + conditionGroup = + "(posType.posTypeName = 'ทั่วไป' AND posLevel.posLevelName = 'ทักษะพิเศษ') OR (posType.posTypeName = 'วิชาการ' AND posLevel.posLevelName = 'เชี่ยวชาญ') OR (posType.posTypeName = 'วิชาการ' AND posLevel.posLevelName = 'ทรงคุณวุฒิ') OR (posType.posTypeName = 'อำนวยการ' AND posLevel.posLevelName = 'สูง') OR (posType.posTypeName = 'บริหาร' AND posLevel.posLevelName = 'ต้น') OR (posType.posTypeName = 'บริหาร' AND posLevel.posLevelName = 'สูง')"; + } else { + throw new HttpError(HttpStatusCode.NOT_FOUND, "กลุ่มเป้าหมายไม่ถูกต้อง"); + } + + let posMaster = await AppDataSource.getRepository(PosMasterAct) + .createQueryBuilder("posMasterAct") + .leftJoinAndSelect("posMasterAct.posMasterChild", "posMasterChild") + .leftJoinAndSelect("posMasterChild.orgRoot", "orgRoot") + .leftJoinAndSelect("posMasterChild.orgChild1", "orgChild1") + .leftJoinAndSelect("posMasterChild.orgChild2", "orgChild2") + .leftJoinAndSelect("posMasterChild.orgChild3", "orgChild3") + .leftJoinAndSelect("posMasterChild.orgChild4", "orgChild4") + .leftJoinAndSelect("posMasterChild.current_holder", "current_holder") + .leftJoinAndSelect("posMasterChild.positions", "positions") + .leftJoinAndSelect("positions.posType", "posType") + .leftJoinAndSelect("positions.posLevel", "posLevel") + .leftJoinAndSelect("posMasterChild.orgRevision", "orgRevision") + .andWhere("posMasterChild.orgRootId LIKE :orgRootId", { + orgRootId: body.type.trim().toUpperCase() == "GROUP1.1" ? body.rootId : `%%`, + }) + .andWhere("posMasterAct.statusReport = :statusReport", { statusReport: "PENDING" }) + .andWhere("posMasterChild.current_holderId IS NOT NULL") + .andWhere("orgRevision.orgRevisionIsCurrent = :orgRevisionIsCurrent", { + orgRevisionIsCurrent: true, + }) + .andWhere("orgRevision.orgRevisionIsDraft = :orgRevisionIsDraft", { + orgRevisionIsDraft: false, + }) + .andWhere("positions.positionIsSelected = :isSelected", { isSelected: true }) + .andWhere( + new Brackets((qb) => { + qb.andWhere(conditionGroup); + }), + ) + .orderBy("posMasterChild.posMasterOrder", "ASC") + .select([ + "posMasterAct.id", + "posMasterChild.posMasterNo", + "positions.positionName", + "positions.positionIsSelected", + "posType.posTypeName", + "posLevel.posLevelName", + "orgRoot.orgRootShortName", + "orgChild1.orgChild1ShortName", + "orgChild2.orgChild2ShortName", + "orgChild3.orgChild3ShortName", + "orgChild4.orgChild4ShortName", + "current_holder.prefix", + "current_holder.firstName", + "current_holder.lastName", + "current_holder.id", + "current_holder.citizenId", + ]) + .getMany(); + const _posMaster = posMaster.map((x) => { + const posMasterNo = + x.posMasterChild.orgChild4 != null + ? `${x.posMasterChild.orgChild4.orgChild4ShortName}${x.posMasterChild.posMasterNo}` + : x.posMasterChild != null && x?.posMasterChild?.orgChild3 != null + ? `${x.posMasterChild.orgChild3.orgChild3ShortName}${x.posMasterChild.posMasterNo}` + : x.posMasterChild != null && x?.posMasterChild?.orgChild2 != null + ? `${x.posMasterChild.orgChild2.orgChild2ShortName}${x.posMasterChild.posMasterNo}` + : x.posMasterChild != null && x?.posMasterChild?.orgChild1 != null + ? `${x.posMasterChild.orgChild1.orgChild1ShortName}${x.posMasterChild.posMasterNo}` + : x.posMasterChild != null && x?.posMasterChild?.orgRoot != null + ? `${x.posMasterChild.orgRoot.orgRootShortName}${x.posMasterChild.posMasterNo}` + : null; + const position = + x.posMasterChild.positions.filter((x) => x.positionIsSelected == true).length > 0 + ? x.posMasterChild.positions.filter((x) => x.positionIsSelected == true)[0] + : null; + return { + id: x.id, + posMasterNo: posMasterNo, + positionName: position?.positionName || null, + posType: position?.posType?.posTypeName || null, + posLevel: position?.posLevel?.posLevelName || null, + profileId: x.posMasterChild?.current_holder?.id || null, + prefix: x.posMasterChild?.current_holder?.prefix || null, + firstName: x.posMasterChild?.current_holder?.firstName || null, + lastName: x.posMasterChild?.current_holder?.lastName || null, + citizenId: x.posMasterChild?.current_holder?.citizenId || null, + }; + }); + + return new HttpSuccess(_posMaster); + } } diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 6b09e1c0..f39c5090 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -4091,7 +4091,7 @@ export class PositionController extends Controller { .leftJoinAndSelect("positions.posLevel", "posLevel") .leftJoinAndSelect("posMaster.orgRevision", "orgRevision") .andWhere("posMaster.orgRootId LIKE :orgRootId", { - orgRootId: body.type.trim().toUpperCase() == "GROUP1" ? body.rootId : `%%`, + orgRootId: body.type.trim().toUpperCase() == "GROUP1.1" ? body.rootId : `%%`, }) .andWhere("posMaster.statusReport = :statusReport", { statusReport: "PENDING" }) .andWhere("posMaster.next_holderId IS NOT NULL") diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index ab0219d3..8163286f 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -26,7 +26,7 @@ import { ProfileHistory, CreateProfileAllFields, } from "../entities/Profile"; -import { Any, Brackets, IsNull, Like, Not } from "typeorm"; +import { Any, Brackets, In, IsNull, Like, Not } from "typeorm"; import { OrgRevision } from "../entities/OrgRevision"; import { PosMaster } from "../entities/PosMaster"; import { PosLevel } from "../entities/PosLevel"; @@ -1224,6 +1224,112 @@ export class ProfileController extends Controller { return new HttpSuccess({ caregiver, commander, chairman }); } + /** + * + * + */ + @Post("commander-director") + async getProfileCommanderDirector( + @Request() request: RequestWithUser, + @Body() body: { isDirector: boolean }, + ) { + const posMaster = await this.posMasterRepo.findOne({ + where: { + current_holder: { keycloak: request.user.sub }, + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + }, + }); + if (!posMaster) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลการครองตำแหน่ง"); + if (body.isDirector == true) { + const _posMaster = await this.posMasterRepo.find({ + where: { + orgRootId: posMaster.orgRootId || "", + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + isDirector: true, + current_holderId: Not(IsNull()), + }, + relations: ["current_holder", "current_holder.posLevel", "current_holder.posType"], + }); + const posMasterActs = await this.posMasterActRepository.find({ + where: { + posMasterId: In(_posMaster.map((x) => x.id)), + posMasterChild: { + current_holderId: Not(In(_posMaster.map((x) => x.current_holderId))), + }, + }, + relations: [ + "posMaster", + "posMaster.current_holder", + "posMasterChild", + "posMasterChild.current_holder", + "posMasterChild.current_holder.posLevel", + "posMasterChild.current_holder.posType", + ], + }); + let data = _posMaster.map((_data) => ({ + id: _data.current_holderId || null, + prefix: _data.current_holder?.prefix || "", + firstName: _data.current_holder?.firstName || "", + lastName: _data.current_holder?.lastName || "", + citizenId: _data.current_holder?.citizenId || "", + position: _data.current_holder?.position || "", + posLevel: + _data.current_holder?.posLevel == null + ? null + : _data.current_holder?.posLevel?.posLevelName || "", + posType: + _data.current_holder?.posType == null + ? null + : _data.current_holder?.posType?.posTypeName || "", + isDirector: _data.isDirector || false, + actFullName: null, + })); + posMasterActs.map((x) => { + let item: any = { + id: x.posMasterChild?.current_holderId || null, + prefix: x.posMasterChild?.current_holder?.prefix || "", + firstName: x.posMasterChild?.current_holder?.firstName || "", + lastName: x.posMasterChild?.current_holder?.lastName || "", + citizenId: x.posMasterChild?.current_holder?.citizenId || "", + position: x.posMasterChild?.current_holder?.position || "", + posLevel: x.posMasterChild?.current_holder?.posLevel?.posLevelName || "", + posType: x.posMasterChild?.current_holder?.posType?.posTypeName || "", + isDirector: x.posMasterChild?.isDirector || true, + actFullName: `${x.posMaster?.current_holder?.prefix || ""}${x.posMaster?.current_holder?.firstName || ""} ${x.posMaster?.current_holder?.lastName || ""}`, + }; + data.push(item); + }); + return new HttpSuccess(data); + } else { + const _posMaster = await this.posMasterRepo.find({ + where: { + orgRootId: posMaster.orgRootId || "", + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + current_holderId: Not(IsNull()), + }, + relations: ["current_holder", "current_holder.posLevel", "current_holder.posType"], + }); + let data = _posMaster.map((_data) => ({ + id: _data.current_holderId || null, + prefix: _data.current_holder?.prefix || "", + firstName: _data.current_holder?.firstName || "", + lastName: _data.current_holder?.lastName || "", + citizenId: _data.current_holder?.citizenId || "", + position: _data.current_holder?.position || "", + posLevel: + _data.current_holder?.posLevel == null + ? null + : _data.current_holder?.posLevel?.posLevelName || "", + posType: + _data.current_holder?.posType == null + ? null + : _data.current_holder?.posType?.posTypeName || "", + isDirector: _data.isDirector || false, + actFullName: null, + })); + return new HttpSuccess(data); + } + } /** * API เลือกผู้ประเมินสำหรับ User (ADMIN) diff --git a/src/controllers/ProfileEditController.ts b/src/controllers/ProfileEditController.ts index c30a23e9..c322d09d 100644 --- a/src/controllers/ProfileEditController.ts +++ b/src/controllers/ProfileEditController.ts @@ -167,6 +167,7 @@ export class ProfileEditController extends Controller { id: getProfileEdit.id, topic: getProfileEdit.topic, detail: getProfileEdit.detail, + citizenId: getProfileEdit?.profile?.citizenId ?? "", status: getProfileEdit.status, remark: getProfileEdit.remark, createdAt: getProfileEdit.createdAt, diff --git a/src/controllers/ProfileEditEmployeeController.ts b/src/controllers/ProfileEditEmployeeController.ts index 99356803..54dcad36 100644 --- a/src/controllers/ProfileEditEmployeeController.ts +++ b/src/controllers/ProfileEditEmployeeController.ts @@ -173,6 +173,7 @@ export class ProfileEditEmployeeController extends Controller { id: getProfileEdit.id, topic: getProfileEdit.topic, detail: getProfileEdit.detail, + citizenId: getProfileEdit?.profile?.citizenId ?? "", status: getProfileEdit.status, remark: getProfileEdit.remark, createdAt: getProfileEdit.createdAt, diff --git a/src/entities/PosMasterAct.ts b/src/entities/PosMasterAct.ts index c1955444..207d1e24 100644 --- a/src/entities/PosMasterAct.ts +++ b/src/entities/PosMasterAct.ts @@ -34,6 +34,13 @@ export class PosMasterAct extends EntityBase { @ManyToOne(() => PosMaster, (posMaster) => posMaster.posMasterActChilds) @JoinColumn({ name: "posMasterChildId" }) posMasterChild: PosMaster; + + @Column({ + comment: "สถานะออกคำสั่ง", + default: "PENDING", + length: 20, + }) + statusReport: string; } export class CreatePosMaster { diff --git a/src/migration/1729617727307-update_root_add_isdeputy1.ts b/src/migration/1729617727307-update_root_add_isdeputy1.ts new file mode 100644 index 00000000..66ce6102 --- /dev/null +++ b/src/migration/1729617727307-update_root_add_isdeputy1.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateRootAddIsdeputy11729617727307 implements MigrationInterface { + name = 'UpdateRootAddIsdeputy11729617727307' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`posMasterAct\` ADD \`statusReport\` varchar(20) NOT NULL COMMENT 'สถานะออกคำสั่ง' DEFAULT 'PENDING'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`posMasterAct\` DROP COLUMN \`statusReport\``); + } + +}