diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index 324f06ab..04603aae 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -836,9 +836,9 @@ export class KeycloakController extends Controller { @Request() request: { user: { sub: string; preferred_username: string } }, ) { const profiles = await this.profileRepo.find({ - // where: { - // citizenId: "3640500632315", - // }, + where: { + keycloak: IsNull(), + }, relations: ["roleKeycloaks"], }); @@ -872,7 +872,7 @@ export class KeycloakController extends Controller { if (!Array.isArray(list)) throw new Error("Failed. Cannot get role(s) data from the server."); const result = await addUserRoles( userId, - list.filter((v) => v.id == "f8619dc2-dc0d-4aab-957f-66bdf905e9d0"), + list.filter((v) => v.id == "8a1a0dc9-304c-4e5b-a90a-65f841048212"), ); if (!result) { @@ -882,7 +882,7 @@ export class KeycloakController extends Controller { _item.keycloak = userId; } const roleKeycloak = await this.roleKeycloakRepo.find({ - where: { id: "f8619dc2-dc0d-4aab-957f-66bdf905e9d0" }, + where: { id: "8a1a0dc9-304c-4e5b-a90a-65f841048212" }, }); if (_item) { _item.roleKeycloaks = Array.from(new Set([..._item.roleKeycloaks, ...roleKeycloak])); diff --git a/src/entities/view/viewCurrentTenureEmployee.ts b/src/entities/view/viewCurrentTenureEmployee.ts index de7cb1c6..a3860a3f 100644 --- a/src/entities/view/viewCurrentTenureEmployee.ts +++ b/src/entities/view/viewCurrentTenureEmployee.ts @@ -56,16 +56,18 @@ import { ViewColumn, ViewEntity } from "typeorm"; commandYear, remark, profileEmployeeId, - @group := IF(@prevPosition = positionName, @group, @group + 1) AS groupedId, - @prevPosition := positionName + LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign, + ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) - + ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId FROM - profileSalary, - (SELECT @group := 0, @prevPosition := NULL) AS vars + profileSalary WHERE commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) ORDER BY commandDateAffect ASC, commandDateSign ASC ) AS groupedPosition + WHERE + prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign GROUP BY profileEmployeeId, groupedId, positionName ) diff --git a/src/entities/view/viewCurrentTenureExcOfficer.ts b/src/entities/view/viewCurrentTenureExcOfficer.ts index eba8457f..8668a71c 100644 --- a/src/entities/view/viewCurrentTenureExcOfficer.ts +++ b/src/entities/view/viewCurrentTenureExcOfficer.ts @@ -2,27 +2,86 @@ import { ViewColumn, ViewEntity } from "typeorm"; @ViewEntity({ expression: ` + WITH resultData AS ( + SELECT + commandDateAffect, + positionName, + positionCee, + TIMESTAMPDIFF( + DAY, + LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff, + TIMESTAMPDIFF( + DAY, + LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years', + TIMESTAMPDIFF( + DAY, + LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months', + TIMESTAMPDIFF( + DAY, + LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days', + posNo, + positionExecutive, + positionType, + positionLevel, + orgRoot, + orgChild1, + orgChild2, + orgChild3, + orgChild4, + commandCode, + commandName, + commandNo, + commandYear, + remark, + profileId, + ROW_NUMBER() OVER (PARTITION BY profileId ORDER BY commandDateAffect ASC) AS orderNumber + FROM ( + SELECT + commandDateAffect, + commandDateSign, + positionName, + positionCee, + posNo, + positionExecutive, + positionType, + positionLevel, + orgRoot, + orgChild1, + orgChild2, + orgChild3, + orgChild4, + commandCode, + commandName, + commandNo, + commandYear, + remark, + profileId, + ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) - + ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId + FROM + profileSalary + WHERE + commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) AND + positionExecutive <> '' + ORDER BY + commandDateAffect ASC, commandDateSign ASC + ) AS groupedPositionExe + GROUP BY + groupedId, positionExecutive + ) SELECT - DATE(MIN(commandDateAffect)) AS commandDateAffect, - TIMESTAMPDIFF( - DAY, - LAG(MIN(commandDateAffect)) OVER (PARTITION BY profileId ORDER BY commandDateAffect, \`order\` ASC), MIN(commandDateAffect)) AS days_diff, - TIMESTAMPDIFF( - DAY, - LAG(MIN(commandDateAffect)) OVER (PARTITION BY profileId ORDER BY commandDateAffect, \`order\` ASC), MIN(commandDateAffect)) / 365.2524 AS 'Years', - TIMESTAMPDIFF( - DAY, - LAG(MIN(commandDateAffect)) OVER (PARTITION BY profileId ORDER BY commandDateAffect, \`order\` ASC), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months', - TIMESTAMPDIFF( - DAY, - LAG(MIN(commandDateAffect)) OVER (PARTITION BY profileId ORDER BY commandDateAffect, \`order\` ASC), MIN(commandDateAffect)) % 30.4375 AS 'Days', + commandDateAffect, positionName, positionCee, + days_diff, + Years, + Months, + Days, posNo, positionExecutive, positionType, positionLevel, - OrgRoot, + orgRoot, orgChild1, orgChild2, orgChild3, @@ -33,31 +92,24 @@ import { ViewColumn, ViewEntity } from "typeorm"; commandYear, remark, profileId, - ROW_NUMBER() OVER (PARTITION BY profileId ORDER BY commandDateAffect ASC) AS orderNumber - FROM - profileSalary - WHERE - commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) AND - positionExecutive <> '' AND - positionExecutive is not null - GROUP BY - profileId, positionExecutive + orderNumber + FROM resultData UNION ALL SELECT CURDATE() AS commandDateAffect, + NULL AS positionName, + NULL AS positionCee, TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff, TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years', TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months', - TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days', - NULL AS positionName, - NULL AS positionCee, + TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days', NULL AS posNo, NULL AS positionExecutive, NULL AS positionType, NULL AS positionLevel, - NULL AS OrgRoot, + NULL AS orgRoot, NULL AS orgChild1, NULL AS orgChild2, NULL AS orgChild3, @@ -66,21 +118,10 @@ import { ViewColumn, ViewEntity } from "typeorm"; NULL AS commandName, NULL AS commandNo, NULL AS commandYear, - 'Comparison with current date' AS remark, + NULL AS remark, profileId, NULL AS orderNumber - FROM - profileSalary - WHERE - commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) AND - positionExecutive <> '' AND - positionExecutive is not null - GROUP BY - profileId - - ORDER BY - profileId, - commandDateAffect ASC + FROM resultData `, }) export class viewCurrentTenureExcOfficer { diff --git a/src/entities/view/viewCurrentTenureLevelOfficer.ts b/src/entities/view/viewCurrentTenureLevelOfficer.ts index 1123cf03..783801e4 100644 --- a/src/entities/view/viewCurrentTenureLevelOfficer.ts +++ b/src/entities/view/viewCurrentTenureLevelOfficer.ts @@ -55,22 +55,21 @@ import { ViewColumn, ViewEntity } from "typeorm"; commandNo, commandYear, remark, - profileId/*, + profileId, LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign, - @group := IF(@prevPosition = positionName, @group, @group + 1) AS groupedId, - @prevPosition := positionName*/ + ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) - + ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId FROM - profileSalary/*, - (SELECT @group := 0, @prevPosition := NULL) AS vars*/ + profileSalary WHERE commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) ORDER BY commandDateAffect ASC, commandDateSign ASC ) AS groupedPosition - /*WHERE - prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign*/ + WHERE + prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign GROUP BY - profileId, /*groupedId,*/ positionName, positionCee, positionType, positionLevel + groupedId, positionName, positionCee, positionType, positionLevel ) SELECT commandDateAffect, diff --git a/src/entities/view/viewCurrentTenureOfficer.ts b/src/entities/view/viewCurrentTenureOfficer.ts index c7078c87..19a85cb8 100644 --- a/src/entities/view/viewCurrentTenureOfficer.ts +++ b/src/entities/view/viewCurrentTenureOfficer.ts @@ -56,16 +56,18 @@ import { ViewColumn, ViewEntity } from "typeorm"; commandYear, remark, profileId, - @group := IF(@prevPosition = positionName, @group, @group + 1) AS groupedId, - @prevPosition := positionName + LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign, + ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) - + ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId FROM - profileSalary, - (SELECT @group := 0, @prevPosition := NULL) AS vars + profileSalary WHERE commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) ORDER BY commandDateAffect ASC, commandDateSign ASC ) AS groupedPosition + WHERE + prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign GROUP BY profileId, groupedId, positionName )