From 53e19272d86459efb087dd5a959993d7ff177caf Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 5 Mar 2025 16:07:14 +0700 Subject: [PATCH 1/6] migrate --- src/entities/TenureLevelEmployee.ts | 88 +++++++++++++++++++ src/entities/TenureLevelOfficer.ts | 88 +++++++++++++++++++ src/entities/TenurePositionEmployee.ts | 71 +++++++++++++++ src/entities/TenurePositionOfficer.ts | 71 +++++++++++++++ .../1741164808500-addNewTable05032025.ts | 21 +++++ 5 files changed, 339 insertions(+) create mode 100644 src/entities/TenureLevelEmployee.ts create mode 100644 src/entities/TenureLevelOfficer.ts create mode 100644 src/entities/TenurePositionEmployee.ts create mode 100644 src/entities/TenurePositionOfficer.ts create mode 100644 src/migration/1741164808500-addNewTable05032025.ts diff --git a/src/entities/TenureLevelEmployee.ts b/src/entities/TenureLevelEmployee.ts new file mode 100644 index 00000000..36ae0176 --- /dev/null +++ b/src/entities/TenureLevelEmployee.ts @@ -0,0 +1,88 @@ +import { + Entity, + Column, + OneToMany, + JoinColumn, + ManyToOne, + Double, + ManyToMany, + JoinTable, +} from "typeorm"; +import { EntityBase } from "./base/Base"; + + +@Entity("tenureLevelEmployee") +export class TenureLevelEmployee extends EntityBase { + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง profileEmployee", + default: null, + }) + profileEmployeeId: string; + + @Column({ + nullable: true, + comment: "ระดับซี", + default: null, + length: 255, + }) + positionCee: string; + + @Column({ + nullable: true, + comment: "จำนวนวัน", + default: null, + }) + days_diff: number; + + @Column({ + nullable: true, + comment: "จำนวนปีดำรงตำแหน่งงปัจจุบัน", + default: null, + }) + Years: number; + + @Column({ + nullable: true, + comment: "จำนวนเดือนดำรงตำแหน่งงปัจจุบัน", + default: null, + }) + Months: number; + + @Column({ + nullable: true, + comment: "จำนวนวันดำรงตำแหน่งงปัจจุบัน", + default: null, + }) + Days: number; + + @Column({ + nullable: true, + comment: "ชื่อประเภทตำแหน่ง", + default: null, + length: 255, + }) + positionType: string; + + @Column({ + nullable: true, + comment: "ชื่อระดับตำแหน่ง", + default: null, + length: 255, + }) + positionLevel: string; +} + +export class CreateTenureLevelOfficer { + profileEmployeeId: string; + positionCee: string | null; + days_diff: number | null; + Years: number | null; + Months: number | null; + Days: number | null; + positionType: string | null; + positionLevel: string | null; +} + + diff --git a/src/entities/TenureLevelOfficer.ts b/src/entities/TenureLevelOfficer.ts new file mode 100644 index 00000000..d6df2399 --- /dev/null +++ b/src/entities/TenureLevelOfficer.ts @@ -0,0 +1,88 @@ +import { + Entity, + Column, + OneToMany, + JoinColumn, + ManyToOne, + Double, + ManyToMany, + JoinTable, +} from "typeorm"; +import { EntityBase } from "./base/Base"; + + +@Entity("tenureLevelOfficer") +export class TenureLevelOfficer extends EntityBase { + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง Profile", + default: null, + }) + profileId: string; + + @Column({ + nullable: true, + comment: "ระดับซี", + default: null, + length: 255, + }) + positionCee: string; + + @Column({ + nullable: true, + comment: "จำนวนวัน", + default: null, + }) + days_diff: number; + + @Column({ + nullable: true, + comment: "จำนวนปีดำรงตำแหน่งงปัจจุบัน", + default: null, + }) + Years: number; + + @Column({ + nullable: true, + comment: "จำนวนเดือนดำรงตำแหน่งงปัจจุบัน", + default: null, + }) + Months: number; + + @Column({ + nullable: true, + comment: "จำนวนวันดำรงตำแหน่งงปัจจุบัน", + default: null, + }) + Days: number; + + @Column({ + nullable: true, + comment: "ชื่อประเภทตำแหน่ง", + default: null, + length: 255, + }) + positionType: string; + + @Column({ + nullable: true, + comment: "ชื่อระดับตำแหน่ง", + default: null, + length: 255, + }) + positionLevel: string; +} + +export class CreateTenureLevelOfficer { + profileId: string; + positionCee: string | null; + days_diff: number | null; + Years: number | null; + Months: number | null; + Days: number | null; + positionType: string | null; + positionLevel: string | null; +} + + diff --git a/src/entities/TenurePositionEmployee.ts b/src/entities/TenurePositionEmployee.ts new file mode 100644 index 00000000..a246cbd0 --- /dev/null +++ b/src/entities/TenurePositionEmployee.ts @@ -0,0 +1,71 @@ +import { + Entity, + Column, + OneToMany, + JoinColumn, + ManyToOne, + Double, + ManyToMany, + JoinTable, +} from "typeorm"; +import { EntityBase } from "./base/Base"; + + +@Entity("tenurePositionEmployee") +export class TenurePositionEmployee extends EntityBase { + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง ProfileEmployee", + default: null, + }) + profileEmployeeId: string; + + @Column({ + nullable: true, + comment: "ชื่อตำแหน่ง", + default: null, + length: 255, + }) + positionName: string; + + @Column({ + nullable: true, + comment: "จำนวนวัน", + default: null, + }) + days_diff: number; + + @Column({ + nullable: true, + comment: "จำนวนปีดำรงตำแหน่งงปัจจุบัน", + default: null, + }) + Years: number; + + @Column({ + nullable: true, + comment: "จำนวนเดือนดำรงตำแหน่งงปัจจุบัน", + default: null, + }) + Months: number; + + @Column({ + nullable: true, + comment: "จำนวนวันดำรงตำแหน่งงปัจจุบัน", + default: null, + }) + Days: number; + +} + +export class CreateTenurePositionEmployee { + profileEmployeeId: string; + positionName: string | null; + days_diff: number | null; + Years: number | null; + Months: number | null; + Days: number | null; +} + + diff --git a/src/entities/TenurePositionOfficer.ts b/src/entities/TenurePositionOfficer.ts new file mode 100644 index 00000000..3d4efe43 --- /dev/null +++ b/src/entities/TenurePositionOfficer.ts @@ -0,0 +1,71 @@ +import { + Entity, + Column, + OneToMany, + JoinColumn, + ManyToOne, + Double, + ManyToMany, + JoinTable, +} from "typeorm"; +import { EntityBase } from "./base/Base"; + + +@Entity("tenurePositionOfficer") +export class TenurePositionOfficer extends EntityBase { + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง Profile", + default: null, + }) + profileId: string; + + @Column({ + nullable: true, + comment: "ชื่อตำแหน่ง", + default: null, + length: 255, + }) + positionName: string; + + @Column({ + nullable: true, + comment: "จำนวนวัน", + default: null, + }) + days_diff: number; + + @Column({ + nullable: true, + comment: "จำนวนปีดำรงตำแหน่งงปัจจุบัน", + default: null, + }) + Years: number; + + @Column({ + nullable: true, + comment: "จำนวนเดือนดำรงตำแหน่งงปัจจุบัน", + default: null, + }) + Months: number; + + @Column({ + nullable: true, + comment: "จำนวนวันดำรงตำแหน่งงปัจจุบัน", + default: null, + }) + Days: number; + +} + +export class CreateTenurePositionOfficer { + profileId: string; + positionName: string | null; + days_diff: number | null; + Years: number | null; + Months: number | null; + Days: number | null; +} + + diff --git a/src/migration/1741164808500-addNewTable05032025.ts b/src/migration/1741164808500-addNewTable05032025.ts new file mode 100644 index 00000000..3d7539ec --- /dev/null +++ b/src/migration/1741164808500-addNewTable05032025.ts @@ -0,0 +1,21 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddNewTable050320251741164808500 implements MigrationInterface { + name = 'AddNewTable050320251741164808500' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE \`tenurePositionEmployee\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileEmployee', \`positionName\` varchar(255) NULL COMMENT 'ชื่อตำแหน่ง', \`days_diff\` int NULL COMMENT 'จำนวนวัน', \`Years\` int NULL COMMENT 'จำนวนปีดำรงตำแหน่งงปัจจุบัน', \`Months\` int NULL COMMENT 'จำนวนเดือนดำรงตำแหน่งงปัจจุบัน', \`Days\` int NULL COMMENT 'จำนวนวันดำรงตำแหน่งงปัจจุบัน', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`tenurePositionOfficer\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`profileId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง Profile', \`positionName\` varchar(255) NULL COMMENT 'ชื่อตำแหน่ง', \`days_diff\` int NULL COMMENT 'จำนวนวัน', \`Years\` int NULL COMMENT 'จำนวนปีดำรงตำแหน่งงปัจจุบัน', \`Months\` int NULL COMMENT 'จำนวนเดือนดำรงตำแหน่งงปัจจุบัน', \`Days\` int NULL COMMENT 'จำนวนวันดำรงตำแหน่งงปัจจุบัน', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`tenureLevelEmployee\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง profileEmployee', \`positionCee\` varchar(255) NULL COMMENT 'ระดับซี', \`days_diff\` int NULL COMMENT 'จำนวนวัน', \`Years\` int NULL COMMENT 'จำนวนปีดำรงตำแหน่งงปัจจุบัน', \`Months\` int NULL COMMENT 'จำนวนเดือนดำรงตำแหน่งงปัจจุบัน', \`Days\` int NULL COMMENT 'จำนวนวันดำรงตำแหน่งงปัจจุบัน', \`positionType\` varchar(255) NULL COMMENT 'ชื่อประเภทตำแหน่ง', \`positionLevel\` varchar(255) NULL COMMENT 'ชื่อระดับตำแหน่ง', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`tenureLevelOfficer\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`profileId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง Profile', \`positionCee\` varchar(255) NULL COMMENT 'ระดับซี', \`days_diff\` int NULL COMMENT 'จำนวนวัน', \`Years\` int NULL COMMENT 'จำนวนปีดำรงตำแหน่งงปัจจุบัน', \`Months\` int NULL COMMENT 'จำนวนเดือนดำรงตำแหน่งงปัจจุบัน', \`Days\` int NULL COMMENT 'จำนวนวันดำรงตำแหน่งงปัจจุบัน', \`positionType\` varchar(255) NULL COMMENT 'ชื่อประเภทตำแหน่ง', \`positionLevel\` varchar(255) NULL COMMENT 'ชื่อระดับตำแหน่ง', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE \`tenureLevelOfficer\``); + await queryRunner.query(`DROP TABLE \`tenureLevelEmployee\``); + await queryRunner.query(`DROP TABLE \`tenurePositionOfficer\``); + await queryRunner.query(`DROP TABLE \`tenurePositionEmployee\``); + } + +} \ No newline at end of file From e605aea0eeb7564b5e2acb642ab9666cc1f8beb2 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 5 Mar 2025 16:44:45 +0700 Subject: [PATCH 2/6] add report filter1 --- src/controllers/ProfileController.ts | 46 +++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 12582e36..391fb4d5 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -31,7 +31,7 @@ import { UpdateProfileMother, UpdateProfileCouple, } from "../entities/Profile"; -import { Brackets, IsNull, Like, Not } from "typeorm"; +import { Brackets, In, IsNull, Like, Not } from "typeorm"; import { OrgRevision } from "../entities/OrgRevision"; import { PosMaster } from "../entities/PosMaster"; import { PosLevel } from "../entities/PosLevel"; @@ -1136,7 +1136,11 @@ export class ProfileController extends Controller { "amount", "remark", ], - where: { profileId: id }, + where: { + profileId: id, + commandCode: In(["5","6"]), + isEntry: false + }, order: { order: "ASC" }, }); @@ -1291,7 +1295,11 @@ export class ProfileController extends Controller { ]; const position_raw = await this.salaryRepo.find({ - where: { profileId: id }, + where: { + profileId: id, + commandCode: In(["1", "2", "3", "4", "8", "10", "11", "12", "15", "16"]), + isEntry: false + }, order: { order: "ASC" }, }); const positionList = @@ -1310,7 +1318,6 @@ export class ProfileController extends Controller { { commandDateAffect: "-", commandDateSign: "-", - refCommandNo: "-", posNo: "-", position: "-", posType: "-", @@ -1402,6 +1409,36 @@ export class ProfileController extends Controller { detail: "-", }, ]; + + const otherIncome_raw = await this.salaryRepo.find({ + where: { + profileId: id, + commandCode: "7", + isEntry: false + }, + order: { order: "ASC" }, + }); + const otherIncome = + otherIncome_raw.length > 0 + ? otherIncome_raw.map((item) => ({ + commandDateAffect: item.commandDateAffect?Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect)):"", + commandDateSign: item.commandDateSign?Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateSign)):"", + commandNo: item.commandNo?Extension.ToThaiNumber(item.commandNo):"", + position: item.positionName, + posLevel: item.positionLevel?Extension.ToThaiNumber(item.positionLevel):"", + amount: item.amount?Extension.ToThaiNumber(Number(item.amount).toLocaleString()):"", + })) + : [ + { + commandDateAffect: "-", + commandDateSign: "-", + commandNo: "-", + position: "-", + posLevel: "-", + amount: "-", + }, + ]; + const sum = profiles?Extension.ToThaiNumber((Number(profiles.amount) + Number(profiles.positionSalaryAmount) + Number(profiles.mouthSalaryAmount) + Number(profiles.amountSpecial)).toLocaleString()):""; const fullCurrentAddress = profiles?Extension.ToThaiNumber(profiles.currentAddress + " ตำบล/แขวง " + profiles.currentSubDistrict.name + " อำเภอ/เขต " + profiles.currentDistrict.name + " จังหวัด " + profiles.currentProvince.name + profiles.currentZipCode):""; const fullRegistrationAddress = profiles?Extension.ToThaiNumber(profiles.registrationAddress + " ตำบล/แขวง " + profiles.registrationSubDistrict.name + " อำเภอ/เขต " + profiles.registrationDistrict.name + " จังหวัด " + profiles.registrationProvince.name + profiles.registrationZipCode):""; @@ -1535,6 +1572,7 @@ export class ProfileController extends Controller { duty, assessments, profileAbility, + otherIncome }; return new HttpSuccess({ From cf03109db1201c340f615a6cd8a9b3f38bd8470e Mon Sep 17 00:00:00 2001 From: kittapath Date: Wed, 5 Mar 2025 16:58:11 +0700 Subject: [PATCH 3/6] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=A3?= =?UTF-8?q?=E0=B8=B2=E0=B8=A2=E0=B8=87=E0=B8=B2=E0=B8=99=E0=B9=81=E0=B8=9A?= =?UTF-8?q?=E0=B8=9A=E0=B8=A2=E0=B9=88=E0=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 46 ++++++++++-------- src/controllers/ProfileEmployeeController.ts | 48 +++++++++++-------- .../ProfileEmployeeTempController.ts | 48 +++++++++++-------- 3 files changed, 83 insertions(+), 59 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index a18aca6c..32da2951 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -236,23 +236,23 @@ export class ProfileController extends Controller { let _child4 = child4 == null || child4 == undefined ? "" : `${child4.orgChild4Name}/`; const salary_raw = await this.salaryRepo.find({ - select: [ - "commandDateAffect", - "positionName", - "posNo", - "positionType", - "positionLevel", - "positionSalaryAmount", - "commandNo", - "amount", - "remark", - "orgRoot", - "orgChild1", - "orgChild2", - "orgChild3", - "orgChild4", - "positionExecutive", - ], + // select: [ + // "commandDateAffect", + // "positionName", + // "posNo", + // "positionType", + // "positionLevel", + // "positionSalaryAmount", + // "commandNo", + // "amount", + // "remark", + // "orgRoot", + // "orgChild1", + // "orgChild2", + // "orgChild3", + // "orgChild4", + // "positionExecutive", + // ], where: { profileId: id, commandCode: In(["1", "2", "3", "4", "8", "10", "11", "12", "15", "16"]), @@ -266,7 +266,11 @@ export class ProfileController extends Controller { date: item.commandDateAffect ? Extension.ToThaiNumber(Extension.ToThaiShortDate(item.commandDateAffect)) : null, - position: item.positionName != null ? item.positionName : "-", + position: Extension.ToThaiNumber( + Extension.ToThaiNumber( + `${item.positionName != null ? item.positionName : "-"} ${item.positionType == null ? item.positionCee : (item.positionType == "อำนวยการ" || item.positionType == "บริหาร" ? item.positionType : "") + item.positionLevel}`, + ), + ), posNo: item.posNo != null ? Extension.ToThaiNumber(item.posNo) : null, orgRoot: item.orgRoot, orgChild1: item.orgChild1, @@ -349,7 +353,11 @@ export class ProfileController extends Controller { : "", position: salary_raw.length > 0 && salary_raw[0].positionName != null - ? Extension.ToThaiNumber(Extension.ToThaiNumber(salary_raw[0].positionName)) + ? Extension.ToThaiNumber( + Extension.ToThaiNumber( + `${salary_raw[0].positionName != null ? salary_raw[0].positionName : "-"} ${salary_raw[0].positionType == null ? salary_raw[0].positionCee : (salary_raw[0].positionType == "อำนวยการ" || salary_raw[0].positionType == "บริหาร" ? salary_raw[0].positionType : "") + salary_raw[0].positionLevel}`, + ), + ) : "", positionCee: salary_raw.length > 0 && salary_raw[0].positionCee != null diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index e1a1f707..c54ad861 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -228,24 +228,24 @@ export class ProfileEmployeeController extends Controller { let _child4 = child4 == null || child4 == undefined ? "" : `${child4.orgChild4Name}/`; const salary_raw = await this.salaryRepo.find({ - select: [ - "commandDateAffect", - "posNo", - "positionType", - "positionLevel", - "positionSalaryAmount", - "commandNo", - "amount", - "remark", - "positionName", - "orgRoot", - "orgChild1", - "orgChild2", - "orgChild3", - "orgChild4", - "positionCee", - "positionExecutive", - ], + // select: [ + // "commandDateAffect", + // "posNo", + // "positionType", + // "positionLevel", + // "positionSalaryAmount", + // "commandNo", + // "amount", + // "remark", + // "positionName", + // "orgRoot", + // "orgChild1", + // "orgChild2", + // "orgChild3", + // "orgChild4", + // "positionCee", + // "positionExecutive", + // ], where: { profileEmployeeId: id, commandCode: In(["1", "2", "3", "4", "8", "10", "11", "12", "15", "16"]), @@ -258,7 +258,11 @@ export class ProfileEmployeeController extends Controller { date: item.commandDateAffect ? Extension.ToThaiNumber(Extension.ToThaiShortDate(item.commandDateAffect)) : null, - position: item.positionName != null ? item.positionName : "-", + position: Extension.ToThaiNumber( + Extension.ToThaiNumber( + `${item.positionName != null ? item.positionName : "-"} ${item.positionType == null ? item.positionCee : (item.positionType == "อำนวยการ" || item.positionType == "บริหาร" ? item.positionType : "") + item.positionLevel}`, + ), + ), posNo: item.posNo != null ? Extension.ToThaiNumber(item.posNo) : null, orgRoot: item.orgRoot, orgChild1: item.orgChild1, @@ -341,7 +345,11 @@ export class ProfileEmployeeController extends Controller { : "", position: salary_raw.length > 0 && salary_raw[0].positionName != null - ? Extension.ToThaiNumber(Extension.ToThaiNumber(salary_raw[0].positionName)) + ? Extension.ToThaiNumber( + Extension.ToThaiNumber( + `${salary_raw[0].positionName != null ? salary_raw[0].positionName : "-"} ${salary_raw[0].positionType == null ? salary_raw[0].positionCee : (salary_raw[0].positionType == "อำนวยการ" || salary_raw[0].positionType == "บริหาร" ? salary_raw[0].positionType : "") + salary_raw[0].positionLevel}`, + ), + ) : "", positionCee: salary_raw.length > 0 && salary_raw[0].positionCee != null diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index eb090a7d..6d98310d 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -223,24 +223,24 @@ export class ProfileEmployeeTempController extends Controller { let _child4 = child4 == null || child4 == undefined ? "" : `${child4.orgChild4Name}/`; const salary_raw = await this.salaryRepo.find({ - select: [ - "commandDateAffect", - "positionName", - "posNo", - "positionType", - "positionLevel", - "positionSalaryAmount", - "commandNo", - "amount", - "remark", - "orgRoot", - "orgChild1", - "orgChild2", - "orgChild3", - "orgChild4", - "positionCee", - "positionExecutive", - ], + // select: [ + // "commandDateAffect", + // "positionName", + // "posNo", + // "positionType", + // "positionLevel", + // "positionSalaryAmount", + // "commandNo", + // "amount", + // "remark", + // "orgRoot", + // "orgChild1", + // "orgChild2", + // "orgChild3", + // "orgChild4", + // "positionCee", + // "positionExecutive", + // ], where: { profileEmployeeId: id, commandCode: In(["1", "2", "3", "4", "8", "10", "11", "12", "15", "16"]), @@ -253,7 +253,11 @@ export class ProfileEmployeeTempController extends Controller { date: item.commandDateAffect ? Extension.ToThaiNumber(Extension.ToThaiShortDate(item.commandDateAffect)) : null, - position: item.positionName != null ? item.positionName : "-", + position: Extension.ToThaiNumber( + Extension.ToThaiNumber( + `${item.positionName != null ? item.positionName : "-"} ${item.positionType == null ? item.positionCee : (item.positionType == "อำนวยการ" || item.positionType == "บริหาร" ? item.positionType : "") + item.positionLevel}`, + ), + ), posNo: item.posNo != null ? Extension.ToThaiNumber(item.posNo) : null, orgRoot: item.orgRoot, orgChild1: item.orgChild1, @@ -335,7 +339,11 @@ export class ProfileEmployeeTempController extends Controller { : "", position: salary_raw.length > 0 && salary_raw[0].positionName != null - ? Extension.ToThaiNumber(Extension.ToThaiNumber(salary_raw[0].positionName)) + ? Extension.ToThaiNumber( + Extension.ToThaiNumber( + `${salary_raw[0].positionName != null ? salary_raw[0].positionName : "-"} ${salary_raw[0].positionType == null ? salary_raw[0].positionCee : (salary_raw[0].positionType == "อำนวยการ" || salary_raw[0].positionType == "บริหาร" ? salary_raw[0].positionType : "") + salary_raw[0].positionLevel}`, + ), + ) : "", positionCee: salary_raw.length > 0 && salary_raw[0].positionCee != null From 01116aed740c93b0851854caf0948a7572796367 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 5 Mar 2025 17:01:38 +0700 Subject: [PATCH 4/6] webSocket --- src/app.ts | 106 +++++++++++++--------------- src/controllers/ReportController.ts | 29 ++++---- 2 files changed, 65 insertions(+), 70 deletions(-) diff --git a/src/app.ts b/src/app.ts index fe35775d..9ba50137 100644 --- a/src/app.ts +++ b/src/app.ts @@ -12,38 +12,25 @@ import { RegisterRoutes } from "./routes"; import { OrganizationController } from "./controllers/OrganizationController"; import logMiddleware from "./middlewares/logs"; import { CommandController } from "./controllers/CommandController"; -// import { WebSocketServer } from "ws"; -// import http from "http"; -// export const wss = new WebSocketServer({ noServer: true }); -// export const wss = new WebSocketServer({ -// port: 8080, -// perMessageDeflate: { -// zlibDeflateOptions: { -// // See zlib defaults. -// chunkSize: 1024, -// memLevel: 7, -// level: 3 -// }, -// zlibInflateOptions: { -// chunkSize: 10 * 1024 -// }, -// // Other options settable: -// clientNoContextTakeover: true, // Defaults to negotiated value. -// serverNoContextTakeover: true, // Defaults to negotiated value. -// serverMaxWindowBits: 10, // Defaults to negotiated value. -// // Below options specified as default values. -// concurrencyLimit: 10, // Limits zlib concurrency for perf. -// threshold: 1024 // Size (in bytes) below which messages -// // should not be compressed if context takeover is disabled. -// } -// }); +import { WebSocketServer } from "ws"; +import http from "http"; + +export const wss = new WebSocketServer({ noServer: true, + path: "/api/vi/org/socket", + }); async function main() { await AppDataSource.initialize(); const app = express(); - // const server = http.createServer(app); + // สร้างเซิร์ฟเวอร์ HTTP + const server = http.createServer(app); + + // socket.instance = new Server(server, { + // cors: { origin: "*" }, + // path: "/api/v1/org/socket", + // }); app.use( cors({ @@ -94,32 +81,15 @@ async function main() { } }); - // การจัดการคำขออัปเกรดจาก HTTP เป็น WebSocket - // server.on("upgrade", (request:any, socket:any, head:any) => { - // console.log("🔹 Handling upgrade request..."); - // wss.handleUpgrade(request, socket, head, (ws:any) => { - // console.log("🔹 WebSocket connection established"); - // wss.emit("connection", ws, request); - // }); - // }); - - // wss.on("connection", (ws:any) => { - // console.log("✅ Client connected to WebSocket"); - - // ws.on("close", () => { - // console.log("❌ Client disconnected"); - // }); - // }); - // app.listen(APP_PORT, APP_HOST, () => console.log(`Listening on: http://localhost:${APP_PORT}`)); - app.listen( - APP_PORT, - APP_HOST, - () => ( - console.log(`[APP] Application is running on: http://localhost:${APP_PORT}`), - console.log(`[APP] Swagger on: http://localhost:${APP_PORT}/api-docs`) - ), - ); + // app.listen( + // APP_PORT, + // APP_HOST, + // () => ( + // console.log(`[APP] Application is running on: http://localhost:${APP_PORT}`), + // console.log(`[APP] Swagger on: http://localhost:${APP_PORT}/api-docs`) + // ), + // ); async function runMessageQueue() { try { await rabbitmqInit(); @@ -131,13 +101,37 @@ async function main() { runMessageQueue(); - // สร้างเซิร์ฟเวอร์ HTTP + // การจัดการคำขออัปเกรดจาก HTTP เป็น WebSocket + server.on("upgrade", (request:any, socket:any, head:any) => { + console.log("🔹 Handling upgrade request..."); + wss.handleUpgrade(request, socket, head, (ws:any) => { + console.log("🔹 WebSocket connection established"); + wss.emit("connection", ws, request); + }); + }); + wss.on("connection", (ws:any) => { + console.log("✅ Client connected to WebSocket"); - // เริ่มเซิร์ฟเวอร์ที่พอร์ตปัจจุบัน - // server.listen(8080, () => { - // console.log("[APP] HTTP Server is listening on current port"); - // }); + ws.on("close", () => { + console.log("❌ Client disconnected"); + }); + + ws.on("error", (error:any) => { + console.error("WebSocket error:", error); + }); + }); + + // ตั้งค่า Express routes + app.get('/', (req, res) => { + res.send('Hello from Express!'); + }); + + server.listen(APP_PORT, APP_HOST, () => { + console.log(`[APP] Application is running on: http://${APP_HOST}:${APP_PORT}`); + console.log(`[APP] Swagger on: http://${APP_HOST}:${APP_PORT}/api-docs`); + console.log("[APP] HTTP Server is listening on current port"); + }); } diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index ade35489..08fc9bf7 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -31,8 +31,9 @@ import { Profile } from "../entities/Profile"; import { viewRegistryOfficer } from "../entities/view/viewRegistryOfficer"; import { viewRegistryEmployee } from "../entities/view/viewRegistryEmployee"; import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster"; -// import { WebSocket } from "ws"; -// import { wss } from "../app"; + +import { WebSocket } from "ws"; +import { wss } from "../app"; @Route("api/v1/org/report") @Tags("Report") @@ -3565,19 +3566,19 @@ export class ReportController extends Controller { } // console.log(">>",data); - // wss.clients.forEach((client: any) => { - // if (client.readyState === WebSocket.OPEN) { - // const message = JSON.stringify({ template: "report2", reportName: "report2", data: { data } }); - // console.log("📤 Sending data to client:", message); - // client.send(message, (err:any) => { - // if (err) { - // console.error("❌ Error sending message:", err); - // } - // }); - // } - // }); + wss.clients.forEach((client: any) => { + if (client.readyState === WebSocket.OPEN) { + const message = JSON.stringify({ template: "report2", reportName: "report2", data: { data } }); + console.log("📤 Sending data to client:", message); + client.send(message, (err:any) => { + if (err) { + console.error("❌ Error sending message:", err); + } + }); + } + }); - return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } }); + // return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } }); } /** From 74f20ee50c547067849a4f1551e242ff020f968c Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 5 Mar 2025 17:18:27 +0700 Subject: [PATCH 5/6] no message --- src/controllers/ProfileSalaryController.ts | 51 +++++++++++++++++++ .../1741164808500-addNewTable05032025.ts | 21 -------- 2 files changed, 51 insertions(+), 21 deletions(-) delete mode 100644 src/migration/1741164808500-addNewTable05032025.ts diff --git a/src/controllers/ProfileSalaryController.ts b/src/controllers/ProfileSalaryController.ts index 2407809b..2f69a0ca 100644 --- a/src/controllers/ProfileSalaryController.ts +++ b/src/controllers/ProfileSalaryController.ts @@ -22,6 +22,10 @@ import { Profile } from "../entities/Profile"; import { In, LessThan, MoreThan } from "typeorm"; import permission from "../interfaces/permission"; import { setLogDataDiff } from "../interfaces/utils"; +import { TenurePositionOfficer } from "../entities/TenurePositionOfficer"; +import { TenureLevelOfficer } from "../entities/TenureLevelOfficer"; +import { TenurePositionEmployee } from "../entities/TenurePositionEmployee"; +import { TenureLevelEmployee } from "../entities/TenureLevelEmployee"; @Route("api/v1/org/profile/salary") @Tags("ProfileSalary") @Security("bearerAuth") @@ -29,7 +33,54 @@ export class ProfileSalaryController extends Controller { private profileRepo = AppDataSource.getRepository(Profile); private salaryRepo = AppDataSource.getRepository(ProfileSalary); private salaryHistoryRepo = AppDataSource.getRepository(ProfileSalaryHistory); + private positionOfficerRepo = AppDataSource.getRepository(TenurePositionOfficer); + private levelOfficerRepo = AppDataSource.getRepository(TenureLevelOfficer); + // async cronjobTenurePositionOfficer() { + @Get("XXX") + public async cronjobTenurePositionOfficer() { + let data: any = []; + const profile = await this.profileRepo.find({where:{id: "09e89026-c420-4136-bd9e-7e408f530b69"}}) + await Promise.all( + profile.map(async (x) => { + const sql_mode = await AppDataSource.query( + "SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));", + ); + const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?)", [x.id]); + const _position = position.length > 0 ? position[0] : []; + const mapPosition = + _position.length > 1 + ? _position.slice(1) + .map((curr: any, index: number) => ({ + days_diff: curr.days_diff, + positionName: _position[index]?.positionName, + })) + : []; + const calDayDiff = mapPosition + .filter((curr: any) => curr.positionName == x.position) + .reduce( + (acc: any, curr: any) => { + acc.days_diff += Number(curr.days_diff) || 0; + return acc; + }, + { days_diff: 0} + ); + console.log("==========> ", calDayDiff) + const _mapData = { + profileId: x.id, + positionName: x.position, + days_diff: null, + Years: null, + Months: null, + Days: null, + } + data.push(_mapData); + }) + // await this.positionOfficerRepo.save(data); + ); + + return new HttpSuccess(); + } @Get("user") public async getSalaryUser(@Request() request: { user: Record }) { const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); diff --git a/src/migration/1741164808500-addNewTable05032025.ts b/src/migration/1741164808500-addNewTable05032025.ts deleted file mode 100644 index 3d7539ec..00000000 --- a/src/migration/1741164808500-addNewTable05032025.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class AddNewTable050320251741164808500 implements MigrationInterface { - name = 'AddNewTable050320251741164808500' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`CREATE TABLE \`tenurePositionEmployee\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileEmployee', \`positionName\` varchar(255) NULL COMMENT 'ชื่อตำแหน่ง', \`days_diff\` int NULL COMMENT 'จำนวนวัน', \`Years\` int NULL COMMENT 'จำนวนปีดำรงตำแหน่งงปัจจุบัน', \`Months\` int NULL COMMENT 'จำนวนเดือนดำรงตำแหน่งงปัจจุบัน', \`Days\` int NULL COMMENT 'จำนวนวันดำรงตำแหน่งงปัจจุบัน', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); - await queryRunner.query(`CREATE TABLE \`tenurePositionOfficer\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`profileId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง Profile', \`positionName\` varchar(255) NULL COMMENT 'ชื่อตำแหน่ง', \`days_diff\` int NULL COMMENT 'จำนวนวัน', \`Years\` int NULL COMMENT 'จำนวนปีดำรงตำแหน่งงปัจจุบัน', \`Months\` int NULL COMMENT 'จำนวนเดือนดำรงตำแหน่งงปัจจุบัน', \`Days\` int NULL COMMENT 'จำนวนวันดำรงตำแหน่งงปัจจุบัน', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); - await queryRunner.query(`CREATE TABLE \`tenureLevelEmployee\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง profileEmployee', \`positionCee\` varchar(255) NULL COMMENT 'ระดับซี', \`days_diff\` int NULL COMMENT 'จำนวนวัน', \`Years\` int NULL COMMENT 'จำนวนปีดำรงตำแหน่งงปัจจุบัน', \`Months\` int NULL COMMENT 'จำนวนเดือนดำรงตำแหน่งงปัจจุบัน', \`Days\` int NULL COMMENT 'จำนวนวันดำรงตำแหน่งงปัจจุบัน', \`positionType\` varchar(255) NULL COMMENT 'ชื่อประเภทตำแหน่ง', \`positionLevel\` varchar(255) NULL COMMENT 'ชื่อระดับตำแหน่ง', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); - await queryRunner.query(`CREATE TABLE \`tenureLevelOfficer\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`profileId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง Profile', \`positionCee\` varchar(255) NULL COMMENT 'ระดับซี', \`days_diff\` int NULL COMMENT 'จำนวนวัน', \`Years\` int NULL COMMENT 'จำนวนปีดำรงตำแหน่งงปัจจุบัน', \`Months\` int NULL COMMENT 'จำนวนเดือนดำรงตำแหน่งงปัจจุบัน', \`Days\` int NULL COMMENT 'จำนวนวันดำรงตำแหน่งงปัจจุบัน', \`positionType\` varchar(255) NULL COMMENT 'ชื่อประเภทตำแหน่ง', \`positionLevel\` varchar(255) NULL COMMENT 'ชื่อระดับตำแหน่ง', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); - - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`DROP TABLE \`tenureLevelOfficer\``); - await queryRunner.query(`DROP TABLE \`tenureLevelEmployee\``); - await queryRunner.query(`DROP TABLE \`tenurePositionOfficer\``); - await queryRunner.query(`DROP TABLE \`tenurePositionEmployee\``); - } - -} \ No newline at end of file From dd02c8100895d550cad6fa2f79462ce8456869c3 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 5 Mar 2025 17:29:07 +0700 Subject: [PATCH 6/6] reverse --- src/app.ts | 83 ++++++++++++++--------------- src/controllers/ReportController.ts | 28 +++++----- 2 files changed, 53 insertions(+), 58 deletions(-) diff --git a/src/app.ts b/src/app.ts index 9ba50137..6516b984 100644 --- a/src/app.ts +++ b/src/app.ts @@ -13,24 +13,19 @@ import { OrganizationController } from "./controllers/OrganizationController"; import logMiddleware from "./middlewares/logs"; import { CommandController } from "./controllers/CommandController"; -import { WebSocketServer } from "ws"; -import http from "http"; +// import { WebSocketServer } from "ws"; +// import http from "http"; -export const wss = new WebSocketServer({ noServer: true, - path: "/api/vi/org/socket", - }); +// export const wss = new WebSocketServer({ noServer: true, +// path: "/api/v1/org/socket", +// }); async function main() { await AppDataSource.initialize(); const app = express(); // สร้างเซิร์ฟเวอร์ HTTP - const server = http.createServer(app); - - // socket.instance = new Server(server, { - // cors: { origin: "*" }, - // path: "/api/v1/org/socket", - // }); + // const server = http.createServer(app); app.use( cors({ @@ -82,14 +77,14 @@ async function main() { }); // app.listen(APP_PORT, APP_HOST, () => console.log(`Listening on: http://localhost:${APP_PORT}`)); - // app.listen( - // APP_PORT, - // APP_HOST, - // () => ( - // console.log(`[APP] Application is running on: http://localhost:${APP_PORT}`), - // console.log(`[APP] Swagger on: http://localhost:${APP_PORT}/api-docs`) - // ), - // ); + app.listen( + APP_PORT, + APP_HOST, + () => ( + console.log(`[APP] Application is running on: http://localhost:${APP_PORT}`), + console.log(`[APP] Swagger on: http://localhost:${APP_PORT}/api-docs`) + ), + ); async function runMessageQueue() { try { await rabbitmqInit(); @@ -102,36 +97,36 @@ async function main() { runMessageQueue(); // การจัดการคำขออัปเกรดจาก HTTP เป็น WebSocket - server.on("upgrade", (request:any, socket:any, head:any) => { - console.log("🔹 Handling upgrade request..."); - wss.handleUpgrade(request, socket, head, (ws:any) => { - console.log("🔹 WebSocket connection established"); - wss.emit("connection", ws, request); - }); - }); + // server.on("upgrade", (request:any, socket:any, head:any) => { + // console.log("🔹 Handling upgrade request..."); + // wss.handleUpgrade(request, socket, head, (ws:any) => { + // console.log("🔹 WebSocket connection established"); + // wss.emit("connection", ws, request); + // }); + // }); - wss.on("connection", (ws:any) => { - console.log("✅ Client connected to WebSocket"); + // wss.on("connection", (ws:any) => { + // console.log("✅ Client connected to WebSocket"); - ws.on("close", () => { - console.log("❌ Client disconnected"); - }); + // ws.on("close", () => { + // console.log("❌ Client disconnected"); + // }); - ws.on("error", (error:any) => { - console.error("WebSocket error:", error); - }); - }); + // ws.on("error", (error:any) => { + // console.error("WebSocket error:", error); + // }); + // }); - // ตั้งค่า Express routes - app.get('/', (req, res) => { - res.send('Hello from Express!'); - }); + // // ตั้งค่า Express routes + // app.get('/', (req, res) => { + // res.send('Hello from Express!'); + // }); - server.listen(APP_PORT, APP_HOST, () => { - console.log(`[APP] Application is running on: http://${APP_HOST}:${APP_PORT}`); - console.log(`[APP] Swagger on: http://${APP_HOST}:${APP_PORT}/api-docs`); - console.log("[APP] HTTP Server is listening on current port"); - }); + // server.listen(APP_PORT, APP_HOST, () => { + // console.log(`[APP] Application is running on: http://${APP_HOST}:${APP_PORT}`); + // console.log(`[APP] Swagger on: http://${APP_HOST}:${APP_PORT}/api-docs`); + // console.log("[APP] HTTP Server is listening on current port"); + // }); } diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 08fc9bf7..75d50cc7 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -32,8 +32,8 @@ import { viewRegistryOfficer } from "../entities/view/viewRegistryOfficer"; import { viewRegistryEmployee } from "../entities/view/viewRegistryEmployee"; import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster"; -import { WebSocket } from "ws"; -import { wss } from "../app"; +// import { WebSocket } from "ws"; +// import { wss } from "../app"; @Route("api/v1/org/report") @Tags("Report") @@ -3566,19 +3566,19 @@ export class ReportController extends Controller { } // console.log(">>",data); - wss.clients.forEach((client: any) => { - if (client.readyState === WebSocket.OPEN) { - const message = JSON.stringify({ template: "report2", reportName: "report2", data: { data } }); - console.log("📤 Sending data to client:", message); - client.send(message, (err:any) => { - if (err) { - console.error("❌ Error sending message:", err); - } - }); - } - }); + // wss.clients.forEach((client: any) => { + // if (client.readyState === WebSocket.OPEN) { + // const message = JSON.stringify({ template: "report2", reportName: "report2", data: { data } }); + // console.log("📤 Sending data to client:", message); + // client.send(message, (err:any) => { + // if (err) { + // console.error("❌ Error sending message:", err); + // } + // }); + // } + // }); - // return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } }); + return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } }); } /**