update org position

This commit is contained in:
kittapath 2025-03-10 14:35:12 +07:00
parent a35e5fca50
commit 0b43d34fe3
2 changed files with 310 additions and 20 deletions

View file

@ -231,6 +231,22 @@ export class ProfileSalary extends EntityBase {
})
isEntry: boolean;
@Column({
nullable: true,
length: 255,
comment: "ด้านของตำแหน่ง",
default: null,
})
positionPathSide: string;
@Column({
nullable: true,
length: 255,
comment: "ตำแหน่งในสายงาน",
default: null,
})
positionLine: string;
@Column({
nullable: true,
length: 40,
@ -274,11 +290,11 @@ export class CreateProfileSalary {
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null;
orgRootName?: string | null;
orgChild1Name?: string | null;
orgChild2Name?: string | null;
orgChild3Name?: string | null;
orgChild4Name?: string | null;
orgRoot?: string | null;
orgChild1?: string | null;
orgChild2?: string | null;
orgChild3?: string | null;
orgChild4?: string | null;
remark: string | null;
commandId?: string | null;
isGovernment?: boolean | null;
@ -305,11 +321,11 @@ export class CreateProfileSalaryEmployee {
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null;
orgRootName?: string | null;
orgChild1Name?: string | null;
orgChild2Name?: string | null;
orgChild3Name?: string | null;
orgChild4Name?: string | null;
orgRoot?: string | null;
orgChild1?: string | null;
orgChild2?: string | null;
orgChild3?: string | null;
orgChild4?: string | null;
remark: string | null;
commandId?: string | null;
isGovernment?: boolean | null;
@ -335,11 +351,11 @@ export class UpdateProfileSalaryEmployee {
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null;
orgRootName?: string | null;
orgChild1Name?: string | null;
orgChild2Name?: string | null;
orgChild3Name?: string | null;
orgChild4Name?: string | null;
orgRoot?: string | null;
orgChild1?: string | null;
orgChild2?: string | null;
orgChild3?: string | null;
orgChild4?: string | null;
remark: string | null;
commandId?: string | null;
isGovernment?: boolean | null;
@ -365,11 +381,11 @@ export type UpdateProfileSalary = {
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null;
orgRootName?: string | null;
orgChild1Name?: string | null;
orgChild2Name?: string | null;
orgChild3Name?: string | null;
orgChild4Name?: string | null;
orgRoot?: string | null;
orgChild1?: string | null;
orgChild2?: string | null;
orgChild3?: string | null;
orgChild4?: string | null;
remark: string | null;
commandId?: string | null;
isGovernment?: boolean | null;

View file

@ -0,0 +1,274 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateprofileSalaryaddpositionPathSide1741591665901 implements MigrationInterface {
name = 'UpdateprofileSalaryaddpositionPathSide1741591665901'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`positionPathSide\` varchar(255) NULL COMMENT 'ด้านของตำแหน่ง'`);
await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`positionLine\` varchar(255) NULL COMMENT 'ตำแหน่งในสายงาน'`);
// await queryRunner.query(`ALTER TABLE \`profileDiscipline\` CHANGE \`createdAt\` \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6)`);
// await queryRunner.query(`ALTER TABLE \`profileDiscipline\` CHANGE \`lastUpdatedAt\` \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)`);
// await queryRunner.query(`CREATE VIEW \`view_current_tenure_officer\` AS
// 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,
// 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
// 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
// )
// SELECT
// commandDateAffect,
// positionName,
// positionCee,
// days_diff,
// Years,
// Months,
// Days,
// posNo,
// positionExecutive,
// positionType,
// positionLevel,
// OrgRoot,
// orgChild1,
// orgChild2,
// orgChild3,
// orgChild4,
// commandCode,
// commandName,
// commandNo,
// commandYear,
// remark,
// profileId,
// 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 posNo,
// NULL AS positionExecutive,
// NULL AS positionType,
// NULL AS positionLevel,
// NULL AS OrgRoot,
// NULL AS orgChild1,
// NULL AS orgChild2,
// NULL AS orgChild3,
// NULL AS orgChild4,
// NULL AS commandCode,
// NULL AS commandName,
// NULL AS commandNo,
// NULL AS commandYear,
// NULL AS remark,
// profileId,
// NULL AS orderNumber
// FROM resultData
// `);
// await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_current_tenure_officer","WITH resultData AS (\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days',\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n ROW_NUMBER() OVER (PARTITION BY profileId ORDER BY commandDateAffect ASC) AS orderNumber\n FROM (\n SELECT\n commandDateAffect,\n commandDateSign,\n positionName,\n positionCee,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign,\n ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) -\n ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId\n FROM\n profileSalary\n WHERE\n commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16)\n ORDER BY\n commandDateAffect ASC, commandDateSign ASC\n ) AS groupedPosition\n WHERE\n prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign\n GROUP BY\n profileId, groupedId, positionName\n )\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n days_diff,\n Years,\n Months,\n Days,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n orderNumber\n FROM resultData\n\n UNION ALL\n\n SELECT\n CURDATE() AS commandDateAffect,\n NULL AS positionName,\n NULL AS positionCee,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days',\n NULL AS posNo,\n NULL AS positionExecutive,\n NULL AS positionType,\n NULL AS positionLevel,\n NULL AS OrgRoot,\n NULL AS orgChild1,\n NULL AS orgChild2,\n NULL AS orgChild3,\n NULL AS orgChild4,\n NULL AS commandCode,\n NULL AS commandName,\n NULL AS commandNo,\n NULL AS commandYear,\n NULL AS remark,\n profileId,\n NULL AS orderNumber\n FROM resultData"]);
// await queryRunner.query(`CREATE VIEW \`view_current_tenure_employee\` AS
// 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,
// profileEmployeeId,
// ROW_NUMBER() OVER (PARTITION BY profileEmployeeId 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,
// profileEmployeeId,
// 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
// 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
// )
// SELECT
// commandDateAffect,
// positionName,
// positionCee,
// days_diff,
// Years,
// Months,
// Days,
// posNo,
// positionExecutive,
// positionType,
// positionLevel,
// OrgRoot,
// orgChild1,
// orgChild2,
// orgChild3,
// orgChild4,
// commandCode,
// commandName,
// commandNo,
// commandYear,
// remark,
// profileEmployeeId,
// 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 posNo,
// NULL AS positionExecutive,
// NULL AS positionType,
// NULL AS positionLevel,
// NULL AS OrgRoot,
// NULL AS orgChild1,
// NULL AS orgChild2,
// NULL AS orgChild3,
// NULL AS orgChild4,
// NULL AS commandCode,
// NULL AS commandName,
// NULL AS commandNo,
// NULL AS commandYear,
// NULL AS remark,
// profileEmployeeId,
// NULL AS orderNumber
// FROM resultData
// `);
// await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_current_tenure_employee","WITH resultData AS (\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days',\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileEmployeeId,\n ROW_NUMBER() OVER (PARTITION BY profileEmployeeId ORDER BY commandDateAffect ASC) AS orderNumber\n FROM (\n SELECT\n commandDateAffect,\n commandDateSign,\n positionName,\n positionCee,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileEmployeeId,\n LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign,\n ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) -\n ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId\n FROM\n profileSalary\n WHERE\n commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16)\n ORDER BY\n commandDateAffect ASC, commandDateSign ASC\n ) AS groupedPosition\n WHERE\n prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign\n GROUP BY\n profileEmployeeId, groupedId, positionName\n )\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n days_diff,\n Years,\n Months,\n Days,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileEmployeeId,\n orderNumber\n FROM resultData\n\n UNION ALL\n\n SELECT\n CURDATE() AS commandDateAffect,\n NULL AS positionName,\n NULL AS positionCee,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days',\n NULL AS posNo,\n NULL AS positionExecutive,\n NULL AS positionType,\n NULL AS positionLevel,\n NULL AS OrgRoot,\n NULL AS orgChild1,\n NULL AS orgChild2,\n NULL AS orgChild3,\n NULL AS orgChild4,\n NULL AS commandCode,\n NULL AS commandName,\n NULL AS commandNo,\n NULL AS commandYear,\n NULL AS remark,\n profileEmployeeId,\n NULL AS orderNumber\n FROM resultData"]);
}
public async down(queryRunner: QueryRunner): Promise<void> {
// await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_current_tenure_employee","bma_ehr_organization_demo"]);
// await queryRunner.query(`DROP VIEW \`view_current_tenure_employee\``);
// await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_current_tenure_officer","bma_ehr_organization_demo"]);
// await queryRunner.query(`DROP VIEW \`view_current_tenure_officer\``);
// await queryRunner.query(`ALTER TABLE \`profileDiscipline\` CHANGE \`lastUpdatedAt\` \`lastUpdatedAt\` datetime(6) NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)`);
// await queryRunner.query(`ALTER TABLE \`profileDiscipline\` CHANGE \`createdAt\` \`createdAt\` datetime(6) NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6)`);
await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`positionLine\``);
await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`positionPathSide\``);
}
}