From 935ec5dae263984bcf0ab2575e91f1bfffc5f86d Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 5 Mar 2025 18:14:40 +0700 Subject: [PATCH] update view --- src/entities/view/viewRegistryEmployee.ts | 28 +++++++++++++++++++-- src/entities/view/viewRegistryOfficer.ts | 30 +++++------------------ 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/entities/view/viewRegistryEmployee.ts b/src/entities/view/viewRegistryEmployee.ts index c27f869c..10d04c2d 100644 --- a/src/entities/view/viewRegistryEmployee.ts +++ b/src/entities/view/viewRegistryEmployee.ts @@ -51,7 +51,23 @@ import { ViewColumn, ViewEntity } from "typeorm"; FROM profileEducation ed WHERE ed.isUse IS TRUE ORDER BY ed.level ASC - ) + ), + PositionDate AS ( + SELECT + vcto.Years, + vcto.Months, + vcto.Days, + vcto.profileEmployeeId + FROM tenurePositionEmployee vcto + ), + PositionLevelDate AS ( + SELECT + vctlo.Years, + vctlo.Months, + vctlo.Days, + vctlo.profileEmployeeId + FROM tenureLevelEmployee vctlo + ) SELECT p.id as profileEmployeeId, p.citizenId, @@ -93,12 +109,20 @@ import { ViewColumn, ViewEntity } from "typeorm"; p.dateRetireLaw, p.birthdate, ed.degree, - TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age + TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age, + vcto.Years, + vcto.Months, + vcto.Days, + vctlo.Years AS levelYears, + vctlo.Months AS levelMonths, + vctlo.Days AS levelDays FROM profileEmployee p LEFT JOIN employeePosLevel posLevel ON p.posLevelId = posLevel.id LEFT JOIN employeePosType posType ON p.posTypeId = posType.id LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1 LEFT JOIN Education ed ON p.id = ed.profileEmployeeId AND ed.ed_number = 1 + LEFT JOIN PositionDate vcto ON p.id = vcto.profileEmployeeId + LEFT JOIN PositionLevelDate vctlo ON p.id = vctlo.profileEmployeeId `, }) export class viewRegistryEmployee { diff --git a/src/entities/view/viewRegistryOfficer.ts b/src/entities/view/viewRegistryOfficer.ts index b2595025..c411d0e2 100644 --- a/src/entities/view/viewRegistryOfficer.ts +++ b/src/entities/view/viewRegistryOfficer.ts @@ -61,30 +61,16 @@ import { ViewColumn, ViewEntity } from "typeorm"; vcto.Years, vcto.Months, vcto.Days, - vcto.profileId, - ROW_NUMBER() OVER (PARTITION BY vcto.profileId) AS vcto_number - FROM view_current_tenure_officer vcto - WHERE vcto.orderNumber Is Null - ), - PositionExcDate AS ( - SELECT - vctoExc.Years, - vctoExc.Months, - vctoExc.Days, - vctoExc.profileId, - ROW_NUMBER() OVER (PARTITION BY vctoExc.profileId) AS vctoExc_number - FROM view_current_tenure_exc_officer vctoExc - WHERE vctoExc.orderNumber Is Null + vcto.profileId + FROM tenurePositionOfficer vcto ), PositionLevelDate AS ( SELECT vctlo.Years, vctlo.Months, vctlo.Days, - vctlo.profileId, - ROW_NUMBER() OVER (PARTITION BY vctlo.profileId) AS vctlo_number - FROM view_current_tenure_level_officer vctlo - WHERE vctlo.orderNumber Is Null + vctlo.profileId + FROM tenureLevelOfficer vctlo ) SELECT p.id as profileId, @@ -131,9 +117,6 @@ import { ViewColumn, ViewEntity } from "typeorm"; vcto.Years, vcto.Months, vcto.Days, - vctoExc.Years AS posExecutiveYears, - vctoExc.Months AS posExecutiveMonths, - vctoExc.Days AS posExecutiveDays, vctlo.Years AS levelYears, vctlo.Months AS levelMonths, vctlo.Days AS levelDays @@ -142,9 +125,8 @@ import { ViewColumn, ViewEntity } from "typeorm"; LEFT JOIN posType ON p.posTypeId = posType.id LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1 LEFT JOIN Education ed ON p.id = ed.profileId AND ed.ed_number = 1 - LEFT JOIN PositionDate vcto ON p.id = vcto.profileId AND vcto.vcto_number = 1 - LEFT JOIN PositionExcDate vctoExc ON p.id = vctoExc.profileId AND vctoExc.vctoExc_number = 1 - LEFT JOIN PositionLevelDate vctlo ON p.id = vctlo.profileId AND vctlo.vctlo_number = 1 + LEFT JOIN PositionDate vcto ON p.id = vcto.profileId + LEFT JOIN PositionLevelDate vctlo ON p.id = vctlo.profileId `, }) export class viewRegistryOfficer {