Merge branch 'develop'

This commit is contained in:
kittapath 2025-03-11 13:08:19 +07:00
commit 4871ddabbe
3 changed files with 1089 additions and 1152 deletions

View file

@ -14,7 +14,7 @@ import logMiddleware from "./middlewares/logs";
import { CommandController } from "./controllers/CommandController"; import { CommandController } from "./controllers/CommandController";
import { ProfileSalaryController } from "./controllers/ProfileSalaryController"; import { ProfileSalaryController } from "./controllers/ProfileSalaryController";
import { initWebSocket } from "./services/webSocket"; // import { initWebSocket } from "./services/webSocket";
async function main() { async function main() {
await AppDataSource.initialize(); await AppDataSource.initialize();

View file

@ -31,7 +31,7 @@ import { Profile } from "../entities/Profile";
import { viewRegistryOfficer } from "../entities/view/viewRegistryOfficer"; import { viewRegistryOfficer } from "../entities/view/viewRegistryOfficer";
import { viewRegistryEmployee } from "../entities/view/viewRegistryEmployee"; import { viewRegistryEmployee } from "../entities/view/viewRegistryEmployee";
import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster"; import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster";
import { sendWebSocket } from "../services/webSocket"; // import { sendWebSocket } from "../services/webSocket";
@Route("api/v1/org/report") @Route("api/v1/org/report")
@Tags("Report") @Tags("Report")
@ -225,9 +225,7 @@ export class ReportController extends Controller {
}, },
) )
.andWhere( .andWhere(
education != null && education != "" education != null && education != "" ? "registryOfficer.degrees LIKE :degrees" : "1=1",
? "registryOfficer.degrees LIKE :degrees"
: "1=1",
{ {
degrees: `%${education}%`, degrees: `%${education}%`,
}, },
@ -240,14 +238,9 @@ export class ReportController extends Controller {
educationLevels: `%${educationLevel}%`, educationLevels: `%${educationLevel}%`,
}, },
) )
.andWhere( .andWhere(field != null && field != "" ? "registryOfficer.fields LIKE :fields" : "1=1", {
field != null && field != ""
? "registryOfficer.fields LIKE :fields"
: "1=1",
{
fields: `%${field}%`, fields: `%${field}%`,
}, })
)
.orderBy(`registryOfficer.${sortBy}`, sort) .orderBy(`registryOfficer.${sortBy}`, sort)
.getManyAndCount(); .getManyAndCount();
@ -306,38 +299,38 @@ export class ReportController extends Controller {
const mapData = []; const mapData = [];
for await (const x of lists) { for await (const x of lists) {
let _educations:any = [] let _educations: any = [];
if(!education && !educationLevel && !field) { if (!education && !educationLevel && !field) {
_educations = Array.isArray(x.Educations) && x.Educations != null _educations =
? (x.Educations as any[]).filter( Array.isArray(x.Educations) && x.Educations != null
(i: any) => i.isEducation == true ? (x.Educations as any[]).filter((i: any) => i.isEducation == true)
) : [];
: [] if (_educations.length == 0) {
if(_educations.length == 0) { _educations =
_educations = Array.isArray(x.Educations) && x.Educations != null Array.isArray(x.Educations) && x.Educations != null
? (x.Educations as any[]).filter( ? (x.Educations as any[]).filter((i: any) => i.isHigh == true)
(i: any) => i.isHigh == true : [];
)
: []
// if(_educations.length == 0) { // if(_educations.length == 0) {
// _educations = Array.isArray(x.Educations) && x.Educations != null // _educations = Array.isArray(x.Educations) && x.Educations != null
// ? (x.Educations as any[])[0] // ? (x.Educations as any[])[0]
// : [] // : []
// } // }
} }
} } else {
else { _educations =
_educations = Array.isArray(x.Educations) && x.Educations != null Array.isArray(x.Educations) && x.Educations != null
? (x.Educations as any[]).filter( ? (x.Educations as any[]).filter(
(i: any) => (i: any) =>
// i.degree === education || // i.degree === education ||
// i.educationLevel === educationLevel || // i.educationLevel === educationLevel ||
// i.field === field // i.field === field
(education ? i.degree?.toString().includes(education) : false) || (education ? i.degree?.toString().includes(education) : false) ||
(educationLevel ? i.educationLevel?.toString().includes(educationLevel) : false) || (educationLevel
(field ? i.field?.toString().includes(field) : false) ? i.educationLevel?.toString().includes(educationLevel)
: false) ||
(field ? i.field?.toString().includes(field) : false),
) )
: [] : [];
} }
mapData.push({ mapData.push({
profileId: x.profileId, profileId: x.profileId,
@ -540,32 +533,22 @@ export class ReportController extends Controller {
}, },
) )
.andWhere( .andWhere(
position != null && position != "" position != null && position != "" ? "registryEmployee.position LIKE :position" : "1=1",
? "registryEmployee.position LIKE :position"
: "1=1",
{ {
position: `${position}`, position: `${position}`,
}, },
) )
.andWhere(gender != null && gender != "" .andWhere(gender != null && gender != "" ? "registryEmployee.gender LIKE :gender" : "1=1", {
? "registryEmployee.gender LIKE :gender"
: "1=1",
{
gender: `${gender}`, gender: `${gender}`,
} })
)
.andWhere( .andWhere(
status != null && status != "" status != null && status != "" ? "registryEmployee.relationship LIKE :relationship" : "1=1",
? "registryEmployee.relationship LIKE :relationship"
: "1=1",
{ {
relationship: `${status}`, relationship: `${status}`,
}, },
) )
.andWhere( .andWhere(
education != null && education != "" education != null && education != "" ? "registryEmployee.degrees LIKE :degrees" : "1=1",
? "registryEmployee.degrees LIKE :degrees"
: "1=1",
{ {
degrees: `%${education}%`, degrees: `%${education}%`,
}, },
@ -578,43 +561,38 @@ export class ReportController extends Controller {
educationLevels: `%${educationLevel}%`, educationLevels: `%${educationLevel}%`,
}, },
) )
.andWhere( .andWhere(field != null && field != "" ? "registryEmployee.fields LIKE :fields" : "1=1", {
field != null && field != ""
? "registryEmployee.fields LIKE :fields"
: "1=1",
{
fields: `%${field}%`, fields: `%${field}%`,
}, })
)
.orderBy(`registryEmployee.${sortBy}`, sort) .orderBy(`registryEmployee.${sortBy}`, sort)
.getManyAndCount(); .getManyAndCount();
const mapData = []; const mapData = [];
for await (const x of lists) { for await (const x of lists) {
let _educations:any = [] let _educations: any = [];
if(!education && !educationLevel && !field) { if (!education && !educationLevel && !field) {
_educations = Array.isArray(x.Educations) && x.Educations != null _educations =
? (x.Educations as any[]).filter( Array.isArray(x.Educations) && x.Educations != null
(i: any) => i.isEducation == true ? (x.Educations as any[]).filter((i: any) => i.isEducation == true)
) : [];
: [] if (_educations.length == 0) {
if(_educations.length == 0) { _educations =
_educations = Array.isArray(x.Educations) && x.Educations != null Array.isArray(x.Educations) && x.Educations != null
? (x.Educations as any[]).filter( ? (x.Educations as any[]).filter((i: any) => i.isHigh == true)
(i: any) => i.isHigh == true : [];
)
: []
} }
} } else {
else { _educations =
_educations = Array.isArray(x.Educations) && x.Educations != null Array.isArray(x.Educations) && x.Educations != null
? (x.Educations as any[]).filter( ? (x.Educations as any[]).filter(
(i: any) => (i: any) =>
(education ? i.degree?.toString().includes(education) : false) || (education ? i.degree?.toString().includes(education) : false) ||
(educationLevel ? i.educationLevel?.toString().includes(educationLevel) : false) || (educationLevel
(field ? i.field?.toString().includes(field) : false) ? i.educationLevel?.toString().includes(educationLevel)
: false) ||
(field ? i.field?.toString().includes(field) : false),
) )
: [] : [];
} }
mapData.push({ mapData.push({
profileId: x.profileEmployeeId, profileId: x.profileEmployeeId,
@ -671,7 +649,7 @@ export class ReportController extends Controller {
data: mapData, data: mapData,
total: total, total: total,
}); });
} }
/** /**
* API Report1 * API Report1
@ -1649,8 +1627,8 @@ export class ReportController extends Controller {
posMaster.next_holder == null posMaster.next_holder == null
? posType.join(" หรือ ") ? posType.join(" หรือ ")
: posMaster.isSit == false : posMaster.isSit == false
? posMaster.positions.find((x: any) => x.positionIsSelected == true) ? posMaster.positions.find((x: any) => x.positionIsSelected == true)?.posType
?.posType?.posTypeName ?.posTypeName
: posMaster.next_holder.posType == null : posMaster.next_holder.posType == null
? "-" ? "-"
: posMaster.next_holder.posType.posTypeName, : posMaster.next_holder.posType.posTypeName,
@ -1658,8 +1636,8 @@ export class ReportController extends Controller {
posMaster.next_holder == null posMaster.next_holder == null
? posLevel.join(" หรือ ") ? posLevel.join(" หรือ ")
: posMaster.isSit == false : posMaster.isSit == false
? posMaster.positions.find((x: any) => x.positionIsSelected == true) ? posMaster.positions.find((x: any) => x.positionIsSelected == true)?.posLevel
?.posLevel?.posLevelName ?.posLevelName
: posMaster.next_holder.posLevel == null : posMaster.next_holder.posLevel == null
? "-" ? "-"
: posMaster.next_holder.posLevel.posLevelName, : posMaster.next_holder.posLevel.posLevelName,
@ -1813,12 +1791,9 @@ export class ReportController extends Controller {
? "" ? ""
: Extension.ToThaiNumber(node.profilePosLevel.toString()), : Extension.ToThaiNumber(node.profilePosLevel.toString()),
education: education:
node.education == null node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()),
? ""
: Extension.ToThaiNumber(node.education.toString()),
salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "",
reason: reason: node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()),
node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()),
}; };
data.push(_head); data.push(_head);
} else { } else {
@ -1830,9 +1805,7 @@ export class ReportController extends Controller {
) { ) {
const head = { const head = {
posMasterNo: posMasterNo:
node.orgTreeShortName == _node.orgTreeShortName node.orgTreeShortName == _node.orgTreeShortName ? "" : node.orgTreeShortName,
? ""
: node.orgTreeShortName,
profileFullname: profileFullname:
node.profileOrgName == _node.profileOrgName ? "" : node.profileOrgName, node.profileOrgName == _node.profileOrgName ? "" : node.profileOrgName,
posExecutive: node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, posExecutive: node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName,
@ -1894,12 +1867,9 @@ export class ReportController extends Controller {
? "" ? ""
: Extension.ToThaiNumber(node.profilePosLevel.toString()), : Extension.ToThaiNumber(node.profilePosLevel.toString()),
education: education:
node.education == null node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()),
? ""
: Extension.ToThaiNumber(node.education.toString()),
salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "",
reason: reason: node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()),
node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()),
}; };
data.push(head); data.push(head);
} }
@ -2145,9 +2115,7 @@ export class ReportController extends Controller {
positionName: "", positionName: "",
posType: "", posType: "",
posLevel: "", posLevel: "",
profilePosMasterNo: Extension.ToThaiNumber( profilePosMasterNo: Extension.ToThaiNumber(node.profileOrgShortName.toString()),
node.profileOrgShortName.toString(),
),
profilePosExecutive: "", profilePosExecutive: "",
profilePositionName: "", profilePositionName: "",
profilePosType: "", profilePosType: "",
@ -2178,12 +2146,8 @@ export class ReportController extends Controller {
posType: posType:
node.posType == null ? "" : Extension.ToThaiNumber(node.posType.toString()), node.posType == null ? "" : Extension.ToThaiNumber(node.posType.toString()),
posLevel: posLevel:
node.posLevel == null node.posLevel == null ? "" : Extension.ToThaiNumber(node.posLevel.toString()),
? "" profilePosMasterNo: Extension.ToThaiNumber(node.profilePosMasterNo.toString()),
: Extension.ToThaiNumber(node.posLevel.toString()),
profilePosMasterNo: Extension.ToThaiNumber(
node.profilePosMasterNo.toString(),
),
profilePosExecutive: profilePosExecutive:
node.profilePosExecutive == null node.profilePosExecutive == null
? "" ? ""
@ -2204,9 +2168,7 @@ export class ReportController extends Controller {
node.education == null node.education == null
? "" ? ""
: Extension.ToThaiNumber(node.education.toString()), : Extension.ToThaiNumber(node.education.toString()),
salary: node.salary salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "",
? Extension.ToThaiNumber(node.salary.toLocaleString())
: "",
reason: reason:
node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()), node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()),
}; };
@ -2265,12 +2227,8 @@ export class ReportController extends Controller {
posType: posType:
node.posType == null ? "" : Extension.ToThaiNumber(node.posType.toString()), node.posType == null ? "" : Extension.ToThaiNumber(node.posType.toString()),
posLevel: posLevel:
node.posLevel == null node.posLevel == null ? "" : Extension.ToThaiNumber(node.posLevel.toString()),
? "" profilePosMasterNo: Extension.ToThaiNumber(node.profilePosMasterNo.toString()),
: Extension.ToThaiNumber(node.posLevel.toString()),
profilePosMasterNo: Extension.ToThaiNumber(
node.profilePosMasterNo.toString(),
),
profilePosExecutive: profilePosExecutive:
node.profilePosExecutive == null node.profilePosExecutive == null
? "" ? ""
@ -2291,9 +2249,7 @@ export class ReportController extends Controller {
node.education == null node.education == null
? "" ? ""
: Extension.ToThaiNumber(node.education.toString()), : Extension.ToThaiNumber(node.education.toString()),
salary: node.salary salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "",
? Extension.ToThaiNumber(node.salary.toLocaleString())
: "",
reason: reason:
node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()), node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()),
}; };
@ -2314,9 +2270,7 @@ export class ReportController extends Controller {
.sort((a, b) => a.posMasterOrder - b.posMasterOrder) .sort((a, b) => a.posMasterOrder - b.posMasterOrder)
.map(async (posMaster) => { .map(async (posMaster) => {
if (posMaster.orgChild3Id == null) { if (posMaster.orgChild3Id == null) {
const positionName = [ const positionName = [...new Set(posMaster.positions.map((x) => x.positionName))];
...new Set(posMaster.positions.map((x) => x.positionName)),
];
const posType = [ const posType = [
...new Set( ...new Set(
posMaster.positions posMaster.positions
@ -2574,9 +2528,7 @@ export class ReportController extends Controller {
? "" ? ""
: Extension.ToThaiNumber(node.positionName.toString()), : Extension.ToThaiNumber(node.positionName.toString()),
posType: posType:
node.posType == null node.posType == null ? "" : Extension.ToThaiNumber(node.posType.toString()),
? ""
: Extension.ToThaiNumber(node.posType.toString()),
posLevel: posLevel:
node.posLevel == null node.posLevel == null
? "" ? ""
@ -2625,8 +2577,7 @@ export class ReportController extends Controller {
: node.orgTreeShortName, : node.orgTreeShortName,
profileFullname: profileFullname:
node.profileOrgName == _node.profileOrgName ? "" : node.profileOrgName, node.profileOrgName == _node.profileOrgName ? "" : node.profileOrgName,
posExecutive: posExecutive: node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName,
node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName,
positionName: "", positionName: "",
posType: "", posType: "",
posLevel: "", posLevel: "",
@ -2664,9 +2615,7 @@ export class ReportController extends Controller {
? "" ? ""
: Extension.ToThaiNumber(node.positionName.toString()), : Extension.ToThaiNumber(node.positionName.toString()),
posType: posType:
node.posType == null node.posType == null ? "" : Extension.ToThaiNumber(node.posType.toString()),
? ""
: Extension.ToThaiNumber(node.posType.toString()),
posLevel: posLevel:
node.posLevel == null node.posLevel == null
? "" ? ""
@ -3011,9 +2960,7 @@ export class ReportController extends Controller {
? Extension.ToThaiNumber(node.salary.toLocaleString()) ? Extension.ToThaiNumber(node.salary.toLocaleString())
: "", : "",
reason: reason:
node.reason == null node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()),
? ""
: Extension.ToThaiNumber(node.reason.toString()),
}; };
data.push(_head); data.push(_head);
} else { } else {
@ -3029,9 +2976,7 @@ export class ReportController extends Controller {
? "" ? ""
: node.orgTreeShortName, : node.orgTreeShortName,
profileFullname: profileFullname:
node.profileOrgName == _node.profileOrgName node.profileOrgName == _node.profileOrgName ? "" : node.profileOrgName,
? ""
: node.profileOrgName,
posExecutive: posExecutive:
node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName,
positionName: "", positionName: "",
@ -3105,9 +3050,7 @@ export class ReportController extends Controller {
? Extension.ToThaiNumber(node.salary.toLocaleString()) ? Extension.ToThaiNumber(node.salary.toLocaleString())
: "", : "",
reason: reason:
node.reason == null node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()),
? ""
: Extension.ToThaiNumber(node.reason.toString()),
}; };
data.push(head); data.push(head);
} }
@ -3419,9 +3362,7 @@ export class ReportController extends Controller {
? Extension.ToThaiNumber(node.salary.toLocaleString()) ? Extension.ToThaiNumber(node.salary.toLocaleString())
: "", : "",
reason: reason:
node.reason == null node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()),
? ""
: Extension.ToThaiNumber(node.reason.toString()),
}; };
data.push(_head); data.push(_head);
} else { } else {
@ -3437,9 +3378,7 @@ export class ReportController extends Controller {
? "" ? ""
: node.orgTreeShortName, : node.orgTreeShortName,
profileFullname: profileFullname:
node.profileOrgName == _node.profileOrgName node.profileOrgName == _node.profileOrgName ? "" : node.profileOrgName,
? ""
: node.profileOrgName,
posExecutive: posExecutive:
node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName,
positionName: "", positionName: "",
@ -3513,9 +3452,7 @@ export class ReportController extends Controller {
? Extension.ToThaiNumber(node.salary.toLocaleString()) ? Extension.ToThaiNumber(node.salary.toLocaleString())
: "", : "",
reason: reason:
node.reason == null node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()),
? ""
: Extension.ToThaiNumber(node.reason.toString()),
}; };
data.push(head); data.push(head);
} }

View file

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