From 0d190479e2e9d3e790d5279a7e8d9c1d8d2a642f Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 6 Jan 2025 12:04:54 +0700 Subject: [PATCH 1/7] checkpoint --- src/controllers/ReportController.ts | 9 +++++++++ src/entities/Evaluation.ts | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 63a5328..5b1fd4c 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -59,6 +59,15 @@ export class ReoportController { */ @Get() async sumaryEvaluationReport(@Query("year") year?: string, @Query("rootid") rootId?: string) { + + const yearInAD = year?year:null; + + const evaluation = await AppDataSource.getRepository(Evaluation) + .createQueryBuilder("evaluation") + .where( yearInAD && yearInAD != null? 'YEAR(createdAt) = :year': "1=1", { year: yearInAD }) + .andWhere(rootId?'orgRootId = :rootId': "1=1", { rootId: rootId }) + .getMany(); + return new HttpSuccess({ template: "summary-evaluation", reportName: "xlsx-report", diff --git a/src/entities/Evaluation.ts b/src/entities/Evaluation.ts index 5aa0945..5c5f12d 100644 --- a/src/entities/Evaluation.ts +++ b/src/entities/Evaluation.ts @@ -33,6 +33,12 @@ export class Evaluation extends EntityBase { @Column({ nullable: true, comment: "สังกัด" }) oc: string; + @Column({ nullable: true, comment: "สำนักงานที่สังกัด" }) + root: string; + + @Column({ nullable: true, length: 255, comment: "ไอดีสำนักงานที่สังกัด" }) + orgRootId: string; + @Column({ nullable: true, comment: "root", @@ -294,6 +300,12 @@ export class CreateEvaluation { @Column() assessments?: CreateAssessment[]; + + @Column() + root?: string | null; + + @Column() + orgRootId?: string | null; } export class CreateEducation { From 72e3e66afe54fef62005f793a64e2216752f4844 Mon Sep 17 00:00:00 2001 From: "DESKTOP-2S5P7D1\\Windows 10" Date: Mon, 6 Jan 2025 12:13:26 +0700 Subject: [PATCH 2/7] migrate --- .../1736140332359-update_eva_add_root.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/migration/1736140332359-update_eva_add_root.ts diff --git a/src/migration/1736140332359-update_eva_add_root.ts b/src/migration/1736140332359-update_eva_add_root.ts new file mode 100644 index 0000000..434ad04 --- /dev/null +++ b/src/migration/1736140332359-update_eva_add_root.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateEvaAddRoot1736140332359 implements MigrationInterface { + name = 'UpdateEvaAddRoot1736140332359' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`evaluation\` ADD \`root\` varchar(255) NULL COMMENT 'สำนักงานที่สังกัด'`); + await queryRunner.query(`ALTER TABLE \`evaluation\` ADD \`orgRootId\` varchar(255) NULL COMMENT 'ไอดีสำนักงานที่สังกัด'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`evaluation\` DROP COLUMN \`orgRootId\``); + await queryRunner.query(`ALTER TABLE \`evaluation\` DROP COLUMN \`root\``); + } + +} From 8b01454d0a0b70c8a7d253618a24132ce225e458 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 6 Jan 2025 14:41:25 +0700 Subject: [PATCH 3/7] #984(3) --- src/controllers/EvaluationController.ts | 2 + src/controllers/ReportController.ts | 51 ++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/controllers/EvaluationController.ts b/src/controllers/EvaluationController.ts index ce954d7..de25b31 100644 --- a/src/controllers/EvaluationController.ts +++ b/src/controllers/EvaluationController.ts @@ -331,6 +331,8 @@ export class EvaluationController { posNo: null, oc: null, salary: null, + root: null, + orgRootId: null, positionLevel: null, birthDate: null, govAge: null, diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 5b1fd4c..fab4290 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -64,14 +64,61 @@ export class ReoportController { const evaluation = await AppDataSource.getRepository(Evaluation) .createQueryBuilder("evaluation") - .where( yearInAD && yearInAD != null? 'YEAR(createdAt) = :year': "1=1", { year: yearInAD }) + .where('evaluation.evaluationResult NOT IN (:...evaluationResults)', { evaluationResults: ['PENDING'] }) + .andWhere( yearInAD && yearInAD != null? 'YEAR(createdAt) = :year': "1=1", { year: yearInAD }) .andWhere(rootId?'orgRootId = :rootId': "1=1", { rootId: rootId }) + .andWhere('evaluation.step = :step', { step: 'DONE' }) .getMany(); + const groupedData = evaluation.reduce((acc:any, item) => { + const key = item.root; + if (!acc[key]) { + acc[key] = { + agency: item.root && item.root != "" ? item.root: "-", + submitter: 0, + passCount: 0, + notPassCount: 0, + }; + } + if (item.evaluationResult === 'PASS') { + acc[key].passCount++; + } else if (item.evaluationResult === 'NOTPASS') { + acc[key].notPassCount++; + } + return acc; + }, {}); + + const result = Object.values(groupedData).map((item: any) => ({ + ...item , + submitter: Extension.ToThaiNumber((item.passCount + item.notPassCount).toString()), + passCount: Extension.ToThaiNumber(item.passCount.toString()), + notPassCount: Extension.ToThaiNumber(item.notPassCount.toString()), + })); + + const submitter = Object.values(groupedData).reduce((acc: number, item: any) => { + return acc + item.passCount + item.notPassCount; + }, 0); + + const sumPass = Object.values(groupedData).reduce((acc: number, item: any) => { + return acc + item.passCount; + }, 0); + + const sumNotPass = Object.values(groupedData).reduce((acc: number, item: any) => { + return acc + item.notPassCount; + }, 0); + return new HttpSuccess({ template: "summary-evaluation", reportName: "xlsx-report", - data: null, + data: { + year: year?Extension.ToThaiNumber(year.toString()):Extension.ToThaiNumber(new Date().getFullYear().toString()), + date: Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())), + mainAgency: rootId?result[0].root:"ทุกสำนักงานเขต", + list: result, + total: Extension.ToThaiNumber(submitter.toString()), + sumPass: Extension.ToThaiNumber(sumPass.toString()), + sumNotPass: Extension.ToThaiNumber(sumNotPass.toString()), + }, }); } From b3529b4b9c09d71256ff02e1d8d90d41ded87c9b Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 6 Jan 2025 14:49:31 +0700 Subject: [PATCH 4/7] fix --- src/controllers/ReportController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index fab4290..9dbf86e 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -113,7 +113,7 @@ export class ReoportController { data: { year: year?Extension.ToThaiNumber(year.toString()):Extension.ToThaiNumber(new Date().getFullYear().toString()), date: Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())), - mainAgency: rootId?result[0].root:"ทุกสำนักงานเขต", + mainAgency: rootId?result[0].agency:"ทุกสำนักงานเขต", list: result, total: Extension.ToThaiNumber(submitter.toString()), sumPass: Extension.ToThaiNumber(sumPass.toString()), From 6f5eb2455a891001ddc4bcddd353904f3909fc76 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 6 Jan 2025 15:05:36 +0700 Subject: [PATCH 5/7] fix year --- src/controllers/ReportController.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 9dbf86e..1d1ead2 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -61,11 +61,12 @@ export class ReoportController { async sumaryEvaluationReport(@Query("year") year?: string, @Query("rootid") rootId?: string) { const yearInAD = year?year:null; + const yearInBE = yearInAD ? (parseInt(yearInAD) - 543).toString() : null; const evaluation = await AppDataSource.getRepository(Evaluation) .createQueryBuilder("evaluation") .where('evaluation.evaluationResult NOT IN (:...evaluationResults)', { evaluationResults: ['PENDING'] }) - .andWhere( yearInAD && yearInAD != null? 'YEAR(createdAt) = :year': "1=1", { year: yearInAD }) + .andWhere( yearInBE && yearInBE != null? 'YEAR(createdAt) = :year': "1=1", { year: yearInBE }) .andWhere(rootId?'orgRootId = :rootId': "1=1", { rootId: rootId }) .andWhere('evaluation.step = :step', { step: 'DONE' }) .getMany(); From 38a32f95503d7a89085d27b69edc9babe88c5fa3 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 6 Jan 2025 15:09:53 +0700 Subject: [PATCH 6/7] no message --- src/controllers/ReportController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 1d1ead2..5470421 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -114,7 +114,7 @@ export class ReoportController { data: { year: year?Extension.ToThaiNumber(year.toString()):Extension.ToThaiNumber(new Date().getFullYear().toString()), date: Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())), - mainAgency: rootId?result[0].agency:"ทุกสำนักงานเขต", + mainAgency: rootId && result.length > 0?result[0].agency:"ทุกสำนักงานเขต", list: result, total: Extension.ToThaiNumber(submitter.toString()), sumPass: Extension.ToThaiNumber(sumPass.toString()), From 69fc354e6713ac3b9a04d848171a203c121993fb Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 6 Jan 2025 16:19:16 +0700 Subject: [PATCH 7/7] add evarsult --- src/controllers/EvaluationController.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/controllers/EvaluationController.ts b/src/controllers/EvaluationController.ts index de25b31..24a13b7 100644 --- a/src/controllers/EvaluationController.ts +++ b/src/controllers/EvaluationController.ts @@ -2328,6 +2328,7 @@ export class EvaluationController { "commanderPositionDoc2", "commanderAboveFullnameDoc2", "commanderAbovePositionDoc2", + "evaluationResult", ], }); if (!evaluation) { @@ -2361,6 +2362,7 @@ export class EvaluationController { "commanderPositionDoc2", "commanderAboveFullnameDoc2", "commanderAbovePositionDoc2", + "evaluationResult", ], }); if (!evaluation) {