create user

This commit is contained in:
kittapath 2025-03-05 12:18:24 +07:00
parent 7b2773f557
commit a7e9f78dae
5 changed files with 105 additions and 61 deletions

View file

@ -836,9 +836,9 @@ export class KeycloakController extends Controller {
@Request() request: { user: { sub: string; preferred_username: string } }, @Request() request: { user: { sub: string; preferred_username: string } },
) { ) {
const profiles = await this.profileRepo.find({ const profiles = await this.profileRepo.find({
// where: { where: {
// citizenId: "3640500632315", keycloak: IsNull(),
// }, },
relations: ["roleKeycloaks"], 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."); if (!Array.isArray(list)) throw new Error("Failed. Cannot get role(s) data from the server.");
const result = await addUserRoles( const result = await addUserRoles(
userId, userId,
list.filter((v) => v.id == "f8619dc2-dc0d-4aab-957f-66bdf905e9d0"), list.filter((v) => v.id == "8a1a0dc9-304c-4e5b-a90a-65f841048212"),
); );
if (!result) { if (!result) {
@ -882,7 +882,7 @@ export class KeycloakController extends Controller {
_item.keycloak = userId; _item.keycloak = userId;
} }
const roleKeycloak = await this.roleKeycloakRepo.find({ const roleKeycloak = await this.roleKeycloakRepo.find({
where: { id: "f8619dc2-dc0d-4aab-957f-66bdf905e9d0" }, where: { id: "8a1a0dc9-304c-4e5b-a90a-65f841048212" },
}); });
if (_item) { if (_item) {
_item.roleKeycloaks = Array.from(new Set([..._item.roleKeycloaks, ...roleKeycloak])); _item.roleKeycloaks = Array.from(new Set([..._item.roleKeycloaks, ...roleKeycloak]));

View file

@ -56,16 +56,18 @@ import { ViewColumn, ViewEntity } from "typeorm";
commandYear, commandYear,
remark, remark,
profileEmployeeId, profileEmployeeId,
@group := IF(@prevPosition = positionName, @group, @group + 1) AS groupedId, LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign,
@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 FROM
profileSalary, profileSalary
(SELECT @group := 0, @prevPosition := NULL) AS vars
WHERE WHERE
commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16)
ORDER BY ORDER BY
commandDateAffect ASC, commandDateSign ASC commandDateAffect ASC, commandDateSign ASC
) AS groupedPosition ) AS groupedPosition
WHERE
prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign
GROUP BY GROUP BY
profileEmployeeId, groupedId, positionName profileEmployeeId, groupedId, positionName
) )

View file

@ -2,27 +2,86 @@ import { ViewColumn, ViewEntity } from "typeorm";
@ViewEntity({ @ViewEntity({
expression: ` 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 SELECT
DATE(MIN(commandDateAffect)) AS commandDateAffect, 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',
positionName, positionName,
positionCee, positionCee,
days_diff,
Years,
Months,
Days,
posNo, posNo,
positionExecutive, positionExecutive,
positionType, positionType,
positionLevel, positionLevel,
OrgRoot, orgRoot,
orgChild1, orgChild1,
orgChild2, orgChild2,
orgChild3, orgChild3,
@ -33,31 +92,24 @@ import { ViewColumn, ViewEntity } from "typeorm";
commandYear, commandYear,
remark, remark,
profileId, profileId,
ROW_NUMBER() OVER (PARTITION BY profileId ORDER BY commandDateAffect ASC) AS orderNumber orderNumber
FROM FROM resultData
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
UNION ALL UNION ALL
SELECT SELECT
CURDATE() AS commandDateAffect, CURDATE() AS commandDateAffect,
NULL AS positionName,
NULL AS positionCee,
TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff, TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff,
TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years', 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 % 12 AS 'Months',
TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days', TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days',
NULL AS positionName,
NULL AS positionCee,
NULL AS posNo, NULL AS posNo,
NULL AS positionExecutive, NULL AS positionExecutive,
NULL AS positionType, NULL AS positionType,
NULL AS positionLevel, NULL AS positionLevel,
NULL AS OrgRoot, NULL AS orgRoot,
NULL AS orgChild1, NULL AS orgChild1,
NULL AS orgChild2, NULL AS orgChild2,
NULL AS orgChild3, NULL AS orgChild3,
@ -66,21 +118,10 @@ import { ViewColumn, ViewEntity } from "typeorm";
NULL AS commandName, NULL AS commandName,
NULL AS commandNo, NULL AS commandNo,
NULL AS commandYear, NULL AS commandYear,
'Comparison with current date' AS remark, NULL AS remark,
profileId, profileId,
NULL AS orderNumber NULL AS orderNumber
FROM FROM resultData
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
`, `,
}) })
export class viewCurrentTenureExcOfficer { export class viewCurrentTenureExcOfficer {

View file

@ -55,22 +55,21 @@ import { ViewColumn, ViewEntity } from "typeorm";
commandNo, commandNo,
commandYear, commandYear,
remark, remark,
profileId/*, profileId,
LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign, LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign,
@group := IF(@prevPosition = positionName, @group, @group + 1) AS groupedId, ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) -
@prevPosition := positionName*/ ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId
FROM FROM
profileSalary/*, profileSalary
(SELECT @group := 0, @prevPosition := NULL) AS vars*/
WHERE WHERE
commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16)
ORDER BY ORDER BY
commandDateAffect ASC, commandDateSign ASC commandDateAffect ASC, commandDateSign ASC
) AS groupedPosition ) AS groupedPosition
/*WHERE WHERE
prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign*/ prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign
GROUP BY GROUP BY
profileId, /*groupedId,*/ positionName, positionCee, positionType, positionLevel groupedId, positionName, positionCee, positionType, positionLevel
) )
SELECT SELECT
commandDateAffect, commandDateAffect,

View file

@ -56,16 +56,18 @@ import { ViewColumn, ViewEntity } from "typeorm";
commandYear, commandYear,
remark, remark,
profileId, profileId,
@group := IF(@prevPosition = positionName, @group, @group + 1) AS groupedId, LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign,
@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 FROM
profileSalary, profileSalary
(SELECT @group := 0, @prevPosition := NULL) AS vars
WHERE WHERE
commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16)
ORDER BY ORDER BY
commandDateAffect ASC, commandDateSign ASC commandDateAffect ASC, commandDateSign ASC
) AS groupedPosition ) AS groupedPosition
WHERE
prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign
GROUP BY GROUP BY
profileId, groupedId, positionName profileId, groupedId, positionName
) )