Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2025-03-11 16:13:34 +07:00
commit 5b814787d5
14 changed files with 1505 additions and 1174 deletions

View file

@ -14,13 +14,13 @@ import logMiddleware from "./middlewares/logs";
import { CommandController } from "./controllers/CommandController";
import { ProfileSalaryController } from "./controllers/ProfileSalaryController";
import { initWebSocket } from "./services/webSocket";
// import { initWebSocket } from "./services/webSocket";
async function main() {
await AppDataSource.initialize();
initWebSocket();
// initWebSocket();
const app = express();
app.use(
@ -104,8 +104,6 @@ async function main() {
}
runMessageQueue();
}
main();

View file

@ -1242,14 +1242,15 @@ export class ImportDataController extends Controller {
for (const _item of profiles) {
const existingProfile = await this.HR_EDUCATIONRepo.find({
where: { CIT: _item.citizenId },
select: [
"CIT",
"EDUCATION_CODE",
"START_EDUCATION_YEAR",
"EDUCATION_YEAR",
"INSTITUE",
"EDUCATION_SEQ",
],
// select: [
// "CIT",
// "EDUCATION_CODE",
// "START_EDUCATION_YEAR",
// "EDUCATION_YEAR",
// "INSTITUE",
// "EDUCATION_SEQ",
// ],
order: { EDUCATION_SEQ: "ASC" },
});
const educationLevel = await this.profileEducationRepo.findOne({
@ -1281,7 +1282,36 @@ export class ImportDataController extends Controller {
? Extension.ConvertToDateTimeV2(item.EDUCATION_YEAR)
: _null;
// endDate = endDate ? new Date(endDate, 0, 1) : _null;
if (item.FLAG_EDUCATION == "1") {
const checkData = await this.HR_EDUCATIONRepo.find({
where: { CIT: _item.citizenId, FLAG_EDUCATION: "1" },
order: { EDUCATION_SEQ: "DESC" },
});
if ((checkData.length > 1 && checkData[0].id == item.id) || checkData.length == 1) {
education.isEducation = true;
const findIsHigh = await this.HR_EDUCATIONRepo.findOne({
where: { CIT: _item.citizenId, FLAG_EDUCATION: "3" },
});
if (findIsHigh == null) {
education.isHigh = true;
}
}
} else if (item.FLAG_EDUCATION == "2") {
} else if (item.FLAG_EDUCATION == "3") {
const checkData = await this.HR_EDUCATIONRepo.find({
where: { CIT: _item.citizenId, FLAG_EDUCATION: "3" },
order: { EDUCATION_SEQ: "DESC" },
});
if ((checkData.length > 1 && checkData[0].id == item.id) || checkData.length == 1) {
education.isHigh = true;
const findIsEducation = await this.HR_EDUCATIONRepo.findOne({
where: { CIT: _item.citizenId, FLAG_EDUCATION: "1" },
});
if (findIsEducation == null) {
education.isEducation = true;
}
}
}
education.level = educationLevel == null ? 1 : educationLevel.level + 1;
education.profileId = _item.id;
education.degree = educationCode ? educationCode.EDUCATION_NAME : _null;

View file

@ -12,11 +12,10 @@ import {
Patch,
Put,
} from "tsoa";
import { Not } from "typeorm"
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
import {
ProfileEducation,
CreateProfileEducation,
@ -118,6 +117,18 @@ export class ProfileEducationsController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
if (body.isEducation) {
await this.profileEducationRepo.update(
{ profileId: body.profileId, isEducation: true },
{ isEducation: false }
);
}
if (body.isHigh) {
await this.profileEducationRepo.update(
{ profileId: body.profileId, isHigh: true },
{ isHigh: false }
);
}
const before = null;
const data = new ProfileEducation();
const meta = {
@ -157,6 +168,18 @@ export class ProfileEducationsController extends Controller {
const record = await this.profileEducationRepo.findOneBy({ id: educationId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
if (body.isEducation) {
await this.profileEducationRepo.update(
{ profileId: record.profileId, isEducation: true, id: Not(educationId) },
{ isEducation: false }
);
}
if (body.isHigh) {
await this.profileEducationRepo.update(
{ profileId: record.profileId, isHigh: true, id: Not(educationId) },
{ isHigh: false }
);
}
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileEducationHistory();

View file

@ -12,6 +12,7 @@ import {
Patch,
Put,
} from "tsoa";
import { Not } from "typeorm"
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
@ -124,6 +125,18 @@ export class ProfileEducationsEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
if (body.isEducation) {
await this.profileEducationRepo.update(
{ profileEmployeeId: body.profileEmployeeId, isEducation: true },
{ isEducation: false }
);
}
if (body.isHigh) {
await this.profileEducationRepo.update(
{ profileEmployeeId: body.profileEmployeeId, isHigh: true },
{ isHigh: false }
);
}
const before = null;
const data = new ProfileEducation();
const meta = {
@ -167,6 +180,18 @@ export class ProfileEducationsEmployeeController extends Controller {
"SYS_REGISTRY_EMP",
record.profileEmployeeId,
);
if (body.isEducation) {
await this.profileEducationRepo.update(
{ profileEmployeeId: record.profileEmployeeId, isEducation: true, id: Not(educationId) },
{ isEducation: false }
);
}
if (body.isHigh) {
await this.profileEducationRepo.update(
{ profileEmployeeId: record.profileEmployeeId, isHigh: true, id: Not(educationId) },
{ isHigh: false }
);
}
const before = structuredClone(record);
const before_null = null;
const history = new ProfileEducationHistory();

View file

@ -12,6 +12,7 @@ import {
Patch,
Put,
} from "tsoa";
import { Not } from "typeorm"
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
@ -114,6 +115,22 @@ export class ProfileEducationsEmployeeTempController extends Controller {
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
if (body.isEducation) {
await this.profileEducationRepo.update(
{ profileEmployeeId: body.profileEmployeeId, isEducation: true },
{ isEducation: false }
);
}
if (body.isHigh) {
const existing = await this.profileEducationRepo.find({
where: { profileId: body.profileEmployeeId, isHigh: true },
});
console.log("isHigh ",existing)
await this.profileEducationRepo.update(
{ profileEmployeeId: body.profileEmployeeId, isHigh: true },
{ isHigh: false }
);
}
const before = null;
const data = new ProfileEducation();
const meta = {
@ -153,6 +170,18 @@ export class ProfileEducationsEmployeeTempController extends Controller {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
const record = await this.profileEducationRepo.findOneBy({ id: educationId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
if (body.isEducation) {
await this.profileEducationRepo.update(
{ profileEmployeeId: record.profileEmployeeId, isEducation: true, id: Not(educationId) },
{ isEducation: false }
);
}
if (body.isHigh) {
await this.profileEducationRepo.update(
{ profileEmployeeId: record.profileEmployeeId, isHigh: true, id: Not(educationId) },
{ isHigh: false }
);
}
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileEducationHistory();

File diff suppressed because it is too large Load diff

View file

@ -34,9 +34,9 @@ export class MyCustomLogger implements Logger {
export const AppDataSource = new DataSource({
type: "mysql",
extra: {
timezone: "+07:00", // Bangkok timezone (UTC+7)
},
// extra: {
// timezone: "+07:00", // Bangkok timezone (UTC+7)
// },
database: process.env.DB_NAME,
host: process.env.DB_HOST,
port: +(process.env.DB_PORT || 3306),

View file

@ -66,4 +66,11 @@ export class HR_EDUCATION {
default: null,
})
MAJOR_CODE: string;
@Column({
nullable: true,
type: "text",
default: null,
})
FLAG_EDUCATION: string;
}

View file

@ -225,6 +225,7 @@ export class CreateProfileEducation {
positionPathId: string | null;
isDate: boolean | null;
isEducation: boolean | null;
isHigh?: boolean | null;
note: string | null;
}
@ -248,6 +249,7 @@ export class CreateProfileEducationEmployee {
positionPathId: string | null;
isDate: boolean | null;
isEducation: boolean | null;
isHigh?: boolean | null;
note: string | null;
}
@ -270,5 +272,6 @@ export type UpdateProfileEducation = {
positionPathId?: string | null;
isDate?: boolean | null;
isEducation?: boolean | null;
isHigh?: boolean | null;
note?: string | null;
};

View file

@ -144,6 +144,13 @@ export class ProfileEducationHistory extends EntityBase {
})
isEducation: boolean;
@Column({
nullable: true,
comment: "เป็นวุฒิศึกษาสูงสุด",
default: null,
})
isHigh: boolean;
@Column({
nullable: true,
comment: "หมายเหตุ",
@ -222,6 +229,9 @@ export class CreateProfileEducationHistory {
@Column()
isEducation: boolean | null;
@Column()
isHigh?: boolean | null;
@Column("uuid")
profileEducationId: string | null;

View file

@ -61,10 +61,12 @@ import { ViewColumn, ViewEntity } from "typeorm";
eds.educationLevel,
eds.isEducation,
eds.isHigh,
eds.profileEmployeeId
eds.profileEmployeeId,
eds.level
FROM profileEducation eds
) AS eds
GROUP BY eds.profileEmployeeId
ORDER BY eds.level DESC
),
EducationLevels AS (
SELECT

View file

@ -67,10 +67,12 @@ import { ViewColumn, ViewEntity } from "typeorm";
eds.educationLevel,
eds.isEducation,
eds.isHigh,
eds.profileId
eds.profileId,
eds.level
FROM profileEducation eds
) AS eds
GROUP BY eds.profileId
ORDER BY eds.level DESC
),
EducationLevels AS (
SELECT

View file

@ -0,0 +1,266 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateFieldIsHigh1741663507026 implements MigrationInterface {
name = 'UpdateFieldIsHigh1741663507026'
public async up(queryRunner: QueryRunner): Promise<void> {
// 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\``);
}
}

View file

@ -1,43 +1,43 @@
import { WebSocketServer } from "ws";
// import { WebSocketServer } from "ws";
let wss: WebSocketServer;
// let wss: WebSocketServer;
export function initWebSocket() {
wss = new WebSocketServer({ port: 13002, path: "/api/v1/org-socket" });
// export function initWebSocket() {
// wss = new WebSocketServer({ port: 13002, path: "/api/v1/org-socket" });
// การจัดการคำขออัปเกรดจาก HTTP เป็น WebSocket
wss.on("upgrade", (request: any, socket: any, head: any) => {
console.log("🔹 Handling upgrade request...");
wss.handleUpgrade(request, socket, head, (ws: any) => {
console.log("🔹 WebSocket connection established");
wss.emit("connection", ws, request);
});
});
// // การจัดการคำขออัปเกรดจาก HTTP เป็น WebSocket
// wss.on("upgrade", (request: any, socket: any, head: any) => {
// console.log("🔹 Handling upgrade request...");
// wss.handleUpgrade(request, socket, head, (ws: any) => {
// console.log("🔹 WebSocket connection established");
// wss.emit("connection", ws, request);
// });
// });
wss.on("connection", (ws: any) => {
console.log("✅ Client connected to WebSocket");
// wss.on("connection", (ws: any) => {
// console.log("✅ Client connected to WebSocket");
ws.on("close", () => {
console.log("❌ Client disconnected");
});
// ws.on("close", () => {
// console.log("❌ Client disconnected");
// });
ws.on("error", (error: any) => {
console.error("WebSocket error:", error);
});
});
}
// ws.on("error", (error: any) => {
// console.error("WebSocket error:", error);
// });
// });
// }
export async function sendWebSocket(data: any) {
if (!wss) initWebSocket();
wss.clients.forEach((client: any) => {
if (client.readyState === WebSocket.OPEN) {
const message = JSON.stringify(data);
console.log("📤 Sending data to client:", message);
client.send(message, (err: any) => {
if (err) {
console.error("❌ Error sending message:", err);
}
});
}
});
}
// export async function sendWebSocket(data: any) {
// if (!wss) initWebSocket();
// wss.clients.forEach((client: any) => {
// if (client.readyState === WebSocket.OPEN) {
// const message = JSON.stringify(data);
// console.log("📤 Sending data to client:", message);
// client.send(message, (err: any) => {
// if (err) {
// console.error("❌ Error sending message:", err);
// }
// });
// }
// });
// }